diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..d988247 --- /dev/null +++ b/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ae3c172 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/bin/ diff --git a/.project b/.project new file mode 100644 index 0000000..43a6c77 --- /dev/null +++ b/.project @@ -0,0 +1,17 @@ + + + HELYX-OS + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/README.md b/README.md index 3c4e70e..e9df699 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,18 @@ # HELYX-OS -[HELYX-OS](http://engys.com/products/helyx-os) is an open-source Graphical User Interface designed to work natively with OpenFOAM [version 2.4.0](http://www.openfoam.org/archive/2.4.0/download/source.php). The GUI is developed by [ENGYS](http://engys.com/) using Java+[VTK](http://www.vtk.org/) and delivered to the public under the GNU General Public License. +[HELYX-OS](http://engys.com/products/helyx-os) is an open-source Graphical User Interface designed to work natively with OpenFOAM [version 4.1](http://www.openfoam.org/archive/4.1/download/source.php) and OpenFOAM [v1606+](http://openfoam.com/download/install-binary.php). The GUI is developed by [ENGYS](http://engys.com/) using Java+[VTK](http://www.vtk.org/) and delivered to the public under the GNU General Public License. HELYX-OS has been created to facilitate the usage of the standard OpenFOAM libraries, by removing the complexity of text based case definition in favour of an intuitive easy-to-use graphical user interface. The GUI is focused on pre-processing tasks, including meshing, case definition and solver execution. Visit the [HELYX-OS Project Page](http://engys.github.io/HELYX-OS/) for more information. ## Installing the latest binary file for 64 bit linux Visit [http://engys.github.io/HELYX-OS/](http://engys.github.io/HELYX-OS/) to download the latest HELYX-OS binary and view [installation instructions](http://engys.github.io/HELYX-OS/installation/). +## Configuring HELYX-OS for OpenFOAM v1606+ +To use OpenFOAM v1606+ installed via Docker following the instructions detailed [here](http://openfoam.com/download/install-binary.php) you need to do the following: + - Open HELYX-OS + - Go to Edit>Preferences + - In the "Misc" section check the "Use Docker" tick box and then type "openfoamplus/of_v1606plus_centos66" in the "Docker Image" textbox + - Press "OK" to apply settings + ## Compiling HELYX-OS on your own ### Prerequisites diff --git a/build_src.xml b/build_src.xml index b5a4d2d..de4a44f 100644 --- a/build_src.xml +++ b/build_src.xml @@ -1,22 +1,20 @@ - + - - - - - - + + + + + + + - - - - + @@ -29,24 +27,27 @@ - - + - - - - - - - + + + + + + + + + + + - + - + @@ -54,7 +55,6 @@ - @@ -64,7 +64,7 @@ - + @@ -73,25 +73,11 @@ - + - - - - - - - - - - - - - - diff --git a/src/eu/engys/application/AbstractApplication.java b/src/eu/engys/application/AbstractApplication.java index b8c087f..a13b01f 100644 --- a/src/eu/engys/application/AbstractApplication.java +++ b/src/eu/engys/application/AbstractApplication.java @@ -1,32 +1,30 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.application; -import static eu.engys.launcher.StartUpMonitor.close; +import static eu.engys.launcher.StartUpMonitor.closeSplash; import java.awt.BorderLayout; import java.awt.Dimension; @@ -37,6 +35,7 @@ import java.awt.event.ActionEvent; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.util.Arrays; +import java.util.Set; import javax.swing.AbstractAction; import javax.swing.Icon; @@ -51,202 +50,205 @@ import org.slf4j.LoggerFactory; import eu.engys.core.Arguments; import eu.engys.core.OpenFOAMEnvironment; import eu.engys.core.controller.Controller; -import eu.engys.core.presentation.ActionContainer; +import eu.engys.core.controller.Controller.OpenMode; +import eu.engys.core.controller.OpenOptions; +import eu.engys.core.modules.ApplicationModule; import eu.engys.core.presentation.ActionManager; import eu.engys.core.project.Model; import eu.engys.gui.AboutWindow; import eu.engys.gui.GlassPane; +import eu.engys.gui.PreferencesBean; import eu.engys.gui.PreferencesDialog; import eu.engys.gui.events.EventManager; import eu.engys.gui.view.View; import eu.engys.gui.view3D.View3DEventListener; +import eu.engys.util.ui.ExecUtil; import eu.engys.util.ui.ResourcesUtil; import eu.engys.util.ui.UiUtil; -public abstract class AbstractApplication implements Application, ActionContainer { +public abstract class AbstractApplication implements Application { - private static final Logger logger = LoggerFactory.getLogger(AbstractApplication.class); + private static final Logger logger = LoggerFactory.getLogger(AbstractApplication.class); - protected JFrame frame; - public View view; - protected Model model; - public Controller controller; - protected View3DEventListener view3dListener; + protected JFrame frame; + public View view; + protected Model model; + public Controller controller; + protected View3DEventListener view3dListener; - public AbstractApplication(Model model, View view, Controller controller) { - this.model = model; - this.view = view; - this.controller = controller; - } + protected Set modules; - @Override - public JFrame getFrame() { - return frame; - } - - @Override - public boolean isDemo() { - return false; - } - - @Override - public void checkVersion() { - } + public AbstractApplication(Model model, Set modules, View view, Controller controller) { + this.model = model; + this.modules = modules; + this.view = view; + this.controller = controller; + } - @Override - public void run() { - initFrame(); - frame.setVisible(true); - trySettingOpenFoamFolder(); + @Override + public JFrame getFrame() { + return frame; + } - if (Arguments.stlFiles != null) { - if (Arguments.baseDir != null) { - ActionManager.getInstance().invoke("application.open"); - } else { - ActionManager.getInstance().invoke("application.create"); - } - } else { - if (Arguments.baseDir != null) { - controller.openCase(Arguments.baseDir); - } else { - view.showStartupDialog(this); - } - } - close(); - } + @Override + public void checkVersion() { + } - protected void trySettingOpenFoamFolder() { - OpenFOAMEnvironment.trySettingOpenFoamFolder(frame); - } + @Override + public void start(final Arguments arguments) { + ExecUtil.invokeLater(new Runnable() { + @Override + public void run() { + initFrame(); + frame.setVisible(true); + trySettingOpenFoamFolder(); - @Override - public void initFrame() { - view.layoutComponents(); - frame = new JFrame(getTitle()) { - @Override - public void dispose() { - EventManager.unregisterAllEventSubscriptions(); - super.dispose(); - } + executeStartupActions(arguments); - /** - * This method fixes the Synthetica laf bug that causes incorrect - * fullscreen window size on secondary monitor. - */ - @Override - public void setMaximizedBounds(Rectangle bounds) { - GraphicsDevice currentFrame = getGraphicsConfiguration().getDevice(); - if (UiUtil.isSecondaryScreen(currentFrame) && getExtendedState() == JFrame.NORMAL) { - super.setMaximizedBounds(UiUtil.getCurrentScreenSize(frame)); - } else { - super.setMaximizedBounds(bounds); - } - } - }; - view.setProgressMonitorParent(frame); + closeSplash(); + } + }); + } - Dimension preferredDimension = UiUtil.getPreferredScreenSize(); - logger.info("Set dimendions to {}", preferredDimension); - frame.setSize(preferredDimension); - frame.setLocationRelativeTo(null); - - UiUtil.center(frame); + protected void executeStartupActions(Arguments arguments) { + if (arguments.baseDir != null) { + controller.openCase(OpenOptions.file(arguments.baseDir, OpenMode.CHECK_FOLDER_ASK_USER)); + } else { + view.showStartupDialog(this); + } + } - frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); + protected void trySettingOpenFoamFolder() { + OpenFOAMEnvironment.trySettingOpenFoamFolder(frame); + } - frame.setIconImages(Arrays.asList(new Image[] { ((ImageIcon) getSmallIcon()).getImage(), ((ImageIcon) getBigIcon()).getImage() })); + @Override + public void initFrame() { + view.layoutComponents(); + frame = new JFrame(getTitle()) { + @Override + public void dispose() { + EventManager.unregisterAllEventSubscriptions(); + super.dispose(); + } - frame.addWindowListener(new WindowAdapter() { - @Override - public void windowClosing(WindowEvent e) { - ActionManager.getInstance().invoke("application.exit"); - } - }); - frame.setName("MainFrame"); - frame.getRootPane().updateUI(); - frame.setJMenuBar(view.getMenuBar()); + /** + * This method fixes the Synthetica laf bug that causes incorrect fullscreen window size on secondary monitor. + */ + @Override + public void setMaximizedBounds(Rectangle bounds) { + GraphicsDevice currentFrame = getGraphicsConfiguration().getDevice(); + if (UiUtil.isSecondaryScreen(currentFrame) && getExtendedState() == JFrame.NORMAL) { + super.setMaximizedBounds(UiUtil.getCurrentScreenSize(this)); + } else { + super.setMaximizedBounds(bounds); + } + } + }; + view.setProgressMonitorParent(frame); - frame.getContentPane().setLayout(new BorderLayout()); - frame.getContentPane().add(view, BorderLayout.CENTER); - frame.getContentPane().add(view.getStatusBar(), BorderLayout.SOUTH); - - GlassPane glassPane = new GlassPane(); - frame.setGlassPane(glassPane); - glassPane.setVisible(false); - + Dimension preferredDimension = UiUtil.getPreferredScreenSize(); + logger.info("Set dimendions to {}", preferredDimension); + frame.setSize(preferredDimension); + frame.setLocationRelativeTo(null); - customizeGUIFrame(view); - } + UiUtil.center(frame); - public View getView() { - return view; - } + frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); - public Model getModel() { - return model; - } + frame.setIconImages(Arrays.asList(new Image[] { ((ImageIcon) getSmallIcon()).getImage(), ((ImageIcon) getBigIcon()).getImage() })); - public abstract String getTitle(); + frame.addWindowListener(new WindowAdapter() { + @Override + public void windowClosing(WindowEvent e) { + ActionManager.getInstance().invoke(View.EXIT); + } + }); + frame.setName("MainFrame"); + frame.getRootPane().updateUI(); + frame.setJMenuBar(view.getMenuBar()); - protected abstract void customizeGUIFrame(View view); + frame.getContentPane().setLayout(new BorderLayout()); + frame.getContentPane().add(view, BorderLayout.CENTER); + frame.getContentPane().add(view.getStatusBar(), BorderLayout.SOUTH); - protected void addPreferencesItem(final View view) { - JMenuItem preferencesItem = new JMenuItem(new AbstractAction("Preferences", PREFERENCES_ICON) { - @Override - public void actionPerformed(ActionEvent e) { - new PreferencesDialog(isOS(), hasParaview(), hasFieldView(), hasEnsight(), hasSolverPreferences(), model.getDefaults().getDictDataFolder()).show(); - } - }); - preferencesItem.setName("Application Preferences"); - view.getMenuBar().getEditMenu().add(preferencesItem); - } + GlassPane glassPane = new GlassPane(); + frame.setGlassPane(glassPane); + glassPane.setVisible(false); - protected abstract boolean hasParaview(); + customizeGUIFrame(view); + } - protected abstract boolean hasFieldView(); + public View getView() { + return view; + } - protected abstract boolean hasEnsight(); + public Model getModel() { + return model; + } - protected boolean hasSolverPreferences() { - return true; - } + public abstract String getTitle(); - protected boolean isOS() { - return false; - } + protected abstract void customizeGUIFrame(View view); - protected void addHelpItem(final View view) { - view.getMenuBar().getHelpMenu().add(new AbstractAction("About", INFO_ICON) { - @Override - public void actionPerformed(ActionEvent e) { - new AboutWindow(getMediumIcon(), getBannerIcon()); - } - }); - } + protected void addPreferencesItem(final View view) { + JMenuItem preferencesItem = new JMenuItem(new AbstractAction(PREFERENCES_LABEL, PREFERENCES_ICON) { + @Override + public void actionPerformed(ActionEvent e) { + if (controller.isDemo()) { + UiUtil.showDemoMessage(); + } else { + new PreferencesDialog(getPreferencesBean(), model.getDefaults().getDictDataFolder()).show(); + } + } + }); + preferencesItem.setName("Application Preferences"); + view.getMenuBar().getEditMenu().add(preferencesItem); + } - - @Override - public JPanel createAdPanel() { - return new JPanel(); - } + protected abstract PreferencesBean getPreferencesBean(); - @Override - public JPanel createVersionPanel() { - return new JPanel(); - } - - /** - * RESOURCES - */ + protected void addHelpItem(final View view) { + view.getMenuBar().getHelpMenu().add(new AbstractAction("About", INFO_ICON) { + @Override + public void actionPerformed(ActionEvent e) { + new AboutWindow(getMediumIcon(), getBannerIcon()); + } + }); + } - public static final Icon PREFERENCES_ICON = ResourcesUtil.getIcon("preferences.icon"); - public static final Icon LICENSE_ICON = ResourcesUtil.getIcon("license.icon"); - public static final Icon INFO_ICON = ResourcesUtil.getIcon("info.icon"); - public static final Icon PDF_ICON = ResourcesUtil.getIcon("file.pdf"); - public static final Icon FOLDER_ICON = ResourcesUtil.getIcon("application.open.icon"); + @Override + public JPanel createAdPanel() { + return new JPanel(); + } - public static final Icon SMALL_LOGO = ResourcesUtil.getIcon("engys.logo"); - public static final Icon BIG_LOGO = ResourcesUtil.getIcon("engys.logo.big"); - public static final Icon MEDIUM_LOGO = ResourcesUtil.getIcon("engys.logo.medium"); - public static final Icon FULL_LOGO = ResourcesUtil.getIcon("engys.logo.full"); + @Override + public JPanel createVersionPanel() { + return new JPanel(); + } + + /* + * RESOURCES + */ + + public static final String PREFERENCES_LABEL = "Preferences"; + public static final Icon PREFERENCES_ICON = ResourcesUtil.getIcon("preferences.icon"); + + public static final String LICENSE_MANAGER_LABEL = "License Manager"; + public static final Icon LICENSE_MANAGER_ICON = ResourcesUtil.getIcon("license.icon"); + + public static final String RELEASE_NOTES_LABEL = "Release Notes"; + public static final String RELEASE_NOTES_WARNING_MESSAGE = "Release notes not found or not installed"; + + public static final String DOCUMENTATION_LABEL = "Documentation"; + public static final Icon DOCUMENTATION_ICON = ResourcesUtil.getIcon("file.pdf"); + public static final String DOCUMENTATION_WARNING_MESSAGE = "Documentation not found or not installed"; + + public static final Icon INFO_ICON = ResourcesUtil.getIcon("info.icon"); + public static final Icon FOLDER_ICON = ResourcesUtil.getIcon("application.open.icon"); + + public static final Icon SMALL_LOGO = ResourcesUtil.getIcon("engys.logo"); + public static final Icon BIG_LOGO = ResourcesUtil.getIcon("engys.logo.big"); + public static final Icon MEDIUM_LOGO = ResourcesUtil.getIcon("engys.logo.medium"); + public static final Icon FULL_LOGO = ResourcesUtil.getIcon("engys.logo.full"); } diff --git a/src/eu/engys/application/AdPanel.java b/src/eu/engys/application/AdPanel.java index ecba263..fc85e94 100644 --- a/src/eu/engys/application/AdPanel.java +++ b/src/eu/engys/application/AdPanel.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.application; import java.awt.BorderLayout; diff --git a/src/eu/engys/application/Application.java b/src/eu/engys/application/Application.java index 41278b3..733dc48 100644 --- a/src/eu/engys/application/Application.java +++ b/src/eu/engys/application/Application.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.application; @@ -30,8 +29,12 @@ import javax.swing.Icon; import javax.swing.JFrame; import javax.swing.JPanel; -public interface Application extends Runnable { +import eu.engys.core.Arguments; +public interface Application { + + public void start(Arguments arguments); + public JFrame getFrame(); public void initFrame(); diff --git a/src/eu/engys/application/ApplicationEventListener.java b/src/eu/engys/application/ApplicationEventListener.java index 21dec04..a0b38a7 100644 --- a/src/eu/engys/application/ApplicationEventListener.java +++ b/src/eu/engys/application/ApplicationEventListener.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.application; diff --git a/src/eu/engys/application/Batch.java b/src/eu/engys/application/Batch.java index 66e8147..5555594 100644 --- a/src/eu/engys/application/Batch.java +++ b/src/eu/engys/application/Batch.java @@ -1,35 +1,37 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.application; +import eu.engys.core.Arguments; + +public interface Batch { -public interface Batch extends Runnable { - public abstract String getTitle(); -} + public abstract void start(Arguments arguments); + public abstract void checkLicense(); + +} diff --git a/src/eu/engys/application/HELYXOS.java b/src/eu/engys/application/HELYXOS.java index 3e70ead..2c15ac7 100644 --- a/src/eu/engys/application/HELYXOS.java +++ b/src/eu/engys/application/HELYXOS.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.application; import java.awt.Color; @@ -31,6 +30,7 @@ import java.awt.Font; import java.awt.event.ActionEvent; import java.net.MalformedURLException; import java.net.URL; +import java.util.Set; import javax.swing.AbstractAction; import javax.swing.BorderFactory; @@ -46,16 +46,17 @@ import com.google.inject.Inject; import eu.engys.core.OpenFOAMEnvironment; import eu.engys.core.controller.Controller; -import eu.engys.core.presentation.Action; -import eu.engys.core.presentation.ActionManager; +import eu.engys.core.modules.ApplicationModule; import eu.engys.core.project.Model; import eu.engys.core.project.zero.patches.BoundaryType; +import eu.engys.gui.PreferencesBean; import eu.engys.gui.view.View; import eu.engys.util.ApplicationInfo; import eu.engys.util.Symbols; import eu.engys.util.Util; import eu.engys.util.VersionChecker; import eu.engys.util.VersionChecker.VersionType; +import eu.engys.util.ui.ExecUtil; import eu.engys.util.ui.ResourcesUtil; public class HELYXOS extends AbstractApplication { @@ -67,9 +68,8 @@ public class HELYXOS extends AbstractApplication { private JButton versionButton; @Inject - public HELYXOS(Model model, View view, Controller controller) { - super(model, view, controller); - ActionManager.getInstance().parseActions(this); + public HELYXOS(Model model, Set modules, View view, Controller controller) { + super(model, modules, view, controller); BoundaryType.registerBoundaryType(BoundaryType.PATCH); BoundaryType.registerBoundaryType(BoundaryType.WALL); @@ -107,7 +107,6 @@ public class HELYXOS extends AbstractApplication { }); } - @Action(key = "application.support.window") public void showSupportWindow() { new SupportWindow(getMediumIcon(), getBannerIcon(), DISCLAIMER); } @@ -117,19 +116,23 @@ public class HELYXOS extends AbstractApplication { new Thread(new Runnable() { @Override public void run() { - VersionType versionType = VersionChecker.isNewVersionAvailable(); - if (versionType.isUpdated()) { - versionLabel.setText("Your version is up to date!"); - versionLabel.setForeground(Color.GREEN.darker()); - versionButton.setVisible(false); - } else if (versionType.isOld()) { - versionLabel.setText("Version " + VersionChecker.getOnlineVersion() + " is available for download!"); - versionLabel.setForeground(Color.RED); - versionButton.setVisible(true); - } else if (versionType.isNotAvailable()) { - versionLabel.setText("Version not available!"); - versionButton.setVisible(false); - } + final VersionType versionType = VersionChecker.isNewVersionAvailable(); + ExecUtil.invokeLater(new Runnable() { + public void run() { + if (versionType.isUpdated()) { + versionLabel.setText("Your version is up to date!"); + versionLabel.setForeground(Color.GREEN.darker()); + versionButton.setVisible(false); + } else if (versionType.isOld()) { + versionLabel.setText("Version " + VersionChecker.getOnlineVersion() + " is available for download!"); + versionLabel.setForeground(Color.RED); + versionButton.setVisible(true); + } else if (versionType.isNotAvailable()) { + versionLabel.setText("Version not available!"); + versionButton.setVisible(false); + } + } + }); } }).start(); } @@ -162,23 +165,18 @@ public class HELYXOS extends AbstractApplication { } @Override - protected boolean isOS() { - return true; - } - - @Override - protected boolean hasParaview() { - return true; - } - - @Override - protected boolean hasFieldView() { - return false; - } - - @Override - protected boolean hasEnsight() { - return false; + protected PreferencesBean getPreferencesBean() { + PreferencesBean bean = new PreferencesBean(); + bean.setPathPreferences(true); + bean.setBatchPreferences(false); + bean.setVtkPreferences(true); + bean.setMiscPreferences(true); + bean.setParaview(true); + bean.setParaviewBatch(false); + bean.setEnsight(false); + bean.setFieldview(false); + bean.setOS(true); + return bean; } @Override diff --git a/src/eu/engys/application/SupportWindow.java b/src/eu/engys/application/SupportWindow.java index 946395d..9ab8a31 100644 --- a/src/eu/engys/application/SupportWindow.java +++ b/src/eu/engys/application/SupportWindow.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.application; diff --git a/src/eu/engys/application/modules/HELYXOSModule.java b/src/eu/engys/application/modules/HELYXOSModule.java index 68a9b81..414c9df 100644 --- a/src/eu/engys/application/modules/HELYXOSModule.java +++ b/src/eu/engys/application/modules/HELYXOSModule.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.application.modules; import com.google.inject.AbstractModule; @@ -32,7 +31,6 @@ import com.google.inject.name.Names; import eu.engys.application.Application; import eu.engys.application.HELYXOS; -import eu.engys.core.Arguments; import eu.engys.core.controller.Controller; import eu.engys.core.controller.HelyxOSController; import eu.engys.core.controller.ScriptFactory; @@ -65,12 +63,13 @@ import eu.engys.gui.casesetup.CaseSetup; import eu.engys.gui.casesetup.CaseSetup3DElement; import eu.engys.gui.casesetup.CaseSetupElement; import eu.engys.gui.casesetup.RuntimeControlsPanel; +import eu.engys.gui.casesetup.StandardSolverSettingsPanel; import eu.engys.gui.casesetup.actions.StandardCaseSetupActions; -import eu.engys.gui.casesetup.boundaryconditions.BoundaryConditionsPanel; -import eu.engys.gui.casesetup.boundaryconditions.panels.CyclicSettingsPanel; +import eu.engys.gui.casesetup.boundaryconditions.panels.BoundaryConditionsPanel; import eu.engys.gui.casesetup.boundaryconditions.panels.StandardCyclicAMISettingsPanel; import eu.engys.gui.casesetup.boundaryconditions.panels.patch.PatchSettingsPanel; import eu.engys.gui.casesetup.boundaryconditions.panels.wall.StandardWallSettingsPanel; +import eu.engys.gui.casesetup.boundaryconditions.parameterspanel.CyclicSettingsPanel; import eu.engys.gui.casesetup.cellzones.CellZonesPanel; import eu.engys.gui.casesetup.cellzones.StandardCellZonesBuilder; import eu.engys.gui.casesetup.cellzones.mrf.StandardMRF; @@ -89,13 +88,12 @@ import eu.engys.gui.casesetup.materials.panels.MaterialsPanel; import eu.engys.gui.casesetup.run.StandardTable15; import eu.engys.gui.casesetup.schemes.NumericalSchemesPanel; import eu.engys.gui.casesetup.solution.StandardSolutionModellingPanel; -import eu.engys.gui.casesetup.solver.SolverSettingsPanel; import eu.engys.gui.custom.CustomNodePanel; import eu.engys.gui.mesh.Mesh; import eu.engys.gui.mesh.Mesh3DElement; import eu.engys.gui.mesh.MeshElement; +import eu.engys.gui.mesh.StandardBoundaryMeshPanel; import eu.engys.gui.mesh.actions.StandardMeshActions; -import eu.engys.gui.mesh.panels.DefaultBoundaryMeshPanel; import eu.engys.gui.mesh.panels.DefaultMeshAdvancedOptionsPanel; import eu.engys.gui.mesh.panels.MaterialPointsPanel; import eu.engys.gui.mesh.panels.SolverBoundaryMeshPanel; @@ -113,26 +111,18 @@ import eu.engys.gui.solver.postprocessing.panels.residuals.ResidualsPanel; import eu.engys.gui.view.View; import eu.engys.gui.view.View3DElement; import eu.engys.gui.view.ViewElement; -import eu.engys.gui.view3D.CanvasPanel; import eu.engys.gui.view3D.Controller3D; import eu.engys.gui.view3D.Geometry3DController; import eu.engys.gui.view3D.Mesh3DController; -import eu.engys.gui.view3D.fallback.FallbackGeometry3DController; -import eu.engys.gui.view3D.fallback.FallbackMesh3DController; -import eu.engys.gui.view3D.fallback.FallbackView3D; import eu.engys.gui.view3D.widget.Widget; import eu.engys.launcher.ApplicationLauncher; import eu.engys.launcher.HELYXOSLauncher; +import eu.engys.standardDynamic.StandardDynamicModule; import eu.engys.standardVOF.StandardVOFModule; -import eu.engys.util.VTKSettings; import eu.engys.util.plaf.HelyxOSLookAndFeel; import eu.engys.util.plaf.ILookAndFeel; import eu.engys.util.progress.ProgressMonitor; import eu.engys.util.progress.ProgressMonitorImpl; -import eu.engys.vtk.VTKEmptyView3D; -import eu.engys.vtk.VTKGeometry3DController; -import eu.engys.vtk.VTKMesh3DController; -import eu.engys.vtk.VTKView3D; import eu.engys.vtk.WidgetPanel; public class HELYXOSModule extends AbstractModule { @@ -184,27 +174,11 @@ public class HELYXOSModule extends AbstractModule { private void configureModules() { Multibinder applicationModules = Multibinder.newSetBinder(binder(), ApplicationModule.class); applicationModules.addBinding().to(StandardVOFModule.class).in(Singleton.class); + applicationModules.addBinding().to(StandardDynamicModule.class).in(Singleton.class); } protected void configure3D() { bind(WidgetPanel.class).in(Singleton.class); - if (!VTKSettings.librariesAreLoaded()) { - VTKSettings.LoadAllNativeLibraries(); - } - if (VTKSettings.librariesAreLoaded()) { - if (Arguments.no3D) { - bind(CanvasPanel.class).to(VTKEmptyView3D.class).in(Singleton.class); - } else { - bind(CanvasPanel.class).to(VTKView3D.class).in(Singleton.class); - } - bind(Geometry3DController.class).to(VTKGeometry3DController.class).in(Singleton.class); - bind(Mesh3DController.class).to(VTKMesh3DController.class).in(Singleton.class); - } else { - bind(CanvasPanel.class).to(FallbackView3D.class).in(Singleton.class); - bind(Geometry3DController.class).to(FallbackGeometry3DController.class).in(Singleton.class); - bind(Mesh3DController.class).to(FallbackMesh3DController.class).in(Singleton.class); - } - Multibinder controllers = Multibinder.newSetBinder(binder(), Controller3D.class); controllers.addBinding().to(Geometry3DController.class).in(Singleton.class); controllers.addBinding().to(Mesh3DController.class).in(Singleton.class); @@ -242,7 +216,7 @@ public class HELYXOSModule extends AbstractModule { panelsMesh.addBinding().to(StandardGeometryPanel.class).in(Singleton.class); panelsMesh.addBinding().to(StandardFeatureLinesPanel.class).in(Singleton.class); panelsMesh.addBinding().to(MaterialPointsPanel.class).in(Singleton.class); - panelsMesh.addBinding().to(DefaultBoundaryMeshPanel.class).in(Singleton.class); + panelsMesh.addBinding().to(StandardBoundaryMeshPanel.class).in(Singleton.class); panelsMesh.addBinding().to(CustomNodePanel.class).in(Singleton.class); Multibinder panelsCaseSetup = Multibinder.newSetBinder(binder(), GUIPanel.class, CaseSetup.class); @@ -250,8 +224,9 @@ public class HELYXOSModule extends AbstractModule { panelsCaseSetup.addBinding().to(MaterialsPanel.class).in(Singleton.class); panelsCaseSetup.addBinding().to(BoundaryConditionsPanel.class).in(Singleton.class); panelsCaseSetup.addBinding().to(CellZonesPanel.class).in(Singleton.class); +// panelsCaseSetup.addBinding().to(FaceZonesPanel.class).in(Singleton.class); panelsCaseSetup.addBinding().to(NumericalSchemesPanel.class).in(Singleton.class); - panelsCaseSetup.addBinding().to(SolverSettingsPanel.class).in(Singleton.class); + panelsCaseSetup.addBinding().to(StandardSolverSettingsPanel.class).in(Singleton.class); panelsCaseSetup.addBinding().to(RuntimeControlsPanel.class).in(Singleton.class); panelsCaseSetup.addBinding().to(StandardFieldsInitialisationPanel.class).in(Singleton.class); panelsCaseSetup.addBinding().to(CustomNodePanel.class).in(Singleton.class); diff --git a/src/eu/engys/core/Arguments.java b/src/eu/engys/core/Arguments.java index 90ca5a5..04c418b 100644 --- a/src/eu/engys/core/Arguments.java +++ b/src/eu/engys/core/Arguments.java @@ -1,33 +1,33 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core; import java.io.File; import java.io.FilenameFilter; +import java.io.IOException; +import java.nio.file.Paths; import org.apache.log4j.Level; @@ -36,197 +36,237 @@ import eu.engys.util.Util; public class Arguments { - private static final String LINE = " ********************************"; - private static final String TAB = " "; + private static final String LINE = " ********************************"; + private static final String TAB = " "; - public enum CaseType { - SERIAL, PARALLEL - } + public boolean verbose = false; + public boolean no3D = false; + public boolean load3Dmesh = true; + public boolean load3Dgeometry = true; + public Level logLevel = Level.ERROR; - public static boolean verbose = false; - public static boolean no3D = false; - public static boolean load3Dmesh = true; - public static boolean load3Dgeometry = true; - public static Level logLevel = Level.ERROR; + public File baseDir = null; + public File studyDir = null; - public static File baseDir = null; + public boolean mesh = false; + public boolean run = false; + public boolean setup = false; + public boolean all = false; + public boolean initialise = false; + public boolean post = false; - public static boolean mesh = false; - public static boolean run = false; - public static boolean setup = false; - public static boolean all = false; - public static boolean initialise = false; + public int concurrentDesigns = 1; - public static boolean server = false; - public static CaseType caseType = null; - public static File[] stlFiles = null; -// public static long timeout = -1L; + public boolean server = false; + public File[] importFiles = null; - private static final String OPTION_V = "-v"; - private static final String OPTION_VV = "-V"; - private static final String OPTION_HELP = "-help"; - private static final String OPTION_NO3D = "-no3D"; - private static final String OPTION_CASE = "-case"; - - public static final String OPTION_MESH = "-mesh"; - public static final String OPTION_RUN = "-run"; - public static final String OPTION_SETUP = "-setup"; - public static final String OPTION_ALL = "-all"; - public static final String OPTION_INITIALISE = "-initialise"; + private static final String OPTION_V = "-v"; + private static final String OPTION_VV = "-V"; + private static final String OPTION_HELP = "-help"; + private static final String OPTION_NO3D = "-no3D"; + private static final String OPTION_CASE = "-case"; + private static final String OPTION_STUDY = "-study"; - private static final String OPTION_SERVER = "-server"; /* INTERNAL */ - private static final String OPTION_IMPORT = "-import"; /* INTERNAL */ - private static final String OPTION_NOMESH = "-no3Dmesh"; /* INTERNAL */ - private static final String OPTION_NOGEOM = "-no3DGeom"; /* INTERNAL */ -// private static final String OPTION_CORE = "-core"; /* INTERNAL */ -// private static final String OPTION_TIMEOUT = "-timeout"; /* INTERNAL */ + public static final String OPTION_MESH = "-mesh"; + public static final String OPTION_RUN = "-run"; + public static final String OPTION_SETUP = "-setup"; + public static final String OPTION_ALL = "-all"; + public static final String OPTION_INITIALISE = "-initialise"; + public static final String OPTION_POST = "-post"; + public static final String OPTION_MEMORY = "-memory="; - public static void init(final String[] argv) { - for (int i = 0; i < argv.length; i++) { - final String arg = argv[i]; + public static final String OPTION_CONCURRENT_DESIGNS = "-concurrent"; - if (arg.charAt(0) == '-') { - switch (arg) { + private static final String OPTION_SERVER = "-server"; /* INTERNAL */ + private static final String OPTION_IMPORT = "-import"; /* INTERNAL */ + private static final String OPTION_NOMESH = "-no3Dmesh"; /* INTERNAL */ + private static final String OPTION_NOGEOM = "-no3DGeom"; /* INTERNAL */ + + // private static final String OPTION_CORE = "-core"; /* INTERNAL */ + // private static final String OPTION_TIMEOUT = "-timeout"; /* INTERNAL */ + + public void parse(final String[] argv) { + for (int i = 0; i < argv.length; i++) { + final String arg = argv[i]; + + if (arg.charAt(0) == '-') { + switch (arg) { case OPTION_V: logLevel = Level.INFO; verbose = true; break; case OPTION_VV: logLevel = Level.DEBUG; verbose = true; break; case OPTION_NO3D: no3D = true; break; - - case OPTION_CASE: - if (i == argv.length - 1) { - fatal("Missing case folder"); - printUsage(); - exit(-1); - } - String baseDirPath = argv[++i]; - final File baseDir = new File(baseDirPath); - if (!baseDir.exists()) { - warning("Case Folder \"" + baseDir.getAbsolutePath() + "\" Does Not Exist!"); - } else { - Arguments.baseDir = baseDir; - } - break; - - case OPTION_MESH: mesh = true; break; - case OPTION_RUN: run = true; break; - case OPTION_SETUP: setup = true; break; - case OPTION_ALL: all = true; break; - case OPTION_INITIALISE: initialise = true; break; - case OPTION_SERVER: server = true; break; - + + case OPTION_CASE: + if (i == argv.length - 1) { + fatal("Missing case folder"); + printUsage(); + exit(-1); + } + String baseDirPath = argv[++i]; + try { + /* + * Use toRealPath to avoid bad path display when using "." and ".." + */ + File baseDir = Paths.get(baseDirPath).toRealPath().toFile(); + if (!baseDir.exists()) { + warning("Case Folder \"" + baseDir.getAbsolutePath() + "\" Does Not Exist!"); + } else { + this.baseDir = baseDir; + } + } catch (IOException e) { + warning(e.getMessage()); + } + + break; + case OPTION_STUDY: + if (i == argv.length - 1) { + fatal("Missing study folder"); + printUsage(); + exit(-1); + } + String studyDirPath = argv[++i]; + final File studyDir = new File(studyDirPath); + if (!studyDir.exists()) { + warning("Case Folder \"" + studyDir.getAbsolutePath() + "\" Does Not Exist!"); + } else { + this.studyDir = studyDir; + } + break; + + case OPTION_MESH: this.mesh = true; break; + case OPTION_RUN: this.run = true; break; + case OPTION_SETUP: this.setup = true; break; + case OPTION_ALL: this.all = true; break; + case OPTION_INITIALISE: this.initialise = true; break; + case OPTION_POST: this.post = true; break; + case OPTION_SERVER: this.server = true; break; + + case OPTION_CONCURRENT_DESIGNS: + if (i == argv.length - 1) { + fatal("Missing number of concurrent designs folder"); + printUsage(); + exit(-1); + } + String designs = argv[++i]; + try { + int nDesigns = Integer.parseInt(designs); + this.concurrentDesigns = nDesigns; + } catch (NumberFormatException nfe) { + warning("Invalid number of concurrent designs"); + } + break; case OPTION_NOGEOM: load3Dgeometry = false; break; case OPTION_NOMESH: load3Dmesh = false; break; - - case OPTION_IMPORT: - if (i == argv.length - 1) { - fatal("Missing import folder"); - printUsage(); - exit(-1); - } - String importPath = argv[++i]; - final File importFolder = new File(importPath); - if (!importFolder.exists()) { - fatal("Import Folder Does Not Exist!"); - exit(-1); - } else if (importFolder.isFile()) { - String name = importFolder.getName(); - if (name.endsWith("stl") || name.endsWith("STL")) { - Arguments.stlFiles = new File[]{importFolder}; - } else { - fatal("Import Folder Does Not Exist!"); - exit(-1); - } - } else { - File[] stls = importFolder.listFiles(new FilenameFilter() { - @Override - public boolean accept(File dir, String name) { - return name.endsWith("stl") || name.endsWith("STL"); - } - }); - if (stls.length == 0) { - fatal("No files to import!"); - exit(-1); - } else { - Arguments.stlFiles = stls; - } - } - break; - case OPTION_HELP: - printUsage(); - exit(0); - break; - default: - fatal("Unknown Option " + arg); - printUsage(); - exit(0); - break; - } - } - } - checkCase(); - } - private static void checkCase() { - if (hasCommand()) { - if (Arguments.baseDir == null) { - fatal("Missing case folder"); - printUsage(); - exit(-1); - } - } - } + case OPTION_IMPORT: + if (i == argv.length - 1) { + fatal("Missing import file/folder"); + printUsage(); + exit(-1); + } + String importPath = argv[++i]; + final File importFolder = new File(importPath); + if (!importFolder.exists()) { + fatal("Import Folder Does Not Exist!"); + exit(-1); + } else if (importFolder.isFile()) { + this.importFiles = new File[] { importFolder }; + } else { + File[] stls = importFolder.listFiles(new FilenameFilter() { + @Override + public boolean accept(File dir, String name) { + return name.endsWith("stl") || name.endsWith("STL"); + } + }); + if (stls.length == 0) { + fatal("No files to import!"); + exit(-1); + } else { + this.importFiles = stls; + } + } + break; + case OPTION_HELP: + printUsage(); + exit(0); + break; + default: + fatal("Unknown Option " + arg); + printUsage(); + exit(0); + break; + } + } + } + checkCaseOrStudy(); + } - private static void fatal(String msg) { - System.err.println(); - System.err.println(LINE); - System.err.println(" " + TAB + "FATAL ERROR:"); - System.err.println(" " + TAB + TAB + msg); - System.err.println(LINE); - } + private void checkCaseOrStudy() { + if (hasCommand()) { + if (baseDir == null && studyDir == null) { + fatal("Missing case (or study) folder"); + printUsage(); + exit(-1); + } + } + } - private static void warning(String msg) { - System.err.println(); - System.err.println(LINE); - System.err.println(" " + TAB+"WARNING:"); - System.err.println(" " + TAB + TAB + msg); - System.err.println(TAB+LINE); - } - - private static void exit(int status) { - System.exit(status); - } + private static void fatal(String msg) { + System.err.println(); + System.err.println(LINE); + System.err.println(" " + TAB + "FATAL ERROR:"); + System.err.println(" " + TAB + TAB + msg); + System.err.println(LINE); + } - private static void printUsage() { - - System.err.println(" USAGE"); - System.err.println(" -----------------------------------------------------"); - if (Util.isWindows()) - System.err.println(" "+ApplicationInfo.getName()+".bat ["+OPTION_V+"] ["+OPTION_VV+"] [-case ] [command] "); - else - System.err.println(" "+ApplicationInfo.getName()+".sh ["+OPTION_V+"] ["+OPTION_VV+"] [-case ] [command] "); - - System.err.println(); - System.err.println(" Options:"); - System.err.println(" " + Util.padWithSpaces(OPTION_HELP, 12) + " Print this help screen."); - System.err.println(" " + Util.padWithSpaces(OPTION_V, 12) + " The verbose output."); - System.err.println(" " + Util.padWithSpaces(OPTION_VV, 12) + " The very verbose output."); - System.err.println(" " + Util.padWithSpaces(OPTION_CASE, 12) + " Specify the case directory for the application."); - System.err.println(" " + Util.padWithSpaces(OPTION_NO3D, 12) + " Does not display 3D window."); - System.err.println(); - System.err.println(" Commands:"); - System.err.println(" " + Util.padWithSpaces(OPTION_MESH, 12) + " Launch mesh creation according to system/snappyHexMeshDict."); - System.err.println(" " + Util.padWithSpaces(OPTION_SETUP, 12) + " Setup the cfd case according to system/caseSetupDict."); - System.err.println(" " + Util.padWithSpaces(OPTION_INITIALISE, 12) + " Initialise the fields according to system/caseSetupDict."); - System.err.println(" " + Util.padWithSpaces(OPTION_RUN, 12) + " Launch the solver."); - System.err.println(" " + Util.padWithSpaces(OPTION_ALL, 12) + " Launch mesh + setup + run."); - System.err.println(" -----------------------------------------------------"); - } + private static void warning(String msg) { + System.err.println(); + System.err.println(LINE); + System.err.println(" " + TAB + "WARNING:"); + System.err.println(" " + TAB + TAB + msg); + System.err.println(TAB + LINE); + } - public static boolean isBatch() { - return Arguments.server || hasCommand(); - } + private static void exit(int status) { + System.exit(status); + } - private static boolean hasCommand() { - return Arguments.mesh || Arguments.setup || Arguments.run || Arguments.all || Arguments.initialise; - } + private static void printUsage() { + + System.err.println(" USAGE"); + System.err.println(" -----------------------------------------------------"); + if (Util.isWindows()) + System.err.println(" " + ApplicationInfo.getName() + ".bat [" + OPTION_V + "] [" + OPTION_VV + "] [-case ] [command] "); + else + System.err.println(" " + ApplicationInfo.getName() + ".sh [" + OPTION_V + "] [" + OPTION_VV + "] [-case ] [command] "); + + System.err.println(); + System.err.println(" Options:"); + System.err.println(" " + Util.padWithSpaces(OPTION_HELP, 12) + " Print this help screen."); + System.err.println(" " + Util.padWithSpaces(OPTION_V, 12) + " The verbose output."); + System.err.println(" " + Util.padWithSpaces(OPTION_VV, 12) + " The very verbose output."); + System.err.println(" " + Util.padWithSpaces(OPTION_NO3D, 12) + " Does not display 3D window."); + System.err.println(" " + Util.padWithSpaces(OPTION_CASE, 12) + " Specify the case directory for the application."); + System.err.println(" " + Util.padWithSpaces(OPTION_STUDY, 12) + " Specify the study directory for the application (case manager only)."); + System.err.println(" " + Util.padWithSpaces(OPTION_CONCURRENT_DESIGNS, 12) + " Specify the number of cases to run in parallel (case manager only)."); + System.err.println(); + System.err.println(" " + Util.padWithSpaces(OPTION_MEMORY, 12) + " Set the maximum memory size. Size is expressed as '1234m' or '1g' "); + System.err.println(); + System.err.println(" Commands:"); + System.err.println(" " + Util.padWithSpaces(OPTION_MESH, 12) + " Launch mesh creation according to system/snappyHexMeshDict."); + System.err.println(" " + Util.padWithSpaces(OPTION_SETUP, 12) + " Setup the cfd case according to system/caseSetupDict."); + System.err.println(" " + Util.padWithSpaces(OPTION_INITIALISE, 12) + " Initialise the fields according to system/caseSetupDict."); + System.err.println(" " + Util.padWithSpaces(OPTION_RUN, 12) + " Launch the solver."); + System.err.println(" " + Util.padWithSpaces(OPTION_ALL, 12) + " Launch mesh + setup + run."); + System.err.println(" " + Util.padWithSpaces(OPTION_POST, 12) + " Extract post-processing results."); + System.err.println(" -----------------------------------------------------"); + } + + public boolean isBatch() { + return server || hasCommand(); + } + + private boolean hasCommand() { + return mesh || setup || run || all || initialise || post; + } } diff --git a/src/eu/engys/core/DockerUtil.java b/src/eu/engys/core/DockerUtil.java new file mode 100644 index 0000000..e6eaa24 --- /dev/null +++ b/src/eu/engys/core/DockerUtil.java @@ -0,0 +1,239 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.core; + +import static eu.engys.util.OpenFOAMCommands.PARA_FOAM; +import static eu.engys.util.PrefUtil.DOCKER_IMAGE; + +import java.io.File; +import java.io.IOException; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; + +import org.apache.commons.exec.CommandLine; +import org.apache.commons.io.FileUtils; + +import eu.engys.util.PrefUtil; +import eu.engys.util.Util; + +public class DockerUtil { + + private static final String USER = PrefUtil.USER_NAME; + private static final String HOME = PrefUtil.USER_HOME; + private static final String USER_UID = Util.getUID(); + private static final String DISPLAY = PrefUtil.DISPLAY; + private static final String SHARE = "/share"; + + private static final String ENGYS_22_BETA_VENDOR_HOME = "/opt"; + private static final String ENGYS_22_BETA_ENV_LOADER = "/opt/OpenFOAM-2.2_engysEdition-beta/etc/bashrc"; + + private static final String OF_PLUS_VENDOR_HOME = "/opt/OpenFOAM"; + private static final String OF_PLUS_ENV_LOADER = "/opt/OpenFOAM/OpenFOAM-v1606+/etc/bashrc"; + + private static final String PV_VERSION = "4.1.0"; + private static final String MACHINEFILE = ""; + + private static final String WINDOWS_DOCKER_ENV = "FOR /f \"tokens=*\" %%i IN ('\"C:\\Program Files\\Docker Toolbox\\docker-machine\" env default --shell=cmd') DO %%i"; + + public static CommandLine getCommandLine(Map environment, String script) { + String dockerImage = PrefUtil.getString(DOCKER_IMAGE); + + String casePath = ensureLinuxPath(environment.get("CASE")); + String scriptPath = ensureLinuxPath(casePath + "/" + script); + + List arguments = new LinkedList<>(); + + addRunCommand(arguments, false, false); + addScriptVariables(arguments, environment); + addDisplayVariables(arguments); + addUserVariables(arguments); + addWorkDir(arguments, Util.isWindows() ? SHARE : HOME); + + arguments.add(dockerImage); + + // the actual command + arguments.add(scriptPath); + + CommandLine commandLine = new CommandLine("docker"); + commandLine.addArguments(arguments.toArray(new String[0]), false); + return Util.isWindows() ? windowsWrapper(environment.get("CASE"), commandLine) : commandLine; + } + + public static String terminal(File baseDir) { + String dockerImage = PrefUtil.getString(DOCKER_IMAGE); + boolean isOFPlus = dockerImage.contains("openfoamplus"); + + String ENV_LOADER = isOFPlus ? OF_PLUS_ENV_LOADER : ENGYS_22_BETA_ENV_LOADER; + + List arguments = new LinkedList<>(); + + addRunCommand(arguments, true, true); + addDisplayVariables(arguments); + addUserVariables(arguments); + addWorkDir(arguments, baseDir.getAbsolutePath()); + + arguments.add(dockerImage); + + // the actual command + arguments.add("/bin/bash"); + arguments.add("--rcfile"); + arguments.add(ENV_LOADER); + + CommandLine commandLine = new CommandLine("docker"); + commandLine.addArguments(arguments.toArray(new String[0]), false); + return Util.isWindows() ? windowsWrapper(baseDir.getAbsolutePath(), commandLine).toString() : commandLine.toString(); + } + + public static String paraview(File baseDir) { + String dockerImage = PrefUtil.getString(DOCKER_IMAGE); + boolean isOFPlus = dockerImage.contains("openfoamplus"); + + String ENV_LOADER = isOFPlus ? OF_PLUS_ENV_LOADER : ENGYS_22_BETA_ENV_LOADER; + + List arguments = new LinkedList<>(); + + addRunCommand(arguments, true, false); + addDisplayVariables(arguments); + addUserVariables(arguments); + addWorkDir(arguments, baseDir.getAbsolutePath()); + + arguments.add(dockerImage); + + // the actual command + arguments.add("/bin/bash"); + arguments.add("--rcfile"); + arguments.add(ENV_LOADER); + arguments.add("-ci"); + arguments.add(PARA_FOAM); + + CommandLine commandLine = new CommandLine("docker"); + commandLine.addArguments(arguments.toArray(new String[0]), false); + return Util.isWindows() ? windowsWrapper(baseDir.getAbsolutePath(), commandLine).toString() : commandLine.toString(); + } + + /* + * Utils + */ + private static String ensureLinuxPath(String winPath) { + if (Util.isWindows()) { + String linuxPath = winPath; + linuxPath = linuxPath.replace(HOME, SHARE); + if (linuxPath.endsWith("bat")) { + linuxPath = linuxPath.replace("bat", "run"); + } + return linuxPath.replace("\\", "/"); + } else { + return winPath; + } + } + + private static void addWorkDir(List arguments, String workDir) { + arguments.add("-w"); + arguments.add(ensureLinuxPath(workDir)); + } + + private static void addScriptVariables(List arguments, Map environment) { + String dockerImage = PrefUtil.getString(DOCKER_IMAGE); + boolean isOFPlus = dockerImage.contains("openfoamplus"); + + String NP = environment.get("NP"); + String SOLVER = environment.get("SOLVER"); + + String VENDOR_HOME = isOFPlus ? OF_PLUS_VENDOR_HOME : ENGYS_22_BETA_VENDOR_HOME; + String ENV_LOADER = isOFPlus ? OF_PLUS_ENV_LOADER : ENGYS_22_BETA_ENV_LOADER; + + String CASE = ensureLinuxPath(environment.get("CASE")); + String LOG = ensureLinuxPath(environment.get("LOG")); + + arguments.add("-e"); + arguments.add("CASE=" + CASE); + arguments.add("-e"); + arguments.add("NP=" + NP); + arguments.add("-e"); + arguments.add("LOG=" + LOG); + arguments.add("-e"); + arguments.add("ENV_LOADER=" + ENV_LOADER); + arguments.add("-e"); + arguments.add("VENDOR_HOME=" + VENDOR_HOME); + arguments.add("-e"); + arguments.add("SOLVER=" + SOLVER); + arguments.add("-e"); + arguments.add("PV_VERSION=" + PV_VERSION); + arguments.add("-e"); + arguments.add("MACHINEFILE=" + MACHINEFILE); + } + + private static void addDisplayVariables(List arguments) { + arguments.add("-e"); + arguments.add("QT_X11_NO_MITSHM=1"); + arguments.add("-e"); + arguments.add("DISPLAY=" + DISPLAY); + } + + private static void addUserVariables(List arguments) { + arguments.add("-e"); + arguments.add("USER=" + USER); + arguments.add("-v"); + arguments.add(Util.isWindows() ? (SHARE + ":" + SHARE) : (HOME + ":" + HOME)); + arguments.add("-v"); + arguments.add("/etc/group:/etc/group:ro"); + arguments.add("-v"); + arguments.add("/etc/passwd:/etc/passwd:ro"); + arguments.add("-v"); + arguments.add("/etc/shadow:/etc/shadow:ro"); + arguments.add("-v"); + arguments.add("/etc/sudoers.d:/etc"); + arguments.add("-v"); + arguments.add("/tmp:/tmp"); + } + + private static void addRunCommand(List arguments, boolean interactive, boolean tty) { + arguments.add("run"); + arguments.add("--rm"); + if (interactive && tty) { + arguments.add("-it"); + } else if (interactive) { + arguments.add("-i"); + } + arguments.add("-u"); + arguments.add(USER_UID); + } + + private static CommandLine windowsWrapper(String baseDir, CommandLine commandLine) { + File f = new File(baseDir, "dockerWrapper.bat"); + List lines = new LinkedList<>(); + lines.add("@echo off"); + lines.add(WINDOWS_DOCKER_ENV); + lines.add(commandLine.toString()); + try { + FileUtils.writeLines(f, lines, false); + } catch (IOException e) { + e.printStackTrace(); + } + return new CommandLine(f.getAbsolutePath()); + } + +} diff --git a/src/eu/engys/core/OpenFOAMEnvironment.java b/src/eu/engys/core/OpenFOAMEnvironment.java index ca14fd9..4b7bd3d 100644 --- a/src/eu/engys/core/OpenFOAMEnvironment.java +++ b/src/eu/engys/core/OpenFOAMEnvironment.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core; import static eu.engys.core.project.openFOAMProject.LOG; @@ -38,6 +37,7 @@ import java.util.Map; import javax.swing.JFrame; import org.apache.commons.exec.CommandLine; +import org.apache.commons.lang.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -106,10 +106,6 @@ public class OpenFOAMEnvironment { return getEnvironment(model, ""); } -// public static Map getEnvironment(Model model, File baseDir) { -// return getEnvironment(model, baseDir, null, null); -// } - public static Map getEnvironment(Model model, String logFileName) { return getEnvironment(model, model.getProject().getBaseDir(), logFileName, null); } @@ -137,11 +133,11 @@ public class OpenFOAMEnvironment { map.put("LOG", Paths.get(model.getProject().getBaseDir().getAbsolutePath(), LOG, logFileName).toString()); } - map.put("VENDOR_HOME", getVendorHome().getAbsolutePath()); + map.put("VENDOR_HOME", getVendorHome() != null ? getVendorHome().getAbsolutePath() : ""); map.put("PV_VERSION", getParaviewVersion()); - map.put("ENV_LOADER", getEnvLoader().getAbsolutePath()); + map.put("ENV_LOADER", getEnvLoader() != null ? getEnvLoader().getAbsolutePath() : ""); if (option != null) { JavaExecutor executor = Executor.jvm("eu.engys.launcher.Launcher", option, "-V"); @@ -219,6 +215,8 @@ public class OpenFOAMEnvironment { } else { UiUtil.showCoreEnvironmentNotLoadedWarning(frame); } + } else { + logger.info("Environment set to {}. Version {} ({})", PrefUtil.getOpenFoamEntry(), getOpenFoamVersion(), getOpenFoamSubVersion()); } } @@ -239,7 +237,7 @@ public class OpenFOAMEnvironment { } } - public static void trySettingParaviewExecutable() { + public static void trySettingParaviewExecutables() { if (!OpenFOAMEnvironment.isParaviewPathSet() && OpenFOAMEnvironment.isEnvironementLoaded()) { File paraviewExecutable = getParaViewExecutablePath(); if (paraviewExecutable != null) { @@ -249,6 +247,15 @@ public class OpenFOAMEnvironment { logger.warn("ParaView path NOT set"); } } + if (!OpenFOAMEnvironment.isParaviewBatchPathSet() && OpenFOAMEnvironment.isEnvironementLoaded()) { + File paraviewBatchExecutable = getParaViewBatchExecutablePath(); + if (paraviewBatchExecutable != null) { + PrefUtil.setParaViewBatchEntry(paraviewBatchExecutable); + logger.info("ParaView BATCH path set to {}", PrefUtil.getParaViewEntry()); + } else { + logger.warn("ParaView BATCH path NOT set"); + } + } } public static File[] getOpenFoamDir() { @@ -259,7 +266,6 @@ public class OpenFOAMEnvironment { File vendorHome = Paths.get(jarPath).getParent().getParent().getParent().getParent().toFile(); logger.info("Check for valid OpenFOAM folder in {}", vendorHome); openFoamFolders = vendorHome.listFiles(new FileFilter() { - @Override public boolean accept(File file) { return file.isDirectory() && file.getName().startsWith("OpenFOAM"); @@ -271,16 +277,40 @@ public class OpenFOAMEnvironment { return openFoamFolders; } - private static File getParaViewExecutablePath() { - File[] paraviewFolders = new File[0]; - File[] thirdPartyDirs = getThirdPartyDir(); + private static File getParaViewBatchExecutablePath() { + File[] paraview_OSMESA_Folders = new File[0]; + File[] thirdPartyDirs = getThirdPartyDir(getOpenFoamVersion()); if (Util.isVarArgsNotNullAndOfSize(1, thirdPartyDirs)) { File thirdPartyDir = thirdPartyDirs[0]; logger.info("Check for valid ParaView folder in {}", thirdPartyDir); + paraview_OSMESA_Folders = thirdPartyDir.listFiles(new FileFilter() { + @Override + public boolean accept(File file) { + return file.isDirectory() && file.getName().startsWith("ParaView-") && file.getName().endsWith("osmesa"); + } + }); + } + if (Util.isVarArgsNotNull(paraview_OSMESA_Folders)) { + for (File pvFolder : paraview_OSMESA_Folders) { + File pvBatchExecutable = Paths.get(pvFolder.getAbsolutePath(), "platforms", "linux64Gcc", "bin", "pvbatch").toFile(); + if (pvBatchExecutable.exists()) { + return pvBatchExecutable; + } + } + } + return null; + } + + private static File getParaViewExecutablePath() { + File[] paraviewFolders = new File[0]; + File[] thirdPartyDirs = getThirdPartyDir(getOpenFoamVersion()); + if (Util.isVarArgsNotNullAndOfSize(1, thirdPartyDirs)) { + File thirdPartyDir = thirdPartyDirs[0]; + logger.info("Check for valid ParaView BATCH folder in {}", thirdPartyDir); paraviewFolders = thirdPartyDir.listFiles(new FileFilter() { @Override public boolean accept(File file) { - return file.isDirectory() && file.getName().startsWith("ParaView"); + return file.isDirectory() && file.getName().startsWith("ParaView-"); } }); } @@ -295,28 +325,31 @@ public class OpenFOAMEnvironment { return null; } - private static File[] getThirdPartyDir() { - File[] openFoamFolders = getOpenFoamDir(); + private static File[] getThirdPartyDir(final String version) { File[] thirdPartyFolders = new File[0]; - if (Util.isVarArgsNotNullAndOfSize(1, openFoamFolders)) { - File vendorHome = getOpenFoamDir()[0].getParentFile(); - logger.info("Check for valid ThirdParty folder in {}", vendorHome); + if (OpenFOAMEnvironment.isEnvironementLoaded()) { + File openFoamDir = PrefUtil.getOpenFoamEntry(); + File vendorHome = openFoamDir.getParentFile(); + logger.info("Check for valid ThirdParty folder in {} for version {}", vendorHome, version); thirdPartyFolders = vendorHome.listFiles(new FileFilter() { @Override public boolean accept(File file) { - return file.isDirectory() && file.getName().startsWith("ThirdParty"); + String name = file.getName(); + return file.isDirectory() && name.startsWith("ThirdParty") && name.endsWith(version); } }); + } else { + logger.warn("ThirdParty folder not found: missing "); } return thirdPartyFolders; + } - private static File[] getOpenFoamDirOS_onUnix() { + public static File[] getOpenFoamDirOS_onUnix() { File[] openFoamFolders = new File[0]; File optFolder = new File("/opt"); logger.info("Check for valid OpenFOAM folder in {}", optFolder); openFoamFolders = optFolder.listFiles(new FileFilter() { - @Override public boolean accept(File file) { boolean isDir = file.isDirectory(); @@ -351,6 +384,9 @@ public class OpenFOAMEnvironment { } public static boolean isEnvironementLoaded() { + if(PrefUtil.isUsingDocker()){ + return true; + } File openFoamDir = PrefUtil.getOpenFoamEntry(); if (openFoamDir == null || !openFoamDir.exists() || !openFoamDir.isDirectory()) { return false; @@ -366,6 +402,14 @@ public class OpenFOAMEnvironment { return true; } + public static boolean isParaviewBatchPathSet() { + File paraViewBatch = PrefUtil.getParaViewBatchEntry(); + if (paraViewBatch == null || !paraViewBatch.exists() || !paraViewBatch.isFile() || !paraViewBatch.canExecute()) { + return false; + } + return true; + } + public static boolean isFieldViewPathSet() { File fieldView = PrefUtil.getFieldViewEntry(); if (fieldView == null || !fieldView.exists() || !fieldView.isFile() || !fieldView.canExecute()) { @@ -402,9 +446,35 @@ public class OpenFOAMEnvironment { return new File(""); } - public static String getParaviewVersion() { - File pvHome = PrefUtil.getParaViewEntry(); - if (pvHome != null && pvHome.exists()) { + private static String getOpenFoamVersion() { + File openFoamEntry = PrefUtil.getOpenFoamEntry(); + if (openFoamEntry != null) { + String name = openFoamEntry.getName(); + String[] split = StringUtils.split(name, "-"); + if (split.length > 1) { + return split[1]; + } + } + return ""; + } + + private static String getOpenFoamSubVersion() { + File openFoamEntry = PrefUtil.getOpenFoamEntry(); + if (openFoamEntry != null) { + String name = openFoamEntry.getName(); + String[] split = StringUtils.split(name, "-"); + if (split.length > 2) { + return split[2]; + } + } + return ""; + } + + private static String getParaviewVersion() { +// File pvHome = PrefUtil.getParaViewEntry(); + File pvExe = PrefUtil.getParaViewBatchEntry(); + if (pvExe != null && pvExe.exists()) { + File pvHome = pvExe.toPath().getParent().getParent().getParent().getParent().toFile(); String name = pvHome.getName(); if (name.startsWith("ParaView-")) { String version = name.substring("ParaView-".length()); diff --git a/src/eu/engys/core/controller/AbstractController.java b/src/eu/engys/core/controller/AbstractController.java index 9c322da..ef8946d 100644 --- a/src/eu/engys/core/controller/AbstractController.java +++ b/src/eu/engys/core/controller/AbstractController.java @@ -1,32 +1,35 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.controller; +import static javax.swing.JOptionPane.INFORMATION_MESSAGE; +import static javax.swing.JOptionPane.OK_CANCEL_OPTION; +import static javax.swing.JOptionPane.QUESTION_MESSAGE; +import static javax.swing.JOptionPane.YES_NO_CANCEL_OPTION; + import java.io.File; -import java.rmi.RemoteException; import java.util.Set; import javax.swing.Icon; @@ -35,22 +38,28 @@ import javax.swing.JOptionPane; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import eu.engys.core.Arguments; import eu.engys.core.controller.actions.CommandException; import eu.engys.core.controller.actions.DeleteMesh; +import eu.engys.core.executor.ExecutorTerminal; +import eu.engys.core.executor.TerminalManager; import eu.engys.core.modules.ApplicationModule; import eu.engys.core.presentation.Action; import eu.engys.core.presentation.ActionContainer; import eu.engys.core.presentation.ActionManager; import eu.engys.core.project.CaseParameters; -import eu.engys.core.project.InvalidProjectException; +import eu.engys.core.project.CreateCaseDialog; import eu.engys.core.project.Model; import eu.engys.core.project.Project200To210Converter; +import eu.engys.core.project.Project210To240Converter; import eu.engys.core.project.ProjectFolderAnalyzer; +import eu.engys.core.project.ProjectFolderAnalyzer.WhenInDoubt; +import eu.engys.core.project.ProjectFolderStructure; import eu.engys.core.project.ProjectReader; import eu.engys.core.project.ProjectWriter; import eu.engys.core.project.SolverState; import eu.engys.core.project.openFOAMProject; +import eu.engys.core.project.mesh.MeshInfo; +import eu.engys.core.project.mesh.MeshInfoWriter; import eu.engys.core.project.system.monitoringfunctionobjects.ParserView; import eu.engys.core.project.zero.cellzones.CellZonesBuilder; import eu.engys.util.ApplicationInfo; @@ -65,20 +74,42 @@ import eu.engys.util.ui.UiUtil; public abstract class AbstractController implements Controller, ActionContainer { - public static final String STOP_SOLVER = "Stop Solver"; - public static final String KILL_SOLVER = "Kill Solver"; + public static final String SOLVER_RUN = "solver.run"; + public static final String SOLVER_RUN_EDIT = "solver.run.edit"; + + public static final String SOLVER_STOP = "solver.stop"; + public static final String REFRESH_ONCE = "solver.refresh.once"; + public static final String RUN_ALL = "solver.run.all"; + + public static final String INITIALISE_SCRIPT = "initialise.fields"; + public static final String INITIALISE_SCRIPT_EDIT = "initialise.fields.edit"; + + public static final String MESH_CREATE = "mesh.create"; + public static final String MESH_CREATE_EDIT = "mesh.create.edit"; + public static final String MESH_CHECK = "mesh.check"; + public static final String MESH_CHECK_EDIT = "mesh.check.edit"; + public static final String MESH_DELETE = "mesh.delete"; + public static final String MESH_STRETCH = "mesh.stretch"; + public static final String DECOMPOSE = "decompose"; + + public static final String OPEN_RUN_MODE = "application.connection.window"; + public static final String OPEN_PARAMETERS_MANAGER = "application.parameters.manager"; + public static final String SAVE_SCREENSHOT = "save.screenshot"; + + public static final String STOP_SOLVER_LABEL = "Stop Solver"; + public static final String KILL_SOLVER_LABEL = "Kill Solver"; public static final String STOP_EXECUTION = "Stop Execution"; public static final String KILL_PROCESS = "Kill Process"; - - public static final String STOP_FIELDS_INITIALISATION = "Stop Fields Initialisation"; - public static final String STOP_MESH_GENERATOR = "Stop Mesh Generator"; - + public static final String CANCEL = "Cancel"; public static final String CONTINUE_IN_BATCH = "Continue in Batch"; - private static final Icon EXIT_BIG_ICON = ResourcesUtil.getIcon("application.exit.big.icon"); - private static final String EXIT_LABEL = ResourcesUtil.getString("application.exit.label"); + public static final String PARALLEL_WORKS = "application.parallel.works"; + + protected static final Icon EXIT_BIG_ICON = ResourcesUtil.getIcon("application.exit.big.icon"); + protected static final String EXIT_LABEL = ResourcesUtil.getString("application.exit.label"); + private static final Logger logger = LoggerFactory.getLogger(Controller.class); protected final Model model; @@ -90,6 +121,8 @@ public abstract class AbstractController implements Controller, ActionContainer protected ControllerListener listener; protected CellZonesBuilder cellZonesBuilder; + public static boolean isServer = false; + public AbstractController(Model model, Set modules, ProjectReader reader, ProjectWriter writer, CellZonesBuilder cellZonesBuilder, ProgressMonitor monitor, ScriptFactory scriptFactory) { this.cellZonesBuilder = cellZonesBuilder; logger.info("Loading {}", getClass().getSimpleName()); @@ -106,33 +139,61 @@ public abstract class AbstractController implements Controller, ActionContainer */ @Override - public void createCase(CaseParameters params) { - if (params != null) { - newCaseInAThread(params); + public void createCase(CaseParameters params, OpenOptions oo) { + if (params == null) { + params = caseParametersOrNull(); + } + + if (params.getBaseDir() != null) { + newCaseInAThread(params, oo); } } - private void newCaseInAThread(final CaseParameters params) { + private CaseParameters caseParametersOrNull() { + final CaseParameters p = new CaseParameters(); + + ExecUtil.invokeAndWait(new Runnable() { + @Override + public void run() { + final CreateCaseDialog createCaseDialog = new CreateCaseDialog(); + createCaseDialog.showDialog(); + if (createCaseDialog.isOK()) { + ActionManager.getInstance().invoke("application.startup.hide"); + p.setBaseDir(createCaseDialog.getParameters().getBaseDir()); + p.setnHierarchy(createCaseDialog.getParameters().getnHierarchy()); + p.setnProcessors(createCaseDialog.getParameters().getnProcessors()); + p.setParallel(createCaseDialog.getParameters().isParallel()); + } + } + }); + + return p; + } + + private void newCaseInAThread(final CaseParameters params, final OpenOptions oo) { monitor.setTotal(10); monitor.start(String.format("Creating %s", params), false, new Runnable() { @Override public void run() { - create(params); + create(params, oo); PrefUtil.putFile(PrefUtil.WORK_DIR, model.getProject().getBaseDir().getParentFile()); + if (oo != null && oo.getFilesToImport() != null) { + importFiles(oo.getFilesToImport()); + } monitor.end(); } }); } @Override - public void create(final CaseParameters params) { + public void create(final CaseParameters params, final OpenOptions oo) { if (listener != null) { listener.beforeNewCase(); } clearModel(); writer.create(params); if (listener != null) { - listener.afterNewCase(); + listener.afterNewCase(oo != null ? oo.isLoadMesh() : true); } } @@ -141,94 +202,124 @@ public abstract class AbstractController implements Controller, ActionContainer */ @Override - public void openCase(File file) { - if (file == null) { - file = fileToOpenOrNull(); + public void openCase(OpenOptions oo) { + if (oo == null) { + oo = fileToOpenOrNull(); } - if (file != null) { - ActionManager.getInstance().invoke("application.startup.hide"); - openInAThread(file); + if (oo != null && oo.getFile() != null) { + openInAThread(oo); } - Arguments.load3Dgeometry = true; - Arguments.load3Dmesh = true; } - private File fileToOpenOrNull() { - final File[] openFile = new File[1]; - Runnable r = new Runnable() { - @Override - public void run() { - File workDir = PrefUtil.getWorkDir(PrefUtil.WORK_DIR); - HelyxFileChooser fileChooser = new HelyxFileChooser(workDir.getAbsolutePath()); - fileChooser.setTitle("Open"); - fileChooser.setSelectionMode(SelectionMode.DIRS_AND_ARCHIVES); - - View3DOptions options = new View3DOptions(); - ReturnValue returnValue = fileChooser.showOpenDialog(options); - if (returnValue.isApprove()) { - File selectedCase = fileChooser.getSelectedFile(); - if (isSuitable(selectedCase)) { - PrefUtil.putFile(PrefUtil.WORK_DIR, selectedCase.getParentFile()); - Arguments.load3Dgeometry = true; - Arguments.load3Dmesh = options.loadMesh(); - openFile[0] = selectedCase; - return; - } - JOptionPane.showMessageDialog(UiUtil.getActiveWindow(), selectedCase + "\n appears not to be a valid case folder", "File System Error", JOptionPane.ERROR_MESSAGE); - } - openFile[0] = null; - return; - } - }; + private OpenOptions fileToOpenOrNull() { + OpenFile r = new OpenFile(); ExecUtil.invokeAndWait(r); - return openFile[0]; + return r.getOpenOptions(); } - private void openInAThread(final File file) { + class OpenFile implements Runnable { + + private OpenOptions openOptions; + + @Override + public void run() { + File workDir = PrefUtil.getWorkDir(PrefUtil.WORK_DIR); + HelyxFileChooser fileChooser = new HelyxFileChooser(workDir.getAbsolutePath()); + fileChooser.setTitle("Open"); + fileChooser.setSelectionMode(SelectionMode.DIRS_AND_ARCHIVES); + + View3DOptions options = new View3DOptions(); + ReturnValue returnValue = fileChooser.showOpenDialog(options); + if (returnValue.isApprove()) { + File selectedCase = fileChooser.getSelectedFile(); + if (isSuitable(selectedCase)) { + PrefUtil.putFile(PrefUtil.WORK_DIR, selectedCase.getParentFile()); + openOptions = OpenOptions.file(selectedCase, OpenMode.CHECK_FOLDER_ASK_USER).loadMesh(options.loadMesh()); + ActionManager.getInstance().invoke("application.startup.hide"); + return; + } + JOptionPane.showMessageDialog(UiUtil.getActiveWindow(), selectedCase + "\n appears not to be a valid case folder", "File System Error", JOptionPane.ERROR_MESSAGE); + } + return; + } + + public OpenOptions getOpenOptions() { + return openOptions; + } + } + + private void openInAThread(final OpenOptions oo) { monitor.setTotal(10); - monitor.start("Open " + file.getName(), false, new Runnable() { + monitor.start("Open " + oo.getFile().getName(), false, new Runnable() { @Override public void run() { - open(file); + open(oo); monitor.end(); } }); } @Override - public void open(File file) { + public void open(OpenOptions oo) { + File file = oo.getFile(); + OpenMode mode = oo.getMode(); + final File baseDir = file.isAbsolute() ? file : file.getAbsoluteFile(); logger.debug("OPEN file {}", baseDir.getAbsolutePath()); + if (listener != null) { listener.beforeLoadCase(); } clearModel(); - model.setProject(openFOAMProject.createProject(baseDir, monitor)); + switch (mode) { + case SERIAL: + model.setProject(openFOAMProject.newSerialProject(baseDir)); + break; + case PARALLEL: + model.setProject(openFOAMProject.newParallelProject(baseDir)); + break; + case CURRENT_SETTINGS: + case CHECK_FOLDER_ASK_USER: + ProjectFolderStructure structure1 = new ProjectFolderAnalyzer(baseDir, monitor).checkAll(WhenInDoubt.ASK_USER); + model.setProject(structure1.isParallel() ? openFOAMProject.newParallelProject(baseDir, structure1.getProcessors()) : openFOAMProject.newSerialProject(baseDir)); + break; + case CHECK_FOLDER_PARALLEL: + ProjectFolderStructure structure2 = new ProjectFolderAnalyzer(baseDir, monitor).checkAll(WhenInDoubt.READ_PARALLEL); + model.setProject(structure2.isParallel() ? openFOAMProject.newParallelProject(baseDir, structure2.getProcessors()) : openFOAMProject.newSerialProject(baseDir)); + break; + case MESH_ONLY: + break; + default: + break; + } new Project200To210Converter(model.getProject(), cellZonesBuilder).convert(); + new Project210To240Converter(model.getProject()).convert(); - _read(); + reader.read(); if (listener != null) { - listener.afterLoadCase(); + listener.afterLoadCase(oo.isLoadMesh()); } logger.debug("OPEN file {} done.", baseDir.getName()); } + protected abstract void importFiles(final File[] stlFiles); + @Override - public void reopen(OpenOptions options) { + public void reopen(OpenMode mode) { File baseDir = model.getProject().getBaseDir(); int np = model.getProject().getProcessors(); boolean parallel = model.getProject().isParallel(); - logger.debug("REOPEN file {} with option {}", baseDir.getAbsolutePath(), options); + logger.debug("REOPEN file {} in {} mode", baseDir.getAbsolutePath(), mode); if (listener != null) { listener.beforeReopenCase(); } - if (options == OpenOptions.MESH_ONLY) { + if (mode == OpenMode.MESH_ONLY) { reader.readMesh(); if (listener != null) { listener.afterReopenCase(); @@ -237,23 +328,28 @@ public abstract class AbstractController implements Controller, ActionContainer } clearModel(); - switch (options) { - case SERIAL: - model.setProject(openFOAMProject.newSerialProject(baseDir)); - break; - case PARALLEL: - model.setProject(openFOAMProject.newParallelProject(baseDir)); - break; - case CHECK_FOLDER: - model.setProject(openFOAMProject.createProject(baseDir, monitor)); - break; - case CURRENT_SETTINGS: - model.setProject(parallel ? openFOAMProject.newParallelProject(baseDir, np) : openFOAMProject.newSerialProject(baseDir)); - break; - case MESH_ONLY: - break; - default: - break; + switch (mode) { + case SERIAL: + model.setProject(openFOAMProject.newSerialProject(baseDir)); + break; + case PARALLEL: + model.setProject(openFOAMProject.newParallelProject(baseDir)); + break; + case CHECK_FOLDER_ASK_USER: + ProjectFolderStructure structure1 = new ProjectFolderAnalyzer(baseDir, monitor).checkAll(WhenInDoubt.ASK_USER); + model.setProject(structure1.isParallel() ? openFOAMProject.newParallelProject(baseDir, structure1.getProcessors()) : openFOAMProject.newSerialProject(baseDir)); + break; + case CHECK_FOLDER_PARALLEL: + ProjectFolderStructure structure2 = new ProjectFolderAnalyzer(baseDir, monitor).checkAll(WhenInDoubt.READ_PARALLEL); + model.setProject(structure2.isParallel() ? openFOAMProject.newParallelProject(baseDir, structure2.getProcessors()) : openFOAMProject.newSerialProject(baseDir)); + break; + case CURRENT_SETTINGS: + model.setProject(parallel ? openFOAMProject.newParallelProject(baseDir, np) : openFOAMProject.newSerialProject(baseDir)); + break; + case MESH_ONLY: + break; + default: + break; } reader.read(); @@ -264,18 +360,8 @@ public abstract class AbstractController implements Controller, ActionContainer logger.debug("Open file {} done.", baseDir.getName()); } - private void _read() { - try { - reader.read(); - } catch (InvalidProjectException e) { - logger.error(e.getMessage()); - JOptionPane.showMessageDialog(UiUtil.getActiveWindow(), e.getMessage(), "Project error", JOptionPane.ERROR_MESSAGE); - clearModel(); - } - } - @Override - public void reopenCase(final OpenOptions options) { + public void reopenCase(final OpenMode options) { monitor.start("Reopen " + model.getProject().getBaseDir(), false, new Runnable() { @Override public void run() { @@ -299,7 +385,7 @@ public abstract class AbstractController implements Controller, ActionContainer } } - protected void saveInAThread(final File baseDir) { + private void saveInAThread(final File baseDir) { monitor.info(""); monitor.start("Save: " + baseDir.getAbsolutePath(), false, new Runnable() { @Override @@ -308,6 +394,9 @@ public abstract class AbstractController implements Controller, ActionContainer monitor.end(); } }); + if (ActionManager.getInstance().contains(SAVE_SCREENSHOT)) { + ActionManager.getInstance().get(SAVE_SCREENSHOT).actionPerformed(null); + } } @Override @@ -316,8 +405,9 @@ public abstract class AbstractController implements Controller, ActionContainer baseDir = model.getProject().getBaseDir(); } logger.debug("Save file {}", baseDir.getAbsolutePath()); - if (listener != null) + if (listener != null) { listener.beforeSaveCase(); + } writer.write(baseDir); writeScripts(); if (listener != null) { @@ -368,13 +458,16 @@ public abstract class AbstractController implements Controller, ActionContainer * MESH */ - @Action(key = "mesh.delete") + @Action(key = MESH_DELETE) public void deleteMesh() { int retVal = JOptionPane.showConfirmDialog(UiUtil.getActiveWindow(), "This action will delete the existing mesh.\nContinue?", "Delete Mesh", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE); if (retVal == JOptionPane.YES_OPTION) { saveInAThread(model.getProject().getBaseDir()); new DeleteMesh(model, this).executeClient(); - reopenCase(OpenOptions.CURRENT_SETTINGS); + model.getMesh().setMeshInfo(new MeshInfo()); + new MeshInfoWriter(model).write(); + model.getProject().getSystemFolder().writeProjectDict(null); + reopenCase(OpenMode.CURRENT_SETTINGS); } } @@ -393,10 +486,11 @@ public abstract class AbstractController implements Controller, ActionContainer */ @Override - public void createReport() { + public void createReport(ExecutorTerminal terminal) { } - protected void clearModel() { + @Override + public void clearModel() { logger.info("--- CLEAR MODEL ---"); model.init(); model.setProject(null); @@ -418,31 +512,24 @@ public abstract class AbstractController implements Controller, ActionContainer } @Override - public boolean allowActionsOnRunning(boolean exit) { - if (model != null && model.getSolverModel() != null) { + public boolean allowActionsOnRunning(boolean shouldAskConfirmation) { + String exitMessage = EXIT_LABEL + " " + ApplicationInfo.getName() + "?"; + + boolean thereIsACaseLoaded = model != null && model.getSolverModel() != null; + if (thereIsACaseLoaded) { SolverState solverState = model.getSolverModel().getServerState().getSolverState(); - if (solverState.isMeshing()) { - return handleExitOnMeshRunning(); - } else if (solverState.isInitialising()) { - return handleExitOnFieldsInitialising(); - } else if (solverState.isRunning()) { - return handleExitOnSolverRunning(); - } else if (exit) { - int option = JOptionPane.showConfirmDialog(UiUtil.getActiveWindow(), EXIT_LABEL + " " + ApplicationInfo.getName() + "?", EXIT_LABEL, JOptionPane.OK_CANCEL_OPTION, JOptionPane.INFORMATION_MESSAGE, EXIT_BIG_ICON); - if (option == JOptionPane.CANCEL_OPTION) { - return false; - } else { - if (getClient() != null && getClient().getServer() != null) { - shutdownServer(); + if (solverState.isDoingSomething()) { + return handleExitOnRunning(); + } else {// server not running + if (shouldAskConfirmation) { + int option = JOptionPane.showConfirmDialog(UiUtil.getActiveWindow(), exitMessage, EXIT_LABEL, OK_CANCEL_OPTION, INFORMATION_MESSAGE, EXIT_BIG_ICON); + if (option == JOptionPane.CANCEL_OPTION) { + return false; } - return true; } - } else if (getClient() != null && getClient().getServer() != null) { - shutdownServer(); - return true; } - } else if (exit) {// If no case has been loaded yet - int option = JOptionPane.showConfirmDialog(UiUtil.getActiveWindow(), EXIT_LABEL + " " + ApplicationInfo.getName() + "?", EXIT_LABEL, JOptionPane.OK_CANCEL_OPTION, JOptionPane.INFORMATION_MESSAGE, EXIT_BIG_ICON); + } else if (shouldAskConfirmation) { + int option = JOptionPane.showConfirmDialog(UiUtil.getActiveWindow(), exitMessage, EXIT_LABEL, OK_CANCEL_OPTION, INFORMATION_MESSAGE, EXIT_BIG_ICON); if (option == JOptionPane.CANCEL_OPTION) { return false; } @@ -450,52 +537,15 @@ public abstract class AbstractController implements Controller, ActionContainer return true; } - private void shutdownServer() { - try { - getClient().getServer().shutdown(); - } catch (RemoteException e) { - logger.error("Error shutting down server: {}" + e.getMessage()); - } catch (Exception e) { - logger.error("Error shutting down server: {}" + e.getMessage()); - } - } + protected boolean handleExitOnRunning() { + Object[] options = new Object[] { KILL_PROCESS, CONTINUE_IN_BATCH, CANCEL }; + String message = ApplicationInfo.getName() + " is running. Select an action to perform."; + String title = ApplicationInfo.getName(); - protected boolean handleExitOnMeshRunning() { - Object[] options = new Object[] { STOP_MESH_GENERATOR, CONTINUE_IN_BATCH, CANCEL }; - int option = JOptionPane.showOptionDialog(UiUtil.getActiveWindow(), "Mesh Generator is Running. Select an action to perform.", "Mesh Generator Running", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]); + int option = JOptionPane.showOptionDialog(UiUtil.getActiveWindow(), message, title, YES_NO_CANCEL_OPTION, QUESTION_MESSAGE, null, options, options[0]); if (getClient() != null && option == JOptionPane.YES_OPTION) { - kill(); - return true; - } else if (getClient() != null && option == JOptionPane.NO_OPTION) { - getClient().goToBatch(); - return true; - } else { - return false; - } - } - - protected boolean handleExitOnFieldsInitialising() { - Object[] options = new Object[] { STOP_FIELDS_INITIALISATION, CONTINUE_IN_BATCH, CANCEL }; - int option = JOptionPane.showOptionDialog(UiUtil.getActiveWindow(), "Fields Initialisation is Running. Select an action to perform.", "Fields Initialisation Running", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]); - - if (getClient() != null && option == JOptionPane.YES_OPTION) { - kill(); - return true; - } else if (getClient() != null && option == JOptionPane.NO_OPTION) { - getClient().goToBatch(); - return true; - } else { - return false; - } - } - - protected boolean handleExitOnSolverRunning() { - Object[] options = new Object[] { STOP_SOLVER, CONTINUE_IN_BATCH, CANCEL }; - int option = JOptionPane.showOptionDialog(UiUtil.getActiveWindow(), "Solver is Running. Select an action to perform.", "Solver Running", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]); - - if (getClient() != null && option == JOptionPane.YES_OPTION) { - getClient().stopCommand(Command.ANY); + getClient().killCommand(Command.ANY); return true; } else if (getClient() != null && option == JOptionPane.NO_OPTION) { getClient().goToBatch(); @@ -533,6 +583,11 @@ public abstract class AbstractController implements Controller, ActionContainer return null; } + @Override + public TerminalManager getTerminalManager() { + return null; + } + @Override public ParserView getResidualView() { return null; diff --git a/src/eu/engys/core/controller/AbstractScriptFactory.java b/src/eu/engys/core/controller/AbstractScriptFactory.java index f38e7c3..19557c5 100644 --- a/src/eu/engys/core/controller/AbstractScriptFactory.java +++ b/src/eu/engys/core/controller/AbstractScriptFactory.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.controller; import java.io.File; @@ -35,10 +34,12 @@ import eu.engys.util.Util; public abstract class AbstractScriptFactory implements ScriptFactory { protected static final String RUN_MESH = "Run Mesh"; - public static final String MESH_SERIAL_RUN = "mesh_serial.run"; - public static final String MESH_SERIAL_BAT = "mesh_serial.bat"; - public static final String MESH_PARALLEL_RUN = "mesh_parallel.run"; - public static final String MESH_PARALLEL_BAT = "mesh_parallel.bat"; + public static final String MESH_SERIAL = "mesh_serial"; + public static final String MESH_SERIAL_RUN = MESH_SERIAL + ".run"; + public static final String MESH_SERIAL_BAT = MESH_SERIAL + ".bat"; + public static final String MESH_PARALLEL = "mesh_parallel"; + public static final String MESH_PARALLEL_RUN = MESH_PARALLEL + ".run"; + public static final String MESH_PARALLEL_BAT = MESH_PARALLEL + ".bat"; protected static final String CHECK_MESH = "Check Mesh"; public static final String CHECK_MESH_SERIAL_RUN = "check_mesh_serial.run"; @@ -46,15 +47,25 @@ public abstract class AbstractScriptFactory implements ScriptFactory { public static final String CHECK_MESH_PARALLEL_RUN = "check_mesh_parallel.run"; public static final String CHECK_MESH_PARALLEL_BAT = "check_mesh_parallel.bat"; + protected static final String SNAPPY_CHECK_MESH = "Snappy Check Mesh"; + public static final String SNAPPY_CHECK_MESH_SERIAL_RUN = "snappy_check_mesh_serial.run"; + public static final String SNAPPY_CHECK_MESH_SERIAL_BAT = "snappy_check_mesh_serial.bat"; + public static final String SNAPPY_CHECK_MESH_PARALLEL_RUN = "snappy_check_mesh_parallel.run"; + public static final String SNAPPY_CHECK_MESH_PARALLEL_BAT = "snappy_check_mesh_parallel.bat"; + protected static final String RUN_CASE = "Run Case"; + public static final String SOLVER_SERIAL = "solver_serial"; public static final String SOLVER_SERIAL_RUN = "solver_serial.run"; public static final String SOLVER_SERIAL_BAT = "solver_serial.bat"; + public static final String SOLVER_PARALLEL = "solver_parallel"; public static final String SOLVER_PARALLEL_RUN = "solver_parallel.run"; public static final String SOLVER_PARALLEL_BAT = "solver_parallel.bat"; protected static final String INITIALISE_FIELDS = "Initialise Fields"; + public static final String INITIALISE_FIELDS_SERIAL = "initialiseFields_serial"; public static final String INITIALISE_FIELDS_SERIAL_RUN = "initialiseFields_serial.run"; public static final String INITIALISE_FIELDS_SERIAL_BAT = "initialiseFields_serial.bat"; + public static final String INITIALISE_FIELDS_PARALLEL = "initialiseFields_parallel"; public static final String INITIALISE_FIELDS_PARALLEL_RUN = "initialiseFields_parallel.run"; public static final String INITIALISE_FIELDS_PARALLEL_BAT = "initialiseFields_parallel.bat"; @@ -64,6 +75,12 @@ public abstract class AbstractScriptFactory implements ScriptFactory { private static final String EXTRUDEMESH_PARALLEL_RUN = "extrudeMesh_parallel.run"; private static final String EXTRUDEMESH_PARALLEL_BAT = "extrudeMesh_parallel.bat"; + protected static final String EXPORT = "Export Results"; + private static final String EXPORT_SERIAL_RUN = "exportResults_serial.run"; + private static final String EXPORT_SERIAL_BAT = "exportResults_serial.bat"; + private static final String EXPORT_PARALLEL_RUN = "exportResults_parallel.run"; + private static final String EXPORT_PARALLEL_BAT = "exportResults_parallel.bat"; + /* * MESH */ @@ -102,14 +119,14 @@ public abstract class AbstractScriptFactory implements ScriptFactory { return script; } - private File getMeshParallelScript(Model model) { + protected File getMeshParallelScript(Model model) { File file = new File(model.getProject().getBaseDir(), Util.isWindowsScriptStyle() ? MESH_PARALLEL_BAT : MESH_PARALLEL_RUN); writeFileIfNeeded(file, getParallelMeshScript()); file.setExecutable(true); return file; } - private File getMeshSerialScript(Model model) { + protected File getMeshSerialScript(Model model) { File file = new File(model.getProject().getBaseDir(), Util.isWindowsScriptStyle() ? MESH_SERIAL_BAT : MESH_SERIAL_RUN); writeFileIfNeeded(file, getSerialMeshScript()); file.setExecutable(true); @@ -136,9 +153,9 @@ public abstract class AbstractScriptFactory implements ScriptFactory { public List getDefaultCheckMeshScript(Model model) { List script = null; if (model.getProject().isParallel()) { - script = getParallelMeshScript(); + script = getParallelCheckMeshScript(); } else { - script = getSerialMeshScript(); + script = getSerialCheckMeshScript(); } return script; } @@ -161,6 +178,47 @@ public abstract class AbstractScriptFactory implements ScriptFactory { protected abstract List getSerialCheckMeshScript(); + @Override + public File getSnappyCheckMeshScript(Model model) { + File parallelScript = getSnappyCheckMeshParallelScript(model); + File serialScript = getSnappyCheckMeshSerialScript(model); + + if (model.getProject().isParallel()) { + return parallelScript; + } else { + return serialScript; + } + } + + @Override + public List getDefaultSnappyCheckMeshScript(Model model) { + List script = null; + if (model.getProject().isParallel()) { + script = getParallelSnappyCheckMeshScript(); + } else { + script = getSerialSnappyCheckMeshScript(); + } + return script; + } + + private File getSnappyCheckMeshParallelScript(Model model) { + File file = new File(model.getProject().getBaseDir(), Util.isWindowsScriptStyle() ? CHECK_MESH_PARALLEL_BAT : CHECK_MESH_PARALLEL_RUN); + writeFileIfNeeded(file, getParallelSnappyCheckMeshScript()); + file.setExecutable(true); + return file; + } + + private File getSnappyCheckMeshSerialScript(Model model) { + File file = new File(model.getProject().getBaseDir(), Util.isWindowsScriptStyle() ? CHECK_MESH_SERIAL_BAT : CHECK_MESH_SERIAL_RUN); + writeFileIfNeeded(file, getSerialSnappyCheckMeshScript()); + file.setExecutable(true); + return file; + } + + protected abstract List getParallelSnappyCheckMeshScript(); + + protected abstract List getSerialSnappyCheckMeshScript(); + /* * SOLVER */ @@ -315,18 +373,57 @@ public abstract class AbstractScriptFactory implements ScriptFactory { protected abstract List getLinuxSetupCaseScript(); @Override - public File getExportScript(Model model) { + public File getReportScript(Model model) { File file = new File(model.getProject().getBaseDir(), "export.py"); - writeFileIfNeeded(file, getExportScript()); + writeFileIfNeeded(file, getReportScript()); return file; } @Override - public List getDefaultExportScript(Model model) { - return getExportScript(); + public List getDefaultReportScript(Model model) { + return getReportScript(); } - protected abstract List getExportScript(); + public abstract List getReportScript(); + + @Override + public File getExportScript(Model model) { + File parallelScript = getExportParallelScript(model); + File serialScript = getExporteSerialScript(model); + + if (model.getProject().isParallel()) { + return parallelScript; + } else { + return serialScript; + } + } + + @Override + public List getDefaultExportScript(Model model) { + List script = null; + if (model.getProject().isParallel()) { + script = getParallelExportScript(); + } else { + script = getSerialExportScript(); + } + return script; + } + + protected File getExportParallelScript(Model model) { + File file = new File(model.getProject().getBaseDir(), Util.isWindowsScriptStyle() ? EXPORT_PARALLEL_BAT : EXPORT_PARALLEL_RUN); + writeFileIfNeeded(file, getParallelExportScript()); + return file; + } + + protected File getExporteSerialScript(Model model) { + File file = new File(model.getProject().getBaseDir(), Util.isWindowsScriptStyle() ? EXPORT_SERIAL_BAT : EXPORT_SERIAL_RUN); + writeFileIfNeeded(file, getSerialExportScript()); + return file; + } + + protected abstract List getParallelExportScript(); + + protected abstract List getSerialExportScript(); protected void writeFileIfNeeded(File file, List script) { if (!file.exists()) { diff --git a/src/eu/engys/core/controller/ApplicationActions.java b/src/eu/engys/core/controller/ApplicationActions.java index 6c5f5ef..cab0777 100644 --- a/src/eu/engys/core/controller/ApplicationActions.java +++ b/src/eu/engys/core/controller/ApplicationActions.java @@ -1,43 +1,42 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.controller; import java.io.File; -import eu.engys.core.controller.Controller.OpenOptions; +import eu.engys.core.controller.Controller.OpenMode; import eu.engys.core.project.CaseParameters; public interface ApplicationActions { - void createCase(CaseParameters params); + void createCase(CaseParameters params, OpenOptions oo); - void openCase(File file); + void openCase(OpenOptions oo); - void reopenCase(OpenOptions options); + void reopenCase(OpenMode mode); void saveCase(File file); diff --git a/src/eu/engys/core/controller/BatchActions.java b/src/eu/engys/core/controller/BatchActions.java index 1dccc86..fc4c164 100644 --- a/src/eu/engys/core/controller/BatchActions.java +++ b/src/eu/engys/core/controller/BatchActions.java @@ -1,46 +1,48 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.controller; import java.io.File; -import eu.engys.core.controller.Controller.OpenOptions; -import eu.engys.core.controller.actions.TimeoutException; +import eu.engys.core.controller.Controller.OpenMode; import eu.engys.core.project.CaseParameters; public interface BatchActions { - void create(CaseParameters params); - void open(File file); - void reopen(OpenOptions options); - void save(File file); + void create(CaseParameters params, OpenOptions oo); + + void open(OpenOptions oo); + + void reopen(OpenMode options); + + void save(File file); void setupCase(); - void stopCase() throws TimeoutException; + + void stopCase() throws Exception; + void kill(); - + } diff --git a/src/eu/engys/core/controller/Client.java b/src/eu/engys/core/controller/Client.java index a5aa530..499e7c1 100644 --- a/src/eu/engys/core/controller/Client.java +++ b/src/eu/engys/core/controller/Client.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.controller; import javax.swing.JComponent; @@ -35,12 +34,10 @@ public interface Client { void executeCommands(Command... command); - ParserView getResidualView(); + ParserView getResidualsView(); void refreshOnce(); - void loadState(); - void stopCommand(Command command); void killCommand(Command command); @@ -59,4 +56,6 @@ public interface Client { void waitForFinished(); + void justConnect(); + } diff --git a/src/eu/engys/core/controller/ClientInfo.java b/src/eu/engys/core/controller/ClientInfo.java index 719c8b3..983b9a5 100644 --- a/src/eu/engys/core/controller/ClientInfo.java +++ b/src/eu/engys/core/controller/ClientInfo.java @@ -1,50 +1,56 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.controller; import java.io.Serializable; +import eu.engys.util.Util; + public class ClientInfo implements Serializable { + private String clientID; private boolean connected; - private ClientInfo(boolean connected) { + private ClientInfo(String clientID, boolean connected) { + this.clientID = clientID; this.connected = connected; } public boolean isConnected() { return connected; } + public String getClientID() { + return clientID; + } public static ClientInfo clientConnected() { - return new ClientInfo(true); + return new ClientInfo(Util.generateID(), true); } - public static ClientInfo clientDisconnected() { - return new ClientInfo(false); + public static ClientInfo clientDisconnected(String clientID) { + return new ClientInfo(clientID, false); } -} +} \ No newline at end of file diff --git a/src/eu/engys/core/controller/ClientServerCommand.java b/src/eu/engys/core/controller/ClientServerCommand.java index 4ecee38..096d298 100644 --- a/src/eu/engys/core/controller/ClientServerCommand.java +++ b/src/eu/engys/core/controller/ClientServerCommand.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.controller; import java.io.Serializable; @@ -41,13 +40,6 @@ public class ClientServerCommand implements Serializable { this.parallel = false; this.startParsers = false; } - - public ClientServerCommand(Command command, String open, boolean parallel, boolean startParsers) { - this.commands = new Command[]{command}; - this.open = open; - this.parallel = parallel; - this.startParsers = startParsers; - } public Command getCommand() { return commands[0]; diff --git a/src/eu/engys/core/controller/Command.java b/src/eu/engys/core/controller/Command.java index fbbc050..e8938f1 100644 --- a/src/eu/engys/core/controller/Command.java +++ b/src/eu/engys/core/controller/Command.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.controller; public enum Command { @@ -32,6 +31,7 @@ public enum Command { INITIALISE_FIELDS("", ""), RUN_ALL("", ""), EXTRUDE_TO_REGION("", ""), + EXPORT_RESULTS("", ""), ANY("any", "Any"), NONE("none", "None"); diff --git a/src/eu/engys/core/controller/CommandInfo.java b/src/eu/engys/core/controller/CommandInfo.java index 81afbf7..22aaca6 100644 --- a/src/eu/engys/core/controller/CommandInfo.java +++ b/src/eu/engys/core/controller/CommandInfo.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.controller; import java.io.Serializable; @@ -66,6 +65,15 @@ public class CommandInfo implements Serializable { ci.success = false; return ci; } + + public static CommandInfo error(String message, Exception e) { + logger.warn(">>> SERVER WARNING: {}", message); + CommandInfo ci = new CommandInfo(); + ci.message = message; + ci.exception = e; + ci.success = false; + return ci; + } public static CommandInfo notConnected() { CommandInfo ci = new CommandInfo(); @@ -88,4 +96,9 @@ public class CommandInfo implements Serializable { return ci; } -} + @Override + public String toString() { + return "CommandInfo - msg: " + message + ", job ID: " + jobID + ", succes: " + success + ", exception: " + exception; + } + +} \ No newline at end of file diff --git a/src/eu/engys/core/controller/Controller.java b/src/eu/engys/core/controller/Controller.java index a8aedc9..3c6c9b7 100644 --- a/src/eu/engys/core/controller/Controller.java +++ b/src/eu/engys/core/controller/Controller.java @@ -1,32 +1,33 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.controller; import eu.engys.core.controller.actions.CommandException; +import eu.engys.core.executor.ExecutorTerminal; +import eu.engys.core.executor.TerminalManager; +import eu.engys.core.parameters.Parameters; import eu.engys.core.project.ProjectReader; import eu.engys.core.project.ProjectWriter; import eu.engys.core.project.system.monitoringfunctionobjects.ParserView; @@ -37,8 +38,8 @@ public interface Controller extends ApplicationActions, BatchActions { EXIT, CONTINUE, NONE } - public enum OpenOptions { - SERIAL, PARALLEL, CURRENT_SETTINGS, CHECK_FOLDER, MESH_ONLY + public enum OpenMode { + SERIAL, PARALLEL, CURRENT_SETTINGS, CHECK_FOLDER_ASK_USER, CHECK_FOLDER_PARALLEL, MESH_ONLY } boolean isDemo(); @@ -53,9 +54,9 @@ public interface Controller extends ApplicationActions, BatchActions { public Server getServer(); public ParserView getResidualView(); - boolean allowActionsOnRunning(boolean exit); + boolean allowActionsOnRunning(boolean shouldAskConfirmation); - void createReport(); + void createReport(ExecutorTerminal terminal); void executeCommand(Command command) throws CommandException; @@ -65,4 +66,10 @@ public interface Controller extends ApplicationActions, BatchActions { boolean isRunningCommand(); + void applyParameters(Parameters parameters); + + TerminalManager getTerminalManager(); + + void clearModel(); + } diff --git a/src/eu/engys/core/controller/ControllerListener.java b/src/eu/engys/core/controller/ControllerListener.java index 6225c74..5ab1cc4 100644 --- a/src/eu/engys/core/controller/ControllerListener.java +++ b/src/eu/engys/core/controller/ControllerListener.java @@ -1,39 +1,36 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.controller; - public interface ControllerListener { void beforeNewCase(); - void afterNewCase(); + void afterNewCase(boolean loadMesh); void beforeLoadCase(); - void afterLoadCase(); + void afterLoadCase(boolean loadMesh); void beforeReopenCase(); void afterReopenCase(); @@ -57,4 +54,5 @@ public interface ControllerListener { void afterBlockMesh(); + void afterSetupCase(); } diff --git a/src/eu/engys/core/controller/DefaultNamingConvention.java b/src/eu/engys/core/controller/DefaultNamingConvention.java index b8a8bdd..8b34ea3 100644 --- a/src/eu/engys/core/controller/DefaultNamingConvention.java +++ b/src/eu/engys/core/controller/DefaultNamingConvention.java @@ -1,41 +1,46 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.controller; import eu.engys.core.controller.actions.NamingConvention; import eu.engys.core.project.geometry.Surface; public class DefaultNamingConvention implements NamingConvention { - @Override - public String getCellZoneName(Surface surface) { - return surface.getZoneName(); - } @Override public String getPatchName(Surface surface) { return surface.getPatchName(); } -} + + @Override + public String getCellZoneName(Surface surface) { + return surface.getCellZoneName(); + } + + @Override + public String getFaceZoneName(Surface surface) { + return surface.getFaceZoneName(); + } +} \ No newline at end of file diff --git a/src/eu/engys/core/controller/DefaultScriptFactory.java b/src/eu/engys/core/controller/DefaultScriptFactory.java index 03fb1d2..d4aa62a 100644 --- a/src/eu/engys/core/controller/DefaultScriptFactory.java +++ b/src/eu/engys/core/controller/DefaultScriptFactory.java @@ -1,35 +1,37 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.controller; import static eu.engys.core.OpenFOAMEnvironment.loadEnvironment; import static eu.engys.core.OpenFOAMEnvironment.printHeader; import static eu.engys.core.OpenFOAMEnvironment.printVariables; import static eu.engys.util.OpenFOAMCommands.BLOCK_MESH; +import static eu.engys.util.OpenFOAMCommands.CHECK_MESH_PARALLEL; +import static eu.engys.util.OpenFOAMCommands.CHECK_MESH_PARALLEL_CONSTANT; +import static eu.engys.util.OpenFOAMCommands.CHECK_MESH_SERIAL; +import static eu.engys.util.OpenFOAMCommands.CHECK_MESH_SERIAL_CONSTANT; import static eu.engys.util.OpenFOAMCommands.DECOMPOSE_PAR; import static eu.engys.util.OpenFOAMCommands.DECOMPOSE_PAR_ALLREGIONS; import static eu.engys.util.OpenFOAMCommands.DECOMPOSE_PAR_CONSTANT_ALLREGIONS; @@ -42,8 +44,6 @@ import static eu.engys.util.OpenFOAMCommands.RUN_CASE_PARALLEL; import static eu.engys.util.OpenFOAMCommands.RUN_CASE_SERIAL; import static eu.engys.util.OpenFOAMCommands.RUN_MESH_PARALLEL; import static eu.engys.util.OpenFOAMCommands.RUN_MESH_SERIAL; -//import static eu.engys.util.OpenFOAMCommands.CHECK_MESH_PARALLEL; -//import static eu.engys.util.OpenFOAMCommands.CHECK_MESH_SERIAL; import static eu.engys.util.OpenFOAMCommands.SNAPPY_CHECK_MESH_PARALLEL; import static eu.engys.util.OpenFOAMCommands.SNAPPY_CHECK_MESH_SERIAL; @@ -102,7 +102,7 @@ public class DefaultScriptFactory extends AbstractScriptFactory { sb.newLine(); sb.appendIf(performBlockMesh(), BLOCK_MESH()); sb.newLine(); - sb.appendIf(performBlockMesh(), DECOMPOSE_PAR()); + sb.appendIf(performBlockMesh(), DECOMPOSE_PAR(Collections. emptySet())); sb.newLine(); sb.append(RUN_MESH_PARALLEL()); sb.newLine(); @@ -118,7 +118,7 @@ public class DefaultScriptFactory extends AbstractScriptFactory { printVariables(sb); loadEnvironment(sb); sb.newLine(); - sb.append(SNAPPY_CHECK_MESH_SERIAL()); + sb.append(meshOnZero() ? CHECK_MESH_SERIAL() : CHECK_MESH_SERIAL_CONSTANT()); sb.newLine(); return sb.getLines(); } @@ -130,6 +130,30 @@ public class DefaultScriptFactory extends AbstractScriptFactory { printVariables(sb); loadEnvironment(sb); sb.newLine(); + sb.append(meshOnZero() ? CHECK_MESH_PARALLEL() : CHECK_MESH_PARALLEL_CONSTANT()); + sb.newLine(); + return sb.getLines(); + } + + @Override + protected List getSerialSnappyCheckMeshScript() { + ScriptBuilder sb = new ScriptBuilder(); + printHeader(sb, SNAPPY_CHECK_MESH); + printVariables(sb); + loadEnvironment(sb); + sb.newLine(); + sb.append(SNAPPY_CHECK_MESH_SERIAL()); + sb.newLine(); + return sb.getLines(); + } + + @Override + protected List getParallelSnappyCheckMeshScript() { + ScriptBuilder sb = new ScriptBuilder(); + printHeader(sb, SNAPPY_CHECK_MESH); + printVariables(sb); + loadEnvironment(sb); + sb.newLine(); sb.append(SNAPPY_CHECK_MESH_PARALLEL()); sb.newLine(); return sb.getLines(); @@ -216,7 +240,7 @@ public class DefaultScriptFactory extends AbstractScriptFactory { sb.newLine(); sb.appendIf(meshOnZero(), RECONSTRUCT_PAR_MESH(), RECONSTRUCT_PAR_MESH_CONSTANT()); sb.append(EXTRUDE_REGION_TO_MESH()); - sb.appendIf(meshOnZero(), DECOMPOSE_PAR_ALLREGIONS(), DECOMPOSE_PAR_CONSTANT_ALLREGIONS()); + sb.appendIf(meshOnZero(), DECOMPOSE_PAR_ALLREGIONS(Collections. emptySet()), DECOMPOSE_PAR_CONSTANT_ALLREGIONS(Collections. emptySet())); sb.newLine(); return sb.getLines(); } @@ -263,13 +287,13 @@ public class DefaultScriptFactory extends AbstractScriptFactory { boolean copy = false; for (String l : lines) { - if(l.startsWith(end)){ + if (l.startsWith(end)) { break; } - if(copy){ + if (copy) { support.add(l); } - if(l.startsWith(start)){ + if (l.startsWith(start)) { copy = true; } } @@ -280,17 +304,13 @@ public class DefaultScriptFactory extends AbstractScriptFactory { InputStream inputStream = DefaultScriptFactory.class.getClassLoader().getResourceAsStream("eu/engys/resources/driver.pbs"); try { String body = IOUtils.readStringFromStream(inputStream); - return Arrays.asList(body.split(IOUtils.EOL)); + return Arrays.asList(body.split(IOUtils.LNX_EOL)); } catch (IOException e) { e.printStackTrace(); return Collections.emptyList(); } } - private List getWindowsQueueDriver() { - throw new RuntimeException("NOT IMPLEMENTED"); - } - private List getLinuxQueueDriver(List body) { String name = model.getProject().getBaseDir().getName(); @@ -366,7 +386,17 @@ public class DefaultScriptFactory extends AbstractScriptFactory { } @Override - protected List getExportScript() { + protected List getSerialExportScript() { + throw new RuntimeException("NOT IMPLEMENTED"); + } + + @Override + protected List getParallelExportScript() { + throw new RuntimeException("NOT IMPLEMENTED"); + } + + @Override + public List getReportScript() { throw new RuntimeException("NOT IMPLEMENTED"); } @@ -380,7 +410,7 @@ public class DefaultScriptFactory extends AbstractScriptFactory { e.printStackTrace(); } - return Arrays.asList(driverString.split(IOUtils.EOL)); + return Arrays.asList(driverString.split(IOUtils.LNX_EOL)); } @Override diff --git a/src/eu/engys/core/controller/GeometryToMesh.java b/src/eu/engys/core/controller/GeometryToMesh.java index be0d799..014c2a6 100644 --- a/src/eu/engys/core/controller/GeometryToMesh.java +++ b/src/eu/engys/core/controller/GeometryToMesh.java @@ -1,35 +1,36 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.controller; import static eu.engys.core.project.system.SnappyHexMeshDict.BAFFLE_KEY; import static eu.engys.core.project.system.SnappyHexMeshDict.BOUNDARY_KEY; +import static eu.engys.core.project.system.SnappyHexMeshDict.CELL_ZONE_KEY; import static eu.engys.core.project.system.SnappyHexMeshDict.FACE_TYPE_KEY; import static eu.engys.core.project.system.SnappyHexMeshDict.FACE_ZONE_KEY; import static eu.engys.core.project.system.SnappyHexMeshDict.INSIDE; +import static eu.engys.core.project.system.SnappyHexMeshDict.IS_CELL_ZONE_KEY; import static eu.engys.core.project.system.SnappyHexMeshDict.LEVELS_KEY; import static eu.engys.core.project.system.SnappyHexMeshDict.MODE_KEY; import static eu.engys.core.project.system.SnappyHexMeshDict.NONE_KEY; @@ -48,20 +49,25 @@ import eu.engys.core.project.geometry.Surface; import eu.engys.core.project.geometry.surface.Region; import eu.engys.core.project.geometry.surface.Solid; import eu.engys.core.project.zero.cellzones.CellZone; +import eu.engys.core.project.zero.facezones.FaceZone; import eu.engys.core.project.zero.patches.BoundaryConditions; import eu.engys.core.project.zero.patches.BoundaryType; import eu.engys.core.project.zero.patches.Patch; public class GeometryToMesh { + public static final String SLAVE_SUFFIX = "_slave"; + private static final Logger logger = LoggerFactory.getLogger(GeometryToMesh.class); private Model model; private List patches = new ArrayList<>(); private List cellZones = new ArrayList<>(); + private List faceZones = new ArrayList<>(); private List willBePatches = new ArrayList<>(); private List willBeCellZones = new ArrayList<>(); + private List willBeFaceZones = new ArrayList<>(); private NamingConvention naming; @@ -84,26 +90,27 @@ public class GeometryToMesh { public void execute() { model.getPatches().clear(); model.getCellZones().clear(); + model.getFaceZones().clear(); extractPatchesFromGeometry(); model.getPatches().addPatches(patches); model.getCellZones().addZones(cellZones); - } - - public List getWillBePatches() { - return willBePatches; - } - - public List getWillBeCellZones() { - return willBeCellZones; + model.getFaceZones().addZones(faceZones); } private void extractPatchesFromGeometry() { for (Surface surface : model.getGeometry().getSurfaces()) { logger.debug("Surface {}: {} {} {}", surface.getName(), surface.getSurfaceDictionary(), surface.getVolumeDictionary(), surface.getZoneDictionary()); + surfaceToPatch(surface); surfaceToCellZone(surface); + surfaceToFaceZone(surface); + if (willCreatePatches(surface)) { + zoneToPatches(surface); + } else { + logger.debug("'{}' does NOT become a PATCH+SLAVE", surface.getName()); + } } if (model.getGeometry().hasBlock()) { @@ -111,25 +118,49 @@ public class GeometryToMesh { } } + private void surfaceToPatch(Surface surface) { + if (surface.isSingleton()) { + addPatch(surface); + } else if (surface.hasRegions()) { + for (Region region : surface.getRegions()) { + addPatch(region); + } + } else { + addPatch(surface); + } + } + private void surfaceToCellZone(Surface surface) { if (willBeACellZone(surface)) { - if (willCreatePatches(surface)) { - zoneToPatches(surface); - } else { - logger.debug("'{}' does NOT become a PATCH+SLAVE", surface.getName()); - } String zoneName = naming.getCellZoneName(surface); CellZone zone = new CellZone(zoneName); zone.setName(zoneName); zone.setVisible(true); zone.setLoaded(true); - logger.debug("'{}' becomes a ZONE with name {}", surface.getName(), zoneName); + logger.debug("'{}' becomes a CELLZONE with name {}", surface.getName(), zoneName); cellZones.add(zone); willBeCellZones.add(surface); } else { - logger.debug("'{}' does NOT become a ZONE", surface.getName()); + logger.debug("'{}' does NOT become a CELLZONE", surface.getName()); + } + } + + private void surfaceToFaceZone(Surface surface) { + if (willBeAFaceZone(surface)) { + String zoneName = naming.getFaceZoneName(surface); + FaceZone zone = new FaceZone(zoneName); + zone.setName(zoneName); + zone.setVisible(true); + zone.setLoaded(true); + + logger.debug("'{}' becomes a FACEZONE with name {}", surface.getName(), zoneName); + + faceZones.add(zone); + willBeFaceZones.add(surface); + } else { + logger.debug("'{}' does NOT become a FACEZONE", surface.getName()); } } @@ -148,15 +179,48 @@ public class GeometryToMesh { addPatchAndSlave(surface); } } + + private boolean willBeAPatch(Surface surface) { + boolean typePlane = surface.getType().isPlane(); + boolean singletonSTLRefinementOnly = surface.getType().isStl() && surface.isSingleton() && isSurfaceRefinementOnly(surface); + boolean typeSolidAndParentOK = surface.getType().isSolid() && willBeAPatch(((Solid) surface).getParent()); + boolean notSolidButRefinementOnly = !surface.getType().isSolid() && isSurfaceRefinementOnly(surface); + return typePlane || singletonSTLRefinementOnly || typeSolidAndParentOK || notSolidButRefinementOnly; + } private boolean willBeACellZone(Surface surface) { Dictionary zoneDictionary = surface.getZoneDictionary(); - return zoneDictionary != null && !zoneDictionary.isEmpty() && zoneDictionary.isField(FACE_ZONE_KEY) && zoneDictionary.found(FACE_TYPE_KEY) && !zoneDictionary.lookup(FACE_TYPE_KEY).equals(NONE_KEY); + if (zoneDictionary == null) { + return false; + } else { + boolean hasCellZoneField = zoneDictionary.isField(CELL_ZONE_KEY); + boolean isCellZoneTrue = zoneDictionary.found(IS_CELL_ZONE_KEY) && zoneDictionary.lookupBoolean(IS_CELL_ZONE_KEY); + boolean faceTypeIsNotNone = zoneDictionary.found(FACE_TYPE_KEY) && !zoneDictionary.lookup(FACE_TYPE_KEY).equals(NONE_KEY); + return hasCellZoneField && isCellZoneTrue && faceTypeIsNotNone; + } + } + + private boolean willBeAFaceZone(Surface surface) { + Dictionary zoneDictionary = surface.getZoneDictionary(); + if (zoneDictionary == null) { + return false; + } else { + boolean hasFaceZoneField = zoneDictionary.isField(FACE_ZONE_KEY); + boolean faceTypeIsNotNone = zoneDictionary.found(FACE_TYPE_KEY) && !zoneDictionary.lookup(FACE_TYPE_KEY).equals(NONE_KEY); + return hasFaceZoneField && faceTypeIsNotNone; + } } private boolean willCreatePatches(Surface surface) { Dictionary zoneDictionary = surface.getZoneDictionary(); - return zoneDictionary.found(FACE_TYPE_KEY) && (zoneDictionary.lookup(FACE_TYPE_KEY).equals(BOUNDARY_KEY) || zoneDictionary.lookup(FACE_TYPE_KEY).equals(BAFFLE_KEY)); + if (zoneDictionary == null) { + return false; + } else { + boolean faceTypeIsBoundary = zoneDictionary.found(FACE_TYPE_KEY) && (zoneDictionary.lookup(FACE_TYPE_KEY).equals(BOUNDARY_KEY)); + boolean faceTypeIsBaffle = zoneDictionary.found(FACE_TYPE_KEY) && (zoneDictionary.lookup(FACE_TYPE_KEY).equals(BAFFLE_KEY)); + + return faceTypeIsBoundary || faceTypeIsBaffle; + } } private boolean isBoundary(Surface surface) { @@ -169,18 +233,6 @@ public class GeometryToMesh { return zoneDictionary.lookup(FACE_TYPE_KEY).equals(BAFFLE_KEY); } - private void surfaceToPatch(Surface surface) { - if (surface.isSingleton()) { - addPatch(surface); - } else if (surface.hasRegions()) { - for (Region region : surface.getRegions()) { - addPatch(region); - } - } else { - addPatch(surface); - } - } - private void addPatch(Surface surface) { if (willBeAPatch(surface)) { String patchName = naming.getPatchName(surface); @@ -194,7 +246,7 @@ public class GeometryToMesh { private void addPatchAndSlave(Surface surface) { String patchName = naming.getPatchName(surface); - String slaveName = patchName + "_slave"; + String slaveName = patchName + SLAVE_SUFFIX; logger.debug("'{}' becomes 2 PATCHES with name {} and {}", surface.getName(), patchName, slaveName); patches.add(newPatch(patchName)); willBePatches.add(surface); @@ -209,25 +261,19 @@ public class GeometryToMesh { patch.setVisible(true); patch.setLoaded(true); patch.setEmpty(false); - patch.setPhisicalType(BoundaryType.getDefaultType()); + patch.setPhysicalType(BoundaryType.getDefaultType()); patch.setBoundaryConditions(new BoundaryConditions()); return patch; } - private boolean willBeAPatch(Surface surface) { - return surface.getType().isPlane() - || (surface.getType().isStl() && surface.isSingleton() && isSurfaceRefinementOnly(surface)) - || (surface.getType().isSolid() && willBeAPatch(((Solid)surface).getParent()) ) - || (!surface.getType().isSolid() && isSurfaceRefinementOnly(surface)); - } - private boolean isSurfaceRefinementOnly(Surface surface) { boolean surfaceRefinement = isSurfaceRefinement(surface); boolean volumeRefinement = isVolumeRefinement(surface); boolean willBeACellZone = willBeACellZone(surface); + boolean willBeAFaceZone = willBeAFaceZone(surface); // System.err.println("GeometryToMesh.isSurfaceRefinementOnly() surfaceRefinement: "+surfaceRefinement+", volumeRefinement: "+volumeRefinement+", willBeACellZone: "+willBeACellZone); - return surfaceRefinement && !volumeRefinement && !willBeACellZone; + return surfaceRefinement && !volumeRefinement && !willBeACellZone && !willBeAFaceZone; } private boolean isVolumeRefinement(Surface surface) { @@ -248,4 +294,20 @@ public class GeometryToMesh { return naming.getCellZoneName(surface); } + public String getFaceZoneName(Surface surface) { + return naming.getFaceZoneName(surface); + } + + public List getWillBePatches() { + return willBePatches; + } + + public List getWillBeCellZones() { + return willBeCellZones; + } + + public List getWillBeFaceZones() { + return willBeFaceZones; + } + } diff --git a/src/eu/engys/core/controller/HelyxOSController.java b/src/eu/engys/core/controller/HelyxOSController.java index 26c3443..e617dd4 100644 --- a/src/eu/engys/core/controller/HelyxOSController.java +++ b/src/eu/engys/core/controller/HelyxOSController.java @@ -1,31 +1,30 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.controller; -import static eu.engys.core.project.system.SetFieldsDict.CELL_SET_KEY; +import static javax.swing.JOptionPane.ERROR_MESSAGE; import java.io.File; import java.util.List; @@ -42,24 +41,27 @@ import org.slf4j.LoggerFactory; import com.google.inject.Inject; import eu.engys.core.controller.actions.CheckMesh; +import eu.engys.core.controller.actions.DecomposeCaseAction; import eu.engys.core.controller.actions.InitialiseFields; import eu.engys.core.controller.actions.RunCommand; import eu.engys.core.controller.actions.StandardInitialiseFields; import eu.engys.core.controller.actions.StandardRunCase; import eu.engys.core.controller.actions.StandardRunMesh; -import eu.engys.core.controller.actions.TimeoutException; import eu.engys.core.executor.Executor; +import eu.engys.core.executor.TerminalManager; import eu.engys.core.modules.ApplicationModule; +import eu.engys.core.parameters.Parameters; import eu.engys.core.presentation.Action; import eu.engys.core.presentation.ActionManager; import eu.engys.core.project.Model; import eu.engys.core.project.ProjectReader; import eu.engys.core.project.ProjectWriter; +import eu.engys.core.project.geometry.surface.Stl; import eu.engys.core.project.state.ServerState; import eu.engys.core.project.system.monitoringfunctionobjects.ParserView; import eu.engys.core.project.system.monitoringfunctionobjects.TimeBlocks; +import eu.engys.core.project.zero.ZeroFileManager; import eu.engys.core.project.zero.cellzones.CellZonesBuilder; -import eu.engys.core.project.zero.fields.Field; import eu.engys.gui.casesetup.fields.StandardInitialisations; import eu.engys.gui.events.EventManager; import eu.engys.gui.events.EventManager.Event; @@ -67,33 +69,53 @@ import eu.engys.gui.events.EventManager.GenericEventListener; import eu.engys.gui.events.application.ApplicationEvent; import eu.engys.gui.events.application.BaseMeshTypeChangedEvent; import eu.engys.gui.events.application.OpenMonitorEvent; +import eu.engys.gui.events.view3D.AddSurfaceEvent; import eu.engys.gui.solver.postprocessing.ParsersHandler; import eu.engys.gui.solver.postprocessing.ParsersViewHandler; import eu.engys.gui.solver.postprocessing.panels.residuals.ResidualsView; +import eu.engys.parallelworks.CloudPanel; +import eu.engys.parallelworks.ParallelWorksClient; +import eu.engys.parallelworks.ParallelWorksData; +import eu.engys.parallelworks.actions.ParallelWorksInitialiseFields; +import eu.engys.parallelworks.actions.ParallelWorksRunCase; +import eu.engys.parallelworks.actions.ParallelWorksRunMesh; +import eu.engys.util.ApplicationInfo; +import eu.engys.util.PrefUtil; import eu.engys.util.progress.ProgressMonitor; +import eu.engys.util.progress.SilentMonitor; import eu.engys.util.ui.ScriptEditor; import eu.engys.util.ui.UiUtil; public class HelyxOSController extends AbstractController implements GenericEventListener, ParsersManager { + private static final String PARALLEL_WORKS_RESOURCES_ERROR_TITLE = "Remote Error"; + private static final String PARALLEL_WORKS_RESOURCES_ERROR_MESSAGE = "No Compute Resources Available - Please Start your Resources on Parallel Works"; + private static final long TIMER_INITIAL_DELAY = 500L; private static final long TIMER_REFRESH_RATE = 1000L; private static final Logger logger = LoggerFactory.getLogger(HelyxOSController.class); - private ResidualsView residualsView; + private ParserView residualsView; private RunCommand command; private Timer timer; private ParsersHandler parsersHandler; private ParsersViewHandler viewHandler; private ThreadPoolExecutor executor; + private TerminalManager terminalManager; @Inject public HelyxOSController(Model model, CellZonesBuilder cellZonesBuilder, Set modules, ProjectReader reader, ProjectWriter writer, CellZonesBuilder zonesBuilder, ProgressMonitor monitor, ScriptFactory scriptFactory) { super(model, modules, reader, writer, zonesBuilder, monitor, scriptFactory); - this.residualsView = new ResidualsView(model, monitor); + this.residualsView = new ResidualsView(model, modules, monitor); EventManager.registerEventListener(this, ApplicationEvent.class); ActionManager.getInstance().parseActions(this); + this.terminalManager = new TerminalManager(); + } + + @Override + public TerminalManager getTerminalManager() { + return terminalManager; } @Override @@ -110,16 +132,25 @@ public class HelyxOSController extends AbstractController implements GenericEven * MESH */ - @Action(key = "mesh.create", checkEnv = true) + @Action(key = MESH_CREATE, checkEnv = true) public void runMesh() { save(model.getProject().getBaseDir()); - command = new StandardRunMesh(model, this, scriptFactory); + if (PrefUtil.isRunningOnCloud()) { + if (ParallelWorksClient.getInstance().isPoolOn()) { + command = new ParallelWorksRunMesh(model, this, scriptFactory, monitor); + } else { + JOptionPane.showMessageDialog(UiUtil.getActiveWindow(), PARALLEL_WORKS_RESOURCES_ERROR_MESSAGE, PARALLEL_WORKS_RESOURCES_ERROR_TITLE, JOptionPane.ERROR_MESSAGE); + return; + } + } else { + command = new StandardRunMesh(model, this, scriptFactory); + } command.beforeExecute(); command.executeClient(); } - @Action(key = "mesh.check", checkEnv = true) + @Action(key = MESH_CHECK, checkEnv = true) public void checkMesh() { model.getProject().getSystemFolder().write(model, null); RunCommand checkMesh = new CheckMesh(model, this, scriptFactory); @@ -136,13 +167,13 @@ public class HelyxOSController extends AbstractController implements GenericEven monitor.start("Open " + model.getProject().getBaseDir(), false, new Runnable() { @Override public void run() { - reopen(OpenOptions.CURRENT_SETTINGS); + reopen(OpenMode.CURRENT_SETTINGS); monitor.end(); } }); } - @Action(key = "initialise.fields", checkEnv = true) + @Action(key = INITIALISE_SCRIPT, checkEnv = true) public void initialiseFields() { if (model.getProject().getZeroFolder().hasNonZeroTimeFolders()) { int retVal = JOptionPane.showConfirmDialog(UiUtil.getActiveWindow(), "This action will DELETE all the time folders. Continue?", "Initialise Fields", JOptionPane.YES_NO_OPTION); @@ -161,23 +192,46 @@ public class HelyxOSController extends AbstractController implements GenericEven } }); - new StandardInitialisations(model, cellZonesBuilder, modules).initializeFields(); - if (cellSetFieldPresent()) { + StandardInitialisations initialisations = new StandardInitialisations(model, monitor); + initialisations.initializeFields(); + + model.getProject().getZeroFolder().write(model, cellZonesBuilder, modules, initialisations, new SilentMonitor()); + if (model.getFields().hasCellSetInitialisationField() || model.getFields().hasPotentialFlowInitialisationField()) { save(model.getProject().getBaseDir()); - command = new StandardInitialiseFields(model, this, scriptFactory); + if (PrefUtil.isRunningOnCloud()) { + if (ParallelWorksClient.getInstance().isPoolOn()) { + JOptionPane.showMessageDialog(UiUtil.getActiveWindow(), PARALLEL_WORKS_RESOURCES_ERROR_MESSAGE, PARALLEL_WORKS_RESOURCES_ERROR_TITLE, ERROR_MESSAGE); + command = new ParallelWorksInitialiseFields(model, this, scriptFactory, monitor); + } else { + return; + } + } else { + command = new StandardInitialiseFields(model, this, scriptFactory); + } command.beforeExecute(); command.executeClient(); + } else { + // just clear polymesh + ((ZeroFileManager) model.getProject().getZeroFolder().getFileManager()).removeNonZeroDirs("0"); } } - public boolean cellSetFieldPresent() { - for (Field f : model.getFields().values()) { - if (f.getInitialisationType().equals(CELL_SET_KEY)) { - return true; - } - } - return false; + /* + * DECOMPOSE + */ + @Action(key = DECOMPOSE) + public void decomposeCase() { + new DecomposeCaseAction(model, this, true).executeClient(); + } + + /* + * Parallel Works + */ + @Action(key = PARALLEL_WORKS) + public void openCloud() { + new CloudPanel(model, this, monitor).showDialog(ParallelWorksData.fromPrefences()); + } /* @@ -186,7 +240,7 @@ public class HelyxOSController extends AbstractController implements GenericEven private void startTimer() { startParsers(); - viewHandler = new ParsersViewHandler(model, this, residualsView); + viewHandler = new ParsersViewHandler(model, modules, this, residualsView); executor = Executor.newExecutor("ServerStateMonitor"); if (timer == null) { @@ -243,7 +297,18 @@ public class HelyxOSController extends AbstractController implements GenericEven save(model.getProject().getBaseDir()); listener.beforeRunCase(); - command = new StandardRunCase(model, this, scriptFactory); + + if (PrefUtil.isRunningOnCloud()) { + if (ParallelWorksClient.getInstance().isPoolOn()) { + command = new ParallelWorksRunCase(model, this, scriptFactory, monitor); + } else { + JOptionPane.showMessageDialog(UiUtil.getActiveWindow(), PARALLEL_WORKS_RESOURCES_ERROR_MESSAGE, PARALLEL_WORKS_RESOURCES_ERROR_TITLE, JOptionPane.ERROR_MESSAGE); + return; + } + } else { + command = new StandardRunCase(model, this, scriptFactory); + } + command.beforeExecute(); command.executeClient(); @@ -252,7 +317,7 @@ public class HelyxOSController extends AbstractController implements GenericEven @Action(key = "solver.refresh.once") public void refreshOnce() { - ParsersViewHandler viewHandler = new ParsersViewHandler(model, this, residualsView); + ParsersViewHandler viewHandler = new ParsersViewHandler(model, modules, this, residualsView); viewHandler.refreshOnce(); } @@ -274,7 +339,7 @@ public class HelyxOSController extends AbstractController implements GenericEven private void _stopCase() { try { command.stop(); - } catch (TimeoutException e) { + } catch (Exception e) { Object[] options = new Object[] { "Wait", "Kill Process" }; int option = JOptionPane.showOptionDialog(monitor.getDialog(), "Solver has not finished yet.\nSelect an action to perform.", "Stop Execution", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE, null, options, options[0]); if (timer != null) { @@ -306,26 +371,49 @@ public class HelyxOSController extends AbstractController implements GenericEven command.kill(); } + /* + * IMPORT FILES + */ + @Override + protected void importFiles(final File[] stlFiles) { + if (stlFiles != null) { + monitor.setIndeterminate(false); + monitor.start("Loading STL Files", false, new Runnable() { + @Override + public void run() { + for (File file : stlFiles) { + Stl stl = model.getGeometry().getFactory().readSTL(file, monitor); + model.getGeometry().addSurface(stl); + model.geometryChanged(stl); + + EventManager.triggerEvent(this, new AddSurfaceEvent(stl)); + } + monitor.end(); + } + }); + } + } + /* * EDIT SCRIPTS */ - @Action(key = "solver.run.edit") + @Action(key = SOLVER_RUN_EDIT) public void editRunCaseScript() { ScriptEditor.getInstance().show(scriptFactory.getSolverScript(model).toPath(), scriptFactory.getDefaultSolverScript(model)); } - @Action(key = "mesh.create.edit") + @Action(key = MESH_CREATE_EDIT) public void editRunMeshScript() { ScriptEditor.getInstance().show(scriptFactory.getMeshScript(model).toPath(), scriptFactory.getDefaultMeshScript(model)); } - @Action(key = "mesh.check.edit") + @Action(key = MESH_CHECK_EDIT) public void editCheckMeshScript() { ScriptEditor.getInstance().show(scriptFactory.getCheckMeshScript(model).toPath(), scriptFactory.getDefaultCheckMeshScript(model)); } - @Action(key = "initialise.fields.edit") + @Action(key = INITIALISE_SCRIPT_EDIT) public void editInitialiseScript() { ScriptEditor.getInstance().show(scriptFactory.getInitialiseScript(model).toPath(), scriptFactory.getDefaultInitialiseScript(model)); } @@ -336,7 +424,7 @@ public class HelyxOSController extends AbstractController implements GenericEven @Override public void startParsers() { logger.info("[SERVER] START PARSERS"); - parsersHandler = new ParsersHandler(model); + parsersHandler = new ParsersHandler(model, modules); parsersHandler.deleteUselessLogFiles(); } @@ -358,7 +446,7 @@ public class HelyxOSController extends AbstractController implements GenericEven @Override public List updateParserOnce(String foName) { logger.info("[SERVER] UPDATE PARSERS ONCE"); - ParsersHandler ph = new ParsersHandler(model); + ParsersHandler ph = new ParsersHandler(model, modules); return ph.refreshOnceForFunctionObject(foName); } @@ -372,8 +460,8 @@ public class HelyxOSController extends AbstractController implements GenericEven } @Override - public void open(File baseDir) { - super.open(baseDir); + public void open(OpenOptions oo) { + super.open(oo); if (listener != null) { // client.loadState(); listener.selectDestinationAndGo(); @@ -381,7 +469,7 @@ public class HelyxOSController extends AbstractController implements GenericEven } @Override - public void reopen(OpenOptions options) { + public void reopen(OpenMode options) { if (listener != null) { listener.saveLocation(); } @@ -411,18 +499,21 @@ public class HelyxOSController extends AbstractController implements GenericEven } @Override - protected boolean handleExitOnSolverRunning() { - Object[] options = new Object[] { STOP_SOLVER, KILL_SOLVER, CANCEL }; - int option = JOptionPane.showOptionDialog(UiUtil.getActiveWindow(), "Solver is Running. Select an action to perform.", STOP_SOLVER, JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]); + protected boolean handleExitOnRunning() { + Object[] options = new Object[] { KILL_PROCESS, CANCEL }; + String message = ApplicationInfo.getName() + " is running. Select an action to perform."; + String title = ApplicationInfo.getName(); + int option = JOptionPane.showOptionDialog(UiUtil.getActiveWindow(), message, title, JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]); if (option == JOptionPane.YES_OPTION) { - stopCase(); - return true; - } else if (option == JOptionPane.NO_OPTION) { kill(); return true; - } else { - return false; } + return false; } + + @Override + public void applyParameters(Parameters parameters) { + } + } diff --git a/src/eu/engys/core/controller/ILogServer.java b/src/eu/engys/core/controller/ILogServer.java index 0f5708d..de3747f 100644 --- a/src/eu/engys/core/controller/ILogServer.java +++ b/src/eu/engys/core/controller/ILogServer.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.controller; import java.io.Serializable; diff --git a/src/eu/engys/core/controller/KillCommandOS.java b/src/eu/engys/core/controller/KillCommandOS.java new file mode 100644 index 0000000..d3d52ec --- /dev/null +++ b/src/eu/engys/core/controller/KillCommandOS.java @@ -0,0 +1,46 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.core.controller; + +import javax.swing.JOptionPane; + +import eu.engys.util.ui.UiUtil; + +public class KillCommandOS implements Runnable { + + private Controller controller; + + public KillCommandOS(Controller controller) { + this.controller = controller; + } + + @Override + public void run() { + int retVal = JOptionPane.showConfirmDialog(UiUtil.getActiveWindow(), "Stop execution?", "Close Monitor", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE); + if (retVal == JOptionPane.YES_OPTION) { + controller.kill(); + } + } +} diff --git a/src/eu/engys/core/controller/LogClient.java b/src/eu/engys/core/controller/LogClient.java index 97ea61f..1353c17 100644 --- a/src/eu/engys/core/controller/LogClient.java +++ b/src/eu/engys/core/controller/LogClient.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.controller; import java.io.OutputStream; @@ -32,10 +31,6 @@ public interface LogClient extends Serializable { void start(String key, OutputStream out, OutputStream err); - void pump(String key, String lines); - - void close(); - void stop(String key); } diff --git a/src/eu/engys/core/controller/OpenOptions.java b/src/eu/engys/core/controller/OpenOptions.java new file mode 100644 index 0000000..d55ef39 --- /dev/null +++ b/src/eu/engys/core/controller/OpenOptions.java @@ -0,0 +1,73 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.core.controller; + +import java.io.File; + +import eu.engys.core.controller.Controller.OpenMode; + +public class OpenOptions { + private File file; + private File[] filesToImport; + private boolean loadMesh; + private OpenMode mode; + + public OpenOptions() { + } + + private OpenOptions(File file, File[] files, boolean loadMesh, OpenMode mode) { + this.file = file; + this.filesToImport = files; + this.loadMesh = loadMesh; + this.mode = mode; + } + + public static OpenOptions file(File file, OpenMode mode) { + return new OpenOptions(file, null, true, mode); + } + + public OpenOptions importFiles(File[] filesToImport) { + this.filesToImport = filesToImport; + return this; + } + public OpenOptions loadMesh(boolean loadMesh) { + this.loadMesh = loadMesh; + return this; + } + + public File getFile() { + return file; + } + public OpenMode getMode() { + return mode; + } + public File[] getFilesToImport() { + return filesToImport; + } + public boolean isLoadMesh() { + return loadMesh; + } + +} diff --git a/src/eu/engys/core/controller/ParsersManager.java b/src/eu/engys/core/controller/ParsersManager.java index eaefad8..d515096 100644 --- a/src/eu/engys/core/controller/ParsersManager.java +++ b/src/eu/engys/core/controller/ParsersManager.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.controller; import java.rmi.RemoteException; diff --git a/src/eu/engys/core/controller/QueueConnector.java b/src/eu/engys/core/controller/QueueConnector.java index 0ecf225..915e9a2 100644 --- a/src/eu/engys/core/controller/QueueConnector.java +++ b/src/eu/engys/core/controller/QueueConnector.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.controller; import java.util.Map; diff --git a/src/eu/engys/core/controller/QueueInfo.java b/src/eu/engys/core/controller/QueueInfo.java index c18d168..7e88b35 100644 --- a/src/eu/engys/core/controller/QueueInfo.java +++ b/src/eu/engys/core/controller/QueueInfo.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.controller; import java.io.Serializable; diff --git a/src/eu/engys/core/controller/ScriptBuilder.java b/src/eu/engys/core/controller/ScriptBuilder.java index 4195303..e6a2932 100644 --- a/src/eu/engys/core/controller/ScriptBuilder.java +++ b/src/eu/engys/core/controller/ScriptBuilder.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.controller; import java.util.LinkedList; @@ -33,7 +32,7 @@ public class ScriptBuilder { private List lines; public ScriptBuilder() { - lines = new LinkedList(); + lines = new LinkedList<>(); } public void append(String s) { @@ -62,4 +61,4 @@ public class ScriptBuilder { return lines; } -} +} \ No newline at end of file diff --git a/src/eu/engys/core/controller/ScriptFactory.java b/src/eu/engys/core/controller/ScriptFactory.java index 511cf80..11479ae 100644 --- a/src/eu/engys/core/controller/ScriptFactory.java +++ b/src/eu/engys/core/controller/ScriptFactory.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.controller; @@ -39,6 +38,9 @@ public interface ScriptFactory { File getCheckMeshScript(Model model); List getDefaultCheckMeshScript(Model model); + File getSnappyCheckMeshScript(Model model); + List getDefaultSnappyCheckMeshScript(Model model); + File getSolverScript(Model model); List getDefaultSolverScript(Model model); @@ -59,4 +61,7 @@ public interface ScriptFactory { File getExportScript(Model model); List getDefaultExportScript(Model model); + File getReportScript(Model model); + List getDefaultReportScript(Model model); + } diff --git a/src/eu/engys/core/controller/Server.java b/src/eu/engys/core/controller/Server.java index 8dfbff2..3d83b5e 100644 --- a/src/eu/engys/core/controller/Server.java +++ b/src/eu/engys/core/controller/Server.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.controller; import java.rmi.Remote; @@ -58,12 +57,17 @@ public interface Server extends Remote, ParsersManager { String test() throws RemoteException; - void disconnect() throws RemoteException; + void clientDisconnect() throws RemoteException; QueueInfo getQueueInfo() throws RemoteException; - void goToBatch() throws RemoteException; + CommandInfo goToBatch() throws RemoteException; - void connect(ClientInfo clientInfo) throws RemoteException; + CommandInfo connect(ClientInfo clientInfo) throws RemoteException; + String getServerID() throws RemoteException; + + boolean isRunningCommand() throws RemoteException; + + ClientInfo getClientInfo() throws RemoteException; } diff --git a/src/eu/engys/core/controller/ServerInfo.java b/src/eu/engys/core/controller/ServerInfo.java index f5ffb23..7cf91ee 100644 --- a/src/eu/engys/core/controller/ServerInfo.java +++ b/src/eu/engys/core/controller/ServerInfo.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.controller; import java.util.Scanner; @@ -39,7 +38,7 @@ public class ServerInfo { public void decodePorts(String payload) { if (payload != null && !payload.isEmpty()) { Scanner scanner = new Scanner(payload); - String date = scanner.hasNextLine() ? scanner.nextLine() : ""; + this.date = scanner.hasNextLine() ? scanner.nextLine() : ""; this.port1 = scanner.hasNextInt() ? scanner.nextInt() : 0; this.port2 = scanner.hasNextInt() ? scanner.nextInt() : 0; scanner.close(); @@ -48,6 +47,6 @@ public class ServerInfo { @Override public String toString() { - return "ServerInfo - ID: " + id + ", msg: " + message + ", port1: " + port1 + ", port2: " + port2 + ", succes: " + success + "date: " + date; + return "ServerInfo - ID: " + id + ", msg: " + message + ", port1: " + port1 + ", port2: " + port2 + ", succes: " + success + ", date: " + date; } -} +} \ No newline at end of file diff --git a/src/eu/engys/core/controller/StateConnector.java b/src/eu/engys/core/controller/StateConnector.java index 59d1d29..d9d9a5c 100644 --- a/src/eu/engys/core/controller/StateConnector.java +++ b/src/eu/engys/core/controller/StateConnector.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.controller; import java.io.Serializable; diff --git a/src/eu/engys/core/controller/StopOrKillCommandOS.java b/src/eu/engys/core/controller/StopOrKillCommandOS.java index 7110cdb..dab3198 100644 --- a/src/eu/engys/core/controller/StopOrKillCommandOS.java +++ b/src/eu/engys/core/controller/StopOrKillCommandOS.java @@ -1,37 +1,35 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.controller; import static eu.engys.core.controller.AbstractController.CANCEL; -import static eu.engys.core.controller.AbstractController.KILL_SOLVER; -import static eu.engys.core.controller.AbstractController.STOP_SOLVER; +import static eu.engys.core.controller.AbstractController.KILL_SOLVER_LABEL; +import static eu.engys.core.controller.AbstractController.STOP_SOLVER_LABEL; import javax.swing.JOptionPane; -import eu.engys.core.controller.actions.TimeoutException; import eu.engys.util.ui.UiUtil; public class StopOrKillCommandOS implements Runnable { @@ -44,12 +42,12 @@ public class StopOrKillCommandOS implements Runnable { @Override public void run() { - Object[] options = new Object[] { STOP_SOLVER, KILL_SOLVER, CANCEL }; - int option = JOptionPane.showOptionDialog(UiUtil.getActiveWindow(), "Select an action to perform.", STOP_SOLVER, JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]); + Object[] options = new Object[] { STOP_SOLVER_LABEL, KILL_SOLVER_LABEL, CANCEL }; + int option = JOptionPane.showOptionDialog(UiUtil.getActiveWindow(), "Select an action to perform.", STOP_SOLVER_LABEL, JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]); if (option == JOptionPane.YES_OPTION) { try { controller.stopCase(); - } catch (TimeoutException e) { + } catch (Exception e) { // should never pass here } } else if (option == JOptionPane.NO_OPTION) { diff --git a/src/eu/engys/core/controller/View3DOptions.java b/src/eu/engys/core/controller/View3DOptions.java index f1e380a..3aeaf49 100644 --- a/src/eu/engys/core/controller/View3DOptions.java +++ b/src/eu/engys/core/controller/View3DOptions.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.controller; import javax.swing.BorderFactory; diff --git a/src/eu/engys/core/controller/actions/AbstractRunCommand.java b/src/eu/engys/core/controller/actions/AbstractRunCommand.java index 7f7e23f..6f4e5d6 100644 --- a/src/eu/engys/core/controller/actions/AbstractRunCommand.java +++ b/src/eu/engys/core/controller/actions/AbstractRunCommand.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.controller.actions; import java.util.concurrent.ExecutorService; @@ -36,11 +35,14 @@ import eu.engys.core.project.Model; public abstract class AbstractRunCommand implements RunCommand { protected Model model; - protected Executor executor; protected Controller controller; + protected Executor executor; + protected ExecutorService service; protected ExecutorTerminal terminal; + protected String jobID = null; + public AbstractRunCommand(Model model, Controller controller) { this.model = model; this.controller = controller; @@ -71,7 +73,7 @@ public abstract class AbstractRunCommand implements RunCommand { } @Override - public void stop() throws TimeoutException { + public void stop() throws Exception { } @Override @@ -83,12 +85,16 @@ public abstract class AbstractRunCommand implements RunCommand { } @Override - public String executeQueue(Server server) throws CommandException { - return null; + public void executeQueue(Server server) throws CommandException { } @Override public void executeBatch() { } + @Override + public String getJobID() { + return jobID; + } + } diff --git a/src/eu/engys/core/controller/actions/CheckMesh.java b/src/eu/engys/core/controller/actions/CheckMesh.java index c844f55..9982745 100644 --- a/src/eu/engys/core/controller/actions/CheckMesh.java +++ b/src/eu/engys/core/controller/actions/CheckMesh.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.controller.actions; import static eu.engys.core.OpenFOAMEnvironment.getEnvironment; @@ -30,17 +29,18 @@ import static eu.engys.core.project.openFOAMProject.LOG; import java.io.File; import java.nio.file.Paths; +import java.util.concurrent.Executors; import eu.engys.core.controller.Controller; -import eu.engys.core.controller.Controller.OpenOptions; import eu.engys.core.controller.ScriptFactory; import eu.engys.core.executor.Executor; import eu.engys.core.executor.ExecutorHook; import eu.engys.core.executor.ExecutorListener.ExecutorState; import eu.engys.core.executor.ExecutorMonitor; -import eu.engys.core.executor.ExecutorTerminal; import eu.engys.core.executor.TerminalExecutorMonitor; import eu.engys.core.project.Model; +import eu.engys.core.project.mesh.MeshInfoReader; +import eu.engys.core.project.mesh.MeshInfoWriter; import eu.engys.util.IOUtils; public class CheckMesh extends AbstractRunCommand { @@ -48,39 +48,51 @@ public class CheckMesh extends AbstractRunCommand { public static final String ACTION_NAME = "Check Mesh"; public static final String LOG_NAME = "checkMesh.log"; - private File logFile; private ScriptFactory scriptFactory; + private String logName; + private String actionName; + private File logFile; public CheckMesh(Model model, Controller controller, ScriptFactory scriptFactory) { + this(model, controller, scriptFactory, LOG_NAME, ACTION_NAME); + } + + public CheckMesh(Model model, Controller controller, ScriptFactory scriptFactory, String logName, String actionName) { super(model, controller); this.scriptFactory = scriptFactory; - this.logFile = Paths.get(model.getProject().getBaseDir().getAbsolutePath(), LOG, LOG_NAME).toFile(); + this.logName = logName; + this.actionName = actionName; + this.logFile = Paths.get(model.getProject().getBaseDir().getAbsolutePath(), LOG, logName).toFile(); } @Override public void beforeExecute() { IOUtils.clearFile(logFile); - if (controller.getListener() != null) { - controller.getListener().beforeCheckMesh(); - } } @Override public void executeClient() { - ExecutorTerminal terminal = new TerminalExecutorMonitor(logFile); + if (terminal == null) { + this.terminal = new TerminalExecutorMonitor(controller.getTerminalManager(), logFile); + } + if (service == null) { + this.service = Executors.newSingleThreadExecutor(); + } + ExecutorMonitor monitor = new ExecutorMonitor(); monitor.addHook(ExecutorState.FINISH, new FinishHook()); - this.executor = Executor.script(scriptFactory.getCheckMeshScript(model)).description(ACTION_NAME).inFolder(model.getProject().getBaseDir()).inTerminal(terminal).withMonitors(monitor).env(getEnvironment(model, LOG_NAME)).keepFileOnEnd(); + this.executor = Executor.script(scriptFactory.getCheckMeshScript(model)).description(actionName).inFolder(model.getProject().getBaseDir()).inTerminal(terminal).withMonitors(monitor).inService(service).env(getEnvironment(model, logName)).keepFileOnEnd(); executor.exec(); } private class FinishHook implements ExecutorHook { - @Override public void run(ExecutorMonitor monitor) { if (controller.getListener() != null) { - controller.reopenCase(OpenOptions.MESH_ONLY); + new MeshInfoReader(model).read(logFile); + new MeshInfoWriter(model).write(); + model.getProject().getSystemFolder().writeProjectDict(null); controller.getListener().afterCheckMesh(); } } diff --git a/src/eu/engys/core/controller/actions/CommandException.java b/src/eu/engys/core/controller/actions/CommandException.java index 707ea9b..b8e4839 100644 --- a/src/eu/engys/core/controller/actions/CommandException.java +++ b/src/eu/engys/core/controller/actions/CommandException.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.controller.actions; public class CommandException extends Exception { @@ -31,4 +30,8 @@ public class CommandException extends Exception { super(message); } + public CommandException(String message, Exception e) { + super(message, e); + } + } diff --git a/src/eu/engys/gui/casesetup/actions/DecomposeCase.java b/src/eu/engys/core/controller/actions/DecomposeCase.java similarity index 56% rename from src/eu/engys/gui/casesetup/actions/DecomposeCase.java rename to src/eu/engys/core/controller/actions/DecomposeCase.java index ebbab68..55c5e00 100644 --- a/src/eu/engys/gui/casesetup/actions/DecomposeCase.java +++ b/src/eu/engys/core/controller/actions/DecomposeCase.java @@ -1,29 +1,28 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - -package eu.engys.gui.casesetup.actions; +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.core.controller.actions; import static eu.engys.core.OpenFOAMEnvironment.getEnvironment; import static eu.engys.core.OpenFOAMEnvironment.loadEnvironment; @@ -37,12 +36,12 @@ import static eu.engys.util.OpenFOAMCommands.DECOMPOSE_PAR_CONSTANT_ALLREGIONS; import java.io.File; import java.nio.file.Paths; +import java.util.Set; import java.util.concurrent.Executors; import eu.engys.core.controller.Controller; -import eu.engys.core.controller.Controller.OpenOptions; +import eu.engys.core.controller.Controller.OpenMode; import eu.engys.core.controller.ScriptBuilder; -import eu.engys.core.controller.actions.AbstractRunCommand; import eu.engys.core.executor.Executor; import eu.engys.core.executor.ExecutorHook; import eu.engys.core.executor.ExecutorListener.ExecutorState; @@ -54,19 +53,23 @@ import eu.engys.util.Util; public class DecomposeCase extends AbstractRunCommand { + public static final String ACTION_NAME = "Decompose"; private static final String DECOMPOSE_RUN = "decomposeCase.run"; private static final String DECOMPOSE_BAT = "decomposeCase.bat"; private File logFile; private String actionName; private String logName; + private Set timeSteps; - public DecomposeCase(Model model, Controller controller, String actionName, String logName) { + public DecomposeCase(Model model, Controller controller, String logName, String actionName, Set timeSteps) { super(model, controller); this.actionName = actionName; this.logName = logName; + this.timeSteps = timeSteps; this.logFile = Paths.get(model.getProject().getBaseDir().getAbsolutePath(), LOG, logName).toFile(); } + @Override public void beforeExecute() { @@ -79,7 +82,7 @@ public class DecomposeCase extends AbstractRunCommand { File baseDir = model.getProject().getBaseDir(); if (terminal == null) { - this.terminal = new TerminalExecutorMonitor(logFile); + this.terminal = new TerminalExecutorMonitor(controller.getTerminalManager(), logFile); } if (service == null) { this.service = Executors.newSingleThreadExecutor(); @@ -104,7 +107,7 @@ public class DecomposeCase extends AbstractRunCommand { } private void writeScript(ScriptBuilder sb) { - printHeader(sb, actionName.toUpperCase()); + printHeader(sb, ACTION_NAME); printVariables(sb); loadEnvironment(sb); writeCommand(sb); @@ -113,15 +116,15 @@ public class DecomposeCase extends AbstractRunCommand { private void writeCommand(ScriptBuilder sb) { if (model.getProject().isMeshOnZero() || model.getProject().isSerial()) { if (model.getProject().getZeroFolder().hasRegions()) { - sb.append(DECOMPOSE_PAR_ALLREGIONS()); + sb.append(DECOMPOSE_PAR_ALLREGIONS(timeSteps)); } else { - sb.append(DECOMPOSE_PAR()); + sb.append(DECOMPOSE_PAR(timeSteps)); } } else { if (model.getProject().getZeroFolder().hasRegions()) { - sb.append(DECOMPOSE_PAR_CONSTANT_ALLREGIONS()); + sb.append(DECOMPOSE_PAR_CONSTANT_ALLREGIONS(timeSteps)); } else { - sb.append(DECOMPOSE_PAR_CONSTANT()); + sb.append(DECOMPOSE_PAR_CONSTANT(timeSteps)); } } } @@ -131,7 +134,7 @@ public class DecomposeCase extends AbstractRunCommand { @Override public void run(ExecutorMonitor monitor) { if (controller.getListener() != null) { - controller.reopenCase(OpenOptions.PARALLEL); + controller.reopenCase(OpenMode.PARALLEL); } } } diff --git a/src/eu/engys/core/controller/actions/DecomposeCaseAction.java b/src/eu/engys/core/controller/actions/DecomposeCaseAction.java new file mode 100644 index 0000000..67d0d4b --- /dev/null +++ b/src/eu/engys/core/controller/actions/DecomposeCaseAction.java @@ -0,0 +1,105 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.core.controller.actions; + +import static eu.engys.core.controller.actions.DecomposeCase.ACTION_NAME; +import static eu.engys.core.project.openFOAMProject.LOG; + +import java.io.File; +import java.nio.file.Paths; +import java.util.Set; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; + +import eu.engys.core.controller.Controller; +import eu.engys.core.executor.TerminalExecutorMonitor; +import eu.engys.core.project.Model; +import eu.engys.util.IOUtils; + +public class DecomposeCaseAction extends AbstractRunCommand { + + public static final String LOG_NAME = "decomposeCase.log"; + + private Model model; + private Controller controller; + + private boolean shouldUseWithZeroFlag; + + public DecomposeCaseAction(Model model, Controller controller, boolean shouldUseWithZeroFlag) { + super(model, controller); + this.model = model; + this.controller = controller; + this.shouldUseWithZeroFlag = shouldUseWithZeroFlag; + } + + @Override + public void executeClient() { + DecomposeCasePanel panel = new DecomposeCasePanel(model); + panel.showDialog(); + if (panel.getStatus().isOK()) { + controller.saveCase(model.getProject().getBaseDir()); + decompose(panel.getTimeSteps()); + } + } + + private void decompose(Set timeSteps) { + if (model.getProject().isParallel()) { + decomposeParallelCase(timeSteps); + } else { + decomposeSerialCase(timeSteps); + } + } + + private void decomposeSerialCase(Set timeSteps) { + RunCommand command = new DecomposeCase(model, controller, LOG_NAME, ACTION_NAME, timeSteps); + command.beforeExecute(); + command.executeClient(); + } + + private void decomposeParallelCase(Set timeSteps) { + File logFile = Paths.get(model.getProject().getBaseDir().getAbsolutePath(), LOG, LOG_NAME).toFile(); + + IOUtils.clearFile(logFile); + + TerminalExecutorMonitor terminal = new TerminalExecutorMonitor(controller.getTerminalManager(), logFile); + ExecutorService service = Executors.newSingleThreadExecutor(); + + RunCommand reconstructMesh = new ReconstructMesh(model, controller, ACTION_NAME, LOG_NAME); + reconstructMesh.inService(service); + reconstructMesh.inTerminal(terminal); + reconstructMesh.executeClient(); + + RunCommand reconstructCase = new ReconstructCase(model, controller, shouldUseWithZeroFlag, ACTION_NAME, LOG_NAME); + reconstructCase.inService(service); + reconstructCase.inTerminal(terminal); + reconstructCase.executeClient(); + + RunCommand decomposeCase = new DecomposeCase(model, controller, LOG_NAME, ACTION_NAME, timeSteps); + decomposeCase.inService(service); + decomposeCase.inTerminal(terminal); + decomposeCase.executeClient(); + } + +} diff --git a/src/eu/engys/gui/casesetup/actions/DecomposeCasePanel.java b/src/eu/engys/core/controller/actions/DecomposeCasePanel.java similarity index 60% rename from src/eu/engys/gui/casesetup/actions/DecomposeCasePanel.java rename to src/eu/engys/core/controller/actions/DecomposeCasePanel.java index 3566091..5e3f2ef 100644 --- a/src/eu/engys/gui/casesetup/actions/DecomposeCasePanel.java +++ b/src/eu/engys/core/controller/actions/DecomposeCasePanel.java @@ -1,29 +1,28 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - -package eu.engys.gui.casesetup.actions; +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.core.controller.actions; import static eu.engys.core.project.system.DecomposeParDict.DELTA_KEY; import static eu.engys.core.project.system.DecomposeParDict.HIERARCHICAL_COEFFS_KEY; @@ -36,21 +35,34 @@ import static eu.engys.core.project.system.DecomposeParDict.SCOTCH_KEY; import static eu.engys.core.project.system.DecomposeParDict.TYPE_KEYS; import static eu.engys.core.project.system.DecomposeParDict.YXZ_KEY; import static eu.engys.util.ui.ComponentsFactory.labelArrayField; +import static eu.engys.util.ui.UiUtil.DIALOG_CANCEL_LABEL; +import static eu.engys.util.ui.UiUtil.DIALOG_OK_LABEL; import java.awt.BorderLayout; import java.awt.FlowLayout; +import java.awt.GridLayout; import java.awt.event.ActionEvent; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; +import java.io.File; +import java.util.Comparator; +import java.util.HashMap; +import java.util.Map; +import java.util.Set; +import java.util.TreeSet; import javax.swing.AbstractAction; +import javax.swing.BorderFactory; import javax.swing.JButton; +import javax.swing.JCheckBox; import javax.swing.JComboBox; +import javax.swing.JComponent; import javax.swing.JDialog; import javax.swing.JOptionPane; import javax.swing.JPanel; +import javax.swing.JScrollPane; import eu.engys.core.dictionary.Dictionary; import eu.engys.core.dictionary.model.DictionaryModel; @@ -67,10 +79,16 @@ public class DecomposeCasePanel extends JPanel { public static final String HIERARCHY_LABEL = "Hierarchy"; public static final String PROCESSORS_LABEL = "Processors"; public static final String DECOMPOSITION_TYPE_LABEL = "Decomposition Type"; + public static final String TIME_STEP = "Time Steps"; public static final String HIERARCHICAL_LABEL = "Hierarchical"; public static final String SCOTCH_LABEL = "Scotch"; private static final String[] TYPE_LABELS = { HIERARCHICAL_LABEL, SCOTCH_LABEL }; + private static final String SELECT_ALL = "Select All"; + private static final String DESELECT_ALL = "Deselect All"; + public static final String DECOMPOSE_PANEL = "decompose.panel"; + + private Map timeStepMap; public enum Status { OK, CANCEL; @@ -103,10 +121,11 @@ public class DecomposeCasePanel extends JPanel { public DecomposeCasePanel(Model model) { super(new BorderLayout()); - setName("decompose.panel"); + setName(DECOMPOSE_PANEL); this.model = model; this.mainModel = new DictionaryModel(); this.hierarchicalDictionaryModel = new DictionaryModel(); + this.timeStepMap = new HashMap<>(); layoutComponents(); } @@ -146,7 +165,49 @@ public class DecomposeCasePanel extends JPanel { nProcessorsField.addPropertyChangeListener(new RecalculateFactorsOnChange()); nProcessorsField.setIntValue(1); - add(builder.getPanel()); + add(builder.getPanel(), BorderLayout.CENTER); + add(createTimeStepsPanel(), BorderLayout.SOUTH); + } + + private JComponent createTimeStepsPanel() { + JPanel panel = new JPanel(new GridLayout(0, 4)); + + File[] zeroDirs = model.getProject().getZeroFolder().getFileManager().getZeroDirs("0"); + File[] nonZeroDirs = model.getProject().getZeroFolder().getFileManager().getNonZeroDirs("0"); + + Set timeSteps = new TreeSet<>(new Comparator() { + @Override + public int compare(String o1, String o2) { + return Double.valueOf(o1).compareTo(Double.valueOf(o2)); + } + }); + for (File zeroDir : zeroDirs) { + timeSteps.add(zeroDir.getName()); + } + for (File nonZeroDir : nonZeroDirs) { + timeSteps.add(nonZeroDir.getName()); + } + + for (String timeStep : timeSteps) { + JCheckBox chk = new JCheckBox(timeStep, true); + timeStepMap.put(chk, timeStep); + chk.setName(timeStep); + panel.add(chk); + } + + panel.setBorder(BorderFactory.createTitledBorder(TIME_STEP)); + panel.setName(TIME_STEP); + return panel; + } + + public Set getTimeSteps() { + Set timeSteps = new TreeSet<>(); + for (JCheckBox check : timeStepMap.keySet()){ + if(check.isSelected()){ + timeSteps.add(timeStepMap.get(check)); + } + } + return timeSteps; } public void showDialog() { @@ -158,9 +219,9 @@ public class DecomposeCasePanel extends JPanel { private void createDialog() { if (dialog == null) { dialog = new JDialog(UiUtil.getActiveWindow(), DECOMPOSE_CASE_LABEL); - dialog.setName("create.case.dialog"); + dialog.setName(DECOMPOSE_PANEL); - AbstractAction saveAndCloseDialogAction = new AbstractAction("OK") { + AbstractAction saveAndCloseDialogAction = new AbstractAction(DIALOG_OK_LABEL) { @Override public void actionPerformed(ActionEvent e) { if (TYPE_KEYS[0].equals(decompositionType.getSelectedItem()) && !productEqualsToNumberOfSubdomain()) { @@ -173,7 +234,7 @@ public class DecomposeCasePanel extends JPanel { } }; - final AbstractAction cancelAction = new AbstractAction("Cancel") { + final AbstractAction cancelAction = new AbstractAction(DIALOG_CANCEL_LABEL) { @Override public void actionPerformed(ActionEvent e) { status = Status.CANCEL; @@ -182,26 +243,20 @@ public class DecomposeCasePanel extends JPanel { dialog = null; } }; - - JPanel buttonsPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); - - JButton okButton = new JButton(saveAndCloseDialogAction); - okButton.setName("OK"); - buttonsPanel.add(okButton); - - JButton cancelButton = new JButton(cancelAction); - cancelButton.setName("Cancel"); - buttonsPanel.add(cancelButton); - + + JPanel buttonsPanel = createButtonsPanel(saveAndCloseDialogAction, cancelAction); + + JScrollPane pane = new JScrollPane(this); + pane.setBorder(BorderFactory.createEmptyBorder()); + JPanel mainPanel = new JPanel(new BorderLayout()); - mainPanel.add(this, BorderLayout.CENTER); + mainPanel.add(pane, BorderLayout.CENTER); mainPanel.add(buttonsPanel, BorderLayout.SOUTH); dialog.add(mainPanel); - dialog.setSize(350, 200); + dialog.setSize(400, 300); dialog.setLocationRelativeTo(null); dialog.setModal(true); - dialog.getRootPane().setDefaultButton(okButton); dialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE); dialog.addWindowListener(new WindowAdapter() { @@ -213,6 +268,44 @@ public class DecomposeCasePanel extends JPanel { } } + private JPanel createButtonsPanel(AbstractAction saveAndCloseDialogAction, AbstractAction cancelAction) { + JPanel rightButtonsPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); + JButton okButton = new JButton(saveAndCloseDialogAction); + okButton.setName(DIALOG_OK_LABEL); + JButton cancelButton = new JButton(cancelAction); + cancelButton.setName(DIALOG_CANCEL_LABEL); + rightButtonsPanel.add(okButton); + rightButtonsPanel.add(cancelButton); + + JPanel leftButtonsPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); + JButton selectAll = new JButton(new AbstractAction(SELECT_ALL) { + @Override + public void actionPerformed(ActionEvent e) { + for (JCheckBox chk : timeStepMap.keySet()) { + chk.setSelected(true); + } + } + }); + + JButton deselectAll = new JButton(new AbstractAction(DESELECT_ALL) { + @Override + public void actionPerformed(ActionEvent e) { + for (JCheckBox chk : timeStepMap.keySet()) { + chk.setSelected(false); + } + } + }); + + leftButtonsPanel.add(selectAll); + leftButtonsPanel.add(deselectAll); + + JPanel buttonsPanel = new JPanel(new GridLayout(1, 2)); + buttonsPanel.add(leftButtonsPanel); + buttonsPanel.add(rightButtonsPanel); + + return buttonsPanel; + } + private boolean productEqualsToNumberOfSubdomain() { int nOfSubdomains = nProcessorsField.getIntValue(); int x = nHierarchyField[X].getIntValue(); diff --git a/src/eu/engys/core/controller/actions/DeleteMesh.java b/src/eu/engys/core/controller/actions/DeleteMesh.java index e2b0c31..e9369e6 100644 --- a/src/eu/engys/core/controller/actions/DeleteMesh.java +++ b/src/eu/engys/core/controller/actions/DeleteMesh.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.controller.actions; import eu.engys.core.controller.Controller; diff --git a/src/eu/engys/core/controller/actions/InitialiseFields.java b/src/eu/engys/core/controller/actions/InitialiseFields.java index 94f32cf..f339280 100644 --- a/src/eu/engys/core/controller/actions/InitialiseFields.java +++ b/src/eu/engys/core/controller/actions/InitialiseFields.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.controller.actions; import static eu.engys.core.project.openFOAMProject.LOG; diff --git a/src/eu/engys/core/controller/actions/NamingConvention.java b/src/eu/engys/core/controller/actions/NamingConvention.java index baf8d0d..3bf5c28 100644 --- a/src/eu/engys/core/controller/actions/NamingConvention.java +++ b/src/eu/engys/core/controller/actions/NamingConvention.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.controller.actions; import eu.engys.core.project.geometry.Surface; @@ -32,4 +31,6 @@ public interface NamingConvention { String getPatchName(Surface surface); String getCellZoneName(Surface surface); + + String getFaceZoneName(Surface surface); } diff --git a/src/eu/engys/core/controller/actions/ReconstructCase.java b/src/eu/engys/core/controller/actions/ReconstructCase.java new file mode 100644 index 0000000..8378cb7 --- /dev/null +++ b/src/eu/engys/core/controller/actions/ReconstructCase.java @@ -0,0 +1,107 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.core.controller.actions; + +import static eu.engys.core.OpenFOAMEnvironment.getEnvironment; +import static eu.engys.core.OpenFOAMEnvironment.loadEnvironment; +import static eu.engys.core.OpenFOAMEnvironment.printHeader; +import static eu.engys.core.OpenFOAMEnvironment.printVariables; +import static eu.engys.core.project.openFOAMProject.LOG; +import static eu.engys.util.OpenFOAMCommands.RECONSTRUCT_PAR; +import static eu.engys.util.OpenFOAMCommands.RECONSTRUCT_PAR_ALLREGIONS; + +import java.io.File; +import java.nio.file.Paths; +import java.util.concurrent.Executors; + +import eu.engys.core.controller.Controller; +import eu.engys.core.controller.ScriptBuilder; +import eu.engys.core.executor.Executor; +import eu.engys.core.executor.TerminalExecutorMonitor; +import eu.engys.core.project.Model; +import eu.engys.util.IOUtils; +import eu.engys.util.Util; + +public class ReconstructCase extends AbstractRunCommand { + + public static final String ACTION_NAME = "Reconstruct Par"; + private static final String RECONSTRUCT_CASE_RUN = "reconstructCase.run"; + private static final String RECONSTRUCT_CASE_BAT = "reconstructCase.bat"; + + private String actionName; + private String logName; + private File logFile; + private boolean shouldUseWithZeroFlag; + + public ReconstructCase(Model model, Controller controller, boolean shouldUseWithZeroFlag, String actionName, String logName) { + super(model, controller); + this.shouldUseWithZeroFlag = shouldUseWithZeroFlag; + this.actionName = actionName; + this.logName = logName; + this.logFile = Paths.get(model.getProject().getBaseDir().getAbsolutePath(), LOG, logName).toFile(); + } + + @Override + public void executeClient() { + File script = getScript(); + File baseDir = model.getProject().getBaseDir(); + + if (terminal == null) { + this.terminal = new TerminalExecutorMonitor(controller.getTerminalManager(), logFile); + } + if (service == null) { + this.service = Executors.newSingleThreadExecutor(); + } + + this.executor = Executor.script(script).description(actionName).inFolder(baseDir).inTerminal(terminal).inService(service).env(getEnvironment(model, logName)); + executor.exec(); + } + + private File getScript() { + File file = new File(model.getProject().getBaseDir(), Util.isWindows() ? RECONSTRUCT_CASE_BAT : RECONSTRUCT_CASE_RUN); + ScriptBuilder sb = new ScriptBuilder(); + writeScript(sb); + IOUtils.writeLinesToFile(file, sb.getLines()); + file.setExecutable(true); + return file; + } + + private void writeScript(ScriptBuilder sb) { + printHeader(sb, ACTION_NAME); + printVariables(sb); + loadEnvironment(sb); + writeCommand(sb); + } + + private void writeCommand(ScriptBuilder sb) { + if (model.getProject().getZeroFolder().hasRegions()) { + sb.append(RECONSTRUCT_PAR_ALLREGIONS(shouldUseWithZeroFlag)); + } else { + sb.append(RECONSTRUCT_PAR(shouldUseWithZeroFlag)); + } + + } + +} diff --git a/src/eu/engys/core/controller/actions/ReconstructMesh.java b/src/eu/engys/core/controller/actions/ReconstructMesh.java new file mode 100644 index 0000000..ab805d8 --- /dev/null +++ b/src/eu/engys/core/controller/actions/ReconstructMesh.java @@ -0,0 +1,116 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.core.controller.actions; + +import static eu.engys.core.OpenFOAMEnvironment.getEnvironment; +import static eu.engys.core.OpenFOAMEnvironment.loadEnvironment; +import static eu.engys.core.OpenFOAMEnvironment.printHeader; +import static eu.engys.core.OpenFOAMEnvironment.printVariables; +import static eu.engys.core.project.openFOAMProject.LOG; +import static eu.engys.util.OpenFOAMCommands.RECONSTRUCT_PAR_MESH; +import static eu.engys.util.OpenFOAMCommands.RECONSTRUCT_PAR_MESH_ALLREGIONS; +import static eu.engys.util.OpenFOAMCommands.RECONSTRUCT_PAR_MESH_CONSTANT; +import static eu.engys.util.OpenFOAMCommands.RECONSTRUCT_PAR_MESH_CONSTANT_ALLREGIONS; + +import java.io.File; +import java.nio.file.Paths; +import java.util.concurrent.Executors; + +import eu.engys.core.controller.Controller; +import eu.engys.core.controller.ScriptBuilder; +import eu.engys.core.executor.Executor; +import eu.engys.core.executor.TerminalExecutorMonitor; +import eu.engys.core.project.Model; +import eu.engys.util.IOUtils; +import eu.engys.util.Util; + +public class ReconstructMesh extends AbstractRunCommand { + + public static final String ACTION_NAME = "Reconstruct Par Mesh"; + private static final String RECONSTRUCT_MESH_RUN = "reconstructMesh.run"; + private static final String RECONSTRUCT_MESH_BAT = "reconstructMesh.bat"; + + private String actionName; + private String logName; + private File logFile; + + public ReconstructMesh(Model model, Controller controller, String actionName, String logName) { + super(model, controller); + this.actionName = actionName; + this.logName = logName; + this.logFile = Paths.get(model.getProject().getBaseDir().getAbsolutePath(), LOG, logName).toFile(); + } + + @Override + public void executeClient() { + File script = getScript(); + File baseDir = model.getProject().getBaseDir(); + + if (terminal == null) { + this.terminal = new TerminalExecutorMonitor(controller.getTerminalManager(), logFile); + } + if (service == null) { + this.service = Executors.newSingleThreadExecutor(); + } + + this.executor = Executor.script(script).description(actionName).inFolder(baseDir).inTerminal(terminal).inService(service).env(getEnvironment(model, logName)); + executor.exec(); + } + + private File getScript() { + File file = new File(model.getProject().getBaseDir(), Util.isWindows() ? RECONSTRUCT_MESH_BAT : RECONSTRUCT_MESH_RUN); + ScriptBuilder sb = new ScriptBuilder(); + writeScript(sb); + IOUtils.writeLinesToFile(file, sb.getLines()); + file.setExecutable(true); + return file; + } + + private void writeScript(ScriptBuilder sb) { + printHeader(sb, ACTION_NAME); + printVariables(sb); + loadEnvironment(sb); + writeCommand(sb); + } + + private void writeCommand(ScriptBuilder sb) { + boolean meshOnZero = model.getProject().isMeshOnZero(); + + if (meshOnZero) { + if (model.getProject().getZeroFolder().hasRegions()) { + sb.append(RECONSTRUCT_PAR_MESH_ALLREGIONS()); + } else { + sb.append(RECONSTRUCT_PAR_MESH()); + } + } else { + if (model.getProject().getZeroFolder().hasRegions()) { + sb.append(RECONSTRUCT_PAR_MESH_CONSTANT_ALLREGIONS()); + } else { + sb.append(RECONSTRUCT_PAR_MESH_CONSTANT()); + } + } + } + +} diff --git a/src/eu/engys/core/controller/actions/RunCase.java b/src/eu/engys/core/controller/actions/RunCase.java index 05bbd68..7104e7e 100644 --- a/src/eu/engys/core/controller/actions/RunCase.java +++ b/src/eu/engys/core/controller/actions/RunCase.java @@ -1,57 +1,43 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.controller.actions; -import static eu.engys.core.project.system.ControlDict.CONTROL_DICT; -import static eu.engys.core.project.system.ControlDict.END_TIME_KEY; -import static eu.engys.core.project.system.ControlDict.STOP_AT_KEY; -import static eu.engys.core.project.system.ControlDict.WRITE_NOW_KEY; - import java.io.File; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import eu.engys.core.controller.Command; import eu.engys.core.controller.Controller; import eu.engys.core.controller.ScriptFactory; -import eu.engys.core.dictionary.DictionaryUtils; import eu.engys.core.executor.ExecutorHook; import eu.engys.core.executor.ExecutorMonitor; import eu.engys.core.project.Model; import eu.engys.core.project.SolverState; import eu.engys.core.project.openFOAMProject; import eu.engys.core.project.state.ServerState; -import eu.engys.core.project.system.ControlDict; -import eu.engys.util.PrefUtil; public class RunCase extends AbstractRunCommand { - private static final Logger logger = LoggerFactory.getLogger(RunCase.class); - public static final String ACTION_NAME = "Run Case"; public static final String RUNNING_LABEL = "Running: "; @@ -67,7 +53,8 @@ public class RunCase extends AbstractRunCommand { setupLogFolder(); setupPostProcFolder(); clearPolyMesh(); - setStopAtVariableToEndTime(); + + new Stopper(model, executor).setStopAtVariableToEndTime(); } private void setupLogFolder() { @@ -87,41 +74,8 @@ public class RunCase extends AbstractRunCommand { } @Override - public void stop() throws TimeoutException { - int stop_refresh_time = PrefUtil.getInt(PrefUtil.SERVER_CONNECTION_REFRESH_TIME, 1000); - int stop_max_tries = PrefUtil.getInt(PrefUtil.SERVER_CONNECTION_MAX_TRIES, 60); - - int tryIndex = 0; - while (this.executor.getState().isDoingSomething() && (tryIndex < stop_max_tries)) { - try { - Thread.sleep(stop_refresh_time); - } catch (Exception e) { - } - setStopAtVariableToWriteNow(); - tryIndex++; - } - if (tryIndex >= stop_max_tries) { - throw new TimeoutException("Timeout stopping solver"); - } - setStopAtVariableToEndTime(); - } - - private void setStopAtVariableToWriteNow() { - File systemFolder = model.getProject().getSystemFolder().getFileManager().getFile(); - ControlDict controlDict = new ControlDict(new File(systemFolder, CONTROL_DICT)); - controlDict.add(STOP_AT_KEY, WRITE_NOW_KEY); - controlDict.functionObjectsToList(); - DictionaryUtils.writeDictionary(systemFolder, controlDict, null); - } - - private void setStopAtVariableToEndTime() { - File systemFolder = model.getProject().getSystemFolder().getFileManager().getFile(); - ControlDict controlDict = new ControlDict(new File(systemFolder, CONTROL_DICT)); - if (controlDict.found(STOP_AT_KEY) && controlDict.lookup(STOP_AT_KEY).equals(WRITE_NOW_KEY)) { - controlDict.add(STOP_AT_KEY, END_TIME_KEY); - controlDict.functionObjectsToList(); - DictionaryUtils.writeDictionary(systemFolder, controlDict, null); - } + public void stop() throws Exception { + new Stopper(model, executor).stop(); } protected class StartHook implements ExecutorHook { diff --git a/src/eu/engys/core/controller/actions/RunCommand.java b/src/eu/engys/core/controller/actions/RunCommand.java index 7e45ed2..056747d 100644 --- a/src/eu/engys/core/controller/actions/RunCommand.java +++ b/src/eu/engys/core/controller/actions/RunCommand.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.controller.actions; import java.util.concurrent.ExecutorService; @@ -40,9 +39,9 @@ public interface RunCommand { public void executeServer(Server server) throws CommandException; - public String executeQueue(Server server) throws CommandException; + public void executeQueue(Server server) throws CommandException; - public void stop() throws TimeoutException; + public void stop() throws Exception; public void kill(); @@ -52,4 +51,5 @@ public interface RunCommand { public boolean isRunning(); + public String getJobID(); } diff --git a/src/eu/engys/core/controller/actions/RunMesh.java b/src/eu/engys/core/controller/actions/RunMesh.java index cbfebd9..65764b8 100644 --- a/src/eu/engys/core/controller/actions/RunMesh.java +++ b/src/eu/engys/core/controller/actions/RunMesh.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.controller.actions; import static eu.engys.core.project.openFOAMProject.LOG; @@ -42,6 +41,7 @@ public class RunMesh extends AbstractRunCommand { public static final String LOG_NAME = "snappyHexMesh.log"; protected final ScriptFactory scriptFactory; + protected File logFile; public RunMesh(Model model, Controller controller, ScriptFactory scriptFactory) { super(model, controller); @@ -50,7 +50,8 @@ public class RunMesh extends AbstractRunCommand { @Override public void beforeExecute() { - IOUtils.clearFile(Paths.get(model.getProject().getBaseDir().getAbsolutePath(), LOG, LOG_NAME).toFile()); + this.logFile = Paths.get(model.getProject().getBaseDir().getAbsolutePath(), LOG, LOG_NAME).toFile(); + IOUtils.clearFile(logFile); clearPolyMesh(); setupLogFolder(); fixDecomposeParDict(model); diff --git a/src/eu/engys/core/controller/actions/StandardInitialiseFields.java b/src/eu/engys/core/controller/actions/StandardInitialiseFields.java index 0cb18c8..7849f88 100644 --- a/src/eu/engys/core/controller/actions/StandardInitialiseFields.java +++ b/src/eu/engys/core/controller/actions/StandardInitialiseFields.java @@ -1,50 +1,55 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.controller.actions; import static eu.engys.core.OpenFOAMEnvironment.getEnvironment; +import static eu.engys.core.controller.AbstractScriptFactory.INITIALISE_FIELDS_PARALLEL_BAT; +import static eu.engys.core.controller.AbstractScriptFactory.INITIALISE_FIELDS_PARALLEL_RUN; +import static eu.engys.core.controller.AbstractScriptFactory.INITIALISE_FIELDS_SERIAL_BAT; +import static eu.engys.core.controller.AbstractScriptFactory.INITIALISE_FIELDS_SERIAL_RUN; import java.io.File; import java.nio.file.Paths; import java.util.concurrent.ExecutorService; +import org.apache.commons.io.FileUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import eu.engys.core.controller.Controller; -import eu.engys.core.controller.Controller.OpenOptions; +import eu.engys.core.controller.Controller.OpenMode; +import eu.engys.core.controller.KillCommandOS; import eu.engys.core.controller.ScriptFactory; import eu.engys.core.executor.Executor; import eu.engys.core.executor.ExecutorHook; import eu.engys.core.executor.ExecutorListener.ExecutorState; import eu.engys.core.executor.ExecutorMonitor; -import eu.engys.core.executor.ExecutorTerminal; import eu.engys.core.executor.TerminalExecutorMonitor; import eu.engys.core.project.Model; import eu.engys.core.project.openFOAMProject; +import eu.engys.util.Util; public class StandardInitialiseFields extends InitialiseFields { @@ -53,27 +58,36 @@ public class StandardInitialiseFields extends InitialiseFields { public StandardInitialiseFields(Model model, Controller controller, ScriptFactory scriptFactory) { super(model, controller, scriptFactory); } + + @Override + public void beforeExecute() { + super.beforeExecute(); + FileUtils.deleteQuietly(new File(model.getProject().getBaseDir(), Util.isWindowsScriptStyle() ? INITIALISE_FIELDS_SERIAL_BAT : INITIALISE_FIELDS_SERIAL_RUN)); + FileUtils.deleteQuietly(new File(model.getProject().getBaseDir(), Util.isWindowsScriptStyle() ? INITIALISE_FIELDS_PARALLEL_BAT : INITIALISE_FIELDS_PARALLEL_RUN)); + } @Override public void executeClient() { logger.debug("EXECUTE IN CLIENT"); - File script = scriptFactory.getInitialiseScript(model); File baseDir = model.getProject().getBaseDir(); File logFile = Paths.get(baseDir.getAbsolutePath(), openFOAMProject.LOG, LOG_NAME).toFile(); - - ExecutorTerminal terminal = new TerminalExecutorMonitor(logFile); + ExecutorMonitor monitor = new ExecutorMonitor(); - ExecutorService service = Executor.newExecutor(ACTION_NAME); monitor.addHook(ExecutorState.FINISH, new FinishHook()); + + ExecutorService service = Executor.newExecutor(ACTION_NAME); - this.executor = Executor.script(script).description(ACTION_NAME).inFolder(baseDir).inTerminal(terminal).withMonitors(monitor).inService(service).env(getEnvironment(model, LOG_NAME)).keepFileOnEnd(); + TerminalExecutorMonitor terminal = new TerminalExecutorMonitor(controller.getTerminalManager(), logFile); + terminal.setStopCommand(new KillCommandOS(controller)); + + this.executor = Executor.script(scriptFactory.getInitialiseScript(model)).description(ACTION_NAME).inFolder(baseDir).inTerminal(terminal).withMonitors(monitor).inService(service).env(getEnvironment(model, LOG_NAME)); executor.exec(); } private class FinishHook implements ExecutorHook { @Override public void run(ExecutorMonitor m) { - controller.reopenCase(OpenOptions.CURRENT_SETTINGS); + controller.reopenCase(OpenMode.CURRENT_SETTINGS); } } diff --git a/src/eu/engys/core/controller/actions/StandardRunCase.java b/src/eu/engys/core/controller/actions/StandardRunCase.java index fb18cca..289d683 100644 --- a/src/eu/engys/core/controller/actions/StandardRunCase.java +++ b/src/eu/engys/core/controller/actions/StandardRunCase.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.controller.actions; import static eu.engys.core.OpenFOAMEnvironment.getEnvironment; @@ -59,19 +58,19 @@ public class StandardRunCase extends RunCase { @Override public void executeClient() { logger.debug("EXECUTE IN CLIENT"); - File logFile = Paths.get(model.getProject().getBaseDir().getAbsolutePath(), openFOAMProject.LOG, model.getSolverModel().getLogFile()).toFile(); - TerminalExecutorMonitor terminal = new TerminalExecutorMonitor(logFile); - terminal.setStopCommand(new StopOrKillCommandOS(controller)); - + File baseDir = model.getProject().getBaseDir(); + File logFile = Paths.get(baseDir.getAbsolutePath(), openFOAMProject.LOG, model.getSolverModel().getLogFile()).toFile(); + ExecutorMonitor monitor = new ExecutorMonitor(); monitor.addHook(ExecutorState.START, new StartHook()); monitor.addHook(ExecutorState.RUNNING, new RunningHook()); - monitor.addHook(ExecutorState.FINISH, new FinishHook()); monitor.addHook(ExecutorState.ERROR, new ErrorHook()); + monitor.addHook(ExecutorState.FINISH, new FinishHook()); ExecutorService service = Executor.newExecutor(ACTION_NAME); - File baseDir = model.getProject().getBaseDir(); + TerminalExecutorMonitor terminal = new TerminalExecutorMonitor(controller.getTerminalManager(), logFile); + terminal.setStopCommand(new StopOrKillCommandOS(controller)); this.executor = Executor.script(scriptFactory.getSolverScript(model)).description(ACTION_NAME).inFolder(baseDir).inTerminal(terminal).withMonitors(monitor).inService(service).env(getEnvironment(model, model.getSolverModel().getLogFile())).keepFileOnEnd(); executor.exec(); @@ -91,14 +90,14 @@ public class StandardRunCase extends RunCase { } } - protected class FinishHook implements ExecutorHook { + private class FinishHook implements ExecutorHook { @Override public void run(ExecutorMonitor m) { model.getSolverModel().setServerState(new ServerState(Command.RUN_CASE, SolverState.FINISHED)); } } - protected class ErrorHook implements ExecutorHook { + private class ErrorHook implements ExecutorHook { @Override public void run(ExecutorMonitor m) { model.getSolverModel().setServerState(new ServerState(Command.RUN_CASE, SolverState.ERROR)); diff --git a/src/eu/engys/core/controller/actions/StandardRunMesh.java b/src/eu/engys/core/controller/actions/StandardRunMesh.java index 498ce38..b3d8fd9 100644 --- a/src/eu/engys/core/controller/actions/StandardRunMesh.java +++ b/src/eu/engys/core/controller/actions/StandardRunMesh.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.controller.actions; import static eu.engys.core.OpenFOAMEnvironment.getEnvironment; @@ -35,6 +34,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import eu.engys.core.controller.Controller; +import eu.engys.core.controller.KillCommandOS; import eu.engys.core.controller.ScriptFactory; import eu.engys.core.executor.Executor; import eu.engys.core.executor.ExecutorHook; @@ -63,7 +63,10 @@ public class StandardRunMesh extends RunMesh { ExecutorService service = Executor.newExecutor(ACTION_NAME); - this.executor = Executor.script(scriptFactory.getMeshScript(model)).description(ACTION_NAME).inFolder(baseDir).inService(service).inTerminal(new TerminalExecutorMonitor(logFile)).withMonitors(monitor).env(getEnvironment(model, LOG_NAME)).keepFileOnEnd(); + TerminalExecutorMonitor terminal = new TerminalExecutorMonitor(controller.getTerminalManager(), logFile); + terminal.setStopCommand(new KillCommandOS(controller)); + + this.executor = Executor.script(scriptFactory.getMeshScript(model)).description(ACTION_NAME).inFolder(baseDir).inService(service).inTerminal(terminal).withMonitors(monitor).env(getEnvironment(model, LOG_NAME)).keepFileOnEnd(); executor.exec(); } diff --git a/src/eu/engys/core/controller/actions/StopCommandInfo.java b/src/eu/engys/core/controller/actions/StopCommandInfo.java index 76a1664..c8f6f7b 100644 --- a/src/eu/engys/core/controller/actions/StopCommandInfo.java +++ b/src/eu/engys/core/controller/actions/StopCommandInfo.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.controller.actions; import org.slf4j.Logger; @@ -34,6 +33,8 @@ public class StopCommandInfo extends CommandInfo { private static final Logger logger = LoggerFactory.getLogger(StopCommandInfo.class); + public static final String TIMEOUT = "Timeout"; + public boolean timeout; public static StopCommandInfo wrap(CommandInfo info) { @@ -48,7 +49,7 @@ public class StopCommandInfo extends CommandInfo { public static StopCommandInfo timeoutException(Exception e) { logger.error(">>> SERVER STOP ERROR", e); StopCommandInfo ci = new StopCommandInfo(); - ci.message = "Timeout"; + ci.message = TIMEOUT; ci.exception = e; ci.success = false; ci.timeout = true; diff --git a/src/eu/engys/core/controller/actions/Stopper.java b/src/eu/engys/core/controller/actions/Stopper.java new file mode 100644 index 0000000..bd84f9a --- /dev/null +++ b/src/eu/engys/core/controller/actions/Stopper.java @@ -0,0 +1,100 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.core.controller.actions; + +import static eu.engys.core.project.system.ControlDict.CONTROL_DICT; +import static eu.engys.core.project.system.ControlDict.END_TIME_KEY; +import static eu.engys.core.project.system.ControlDict.STOP_AT_KEY; +import static eu.engys.core.project.system.ControlDict.WRITE_NOW_KEY; + +import java.io.File; + +import eu.engys.core.dictionary.DictionaryUtils; +import eu.engys.core.executor.Executor; +import eu.engys.core.project.Model; +import eu.engys.core.project.system.ControlDict; +import eu.engys.util.PrefUtil; + +public class Stopper { + + protected Executor executor; + protected Model model; + + public Stopper(Model model, Executor executor) { + this.model = model; + this.executor = executor; + } + + public void stop() throws Exception { + setStopAtVariableToWriteNow(); + + waitForExecutorToStop(); + + setStopAtVariableToEndTime(); + } + + protected void waitForExecutorToStop() throws Exception { + int stop_refresh_time = PrefUtil.getInt(PrefUtil.SERVER_CONNECTION_REFRESH_TIME, 1000); + int stop_max_tries = PrefUtil.getInt(PrefUtil.SERVER_CONNECTION_MAX_TRIES, 60); + + int tryIndex = 0; + while (this.executor.getState().isDoingSomething() && (tryIndex < stop_max_tries)) { + try { + Thread.sleep(stop_refresh_time); + } catch (Exception e) { + } + tryIndex++; + } + if (tryIndex >= stop_max_tries) { + throw new TimeoutException("Timeout stopping solver"); + } + } + + private void setStopAtVariableToWriteNow() { + File systemFolder = model.getProject().getSystemFolder().getFileManager().getFile(); + ControlDict controlDict = new ControlDict(new File(systemFolder, CONTROL_DICT)); + controlDict.add(STOP_AT_KEY, WRITE_NOW_KEY); + DictionaryUtils.writeDictionary(systemFolder, controlDict, null); + + ControlDict readControlDict = new ControlDict(new File(systemFolder, CONTROL_DICT)); + if(!readControlDict.found(STOP_AT_KEY) || !readControlDict.lookup(STOP_AT_KEY).equals(WRITE_NOW_KEY)){ + try { + Thread.sleep(500L); + } catch (Exception e) { + } + setStopAtVariableToWriteNow(); + } + } + + void setStopAtVariableToEndTime() { + File systemFolder = model.getProject().getSystemFolder().getFileManager().getFile(); + ControlDict controlDict = new ControlDict(new File(systemFolder, CONTROL_DICT)); + if (controlDict.found(STOP_AT_KEY) && controlDict.lookup(STOP_AT_KEY).equals(WRITE_NOW_KEY)) { + controlDict.add(STOP_AT_KEY, END_TIME_KEY); + DictionaryUtils.writeDictionary(systemFolder, controlDict, null); + } + } + +} \ No newline at end of file diff --git a/src/eu/engys/core/controller/actions/TimeoutException.java b/src/eu/engys/core/controller/actions/TimeoutException.java index 66a8ae3..2ba956f 100644 --- a/src/eu/engys/core/controller/actions/TimeoutException.java +++ b/src/eu/engys/core/controller/actions/TimeoutException.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.controller.actions; public class TimeoutException extends Exception { diff --git a/src/eu/engys/core/dictionary/BeanToDict.java b/src/eu/engys/core/dictionary/BeanToDict.java index c27988a..159a628 100644 --- a/src/eu/engys/core/dictionary/BeanToDict.java +++ b/src/eu/engys/core/dictionary/BeanToDict.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.dictionary; import java.io.File; @@ -130,7 +129,7 @@ public class BeanToDict { for (Method m : methods) { String fieldName = ""; - if (m.getName().startsWith("get") && !m.getName().startsWith("getClass")) { + if (m.getName().startsWith("get") && !m.getName().startsWith("getClass") && m.getParameterTypes().length == 0) { fieldName = getFieldNameFromGetter(m); } else if (m.getName().startsWith("is")) { fieldName = getFieldNameFromBooleanGetter(m); @@ -143,7 +142,7 @@ public class BeanToDict { addToDictionary(dictionary, fieldName, value); } } catch (Exception ex) { - ex.printStackTrace(); + logger.error("Error invoking method {}", m, ex); } } return dictionary; @@ -225,6 +224,10 @@ public class BeanToDict { return dict; } +// public static Map dictToMap(Dictionary dictionary, B bean) { +// +// } + private static String toArray(Object array) throws Exception { return toBracketedArrayOfStrings(array); } diff --git a/src/eu/engys/core/dictionary/BlockMeshWriter.java b/src/eu/engys/core/dictionary/BlockMeshWriter.java index 6670671..11908a0 100644 --- a/src/eu/engys/core/dictionary/BlockMeshWriter.java +++ b/src/eu/engys/core/dictionary/BlockMeshWriter.java @@ -1,39 +1,37 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.dictionary; import static eu.engys.core.dictionary.Dictionary.SPACER; import static eu.engys.core.dictionary.Dictionary.TAB; import static eu.engys.core.dictionary.Dictionary.VERBOSE; + import eu.engys.core.dictionary.parser.ListField2; public class BlockMeshWriter extends DictionaryWriter { - public BlockMeshWriter(Dictionary dictionary) { super(dictionary); } @@ -50,10 +48,10 @@ public class BlockMeshWriter extends DictionaryWriter { BlockMeshWriter writer = new BlockMeshWriter(dictionary.getFoamFile()); writer.writeDictionary(sb, ""); -// if (dictionary.isList("")) { -// ListField.class.cast(dictionary.getList()).writeListDict(sb, rowHeader); -// return; -// } + // if (dictionary.isList("")) { + // ListField.class.cast(dictionary.getList()).writeListDict(sb, rowHeader); + // return; + // } } else { sb.append("\n"); sb.append(rowHeader); @@ -66,7 +64,7 @@ public class BlockMeshWriter extends DictionaryWriter { DefaultElement ele = dictionary.getElement(key); write(sb, rowHeader, ele); } - + for (String includeFile : dictionary.getIncludeFiles()) { writeInclude(sb, includeFile, rowHeader); } @@ -105,16 +103,18 @@ public class BlockMeshWriter extends DictionaryWriter { private static void writeDimensionedScalar(StringBuffer sb, DimensionedScalar ds, String rowHeader) { if (VERBOSE) System.out.println("Dictionary.writeDimensionedScalar() " + (ds != null ? ds.getName() : "NULL!!!")); - sb.append("\n"); - sb.append(rowHeader); - sb.append(TAB); - sb.append(ds.getName()); - sb.append(SPACER); - sb.append(ds.getName()); - sb.append(SPACER); - sb.append(ds.getDimensions()); - sb.append(SPACER); - sb.append(ds.getValue()); - sb.append(";"); + if (ds != null) { + sb.append("\n"); + sb.append(rowHeader); + sb.append(TAB); + sb.append(ds.getName()); + sb.append(SPACER); + sb.append(ds.getName()); + sb.append(SPACER); + sb.append(ds.getDimensions()); + sb.append(SPACER); + sb.append(ds.getValue()); + sb.append(";"); + } } } diff --git a/src/eu/engys/core/dictionary/DefaultElement.java b/src/eu/engys/core/dictionary/DefaultElement.java index 0fb3d97..da4885e 100644 --- a/src/eu/engys/core/dictionary/DefaultElement.java +++ b/src/eu/engys/core/dictionary/DefaultElement.java @@ -1,39 +1,40 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.dictionary; -public class DefaultElement { +import org.apache.commons.lang.builder.EqualsBuilder; +import org.apache.commons.lang.builder.HashCodeBuilder; + +public abstract class DefaultElement { private String name; - + public DefaultElement(String name) { this.name = name; } - + public String getName() { return name; } @@ -41,12 +42,21 @@ public class DefaultElement { public void setName(String name) { this.name = name; } - + @Override public boolean equals(Object obj) { - if (obj instanceof DefaultElement) { - return ((DefaultElement) obj).name.equals(name); - } - return super.equals(obj); + if (!(obj instanceof DefaultElement)) { + return false; + } + if (obj == this) { + return true; + } + DefaultElement fz = (DefaultElement) obj; + return new EqualsBuilder().append(name, fz.name).isEquals(); + } + + @Override + public int hashCode() { + return new HashCodeBuilder(17, 31).append(name).toHashCode(); } } diff --git a/src/eu/engys/core/dictionary/Dictionary.java b/src/eu/engys/core/dictionary/Dictionary.java index 3511d55..e6e13db 100644 --- a/src/eu/engys/core/dictionary/Dictionary.java +++ b/src/eu/engys/core/dictionary/Dictionary.java @@ -1,807 +1,971 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.dictionary; import java.io.File; import java.io.InputStream; import java.util.ArrayList; import java.util.LinkedHashMap; +import java.util.LinkedList; import java.util.List; import java.util.Map; +import javax.vecmath.Point3d; + import org.apache.commons.lang.ArrayUtils; +import org.apache.commons.lang.builder.EqualsBuilder; +import org.apache.commons.lang.builder.HashCodeBuilder; import eu.engys.core.dictionary.parser.ListField2; import eu.engys.core.dictionary.parser.ThetaListField2; public class Dictionary extends DefaultElement { - public static boolean VERBOSE = false; + public static boolean VERBOSE = false; - public static final String SPACER = " "; - public static final String TAB = " "; + public static final String SPACER = " "; + public static final String TAB = " "; - public static final String DICTIONARY_LINK = "DICTIONARY_LINK"; - public static final String VALUE_LINK = "VALUE_LINK"; - public static final String VALUE_UNIFORM_LINK = "VALUE_UNIFORM_LINK"; + public static final String DICTIONARY_LINK = "DICTIONARY_LINK"; + public static final String VALUE_LINK = "VALUE_LINK"; + public static final String VALUE_UNIFORM_LINK = "VALUE_UNIFORM_LINK"; - public static final String TYPE = "type"; - public static final String VALUE = "value"; + public static final String TYPE = "type"; + public static final String VALUE = "value"; + public static final String CONSTANT = "constant"; + public static final String NONUNIFORM = "nonuniform"; + public static final String UNIFORM = "uniform"; - private FoamFile foamFile; + private FoamFile foamFile; - private Map elements = new LinkedHashMap(); - private List keys = new ArrayList(); - private List genericKeys = new ArrayList(); - private List includeFiles = new ArrayList(); + private Map elements = new LinkedHashMap(); + private List keys = new ArrayList(); + private List genericKeys = new ArrayList(); + private List includeFiles = new ArrayList(); - public Dictionary(String name, File file) { - super(name); - readDictionary(file); - } - - public Dictionary(File file) { - this(file.getName(), file); - } - - - public Dictionary(String name, InputStream input, DictionaryLinkResolver resolver) { - super(name); - readDictionary(input, resolver); - } - - public Dictionary(String name, InputStream input) { - super(name); - readDictionary(input); - } - - public Dictionary(String name) { - super(name); - } - - public Dictionary(Dictionary d) { - this(d.getName(), d); - } - - public Dictionary(String name, Dictionary d) { - super(name); - setFoamFile(d.getFoamFile()); - for (String key : d.keys) { - DefaultElement el = d.elements.get(key); - if (el instanceof Dictionary) { - add(new Dictionary((Dictionary) el)); - } else if (el instanceof DimensionedScalar) { - DimensionedScalar ds = (DimensionedScalar) el; - add(new DimensionedScalar(ds)); - } else if (el instanceof FieldElement) { - FieldElement f = (FieldElement) el; - add(f.getName(), f.getValue()); - } else if (el instanceof ListField) { - ListField lf = (ListField) el; - add(lf.getName(), new ListField(lf)); - } else if (el instanceof ThetaListField2) { - ThetaListField2 tf = (ThetaListField2) el; - add(tf.getName(), new ThetaListField2(tf)); - } else if (el instanceof ListField2) { - ListField2 lf = (ListField2) el; - add(lf.getName(), new ListField2(lf)); - } - } - genericKeys.addAll(d.genericKeys); - } - - public void setFoamFile(FoamFile file) { - if (found("FoamFile")) - remove("FoamFile"); - this.foamFile = file; - } - - public FoamFile getFoamFile() { - return foamFile; - } - - public void check() throws DictionaryException { - } - - public void include(String includeFile) { - includeFiles.add(includeFile); - } - - private void put(String key, DefaultElement value) { - elements.put(key, value); - if (!keys.contains(key)) - keys.add(key); - } - - public void add(DefaultElement el) { - put(el.getName(), el); - } - - public void addGeneric(DefaultElement el) { - String name = el.getName(); - if (!genericKeys.contains(name)) { - genericKeys.add(name); - } - put(name, el); - } - - public void add(Dictionary dictionary) { - put(dictionary.getName(), dictionary); - } - - public void addToList(Dictionary dictionary) { - addToList("", dictionary); - } - - public void addToList(String listName, Dictionary dictionary) { - ListField list = getList(listName); - if (list == null) { - list = new ListField(listName); - add(list); - } - list.add(dictionary); - } - - public void addToList(String listName, FieldElement fe) { - ListField list = getList(listName); - if (list == null) { - list = new ListField(listName); - add(list); - } - list.add(fe); - } - - public void add(String name, String value) { - put(name, new FieldElement(name, value)); - } - -// public void add(Finder finder, String value) { -// String key = findKey(finder); -// put(key, new FieldElement(key, value)); -// } - - public void addGeneric(String name, String value) { - if (!genericKeys.contains(name)) { - genericKeys.add(name); - } - put(name, new FieldElement(name, value)); - } - - public void add(String name, double[] values) { - StringBuffer sb = new StringBuffer("("); - for (double d : values) { - sb.append(String.valueOf(d) + " "); - } - sb.append(")"); - this.add(name, sb.toString()); - } - - public void add(String name, int[] values) { - StringBuffer sb = new StringBuffer("("); - for (int d : values) { - sb.append(String.valueOf(d) + " "); - } - sb.append(")"); - this.add(name, sb.toString()); - } - - public void add(String name, String[] values) { - StringBuffer sb = new StringBuffer("("); - for (String p : values) { - sb.append(p + " "); - } - sb.append(")"); - this.add(name, sb.toString()); - } - - public void add(String name, List values) { - this.add(name, values.toArray(new String[0])); - } - - public void add(DimensionedScalar ds) { - put(ds.getName(), ds); - } - - public void add(String name, ListField list) { - put(name, list); - } - - public void add(String name, ListField2 list) { - put(name, list); - } - - public void add(ListField list) { - put(list.getName(), list); - } - - private String findKey(Finder finder) { - for (String key : keys) { - if (finder.accept(key)) { - return key; - } - } - return null; - } - - public boolean found(Finder finder) { - String key = findKey(finder); - return key != null; - } - - public boolean found(String name) { - if (foundGeneric(name)) - return true; - else - return keys.contains(name); - } - - private boolean foundGeneric(String name) { - if (!genericKeys.isEmpty()) { - for (String genericKey : genericKeys) { - if (("\"" + name + "\"").matches(genericKey)) { - return true; - } - } - } - return false; - } - - DefaultElement getElement(String name) { - if (elements.containsKey(name)) - return elements.get(name); - - if (!genericKeys.isEmpty()) { - for (String genericKey : genericKeys) { - if (("\"" + name + "\"").matches(genericKey)) { - return elements.get(genericKey); - } - } - } - return null; - } - - public boolean isDictionary(String name) { - DefaultElement el = getElement(name); - return (el != null && el instanceof Dictionary); - } - - public boolean isField(String name) { - DefaultElement el = getElement(name); - return (el != null && el instanceof FieldElement); - } - - public boolean isList(String name) { - DefaultElement el = getElement(name); - return (el != null && el instanceof ListField); - } - - public boolean isList2(String name) { - DefaultElement el = getElement(name); - return (el != null && el instanceof ListField2); - } - - public boolean isThetaList2(String name) { - DefaultElement el = getElement(name); - return (el != null && el instanceof ThetaListField2); - } - - public Dictionary subDict(String name) { - DefaultElement el = getElement(name); - if (isDictionary(name)) { - return (Dictionary) el; - } else if (el != null) - throw new DictionaryException(name + " not a dictionary"); - else - return null; - } - -// public ListField getList() { -// return getList(""); -// } -// -// public ListField2 getList2() { -// return getList2(""); -// } - - public ListField getList(String name) { - DefaultElement el = getElement(name); - if (isList(name)) { - return (ListField) el; - } else if (el != null) - throw new DictionaryException(name + " not a list"); - else - return null; - } - - public ListField2 getList2(String name) { - DefaultElement el = getElement(name); - if (isList2(name)) { - return (ListField2) el; - } else if (el != null) - throw new DictionaryException(name + " not a list"); - else - return null; - } - - public ThetaListField2 getThetaList2(String name) { - DefaultElement el = getElement(name); - if (isThetaList2(name)) { - return (ThetaListField2) el; - } else if (el != null) - throw new DictionaryException(name + " not a theta list"); - else - return null; - } - - public DefaultElement lookup(Finder finder) { - String key = findKey(finder); - if (key == null) { - throw new DictionaryException("Key " + key + " is NULL"); - } - - return getElement(key); - } - - public String lookup(String key) { - return lookupString(key); - } - - public String lookupString(String key) { - if (key == null) { - throw new DictionaryException("Key " + key + " is NULL"); - } - DefaultElement el = getElement(key); - if (isField(key)) { - return ((FieldElement) el).getValue(); - } else if (el != null) - throw new DictionaryException(key + " not a field"); - else - return null; - } - - public int lookupInt(String name) { - String value = lookupString(name); - try { - return Integer.parseInt(value); - } catch (NumberFormatException e) { - return -1; - } - } - - public double lookupDouble(String name) { - String value = lookupString(name); - try { - return Double.parseDouble(value); - } catch (NumberFormatException e) { - return Double.NaN; - } - } - - public DimensionedScalar lookupScalar(String name) { - DefaultElement el = getElement(name); - if (el != null && el instanceof DimensionedScalar) { - return (DimensionedScalar) el; - } else if (el != null) - throw new DictionaryException(name + " not a dimensioned scalar"); - else - return null; - } - - public String[] lookupArray(String name) { - DefaultElement el = getElement(name); - if (el != null && el instanceof FieldElement) { - String value = ((FieldElement) el).getValue(); - if (value.startsWith("uniform")) { - value = value.replace("uniform", "").trim(); - } - if (value.startsWith("nonuniform")) { - return new String[] { "Infinity", "Infinity", "Infinity" }; - } - if (value.startsWith("(") && value.endsWith(")")) { - value = value.replace("(", "").replace(")", "").trim(); - // value = value.substring(1, value.length()-1); - if (value.isEmpty()) { - return new String[0]; - } - String[] values = value.split(SPACER); - // System.out.println("Dictionary.lookupArray() "+Arrays.toString(values)); - return values; - } else - throw new DictionaryException(name + " not an array"); - } else if (el != null) - throw new DictionaryException(name + " not a field"); - else - return null; - } - - public String[][] lookupMatrix(String name) { - DefaultElement el = getElement(name); - if (el != null && el instanceof FieldElement) { - String value = ((FieldElement) el).getValue(); - if (value.startsWith("uniform")) { - value = value.replace("uniform", "").trim(); - } - if (value.startsWith("(") && value.endsWith(")")) { - value = value.replaceAll("\\(\\s*\\(", ""); - value = value.replaceAll("\\)\\s*\\)", ""); - - String[] values = value.split("\\)\\s*\\("); - String[][] matrix = new String[values.length][]; - for (int r = 0; r < values.length; r++) { - String[] row = values[r].trim().split("\\s+"); - matrix[r] = row; - } - return matrix; - } else - throw new DictionaryException(name + " not an array"); - } else if (el != null) - throw new DictionaryException(name + " not a field"); - else - return null; - } - - public String[] lookupArray2(String name) { - DefaultElement el = getElement(name); - if (el != null && el instanceof ListField2) { - ListField2 list = (ListField2) el; - return listToArray(list); - } else if (el != null) - throw new DictionaryException(name + " not a field"); - else - return null; - } - - private String[] listToArray(ListField2 list) { - List elements = list.getListElements(); - - String[] values = new String[elements.size()]; - - for (int i = 0; i < elements.size(); i++) { - DefaultElement element = elements.get(i); - if (element instanceof FieldElement) { - String value = ((FieldElement) element).getValue(); - values[i] = value; - } else if (element instanceof ListField2) { - String[] listField = listToArray((ListField2) element); - values[i] = "("; - for (int j = 0; j < listField.length; j++) { - values[i] += listField[j] + " "; - } - values[i] += ")"; - } - } - return values; - } - - public String[][] lookupMatrix2(String name) { - DefaultElement el = getElement(name); - if (el != null && el instanceof ListField2) { - ListField2 list = (ListField2) el; - return listToMatrix(list); - } else if (el != null) { - throw new DictionaryException(name + " not a field"); - } else { - return null; - } - } - - private String[][] listToMatrix(ListField2 list) { - List rows = list.getListElements(); - if (rows.size() > 0 && rows.get(0) instanceof ListField2) { - ListField2 firstRow = (ListField2) rows.get(0); - String[][] values = new String[rows.size()][firstRow.getListElements().size()]; - - for (int i = 0; i < rows.size(); i++) { - if (rows.get(i) instanceof ListField2) { - ListField2 row = (ListField2) rows.get(i); - values[i] = listToArray(row); - } - } - return values; - } else { - return new String[0][0]; - } - } - - public double[] lookupDoubleArray(String name) { - String[] array = lookupArray(name); - double[] doubleArray = new double[array.length]; - for (int i = 0; i < doubleArray.length; i++) { - try { - doubleArray[i] = Double.valueOf(array[i]); - } catch (NumberFormatException e) { - } - } - return doubleArray; - } - - public double[] lookupDoubleArray2(String name) { - String[] array = lookupArray2(name); - double[] doubleArray = new double[array.length]; - for (int i = 0; i < doubleArray.length; i++) { - try { - doubleArray[i] = Double.valueOf(array[i]); - } catch (NumberFormatException e) { - } - } - return doubleArray; - } - - public double[][] lookupDoubleMatrix(String name) { - String[][] matrix = lookupMatrix(name); - double[][] doubleMatrix = new double[matrix.length][matrix[0].length]; - for (int i = 0; i < doubleMatrix.length; i++) { - for (int j = 0; j < doubleMatrix[i].length; j++) { - try { - doubleMatrix[i][j] = Double.valueOf(matrix[i][j]); - } catch (NumberFormatException e) { - } - } - } - return doubleMatrix; - } - - public double[][] lookupDoubleMatrix2(String name) { - String[][] matrix = lookupMatrix2(name); - double[][] doubleMatrix = new double[matrix.length][matrix[0].length]; - for (int i = 0; i < doubleMatrix.length; i++) { - for (int j = 0; j < doubleMatrix[i].length; j++) { - try { - doubleMatrix[i][j] = Double.valueOf(matrix[i][j]); - } catch (NumberFormatException e) { - e.printStackTrace(); - } - } - } - return doubleMatrix; - } - - public int[] lookupIntArray(String name) { - String[] array = lookupArray(name); - int[] intArray = new int[array.length]; - for (int i = 0; i < intArray.length; i++) { - try { - intArray[i] = Integer.valueOf(array[i]); - } catch (NumberFormatException e) { - } - } - return intArray; - } - - public Dictionary removeDict(String name) { - keys.remove(name); - return (Dictionary) elements.remove(name); - } - - public DefaultElement remove(String name) { - keys.remove(name); - return elements.remove(name); - } - - public DefaultElement remove(Finder finder) { - String key = findKey(finder); - return remove(key); - } - - List getGenericKeys() { - return genericKeys; - } - - List getKeys() { - return keys; - } - - List getIncludeFiles() { - return includeFiles; - } - - public boolean isEmpty() { - return keys.isEmpty(); - } - - @Override - public String toString() { - return new DictionaryWriter(this).write(); - } - - public List getDictionaries() { - List list = new ArrayList(); - for (String key : keys) { - DefaultElement el = elements.get(key); - if (el instanceof Dictionary) { - list.add((Dictionary) el); - } - } - return list; - } - - public Map getDictionariesMap() { - Map map = new LinkedHashMap(); - for (String key : keys) { - DefaultElement el = elements.get(key); - if (el instanceof Dictionary) { - map.put(el.getName(), (Dictionary) el); - } - } - return map; - } - - public List getFields() { - List list = new ArrayList(); - for (DefaultElement el : elements.values()) { - if (el instanceof FieldElement) { - list.add((FieldElement) el); - } - } - return list; - } - - public List getListFields() { - List list = new ArrayList<>(); - for (DefaultElement el : elements.values()) { - if (el instanceof ListField) { - list.add((ListField) el); - } - } - return list; - } - - public boolean hasOnlyList(){ - return !getListFields().isEmpty() && getDictionaries().isEmpty() && getFieldsMap().isEmpty(); - } - - public boolean hasOnlyList2(){ - return !getListFields2().isEmpty() && getDictionaries().isEmpty() && getFieldsMap().isEmpty(); - } - - public List getListFields2() { - List list = new ArrayList<>(); - for (DefaultElement el : elements.values()) { - if (el instanceof ListField2) { - list.add((ListField2) el); - } - } - return list; - } - - public Map getFieldsMap() { - Map map = new LinkedHashMap(); - for (DefaultElement el : elements.values()) { - if (el instanceof FieldElement) { - FieldElement field = (FieldElement) el; - map.put(field.getName(), field.getValue()); - } - } - return map; - } - - public void merge(Dictionary dict) { - merge(dict, new String[0]); - } - - public void merge(Dictionary dict, String[] keysToExclude) { - if (dict == null) - return; - // System.out.println("Dictionary.merge(): "+dict); - for (String key : dict.getKeys()) { - if(ArrayUtils.contains(keysToExclude, key)){ - continue; - } - - DefaultElement ele = dict.getElement(key); - if (ele instanceof Dictionary) { - Dictionary d = (Dictionary) ele; - if (found(d.getName()) && isDictionary(d.getName())) { - subDict(d.getName()).merge(d); - } else { - add(new Dictionary(d.getName())); - subDict(d.getName()).merge(d); - } - } else if (ele instanceof ListField) { - ListField l = (ListField) ele; - if (found(l.getName()) && isList(l.getName())) { - getList(l.getName()).merge(l); - } else { - add(new ListField(l.getName())); - getList(l.getName()).merge(l); - } - } else if (ele instanceof ThetaListField2) { - ThetaListField2 t = (ThetaListField2) ele; - if (found(t.getName()) && isThetaList2(t.getName())) { - getThetaList2(t.getName()).merge(t); - } else { - add(new ThetaListField2(t)); - } - } else if (ele instanceof ListField2) { - ListField2 l = (ListField2) ele; - if (found(l.getName()) && isList2(l.getName())) { - getList2(l.getName()).merge(l); - } else { - add(new ListField2(l)); - } - } else if (ele instanceof FieldElement) { - FieldElement f = (FieldElement) ele; - if (f instanceof DimensionedScalar) { - add(new DimensionedScalar((DimensionedScalar) f)); - } else { - add(f.getName(), f.getValue()); - } - } - } - genericKeys.addAll(dict.genericKeys); + public Dictionary(String name, File file) { + super(name); + readDictionary(file); } - public void clear() { - elements.clear(); - keys.clear(); - } + public Dictionary(File file) { + this(file.getName(), file); + } - @Override - public boolean equals(Object obj) { - if (obj instanceof Dictionary) { - Dictionary d = (Dictionary) obj; - if (elements.size() != d.elements.size()) - return false; - for (String key : elements.keySet()) { - if (!elements.get(key).equals(d.elements.get(key))) - return false; - } - return true; - } - return false; - } + public Dictionary(String name, InputStream input, DictionaryLinkResolver resolver) { + super(name); + readDictionary(input, resolver); + } - /* * * * * * * * * * * * * - * READ/WRITE STUFF * * * * * * * * * * * * - */ + public Dictionary(String name, InputStream input) { + super(name); + readDictionary(input); + } - public void readDictionary(File file) { - DictionaryReader reader = new DictionaryReader(this); - reader.read(file); - } + public Dictionary(String name) { + super(name); + } - protected void readDictionary(InputStream input, DictionaryLinkResolver resolver) { - DictionaryReader reader = new DictionaryReader(this, resolver); - reader.read(input); - } + public Dictionary(Dictionary d) { + this(d.getName(), d); + } - protected void readDictionary(InputStream input) { - DictionaryReader reader = new DictionaryReader(this); - reader.read(input); - } + public Dictionary(String name, Dictionary d) { + super(name); + setFoamFile(d.getFoamFile()); + for (String key : d.keys) { + DefaultElement el = d.elements.get(key); + if (el instanceof Dictionary) { + add(new Dictionary((Dictionary) el)); + } else if (el instanceof DimensionedScalar) { + DimensionedScalar ds = (DimensionedScalar) el; + add(new DimensionedScalar(ds)); + } else if (el instanceof FieldElement) { + FieldElement f = (FieldElement) el; + add(f.getName(), f.getValue()); + } else if (el instanceof ListField) { + ListField lf = (ListField) el; + add(lf.getName(), new ListField(lf)); + } else if (el instanceof ThetaListField2) { + ThetaListField2 tf = (ThetaListField2) el; + add(tf.getName(), new ThetaListField2(tf)); + } else if (el instanceof ListField2) { + ListField2 lf = (ListField2) el; + add(lf.getName(), new ListField2(lf)); + } + } + genericKeys.addAll(d.genericKeys); + } - protected void readDictionaryFromString(String text) { - DictionaryReader reader = new DictionaryReader(this); - reader.read(text); - } + public void setFoamFile(FoamFile file) { + if (found("FoamFile")) + remove("FoamFile"); + this.foamFile = file; + } - protected String write() { - DictionaryWriter writer = new DictionaryWriter(this); - return writer.write(); - } + public FoamFile getFoamFile() { + return foamFile; + } + + public void check() throws DictionaryException { + } + + public void include(String includeFile) { + includeFiles.add(includeFile); + } + + private void put(String key, DefaultElement value) { + elements.put(key, value); + if (!keys.contains(key)) + keys.add(key); + } + + public void add(DefaultElement el) { + put(el.getName(), el); + } + + public void addGeneric(DefaultElement el) { + String name = el.getName(); + if (!genericKeys.contains(name)) { + genericKeys.add(name); + } + put(name, el); + } + + public void add(Dictionary dictionary) { + put(dictionary.getName(), dictionary); + } + + public void addToList(Dictionary dictionary) { + addToList("", dictionary); + } + + public void addToList(String listName, Dictionary dictionary) { + ListField list = getList(listName); + if (list == null) { + list = new ListField(listName); + add(list); + } + list.add(dictionary); + } + + public void addToList(String listName, FieldElement fe) { + ListField list = getList(listName); + if (list == null) { + list = new ListField(listName); + add(list); + } + list.add(fe); + } + + public void add(String name, String value) { + put(name, new FieldElement(name, value)); + } + + public void add(String name, Boolean value) { + put(name, new FieldElement(name, String.valueOf(value))); + } + + public void add(String name, Double value) { + put(name, new FieldElement(name, String.valueOf(value))); + } + + public void add(String name, Integer value) { + put(name, new FieldElement(name, String.valueOf(value))); + } + + public void addUniform(String name, Double value) { + put(name, new FieldElement(name, UNIFORM + " " + String.valueOf(value))); + } + + public void addUniform(String name, Integer value) { + put(name, new FieldElement(name, UNIFORM + " " + String.valueOf(value))); + } + + public void addConstant(String name, Double value) { + put(name, new FieldElement(name, CONSTANT + " " + String.valueOf(value))); + } + + public void addConstant(String name, Integer value) { + put(name, new FieldElement(name, CONSTANT + " " + String.valueOf(value))); + } + + public void addGeneric(String name, String value) { + if (!genericKeys.contains(name)) { + genericKeys.add(name); + } + put(name, new FieldElement(name, value)); + } + + public void addUniform(String name, double[] values) { + StringBuffer sb = new StringBuffer(UNIFORM + " ( "); + for (Double d : values) { + sb.append(String.valueOf(d) + " "); + } + sb.append(")"); + this.add(name, sb.toString()); + } + + public static String toString(double[] values) { + StringBuffer sb = new StringBuffer("( "); + for (Double d : values) { + sb.append(String.valueOf(d) + " "); + } + sb.append(")"); + return sb.toString(); + } + + public static String toString(double[][] values) { + StringBuffer sb = new StringBuffer("( "); + for (int i = 0; i < values.length; i++) { + sb.append(toString(values[i]) + " "); + } + sb.append(")"); + return sb.toString(); + } + + public void add(String name, double[] values) { + this.add(name, toString(values)); + } + + public void add(String name, double[][] values) { + this.add(name, toString(values)); + } + + public void add(String name, String[][] values) { + StringBuffer sb = new StringBuffer("( "); + for (int i = 0; i < values.length; i++) { + sb.append("( "); + for (int j = 0; j < values[i].length; j++) { + String d = values[i][j]; + sb.append(d + " "); + } + sb.append(") "); + } + sb.append(")"); + this.add(name, sb.toString()); + } + + public void add(String name, int[] values) { + StringBuffer sb = new StringBuffer("( "); + for (int d : values) { + sb.append(String.valueOf(d) + " "); + } + sb.append(")"); + this.add(name, sb.toString()); + } + + public void add(String name, String[] values) { + StringBuffer sb = new StringBuffer("( "); + for (String p : values) { + sb.append(p + " "); + } + sb.append(")"); + this.add(name, sb.toString()); + } + + public void add(String name, List values) { + this.add(name, values.toArray(new String[0])); + } + + public void add(DimensionedScalar ds) { + put(ds.getName(), ds); + } + + public void add(String name, ListField list) { + put(name, list); + } + + public void add(String name, ListField2 list) { + put(name, list); + } + + public void add(ListField list) { + put(list.getName(), list); + } + + public String findKey(Finder finder) { + for (String key : keys) { + if (finder.accept(key)) { + return key; + } + } + return null; + } + + public boolean found(Finder finder) { + String key = findKey(finder); + return key != null; + } + + public boolean found(String name) { + if (foundGeneric(name)) + return true; + else + return keys.contains(name); + } + + private boolean foundGeneric(String name) { + if (!genericKeys.isEmpty()) { + for (String genericKey : genericKeys) { + if (("\"" + name + "\"").matches(genericKey)) { + return true; + } + } + } + return false; + } + + DefaultElement getElement(String name) { + if (elements.containsKey(name)) + return elements.get(name); + + if (!genericKeys.isEmpty()) { + for (String genericKey : genericKeys) { + if (("\"" + name + "\"").matches(genericKey)) { + return elements.get(genericKey); + } + } + } + return null; + } + + public boolean isDictionary(String name) { + DefaultElement el = getElement(name); + return (el != null && el instanceof Dictionary); + } + + public boolean isScalar(String name) { + DefaultElement el = getElement(name); + return (el != null && el instanceof DimensionedScalar); + } + + public boolean isField(String name) { + DefaultElement el = getElement(name); + return (el != null && el instanceof FieldElement); + } + + public boolean isList(String name) { + DefaultElement el = getElement(name); + return (el != null && el instanceof ListField); + } + + public boolean isList2(String name) { + DefaultElement el = getElement(name); + return (el != null && el instanceof ListField2); + } + + public boolean isThetaList2(String name) { + DefaultElement el = getElement(name); + return (el != null && el instanceof ThetaListField2); + } + + public Dictionary subDict(String name) { + DefaultElement el = getElement(name); + if (isDictionary(name)) { + return (Dictionary) el; + } else if (el != null) + throw new DictionaryException(name + " not a dictionary"); + else + return null; + } + + // public ListField getList() { + // return getList(""); + // } + // + // public ListField2 getList2() { + // return getList2(""); + // } + + public ListField getList(String name) { + DefaultElement el = getElement(name); + if (isList(name)) { + return (ListField) el; + } else if (el != null) + throw new DictionaryException(name + " not a list"); + else + return null; + } + + public ListField2 getList2(String name) { + DefaultElement el = getElement(name); + if (isList2(name)) { + return (ListField2) el; + } else if (el != null) + throw new DictionaryException(name + " not a list"); + else + return null; + } + + public ThetaListField2 getThetaList2(String name) { + DefaultElement el = getElement(name); + if (isThetaList2(name)) { + return (ThetaListField2) el; + } else if (el != null) + throw new DictionaryException(name + " not a theta list"); + else + return null; + } + + public DefaultElement lookup(Finder finder) { + String key = findKey(finder); + if (key == null) { + throw new DictionaryException("Key " + key + " is NULL"); + } + + return getElement(key); + } + + public String lookup(String key) { + return lookupString(key); + } + + public String lookupString(String key) { + if (key == null) { + throw new DictionaryException("Key " + key + " is NULL"); + } + DefaultElement el = getElement(key); + if (isField(key)) { + return ((FieldElement) el).getValue(); + } else if (el != null) + throw new DictionaryException(key + " not a field"); + else + return null; + } + + public boolean lookupBoolean(String name) { + String value = lookupString(name); + if (value != null) { + return value.equalsIgnoreCase("true") || value.equalsIgnoreCase("yes") || value.equalsIgnoreCase("on"); + } else { + return false; + } + } + + public int lookupInt(String name) { + String value = lookupString(name); + try { + return Integer.parseInt(value); + } catch (NumberFormatException e) { + return -1; + } + } + + public int lookupIntConstant(String name) { + String value = lookupString(name).replace(CONSTANT, "").trim(); + try { + return Integer.parseInt(value); + } catch (NumberFormatException e) { + return -1; + } + } + + public double lookupDouble(String name) { + String value = lookupString(name); + try { + return Double.parseDouble(value); + } catch (NumberFormatException e) { + return Double.NaN; + } + } + + public double lookupDoubleUniform(String name) { + String value = lookupString(name).replace(UNIFORM, "").trim(); + try { + return Double.parseDouble(value); + } catch (NumberFormatException e) { + return Double.NaN; + } + } + + public double lookupDoubleConstant(String name) { + String value = lookupString(name).replace(CONSTANT, "").trim(); + try { + return Double.parseDouble(value); + } catch (NumberFormatException e) { + return Double.NaN; + } + } + + public DimensionedScalar lookupScalar(String name) { + DefaultElement el = getElement(name); + if (el != null && el instanceof DimensionedScalar) { + return (DimensionedScalar) el; + } else if (el != null) + throw new DictionaryException(name + " not a dimensioned scalar"); + else + return null; + } + + public static String[] toArray(String value) { + if (value.startsWith("(") && value.endsWith(")")) { + value = value.replace("(", "").replace(")", "").trim(); + // value = value.substring(1, value.length()-1); + if (value.isEmpty()) { + return new String[0]; + } + String[] values = value.split(SPACER); + // System.out.println("Dictionary.lookupArray() "+Arrays.toString(values)); + return values; + } else + throw new DictionaryException("'" + value + "' not an array"); + } + + public String[] lookupArray(String name) { + DefaultElement el = getElement(name); + if (el != null && el instanceof FieldElement) { + String value = ((FieldElement) el).getValue(); + if (value.startsWith(UNIFORM)) { + value = value.replace(UNIFORM, "").trim(); + } + if (value.startsWith(NONUNIFORM)) { + return new String[] { "Infinity", "Infinity", "Infinity" }; + } + + return toArray(value); + + } else if (el != null) { + throw new DictionaryException(name + " not a field [ " + el.getClass() + "]"); + } else { + return null; + } + } + + public String[][] lookupMatrix(String name) { + DefaultElement el = getElement(name); + if (el != null && el instanceof FieldElement) { + String value = ((FieldElement) el).getValue(); + if (value.startsWith(UNIFORM)) { + value = value.replace(UNIFORM, "").trim(); + } + if (value.startsWith("(") && value.endsWith(")")) { + value = value.replaceAll("\\(\\s*\\(", ""); + value = value.replaceAll("\\)\\s*\\)", ""); + + // is empty matrix + if (value.trim().matches("\\(\\s*\\)")) { + return new String[0][0]; + } + + String[] values = value.split("\\)\\s*\\("); + String[][] matrix = new String[values.length][]; + for (int r = 0; r < values.length; r++) { + String[] row = values[r].trim().split("\\s+"); + matrix[r] = row; + } + return matrix; + } else + throw new DictionaryException(name + " not an array"); + } else if (el != null) + throw new DictionaryException(name + " not a field"); + else + return null; + } + + public String[] lookupArray2(String name) { + DefaultElement el = getElement(name); + if (el != null && el instanceof ListField2) { + ListField2 list = (ListField2) el; + return listToArray(list); + } else if (el != null) + throw new DictionaryException(name + " not a field"); + else + return null; + } + + private String[] listToArray(ListField2 list) { + List elements = list.getListElements(); + + String[] values = new String[elements.size()]; + + for (int i = 0; i < elements.size(); i++) { + DefaultElement element = elements.get(i); + if (element instanceof FieldElement) { + String value = ((FieldElement) element).getValue(); + values[i] = value; + } else if (element instanceof ListField2) { + String[] listField = listToArray((ListField2) element); + values[i] = "("; + for (int j = 0; j < listField.length; j++) { + values[i] += listField[j] + " "; + } + values[i] += ")"; + } + } + return values; + } + + public String[][] lookupMatrix2(String name) { + DefaultElement el = getElement(name); + if (el != null && el instanceof ListField2) { + ListField2 list = (ListField2) el; + return listToMatrix(list); + } else if (el != null) { + throw new DictionaryException(name + " not a field"); + } else { + return null; + } + } + + private String[][] listToMatrix(ListField2 list) { + List rows = list.getListElements(); + if (rows.size() > 0 && rows.get(0) instanceof ListField2) { + ListField2 firstRow = (ListField2) rows.get(0); + String[][] values = new String[rows.size()][firstRow.getListElements().size()]; + + for (int i = 0; i < rows.size(); i++) { + if (rows.get(i) instanceof ListField2) { + ListField2 row = (ListField2) rows.get(i); + values[i] = listToArray(row); + } + } + return values; + } else { + return new String[0][0]; + } + } + + public static double[] toDouble(String[] array) { + double[] doubleArray = new double[array.length]; + for (int i = 0; i < doubleArray.length; i++) { + try { + doubleArray[i] = Double.valueOf(array[i]); + } catch (NumberFormatException e) { + } + } + return doubleArray; + } + + public double[] lookupDoubleArray(String key) { + String[] array = lookupArray(key); + double[] doubleArray = new double[array.length]; + for (int i = 0; i < doubleArray.length; i++) { + try { + doubleArray[i] = Double.valueOf(array[i]); + } catch (NumberFormatException e) { + } + } + return doubleArray; + } + + public double[] lookupDoubleArray(Finder finder) { + String key = findKey(finder); + if (key != null) { + String[] array = lookupArray(key); + double[] doubleArray = new double[array.length]; + for (int i = 0; i < doubleArray.length; i++) { + try { + doubleArray[i] = Double.valueOf(array[i]); + } catch (NumberFormatException e) { + } + } + return doubleArray; + } else { + throw new DictionaryException(key + " not a field"); + } + } + + public double[] lookupDoubleArray2(String name) { + String[] array = lookupArray2(name); + double[] doubleArray = new double[array.length]; + for (int i = 0; i < doubleArray.length; i++) { + try { + doubleArray[i] = Double.valueOf(array[i]); + } catch (NumberFormatException e) { + } + } + return doubleArray; + } + + public double[][] lookupDoubleMatrix(String name) { + String[][] matrix = lookupMatrix(name); + double[][] doubleMatrix = new double[matrix.length][matrix.length == 0 ? 0 : matrix[0].length]; + for (int i = 0; i < doubleMatrix.length; i++) { + for (int j = 0; j < doubleMatrix[i].length; j++) { + try { + doubleMatrix[i][j] = Double.valueOf(matrix[i][j]); + } catch (NumberFormatException e) { + } + } + } + return doubleMatrix; + } + + public List lookupPointList(String name) { + double[][] matrix = lookupDoubleMatrix(name); + List doubleMatrixList = new LinkedList<>(); + for (double[] ds : matrix) { + if (ds.length == 3) { + doubleMatrixList.add(new Point3d(ds[0], ds[1], ds[2])); + } else { + doubleMatrixList.add(new Point3d()); + } + } + return doubleMatrixList; + } + + public double[][] lookupDoubleMatrix2(String name) { + String[][] matrix = lookupMatrix2(name); + double[][] doubleMatrix = new double[matrix.length][matrix[0].length]; + for (int i = 0; i < doubleMatrix.length; i++) { + for (int j = 0; j < doubleMatrix[i].length; j++) { + try { + doubleMatrix[i][j] = Double.valueOf(matrix[i][j]); + } catch (NumberFormatException e) { + e.printStackTrace(); + } + } + } + return doubleMatrix; + } + + public int[] lookupIntArray(String name) { + String[] array = lookupArray(name); + int[] intArray = new int[array.length]; + for (int i = 0; i < intArray.length; i++) { + try { + intArray[i] = Integer.valueOf(array[i]); + } catch (NumberFormatException e) { + } + } + return intArray; + } + + public Dictionary removeDict(String name) { + keys.remove(name); + return (Dictionary) elements.remove(name); + } + + public DefaultElement remove(String name) { + keys.remove(name); + return elements.remove(name); + } + + public DefaultElement remove(Finder finder) { + String key = findKey(finder); + return remove(key); + } + + List getGenericKeys() { + return genericKeys; + } + + public List getKeys() { + return keys; + } + + List getIncludeFiles() { + return includeFiles; + } + + public boolean isEmpty() { + return keys.isEmpty(); + } + + @Override + public String toString() { + return new DictionaryWriter(this).write(); + } + + public List getDictionaries() { + List list = new ArrayList(); + for (String key : keys) { + DefaultElement el = elements.get(key); + if (el instanceof Dictionary) { + list.add((Dictionary) el); + } + } + return list; + } + + public Map getDictionariesMap() { + Map map = new LinkedHashMap(); + for (String key : keys) { + DefaultElement el = elements.get(key); + if (el instanceof Dictionary) { + map.put(el.getName(), (Dictionary) el); + } + } + return map; + } + + public List getFields() { + List list = new ArrayList(); + for (DefaultElement el : elements.values()) { + if (el instanceof FieldElement) { + list.add((FieldElement) el); + } + } + return list; + } + + public List getListFields() { + List list = new ArrayList<>(); + for (DefaultElement el : elements.values()) { + if (el instanceof ListField) { + list.add((ListField) el); + } + } + return list; + } + + public boolean hasOnlyList() { + return !getListFields().isEmpty() && getDictionaries().isEmpty() && getFieldsMap().isEmpty(); + } + + public boolean hasOnlyList2() { + return !getListFields2().isEmpty() && getDictionaries().isEmpty() && getFieldsMap().isEmpty(); + } + + public List getListFields2() { + List list = new ArrayList<>(); + for (DefaultElement el : elements.values()) { + if (el instanceof ListField2) { + list.add((ListField2) el); + } + } + return list; + } + + public Map getFieldsMap() { + Map map = new LinkedHashMap(); + for (DefaultElement el : elements.values()) { + if (el instanceof FieldElement) { + FieldElement field = (FieldElement) el; + map.put(field.getName(), field.getValue()); + } + } + return map; + } + + public void merge(Dictionary dict) { + merge(dict, new String[0]); + } + + public void merge(Dictionary dict, String[] keysToExclude) { + if (dict == null) + return; + // System.out.println("Dictionary.merge(): "+dict); + for (String key : dict.getKeys()) { + if (ArrayUtils.contains(keysToExclude, key)) { + continue; + } + + DefaultElement ele = dict.getElement(key); + if (ele instanceof Dictionary) { + Dictionary d = (Dictionary) ele; + if (found(d.getName()) && isDictionary(d.getName())) { + subDict(d.getName()).merge(d); + } else { + add(new Dictionary(d.getName())); + subDict(d.getName()).merge(d); + } + } else if (ele instanceof ListField) { + ListField l = (ListField) ele; + if (found(l.getName()) && isList(l.getName())) { + getList(l.getName()).merge(l); + } else { + add(new ListField(l.getName())); + getList(l.getName()).merge(l); + } + } else if (ele instanceof ThetaListField2) { + ThetaListField2 t = (ThetaListField2) ele; + if (found(t.getName()) && isThetaList2(t.getName())) { + getThetaList2(t.getName()).merge(t); + } else { + add(new ThetaListField2(t)); + } + } else if (ele instanceof ListField2) { + ListField2 l = (ListField2) ele; + if (found(l.getName()) && isList2(l.getName())) { + getList2(l.getName()).merge(l); + } else { + add(new ListField2(l)); + } + } else if (ele instanceof FieldElement) { + FieldElement f = (FieldElement) ele; + if (f instanceof DimensionedScalar) { + add(new DimensionedScalar((DimensionedScalar) f)); + } else { + add(f.getName(), f.getValue()); + } + } + } + genericKeys.addAll(dict.genericKeys); + } + + public void clear() { + elements.clear(); + keys.clear(); + } + + /* * * * * * * * * * * * * + * READ/WRITE STUFF * * * * * * * * * * * * + */ + + public void readDictionary(File file) { + DictionaryReader reader = new DictionaryReader(this); + reader.read(file); + } + + protected void readDictionary(InputStream input, DictionaryLinkResolver resolver) { + DictionaryReader reader = new DictionaryReader(this, resolver); + reader.read(input); + } + + protected void readDictionary(InputStream input) { + DictionaryReader reader = new DictionaryReader(this); + reader.read(input); + } + + protected void readDictionaryFromString(String text) { + DictionaryReader reader = new DictionaryReader(this); + reader.read(text); + } + + protected String write() { + DictionaryWriter writer = new DictionaryWriter(this); + return writer.write(); + } + + @Override + public boolean equals(Object obj) { + if (!(obj instanceof Dictionary)) { + return false; + } + if (obj == this) { + return true; + } + Dictionary dict = (Dictionary) obj; + return new EqualsBuilder().appendSuper(super.equals(obj)).append(elements, dict.elements).isEquals(); + } + + @Override + public int hashCode() { + return new HashCodeBuilder(17, 31).appendSuper(super.hashCode()).append(elements).toHashCode(); + } } diff --git a/src/eu/engys/core/dictionary/DictionaryBuilder.java b/src/eu/engys/core/dictionary/DictionaryBuilder.java index 1bce27d..b40354f 100644 --- a/src/eu/engys/core/dictionary/DictionaryBuilder.java +++ b/src/eu/engys/core/dictionary/DictionaryBuilder.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.dictionary; @@ -45,6 +44,36 @@ public class DictionaryBuilder { dictionary.add(k, v); return this; } + + public DictionaryBuilder field(String k, Double v) { + dictionary.add(k, v); + return this; + } + + public DictionaryBuilder field(String k, Integer v) { + dictionary.add(k, v); + return this; + } + + public DictionaryBuilder fieldUniform(String k, Double v) { + dictionary.addUniform(k, v); + return this; + } + + public DictionaryBuilder field(String k, boolean v) { + dictionary.add(k, v); + return this; + } + + public DictionaryBuilder field(String k, double[] d) { + dictionary.add(k, d); + return this; + } + + public DictionaryBuilder fieldUniform(String k, double[] d) { + dictionary.addUniform(k, d); + return this; + } public DictionaryBuilder dimensionedScalar(String k, String v, String d) { dictionary.add(new DimensionedScalar(k, v, d)); diff --git a/src/eu/engys/core/dictionary/DictionaryException.java b/src/eu/engys/core/dictionary/DictionaryException.java index 51119be..63296a2 100644 --- a/src/eu/engys/core/dictionary/DictionaryException.java +++ b/src/eu/engys/core/dictionary/DictionaryException.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.dictionary; diff --git a/src/eu/engys/core/dictionary/DictionaryLinkResolver.java b/src/eu/engys/core/dictionary/DictionaryLinkResolver.java index 98f3411..5a329d5 100644 --- a/src/eu/engys/core/dictionary/DictionaryLinkResolver.java +++ b/src/eu/engys/core/dictionary/DictionaryLinkResolver.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.dictionary; diff --git a/src/eu/engys/core/dictionary/DictionaryReader.java b/src/eu/engys/core/dictionary/DictionaryReader.java index 34fdc18..84f5688 100644 --- a/src/eu/engys/core/dictionary/DictionaryReader.java +++ b/src/eu/engys/core/dictionary/DictionaryReader.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.dictionary; diff --git a/src/eu/engys/core/dictionary/DictionaryUtils.java b/src/eu/engys/core/dictionary/DictionaryUtils.java index 1493183..e1515c0 100644 --- a/src/eu/engys/core/dictionary/DictionaryUtils.java +++ b/src/eu/engys/core/dictionary/DictionaryUtils.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.dictionary; diff --git a/src/eu/engys/core/dictionary/DictionaryWriter.java b/src/eu/engys/core/dictionary/DictionaryWriter.java index 6eefff9..ff4f240 100644 --- a/src/eu/engys/core/dictionary/DictionaryWriter.java +++ b/src/eu/engys/core/dictionary/DictionaryWriter.java @@ -1,36 +1,45 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.dictionary; import static eu.engys.core.dictionary.Dictionary.SPACER; import static eu.engys.core.dictionary.Dictionary.TAB; import static eu.engys.core.dictionary.Dictionary.VERBOSE; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import eu.engys.core.dictionary.parser.ListField2; public class DictionaryWriter { + + private static final Logger logger = LoggerFactory.getLogger(DictionaryWriter.class); + + private static final String SCALAR_TAG = ""; + private static final String VECTOR_TAG = ""; + private static final String LIST = "List"; protected Dictionary dictionary; @@ -87,7 +96,7 @@ public class DictionaryWriter { if (ele != null) { writeElement(sb, rowHeader, ele); } else { - System.out.println("DictionaryWriter.writeDictionary() ------------------------------>> " + key + " is NUUULLLLL in " + dictionary.getKeys() + " and " + dictionary.getDictionaries()); + logger.error("Dictionary \"{}\" does not contain key {}. Keys are {}", dictionary.getName(), key, dictionary.getKeys()); } } for (String includeFile : dictionary.getIncludeFiles()) { @@ -99,7 +108,9 @@ public class DictionaryWriter { } public static void writeElement(StringBuffer sb, String rowHeader, DefaultElement ele) { - if (ele instanceof Dictionary) { + if (ele == null) { + logger.error("A NULL element has not been written in \n{}", sb.toString()); + } else if (ele instanceof Dictionary) { DictionaryWriter writer = new DictionaryWriter((Dictionary) ele); writer.writeDictionary(sb, rowHeader + TAB); } else if (ele instanceof DimensionedScalar) { @@ -120,7 +131,7 @@ public class DictionaryWriter { private static boolean hasParenthesis(DefaultElement ele) { FieldElement fieldElement = (FieldElement) ele; String value = fieldElement.getValue(); - return value != null && value.contains("(") && value.contains("List"); + return value != null && value.contains("(") && value.contains(LIST); } protected static void writeField(StringBuffer sb, FieldElement field, String rowHeader) { @@ -146,9 +157,9 @@ public class DictionaryWriter { sb.append(SPACER); String value = field.getValue(); if (value.contains("vector")) { - sb.append(value.replace("(", "\n(").replace("))", ")\n)").replace("", "\n")); + sb.append(value.replace("(", "\n(").replace("))", ")\n)").replace(VECTOR_TAG, VECTOR_TAG+"\n")); } else { - sb.append(value.replace("(", "\n(").replace("", "\n").replaceAll("\\s+", "\n")); + sb.append(value.replace("(", "\n(").replace(SCALAR_TAG, SCALAR_TAG+"\n").replaceAll("\\s+", "\n")); } sb.append(";"); } @@ -167,16 +178,18 @@ public class DictionaryWriter { private static void writeDimensionedScalar(StringBuffer sb, DimensionedScalar ds, String rowHeader) { if (VERBOSE) System.out.println("Dictionary.writeDimensionedScalar() " + (ds != null ? ds.getName() : "NULL!!!")); - sb.append("\n"); - sb.append(rowHeader); - sb.append(TAB); - sb.append(ds.getName()); - sb.append(SPACER); - sb.append(ds.getName()); - sb.append(SPACER); - sb.append(ds.getDimensions()); - sb.append(SPACER); - sb.append(ds.getValue()); - sb.append(";"); + if (ds != null) { + sb.append("\n"); + sb.append(rowHeader); + sb.append(TAB); + sb.append(ds.getName()); + sb.append(SPACER); + sb.append(ds.getName()); + sb.append(SPACER); + sb.append(ds.getDimensions()); + sb.append(SPACER); + sb.append(ds.getValue()); + sb.append(";"); + } } } diff --git a/src/eu/engys/core/dictionary/DimensionedScalar.java b/src/eu/engys/core/dictionary/DimensionedScalar.java index 9d43777..ae60241 100644 --- a/src/eu/engys/core/dictionary/DimensionedScalar.java +++ b/src/eu/engys/core/dictionary/DimensionedScalar.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.dictionary; diff --git a/src/eu/engys/core/dictionary/FieldChangeListener.java b/src/eu/engys/core/dictionary/FieldChangeListener.java deleted file mode 100644 index f95afad..0000000 --- a/src/eu/engys/core/dictionary/FieldChangeListener.java +++ /dev/null @@ -1,36 +0,0 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - - -package eu.engys.core.dictionary; - -import java.awt.event.ActionListener; - -public interface FieldChangeListener extends ActionListener { - - public void fieldChanged(); - public boolean isAdjusting(); - public void setAdjusting(boolean b); -} diff --git a/src/eu/engys/core/dictionary/FieldElement.java b/src/eu/engys/core/dictionary/FieldElement.java index dcc3763..f3772fe 100644 --- a/src/eu/engys/core/dictionary/FieldElement.java +++ b/src/eu/engys/core/dictionary/FieldElement.java @@ -1,62 +1,79 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.dictionary; +import org.apache.commons.lang.builder.EqualsBuilder; +import org.apache.commons.lang.builder.HashCodeBuilder; + public class FieldElement extends DefaultElement { private String value; - + public FieldElement(String name, String value) { super(name); this.value = value; } public FieldElement(FieldElement el) { - this(el.getName(), el.getValue()); - } + this(el.getName(), el.getValue()); + } - public void setValue(String value) { + public void setValue(String value) { this.value = value; } public String getValue() { return value; } - + @Override public String toString() { return getName() + "[" + value + "]"; } - + @Override public boolean equals(Object obj) { - if (obj instanceof FieldElement) { - return ((FieldElement) obj).getName().equals(getName()) && ((FieldElement) obj).value.equals(value) ; - } - return false; + if (!(obj instanceof FieldElement)) { + return false; + } + if (obj == this) { + return true; + } + FieldElement fe = (FieldElement) obj; + return new EqualsBuilder() + .appendSuper(super.equals(obj)) + .append(value, fe.value) + .isEquals(); } + + @Override + public int hashCode() { + return new HashCodeBuilder(17, 31) + .appendSuper(super.hashCode()) + .append(value) + .toHashCode(); + } + } diff --git a/src/eu/engys/core/dictionary/FieldListener.java b/src/eu/engys/core/dictionary/FieldListener.java index 072aa20..e38686f 100644 --- a/src/eu/engys/core/dictionary/FieldListener.java +++ b/src/eu/engys/core/dictionary/FieldListener.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.dictionary; diff --git a/src/eu/engys/core/dictionary/Finder.java b/src/eu/engys/core/dictionary/Finder.java index 6f5547b..57e2607 100644 --- a/src/eu/engys/core/dictionary/Finder.java +++ b/src/eu/engys/core/dictionary/Finder.java @@ -1,32 +1,31 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.dictionary; public interface Finder { boolean accept(String key); -} +} \ No newline at end of file diff --git a/src/eu/engys/core/dictionary/FoamFile.java b/src/eu/engys/core/dictionary/FoamFile.java index fcf8f70..b0fc6ca 100644 --- a/src/eu/engys/core/dictionary/FoamFile.java +++ b/src/eu/engys/core/dictionary/FoamFile.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.dictionary; diff --git a/src/eu/engys/core/dictionary/ListField.java b/src/eu/engys/core/dictionary/ListField.java index 7ce63b9..3390883 100644 --- a/src/eu/engys/core/dictionary/ListField.java +++ b/src/eu/engys/core/dictionary/ListField.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.dictionary; @@ -185,4 +184,14 @@ public class ListField extends DefaultElement { return null; } + public List getDictionaries() { + List dicts = new ArrayList<>(); + for (DefaultElement e : list) { + if (e instanceof Dictionary) { + dicts.add((Dictionary) e); + } + } + return dicts; + } + } diff --git a/src/eu/engys/core/dictionary/ListReader.java b/src/eu/engys/core/dictionary/ListReader.java index f83cdfd..7dc2e1e 100644 --- a/src/eu/engys/core/dictionary/ListReader.java +++ b/src/eu/engys/core/dictionary/ListReader.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.dictionary; diff --git a/src/eu/engys/core/dictionary/MatrixReader.java b/src/eu/engys/core/dictionary/MatrixReader.java index 1282a35..f832834 100644 --- a/src/eu/engys/core/dictionary/MatrixReader.java +++ b/src/eu/engys/core/dictionary/MatrixReader.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.dictionary; diff --git a/src/eu/engys/core/dictionary/StartWithFinder.java b/src/eu/engys/core/dictionary/StartWithFinder.java index 861483a..fb67876 100644 --- a/src/eu/engys/core/dictionary/StartWithFinder.java +++ b/src/eu/engys/core/dictionary/StartWithFinder.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.dictionary; public class StartWithFinder implements Finder { @@ -37,4 +36,4 @@ public class StartWithFinder implements Finder { public boolean accept(String key) { return key.startsWith(keyToFind); } -} +} \ No newline at end of file diff --git a/src/eu/engys/core/dictionary/TableRowElement.java b/src/eu/engys/core/dictionary/TableRowElement.java index 6eee171..eb1ee9e 100644 --- a/src/eu/engys/core/dictionary/TableRowElement.java +++ b/src/eu/engys/core/dictionary/TableRowElement.java @@ -1,32 +1,35 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.dictionary; import static eu.engys.core.dictionary.Dictionary.SPACER; + +import org.apache.commons.lang.builder.EqualsBuilder; +import org.apache.commons.lang.builder.HashCodeBuilder; + import eu.engys.core.dictionary.parser.ListField2; public class TableRowElement extends DefaultElement { @@ -73,28 +76,30 @@ public class TableRowElement extends DefaultElement { return values; } - @Override - public boolean equals(Object obj) { - if (obj instanceof TableRowElement) { - TableRowElement t = ((TableRowElement) obj); - return key.equals(t.key) /*&& valuesAreEquals(t.values)*/; - } - return super.equals(obj); - } - - private boolean valuesAreEquals(FieldElement[] values) { - if (this.values.length != values.length) { - return false; - } - for (int i = 0; i < values.length; i++) { - if (!this.values[i].equals(values[i])) { - return false; - } - } - return true; - } - public void merge(TableRowElement el) { this.values = el.values; } + + @Override + public boolean equals(Object obj) { + if (!(obj instanceof TableRowElement)) { + return false; + } + if (obj == this) { + return true; + } + TableRowElement el = (TableRowElement) obj; + return new EqualsBuilder() + .appendSuper(super.equals(obj)) + .append(key, el.key) + .isEquals(); + } + + @Override + public int hashCode() { + return new HashCodeBuilder(17, 31) + .appendSuper(super.hashCode()) + .append(key) + .toHashCode(); + } } diff --git a/src/eu/engys/core/dictionary/model/AbstractTableAdapter.java b/src/eu/engys/core/dictionary/model/AbstractTableAdapter.java index d8ea2e8..0db466e 100644 --- a/src/eu/engys/core/dictionary/model/AbstractTableAdapter.java +++ b/src/eu/engys/core/dictionary/model/AbstractTableAdapter.java @@ -1,31 +1,33 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.dictionary.model; +import static eu.engys.util.ui.UiUtil.ADD_ROW_BUTTON_NAME; +import static eu.engys.util.ui.UiUtil.REM_ROW_BUTTON_NAME; + import java.awt.BorderLayout; import java.awt.FlowLayout; import java.awt.event.ActionEvent; @@ -87,11 +89,11 @@ public abstract class AbstractTableAdapter extends JPanel { buttonsPanel.setOpaque(false); JButton addButton = new JButton(new AddRowAction()); - addButton.setName("add.row.button"); + addButton.setName(ADD_ROW_BUTTON_NAME); buttonsPanel.add(addButton); JButton remButton = new JButton(new RemRowAction()); - remButton.setName("rem.row.button"); + remButton.setName(REM_ROW_BUTTON_NAME); buttonsPanel.add(remButton); return buttonsPanel; } diff --git a/src/eu/engys/core/dictionary/model/AxisInfo.java b/src/eu/engys/core/dictionary/model/AxisInfo.java index 70da1e8..690ff00 100644 --- a/src/eu/engys/core/dictionary/model/AxisInfo.java +++ b/src/eu/engys/core/dictionary/model/AxisInfo.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.dictionary.model; import eu.engys.util.ui.textfields.DoubleField; @@ -33,24 +32,54 @@ public class AxisInfo { public static final String LABEL = "Point "; private DoubleField[] center; private EventActionType action; - private DoubleField[] axis; + private double magnitude; + private DoubleField toe; + private DoubleField camber; + private DoubleField[] axis; + private int sign; - public AxisInfo(DoubleField[] axis, DoubleField[] center, EventActionType action) { - this.axis = axis; - this.center = center; + public AxisInfo(DoubleField toe, DoubleField camber, DoubleField[] center, double magnitude, int sign, EventActionType action) { + this.toe = toe; + this.camber = camber; + this.center = center; + this.sign = sign; this.action = action; + this.magnitude = magnitude; } - public DoubleField[] getAxis() { - return axis; + public AxisInfo(DoubleField[] axis, DoubleField[] center, int magnitude, EventActionType action) { + this.axis = axis; + this.center = center; + this.magnitude = magnitude; + this.action = action; + } + + public DoubleField getToe() { + return toe; } + + public DoubleField getCamber() { + return camber; + } + + public int getSign() { + return sign; + } public DoubleField[] getCenter() { return center; } + public DoubleField[] getAxis() { + return axis; + } + public EventActionType getAction() { return action; } -} + public double getMagnitude() { + return magnitude; + } + +} \ No newline at end of file diff --git a/src/eu/engys/core/dictionary/model/DictionaryModel.java b/src/eu/engys/core/dictionary/model/DictionaryModel.java index dc35441..b70553d 100644 --- a/src/eu/engys/core/dictionary/model/DictionaryModel.java +++ b/src/eu/engys/core/dictionary/model/DictionaryModel.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.dictionary.model; import static eu.engys.util.ui.ComponentsFactory.checkBoxControllerField; @@ -39,6 +38,7 @@ import static eu.engys.util.ui.ComponentsFactory.selectField; import static eu.engys.util.ui.ComponentsFactory.spinnerField; import static eu.engys.util.ui.ComponentsFactory.stringField; +import java.awt.BorderLayout; import java.awt.Color; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; @@ -54,7 +54,9 @@ import java.util.concurrent.CopyOnWriteArrayList; import javax.swing.JCheckBox; import javax.swing.JComboBox; +import javax.swing.JComponent; import javax.swing.JPanel; +import javax.swing.ListModel; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -62,10 +64,10 @@ import org.slf4j.LoggerFactory; import eu.engys.core.dictionary.Dictionary; import eu.engys.core.dictionary.DictionaryUtils; import eu.engys.core.dictionary.DimensionedScalar; -import eu.engys.core.dictionary.FieldChangeListener; import eu.engys.core.project.zero.patches.Patches; import eu.engys.util.filechooser.util.SelectionMode; import eu.engys.util.ui.ComponentsFactory; +import eu.engys.util.ui.FieldChangeListener; import eu.engys.util.ui.FileFieldPanel; import eu.engys.util.ui.ListBuilder; import eu.engys.util.ui.ListFieldPanel; @@ -91,8 +93,8 @@ public class DictionaryModel { public void dictionaryChanged() throws DictionaryError; } - private List listeners = new CopyOnWriteArrayList(); - private Map subModels = new HashMap(); + private List listeners = new CopyOnWriteArrayList<>(); + private Map subModels = new HashMap<>(); public static class DictionaryError extends Exception { private String[] messages; @@ -222,26 +224,34 @@ public class DictionaryModel { } public JCheckBox bindBoolean(String key) { - JCheckBox field = checkField(); - field.addActionListener(new BooleanFieldHandler(key, field, false)); - return field; + return bindBoolean(key, false); } public JCheckBox bindBoolean(String key, boolean def) { - JCheckBox field = checkField(def); - field.addActionListener(new BooleanFieldHandler(key, field, def)); - return field; + return bindBoolean(key, def, true); + } + + public JCheckBox bindBoolean(String key, boolean def, boolean fireEvent) { + JCheckBox field = checkField(def); + field.addActionListener(new BooleanFieldHandler(key, field, def, fireEvent)); + return field; } public JCheckBox bindBoolean(String key, String trueValue, String falseValue) { JCheckBox field = checkField(); - field.addActionListener(new BooleanValuesFieldHandler(key, field, trueValue, falseValue)); + field.addActionListener(new BooleanValuesFieldHandler(key, field, trueValue, falseValue, false)); return field; } public JCheckBox bindBoolean(String key, String trueValue, String falseValue, boolean def) { JCheckBox field = checkField(def); - field.addActionListener(new BooleanValuesFieldHandler(key, field, trueValue, falseValue)); + field.addActionListener(new BooleanValuesFieldHandler(key, field, trueValue, falseValue, false)); + return field; + } + + public JCheckBox bindBoolean(String key, String trueValue, String falseValue, boolean def, boolean lightEvent) { + JCheckBox field = checkField(def); + field.addActionListener(new BooleanValuesFieldHandler(key, field, trueValue, falseValue, lightEvent)); return field; } @@ -291,7 +301,6 @@ public class DictionaryModel { // public IntegerField bindInteger(String key, String name) { // IntegerField field = bindInteger(key); - // field.setName(name); // return field; // } @@ -334,7 +343,6 @@ public class DictionaryModel { // public DoubleField bindUniformDoubleWithName(String key, String name) { // DoubleField field = doubleField(); - // field.setName(name); // field.addPropertyChangeListener(new DoubleUniformFieldHandler(key, // field)); // return field; @@ -377,6 +385,13 @@ public class DictionaryModel { return field; } + public DoubleField bindDoubleAndUniformDouble(String key1, String key2) { + DoubleField field = doubleField(); + field.addPropertyChangeListener(new DoubleFieldHandler(key1, field, null)); + field.addPropertyChangeListener(new DoubleUniformFieldHandler(key2, field)); + return field; + } + public DoubleField bindDouble(String key) { return bindDouble(key, (FieldChangeListener) null); } @@ -393,6 +408,42 @@ public class DictionaryModel { return field; } + public JComponent bindCheckAndDouble(final String key, Double def) { + final JCheckBox checkBox = checkField(); + final DoubleField field = doubleField(def); + field.addPropertyChangeListener(new DoubleFieldHandler(key, field, null)); + field.setEnabled(false); + checkBox.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + if (checkBox.isSelected()) { + field.setEnabled(true); + } else { + field.setValue(null); + field.setEnabled(false); + } + } + }); + DictionaryModel.this.addDictionaryListener(new DictionaryListener() { + @Override + public void dictionaryChanged() throws DictionaryError { + checkBox.setSelected(dictionary.found(key)); + field.setEnabled(checkBox.isSelected()); + } + }); + JPanel panel = new JPanel(new BorderLayout()) { + @Override + public void setName(String name) { + super.setName(name); + checkBox.setName(name); + field.setName(name); + } + }; + panel.add(checkBox, BorderLayout.WEST); + panel.add(field, BorderLayout.CENTER); + return panel; + } + public DoubleField bindDouble(String key, Double def) { DoubleField field = doubleField(def); field.addPropertyChangeListener(new DoubleFieldHandler(key, field, null)); @@ -435,7 +486,6 @@ public class DictionaryModel { DoubleField[] field = doublePointField(); for (int i = 0; i < field.length; i++) { DoubleField f = field[i]; - f.setName(key + "." + i); f.addPropertyChangeListener(new PointFieldHandler(key, field, listener)); } return field; @@ -445,12 +495,21 @@ public class DictionaryModel { DoubleField[] field = doublePointField(places); for (int i = 0; i < field.length; i++) { DoubleField f = field[i]; - f.setName(key + "." + i); f.addPropertyChangeListener(new PointFieldHandler(key, field, listener)); } return field; } + public DoubleField[] bindPointAndUniformPoint(String key1, String key2) { + DoubleField[] field = doublePointField(); + for (int i = 0; i < field.length; i++) { + DoubleField f = field[i]; + f.addPropertyChangeListener(new PointFieldHandler(key1, field, null)); + f.addPropertyChangeListener(new PointUniformFieldHandler(key2, field)); + } + return field; + } + public DoubleField[] bindPoint(String key) { return bindPoint(key, null); } @@ -479,16 +538,6 @@ public class DictionaryModel { return field; } - // public DoubleField[] bindUniformPointWithName(String key, String name) { - // DoubleField[] field = doublePointField(); - // for (int i = 0; i < field.length; i++) { - // DoubleField f = field[i]; - // f.setName(name + "." + i); - // f.addPropertyChangeListener(new PointUniformFieldHandler(key, field)); - // } - // return field; - // } - public DoubleField[] bindUniformPoint(String key1, String key2) { DoubleField[] field = doublePointField(); for (int i = 0; i < field.length; i++) { @@ -513,7 +562,6 @@ public class DictionaryModel { for (int i = 0; i < field.length; i++) { DoubleField f = field[i]; f.setColumns(1); - f.setName(key + "." + i); f.addPropertyChangeListener(new PointFieldHandler(key, field, null)); } return field; @@ -543,6 +591,12 @@ public class DictionaryModel { return combo; } + public JComboBox bindSelection(String key, ListModel listModel) { + JComboBox combo = selectField(listModel); + combo.addActionListener(new SelectFieldHandler(key, combo, null)); + return combo; + } + public JComboBox bindSelection(String key, String... keys) { JComboBox combo = selectField(keys, keys); combo.addActionListener(new SelectFieldHandler(key, combo, null)); @@ -567,7 +621,7 @@ public class DictionaryModel { public JCheckBoxController bindCheckBoxController(String key, String name) { JCheckBoxController combo = checkBoxControllerField(name); - combo.addActionListener(new BooleanFieldHandler(key, combo, false)); + combo.addActionListener(new BooleanFieldHandler(key, combo, false, true)); return combo; } @@ -647,7 +701,7 @@ public class DictionaryModel { public void propertyChange(PropertyChangeEvent evt) { if (evt.getPropertyName().equals("value")) { StringBuilder sb = new StringBuilder(); - sb.append("("); + sb.append("( "); for (int i = 0; i < field.length; i++) { sb.append(field[i].getDoubleValue()); sb.append(" "); @@ -767,19 +821,15 @@ public class DictionaryModel { class SpinnerFieldHandler implements PropertyChangeListener, DictionaryListener { public SpinnerFieldHandler(String key, SpinnerField field) { - // TODO Auto-generated constructor stub } @Override public void dictionaryChanged() throws DictionaryError { - // TODO Auto-generated method stub } @Override public void propertyChange(PropertyChangeEvent evt) { - // TODO Auto-generated method stub - } } @@ -899,7 +949,7 @@ public class DictionaryModel { dictionary.add(key, sb.toString()); logger.trace("PointFieldHandler -> value: {}", dictionary.lookup(key)); if (listener != null) { - listener.fieldChanged(); + listener.fieldChanged(evt.getSource()); } } } @@ -949,7 +999,7 @@ public class DictionaryModel { dictionary.add(key, Double.toString(field.getDoubleValue())); logger.trace("DoubleFieldHandler -> value: {}", dictionary.lookup(key)); if (listener != null) { - listener.fieldChanged(); + listener.fieldChanged(evt.getSource()); } } } @@ -986,7 +1036,7 @@ public class DictionaryModel { public void propertyChange(PropertyChangeEvent evt) { if (evt.getPropertyName().equals("value")) { if (!Double.isInfinite(field.getDoubleValue())) { - dictionary.add(key, "uniform " + Double.toString(field.getDoubleValue())); + dictionary.addUniform(key, field.getDoubleValue()); logger.trace("DoubleUniformFieldHandler -> value: {}", dictionary.lookup(key)); } } @@ -1022,7 +1072,7 @@ public class DictionaryModel { @Override public void propertyChange(PropertyChangeEvent evt) { if (evt.getPropertyName().equals("value")) { - dictionary.add(key, "uniform " + Double.toString(-Math.abs(field.getDoubleValue()))); + dictionary.addUniform(key, -Math.abs(field.getDoubleValue())); logger.trace("DoubleUniformFieldHandler -> " + dictionary.toString()); } } @@ -1053,7 +1103,7 @@ public class DictionaryModel { @Override public void propertyChange(PropertyChangeEvent evt) { if (evt.getPropertyName().equals("value")) { - dictionary.add(key, "uniform " + Double.toString(Math.abs(field.getDoubleValue()))); + dictionary.addUniform(key, Math.abs(field.getDoubleValue())); logger.trace("DoubleUniformFieldHandler -> " + dictionary.toString()); } } @@ -1084,7 +1134,7 @@ public class DictionaryModel { @Override public void propertyChange(PropertyChangeEvent evt) { if (evt.getPropertyName().equals("value")) { - dictionary.add(key, "constant " + Double.toString(field.getDoubleValue())); + dictionary.addConstant(key, field.getDoubleValue()); logger.trace("DoubleUniformFieldHandler -> value: {}", dictionary.lookup(key)); } } @@ -1107,11 +1157,13 @@ public class DictionaryModel { private JCheckBox check; private String key; private final boolean def; + private boolean fireEvent; - public BooleanFieldHandler(String key, JCheckBox check, boolean def) { + public BooleanFieldHandler(String key, JCheckBox check, boolean def, boolean fireEvent) { this.check = check; this.key = key; this.def = def; + this.fireEvent = fireEvent; DictionaryModel.this.addDictionaryListener(this); } @@ -1128,7 +1180,9 @@ public class DictionaryModel { String correctedForYesNo = value == null ? String.valueOf(def) : value.equals("yes") ? "true" : value.equals("no") ? "false" : value; boolean b = Boolean.parseBoolean(correctedForYesNo); if (b != check.isSelected()) { - check.doClick(); + if(fireEvent){ + check.doClick(); + } check.setSelected(b); } logger.trace("BooleanFieldHandler -> value: {}", value); @@ -1141,12 +1195,14 @@ public class DictionaryModel { private String key; private final String trueValue; private final String falseValue; + private boolean lightEvent; - public BooleanValuesFieldHandler(String key, JCheckBox check, String trueValue, String falseValue) { + public BooleanValuesFieldHandler(String key, JCheckBox check, String trueValue, String falseValue, boolean lightEvent) { this.check = check; this.key = key; this.trueValue = trueValue; this.falseValue = falseValue; + this.lightEvent = lightEvent; DictionaryModel.this.addDictionaryListener(this); } @@ -1162,7 +1218,11 @@ public class DictionaryModel { String value = dictionary.lookup(key); boolean selected = value != null && value.equals(trueValue); if (shouldClick(selected, check.isSelected())) { - check.doClick(); + if(lightEvent){ + check.setSelected(!check.isSelected()); + } else { + check.doClick(); + } } logger.trace("BooleanValuesFieldHandler -> value: {}", value); } @@ -1232,11 +1292,10 @@ public class DictionaryModel { public void propertyChange(PropertyChangeEvent evt) { if (evt.getPropertyName().equals("value")) { StringBuilder sb = new StringBuilder(); - sb.append("("); + sb.append("( "); for (int i = 0; i < field.length; i++) { if (field[i].getValue() != null) { - sb.append(field[i].getDoubleValue()); - sb.append(" "); + sb.append(field[i].getDoubleValue() + " "); } else { sb.append("0 "); } @@ -1245,7 +1304,7 @@ public class DictionaryModel { dictionary.add(key, sb.toString()); logger.trace("PointFieldHandler -> value: {}", dictionary.lookup(key)); if (listener != null) { - listener.fieldChanged(); + listener.fieldChanged(evt.getSource()); } } } @@ -1292,14 +1351,7 @@ public class DictionaryModel { return; } } - StringBuilder sb = new StringBuilder(); - sb.append("uniform ("); - for (int i = 0; i < field.length; i++) { - sb.append(field[i].getDoubleValue()); - sb.append(" "); - } - sb.append(")"); - dictionary.add(key, sb.toString()); + dictionary.addUniform(key, DoubleField.toArray(field)); logger.trace("PointFieldHandler -> value: {}", dictionary.lookup(key)); } } diff --git a/src/eu/engys/core/dictionary/model/DictionaryPanelBuilder.java b/src/eu/engys/core/dictionary/model/DictionaryPanelBuilder.java index eb695b8..26fed16 100644 --- a/src/eu/engys/core/dictionary/model/DictionaryPanelBuilder.java +++ b/src/eu/engys/core/dictionary/model/DictionaryPanelBuilder.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.dictionary.model; import static eu.engys.core.dictionary.Dictionary.TYPE; @@ -85,9 +84,13 @@ public class DictionaryPanelBuilder extends PanelBuilder { } public void selectDictionaries(Dictionary newDictionary, Dictionary newCompanion) { + selectDictionaries(newDictionary, newCompanion, TYPE); + } + + public void selectDictionaries(Dictionary newDictionary, Dictionary newCompanion, String selector) { String newName = newDictionary.getName(); - String newType = newDictionary.lookup(TYPE); - String newCompanionType = newCompanion.lookup(TYPE); + String newType = newDictionary.lookup(selector); + String newCompanionType = newCompanion.lookup(selector); // System.out.println("ChoicePanelBuilder.selectDictionary() NEW TYPE: "+newType+" NEW NAME: "+newName+" NEW COMPANION TYPE: "+newCompanionType); // System.out.println("-------------------"); for (String key : modelsByKey.keySet()) { @@ -96,8 +99,8 @@ public class DictionaryPanelBuilder extends PanelBuilder { if (model.getCompanions().size() > 0) { Dictionary oldCompanion = model.getCompanions().get(0).getDictionary(); String oldName = oldDictionary.getName(); - String oldType = oldDictionary.lookup(TYPE); - String oldCompanionType = oldCompanion.lookup(TYPE); + String oldType = oldDictionary.lookup(selector); + String oldCompanionType = oldCompanion.lookup(selector); // System.out.println("DictionaryPanelBuilder.selectDictionaries() OLD TYPE: "+oldType+" OLD NAME: "+oldName+" OLD COMPANION TYPE: "+oldCompanionType); if (newName.equals(oldName) && newType.equals(oldType) && newCompanionType.equals(oldCompanionType)) { @@ -117,9 +120,13 @@ public class DictionaryPanelBuilder extends PanelBuilder { } public void selectDictionary(Dictionary newDictionary) { + selectDictionary(newDictionary, TYPE); + } + + public void selectDictionary(Dictionary newDictionary, String selector) { if (newDictionary != null /* && newDictionary.found(TYPE) */) { String newName = newDictionary.getName(); - String newType = newDictionary.lookup(TYPE); + String newType = newDictionary.lookup(selector); // System.out.println("DictionaryPanelBuilder.selectDictionary() NEW TYPE: "+newType+" NEW NAME: "+newName); if (newName != null && newType != null) { @@ -128,7 +135,7 @@ public class DictionaryPanelBuilder extends PanelBuilder { if (model.getCompanions().size() == 0) { Dictionary oldDictionary = model.getDictionary(); String oldName = oldDictionary.getName(); - String oldType = oldDictionary.lookup(TYPE); + String oldType = oldDictionary.lookup(selector); // System.out.println("DictionaryPanelBuilder.selectDictionary() OLD TYPE: "+oldType+" OLD NAME: "+oldName); diff --git a/src/eu/engys/core/dictionary/model/DictionaryTableAdapter.java b/src/eu/engys/core/dictionary/model/DictionaryTableAdapter.java index dfbea5a..feea6b1 100644 --- a/src/eu/engys/core/dictionary/model/DictionaryTableAdapter.java +++ b/src/eu/engys/core/dictionary/model/DictionaryTableAdapter.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.dictionary.model; import eu.engys.core.dictionary.model.DictionaryModel.DictionaryListener; diff --git a/src/eu/engys/core/dictionary/model/EventActionType.java b/src/eu/engys/core/dictionary/model/EventActionType.java index 086d797..00f863a 100644 --- a/src/eu/engys/core/dictionary/model/EventActionType.java +++ b/src/eu/engys/core/dictionary/model/EventActionType.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.dictionary.model; public enum EventActionType { @@ -39,4 +38,4 @@ public enum EventActionType { public void isRemove() { this.equals(REMOVE); } -} +} \ No newline at end of file diff --git a/src/eu/engys/core/dictionary/model/LevelsTableAdapter.java b/src/eu/engys/core/dictionary/model/LevelsTableAdapter.java index 4adb732..ab4605a 100644 --- a/src/eu/engys/core/dictionary/model/LevelsTableAdapter.java +++ b/src/eu/engys/core/dictionary/model/LevelsTableAdapter.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.dictionary.model; @@ -123,7 +122,7 @@ public class LevelsTableAdapter extends DictionaryTableAdapter { for (JComponent[] row : getRowsMap().values()) { map.put(((IntegerField) row[1]).getIntValue(), ((DoubleField) row[0]).getDoubleValue()); } - return new TreeMap(map); + return new TreeMap<>(map); } } diff --git a/src/eu/engys/core/dictionary/model/LinesTableAdapter.java b/src/eu/engys/core/dictionary/model/LinesTableAdapter.java index 1dfa915..e2e97a6 100644 --- a/src/eu/engys/core/dictionary/model/LinesTableAdapter.java +++ b/src/eu/engys/core/dictionary/model/LinesTableAdapter.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.dictionary.model; diff --git a/src/eu/engys/core/dictionary/model/OneDictionaryPerRowTableAdapter.java b/src/eu/engys/core/dictionary/model/OneDictionaryPerRowTableAdapter.java index c049afa..cad1894 100644 --- a/src/eu/engys/core/dictionary/model/OneDictionaryPerRowTableAdapter.java +++ b/src/eu/engys/core/dictionary/model/OneDictionaryPerRowTableAdapter.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.dictionary.model; @@ -42,6 +41,8 @@ import eu.engys.util.ui.textfields.StringField; public class OneDictionaryPerRowTableAdapter extends DictionaryTableAdapter { + public static final String ROW_NAME = "one.dict.row"; + private final int NAME_COL = 0; protected final String[] columnNames; protected final String[] columnKeys; @@ -71,7 +72,7 @@ public class OneDictionaryPerRowTableAdapter extends DictionaryTableAdapter { this.dictKey = key; this.type = type; - setName("one.dict.row"); + setName(ROW_NAME); if (isStaticTable()) { setRowHeader(); @@ -136,7 +137,7 @@ public class OneDictionaryPerRowTableAdapter extends DictionaryTableAdapter { for (Dictionary d : dict.getDictionaries()) { JComponent[] row = new JComponent[columnKeys.length + 1]; if (isStaticTable()) - row[0] = new JLabel(rowKeys[rowIndex]); + row[0] = new JLabel(rowNames[rowIndex]); else row[0] = new StringField(d.getName()); diff --git a/src/eu/engys/core/dictionary/model/PatchesMapTableAdapter.java b/src/eu/engys/core/dictionary/model/PatchesMapTableAdapter.java index 0d1eb13..072d0a4 100644 --- a/src/eu/engys/core/dictionary/model/PatchesMapTableAdapter.java +++ b/src/eu/engys/core/dictionary/model/PatchesMapTableAdapter.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.dictionary.model; diff --git a/src/eu/engys/core/dictionary/model/PointInfo.java b/src/eu/engys/core/dictionary/model/PointInfo.java index 89c0dd8..5ab6c2b 100644 --- a/src/eu/engys/core/dictionary/model/PointInfo.java +++ b/src/eu/engys/core/dictionary/model/PointInfo.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.dictionary.model; import java.awt.Color; @@ -61,4 +60,4 @@ public class PointInfo { return color; } -} +} \ No newline at end of file diff --git a/src/eu/engys/core/dictionary/model/PointTableAdapter.java b/src/eu/engys/core/dictionary/model/PointTableAdapter.java index aa8c7e2..327733c 100644 --- a/src/eu/engys/core/dictionary/model/PointTableAdapter.java +++ b/src/eu/engys/core/dictionary/model/PointTableAdapter.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.dictionary.model; diff --git a/src/eu/engys/core/dictionary/model/ShowAxisAdapter.java b/src/eu/engys/core/dictionary/model/ShowAxisAdapter.java index f556783..81eace7 100644 --- a/src/eu/engys/core/dictionary/model/ShowAxisAdapter.java +++ b/src/eu/engys/core/dictionary/model/ShowAxisAdapter.java @@ -1,29 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.dictionary.model; import java.awt.BorderLayout; @@ -33,80 +31,81 @@ import java.beans.PropertyChangeListener; import javax.swing.AbstractAction; import javax.swing.AbstractButton; -import javax.swing.ImageIcon; +import javax.swing.Icon; import javax.swing.JComponent; import javax.swing.JPanel; import javax.swing.JToggleButton; -import net.java.dev.designgridlayout.Componentizer; +import eu.engys.util.ui.ResourcesUtil; import eu.engys.util.ui.textfields.DoubleField; +import net.java.dev.designgridlayout.Componentizer; public class ShowAxisAdapter extends JPanel { - private static final ImageIcon ICON_ON = new ImageIcon(AbstractTableAdapter.class.getClassLoader().getResource("eu/engys/resources/images/lightbulb16.png")); - private static final ImageIcon ICON_OFF = new ImageIcon(AbstractTableAdapter.class.getClassLoader().getResource("eu/engys/resources/images/lightbulb_off16.png")); + private static final Icon ICON_ON = ResourcesUtil.getIcon("light.on.icon"); + private static final Icon ICON_OFF = ResourcesUtil.getIcon("light.off.icon"); - private JToggleButton button; - private DoubleField[] axis; - private DoubleField[] centre; + private JToggleButton button; + private DoubleField[] axis; + private DoubleField[] centre; - public ShowAxisAdapter(DoubleField[] axis, DoubleField[] centre) { - super(new BorderLayout()); - this.axis = axis; - this.centre = centre; - this.button = newShowAxisButton(false); - JComponent component = Componentizer.create().minAndMore(centre).minToPref(button).component(); - add(component, BorderLayout.CENTER); - } + public ShowAxisAdapter(DoubleField[] axis, DoubleField[] centre) { + super(new BorderLayout()); + this.axis = axis; + this.centre = centre; + this.button = newShowAxisButton(false); + JComponent component = Componentizer.create().minAndMore(centre).minToPref(button).component(); + add(component, BorderLayout.CENTER); + } - @Override - public void setName(String name) { - super.setName(name); - button.setName(getName()+".button"); - axis[0].setName(getName()+".axis.0"); - axis[1].setName(getName()+".axis.1"); - axis[2].setName(getName()+".axis.2"); - centre[0].setName(getName()+".centre.0"); - centre[1].setName(getName()+".centre.1"); - centre[2].setName(getName()+".centre.2"); - } - - @Override - public void addPropertyChangeListener(String propertyName, PropertyChangeListener listener) { - super.addPropertyChangeListener(propertyName, listener); - if (propertyName.equals("point.location")) { - button.getAction().addPropertyChangeListener(listener); - } - } + @Override + public void setName(String name) { + super.setName(name); + button.setName(getName() + ".button"); + axis[0].setName(getName() + ".axis.0"); + axis[1].setName(getName() + ".axis.1"); + axis[2].setName(getName() + ".axis.2"); + centre[0].setName(getName() + ".centre.0"); + centre[1].setName(getName() + ".centre.1"); + centre[2].setName(getName() + ".centre.2"); + } - public void turnOff() { - if (button.isSelected()) { - button.doClick(); - } - } + @Override + public void addPropertyChangeListener(String propertyName, PropertyChangeListener listener) { + super.addPropertyChangeListener(propertyName, listener); + if (propertyName.equals("point.location")) { + button.getAction().addPropertyChangeListener(listener); + } + } - public JToggleButton newShowAxisButton(boolean selected) { - final JToggleButton button = new JToggleButton(new AbstractAction() { - // private Border originalBorder; + public void turnOff() { + if (button.isSelected()) { + button.doClick(); + } + } - @Override - public void actionPerformed(ActionEvent e) { - AbstractButton b = ((AbstractButton) e.getSource()); - if (b.isSelected()) { - firePropertyChange(PointInfo.PROPERTY_NAME, null, new AxisInfo(axis, centre, EventActionType.SHOW)); - } else { - firePropertyChange(PointInfo.PROPERTY_NAME, null, new AxisInfo(axis, centre, EventActionType.HIDE)); - } - } - }); - if (selected && !button.isSelected() || (!selected && button.isSelected())) { - button.doClick(); - } - button.setPreferredSize(new Dimension(22, 22)); - button.setIcon(ICON_OFF); - button.setSelectedIcon(ICON_ON); - button.setToolTipText("Click to display this point in the 3D canvas"); - return button; - } + public JToggleButton newShowAxisButton(boolean selected) { + final JToggleButton button = new JToggleButton(new AbstractAction() { + // private Border originalBorder; + + @Override + public void actionPerformed(ActionEvent e) { + AbstractButton b = ((AbstractButton) e.getSource()); + if (b.isSelected()) { + firePropertyChange(PointInfo.PROPERTY_NAME, null, new AxisInfo(axis, centre, 1, EventActionType.SHOW)); + } else { + firePropertyChange(PointInfo.PROPERTY_NAME, null, new AxisInfo(axis, centre, 1, EventActionType.HIDE)); + } + } + }); + if (selected && !button.isSelected() || (!selected && button.isSelected())) { + button.doClick(); + } + button.setPreferredSize(new Dimension(22, 22)); + button.setIcon(ICON_OFF); + button.setSelectedIcon(ICON_ON); + button.setToolTipText("Click to display this point in the 3D canvas"); + return button; + } } diff --git a/src/eu/engys/core/dictionary/model/ShowLocationAdapter.java b/src/eu/engys/core/dictionary/model/ShowLocationAdapter.java index 72f99f0..be0a9cc 100644 --- a/src/eu/engys/core/dictionary/model/ShowLocationAdapter.java +++ b/src/eu/engys/core/dictionary/model/ShowLocationAdapter.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.dictionary.model; import java.awt.BorderLayout; @@ -33,22 +32,24 @@ import java.beans.PropertyChangeListener; import javax.swing.AbstractAction; import javax.swing.AbstractButton; -import javax.swing.BorderFactory; import javax.swing.Icon; import javax.swing.JComponent; import javax.swing.JPanel; import javax.swing.JToggleButton; -import javax.swing.border.Border; -import net.java.dev.designgridlayout.Componentizer; import eu.engys.util.ColorUtil; import eu.engys.util.ui.ResourcesUtil; import eu.engys.util.ui.textfields.DoubleField; +import net.java.dev.designgridlayout.Componentizer; public class ShowLocationAdapter extends JPanel { - private static final Icon ICON_ON = ResourcesUtil.getResourceIcon("eu/engys/resources/images/lightbulb16.png"); - private static final Icon ICON_OFF = ResourcesUtil.getResourceIcon("eu/engys/resources/images/lightbulb_off16.png"); + private static final Icon ICON_ON = ResourcesUtil.getIcon("light.on.icon"); + private static final Icon ICON_OFF = ResourcesUtil.getIcon("light.off.icon"); + + public static final String X = "x"; + public static final String Y = "y"; + public static final String Z = "z"; private JToggleButton button; private DoubleField[] fields; @@ -57,50 +58,35 @@ public class ShowLocationAdapter extends JPanel { super(new BorderLayout()); this.fields = fields; this.button = newShowPointButton(fields, key, false); + + fields[0].setName(X); + fields[1].setName(Y); + fields[2].setName(Z); + JComponent component = Componentizer.create().minAndMore(fields).minToPref(button).component(); add(component, BorderLayout.CENTER); } - @Override - public void addPropertyChangeListener(String propertyName, PropertyChangeListener listener) { - super.addPropertyChangeListener(propertyName, listener); - if (propertyName.equals(PointInfo.PROPERTY_NAME)) { - button.getAction().addPropertyChangeListener(listener); - } - } - - public void turnMaterialPointsOn() { - if (!button.isSelected()) { - button.doClick(); - } - } - - public void turnMaterialPointsOff() { - if (button.isSelected()) { - button.doClick(); - } - } - public static JToggleButton newShowPointButton(final DoubleField[] locationInMesh, int index, boolean selected) { return newShowPointButton(locationInMesh, ColorUtil.getColor(index), selected); } - public static JToggleButton newShowPointButton(final DoubleField[] locationInMesh, final Color color, boolean selected) { + private static JToggleButton newShowPointButton(final DoubleField[] locationInMesh, final Color color, boolean selected) { final JToggleButton button = new JToggleButton(new AbstractAction() { - private Border originalBorder; + Object originalColorProperty = new JToggleButton().getClientProperty("Synthetica.background"); + Object originalColorAlphaProperty = new JToggleButton().getClientProperty("Synthetica.background.alpha"); @Override public void actionPerformed(ActionEvent e) { AbstractButton b = ((AbstractButton) e.getSource()); if (b.isSelected()) { firePropertyChange(PointInfo.PROPERTY_NAME, null, new PointInfo(locationInMesh, color.toString(), EventActionType.SHOW, color)); - originalBorder = b.getBorder(); - b.setBorder(BorderFactory.createLineBorder(color, 2)); + b.putClientProperty("Synthetica.background", color); + b.putClientProperty("Synthetica.background.alpha", 0.50f); } else { firePropertyChange(PointInfo.PROPERTY_NAME, null, new PointInfo(locationInMesh, color.toString(), EventActionType.HIDE, color)); - if (originalBorder != null) { - b.setBorder(originalBorder); - } + b.putClientProperty("Synthetica.background", originalColorProperty); + b.putClientProperty("Synthetica.background.alpha", originalColorAlphaProperty); } } }); @@ -114,6 +100,34 @@ public class ShowLocationAdapter extends JPanel { return button; } + @Override + public void addPropertyChangeListener(String propertyName, PropertyChangeListener listener) { + super.addPropertyChangeListener(propertyName, listener); + if (propertyName.equals(PointInfo.PROPERTY_NAME)) { + button.getAction().addPropertyChangeListener(listener); + } + } + + public DoubleField[] getFields() { + return fields; + } + + public JToggleButton getButton() { + return button; + } + + public void turnMaterialPointsOn() { + if (!button.isSelected()) { + button.doClick(); + } + } + + public void turnMaterialPointsOff() { + if (button.isSelected()) { + button.doClick(); + } + } + @Override public void setToolTipText(String text) { super.setToolTipText(text); diff --git a/src/eu/engys/core/dictionary/parser/DictionaryReader2.java b/src/eu/engys/core/dictionary/parser/DictionaryReader2.java index b02e5b7..0e930c6 100644 --- a/src/eu/engys/core/dictionary/parser/DictionaryReader2.java +++ b/src/eu/engys/core/dictionary/parser/DictionaryReader2.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.dictionary.parser; diff --git a/src/eu/engys/core/dictionary/parser/ListField2.java b/src/eu/engys/core/dictionary/parser/ListField2.java index 52a04c1..9335e13 100644 --- a/src/eu/engys/core/dictionary/parser/ListField2.java +++ b/src/eu/engys/core/dictionary/parser/ListField2.java @@ -1,29 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.dictionary.parser; import static eu.engys.core.dictionary.Dictionary.SPACER; @@ -32,9 +30,12 @@ import static eu.engys.core.dictionary.Dictionary.TAB; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; +import java.util.LinkedList; import java.util.List; import java.util.StringTokenizer; +import org.apache.commons.lang.builder.EqualsBuilder; +import org.apache.commons.lang.builder.HashCodeBuilder; import org.apache.commons.lang.math.NumberUtils; import com.google.common.primitives.Doubles; @@ -83,7 +84,7 @@ public class ListField2 extends DefaultElement { StringTokenizer tokenizer = new StringTokenizer(name, SPACER); if (tokenizer.countTokens() == 1) { // internalField (...); oppure // 10 (...); -// System.out.println("ListField2.decodeName() 1"); + // System.out.println("ListField2.decodeName() 1"); String token = tokenizer.nextToken(); try { this.size = Integer.parseInt(token); @@ -97,29 +98,29 @@ public class ListField2 extends DefaultElement { } else if (tokenizer.countTokens() == 2) {// internalField 10 (...); String token1 = tokenizer.nextToken(); String token2 = tokenizer.nextToken(); -// System.out.println("ListField2.decodeName() token1: [" + token1 + "], token2: [" + token2 + "]"); - + // System.out.println("ListField2.decodeName() token1: [" + token1 + "], token2: [" + token2 + "]"); + try { this.size = Integer.parseInt(token2); } catch (NumberFormatException ex) { this.size = -1; } - if(size < 0){ - setName(token1 + " " + token2); + if (size < 0) { + setName(token1 + " " + token2); } else { - setName(token1); + setName(token1); } this.uniformity = ""; this.identifier = ""; } else if (tokenizer.countTokens() == 3) {// internalField // nonuniform 0() -// System.out.println("ListField2.decodeName() 3"); + // System.out.println("ListField2.decodeName() 3"); String token1 = tokenizer.nextToken(); String token2 = tokenizer.nextToken(); String token3 = tokenizer.nextToken(); -// System.out.println("ListField2.decodeName() token1 = '" + token1 + "'"); -// System.out.println("ListField2.decodeName() token2 = '" + token2 + "'"); -// System.out.println("ListField2.decodeName() token3 = '" + token3 + "'"); + // System.out.println("ListField2.decodeName() token1 = '" + token1 + "'"); + // System.out.println("ListField2.decodeName() token2 = '" + token2 + "'"); + // System.out.println("ListField2.decodeName() token3 = '" + token3 + "'"); try { this.size = Integer.parseInt(token3); } catch (NumberFormatException ex) { @@ -131,7 +132,7 @@ public class ListField2 extends DefaultElement { } else if (tokenizer.countTokens() == 4) { // internalField // nonuniform // List 10 -// System.out.println("ListField2.decodeName() 4"); + // System.out.println("ListField2.decodeName() 4"); String token1 = tokenizer.nextToken(); String token2 = tokenizer.nextToken(); String token3 = tokenizer.nextToken(); @@ -148,7 +149,9 @@ public class ListField2 extends DefaultElement { } else { try { this.size = Integer.parseInt(name); - setName(Integer.toString(hashCode())); + // Need to call hashcode method from Object class because we can have to ListFields + // With all the parameters equals (like in a eMesh file) + setName(Integer.toString(System.identityHashCode(this))); } catch (NumberFormatException ex) { this.size = -1; setName(name); @@ -174,12 +177,22 @@ public class ListField2 extends DefaultElement { return Collections.unmodifiableList(listElements); } + public List getListFields2() { + List l = new LinkedList<>(); + for (DefaultElement e : listElements) { + if(e instanceof ListField2){ + l.add((ListField2) e); + } + } + return Collections.unmodifiableList(l); + } + public void removeTopElements(int n) { for (int i = 0; i < n; i++) { listElements.remove(0); } } - + public void merge(ListField2 l) { for (DefaultElement el : l.getListElements()) { if (!containsElement(el)) { @@ -201,24 +214,8 @@ public class ListField2 extends DefaultElement { return false; } - protected boolean haveSameName(DefaultElement element, DefaultElement e) { - return e.getName().equals(element.getName()); - } - - @Override - public boolean equals(Object obj) { - if (obj instanceof ListField2) { - ListField2 list = (ListField2) obj; - boolean haveSameName = haveSameName(this, list); -// boolean equalCollection = CollectionUtils.isEqualCollection(list.getListElements(), listElements); - boolean equalCollection = list.getListElements().containsAll(listElements) && listElements.containsAll(list.getListElements()); - return haveSameName && equalCollection; - } - return false; - } - public void writeListField(StringBuffer sb, String rowHeader) { -// System.out.println("ListField2.writeListField() name: "+getName()+", size: "+size+", uniformity: "+uniformity+", identifier: "+identifier); + // System.out.println("ListField2.writeListField() name: "+getName()+", size: "+size+", uniformity: "+uniformity+", identifier: "+identifier); sb.append("\n"); sb.append(rowHeader); sb.append(TAB); @@ -258,7 +255,7 @@ public class ListField2 extends DefaultElement { String name = getName(); return NumberUtils.isNumber(name); } - + private void writeName(StringBuffer sb) { String name = getName(); if (NumberUtils.isNumber(name)) { @@ -313,25 +310,25 @@ public class ListField2 extends DefaultElement { public boolean isNonuniform() { return uniformity.equals("nonuniform"); } - + public static String convertToString(ListField2 listField) { - StringBuilder sb = new StringBuilder(); - convertToString(listField, sb); - return sb.toString(); + StringBuilder sb = new StringBuilder(); + convertToString(listField, sb); + return sb.toString(); } - + private static void convertToString(ListField2 listField, StringBuilder sb) { - sb.append("("); - for (DefaultElement el : listField.getListElements()) { - if(el instanceof FieldElement){ - sb.append(((FieldElement) el).getValue()); - sb.append(" "); - } else if(el instanceof ListField2){ - convertToString((ListField2)el, sb); - } - } - sb.append(")"); - } + sb.append("("); + for (DefaultElement el : listField.getListElements()) { + if (el instanceof FieldElement) { + sb.append(((FieldElement) el).getValue()); + sb.append(" "); + } else if (el instanceof ListField2) { + convertToString((ListField2) el, sb); + } + } + sb.append(")"); + } public List getElementsAsScalarList() { List list = new ArrayList<>(); @@ -357,5 +354,44 @@ public class ListField2 extends DefaultElement { } return list; } + +// @Override +// public boolean equals(Object obj) { +// if (obj instanceof ListField2) { +// ListField2 list = (ListField2) obj; +// boolean haveSameName = haveSameName(this, list); +//// boolean equalCollection = CollectionUtils.isEqualCollection(list.getListElements(), listElements); +// boolean equalCollection = list.getListElements().containsAll(listElements) && listElements.containsAll(list.getListElements()); +// return haveSameName && equalCollection; +// } +// return false; +// } + + @Override + public boolean equals(Object obj) { + if (!(obj instanceof ListField2)) { + return false; + } + if (obj == this) { + return true; + } + ListField2 lf = (ListField2) obj; + return new EqualsBuilder() + .appendSuper(super.equals(obj)) + .append(getListElements(), lf.getListElements()) + .isEquals(); + } + + @Override + public int hashCode() { + return new HashCodeBuilder(17, 31) + .appendSuper(super.hashCode()) + .append(getListElements()) + .toHashCode(); + } + + protected boolean haveSameName(DefaultElement element, DefaultElement e) { + return e.getName().equals(element.getName()); + } } diff --git a/src/eu/engys/core/dictionary/parser/ListReader2.java b/src/eu/engys/core/dictionary/parser/ListReader2.java index 132f7c7..90ea9d8 100644 --- a/src/eu/engys/core/dictionary/parser/ListReader2.java +++ b/src/eu/engys/core/dictionary/parser/ListReader2.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.dictionary.parser; diff --git a/src/eu/engys/core/dictionary/parser/ThetaListField2.java b/src/eu/engys/core/dictionary/parser/ThetaListField2.java index 3bd9e08..fb251fd 100644 --- a/src/eu/engys/core/dictionary/parser/ThetaListField2.java +++ b/src/eu/engys/core/dictionary/parser/ThetaListField2.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.dictionary.parser; import java.util.ArrayList; diff --git a/src/eu/engys/core/dictionary/parser/ThetaListReader2.java b/src/eu/engys/core/dictionary/parser/ThetaListReader2.java index 27479a6..22f2a59 100644 --- a/src/eu/engys/core/dictionary/parser/ThetaListReader2.java +++ b/src/eu/engys/core/dictionary/parser/ThetaListReader2.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.dictionary.parser; import static eu.engys.core.dictionary.Dictionary.VERBOSE; diff --git a/src/eu/engys/core/executor/AbstractExecutor.java b/src/eu/engys/core/executor/AbstractExecutor.java index 2b8972f..c0fdf95 100644 --- a/src/eu/engys/core/executor/AbstractExecutor.java +++ b/src/eu/engys/core/executor/AbstractExecutor.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.executor; import java.io.File; @@ -169,6 +168,11 @@ public abstract class AbstractExecutor extends Executor { return error; } + @Override + public String getDescription() { + return description; + } + protected void notifyStart() { this.state = ExecutorState.START; if (terminal != null) { diff --git a/src/eu/engys/core/executor/AbstractScriptExecutor.java b/src/eu/engys/core/executor/AbstractScriptExecutor.java index 0fd6f47..c99c66f 100644 --- a/src/eu/engys/core/executor/AbstractScriptExecutor.java +++ b/src/eu/engys/core/executor/AbstractScriptExecutor.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.executor; import java.io.File; @@ -49,6 +48,7 @@ public abstract class AbstractScriptExecutor extends AbstractExecutor { protected int _exec() { int returnValue = 0; CommandLine cmdLine = getCommandLine(); + logger.debug("[EXECUTOR] {}", cmdLine); DefaultExecuteResultHandler resultHandler = new DefaultExecuteResultHandler(); ExecuteWatchdog watchdog = new ScriptExecuteWatchdog(); diff --git a/src/eu/engys/core/executor/CollapseManager.java b/src/eu/engys/core/executor/CollapseManager.java deleted file mode 100644 index 1ab312b..0000000 --- a/src/eu/engys/core/executor/CollapseManager.java +++ /dev/null @@ -1,83 +0,0 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - -package eu.engys.core.executor; - -import javax.swing.JSplitPane; -import javax.swing.JTabbedPane; -import javax.swing.event.ChangeEvent; -import javax.swing.event.ChangeListener; - -public class CollapseManager { - - private JTabbedPane tabbedPane; - - public CollapseManager(JTabbedPane tabbedPane) { - this.tabbedPane = tabbedPane; - tabbedPane.getModel().addChangeListener(new ChangeListener() { - @Override - public void stateChanged(ChangeEvent e) { - collapsePanelIfEmpty(); - } - }); - } - - private void collapsePanelIfEmpty() { - boolean isEmpty = tabbedPane.getTabCount() == 0; - if (isEmpty) { - collapse(); - } else if (canExpand()) { - expand(); - } - } - - public boolean canExpand() { - boolean hasOne = tabbedPane.getTabCount() >= 1; - boolean isCollapsed = getSplitPane().getResizeWeight() == 1; - return hasOne && isCollapsed; - } - - public void collapse() { - getSplitPane().setDividerLocation(getSplitPane().getHeight()); - getSplitPane().setResizeWeight(1); - } - - public void expand() { - getSplitPane().setDividerLocation(getSplitPane().getHeight() - 300); - getSplitPane().setResizeWeight(0.7); - } - - public void toggle() { - if (canExpand()) { - expand(); - } else { - collapse(); - } - } - - private JSplitPane getSplitPane() { - return (JSplitPane) tabbedPane.getParent(); - } -} diff --git a/src/eu/engys/core/executor/CommandExecutor.java b/src/eu/engys/core/executor/CommandExecutor.java index 9cf7e3d..c808aca 100644 --- a/src/eu/engys/core/executor/CommandExecutor.java +++ b/src/eu/engys/core/executor/CommandExecutor.java @@ -1,33 +1,33 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.executor; import static eu.engys.core.OpenFOAMEnvironment.cleanEnvironment; import static eu.engys.core.OpenFOAMEnvironment.loadEnvironment; import static eu.engys.core.OpenFOAMEnvironment.printHeader; +import static eu.engys.core.OpenFOAMEnvironment.printVariables; import java.io.File; import java.util.List; @@ -58,7 +58,11 @@ public class CommandExecutor extends AbstractScriptExecutor { @Override protected void internalDeleteOnEnd() { - FileUtils.deleteQuietly(supportFile); + if(keepFileOnEnd){ + //do nothing + } else { + FileUtils.deleteQuietly(supportFile); + } } private void writeCommandInSupportFile(File supportFile) { @@ -69,6 +73,7 @@ public class CommandExecutor extends AbstractScriptExecutor { private List getCommand() { ScriptBuilder sb = new ScriptBuilder(); printHeader(sb, description); + printVariables(sb); if (Util.isWindows()) { if (loadOpenFoamEnv) { loadEnvironment(sb); diff --git a/src/eu/engys/core/executor/ConsoleExecutorMonitor.java b/src/eu/engys/core/executor/ConsoleExecutorMonitor.java index b92fade..f17779f 100644 --- a/src/eu/engys/core/executor/ConsoleExecutorMonitor.java +++ b/src/eu/engys/core/executor/ConsoleExecutorMonitor.java @@ -1,37 +1,49 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.executor; public class ConsoleExecutorMonitor extends ExecutorTerminal { - @Override + private boolean useHeader; + private boolean flushErrors; + + public ConsoleExecutorMonitor() { + this(false, false); + } + + public ConsoleExecutorMonitor(boolean useHeader, boolean flushErrors) { + this.useHeader = useHeader; + this.flushErrors = flushErrors; + } + + @Override public void start() { } + @Override public void finish(int returnValue) { super.finish(returnValue); @@ -46,7 +58,12 @@ public class ConsoleExecutorMonitor extends ExecutorTerminal { @Override public void refresh() { - System.out.print(getOutputStream().flushLinesBuffer()); + String outputLines = getOutputStream().flushLinesBuffer(); + System.out.print(useHeader? outputLines.replace("\n", "\n[OUT] ") : outputLines); + if (flushErrors) { + String errorLines = getErrorStream().flushLinesBuffer(); + System.err.print(useHeader ? errorLines.replace("\n", "\n[ERR] ") : errorLines); + } } } diff --git a/src/eu/engys/core/executor/Executor.java b/src/eu/engys/core/executor/Executor.java index c9c4d8d..1ca2f2a 100644 --- a/src/eu/engys/core/executor/Executor.java +++ b/src/eu/engys/core/executor/Executor.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.executor; @@ -94,6 +93,7 @@ public abstract class Executor { public abstract ExecutorService getService(); public abstract ExecutorState getState(); public abstract ExecutorError getError(); + public abstract String getDescription(); public void notify(ExecutorState state) { } diff --git a/src/eu/engys/core/executor/ExecutorError.java b/src/eu/engys/core/executor/ExecutorError.java index 085bf0f..4f80260 100644 --- a/src/eu/engys/core/executor/ExecutorError.java +++ b/src/eu/engys/core/executor/ExecutorError.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.executor; import java.io.Serializable; diff --git a/src/eu/engys/core/executor/ExecutorHook.java b/src/eu/engys/core/executor/ExecutorHook.java index 3bbe5a4..4a45f3b 100644 --- a/src/eu/engys/core/executor/ExecutorHook.java +++ b/src/eu/engys/core/executor/ExecutorHook.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.executor; public interface ExecutorHook { diff --git a/src/eu/engys/core/executor/ExecutorListener.java b/src/eu/engys/core/executor/ExecutorListener.java index f138d14..5526914 100644 --- a/src/eu/engys/core/executor/ExecutorListener.java +++ b/src/eu/engys/core/executor/ExecutorListener.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.executor; diff --git a/src/eu/engys/core/executor/ExecutorMonitor.java b/src/eu/engys/core/executor/ExecutorMonitor.java index 7ffc3f1..23ea2a1 100644 --- a/src/eu/engys/core/executor/ExecutorMonitor.java +++ b/src/eu/engys/core/executor/ExecutorMonitor.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.executor; import java.util.ArrayList; diff --git a/src/eu/engys/core/executor/ExecutorTerminal.java b/src/eu/engys/core/executor/ExecutorTerminal.java index f22ab4d..063e630 100644 --- a/src/eu/engys/core/executor/ExecutorTerminal.java +++ b/src/eu/engys/core/executor/ExecutorTerminal.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.executor; import java.util.concurrent.ExecutorService; diff --git a/src/eu/engys/core/executor/FileManagerSupport.java b/src/eu/engys/core/executor/FileManagerSupport.java index 4216049..22648b5 100644 --- a/src/eu/engys/core/executor/FileManagerSupport.java +++ b/src/eu/engys/core/executor/FileManagerSupport.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.executor; import java.awt.Desktop; @@ -40,6 +39,7 @@ import org.slf4j.LoggerFactory; import eu.engys.util.PDFFileFilter; import eu.engys.util.PrefUtil; +import eu.engys.util.TempFolder; import eu.engys.util.Util; import eu.engys.util.ui.UiUtil; @@ -63,7 +63,7 @@ public class FileManagerSupport { public static void open(File file) { if (Util.isWindows()) { // Desktop.getDesktop().open(file) on windows may hang - _open(file, "Open action not supported"); + _openWindows(file); } else { openOnLinux(file); } @@ -76,18 +76,28 @@ public class FileManagerSupport { try { Desktop.getDesktop().open(file); } catch (IOException e) { - _open(file, e.getMessage()); + _openLinux(file); } } else { - _open(file, "Open action not supported"); + _openLinux(file); } } else { - _open(file, "Desktop class not supported by this platform"); + _openLinux(file); } } - private static void _open(File file, String logInfo) { - Executor.command(getOpenCommand(file), getOpenCommandArguments(file)).description(ACTION_NAME).exec(); + private static void _openLinux(File file) { + File inFolder = TempFolder.get(); + Executor.command(getOpenCommand(file), getOpenCommandArguments(file)).inFolder(inFolder).description(ACTION_NAME).exec(); + } + + /* + * If you try to open multiple files (e.g. parser log files) just one of the files is opened. + * The command rundll32.exe is not blocking therefore I can call execAndWait + */ + private static void _openWindows(File file) { + File inFolder = TempFolder.get(); + Executor.command(getOpenCommand(file), getOpenCommandArguments(file)).inFolder(inFolder).description(ACTION_NAME).execAndWait(); } private static String getOpenCommand(File file) { diff --git a/src/eu/engys/core/executor/JavaExecutor.java b/src/eu/engys/core/executor/JavaExecutor.java index 753d5cc..b62f1b6 100644 --- a/src/eu/engys/core/executor/JavaExecutor.java +++ b/src/eu/engys/core/executor/JavaExecutor.java @@ -1,29 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.executor; import java.nio.file.Path; @@ -44,17 +42,13 @@ public class JavaExecutor extends AbstractScriptExecutor { @Override public CommandLine getCommandLine() { - return buildCommandLineScript(); - } - - private CommandLine buildCommandLineScript() { String separator = System.getProperty("file.separator"); String classpath = System.getProperty("java.class.path"); String java = System.getProperty("java.home") + separator + "bin" + separator + "java"; final CommandLine cmdLine = new CommandLine(java); cmdLine.addArgument("-classpath"); - cmdLine.addArgument(reletivize(classpath)); + cmdLine.addArgument(relativize(classpath)); addSystemProperties(cmdLine); cmdLine.addArgument(className); cmdLine.addArguments(args); @@ -62,28 +56,39 @@ public class JavaExecutor extends AbstractScriptExecutor { return cmdLine; } - private String reletivize(String classpath) { + private String relativize(String classpath) { if (currentDir != null) { - String relative = ""; - String[] paths = classpath.split(System.getProperty("path.separator")); - for (String path : paths) { + String relativizedClassPath = ""; + for (String path : classpath.split(System.getProperty("path.separator"))) { Path p = Paths.get(path); - if(!p.isAbsolute()){ + if (!p.isAbsolute()) { p = p.toAbsolutePath(); } - Path relativize = currentDir.getAbsoluteFile().toPath().relativize(p); - relative += (relativize + System.getProperty("path.separator")); + + Path relativize; + if (canRelativize(currentDir.getAbsoluteFile().toPath(), p)) { + relativize = p; + } else { + relativize = currentDir.getAbsoluteFile().toPath().relativize(p); + } + + relativizedClassPath += (relativize + System.getProperty("path.separator")); } - return relative; + return relativizedClassPath; } else { return classpath; } } + private boolean canRelativize(Path p1, Path p2) { + // windows case where you have C:\ and D:\ + return p1.getRoot() != p2.getRoot(); + } + private void addSystemProperties(CommandLine cmdLine) { if (properties != null) { for (String key : properties.stringPropertyNames()) { - cmdLine.addArgument("-D"+key+"="+properties.getProperty(key)); + cmdLine.addArgument("-D" + key + "=" + properties.getProperty(key)); } } } diff --git a/src/eu/engys/core/executor/MailManagerSupport.java b/src/eu/engys/core/executor/MailManagerSupport.java index d414568..9b181fe 100644 --- a/src/eu/engys/core/executor/MailManagerSupport.java +++ b/src/eu/engys/core/executor/MailManagerSupport.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.executor; diff --git a/src/eu/engys/core/executor/ProgressExecutorMonitor.java b/src/eu/engys/core/executor/ProgressExecutorMonitor.java index cf1585f..453724c 100644 --- a/src/eu/engys/core/executor/ProgressExecutorMonitor.java +++ b/src/eu/engys/core/executor/ProgressExecutorMonitor.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.executor; diff --git a/src/eu/engys/core/executor/QueueExecutorMonitor.java b/src/eu/engys/core/executor/QueueExecutorMonitor.java deleted file mode 100644 index 9600bce..0000000 --- a/src/eu/engys/core/executor/QueueExecutorMonitor.java +++ /dev/null @@ -1,91 +0,0 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - - -package eu.engys.core.executor; - -import java.io.File; -import java.util.ArrayList; -import java.util.List; - -import org.apache.commons.io.input.Tailer; -import org.apache.commons.io.input.TailerListenerAdapter; - -public class QueueExecutorMonitor extends ExecutorTerminal { - - private File[] outputFiles; - private List tailers; - - public QueueExecutorMonitor(File... outputFile) { - this.outputFiles = outputFile; - this.tailers = new ArrayList<>(); - } - - @Override - public void start() { - super.start(); - for (File outputFile : outputFiles) { - tailers.add(Tailer.create(outputFile, new MyListener(), 500L)); - } - } - - @Override - public void finish(int returnValue) { - super.finish(returnValue); - for (Tailer tailer : tailers) { - tailer.stop(); - } - } - - @Override - public void error(int returnValue, String msg) { - super.error(returnValue, msg); - for (Tailer tailer : tailers) { - tailer.stop(); - } - System.err.println(msg); - } - - @Override - public void refresh() { - super.refresh(); - System.out.print(getOutputStream().flushLinesBuffer()); - System.err.print(getErrorStream().flushLinesBuffer()); - } - - class MyListener extends TailerListenerAdapter { - - @Override - public void handle(String line) { - System.out.println("[out] "+line); - } - - @Override - public void handle(Exception exception) { - System.err.println("[err] "+exception.getMessage()); - } - - } -} diff --git a/src/eu/engys/core/executor/QueueTerminalExecutorMonitor.java b/src/eu/engys/core/executor/QueueTerminalExecutorMonitor.java deleted file mode 100644 index 9e55c84..0000000 --- a/src/eu/engys/core/executor/QueueTerminalExecutorMonitor.java +++ /dev/null @@ -1,89 +0,0 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - -package eu.engys.core.executor; - -import java.io.File; -import java.util.ArrayList; -import java.util.List; - -import org.apache.commons.io.input.Tailer; -import org.apache.commons.io.input.TailerListenerAdapter; - -public class QueueTerminalExecutorMonitor extends TerminalExecutorMonitor { - - private File[] outputFiles; - private List tailers; - - public QueueTerminalExecutorMonitor(File... outputFile) { - this.outputFiles = outputFile; - this.tailers = new ArrayList<>(); - } - - @Override - public void start() { - for (File outputFile : outputFiles) { - tailers.add(Tailer.create(outputFile, new MyListener(), 500L)); - } - super.start(); - } - - @Override - public void finish(int returnValue) { - super.finish(returnValue); - for (Tailer tailer : tailers) { - tailer.stop(); - } - } - - @Override - public void error(int returnValue, String msg) { - super.error(returnValue, msg); - for (Tailer tailer : tailers) { - tailer.stop(); - } - // System.err.println(msg); - } - - @Override - public void refresh() { - super.refresh(); - // System.out.print(flushLinesBuffer()); - } - - class MyListener extends TailerListenerAdapter { - - @Override - public void handle(String line) { - area.append("[out] " + line + "\n"); - } - - @Override - public void handle(Exception exception) { - area.append("[err] " + exception.getMessage() + "\n"); - } - - } -} diff --git a/src/eu/engys/core/executor/ScriptExecutor.java b/src/eu/engys/core/executor/ScriptExecutor.java index db08d71..c2097f3 100644 --- a/src/eu/engys/core/executor/ScriptExecutor.java +++ b/src/eu/engys/core/executor/ScriptExecutor.java @@ -1,35 +1,36 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.executor; import java.io.File; import org.apache.commons.exec.CommandLine; +import eu.engys.core.DockerUtil; +import eu.engys.util.PrefUtil; + public class ScriptExecutor extends AbstractScriptExecutor { private File file; @@ -43,11 +44,15 @@ public class ScriptExecutor extends AbstractScriptExecutor { @Override protected CommandLine getCommandLine() { - CommandLine commandLine = new CommandLine(file.getAbsolutePath()); - if (args != null && args.length > 0) { - commandLine.addArguments(args); + if (PrefUtil.isUsingDocker()) { + return DockerUtil.getCommandLine(environment, file.getName()); + } else { + CommandLine commandLine = new CommandLine(file.getAbsolutePath()); + if (args != null && args.length > 0) { + commandLine.addArguments(args); + } + return commandLine; } - return commandLine; } @Override diff --git a/src/eu/engys/core/executor/StateMapperHook.java b/src/eu/engys/core/executor/StateMapperHook.java index 8ad94da..b418349 100644 --- a/src/eu/engys/core/executor/StateMapperHook.java +++ b/src/eu/engys/core/executor/StateMapperHook.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.executor; import eu.engys.core.controller.Command; @@ -46,4 +45,4 @@ public class StateMapperHook implements ExecutorHook { public void run(ExecutorMonitor m) { connector.offer(new ServerState(command, solverState, new ExecutorError(m.getReturnValue(), m.getErrorMessage()))); } -} +} \ No newline at end of file diff --git a/src/eu/engys/core/executor/TerminalExecutorMonitor.java b/src/eu/engys/core/executor/TerminalExecutorMonitor.java index d948431..43a5e78 100644 --- a/src/eu/engys/core/executor/TerminalExecutorMonitor.java +++ b/src/eu/engys/core/executor/TerminalExecutorMonitor.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.executor; import static eu.engys.util.ui.UiUtil.createToolBarButton; @@ -68,9 +67,9 @@ public class TerminalExecutorMonitor extends ExecutorTerminal { private static final String RUNNING_LABEL = "Running..."; public static final String TERMINAL_PANEL_AREA = "terminal.panel.area"; + public static final String TERMINAL_TOOLBAR = "terminal.toolbar"; protected JTextArea area; - private JScrollPane scroll; private JToolBar toolbar; private JPanel panel; @@ -94,13 +93,16 @@ public class TerminalExecutorMonitor extends ExecutorTerminal { } }; - public TerminalExecutorMonitor() { + private TerminalManager terminalManager; + + public TerminalExecutorMonitor(TerminalManager terminalManager) { super(); + this.terminalManager = terminalManager; layoutComponents(); } - public TerminalExecutorMonitor(File logFile) { - this(); + public TerminalExecutorMonitor(TerminalManager terminalManager, File logFile) { + this(terminalManager); setLogFile(logFile); } @@ -109,8 +111,9 @@ public class TerminalExecutorMonitor extends ExecutorTerminal { @Override public void run() { area = new JTextArea(); - scroll = new JScrollPane(area); + JScrollPane scroll = new JScrollPane(area); toolbar = new JToolBar(); + toolbar.setName(TERMINAL_TOOLBAR); panel = new JPanel(new BorderLayout()); scroll.setName("terminal.panel.scroll"); @@ -155,9 +158,9 @@ public class TerminalExecutorMonitor extends ExecutorTerminal { }); } - protected void configureFrameActions(JToolBar toolbar) { - maxAction = new MaximiseMonitorAction(panel); - closeAction = new CloseMonitorAction(panel); + private void configureFrameActions(JToolBar toolbar) { + maxAction = new MaximiseMonitorAction(terminalManager, panel); + closeAction = new CloseMonitorAction(terminalManager, panel); closeAction.setEnabled(false); toolbar.add(createToolBarToggleButton(maxAction)); toolbar.add(createToolBarButton(closeAction)); @@ -191,8 +194,10 @@ public class TerminalExecutorMonitor extends ExecutorTerminal { }); } - public void show() { - TerminalManager.getInstance().addTerminal(panel, TerminalExecutorMonitor.this); + private void show() { + if (terminalManager != null) { + terminalManager.addTerminal(panel, TerminalExecutorMonitor.this); + } } @Override @@ -201,7 +206,7 @@ public class TerminalExecutorMonitor extends ExecutorTerminal { } private String getTime() { - return new SimpleDateFormat("'['HH:mm:ss']'").format(startTime); + return startTime == null ? "" : new SimpleDateFormat("'['HH:mm:ss']'").format(startTime); } private void setupFont() { @@ -214,10 +219,10 @@ public class TerminalExecutorMonitor extends ExecutorTerminal { @Override public void error(final int returnValue, final String msg) { super.error(returnValue, msg); - refresh(); ExecUtil.invokeLater(new Runnable() { @Override public void run() { + _refresh(); stateLabel.setText(""); stopAction.setEnabled(false); if (closeAction != null) { @@ -253,15 +258,19 @@ public class TerminalExecutorMonitor extends ExecutorTerminal { }); } - protected void _refresh() { + private void _refresh() { + String lines = getOutputStream().flushLinesBuffer(); + String errors = getErrorStream().flushLinesBuffer(); + _refresh(lines, errors); + } + + protected void _refresh(String lines, String errors) { int maxLines = PrefUtil.getInt(PrefUtil.BATCH_MONITOR_DIALOG_MAX_ROW, 10000); - String lines = getOutputStream().flushLinesBuffer(); if (!lines.isEmpty()) { area.append(lines); } - String errors = getErrorStream().flushLinesBuffer(); if (!errors.isEmpty()) { area.append(errors); } @@ -281,7 +290,6 @@ public class TerminalExecutorMonitor extends ExecutorTerminal { } private boolean stopExecutor() { - // if (getState() == ExecutorState.START || getState() == ExecutorState.RUNNING) { if (executor != null) { int retVal = JOptionPane.showConfirmDialog(UiUtil.getActiveWindow(), "Stop execution?", "Close Monitor", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE); if (retVal == JOptionPane.YES_OPTION) { @@ -292,15 +300,12 @@ public class TerminalExecutorMonitor extends ExecutorTerminal { } else { return true; } - // } else { - // return true; - // } } public JPopupMenu createMenu(Component component) { JPopupMenu pMenu = new JPopupMenu(); pMenu.add(UiUtil.createMenuItem(new StopCommandAction(true))); - pMenu.add(UiUtil.createMenuItem(new CloseMonitorAction(panel, true))); + pMenu.add(UiUtil.createMenuItem(new CloseMonitorAction(terminalManager, panel, true))); return pMenu; } diff --git a/src/eu/engys/core/executor/TerminalManager.java b/src/eu/engys/core/executor/TerminalManager.java index 9209a39..08f31cd 100644 --- a/src/eu/engys/core/executor/TerminalManager.java +++ b/src/eu/engys/core/executor/TerminalManager.java @@ -1,29 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.executor; import java.awt.BorderLayout; @@ -40,12 +38,16 @@ import java.util.Map; import javax.swing.AbstractButton; import javax.swing.ImageIcon; +import javax.swing.JComponent; import javax.swing.JDialog; import javax.swing.JFrame; import javax.swing.JMenuItem; import javax.swing.JPopupMenu; +import javax.swing.JSplitPane; import javax.swing.JTabbedPane; import javax.swing.SwingUtilities; +import javax.swing.event.ChangeEvent; +import javax.swing.event.ChangeListener; import eu.engys.util.ApplicationInfo; import eu.engys.util.ui.ExecUtil; @@ -53,32 +55,28 @@ import eu.engys.util.ui.ResourcesUtil; import eu.engys.util.ui.UiUtil; import eu.engys.util.ui.ViewAction; -public class TerminalManager { +public class TerminalManager implements ChangeListener { - private static TerminalManager instance = null; private Map frames = new HashMap<>(); private Map monitors = new HashMap<>(); public static final String TERMINAL_MANAGER = "terminal.manager"; - private CollapseManager collapseManager; + private JSplitPane parent; private JTabbedPane tabbedPane; - public static TerminalManager getInstance() { - if (instance == null) { - instance = new TerminalManager(); - } - return instance; - } - - private TerminalManager() { + public TerminalManager() { this.tabbedPane = new JTabbedPane(); this.tabbedPane.setName(TERMINAL_MANAGER); - this.collapseManager = new CollapseManager(tabbedPane); + this.tabbedPane.addChangeListener(this); } - public void toggleVisibility() { - collapseManager.toggle(); + public void setParent(JSplitPane parent) { + this.parent = parent; + } + + public JComponent getComponent() { + return tabbedPane; } public void addTerminal(Component component, TerminalExecutorMonitor monitor) { @@ -188,7 +186,7 @@ public class TerminalManager { } } } - + public static JFrame createTerminalFrame(final Component component, final String title, boolean removeMinMax) { final JFrame frame = new JFrame(title) { /** @@ -205,11 +203,11 @@ public class TerminalManager { } }; - + if (removeMinMax) { removeMinMaxClose(frame); } - + frame.setIconImage(((ImageIcon) ResourcesUtil.getIcon(ApplicationInfo.getVendor().toLowerCase() + ".logo")).getImage()); frame.setAlwaysOnTop(false); frame.getContentPane().setLayout(new BorderLayout()); @@ -234,6 +232,42 @@ public class TerminalManager { } } + @Override + public void stateChanged(ChangeEvent e) { + ExecUtil.invokeLater(new Runnable() { + @Override + public void run() { + if (tabbedPane.getTabCount() == 0) { + collapse(); + } else if (tabbedPane.getTabCount() >= 1) { + expand(); + } + } + }); + } + + public void toggleVisibility() { + if (parent != null) { + if (UiUtil.isCollapsed(parent) && tabbedPane.getTabCount() > 0) { + expand(); + } else { + collapse(); + } + } + } + + public void collapse() { + if (parent != null) { + UiUtil.collapseSplitPane(parent); + } + } + + public void expand() { + if (parent != null) { + UiUtil.expandSplitPane(parent, tabbedPane, 0.7, 300); + } + } + class CloseAllAction extends ViewAction { public CloseAllAction() { @@ -250,7 +284,4 @@ public class TerminalManager { } } - public Component getComponent() { - return tabbedPane; - } } diff --git a/src/eu/engys/core/executor/TerminalOutputStream.java b/src/eu/engys/core/executor/TerminalOutputStream.java index 5c8433e..e1101b9 100644 --- a/src/eu/engys/core/executor/TerminalOutputStream.java +++ b/src/eu/engys/core/executor/TerminalOutputStream.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.executor; import java.io.IOException; @@ -61,8 +60,4 @@ public class TerminalOutputStream extends OutputStream { linesBuffer.setLength(0); return s; } - - public String peekLines() { - return linesBuffer.toString(); - } } diff --git a/src/eu/engys/core/executor/TerminalSupport.java b/src/eu/engys/core/executor/TerminalSupport.java index 445a956..29a1b25 100644 --- a/src/eu/engys/core/executor/TerminalSupport.java +++ b/src/eu/engys/core/executor/TerminalSupport.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.executor; @@ -32,27 +31,39 @@ import static eu.engys.core.OpenFOAMEnvironment.getTestEnvironment; import java.io.File; import java.io.IOException; +import eu.engys.core.DockerUtil; import eu.engys.core.project.Model; import eu.engys.util.PrefUtil; import eu.engys.util.Util; public class TerminalSupport { + public static final String SHELL = "$SHELL"; private static final String ACTION_NAME = "Open Terminal"; public static void openTerminal(Model model) { + File baseDir = model.getProject().getBaseDir(); if (Util.isWindows()) { - Executor.command("start", "cmd", "/K").inFolder(model.getProject().getBaseDir()).withOpenFoamEnv().env(getEnvironment(model)).description(ACTION_NAME).exec(); + if(PrefUtil.isUsingDocker()){ + Executor.command("start", "cmd", "/K", DockerUtil.terminal(baseDir)).inFolder(baseDir).description(ACTION_NAME).exec(); + } else { + Executor.command("start", "cmd", "/K").inFolder(baseDir).withOpenFoamEnv().env(getEnvironment(model)).description(ACTION_NAME).exec(); + } } else { - Executor.command(getTerminal() + "$SHELL").inFolder(model.getProject().getBaseDir()).withOpenFoamEnv().env(getEnvironment(model)).description(ACTION_NAME).exec(); + if(PrefUtil.isUsingDocker()){ + Executor.command(getTerminal(), DockerUtil.terminal(baseDir)).inFolder(baseDir).description(ACTION_NAME).exec(); + } else { + Executor.command(getTerminal(), SHELL).inFolder(baseDir).withOpenFoamEnv().env(getEnvironment(model)).description(ACTION_NAME).exec(); + } } } + public static void openTerminal(File baseDir) { if (Util.isWindows()) { Executor.command("start", "cmd", "/K").inFolder(baseDir).withOpenFoamEnv().env(getTestEnvironment()).description(ACTION_NAME).exec(); } else { - Executor.command(getTerminal() + "$SHELL").inFolder(baseDir).withOpenFoamEnv().env(getTestEnvironment()).description(ACTION_NAME).exec(); + Executor.command(getTerminal(), SHELL).inFolder(baseDir).withOpenFoamEnv().env(getTestEnvironment()).description(ACTION_NAME).exec(); } } @@ -60,16 +71,16 @@ public class TerminalSupport { String preferredTerminal = PrefUtil.getString(PrefUtil.HELYX_DEFAULT_TERMINAL); if (preferredTerminal.isEmpty()) { if (checkTerminal("gnome-terminal")) { - return "gnome-terminal --disable-factory --geometry 80x40 -e "; + return "gnome-terminal --disable-factory --geometry 80x40 -e"; } else if (checkTerminal("konsole")) { - return "konsole --geometry 80x40 -e "; + return "konsole --geometry 80x40 -e"; } else if (checkTerminal("xterm")) { - return "xterm -sb -font -*-fixed-medium-r-*-*-18-*-*-*-*-*-iso8859-* -geometry 80x40 -hold -e "; + return "xterm -sb -font -*-fixed-medium-r-*-*-18-*-*-*-*-*-iso8859-* -geometry 80x40 -hold -e"; } else { System.err.println("No terminal found"); } } else { - return preferredTerminal + " -e "; + return preferredTerminal + " -e"; } return ""; diff --git a/src/eu/engys/core/executor/TerminalTabComponent.java b/src/eu/engys/core/executor/TerminalTabComponent.java index af3ea61..80a7ee5 100644 --- a/src/eu/engys/core/executor/TerminalTabComponent.java +++ b/src/eu/engys/core/executor/TerminalTabComponent.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.executor; diff --git a/src/eu/engys/core/executor/actions/CloseMonitorAction.java b/src/eu/engys/core/executor/actions/CloseMonitorAction.java index 1f50e97..ae61798 100644 --- a/src/eu/engys/core/executor/actions/CloseMonitorAction.java +++ b/src/eu/engys/core/executor/actions/CloseMonitorAction.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.executor.actions; import java.awt.event.ActionEvent; @@ -36,18 +35,20 @@ import eu.engys.util.ui.ViewAction; public class CloseMonitorAction extends ViewAction { private JPanel panel; + private TerminalManager terminalManager; - public CloseMonitorAction(JPanel panel) { - this(panel, false); + public CloseMonitorAction(TerminalManager terminalManager, JPanel panel) { + this(terminalManager, panel, false); } - - public CloseMonitorAction(JPanel panel, boolean label) { - super(label ? "Close Current Monitor" : null, ResourcesUtil.getIcon("console.tab.close.icon"), "Close Current Monitor"); - this.panel = panel; + + public CloseMonitorAction(TerminalManager terminalManager, JPanel panel, boolean label) { + super(label ? "Close Current Monitor" : null, ResourcesUtil.getIcon("console.tab.close.icon"), "Close Current Monitor"); + this.terminalManager = terminalManager; + this.panel = panel; } @Override public void actionPerformed(ActionEvent e) { - TerminalManager.getInstance().close(panel, false); + terminalManager.close(panel, false); } } diff --git a/src/eu/engys/core/executor/actions/CopyMonitorToClipboardAction.java b/src/eu/engys/core/executor/actions/CopyMonitorToClipboardAction.java index b6ca06f..609629b 100644 --- a/src/eu/engys/core/executor/actions/CopyMonitorToClipboardAction.java +++ b/src/eu/engys/core/executor/actions/CopyMonitorToClipboardAction.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.executor.actions; import java.awt.Toolkit; diff --git a/src/eu/engys/core/executor/actions/MaximiseMonitorAction.java b/src/eu/engys/core/executor/actions/MaximiseMonitorAction.java index ed50ec0..9695345 100644 --- a/src/eu/engys/core/executor/actions/MaximiseMonitorAction.java +++ b/src/eu/engys/core/executor/actions/MaximiseMonitorAction.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.executor.actions; import java.awt.event.ActionEvent; @@ -36,9 +35,11 @@ import eu.engys.util.ui.ViewAction; public class MaximiseMonitorAction extends ViewAction { private JPanel panel; + private TerminalManager terminalManager; - public MaximiseMonitorAction(JPanel panel) { + public MaximiseMonitorAction(TerminalManager terminalManager, JPanel panel) { this(panel, false); + this.terminalManager = terminalManager; } public MaximiseMonitorAction(JPanel panel, boolean label) { @@ -51,9 +52,9 @@ public class MaximiseMonitorAction extends ViewAction { @Override public void actionPerformed(ActionEvent e) { if (isSelected()) { - TerminalManager.getInstance().toDialog(panel); + terminalManager.toDialog(panel); } else { - TerminalManager.getInstance().toTab(panel); + terminalManager.toTab(panel); } } -} +} \ No newline at end of file diff --git a/src/eu/engys/core/executor/actions/SaveLogFileAction.java b/src/eu/engys/core/executor/actions/SaveLogFileAction.java index e8ee606..bc08ee0 100644 --- a/src/eu/engys/core/executor/actions/SaveLogFileAction.java +++ b/src/eu/engys/core/executor/actions/SaveLogFileAction.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.executor.actions; import java.awt.event.ActionEvent; @@ -94,4 +93,4 @@ public class SaveLogFileAction extends ViewAction { e1.printStackTrace(); } } -} +} \ No newline at end of file diff --git a/src/eu/engys/core/executor/actions/ScrollLockAction.java b/src/eu/engys/core/executor/actions/ScrollLockAction.java index ab68c32..c5a1f55 100644 --- a/src/eu/engys/core/executor/actions/ScrollLockAction.java +++ b/src/eu/engys/core/executor/actions/ScrollLockAction.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.executor.actions; import java.awt.event.ActionEvent; diff --git a/src/eu/engys/core/executor/actions/ShowLogAction.java b/src/eu/engys/core/executor/actions/ShowLogAction.java index a291460..88a5f7c 100644 --- a/src/eu/engys/core/executor/actions/ShowLogAction.java +++ b/src/eu/engys/core/executor/actions/ShowLogAction.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.executor.actions; import java.awt.event.ActionEvent; diff --git a/src/eu/engys/core/executor/actions/StopCommandAction.java b/src/eu/engys/core/executor/actions/StopCommandAction.java index 4272fe5..4bc32d2 100644 --- a/src/eu/engys/core/executor/actions/StopCommandAction.java +++ b/src/eu/engys/core/executor/actions/StopCommandAction.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.executor.actions; import java.awt.event.ActionEvent; diff --git a/src/eu/engys/core/modules/AbstractChart.java b/src/eu/engys/core/modules/AbstractChart.java new file mode 100644 index 0000000..3256593 --- /dev/null +++ b/src/eu/engys/core/modules/AbstractChart.java @@ -0,0 +1,153 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.core.modules; + +import static org.jfree.chart.ChartPanel.DEFAULT_HEIGHT; +import static org.jfree.chart.ChartPanel.DEFAULT_MAXIMUM_DRAW_HEIGHT; +import static org.jfree.chart.ChartPanel.DEFAULT_MAXIMUM_DRAW_WIDTH; +import static org.jfree.chart.ChartPanel.DEFAULT_MINIMUM_DRAW_HEIGHT; +import static org.jfree.chart.ChartPanel.DEFAULT_MINIMUM_DRAW_WIDTH; +import static org.jfree.chart.ChartPanel.DEFAULT_WIDTH; + +import java.awt.Color; + +import javax.swing.JComponent; + +import org.jfree.chart.ChartPanel; +import org.jfree.chart.JFreeChart; +import org.jfree.chart.block.BlockBorder; +import org.jfree.chart.plot.CategoryPlot; +import org.jfree.chart.plot.XYPlot; +import org.jfree.chart.title.LegendTitle; +import org.jfree.data.category.CategoryDataset; +import org.jfree.data.xy.XYDataset; +import org.jfree.ui.RectangleEdge; + +import eu.engys.core.project.state.State; +import eu.engys.core.project.system.monitoringfunctionobjects.TimeBlocks; +import eu.engys.util.ui.ExecUtil; + +public abstract class AbstractChart { + + public static final int DATASET_INDEX = 0; + public static final int MOVING_AVERAGE_DATASET_INDEX = 1; + public static final int WEIGHTING_DATASET_INDEX = 2; + + private ChartPanel chartPanel; + + public AbstractChart() { + } + + public void layoutComponents() { + boolean useBuffer = true; + boolean showPropertiesMenu = true; + boolean showCopyMenu = true; + boolean showSaveMenu = false; + boolean showPrintMenu = true; + boolean showZoomMenu = true; + boolean showTooltipsMenu = true; + + JFreeChart chart = createChart(); + LegendTitle legend = chart.getLegend(); + if (legend != null) { + legend.setFrame(BlockBorder.NONE); + legend.setBackgroundPaint(null); + legend.setPosition(RectangleEdge.RIGHT); + legend.setVisible(false); + } + chart.setBackgroundPaint(new Color(0, 0, 0, 0)); + this.chartPanel = new ChartPanel(chart, DEFAULT_WIDTH, DEFAULT_HEIGHT, DEFAULT_MINIMUM_DRAW_WIDTH, DEFAULT_MINIMUM_DRAW_HEIGHT, DEFAULT_MAXIMUM_DRAW_WIDTH, DEFAULT_MAXIMUM_DRAW_HEIGHT, useBuffer, showPropertiesMenu, showCopyMenu, showSaveMenu, showPrintMenu, showZoomMenu, showTooltipsMenu); + this.chartPanel.setName(getClass().getCanonicalName()); + } + + public abstract JComponent getPanel(); + + protected abstract JFreeChart createChart(); + + public abstract void stop(); + + public void addToDataSet(final TimeBlocks list) { + synchronized (list) { + if (list.size() > 0) { + ExecUtil.invokeLater(new Runnable() { + @Override + public void run() { + notifySeries(false); + _addToDataSet(list); + notifySeries(true); + postAddToDataSet(); + } + }); + } + } + } + + public abstract void postAddToDataSet(); + + public void clear() { + ExecUtil.invokeLater(new Runnable() { + @Override + public void run() { + notifySeries(false); + _clearData(); + notifySeries(true); + chartPanel.restoreAutoDomainBounds(); + } + }); + } + + protected abstract void notifySeries(boolean notify); + + public abstract void _addToDataSet(TimeBlocks list); + + public abstract void _clearData(); + + public abstract void handleStateChanged(State state); + + public ChartPanel getChartPanel() { + return chartPanel; + } + + public JFreeChart getChart() { + return chartPanel.getChart(); + } + + public XYPlot getXYPlot() { + return chartPanel.getChart().getXYPlot(); + } + + public CategoryPlot getCategoryPlot() { + return chartPanel.getChart().getCategoryPlot(); + } + + public CategoryDataset getCategoryDataset(int index) { + return chartPanel.getChart().getCategoryPlot().getDataset(index); + } + + public XYDataset getXYDataset(int index) { + return chartPanel.getChart().getXYPlot().getDataset(index); + } + +} diff --git a/src/eu/engys/core/modules/ApplicationModule.java b/src/eu/engys/core/modules/ApplicationModule.java index 16d5ac6..de87d11 100644 --- a/src/eu/engys/core/modules/ApplicationModule.java +++ b/src/eu/engys/core/modules/ApplicationModule.java @@ -1,49 +1,59 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.modules; +import java.util.List; import java.util.Set; +import javax.swing.JTabbedPane; + import eu.engys.core.modules.boundaryconditions.BoundaryConditionsView; import eu.engys.core.modules.cellzones.CellZonesView; import eu.engys.core.modules.materials.MaterialsView; +import eu.engys.core.modules.residuals.ResidualsViewConfigurator; import eu.engys.core.modules.solutionmodelling.SolutionView; import eu.engys.core.modules.tree.TreeView; -import eu.engys.core.project.InvalidProjectException; import eu.engys.core.project.state.SolverFamily; import eu.engys.core.project.state.State; +import eu.engys.core.project.system.monitoringfunctionobjects.Parser; +import eu.engys.core.project.system.monitoringfunctionobjects.ParserView; import eu.engys.core.project.zero.fields.Field; import eu.engys.core.project.zero.fields.Fields; +import eu.engys.core.project.zero.patches.BoundaryConditions; public interface ApplicationModule { + void checkLicense(); + void checkIfCanOpenCase(); + TreeView getTreeView(); Set getCaseSetupPanels(); + Set getSolverPanels(); + SolutionView getSolutionView(); MaterialsView getMaterialsView(); @@ -53,16 +63,20 @@ public interface ApplicationModule { CellZonesView getCellZonesView(); FieldsInitialisationView getFieldsInitialisationView(); - - String getName(); - void loadState() throws InvalidProjectException; + String getName(); - void loadMaterials(); + void read(); + + void write(); + + void loadState(); void save(); + + void loadMaterials(); - void write(); + void saveMaterials(); void saveDefaultsToProject(); @@ -86,6 +100,18 @@ public interface ApplicationModule { void updateSolverFamilies(State state, Set families); - boolean checkLicense(); + ResidualsViewConfigurator createResidualsViewConfigurator(JTabbedPane pane); + + Parser createResidualsParser(); + + List createParsers(); + + List getParserViews(); + + void deleteUselessLogFiles(); + + Set getFieldsToBeMonitored(); + + void saveToBoundaryConditions(BoundaryConditions bc); } diff --git a/src/eu/engys/core/modules/ApplicationModuleAdapter.java b/src/eu/engys/core/modules/ApplicationModuleAdapter.java index 95d49f4..818300e 100644 --- a/src/eu/engys/core/modules/ApplicationModuleAdapter.java +++ b/src/eu/engys/core/modules/ApplicationModuleAdapter.java @@ -1,74 +1,55 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.modules; import java.util.Collections; +import java.util.List; import java.util.Set; +import javax.swing.JTabbedPane; + import eu.engys.core.modules.boundaryconditions.BoundaryConditionsView; import eu.engys.core.modules.cellzones.CellZonesView; import eu.engys.core.modules.materials.MaterialsView; +import eu.engys.core.modules.residuals.ResidualsViewConfigurator; import eu.engys.core.modules.tree.TreeView; import eu.engys.core.project.state.SolverFamily; import eu.engys.core.project.state.State; +import eu.engys.core.project.system.monitoringfunctionobjects.Parser; +import eu.engys.core.project.system.monitoringfunctionobjects.ParserView; import eu.engys.core.project.zero.fields.Field; +import eu.engys.core.project.zero.patches.BoundaryConditions; public abstract class ApplicationModuleAdapter implements ApplicationModule { + + @Override + public void checkLicense() { + } @Override - public boolean checkLicense() { - return true; - } - - @Override - public void loadMaterials() { - } - - @Override - public void saveDefaultsToProject() { - } - - @Override - public void saveDefaultsTurbulenceModelsToProject() { - } - - @Override - public void saveMaterialsToProject() { - } - -// @Override -// public void initialiseFields(Controller controller, ExecutorService service, Server server) { -// } - - @Override - public void updateSolver(State state) { - } - - @Override - public void updateSolverFamilies(State state, Set families) { + public void checkIfCanOpenCase() { } @Override @@ -76,6 +57,30 @@ public abstract class ApplicationModuleAdapter implements ApplicationModule { return null; } + @Override + public void deleteUselessLogFiles() { + } + + @Override + public Parser createResidualsParser() { + return null; + } + + @Override + public List createParsers() { + return Collections. emptyList(); + } + + @Override + public List getParserViews() { + return Collections. emptyList(); + } + + @Override + public ResidualsViewConfigurator createResidualsViewConfigurator(JTabbedPane pane) { + return null; + } + @Override public MaterialsView getMaterialsView() { return null; @@ -106,11 +111,57 @@ public abstract class ApplicationModuleAdapter implements ApplicationModule { return null; } + @Override + public void read() { + } + + @Override + public void write() { + } + + @Override + public void loadMaterials() { + } + + @Override + public void saveMaterials() { + } + + @Override + public void saveDefaultsToProject() { + } + + @Override + public void saveDefaultsTurbulenceModelsToProject() { + } + + @Override + public void saveMaterialsToProject() { + } + + @Override + public void updateSolver(State state) { + } + + @Override + public void updateSolverFamilies(State state, Set families) { + } + @Override public Set getCaseSetupPanels() { return Collections. emptySet(); } + @Override + public Set getSolverPanels() { + return Collections. emptySet(); + } + + @Override + public Set getFieldsToBeMonitored() { + return Collections. emptySet(); + } + @Override public boolean isFieldInitialisationVetoed(Field field) { return false; @@ -120,5 +171,9 @@ public abstract class ApplicationModuleAdapter implements ApplicationModule { public boolean isNonNewtonianViscosityModelVetoed() { return false; } + + @Override + public void saveToBoundaryConditions(BoundaryConditions bc) { + } } diff --git a/src/eu/engys/core/modules/CaseSetupReader.java b/src/eu/engys/core/modules/CaseSetupReader.java index 0299813..36bdf52 100644 --- a/src/eu/engys/core/modules/CaseSetupReader.java +++ b/src/eu/engys/core/modules/CaseSetupReader.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.modules; import eu.engys.core.dictionary.Dictionary; diff --git a/src/eu/engys/core/modules/CaseSetupWriter.java b/src/eu/engys/core/modules/CaseSetupWriter.java index 5adf001..d3bf98f 100644 --- a/src/eu/engys/core/modules/CaseSetupWriter.java +++ b/src/eu/engys/core/modules/CaseSetupWriter.java @@ -1,39 +1,41 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.modules; import eu.engys.core.dictionary.Dictionary; -import eu.engys.core.project.Model; +import eu.engys.core.project.materials.Materials; +import eu.engys.core.project.state.State; public interface CaseSetupWriter { - void addState(StringBuffer sb); + void addState(State state, StringBuffer sb); - void addToMaterials(Model model, Dictionary materialProperties); - void addToConstant(Dictionary constantFolder); - void addToSystem(Dictionary constantFolder); + void addToMaterials(Materials materials, Dictionary materialProperties); + + void addToConstant(State state, Dictionary constantFolder); + + void addToSystem(State state, Dictionary constantFolder); } diff --git a/src/eu/engys/core/modules/FieldsInitialisationView.java b/src/eu/engys/core/modules/FieldsInitialisationView.java index 5211ba9..0204363 100644 --- a/src/eu/engys/core/modules/FieldsInitialisationView.java +++ b/src/eu/engys/core/modules/FieldsInitialisationView.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.modules; diff --git a/src/eu/engys/core/modules/ModuleDefaults.java b/src/eu/engys/core/modules/ModuleDefaults.java index 40dbfae..e37409f 100644 --- a/src/eu/engys/core/modules/ModuleDefaults.java +++ b/src/eu/engys/core/modules/ModuleDefaults.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.modules; import eu.engys.core.dictionary.Dictionary; @@ -69,4 +68,4 @@ public class ModuleDefaults extends AbstractDefaultsProvider { public Dictionary getStates() { return stateData.found("states") ? stateData.subDict("states") : parent.getStates(); } -} +} \ No newline at end of file diff --git a/src/eu/engys/core/modules/ModulePanel.java b/src/eu/engys/core/modules/ModulePanel.java index 2e0e850..1f7cbca 100644 --- a/src/eu/engys/core/modules/ModulePanel.java +++ b/src/eu/engys/core/modules/ModulePanel.java @@ -1,40 +1,39 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.modules; import javax.swing.JComponent; - public interface ModulePanel { - String getTitle(); - String getKey(); + String getTitle(); - JComponent getPanel(); + String getKey(); - int getIndex(); + JComponent getPanel(); + + int getIndex(); } diff --git a/src/eu/engys/core/modules/ModulesUtil.java b/src/eu/engys/core/modules/ModulesUtil.java index c24148e..c93a72f 100644 --- a/src/eu/engys/core/modules/ModulesUtil.java +++ b/src/eu/engys/core/modules/ModulesUtil.java @@ -1,30 +1,30 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.modules; +import java.io.File; import java.io.InputStream; import java.util.ArrayList; import java.util.HashSet; @@ -46,13 +46,16 @@ import eu.engys.core.modules.cellzones.CellZonesView; import eu.engys.core.modules.materials.MaterialsView; import eu.engys.core.modules.tree.ModuleElementPanel; import eu.engys.core.modules.tree.TreeView; -import eu.engys.core.project.InvalidProjectException; +import eu.engys.core.project.materials.Material; import eu.engys.core.project.state.SolverFamily; import eu.engys.core.project.state.State; +import eu.engys.core.project.system.monitoringfunctionobjects.Parser; +import eu.engys.core.project.system.monitoringfunctionobjects.ParserView; import eu.engys.core.project.zero.cellzones.CellZoneType; import eu.engys.core.project.zero.cellzones.CellZones; import eu.engys.core.project.zero.fields.Field; import eu.engys.core.project.zero.fields.Fields; +import eu.engys.core.project.zero.patches.BoundaryConditions; import eu.engys.util.ui.builder.PanelBuilder; public class ModulesUtil { @@ -91,31 +94,54 @@ public class ModulesUtil { } } - public static Dictionary extractRelativeToStateSettings(String encodedPrimalState, Dictionary mDict) { - if (mDict.found("requirements")) { - Dictionary requirements = (Dictionary) mDict.remove("requirements"); - if (requirements.found("conditional")) { - if (requirements.subDict("conditional").found(encodedPrimalState)) { - Dictionary conditional = requirements.subDict("conditional").subDict(encodedPrimalState); - return conditional; - } - } - } - return null; - } - - public static void updateStateFromGUI(Set modules) { + public static void read(Set modules) { for (ApplicationModule module : modules) { - module.getSolutionView().updateStateFromGUI(); + module.read(); } } - public static void loadState(Set modules) throws InvalidProjectException { + public static void write(Set modules) { + for (ApplicationModule module : modules) { + module.write(); + } + } + + public static void loadState(Set modules) { for (ApplicationModule module : modules) { module.loadState(); } } + public static void checkIfCanOpenCase(Set modules) { + for (ApplicationModule module : modules) { + module.checkIfCanOpenCase(); + } + } + + public static void save(Set modules) { + for (ApplicationModule module : modules) { + module.save(); + } + } + + public static void loadMaterials(Set modules) { + for (ApplicationModule module : modules) { + module.loadMaterials(); + } + } + + public static void saveMaterials(Set modules) { + for (ApplicationModule module : modules) { + module.saveMaterials(); + } + } + + public static void updateStateFromGUI(Set modules, State state) { + for (ApplicationModule module : modules) { + module.getSolutionView().updateStateFromGUI(state); + } + } + public static void updateSolver(Set modules, State state) { for (ApplicationModule module : modules) { module.updateSolver(state); @@ -128,12 +154,6 @@ public class ModulesUtil { } } - public static void loadMaterials(Set modules) { - for (ApplicationModule module : modules) { - module.loadMaterials(); - } - } - public static void saveDefaultsToProject(Set modules) { for (ApplicationModule module : modules) { module.saveDefaultsToProject(); @@ -152,18 +172,6 @@ public class ModulesUtil { } } - public static void save(Set modules) { - for (ApplicationModule module : modules) { - module.save(); - } - } - -// public static void initaliseFields(Set modules, Controller controller, ExecutorService service, Server server) { -// for (ApplicationModule module : modules) { -// module.initialiseFields(controller, service, server); -// } -// } - public static Fields loadFieldsFromDefaults(Set modules, String region) { Fields fields = new Fields(); for (ApplicationModule module : modules) { @@ -182,6 +190,36 @@ public class ModulesUtil { } } + public static void updateMaterialFromDefaults(Set modules, Material material) { + for (ApplicationModule module : modules) { + MaterialsView materialsView = module.getMaterialsView(); + if (materialsView == null) { + continue; + } + materialsView.updateMaterialFromDefaults(material); + } + } + + public static void updateGUIFromMaterial(Set modules, Material material) { + for (ApplicationModule module : modules) { + MaterialsView materialsView = module.getMaterialsView(); + if (materialsView == null) { + continue; + } + materialsView.updateGUIFromMaterial(material); + } + } + + public static void updateMaterialFromGUI(Set modules, Material material) { + for (ApplicationModule module : modules) { + MaterialsView materialsView = module.getMaterialsView(); + if (materialsView == null) { + continue; + } + materialsView.updateMaterialFromGUI(material); + } + } + public static void configureFieldsInitialization(Set modules, List actions) { for (ApplicationModule module : modules) { FieldsInitialisationView fieldsView = module.getFieldsInitialisationView(); @@ -210,11 +248,53 @@ public class ModulesUtil { } } + public static Parser createResidualsParser(Set modules, File fileToParse) { + for (ApplicationModule module : modules) { + Parser parser = module.createResidualsParser(); + if (parser != null) { + return parser; + } + } + return null; + } + + public static List createParsers(Set modules) { + List parsers = new ArrayList<>(); + for (ApplicationModule module : modules) { + List moduleParsers = module.createParsers(); + parsers.addAll(moduleParsers); + } + return parsers; + } + + public static List createParserViews(Set modules) { + List parsers = new ArrayList<>(); + for (ApplicationModule module : modules) { + List moduleParsers = module.getParserViews(); + parsers.addAll(moduleParsers); + } + return parsers; + } + + public static void deleteUselessLogFiles(Set modules) { + for (ApplicationModule module : modules) { + module.deleteUselessLogFiles(); + } + } + + public static List getFieldsToBeMonitored(Set modules) { + List moduleFields = new ArrayList<>(); + for (ApplicationModule module : modules) { + moduleFields.addAll(module.getFieldsToBeMonitored()); + } + return moduleFields; + } + public static List getCellZoneTypes(Set modules) { List moduleCellZoneTypes = new ArrayList(); for (ApplicationModule module : modules) { CellZonesView cellZonesView = module.getCellZonesView(); - if (cellZonesView != null){ + if (cellZonesView != null) { moduleCellZoneTypes.addAll(cellZonesView.getCellZoneTypes()); } } @@ -263,13 +343,35 @@ public class ModulesUtil { return panels; } - public static void updateTree(Set modules, ModuleElementPanel viewElementPanel) { + public static Set getSolverPanels(Set modules) { + Set panels = new HashSet<>(); + for (ApplicationModule module : modules) { + panels.addAll(module.getSolverPanels()); + } + return panels; + } + + public static void updateCaseSetupTree(Set modules, ModuleElementPanel viewElementPanel) { for (ApplicationModule module : modules) { TreeView treeView = module.getTreeView(); if (treeView == null) continue; - treeView.updateTree(viewElementPanel); + treeView.updateCaseSetupTree(viewElementPanel); } } + public static void updateSolverTree(Set modules, ModuleElementPanel viewElementPanel) { + for (ApplicationModule module : modules) { + TreeView treeView = module.getTreeView(); + if (treeView == null) + continue; + treeView.updateSolverTree(viewElementPanel); + } + } + + public static void saveToBoundaryConditions(Set modules, BoundaryConditions bc) { + for (ApplicationModule module : modules) { + module.saveToBoundaryConditions(bc); + } + } } diff --git a/src/eu/engys/core/modules/boundaryconditions/BoundaryConditionsView.java b/src/eu/engys/core/modules/boundaryconditions/BoundaryConditionsView.java index 4233824..13249ef 100644 --- a/src/eu/engys/core/modules/boundaryconditions/BoundaryConditionsView.java +++ b/src/eu/engys/core/modules/boundaryconditions/BoundaryConditionsView.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.modules.boundaryconditions; public interface BoundaryConditionsView { diff --git a/src/eu/engys/core/modules/boundaryconditions/BoundaryTypePanel.java b/src/eu/engys/core/modules/boundaryconditions/BoundaryTypePanel.java index cb6ea78..5bcd133 100644 --- a/src/eu/engys/core/modules/boundaryconditions/BoundaryTypePanel.java +++ b/src/eu/engys/core/modules/boundaryconditions/BoundaryTypePanel.java @@ -1,29 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.modules.boundaryconditions; import java.awt.Component; @@ -33,35 +31,36 @@ import eu.engys.core.project.zero.patches.Patch; public interface BoundaryTypePanel { - public static final String MOMENTUM = "Momentum"; - - public static final String TURBULENCE = "Turbulence"; - public static final String THERMAL = "Thermal"; - public static final String PASSIVE_SCALARS = "Passive Scalars"; - public static final String PHASE_FRACTION = "Phase Fraction"; - void layoutPanel(); - + void loadFromPatches(Patch... patches); void saveToPatch(Patch patch); BoundaryType getType(); + Component getPanel(); ParametersPanel getMomentumPanel(); + ParametersPanel getTurbulencePanel(); + ParametersPanel getThermalPanel(); + ParametersPanel getPanel(String name); - + void stateChanged(); + void materialsChanged(); void addMomentumPanel(ParametersPanel momentumPanel); + void addTurbulencePanel(ParametersPanel momentumPanel); + void addThermalPanel(ParametersPanel momentumPanel); void addPanel(String name, ParametersPanel pPanel); + void addPanel(String name, ParametersPanel pPanel, int index); void resetToDefault(); diff --git a/src/eu/engys/core/modules/boundaryconditions/IBoundaryConditionsPanel.java b/src/eu/engys/core/modules/boundaryconditions/IBoundaryConditionsPanel.java index 81978c3..aec6c8f 100644 --- a/src/eu/engys/core/modules/boundaryconditions/IBoundaryConditionsPanel.java +++ b/src/eu/engys/core/modules/boundaryconditions/IBoundaryConditionsPanel.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.modules.boundaryconditions; diff --git a/src/eu/engys/core/modules/boundaryconditions/ParametersPanel.java b/src/eu/engys/core/modules/boundaryconditions/ParametersPanel.java index bebd08b..5670611 100644 --- a/src/eu/engys/core/modules/boundaryconditions/ParametersPanel.java +++ b/src/eu/engys/core/modules/boundaryconditions/ParametersPanel.java @@ -1,29 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.modules.boundaryconditions; import javax.swing.JPanel; @@ -35,17 +33,26 @@ import eu.engys.core.project.zero.patches.BoundaryConditions; public interface ParametersPanel { public String getTitle(); + public JPanel getComponent(); - public void tabChanged(Model model); + public void stateChanged(Model model); + public void materialsChanged(Model model); + public DictionaryModel getDictionaryModel(); - - public void loadFromBoundaryConditions(String patchName, BoundaryConditions bc); - public void saveToBoundaryConditions(String patchName, BoundaryConditions bc); - - public void setMultipleEditing(boolean multipleSelection); - public boolean canEdit(); - public boolean isEnabled(Model model); - public void resetToDefault(Model model); + + public void loadFromBoundaryConditions(BoundaryConditions bc); + + public void saveToBoundaryConditions(BoundaryConditions bc); + + public void setMultipleEditing(boolean multipleSelection); + + public void setPatchName(String patchName); + + public boolean canEdit(); + + public boolean isEnabled(Model model); + + public void resetToDefault(Model model); } diff --git a/src/eu/engys/core/modules/cellzones/CellZonePanel.java b/src/eu/engys/core/modules/cellzones/CellZonePanel.java index 138231b..5116b16 100644 --- a/src/eu/engys/core/modules/cellzones/CellZonePanel.java +++ b/src/eu/engys/core/modules/cellzones/CellZonePanel.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.modules.cellzones; @@ -43,6 +42,7 @@ public interface CellZonePanel { public static final String ORIGIN_LABEL = "Origin"; public static final String AXIS_LABEL = "Axis"; public static final String OMEGA_RAD_S_LABEL = "Omega [rad/s]"; + public static final String NON_ROTATING_PATCHES_INSIDE_MRF_ZONE_LABEL = "Non-rotating patches inside MRF zone"; /* * Porous @@ -68,9 +68,9 @@ public interface CellZonePanel { void stateChanged(); - void loadFromDictionary(Dictionary cellZoneDictionary); + void loadFromDictionary(String cellZoneName, Dictionary cellZoneDictionary); - Dictionary saveToDictionary(); + Dictionary saveToDictionary(String czName); // Dictionary getDefault(); diff --git a/src/eu/engys/core/modules/cellzones/CellZonesView.java b/src/eu/engys/core/modules/cellzones/CellZonesView.java index 2669ecb..aace418 100644 --- a/src/eu/engys/core/modules/cellzones/CellZonesView.java +++ b/src/eu/engys/core/modules/cellzones/CellZonesView.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.modules.cellzones; import java.util.List; diff --git a/src/eu/engys/core/modules/materials/MaterialsBuilder.java b/src/eu/engys/core/modules/materials/MaterialsBuilder.java index cd710c0..7a4d9ae 100644 --- a/src/eu/engys/core/modules/materials/MaterialsBuilder.java +++ b/src/eu/engys/core/modules/materials/MaterialsBuilder.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.modules.materials; @@ -31,9 +30,9 @@ import eu.engys.core.project.Model; public interface MaterialsBuilder { - Dictionary saveCompressible(Model model, Dictionary materialGUIDict); +// Dictionary saveCompressible(Model model, Dictionary materialGUIDict); - Dictionary saveIncompressible(Model model, Dictionary materialDict); +// Dictionary saveIncompressible(Model model, Dictionary materialDict); Dictionary toGUIFormat(Dictionary defaultMaterialDict); diff --git a/src/eu/engys/core/modules/materials/MaterialsDatabase.java b/src/eu/engys/core/modules/materials/MaterialsDatabase.java index 1e9dac8..105545d 100644 --- a/src/eu/engys/core/modules/materials/MaterialsDatabase.java +++ b/src/eu/engys/core/modules/materials/MaterialsDatabase.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.modules.materials; import java.util.Collection; @@ -34,22 +33,25 @@ import javax.inject.Inject; import eu.engys.core.dictionary.Dictionary; import eu.engys.core.project.defaults.Defaults; +import eu.engys.core.project.materials.MaterialsReader; +import eu.engys.core.project.materials.compressible.CompressibleMaterial; +import eu.engys.core.project.materials.incompressible.IncompressibleMaterial; public class MaterialsDatabase { - private Map compressibleMaterialsMap = new HashMap<>(); - private Map incompressibleMaterialsMap = new HashMap<>(); + private Map compressibleMaterialsMap = new HashMap<>(); + private Map incompressibleMaterialsMap = new HashMap<>(); public static final String AIR = "air"; public static final String MERCURY = "mercury"; public static final String WATER = "water"; public static final String OIL = "oil"; @Inject - public MaterialsDatabase(Defaults defaults) { - load(defaults); + public MaterialsDatabase(Defaults defaults, MaterialsReader reader) { + load(defaults, reader); } - private void load(Defaults defaults) { + private void load(Defaults defaults, MaterialsReader reader) { compressibleMaterialsMap.clear(); incompressibleMaterialsMap.clear(); @@ -57,37 +59,39 @@ public class MaterialsDatabase { Dictionary incompressibleMaterials = defaults.getIncompressibleMaterials(); for (Dictionary matDict : compressibleMaterials.getDictionaries()) { - matDict.add("materialName", matDict.getName()); - compressibleMaterialsMap.put(matDict.getName(), matDict); + String name = matDict.getName(); + matDict.add("materialName", name); + compressibleMaterialsMap.put(name, reader.readCompressibleMaterial(matDict)); } for (Dictionary matDict : incompressibleMaterials.getDictionaries()) { - matDict.add("materialName", matDict.getName()); - incompressibleMaterialsMap.put(matDict.getName(), matDict); + String name = matDict.getName(); + matDict.add("materialName", name); + incompressibleMaterialsMap.put(name, reader.readIncompressibleMaterial(matDict)); } } - public Map getCompressibleMaterialsMap() { + public Map getCompressibleMaterialsMap() { return compressibleMaterialsMap; } - public Map getIncompressibleMaterialsMap() { + public Map getIncompressibleMaterialsMap() { return incompressibleMaterialsMap; } - public Collection getCompressibleMaterials() { + public Collection getCompressibleMaterials() { return Collections.unmodifiableCollection(compressibleMaterialsMap.values()); } - public Collection getIncompressibleMaterials() { + public Collection getIncompressibleMaterials() { return Collections.unmodifiableCollection(incompressibleMaterialsMap.values()); } - public Dictionary getCompressibleMaterial(String materialName) { - return new Dictionary(compressibleMaterialsMap.get(materialName)); + public CompressibleMaterial getCompressibleMaterial(String materialName) { + return new CompressibleMaterial(compressibleMaterialsMap.get(materialName)); } - public Dictionary getIncompressibleMaterial(String materialName) { - return new Dictionary(incompressibleMaterialsMap.get(materialName)); + public IncompressibleMaterial getIncompressibleMaterial(String materialName) { + return new IncompressibleMaterial (incompressibleMaterialsMap.get(materialName)); } } diff --git a/src/eu/engys/core/modules/materials/MaterialsView.java b/src/eu/engys/core/modules/materials/MaterialsView.java index ac7a191..db1cfa8 100644 --- a/src/eu/engys/core/modules/materials/MaterialsView.java +++ b/src/eu/engys/core/modules/materials/MaterialsView.java @@ -1,29 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.modules.materials; import eu.engys.core.project.materials.Material; @@ -31,12 +29,12 @@ import eu.engys.util.ui.builder.PanelBuilder; public interface MaterialsView { - void updateGUIFromModel(Material material); - - void updateModelFromGUI(Material material); - void configure(PanelBuilder builder); - void updateDefaultMaterial(Material material); + void updateMaterialFromDefaults(Material material); + + void updateGUIFromMaterial(Material material); + + void updateMaterialFromGUI(Material material); } diff --git a/src/eu/engys/core/modules/residuals/ResidualsViewConfigurator.java b/src/eu/engys/core/modules/residuals/ResidualsViewConfigurator.java new file mode 100644 index 0000000..e7d2950 --- /dev/null +++ b/src/eu/engys/core/modules/residuals/ResidualsViewConfigurator.java @@ -0,0 +1,55 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.core.modules.residuals; + +import java.util.List; + +import eu.engys.core.modules.AbstractChart; +import eu.engys.core.project.state.State; +import eu.engys.core.project.system.monitoringfunctionobjects.Parser; +import eu.engys.core.project.system.monitoringfunctionobjects.TimeBlocks; +import eu.engys.core.report.Exporter; + +public interface ResidualsViewConfigurator { + + String getKey(); + + boolean isActive(); + + List getReportParsersList(); + + void clearData(); + + void updateParsing(List newTimeBlocks); + + void reloadPanel(); + + Exporter getExporter(); + + void handleStateChanged(State state); + + AbstractChart getSelectedChart(); + +} diff --git a/src/eu/engys/core/modules/residuals/ResidualsViewManager.java b/src/eu/engys/core/modules/residuals/ResidualsViewManager.java new file mode 100644 index 0000000..1dd4e40 --- /dev/null +++ b/src/eu/engys/core/modules/residuals/ResidualsViewManager.java @@ -0,0 +1,60 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.core.modules.residuals; + +import java.util.Set; + +import javax.swing.JTabbedPane; + +import eu.engys.core.modules.ApplicationModule; +import eu.engys.core.project.Model; + +public class ResidualsViewManager { + + private ResidualsViewConfigurator simpleResidualsConfigurator; + private ResidualsViewConfigurator activeConfiguration; + private JTabbedPane tabbedPane; + + public ResidualsViewManager(Model model, JTabbedPane tabbedPane, ResidualsViewConfigurator simpleResidualsConfigurator) { + this.tabbedPane = tabbedPane; + this.simpleResidualsConfigurator = simpleResidualsConfigurator; + } + + public void updateConfiguration(Set modules) { + for (ApplicationModule m : modules) { + ResidualsViewConfigurator rvc = m.createResidualsViewConfigurator(tabbedPane); + if (rvc != null) { + this.activeConfiguration = rvc; + return; + } + } + this.activeConfiguration = simpleResidualsConfigurator; + } + + public ResidualsViewConfigurator getActiveConfigurator() { + return activeConfiguration; + } + +} diff --git a/src/eu/engys/core/modules/solutionmodelling/AbstractSolutionView.java b/src/eu/engys/core/modules/solutionmodelling/AbstractSolutionView.java index d84f361..86fd866 100644 --- a/src/eu/engys/core/modules/solutionmodelling/AbstractSolutionView.java +++ b/src/eu/engys/core/modules/solutionmodelling/AbstractSolutionView.java @@ -1,30 +1,32 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.modules.solutionmodelling; +import java.awt.event.ActionListener; + +import eu.engys.core.project.state.AdjointState; import eu.engys.core.project.state.MultiphaseModel; import eu.engys.core.project.state.SolutionState; import eu.engys.core.project.state.State; @@ -35,23 +37,7 @@ import eu.engys.util.ui.builder.PanelBuilder; public class AbstractSolutionView implements SolutionView { @Override - public void buildSolution(ChooserPanel solutionPanel) { - } - - @Override - public void buildMultiphase(MultiphaseBuilder builder) { - } - - @Override - public void buildScalar(SolutionModellingPanel solutionPanel) { - } - - @Override - public void buildDynamic(PanelBuilder builder) { - } - - @Override - public void buildThermal(PanelBuilder builder) { + public void handleLicenseChanged(SolutionState ss) { } @Override @@ -60,27 +46,108 @@ public class AbstractSolutionView implements SolutionView { fixSolutionState(ss); fixMultiphase(state.getMultiphaseModel()); fixThermal(ss, new ThermalState(state)); + fixAdjoint(new AdjointState(state)); } @Override - public void updateStateFromGUI() { + public void updateStateFromGUI(State state) { } @Override - public boolean hasChanged() { + public boolean hasChanged(State state) { return false; } + /* + * Solution + */ + + @Override + public void buildSolution(ChooserPanel solutionPanel) { + } + @Override public void fixSolutionState(SolutionState ss) { } + /* + * Multiphase + */ + @Override + public void buildMultiphase(MultiphaseBuilder builder) { + } + @Override public void fixMultiphase(MultiphaseModel mm) { } + /* + * Thermal + */ + + @Override + public void buildThermal(PanelBuilder builder) { + } + @Override public void fixThermal(SolutionState ss, ThermalState ts) { } + @Override + public void setThermalListener(ActionListener listener) { + } + + @Override + public void addThermalListener() { + } + + @Override + public void removeThermalListener() { + } + + @Override + public void updateThermalState(ThermalState ts) { + } + + /* + * Dynamic + */ + @Override + public void buildDynamic(PanelBuilder builder) { + } + + /* + * Adjoint + */ + @Override + public void buildAdjoint(PanelBuilder builder) { + } + + @Override + public void fixAdjoint(AdjointState state) { + } + + @Override + public void setAdjointListener(ActionListener listener) { + } + + @Override + public void addAdjointListener() { + } + + @Override + public void removeAdjointListener() { + } + + @Override + public void updateAdjointState(AdjointState as) { + } + + /* + * Scalar + */ + @Override + public void buildScalar(SolutionModellingPanel solutionPanel) { + } + } diff --git a/src/eu/engys/core/modules/solutionmodelling/MultiphaseBuilder.java b/src/eu/engys/core/modules/solutionmodelling/MultiphaseBuilder.java index de060de..5fc9362 100644 --- a/src/eu/engys/core/modules/solutionmodelling/MultiphaseBuilder.java +++ b/src/eu/engys/core/modules/solutionmodelling/MultiphaseBuilder.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.modules.solutionmodelling; import eu.engys.core.project.state.MultiphaseModel; diff --git a/src/eu/engys/core/modules/solutionmodelling/SolutionModellingPanel.java b/src/eu/engys/core/modules/solutionmodelling/SolutionModellingPanel.java index d598907..b87730c 100644 --- a/src/eu/engys/core/modules/solutionmodelling/SolutionModellingPanel.java +++ b/src/eu/engys/core/modules/solutionmodelling/SolutionModellingPanel.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.modules.solutionmodelling; @@ -31,7 +30,7 @@ import eu.engys.util.ui.builder.PanelBuilder; public interface SolutionModellingPanel { - PanelBuilder getDynamicBuilder(); + PanelBuilder getAdjointBuilder(); MultiphaseBuilder getMultiphasePanel(); diff --git a/src/eu/engys/core/modules/solutionmodelling/SolutionView.java b/src/eu/engys/core/modules/solutionmodelling/SolutionView.java index 2aac1d4..187b71e 100644 --- a/src/eu/engys/core/modules/solutionmodelling/SolutionView.java +++ b/src/eu/engys/core/modules/solutionmodelling/SolutionView.java @@ -1,30 +1,32 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.modules.solutionmodelling; +import java.awt.event.ActionListener; + +import eu.engys.core.project.state.AdjointState; import eu.engys.core.project.state.MultiphaseModel; import eu.engys.core.project.state.SolutionState; import eu.engys.core.project.state.State; @@ -33,27 +35,69 @@ import eu.engys.util.ui.ChooserPanel; import eu.engys.util.ui.builder.PanelBuilder; public interface SolutionView { - - void buildSolution(ChooserPanel solutionPanel); - - void buildThermal(PanelBuilder builder); - - void buildMultiphase(MultiphaseBuilder builder); - - void buildDynamic(PanelBuilder builder); - - void buildScalar(SolutionModellingPanel solutionPanel); + + void handleLicenseChanged(SolutionState ss); void updateGUIFromState(State state); - void updateStateFromGUI(); + void updateStateFromGUI(State state); - boolean hasChanged(); + boolean hasChanged(State state); + + + /* + * Solution + */ + void buildSolution(ChooserPanel solutionPanel); void fixSolutionState(SolutionState ss); - + + /* + * Multiphase + */ + void buildMultiphase(MultiphaseBuilder builder); + void fixMultiphase(MultiphaseModel mm); + + /* + * Thermal + */ + void buildThermal(PanelBuilder builder); void fixThermal(SolutionState ss, ThermalState ts); + void setThermalListener(ActionListener listener); + + void addThermalListener(); + + void removeThermalListener(); + + void updateThermalState(ThermalState ts); + + /* + * Dynamic + */ + void buildDynamic(PanelBuilder builder); + + /* + * Adjoint + */ + void buildAdjoint(PanelBuilder builder); + + void fixAdjoint(AdjointState as); + + void setAdjointListener(ActionListener listener); + + void addAdjointListener(); + + void removeAdjointListener(); + + void updateAdjointState(AdjointState as); + + /* + * Scalar + */ + void buildScalar(SolutionModellingPanel solutionPanel); + + } diff --git a/src/eu/engys/core/modules/tree/AbstractTreeViewAdapter.java b/src/eu/engys/core/modules/tree/AbstractTreeViewAdapter.java new file mode 100644 index 0000000..41a796b --- /dev/null +++ b/src/eu/engys/core/modules/tree/AbstractTreeViewAdapter.java @@ -0,0 +1,37 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.core.modules.tree; + +public abstract class AbstractTreeViewAdapter implements TreeView { + + @Override + public void updateCaseSetupTree(ModuleElementPanel viewElementPanel) { + } + + @Override + public void updateSolverTree(ModuleElementPanel viewElementPanel) { + } + +} diff --git a/src/eu/engys/core/modules/tree/ModuleElementPanel.java b/src/eu/engys/core/modules/tree/ModuleElementPanel.java index de1c024..8bec496 100644 --- a/src/eu/engys/core/modules/tree/ModuleElementPanel.java +++ b/src/eu/engys/core/modules/tree/ModuleElementPanel.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.modules.tree; import eu.engys.core.modules.ModulePanel; @@ -30,6 +29,7 @@ import eu.engys.core.modules.ModulePanel; public interface ModuleElementPanel { void addPanel(ModulePanel phasesPanel); + void removePanel(ModulePanel phasesPanel); } diff --git a/src/eu/engys/core/modules/tree/TreeView.java b/src/eu/engys/core/modules/tree/TreeView.java index fdb848a..60a30be 100644 --- a/src/eu/engys/core/modules/tree/TreeView.java +++ b/src/eu/engys/core/modules/tree/TreeView.java @@ -1,32 +1,33 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.modules.tree; public interface TreeView { - void updateTree(ModuleElementPanel viewElementPanel); + void updateCaseSetupTree(ModuleElementPanel viewElementPanel); + + void updateSolverTree(ModuleElementPanel viewElementPanel); } diff --git a/src/eu/engys/core/parameters/Parameter.java b/src/eu/engys/core/parameters/Parameter.java index 8c34f6d..a3de77e 100644 --- a/src/eu/engys/core/parameters/Parameter.java +++ b/src/eu/engys/core/parameters/Parameter.java @@ -1,38 +1,44 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.parameters; import java.io.Serializable; -import eu.engys.util.ui.builder.PanelBuilder; +import eu.engys.core.dictionary.Dictionary; public interface Parameter extends Serializable { - public interface ParameterKey extends Serializable { - void generateKey(); + public interface ParameterKeyFactory { + ParameterKey generateKey(); + } + + public interface ParameterKey extends Serializable, ParameterKeyFactory { + boolean isGenerated(); + String getKeyString(); + Dictionary toDictionary(); + void fromDictionary(Dictionary d); } public interface ParameterKeyArgument extends Serializable { @@ -44,12 +50,13 @@ public interface Parameter extends Serializable { void setName(String name); String getName(); - void populate(PanelBuilder builder); - Number getValue(int component); void setValue(Number value, int component); Parameter cloneParameter(); + + Dictionary toDictionary(); + void fromDictionary(Dictionary d); } diff --git a/src/eu/engys/core/parameters/Parameters.java b/src/eu/engys/core/parameters/Parameters.java index 55a0228..f21759e 100644 --- a/src/eu/engys/core/parameters/Parameters.java +++ b/src/eu/engys/core/parameters/Parameters.java @@ -1,41 +1,67 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.parameters; +import java.io.BufferedInputStream; +import java.io.BufferedOutputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.ObjectInput; +import java.io.ObjectInputStream; +import java.io.ObjectOutput; +import java.io.ObjectOutputStream; +import java.io.OutputStream; import java.io.Serializable; -import java.util.Collection; -import java.util.HashMap; +import java.util.Iterator; +import java.util.LinkedHashMap; +import java.util.List; import java.util.Map; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import eu.engys.core.dictionary.Dictionary; +import eu.engys.core.dictionary.DictionaryUtils; import eu.engys.core.parameters.Parameter.ParameterKey; -import eu.engys.util.ui.builder.PanelBuilder; +import eu.engys.util.progress.ProgressMonitor; -public class Parameters implements Serializable { +public class Parameters implements Serializable, Iterable { - private Map delegate = new HashMap<>(); + + public static final String PARAMETERS = "parameters"; + public static final String BIN = ".bin"; + public static final String DICT = "Dict"; + + private static final Logger logger = LoggerFactory.getLogger(Parameters.class); + + private static final long serialVersionUID = 2397988172238381687L; + + private Map delegate = new LinkedHashMap<>(); public Parameters(Parameters parameters) { for (ParameterKey key : parameters.delegate.keySet()) { @@ -51,8 +77,8 @@ public class Parameters implements Serializable { delegate.put(p.getKey(), p); } - public Parameter get(ParameterKey key) { - return delegate.get(key); + public void remove(Parameter p) { + delegate.remove(p.getKey()); } public int getSize() { @@ -63,20 +89,26 @@ public class Parameters implements Serializable { delegate.clear(); } - public void populate(PanelBuilder builder) { - for (ParameterKey key : delegate.keySet()) { - Parameter p = delegate.get(key); - p.populate(builder); - } + @Override + public Iterator iterator() { + return delegate.values().iterator(); } - public Collection values() { - return delegate.values(); + public Parameter[] toArray() { + return delegate.values().toArray(new Parameter[0]); + } + + public boolean contains(ParameterKey key) { + return delegate.containsKey(key); + } + + public Parameter get(ParameterKey key) { + return delegate.get(key); } public Parameter get(String keyString) { for (ParameterKey key : delegate.keySet()) { - if (key.toString().equals(keyString)) { + if (key.getKeyString().equals(keyString)) { return delegate.get(key); } } @@ -85,7 +117,7 @@ public class Parameters implements Serializable { public void print() { for (ParameterKey key : delegate.keySet()) { - System.out.println("[print] " + key.getClass().getSimpleName()); + System.out.println("[print] " + key.getClass().getSimpleName() + ", " + (key.isGenerated()?"GEN":"NOTGEN") + ", " + (key.isGenerated()? key.getKeyString() : "nokey")); } } @@ -93,4 +125,73 @@ public class Parameters implements Serializable { return delegate; } + public static Parameters read(File parent) { + return readBinary(parent); + } + + static Parameters readBinary(File parent) { + // using java.io.Serializable + File binFile = new File(parent, PARAMETERS + BIN); + if (binFile.exists()) { + try (InputStream is = new FileInputStream(binFile); InputStream buffer = new BufferedInputStream(is); ObjectInput input = new ObjectInputStream(buffer);) { + return (Parameters) input.readObject(); + } catch (ClassNotFoundException ex) { + logger.error("Cannot perform input. Class not found.", ex); + } catch (IOException ex) { + logger.error("Cannot perform input.", ex); + } + } + + return new Parameters(); + } + + static Parameters readDictionary(File parent) { + Parameters parameters = new Parameters(); + File dictFile = new File(parent, PARAMETERS + DICT); + if (dictFile.exists()) { + Dictionary dictionary = DictionaryUtils.readDictionary(dictFile, (ProgressMonitor)null); + List dictionaries = dictionary.subDict(PARAMETERS).getDictionaries(); + for (Dictionary d : dictionaries) { + System.out.println("Parameters.readDictionary() " + d.getName()); + String klass = d.lookup("class"); + try { + Parameter parameter = (Parameter) Class.forName(klass).newInstance(); + parameter.fromDictionary(d); + parameters.add(parameter); + } catch (Exception e) { + e.printStackTrace(); + } + } + } + return parameters; + } + + public static void write(File parent, Parameters parameters) { + writeBinary(parent, parameters); + writeDictionary(parent, parameters); + } + + static void writeDictionary(File parent, Parameters parameters) { + //dictionary + File dictFile = new File(parent, PARAMETERS + DICT); + Dictionary dictionary = new Dictionary(PARAMETERS); + Map map = parameters.toMap(); + for (ParameterKey key : map.keySet()) { + Parameter p = map.get(key); + dictionary.add(p.toDictionary()); + } + +// System.out.println("ParametersManager.writeDictionary() " + dictionary); + DictionaryUtils.writeDictionaryFile(dictFile, dictionary); + } + + public static void writeBinary(File parent, Parameters parameters) { + // using java.io.Serializable + File binFile = new File(parent, PARAMETERS + BIN); + try (OutputStream os = new FileOutputStream(binFile); OutputStream buffer = new BufferedOutputStream(os); ObjectOutput output = new ObjectOutputStream(buffer);) { + output.writeObject(parameters); + } catch (IOException ex) { + logger.error("Cannot perform output.", ex); + } + } } diff --git a/src/eu/engys/core/presentation/Action.java b/src/eu/engys/core/presentation/Action.java index 90a937f..378d391 100644 --- a/src/eu/engys/core/presentation/Action.java +++ b/src/eu/engys/core/presentation/Action.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.presentation; diff --git a/src/eu/engys/core/presentation/ActionContainer.java b/src/eu/engys/core/presentation/ActionContainer.java index 7bb2052..b93edb9 100644 --- a/src/eu/engys/core/presentation/ActionContainer.java +++ b/src/eu/engys/core/presentation/ActionContainer.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.presentation; public interface ActionContainer { diff --git a/src/eu/engys/core/presentation/ActionManager.java b/src/eu/engys/core/presentation/ActionManager.java index d95fb93..98b3ba3 100644 --- a/src/eu/engys/core/presentation/ActionManager.java +++ b/src/eu/engys/core/presentation/ActionManager.java @@ -1,33 +1,33 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.presentation; import java.awt.event.ActionEvent; import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.List; import javax.swing.ActionMap; import javax.swing.Icon; @@ -42,92 +42,107 @@ public class ActionManager { private static ActionManager instance; private ActionMap map = new ActionMap(); + private List bannedKeys = new ArrayList<>(); + public static ActionManager getInstance() { if (instance == null) instance = new ActionManager(); return instance; } - public void parseActions(final ActionContainer o) { - Class klass = o.getClass(); - - for (final Method m : klass.getMethods()) { - Action action = m.getAnnotation(Action.class); - if (action != null) { - String key = action.key(); - final boolean checkEnv = action.checkEnv(); - final boolean checkLic = action.checkLicense(); - -// System.out.println("ActionManager.parseActions() FOUND: "+key); - - String label = ResourcesUtil.getString(key+".label"); - String tooltip = ResourcesUtil.getString(key+".tooltip"); - Icon icon = ResourcesUtil.getIcon(key+".icon"); - - map.put(key, new ViewAction(label, icon, tooltip) { - @Override - public void actionPerformed(ActionEvent e) { - try { - if (checkLic) { - if (o.isDemo()) { - UiUtil.showDemoMessage(); - return; - } - } - if (checkEnv) { - if (!OpenFOAMEnvironment.isEnvironementLoaded()) { - UiUtil.showCoreEnvironmentNotLoadedWarning(); - return; - } - } - - m.invoke(o); - - } catch (Exception ex) { - ex.printStackTrace(); - } - } - }); - } - ActionToggle actionToggle = m.getAnnotation(ActionToggle.class); - if (actionToggle != null) { - Class[] parameterTypes = m.getParameterTypes(); - if (parameterTypes.length != 1 || (parameterTypes.length == 1 && !parameterTypes[0].equals(boolean.class)) ) { - throw new RuntimeException("'ActionToggle' annotation: the method must have 1 boolean parameter"); - } - String key = actionToggle.key(); - String normal = actionToggle.normal(); - String selected = actionToggle.selected(); -// System.out.println("ActionManager.pa1rseActions() FOUND: "+key); - - String labelNormal = ResourcesUtil.getString(key+"."+normal+".label"); - String tooltipNormal = ResourcesUtil.getString(key+"."+normal+".tooltip"); - Icon iconNormal = ResourcesUtil.getIcon(key+"."+normal+".icon"); + public void parseActions(final ActionContainer o) { + Class klass = o.getClass(); + for (final Method m : klass.getMethods()) { + Action action = m.getAnnotation(Action.class); + if (action != null) { + parseActions(o, m, action); + } + ActionToggle actionToggle = m.getAnnotation(ActionToggle.class); + if (actionToggle != null) { + parseToggleActions(o, m, actionToggle); + } + } + } - String labelSelected = ResourcesUtil.getString(key+"."+selected+".label"); - final String tooltipSelected = ResourcesUtil.getString(key+"."+selected+".tooltip"); - final Icon iconSelected = ResourcesUtil.getIcon(key+"."+selected+".icon"); + protected void parseActions(final ActionContainer o, final Method m, Action action) { + String key = action.key(); + if (bannedKeys.contains(key)) + return; - map.put(key, new ViewAction(labelNormal, iconNormal, tooltipNormal) { - { - putValue(SMALL_ICON + SELECTED_KEY, iconSelected); - putValue(SHORT_DESCRIPTION + SELECTED_KEY, tooltipSelected); - } - @Override - public void actionPerformed(ActionEvent e) { - try { - m.invoke(o, isSelected()); - } catch (Exception ex) { - ex.printStackTrace(); - } - } - }); - } - } - } - public void invoke(String string) { - get(string).actionPerformed(new ActionEvent(this, ActionEvent.ACTION_PERFORMED, string)); - } + final boolean checkEnv = action.checkEnv(); + final boolean checkLic = action.checkLicense(); + + String label = ResourcesUtil.getString(key + ".label"); + String tooltip = ResourcesUtil.getString(key + ".tooltip"); + Icon icon = ResourcesUtil.getIcon(key + ".icon"); + + map.put(key, new ViewAction(label, icon, tooltip) { + @Override + public void actionPerformed(ActionEvent e) { + try { + if (checkLic) { + if (o.isDemo()) { + UiUtil.showDemoMessage(); + return; + } + } + if (checkEnv) { + if (!OpenFOAMEnvironment.isEnvironementLoaded()) { + UiUtil.showCoreEnvironmentNotLoadedWarning(); + return; + } + } + + m.invoke(o); + + } catch (Exception ex) { + ex.printStackTrace(); + } + } + }); + } + + protected void parseToggleActions(final ActionContainer o, final Method m, ActionToggle actionToggle) { + Class[] parameterTypes = m.getParameterTypes(); + if (parameterTypes.length != 1 || (parameterTypes.length == 1 && !parameterTypes[0].equals(boolean.class))) { + throw new RuntimeException("'ActionToggle' annotation: the method must have 1 boolean parameter"); + } + String key = actionToggle.key(); + if (bannedKeys.contains(key)) + return; + + String normal = actionToggle.normal(); + String selected = actionToggle.selected(); + // System.out.println("ActionManager.pa1rseActions() FOUND: "+key); + + String labelNormal = ResourcesUtil.getString(key + "." + normal + ".label"); + String tooltipNormal = ResourcesUtil.getString(key + "." + normal + ".tooltip"); + Icon iconNormal = ResourcesUtil.getIcon(key + "." + normal + ".icon"); + +// String labelSelected = ResourcesUtil.getString(key + "." + selected + ".label"); + final String tooltipSelected = ResourcesUtil.getString(key + "." + selected + ".tooltip"); + final Icon iconSelected = ResourcesUtil.getIcon(key + "." + selected + ".icon"); + + map.put(key, new ViewAction(labelNormal, iconNormal, tooltipNormal) { + { + putValue(SMALL_ICON + SELECTED_KEY, iconSelected); + putValue(SHORT_DESCRIPTION + SELECTED_KEY, tooltipSelected); + } + + @Override + public void actionPerformed(ActionEvent e) { + try { + m.invoke(o, isSelected()); + } catch (Exception ex) { + ex.printStackTrace(); + } + } + }); + } + + public void invoke(String string) { + get(string).actionPerformed(new ActionEvent(this, ActionEvent.ACTION_PERFORMED, string)); + } public ViewAction get(String string) { return (ViewAction) map.get(string); @@ -137,4 +152,9 @@ public class ActionManager { return map.get(string) != null; } + public void remove(String key) { + bannedKeys.add(key); + map.remove(key); + } + } diff --git a/src/eu/engys/core/presentation/ActionToggle.java b/src/eu/engys/core/presentation/ActionToggle.java index 786b8ab..68b2069 100644 --- a/src/eu/engys/core/presentation/ActionToggle.java +++ b/src/eu/engys/core/presentation/ActionToggle.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.presentation; diff --git a/src/eu/engys/core/project/AbstractProjectReader.java b/src/eu/engys/core/project/AbstractProjectReader.java index b77e9ec..d0423e9 100644 --- a/src/eu/engys/core/project/AbstractProjectReader.java +++ b/src/eu/engys/core/project/AbstractProjectReader.java @@ -1,29 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project; import java.util.ArrayList; @@ -33,27 +31,27 @@ import eu.engys.util.progress.ProgressMonitor; public abstract class AbstractProjectReader implements ProjectReader { - protected final ProgressMonitor monitor; - protected final Model model; - - protected List readers = new ArrayList<>(); + protected final ProgressMonitor monitor; + protected final Model model; - public AbstractProjectReader(Model model, ProgressMonitor monitor) { - this.model = model; - this.monitor = monitor; - } + protected List readers = new ArrayList<>(); - public Model getModel() { - return model; - } - - public ProgressMonitor getMonitor() { - return monitor; - } - - @Override - public void registerReader(ProjectReader reader) { - if (reader != null) - readers.add(reader); - } + public AbstractProjectReader(Model model, ProgressMonitor monitor) { + this.model = model; + this.monitor = monitor; + } + + public Model getModel() { + return model; + } + + public ProgressMonitor getMonitor() { + return monitor; + } + + @Override + public void registerReader(ProjectReader reader) { + if (reader != null) + readers.add(reader); + } } diff --git a/src/eu/engys/core/project/AbstractProjectWriter.java b/src/eu/engys/core/project/AbstractProjectWriter.java index e4fcbdc..d083b7f 100644 --- a/src/eu/engys/core/project/AbstractProjectWriter.java +++ b/src/eu/engys/core/project/AbstractProjectWriter.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project; diff --git a/src/eu/engys/core/project/CaseParameters.java b/src/eu/engys/core/project/CaseParameters.java index 5016c85..1b7beb5 100644 --- a/src/eu/engys/core/project/CaseParameters.java +++ b/src/eu/engys/core/project/CaseParameters.java @@ -1,29 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project; import java.io.File; @@ -36,7 +34,7 @@ public class CaseParameters { @Override public String toString() { - return String.format("New %s case (%s processors [%s, %s, %s] ) - ", isParallel() ? "parallel" : "serial", getnProcessors(), getnHierarchy()[0], getnHierarchy()[1], getnHierarchy()[2], getBaseDir().getAbsolutePath()); + return String.format("New %s case (%d processors [%d, %d, %d] ) - %s", isParallel() ? "parallel" : "serial", getnProcessors(), getnHierarchy()[0], getnHierarchy()[1], getnHierarchy()[2], getBaseDir().getAbsolutePath()); } public File getBaseDir() { diff --git a/src/eu/engys/core/project/CreateCase.java b/src/eu/engys/core/project/CreateCase.java index 98544cc..455068a 100644 --- a/src/eu/engys/core/project/CreateCase.java +++ b/src/eu/engys/core/project/CreateCase.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project; import static eu.engys.core.project.system.DecomposeParDict.HIERARCHICAL_COEFFS_KEY; @@ -73,11 +72,11 @@ public class CreateCase { try { systemFolder.setBlockMeshDict(defaults.getDefaultBlockMeshDict()); systemFolder.setSnappyHexMeshDict(defaults.getDefaultSnappyHexMeshDict()); + systemFolder.setStretchMeshDict(defaults.getDefaultStretchMeshDict()); systemFolder.setControlDict(defaults.getDefaultControlDict()); systemFolder.setFvSchemes(defaults.getDefaultFvSchemes()); systemFolder.setFvSolution(defaults.getDefaultFvSolution()); systemFolder.setFvOptions(defaults.getDefaultFvOptions()); - // systemFolder.setRunDict(defaults.getDefaultRunDict()); systemFolder.setMapFieldsDict(defaults.getDefaultMapFieldsDict()); systemFolder.setDecomposeParDict(defaults.getDefaultDecomposeParDict()); systemFolder.setCustomNodeDict(defaults.getDefaultCustomNodeDict()); @@ -110,6 +109,10 @@ public class CreateCase { for (File processorDir : baseDir.listFiles(new ProcessorDirectoryFileFilter())) { FileUtils.deleteQuietly(processorDir); } + } else { + for (File timeDir : baseDir.listFiles(new TimeDirectoryFileFilter())) { + FileUtils.deleteQuietly(timeDir); + } } if (Util.isWindows()) { @@ -157,4 +160,17 @@ public class CreateCase { return isDir && isProcessor; } } + + private static class TimeDirectoryFileFilter implements FileFilter { + + @Override + public boolean accept(File pathname) { + try { + Double.parseDouble(pathname.getName()); + return pathname.isDirectory(); + } catch (NumberFormatException nfe) { + return false; + } + } + } } diff --git a/src/eu/engys/gui/CreateCaseDialog.java b/src/eu/engys/core/project/CreateCaseDialog.java similarity index 80% rename from src/eu/engys/gui/CreateCaseDialog.java rename to src/eu/engys/core/project/CreateCaseDialog.java index e3b0926..cf144d4 100644 --- a/src/eu/engys/gui/CreateCaseDialog.java +++ b/src/eu/engys/core/project/CreateCaseDialog.java @@ -1,29 +1,28 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - -package eu.engys.gui; +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.core.project; import static eu.engys.util.ui.ComponentsFactory.checkField; import static eu.engys.util.ui.ComponentsFactory.intArrayField; @@ -50,7 +49,7 @@ import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.SwingUtilities; -import eu.engys.core.project.CaseParameters; +import eu.engys.util.DialogExitStatus; import eu.engys.util.PrefUtil; import eu.engys.util.Util; import eu.engys.util.filechooser.util.SelectionMode; @@ -72,10 +71,6 @@ public class CreateCaseDialog extends JPanel { public static final String PARENT_FOLDER_LABEL = "Parent Folder"; public static final String CASE_NAME_LABEL = "Case Name"; - enum Status { - OK, ERROR, CANCEL - } - private static final int X = 0; private static final int Y = 1; private static final int Z = 2; @@ -91,7 +86,7 @@ public class CreateCaseDialog extends JPanel { private File baseDir; private IntegerField[] nHierarchyField; - private Status status = Status.ERROR; + private DialogExitStatus status = DialogExitStatus.ERROR; public CreateCaseDialog() { super(new BorderLayout()); @@ -152,11 +147,11 @@ public class CreateCaseDialog extends JPanel { JButton cancelButton = new JButton(cancelAction); cancelButton.setName("button.cancel"); - + JPanel buttonsPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); buttonsPanel.add(okButton); buttonsPanel.add(cancelButton); - + dialog = new JDialog(UiUtil.getActiveWindow(), CREATE_CASE_LABEL); dialog.setName("create.case.dialog"); dialog.setModal(true); @@ -180,7 +175,7 @@ public class CreateCaseDialog extends JPanel { private void setDefaultValues() { File lastDir = PrefUtil.getWorkDir(PrefUtil.WORK_DIR); fileField.setFile(lastDir); - + nameField.setText("newCase"); isParallel.setSelected(false); @@ -211,7 +206,7 @@ public class CreateCaseDialog extends JPanel { String parentPath = fileField.getFilePath(); if (parentPath.isEmpty()) { JOptionPane.showMessageDialog(dialog, "Empty parent folder", error, JOptionPane.ERROR_MESSAGE); - status = Status.CANCEL; + status = DialogExitStatus.CANCEL; } else { File parent = new File(parentPath); if (parent.exists()) { @@ -220,35 +215,35 @@ public class CreateCaseDialog extends JPanel { if (baseDir.exists()) { if (baseDir.isFile()) { JOptionPane.showMessageDialog(dialog, "File already exists", error, JOptionPane.ERROR_MESSAGE); - status = Status.CANCEL; + status = DialogExitStatus.CANCEL; } else if (baseDir.isDirectory() && baseDir.list().length != 0) { int retVal = JOptionPane.showConfirmDialog(dialog, "Folder already exists. Continue anyway?", warning, JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE); if (retVal == JOptionPane.NO_OPTION) { - status = Status.CANCEL; + status = DialogExitStatus.CANCEL; } else { - status = Status.OK; + status = DialogExitStatus.OK; } } else { - status = Status.OK; + status = DialogExitStatus.OK; } } else { - status = Status.OK; + status = DialogExitStatus.OK; } } else { JOptionPane.showMessageDialog(dialog, "Write permission", error, JOptionPane.ERROR_MESSAGE); - status = Status.CANCEL; + status = DialogExitStatus.CANCEL; } } else { String msg = String.format("Folder %s does not exist.\n Do you want to create it?", parent); int retVal = JOptionPane.showConfirmDialog(dialog, msg, warning, JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); if (retVal == JOptionPane.NO_OPTION) { - status = Status.CANCEL; + status = DialogExitStatus.CANCEL; } else { if (parent.canWrite()) { - status = Status.OK; + status = DialogExitStatus.OK; } else { JOptionPane.showMessageDialog(dialog, "Write permission", error, JOptionPane.ERROR_MESSAGE); - status = Status.CANCEL; + status = DialogExitStatus.CANCEL; } } } @@ -276,20 +271,20 @@ public class CreateCaseDialog extends JPanel { } private void cancelAction() { - status = Status.CANCEL; + status = DialogExitStatus.CANCEL; closeDialog(); } public boolean isOK() { - return status == Status.OK; + return status == DialogExitStatus.OK; } public boolean isError() { - return status == Status.ERROR; + return status == DialogExitStatus.ERROR; } public boolean isCancel() { - return status == Status.CANCEL; + return status == DialogExitStatus.CANCEL; } private final class OkDialogAction extends AbstractAction implements Runnable { diff --git a/src/eu/engys/core/project/DefaultProjectReader.java b/src/eu/engys/core/project/DefaultProjectReader.java index e7b5d24..acbe923 100644 --- a/src/eu/engys/core/project/DefaultProjectReader.java +++ b/src/eu/engys/core/project/DefaultProjectReader.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project; import java.io.File; @@ -37,6 +36,7 @@ import eu.engys.core.modules.ApplicationModule; import eu.engys.core.modules.ModulesUtil; import eu.engys.core.project.geometry.factory.DefaultGeometryFactory; import eu.engys.core.project.materials.MaterialsReader; +import eu.engys.core.project.mesh.MeshInfoReader; import eu.engys.core.project.state.StateBuilder; import eu.engys.core.project.state.Table15; import eu.engys.core.project.system.ControlDict; @@ -70,7 +70,33 @@ public class DefaultProjectReader extends AbstractProjectReader { } @Override - public void read() throws InvalidProjectException { + public void readMesh() { + File baseDir = model.getProject().getBaseDir(); + if (baseDir.exists() && baseDir.isDirectory()) { + openFOAMProject prj = model.getProject(); + ControlDict controlDict = prj.getSystemFolder().getControlDict(); + if (controlDict != null) { + if (controlDict.isBinary()) { + monitor.error("Binary fields format not supported"); + } else { + prj.getSystemFolder().readProjectDict(model, monitor, prj.getSystemFolder().getFileManager().getFile()); + logger.info("### Read mesh: '{}' ### ", prj.getZeroFolder().getFileManager().getFile()); + prj.getZeroFolder().read(model, cellZoneBuilder, modules, initialisation, monitor); + } + } + + new MeshInfoReader(model).read(); + + if (!model.getPatches().isEmpty()) { + model.getGeometry().hideSurfaces(); + } + } else { + monitor.error(baseDir + " not found"); + } + } + + @Override + public void read() { File baseDir = model.getProject().getBaseDir(); logger.info("################## Read '{}' ################## ", baseDir.getName()); if (baseDir.exists() && baseDir.isDirectory()) { @@ -85,54 +111,42 @@ public class DefaultProjectReader extends AbstractProjectReader { logger.info("################## End Read ################## "); } - @Override - public void readMesh() { - File baseDir = model.getProject().getBaseDir(); - if (baseDir.exists() && baseDir.isDirectory()) { - openFOAMProject prj = model.getProject(); - ControlDict controlDict = prj.getSystemFolder().getControlDict(); - if (controlDict != null) { - if (controlDict.isBinary()) { - monitor.error("Binary fields format not supported"); - } else { - logger.info("### Read mesh: '{}' ### ", prj.getZeroFolder().getFileManager().getFile()); - prj.getZeroFolder().read(model, cellZoneBuilder, modules, initialisation, monitor); - } - } - - if (!model.getPatches().isEmpty()) { - model.getGeometry().hideSurfaces(); - } - } else { - monitor.error(baseDir + " not found"); - } - } - - protected void defaultRead() throws InvalidProjectException { + + private void defaultRead() { monitor.info(""); monitor.info("Reading Project"); openFOAMProject project = model.getProject(); monitor.info("-> Reading Constant Folder"); - project.getConstantFolder().load(model, monitor); + project.getConstantFolder().read(model, monitor); monitor.info("-> Reading System Folder"); project.getSystemFolder().read(model, ffoTypes, mfoTypes, monitor); - new SolverModelReader(model).load(); + new SolverModelReader(model.getSolverModel()).load(project.getSystemFolder().getProjectDict()); + + new MeshInfoReader(model).read(); monitor.info("-> Reading Geometry"); model.getGeometry().loadGeometry(model, monitor); - + + monitor.info("-> Reading Modules Data"); + ModulesUtil.read(modules); + monitor.info("-> Reading State"); StateBuilder.loadState(model, solversTable, monitor); - solversTable.updateSolver(model.getState()); - /* - * Call updateSolver after loadState because some module may need some other module state in order to select the correct solver (e.g. Dynamic and VOF) - */ monitor.info("-> Reading Modules State"); ModulesUtil.loadState(modules); + + /* + * Call updateSolver after loadState because some module may need some other module + * state in order to select the correct solver (e.g. Dynamic and VOF) + */ + monitor.info("-> Reading Solver"); + solversTable.updateSolver(model.getState()); + + monitor.info("-> Reading Modules Solver"); ModulesUtil.updateSolver(modules, model.getState()); monitor.info("-> Reading Materials"); @@ -155,5 +169,4 @@ public class DefaultProjectReader extends AbstractProjectReader { model.getGeometry().hideSurfaces(); } } - } diff --git a/src/eu/engys/core/project/DefaultProjectWriter.java b/src/eu/engys/core/project/DefaultProjectWriter.java index ba1202d..5b508a4 100644 --- a/src/eu/engys/core/project/DefaultProjectWriter.java +++ b/src/eu/engys/core/project/DefaultProjectWriter.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project; @@ -32,16 +31,20 @@ import java.io.IOException; import java.util.Set; import javax.inject.Inject; +import javax.swing.JOptionPane; import org.apache.commons.io.FileUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import eu.engys.core.modules.ApplicationModule; +import eu.engys.core.modules.ModulesUtil; import eu.engys.core.project.materials.MaterialsWriter; +import eu.engys.core.project.mesh.MeshInfoWriter; import eu.engys.core.project.zero.cellzones.CellZonesBuilder; import eu.engys.core.project.zero.fields.Initialisations; import eu.engys.util.progress.ProgressMonitor; +import eu.engys.util.ui.UiUtil; public class DefaultProjectWriter extends AbstractProjectWriter { @@ -78,12 +81,23 @@ public class DefaultProjectWriter extends AbstractProjectWriter { logger.info("################## Write '{}' ################## ", baseDir.getName()); monitor.info(""); monitor.info("Saving Project"); + openFOAMProject oldProject = model.getProject(); + File newProjectBaseDir = baseDir.getAbsoluteFile(); + File oldProjectBaseDir = oldProject.getBaseDir().getAbsoluteFile(); + boolean isSaveAs = !newProjectBaseDir.equals(oldProjectBaseDir); + if(isSaveAs){ + if(newProjectBaseDir.getParentFile().equals(oldProjectBaseDir)){ + String title = "Save error"; + String message = "The destination folder is a subfolder of the source folder"; + JOptionPane.showMessageDialog(UiUtil.getActiveWindow(), message, title, JOptionPane.ERROR_MESSAGE); + return; + } + } + if (!baseDir.exists()) { baseDir.mkdirs(); } - openFOAMProject oldProject = model.getProject(); - boolean isSaveAs = !baseDir.getAbsoluteFile().equals(oldProject.getBaseDir().getAbsoluteFile()); if (isSaveAs) { CreateCase.deleteAll(baseDir, oldProject.isParallel(), oldProject.getProcessors()); makeACopy(baseDir); @@ -96,9 +110,13 @@ public class DefaultProjectWriter extends AbstractProjectWriter { model.getCustom().saveCustomDict(model); - new SolverModelWriter(model).save(); + new SolverModelWriter(model.getSolverModel()).save(model.getProject()); openFOAMProject project = model.getProject(); + + monitor.info("-> Saving Materials"); + model.getMaterials().saveMaterials(model, materialsWriter); + ModulesUtil.saveMaterials(modules); monitor.info("-> Saving Zero Folder"); project.getZeroFolder().write(model, cellZoneBuilder, modules, initialisations, monitor); @@ -110,16 +128,13 @@ public class DefaultProjectWriter extends AbstractProjectWriter { project.getSystemFolder().write(model, monitor); monitor.info("-> Saving Modules"); - for (ApplicationModule m : modules) { - monitor.info(m.getName(), 1); - m.write(); - } + ModulesUtil.write(modules); for (ProjectWriter writer : writers) { writer.write(baseDir); } - File logFolder = new File(baseDir, "log"); + File logFolder = new File(baseDir, openFOAMProject.LOG); if (!logFolder.exists()) { logFolder.mkdir(); } @@ -127,6 +142,8 @@ public class DefaultProjectWriter extends AbstractProjectWriter { monitor.info("-> Saving Custom"); model.getCustom().write(model, monitor); + new MeshInfoWriter(model).write(); + logger.info("################## End Write ############################## "); } diff --git a/src/eu/engys/core/project/InvalidProjectException.java b/src/eu/engys/core/project/InvalidProjectException.java index 1c47ca1..2d583c4 100644 --- a/src/eu/engys/core/project/InvalidProjectException.java +++ b/src/eu/engys/core/project/InvalidProjectException.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project; public class InvalidProjectException extends RuntimeException { diff --git a/src/eu/engys/core/project/Model.java b/src/eu/engys/core/project/Model.java index f777c29..2ad2b00 100644 --- a/src/eu/engys/core/project/Model.java +++ b/src/eu/engys/core/project/Model.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project; import java.util.Observable; @@ -40,10 +39,12 @@ import eu.engys.core.project.mesh.Mesh; import eu.engys.core.project.runtimefields.RuntimeFields; import eu.engys.core.project.state.State; import eu.engys.core.project.system.fieldmanipulationfunctionobjects.FieldManipulationFunctionObjects; +import eu.engys.core.project.system.monitoringfunctionobjects.MonitoringFunctionObject; import eu.engys.core.project.system.monitoringfunctionobjects.MonitoringFunctionObjects; import eu.engys.core.project.zero.cellzones.CellZones; import eu.engys.core.project.zero.facezones.FaceZones; import eu.engys.core.project.zero.fields.Fields; +import eu.engys.core.project.zero.patches.BoundaryType; import eu.engys.core.project.zero.patches.Patches; public class Model extends Observable { @@ -233,6 +234,7 @@ public class Model extends Observable { materialsChanged(); patchesChanged(); cellZonesChanged(); + faceZonesChanged(); fieldManipulationFunctionObjectsChanged(); monitoringFunctionObjectsChanged(); customChanged(); @@ -247,10 +249,6 @@ public class Model extends Observable { notifyObservers(state); } - public void patchesChanged() { - setChanged(); - notifyObservers(patches); - } public void fieldsChanged() { setChanged(); @@ -266,6 +264,17 @@ public class Model extends Observable { setChanged(); notifyObservers(materials); } + + public void patchesChanged() { + setChanged(); + notifyObservers(patches); + } + + + public void boundaryTypeChanged(BoundaryType boundaryType) { + setChanged(); + notifyObservers(boundaryType); + } public void cellZonesChanged() { setChanged(); @@ -281,6 +290,11 @@ public class Model extends Observable { setChanged(); notifyObservers(monitoringFunctionObjects); } + + public void monitoringFunctionObjectChanged(MonitoringFunctionObject fo) { + setChanged(); + notifyObservers(fo); + } public void fieldManipulationFunctionObjectsChanged() { setChanged(); diff --git a/src/eu/engys/core/project/NullProjectReader.java b/src/eu/engys/core/project/NullProjectReader.java index e5653b7..a0a2a43 100644 --- a/src/eu/engys/core/project/NullProjectReader.java +++ b/src/eu/engys/core/project/NullProjectReader.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project; diff --git a/src/eu/engys/core/project/NullProjectWriter.java b/src/eu/engys/core/project/NullProjectWriter.java index 6f20943..65ed11e 100644 --- a/src/eu/engys/core/project/NullProjectWriter.java +++ b/src/eu/engys/core/project/NullProjectWriter.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project; diff --git a/src/eu/engys/core/project/Project200To210Converter.java b/src/eu/engys/core/project/Project200To210Converter.java index 9531715..772fa58 100644 --- a/src/eu/engys/core/project/Project200To210Converter.java +++ b/src/eu/engys/core/project/Project200To210Converter.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project; import static eu.engys.core.controller.AbstractScriptFactory.MESH_PARALLEL_BAT; @@ -230,17 +229,17 @@ public class Project200To210Converter { if (foDict.found(Dictionary.TYPE)) { String type = foDict.lookup(Dictionary.TYPE); switch (type) { - case "liftDrag": - moveLiftDragFunctionObject(baseDirPath, foDict); - break; - case "volumeReport": - moveVolumeReportFunctionObject(baseDirPath, foDict); - break; - case "forces": - moveForcesFunctionObject(baseDirPath, foDict); - break; - default: - break; + case "liftDrag": + moveLiftDragFunctionObject(baseDirPath, foDict); + break; + case "volumeReport": + moveVolumeReportFunctionObject(baseDirPath, foDict); + break; + case "forces": + moveForcesFunctionObject(baseDirPath, foDict); + break; + default: + break; } } @@ -253,7 +252,7 @@ public class Project200To210Converter { private void moveLiftDragFunctionObject(String baseDirPath, Dictionary foDict) { String foName = foDict.getName(); File logFolder = Paths.get(baseDirPath, openFOAMProject.LOG).toFile(); - if (logFolder.exists()) { + if (logFolder.isDirectory() && logFolder.exists()) { for (File child : logFolder.listFiles()) { String fileName = child.getName(); if (fileName.startsWith(foName) && fileName.endsWith(".dat")) { @@ -262,7 +261,7 @@ public class Project200To210Converter { try { FileUtils.moveFileToDirectory(child, functionObjectFolder, true); } catch (IOException e) { - logger.error("Could not move " + child + " to " + functionObjectFolder); + logger.error("Could not move {} to {}", child, functionObjectFolder); } } } @@ -272,7 +271,7 @@ public class Project200To210Converter { private void moveVolumeReportFunctionObject(String baseDirPath, Dictionary foDict) { String foName = foDict.getName(); File logFolder = Paths.get(baseDirPath, openFOAMProject.LOG).toFile(); - if (logFolder.exists()) { + if (logFolder.isDirectory() && logFolder.exists()) { for (File child : logFolder.listFiles()) { String fileName = child.getName(); if (fileName.startsWith(foName + "_volumeStatistics.")) { @@ -404,7 +403,7 @@ public class Project200To210Converter { zones.addAll(CellZones200To210Converter.loadPorousDictionary(porousZones)); } - cellZonesBuilder.saveMRFDictionary(zones, systemFolder.getFvOptions()); + cellZonesBuilder.saveMRFDictionary(zones, systemFolder.getFvOptions(), null); cellZonesBuilder.savePorousDictionary(zones, systemFolder.getFvOptions()); DictionaryUtils.writeDictionary(systemFolder.getFileManager().getFile(), systemFolder.getFvOptions(), monitor); diff --git a/src/eu/engys/core/project/Project210To240Converter.java b/src/eu/engys/core/project/Project210To240Converter.java new file mode 100644 index 0000000..6102865 --- /dev/null +++ b/src/eu/engys/core/project/Project210To240Converter.java @@ -0,0 +1,75 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.core.project; + +import static eu.engys.core.project.system.ProjectDict.PROJECT_DICT; +import static eu.engys.core.project.system.RunDict.RUN_DICT; + +import java.io.File; + +import org.apache.commons.io.FileUtils; + +import eu.engys.core.dictionary.DictionaryUtils; +import eu.engys.core.project.system.ProjectDict; +import eu.engys.core.project.system.RunDict; + +public class Project210To240Converter { + + private openFOAMProject project; + + public Project210To240Converter(openFOAMProject project) { + this.project = project; + } + + public void convert() { + fixLogFolder(); + fixRunDict(); + } + + private void fixRunDict() { + File runDictFile = project.getSystemFolder().getFileManager().getFile(RUN_DICT); + if (runDictFile.exists()) { + RunDict runDict = new RunDict(runDictFile); + + File projectDictFile = project.getSystemFolder().getFileManager().getFile(PROJECT_DICT); + if (!projectDictFile.exists()) { + ProjectDict projectDict = new ProjectDict(); + projectDict.setRunDict(runDict); + DictionaryUtils.writeDictionary(project.getSystemFolder().getFileManager().getFile(), projectDict, null); + } + FileUtils.deleteQuietly(runDictFile); + } + } + + public void fixLogFolder() { + File logFolder = new File(project.getBaseDir(), openFOAMProject.LOG); + if (!logFolder.exists()) { + logFolder.mkdir(); + } else if (logFolder.isFile()) { + logFolder.renameTo(new File(project.getBaseDir(), openFOAMProject.LOG + ".old")); + logFolder.mkdir(); + } + } +} diff --git a/src/eu/engys/core/project/ProjectFolderAnalyzer.java b/src/eu/engys/core/project/ProjectFolderAnalyzer.java index 6d03ec7..3cd5f7c 100644 --- a/src/eu/engys/core/project/ProjectFolderAnalyzer.java +++ b/src/eu/engys/core/project/ProjectFolderAnalyzer.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project; @@ -41,8 +40,6 @@ import javax.swing.JOptionPane; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import eu.engys.core.Arguments; -import eu.engys.core.Arguments.CaseType; import eu.engys.core.dictionary.Dictionary; import eu.engys.core.dictionary.DictionaryUtils; import eu.engys.core.project.system.DecomposeParDict; @@ -56,6 +53,9 @@ import eu.engys.util.ui.UiUtil; public class ProjectFolderAnalyzer { + public static final String PARALLEL_CHOICE = "Parallel"; + public static final String SERIAL_CHOICE = "Serial"; + private static final Logger logger = LoggerFactory.getLogger(ProjectFolderAnalyzer.class); // parallel parallel serial serial @@ -82,26 +82,36 @@ public class ProjectFolderAnalyzer { // F F F F -> N + public enum WhenInDoubt {READ_PARALLEL, ASK_USER}; + private static final String PROCESSOR = "processor"; private final File baseDir; private int processors; - private boolean parallel_constant;/* whether boudary is in 0 or in constant */ - private boolean parallel_zero;/* whether boudary is in 0 or in constant */ + /* whether boundary file is in 0 or in constant */ + private boolean parallel_constant; + private boolean parallel_constant_multiregion; + private boolean parallel_zero_multiregion; + private boolean parallel_zero; - private boolean serial_constant;/* whether boudary is in 0 or in constant */ - private boolean serial_zero;/* whether boudary is in 0 or in constant */ + private boolean serial_constant; + private boolean serial_zero; + private boolean serial_constant_multiregion; + private boolean serial_zero_multiregion; private final ProgressMonitor monitor; + private WhenInDoubt wid; + public ProjectFolderAnalyzer(File baseDir, ProgressMonitor monitor) { this.baseDir = baseDir; this.monitor = monitor; } - public ProjectFolderStructure checkAll() { + public ProjectFolderStructure checkAll(WhenInDoubt wid) { + this.wid = wid; checkSerialOrParallel(); return populateStructure(); } @@ -188,6 +198,8 @@ public class ProjectFolderAnalyzer { parallel_zero = structure.isBoundaryFieldInZero(); parallel_constant = structure.isBoundaryFieldInConstant(); + parallel_zero_multiregion = structure.isBoundaryFieldInZeroMultiRegion(); + parallel_constant_multiregion = structure.isBoundaryFieldInConstantMultiRegion(); } void checkSerialBoundary() { @@ -196,24 +208,18 @@ public class ProjectFolderAnalyzer { serial_zero = structure.isBoundaryFieldInZero(); serial_constant = structure.isBoundaryFieldInConstant(); + serial_zero_multiregion = structure.isBoundaryFieldInZeroMultiRegion(); + serial_constant_multiregion = structure.isBoundaryFieldInConstantMultiRegion(); } private void askToUser(ProjectFolderStructure checkList) { - if (Arguments.isBatch()) { - if (Arguments.caseType == CaseType.SERIAL) { - logger.debug("Is Batch, case type is SERIAL"); - checkList.setParallel(false); - checkList.setProcessors(-1); - } else if (Arguments.caseType == CaseType.PARALLEL) { - logger.debug("Is Batch, case type is PARALLEL"); - checkList.setParallel(true); - checkList.setProcessors(processors); - } else { - System.err.println("Case folder contains a serial AND a parallel case.\nPlease select which case to load: use '-serial' or '-parallel' option"); - System.exit(-1); - } - } else { - Object[] options = { "Serial", "Parallel" }; + if (wid == WhenInDoubt.READ_PARALLEL) { + System.err.println("Case folder contains a serial AND a parallel case.\nSwitch to parallel!");//Please select which case to load: use '-serial' or '-parallel' option"); + logger.debug("Is Batch, case type is PARALLEL"); + checkList.setParallel(true); + checkList.setProcessors(processors); + } else if (wid == WhenInDoubt.ASK_USER) { + Object[] options = { SERIAL_CHOICE, PARALLEL_CHOICE }; Window parentComponent = monitor != null ? monitor.getDialog() : UiUtil.getActiveWindow(); int answer = JOptionPane.showOptionDialog(parentComponent, "Project contains serial AND parallel case.\nPlease select which case to load", "Warning", JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE, null, options, options[0]); logger.debug("Asking user"); @@ -242,22 +248,38 @@ public class ProjectFolderAnalyzer { } } - public boolean isParallel_constant() { + public boolean isParallel_Constant() { return parallel_constant; } - public boolean isParallel_zero() { + public boolean isParallel_Constant_MultiRegion() { + return parallel_constant_multiregion; + } + + public boolean isParallel_Zero() { return parallel_zero; } - public boolean isSerial_constant() { + public boolean isParallel_Zero_MultiRegion() { + return parallel_zero_multiregion; + } + + public boolean isSerial_Constant() { return serial_constant; } - public boolean isSerial_zero() { + public boolean isSerial_Zero() { return serial_zero; } + public boolean isSerial_Constant_MultiRegion() { + return serial_constant_multiregion; + } + + public boolean isSerial_Zero_MultiRegion() { + return serial_zero_multiregion; + } + public static boolean isSuitable(File file) { if (file != null && file.exists() && file.isDirectory()) { File constant = new File(file, CONSTANT); diff --git a/src/eu/engys/core/project/ProjectFolderStructure.java b/src/eu/engys/core/project/ProjectFolderStructure.java index ab87db4..f69cd0f 100644 --- a/src/eu/engys/core/project/ProjectFolderStructure.java +++ b/src/eu/engys/core/project/ProjectFolderStructure.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project; public class ProjectFolderStructure { diff --git a/src/eu/engys/core/project/ProjectReader.java b/src/eu/engys/core/project/ProjectReader.java index 36f4d7a..52f2cfc 100644 --- a/src/eu/engys/core/project/ProjectReader.java +++ b/src/eu/engys/core/project/ProjectReader.java @@ -1,34 +1,32 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project; public interface ProjectReader { - public void read() throws InvalidProjectException; + public void read(); public void readMesh(); diff --git a/src/eu/engys/core/project/ProjectWriter.java b/src/eu/engys/core/project/ProjectWriter.java index 6e8113a..844ca72 100644 --- a/src/eu/engys/core/project/ProjectWriter.java +++ b/src/eu/engys/core/project/ProjectWriter.java @@ -1,38 +1,37 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project; import java.io.File; - public interface ProjectWriter { public void write(File baseDir); + public void create(CaseParameters params); + public void registerWriter(ProjectWriter writer); - + } diff --git a/src/eu/engys/core/project/SolverModel.java b/src/eu/engys/core/project/SolverModel.java index 4ae6e9c..af7ba28 100644 --- a/src/eu/engys/core/project/SolverModel.java +++ b/src/eu/engys/core/project/SolverModel.java @@ -1,40 +1,37 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project; -import static eu.engys.core.project.system.RunDict.RUN_DICT; - import java.io.File; import java.io.Serializable; import java.util.Observable; import eu.engys.core.controller.Command; -import eu.engys.core.dictionary.Dictionary; import eu.engys.core.dictionary.DictionaryUtils; import eu.engys.core.project.state.ServerState; +import eu.engys.core.project.system.ProjectDict; import eu.engys.util.connection.QueueParameters; import eu.engys.util.connection.SshParameters; import eu.engys.util.progress.SilentMonitor; @@ -126,14 +123,13 @@ public class SolverModel extends Observable implements Serializable { return remote; } - private void read(Model model) { - File file = model.getProject().getSystemFolder().getFileManager().getFile(RUN_DICT); - new SolverModelReader(model).loadFromRunDict(new Dictionary(file), this); - } - // Called from Server, so you need to load runDict from disk + // state may be changed by an instance running in queue system + // need to refresh state before public void writeState(ServerState state, Model model) { - read(model); + File file = model.getProject().getSystemFolder().getFileManager().getFile(ProjectDict.PROJECT_DICT); + ProjectDict projectDict = new ProjectDict(file); + new SolverModelReader(this).load(projectDict); setServerState(state); write(model); } @@ -143,9 +139,14 @@ public class SolverModel extends Observable implements Serializable { write(model); } + public void removeServerID(Model model) { + setServerID(null); + write(model); + } + private void write(Model model) { - new SolverModelWriter(model).save(); - DictionaryUtils.writeDictionary(model.getProject().getSystemFolder().getFileManager().getFile(), model.getProject().getSystemFolder().getRunDict(), new SilentMonitor()); + new SolverModelWriter(this).save(model.getProject()); + DictionaryUtils.writeDictionary(model.getProject().getSystemFolder().getFileManager().getFile(), model.getProject().getSystemFolder().getProjectDict(), new SilentMonitor()); } @Override diff --git a/src/eu/engys/core/project/SolverModelReader.java b/src/eu/engys/core/project/SolverModelReader.java index 1e8eb21..545aada 100644 --- a/src/eu/engys/core/project/SolverModelReader.java +++ b/src/eu/engys/core/project/SolverModelReader.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project; import static eu.engys.util.connection.SshParameters.APPLICATION_DIR; @@ -42,7 +41,7 @@ import org.slf4j.LoggerFactory; import eu.engys.core.dictionary.BeanToDict; import eu.engys.core.dictionary.Dictionary; -import eu.engys.core.project.system.RunDict; +import eu.engys.core.project.system.ProjectDict; import eu.engys.util.Util; import eu.engys.util.connection.SshParameters; import eu.engys.util.connection.SshParameters.AuthType; @@ -50,118 +49,26 @@ import eu.engys.util.connection.SshParameters.AuthType; public class SolverModelReader { private static final Logger logger = LoggerFactory.getLogger(SolverModelReader.class); - private Model model; + private SolverModel solverModel; - public SolverModelReader(Model model) { - this.model = model; + public SolverModelReader(SolverModel solverModel) { + this.solverModel = solverModel; } - void load() { - RunDict runDict = model.getProject().getSystemFolder().getRunDict(); - populateSolverModel(runDict); - } - - private void populateSolverModel(Dictionary runDict) { - SolverModel solverModel = model.getSolverModel(); - if (runDict != null) { - loadFromRunDict(runDict, solverModel); + void load(ProjectDict prjDict) { + if (prjDict != null) { + Dictionary runDict = prjDict.getRunDict(); + if (runDict != null) { + loadFromRunDict(runDict, solverModel); + } } } - void loadFromRunDict(Dictionary runDict, SolverModel solverModel) { + private void loadFromRunDict(Dictionary runDict, SolverModel solverModel) { BeanToDict.dictToBean(runDict, solverModel); SolverModelWriter.decryptPassword(solverModel.getSshParameters()); -//// readRMIPort(runDict, solverModel); -//// readLOGPort(runDict, solverModel); -// readServerID(runDict, solverModel); -// readRemote(runDict, solverModel); -// readQueue(runDict, solverModel); -// readLogFile(runDict, solverModel); -// readState(runDict, solverModel); -// readSSHParameters(runDict, solverModel); -// readQueueParameters(runDict, solverModel); -// readMultiMachine(runDict, solverModel); -// readHostfilePath(runDict, solverModel); } -// private void readRemote(Dictionary runDict, SolverModel solverModel) { -// if (runDict.found(REMOTE)) { -// solverModel.setRemote(Boolean.valueOf(runDict.lookup(REMOTE))); -// } -// } -// -// private void readQueue(Dictionary runDict, SolverModel solverModel) { -// if (runDict.found(QUEUE)) { -// solverModel.setQueue(Boolean.valueOf(runDict.lookup(QUEUE))); -// } -// } -// -// private void readMultiMachine(Dictionary runDict, SolverModel solverModel) { -// if (runDict.found(MULTI_MACHINE)) { -// Boolean value = Boolean.valueOf(runDict.lookup(MULTI_MACHINE)); -// solverModel.setMultiMachine(value && !Util.isWindows()); -// } -// } -// -// private void readHostfilePath(Dictionary runDict, SolverModel solverModel) { -// if (runDict.found(HOSTFILE_PATH)) { -// solverModel.setHostfilePath(runDict.lookup(HOSTFILE_PATH)); -// } -// } -// -// private void readLogFile(Dictionary runDict, SolverModel solverModel) { -// if (runDict.found(LOG_FILE)) { -// solverModel.setLogFile(runDict.lookup(LOG_FILE)); -// } -// } - -// private void readRMIPort(Dictionary runDict, SolverModel solverModel) { -// if (runDict.found(RMI_PORT)) { -// solverModel.setRmiPort(runDict.lookupInt(RMI_PORT)); -// } -// } -// -// private void readLOGPort(Dictionary runDict, SolverModel solverModel) { -// if (runDict.found(LOG_PORT)) { -// solverModel.setLogPort(runDict.lookupInt(LOG_PORT)); -// } -// } - -// private void readServerID(Dictionary runDict, SolverModel solverModel) { -// if (runDict.found(SERVER_ID)) { -// solverModel.setServerID(runDict.lookup(SERVER_ID)); -// } -// } -// -// private void readState(Dictionary runDict, SolverModel solverModel) { -// Dictionary serverStateDict = runDict.found(SERVER_STATE) ? runDict.subDict(SERVER_STATE) : new Dictionary(SERVER_STATE); -// -// ServerState serverState = readServerStateFromDictionary(serverStateDict); -// solverModel.setServerState(serverState); -// } - -// public static ServerState readServerStateFromDictionary(Dictionary serverStateDict) { -// ServerState serverState = new ServerState(); -// -// if (serverStateDict.found(ServerState.COMMAND)) { -// serverState.setCommand(Command.valueOf(serverStateDict.lookup(ServerState.COMMAND))); -// } -// if (serverStateDict.found(ServerState.SOLVER_STATE)) { -// serverState.setSolverState(SolverState.valueOf(serverStateDict.lookup(ServerState.SOLVER_STATE))); -// } -// if (serverStateDict.found(ServerState.ERROR)) { -// serverState.setError(new ServerError(1, "message")); -// } -// return serverState; -// } - -// private void readSSHParameters(Dictionary runDict, SolverModel solverModel) { -// Dictionary sshParametersDict = runDict.found(SSH_PARAMETERS) ? runDict.subDict(SSH_PARAMETERS) : new Dictionary(SSH_PARAMETERS); -// -// SshParameters parameters = readSshParametersFromDictionary(sshParametersDict); -// solverModel.setSshParameters(parameters); -// } - public static SshParameters readSshParametersFromDictionary(Dictionary sshParametersDict) { SshParameters parameters = new SshParameters(); if (sshParametersDict.found(USER)) { @@ -200,31 +107,4 @@ public class SolverModelReader { return parameters; } -// private void readQueueParameters(Dictionary runDict, SolverModel solverModel) { -// QueueParameters parameters = new QueueParameters(); -// Dictionary queueParametersDict = runDict.found(QUEUE_PARAMETERS) ? runDict.subDict(QUEUE_PARAMETERS) : new Dictionary(QUEUE_PARAMETERS); -// -// if (queueParametersDict.found(QUEUE_NODES)) { -// String nodes = queueParametersDict.lookup(QUEUE_NODES); -// parameters.setNumberOfNodes(Integer.parseInt(nodes)); -// } -// if (queueParametersDict.found(QUEUE_CPUS)) { -// String cpus = queueParametersDict.lookup(QUEUE_CPUS); -// parameters.setCpuPerNode(Integer.parseInt(cpus)); -// } -// if (queueParametersDict.found(QUEUE_TIMEOUT)) { -// String timeout = queueParametersDict.lookup(QUEUE_TIMEOUT); -// parameters.setTimeout(Integer.parseInt(timeout)); -// } -// if (queueParametersDict.found(QUEUE_FEATURE)) { -// String feature = queueParametersDict.lookup(QUEUE_FEATURE); -// parameters.setFeature(feature); -// } -// if (queueParametersDict.found(QUEUE_NAMES)) { -// String names = queueParametersDict.lookup(QUEUE_NAMES); -// parameters.setNodeNames(names); -// } -// -// solverModel.setQueueParameters(parameters); -// } } diff --git a/src/eu/engys/core/project/SolverModelWriter.java b/src/eu/engys/core/project/SolverModelWriter.java index 10d1210..aa26e17 100644 --- a/src/eu/engys/core/project/SolverModelWriter.java +++ b/src/eu/engys/core/project/SolverModelWriter.java @@ -1,48 +1,51 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project; +import eu.engys.core.project.system.ProjectDict; import eu.engys.core.project.system.RunDict; import eu.engys.util.Util; import eu.engys.util.connection.SshParameters; public class SolverModelWriter { - private Model model; + private SolverModel solverModel; - public SolverModelWriter(Model model) { - this.model = model; + public SolverModelWriter(SolverModel solverModel) { + this.solverModel = solverModel; } - void save() { - SshParameters sshParameters = model.getSolverModel().getSshParameters(); + void save(openFOAMProject project) { + SshParameters sshParameters = solverModel.getSshParameters(); encryptPassword(sshParameters); - RunDict runDict = new RunDict(model.getSolverModel()); - model.getProject().getSystemFolder().setRunDict(runDict); + RunDict runDict = new RunDict(solverModel); + if (project.getSystemFolder().getProjectDict() == null) { + project.getSystemFolder().setProjectDict(new ProjectDict()); + } + project.getSystemFolder().getProjectDict().setRunDict(runDict); decryptPassword(sshParameters); } diff --git a/src/eu/engys/core/project/SolverState.java b/src/eu/engys/core/project/SolverState.java index ec6ed83..8b67045 100644 --- a/src/eu/engys/core/project/SolverState.java +++ b/src/eu/engys/core/project/SolverState.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project; public enum SolverState { @@ -65,4 +64,4 @@ public enum SolverState { return this == STARTED || this == RUNNING || this == MESHING || this == INITIALISING; } -} +} \ No newline at end of file diff --git a/src/eu/engys/core/project/TurbulenceModel.java b/src/eu/engys/core/project/TurbulenceModel.java index 501569e..910e600 100644 --- a/src/eu/engys/core/project/TurbulenceModel.java +++ b/src/eu/engys/core/project/TurbulenceModel.java @@ -1,31 +1,33 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project; +import org.apache.commons.lang.builder.EqualsBuilder; +import org.apache.commons.lang.builder.HashCodeBuilder; + public class TurbulenceModel { private String name; @@ -37,21 +39,14 @@ public class TurbulenceModel { private TurbulenceModelType type; - public TurbulenceModel() { - } - - public TurbulenceModel(String name) { - this.name = name; - } - - public TurbulenceModel(String name, String description) { - this.name = name; - this.description = description; - } - public TurbulenceModel(String name, TurbulenceModelType type) { - this.name = name; - this.type = type; + this(name, name, type); + } + + public TurbulenceModel(String name, String description, TurbulenceModelType type) { + this.name = name; + this.type = type; + this.description = description; } public boolean isTrans() { @@ -74,10 +69,6 @@ public class TurbulenceModel { return name; } - public void setName(String name) { - this.name = name; - } - public String getDescription() { return description; } @@ -110,16 +101,30 @@ public class TurbulenceModel { return type; } + public static TurbulenceModel getPrototypeForDisplay(){ + return new TurbulenceModel("", "MMMMMMM", TurbulenceModelType.LAMINAR); + } + @Override public String toString() { return getName(); } + @Override public boolean equals(Object obj) { - if (obj instanceof TurbulenceModel) { - TurbulenceModel tm = (TurbulenceModel) obj; - return name == null? tm.name == null : name.equals(tm.name); - } else - return super.equals(obj); - }; + if (!(obj instanceof TurbulenceModel)) { + return false; + } + if (obj == this) { + return true; + } + TurbulenceModel fz = (TurbulenceModel) obj; + return new EqualsBuilder().append(name, fz.name).isEquals(); + } + + @Override + public int hashCode() { + return new HashCodeBuilder(17, 31).append(name).toHashCode(); + } + } diff --git a/src/eu/engys/core/project/TurbulenceModelType.java b/src/eu/engys/core/project/TurbulenceModelType.java index 85a49b6..7779ee3 100644 --- a/src/eu/engys/core/project/TurbulenceModelType.java +++ b/src/eu/engys/core/project/TurbulenceModelType.java @@ -1,32 +1,31 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project; public enum TurbulenceModelType { - K_Epsilon, K_Omega, Spalart_Allmaras, K_Equation_Eddy, LAMINAR; + K_Epsilon, K_Omega, Spalart_Allmaras, K_Equation_Eddy, Smagorinsky, LAMINAR; public boolean isSpalartAllmaras() { return equals(Spalart_Allmaras); @@ -47,4 +46,12 @@ public enum TurbulenceModelType { public boolean isLaminar() { return equals(LAMINAR); } -} + + public boolean isSmagorinsky() { + return equals(Smagorinsky); + } + + public boolean hasFields() { + return !isLaminar() && !isSmagorinsky(); + } +} \ No newline at end of file diff --git a/src/eu/engys/core/project/TurbulenceModels.java b/src/eu/engys/core/project/TurbulenceModels.java index e18cd31..ae81ab3 100644 --- a/src/eu/engys/core/project/TurbulenceModels.java +++ b/src/eu/engys/core/project/TurbulenceModels.java @@ -1,29 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project; import java.util.ArrayList; @@ -89,12 +87,10 @@ public class TurbulenceModels { } public static TurbulenceModel dictToTurbulenceModel(Dictionary m) { - TurbulenceModel tm = new TurbulenceModel(); - tm.setName(nameFromDictionary(m)); - tm.setDescription(descriptionFromDictionary(m)); - tm.setType(typeFromDictionary(m)); - - return tm; + String name = nameFromDictionary(m); + String description = descriptionFromDictionary(m); + TurbulenceModelType type = typeFromDictionary(m, name); + return new TurbulenceModel(name, description, type); } private static String nameFromDictionary(Dictionary m) { @@ -105,7 +101,7 @@ public class TurbulenceModels { return m.found("label") ? fromUnicode(m.lookup("label").replace("\"", "")) : m.getName(); } - private static TurbulenceModelType typeFromDictionary(Dictionary m) { + private static TurbulenceModelType typeFromDictionary(Dictionary m, String name) { Dictionary fieldMaps = m.subDict("fieldMaps"); if (fieldMaps == null) { return TurbulenceModelType.LAMINAR; @@ -117,6 +113,8 @@ public class TurbulenceModels { return TurbulenceModelType.Spalart_Allmaras; } else if (fieldMaps.isField(Fields.K) && fieldMaps.isField(Fields.NU_SGS)) { return TurbulenceModelType.K_Equation_Eddy; + } else if (name.contains("Smagorinsky")) { + return TurbulenceModelType.Smagorinsky; } else { return TurbulenceModelType.LAMINAR; } @@ -124,11 +122,8 @@ public class TurbulenceModels { public List getModelsForState(SolverType solverType, Method method, Flow flow) { if (solverType.isCoupled()) { - if (moduleModels.containsKey("coupled")) { - return moduleModels.get("coupled"); - } else { - return Collections.emptyList(); - } + String key = "coupled" + method.key(); + return moduleModels.containsKey(key) ? moduleModels.get(key) : Collections. emptyList(); } else if (solverType.isSegregated()) { if (flow.isCompressible()) { if (method.isRans()) { @@ -136,7 +131,7 @@ public class TurbulenceModels { } else if (method.isLes()) { return compressibleLES; } else { - return Collections.emptyList(); + return Collections. emptyList(); } } else if (flow.isIncompressible()) { if (method.isRans()) { @@ -144,17 +139,16 @@ public class TurbulenceModels { } else if (method.isLes()) { return incompressibleLES; } else { - return Collections.emptyList(); + return Collections. emptyList(); } } else { - return Collections.emptyList(); + return Collections. emptyList(); } } else { - return Collections.emptyList(); + return Collections. emptyList(); } - } - + private static final char[] NUMBERS = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' }; private static final char[] letters = { 'a', 'b', 'c', 'd', 'e', 'f' }; private static final char[] LETTERS = { 'A', 'B', 'C', 'D', 'E', 'F' }; diff --git a/src/eu/engys/core/project/constant/ConstantFolder.java b/src/eu/engys/core/project/constant/ConstantFolder.java index a58dbd3..cfad2cb 100644 --- a/src/eu/engys/core/project/constant/ConstantFolder.java +++ b/src/eu/engys/core/project/constant/ConstantFolder.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.constant; @@ -65,10 +64,9 @@ public class ConstantFolder implements Folder { private Dictionary g; private TurbulenceProperties turbulenceProperties; - private Dictionary RASProperties; - private Dictionary LESProperties; private TransportProperties transportProperties; private ThermophysicalProperties thermophysicalProperties; + private MRFProperties mrfProperties; private final FileManager fileManager; @@ -87,13 +85,9 @@ public class ConstantFolder implements Folder { setG(constantFolder.g); setTurbulenceProperties(constantFolder.turbulenceProperties); - setRASProperties(constantFolder.RASProperties); - setLESProperties(constantFolder.LESProperties); + setMrfProperties(constantFolder.mrfProperties); setTransportProperties(constantFolder.transportProperties); setThermophysicalProperties(constantFolder.thermophysicalProperties); - - // setPorousZones(constantFolder.porousZones); - // setMRFZones(constantFolder.MRFZones); } @Override @@ -108,6 +102,14 @@ public class ConstantFolder implements Folder { public void setG(Dictionary g) { this.g = g; } + + public MRFProperties getMrfProperties() { + return mrfProperties; + } + + public void setMrfProperties(Dictionary mrfProperties) { + this.mrfProperties = new MRFProperties(mrfProperties); + } public TurbulenceProperties getTurbulenceProperties() { return turbulenceProperties; @@ -117,22 +119,6 @@ public class ConstantFolder implements Folder { this.turbulenceProperties = new TurbulenceProperties(turbulenceProperties); } - public Dictionary getRASProperties() { - return RASProperties; - } - - public void setRASProperties(Dictionary rASProperties) { - RASProperties = rASProperties; - } - - public Dictionary getLESProperties() { - return LESProperties; - } - - public void setLESProperties(Dictionary lESProperties) { - LESProperties = lESProperties; - } - public TransportProperties getTransportProperties() { return transportProperties; } @@ -160,31 +146,23 @@ public class ConstantFolder implements Folder { public List getAllDictionaries() { List dictionaries = new ArrayList<>(); dictionaries.add(getG()); - dictionaries.add(getLESProperties()); - dictionaries.add(getRASProperties()); dictionaries.add(getThermophysicalProperties()); dictionaries.add(getTransportProperties()); dictionaries.add(getTurbulenceProperties()); + dictionaries.add(getMrfProperties()); return dictionaries; } public void write(Model model, MaterialsWriter materialsWriter, ProgressMonitor monitor) { - model.getMaterials().saveMaterials(model, materialsWriter); - File constDir = fileManager.getFile(); if (!constDir.exists()) constDir.mkdir(); DictionaryUtils.writeDictionary(constDir, DictionaryUtils.header(CONSTANT, turbulenceProperties), monitor); + DictionaryUtils.writeDictionary(constDir, DictionaryUtils.header(CONSTANT, mrfProperties), monitor); + State state = model.getState(); - if (state.isLES()) { - DictionaryUtils.writeDictionary(constDir, DictionaryUtils.header(CONSTANT, LESProperties), monitor); - DictionaryUtils.removeDictionary(constDir, DictionaryUtils.header(CONSTANT, RASProperties), monitor); - } else if (state.isRANS()) { - DictionaryUtils.writeDictionary(constDir, DictionaryUtils.header(CONSTANT, RASProperties), monitor); - DictionaryUtils.removeDictionary(constDir, DictionaryUtils.header(CONSTANT, LESProperties), monitor); - } if (state.isCompressible() && !state.getMultiphaseModel().isMultiphase()) { DictionaryUtils.writeDictionary(constDir, DictionaryUtils.header(CONSTANT, thermophysicalProperties), monitor); @@ -204,11 +182,10 @@ public class ConstantFolder implements Folder { } - public void load(Model model, ProgressMonitor monitor) { + public void read(Model model, ProgressMonitor monitor) { if (fileManager.getFile().exists() && fileManager.getFile().isDirectory()) { + setMrfProperties(DictionaryUtils.readDictionary(fileManager.getFile(MRFProperties.MRF_PROPERTIES), monitor)); setTurbulenceProperties(DictionaryUtils.readDictionary(fileManager.getFile(TurbulenceProperties.TURBULENCE_PROPERTIES), monitor)); - setRASProperties(DictionaryUtils.readDictionary(fileManager.getFile(RAS_PROPERTIES), monitor)); - setLESProperties(DictionaryUtils.readDictionary(fileManager.getFile(LES_PROPERTIES), monitor)); setThermophysicalProperties(DictionaryUtils.readDictionary(fileManager.getFile(ThermophysicalProperties.THERMOPHYSICAL_PROPERTIES), monitor)); setTransportProperties(DictionaryUtils.readDictionary(fileManager.getFile(TransportProperties.TRANSPORT_PROPERTIES), monitor)); setG(DictionaryUtils.readDictionary(fileManager.getFile(G), monitor)); diff --git a/src/eu/engys/core/project/constant/MRFProperties.java b/src/eu/engys/core/project/constant/MRFProperties.java new file mode 100644 index 0000000..18dde66 --- /dev/null +++ b/src/eu/engys/core/project/constant/MRFProperties.java @@ -0,0 +1,49 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.core.project.constant; + +import eu.engys.core.dictionary.Dictionary; +import eu.engys.core.dictionary.DictionaryException; +import eu.engys.core.dictionary.FoamFile; + +public class MRFProperties extends Dictionary { + + public static final String MRF_PROPERTIES = "MRFProperties"; + + public MRFProperties() { + super(MRF_PROPERTIES); + setFoamFile(FoamFile.getDictionaryFoamFile(ConstantFolder.CONSTANT, MRF_PROPERTIES)); + } + + public MRFProperties(Dictionary mrfProperties) { + this(); + merge(mrfProperties); + setFoamFile(FoamFile.getDictionaryFoamFile(ConstantFolder.CONSTANT, MRF_PROPERTIES)); + } + + @Override + public void check() throws DictionaryException { + } +} diff --git a/src/eu/engys/core/project/constant/PolyMeshFolder.java b/src/eu/engys/core/project/constant/PolyMeshFolder.java index 69c9a5c..db552fa 100644 --- a/src/eu/engys/core/project/constant/PolyMeshFolder.java +++ b/src/eu/engys/core/project/constant/PolyMeshFolder.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.constant; diff --git a/src/eu/engys/core/project/constant/ThermophysicalProperties.java b/src/eu/engys/core/project/constant/ThermophysicalProperties.java index 1eb7401..f81a0e4 100644 --- a/src/eu/engys/core/project/constant/ThermophysicalProperties.java +++ b/src/eu/engys/core/project/constant/ThermophysicalProperties.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.constant; import eu.engys.core.dictionary.Dictionary; @@ -31,6 +30,8 @@ import eu.engys.core.dictionary.FoamFile; public class ThermophysicalProperties extends Dictionary { public static final String THERMOPHYSICAL_PROPERTIES = "thermophysicalProperties"; + + public static final String TYPE_KEY = "type"; // Thermophysical Model public static final String MATERIAL_NAME_KEY = "materialName"; @@ -43,13 +44,6 @@ public class ThermophysicalProperties extends Dictionary { // Equation of State - public static final String EQUATION_OF_STATE_KEY = "equationOfState"; - public static final String ADIABATIC_PERFECT_FLUID_KEY = "adiabaticPerfectFluid"; - public static final String RHO_CONSTANT_KEY = "rhoConst"; - public static final String PERFECT_GAS_KEY = "perfectGas"; - public static final String PERFECT_FLUID_KEY = "perfectFluid"; - public static final String ICO_POLYNOMIAL_KEY = "icoPolynomial"; - public static final String INCOMPRESSIBLE_KEY = "incompressiblePerfectGas"; public static final String P_REF_KEY = "pRef"; public static final String RHO_COEFFS_KEY = "rhoCoeffs"; public static final String R_KEY = "R"; @@ -59,6 +53,14 @@ public class ThermophysicalProperties extends Dictionary { public static final String B_KEY = "B"; public static final String RHO0_KEY = "rho0"; + public static final String EQUATION_OF_STATE_KEY = "equationOfState"; + public static final String ADIABATIC_PERFECT_FLUID_KEY = "adiabaticPerfectFluid"; + public static final String PERFECT_GAS_KEY = "perfectGas"; + public static final String PERFECT_FLUID_KEY = "perfectFluid"; + public static final String EQUATION_CONSTANT_KEY = "rhoConst"; + public static final String INCOMPRESSIBLE_KEY = "incompressiblePerfectGas"; + public static final String EQUATION_POLYNOMIAL_KEY = "icoPolynomial"; + // Transport Properties public static final String TS_KEY = "Ts"; public static final String AS_KEY = "As"; @@ -66,7 +68,6 @@ public class ThermophysicalProperties extends Dictionary { public static final String PRT_KEY = "Prt"; public static final String MU_KEY = "mu"; public static final String NU_KEY = "nu"; - public static final String TRANSPORT_KEY = "transport"; public static final String TRANSPORT_MODEL_KEY = "transportModel"; public static final String MIXTURE_KEY = "mixture"; public static final String PURE_MIXTURE_KEY = "pureMixture"; @@ -76,6 +77,11 @@ public class ThermophysicalProperties extends Dictionary { public static final String MU_COEFFS_KEY = "muCoeffs"; public static final String KAPPA_COEFFS_KEY = "kappaCoeffs"; + public static final String TRANSPORT_KEY = "transport"; + public static final String TRANSPORT_CONST_KEY = "const"; + public static final String TRANSPORT_SUTHERLAND_KEY = "sutherland"; + public static final String TRANSPORT_POLYNOMIAL_KEY = "polynomial"; + // Thermodynamic Model public static final String THERMO_TYPE_KEY = "thermoType"; public static final String THERMO_MODEL_KEY = "thermoModel"; @@ -91,18 +97,16 @@ public class ThermophysicalProperties extends Dictionary { public static final String SF_KEY = "Sf"; public static final String CP_KEY = "Cp"; public static final String T_REF_KEY = "TRef"; - public static final String BETA_OS_KEY = "beta"; - public static final String BETA_KEY = "Beta"; public static final String LAMBDA_KEY = "lambda"; public static final String THERMO_KEY = "thermo"; - public static final String CONST_KEY = "const"; - public static final String POLYNOMIAL_KEY = "polynomial"; - public static final String SUTHERLAND_KEY = "sutherland"; - public static final String CONSTANT_CP_KEY = "hConst"; - public static final String JANAF_KEY = "janaf"; - public static final String H_POLYNOMIAL_KEY = "hPolynomial"; + public static final String THERMO_CONST_KEY = "hConst"; + public static final String THERMO_JANAF_KEY = "janaf"; + public static final String THERMO_POLYNOMIAL_KEY = "hPolynomial"; + + public static final String[] A_KEYS = new String[] { "a0", "a1", "a2", "a3", "a4", "a5", "a6" }; + public static final int COEFFICIENTS_NUMBER = 8; public ThermophysicalProperties() { super(THERMOPHYSICAL_PROPERTIES); diff --git a/src/eu/engys/core/project/constant/TransportProperties.java b/src/eu/engys/core/project/constant/TransportProperties.java index c1da958..39208cc 100644 --- a/src/eu/engys/core/project/constant/TransportProperties.java +++ b/src/eu/engys/core/project/constant/TransportProperties.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.constant; import eu.engys.core.dictionary.Dictionary; @@ -61,7 +60,7 @@ public class TransportProperties extends Dictionary { public static final String CP_KEY = "Cp"; public static final String CP0_KEY = "Cp0"; public static final String RHO_KEY = "rho"; - public static final String RHO_CP0_KEY = "rhoCp0"; + public static final String RHO_CP_KEY = "rhoCp0"; public static final String KAPPA_KEY = "kappa"; public static final String PR_KEY = "Pr"; public static final String PRT_KEY = "Prt"; @@ -71,7 +70,6 @@ public class TransportProperties extends Dictionary { public static final String BETA_KEY = "Beta"; public static final String P_REF_KEY = "pRef"; - //Non newtonian coeffs public static final String NU_0_KEY = "nu0"; public static final String NU_INF_KEY = "nuInf"; diff --git a/src/eu/engys/core/project/constant/TriSurfaceFolder.java b/src/eu/engys/core/project/constant/TriSurfaceFolder.java index a15ad75..775449d 100644 --- a/src/eu/engys/core/project/constant/TriSurfaceFolder.java +++ b/src/eu/engys/core/project/constant/TriSurfaceFolder.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.constant; diff --git a/src/eu/engys/core/project/constant/TurbulenceProperties.java b/src/eu/engys/core/project/constant/TurbulenceProperties.java index 35a74ca..19582ad 100644 --- a/src/eu/engys/core/project/constant/TurbulenceProperties.java +++ b/src/eu/engys/core/project/constant/TurbulenceProperties.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.constant; import eu.engys.core.dictionary.Dictionary; @@ -32,10 +31,17 @@ public class TurbulenceProperties extends Dictionary { public static final String TURBULENCE_PROPERTIES = "turbulenceProperties"; - public static final String SIMULATION_TYPE = "simulationType"; - public static final String RAS = "RAS"; - public static final String LES = "LES"; - public static final String LAMINAR = "laminar"; + public static final String SIMULATION_TYPE_KEY = "simulationType"; + public static final String RAS_KEY = "RAS"; + public static final String LES_KEY = "LES"; + public static final String RAS_MODEL_KEY = "RASModel"; + public static final String LES_MODEL_KEY = "LESModel"; + public static final String LAMINAR_KEY = "laminar"; + + public static final String PRINT_COEFFS_KEY = "printCoeffs"; + public static final String TURBULENCE_KEY = "turbulence"; + public static final String DELTA_KEY = "delta"; + public static final String DELTA1_KEY = "delta1"; public static final String FIELD_MAPS_KEY = "fieldMaps"; @@ -49,4 +55,4 @@ public class TurbulenceProperties extends Dictionary { merge(turbulenceProperties); setFoamFile(FoamFile.getDictionaryFoamFile(ConstantFolder.CONSTANT, TURBULENCE_PROPERTIES)); } -} +} \ No newline at end of file diff --git a/src/eu/engys/core/project/custom/Custom.java b/src/eu/engys/core/project/custom/Custom.java index 71f6acf..6c5f4e0 100644 --- a/src/eu/engys/core/project/custom/Custom.java +++ b/src/eu/engys/core/project/custom/Custom.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.custom; import java.io.File; @@ -160,6 +159,7 @@ public class Custom { constant.write(model, monitor); zero.write(model, monitor); logger.info("-----------------"); + model.customChanged(); } public void saveCustomDict(Model model) { diff --git a/src/eu/engys/core/project/custom/CustomFile.java b/src/eu/engys/core/project/custom/CustomFile.java index 60a20e0..265214b 100644 --- a/src/eu/engys/core/project/custom/CustomFile.java +++ b/src/eu/engys/core/project/custom/CustomFile.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.custom; import static eu.engys.core.project.system.ControlDict.CONTROL_DICT; @@ -45,7 +44,7 @@ import eu.engys.core.dictionary.FoamFile; import eu.engys.core.project.Model; import eu.engys.core.project.system.ControlDict; import eu.engys.core.project.zero.fields.Field; -import eu.engys.util.LineSeparator; +import eu.engys.util.IOUtils; import eu.engys.util.Util; import eu.engys.util.progress.ProgressMonitor; import eu.engys.util.ui.UiUtil; @@ -153,12 +152,12 @@ public class CustomFile { public String toString() { return name; } - + public void setChanged(boolean changed) { this.changed = changed; } - - public boolean hasChanged(){ + + public boolean hasChanged() { return changed; } @@ -181,7 +180,7 @@ public class CustomFile { if (!f.exists()) { f.createNewFile(); } - String lineEnding = Util.isWindowsScriptStyle() ? LineSeparator.DOS.getSeparator() : LineSeparator.UNIX.getSeparator(); + String lineEnding = Util.isWindowsScriptStyle() ? IOUtils.WIN_EOL : IOUtils.LNX_EOL; FileUtils.writeLines(f, null, rawFileContent, lineEnding); } catch (IOException e) { logger.error("Cannot create new raw file: " + f); diff --git a/src/eu/engys/core/project/custom/CustomFileType.java b/src/eu/engys/core/project/custom/CustomFileType.java index b087a6e..b7a1ff3 100644 --- a/src/eu/engys/core/project/custom/CustomFileType.java +++ b/src/eu/engys/core/project/custom/CustomFileType.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.custom; public enum CustomFileType { diff --git a/src/eu/engys/core/project/custom/CustomUtils.java b/src/eu/engys/core/project/custom/CustomUtils.java index d4e63b7..7794675 100644 --- a/src/eu/engys/core/project/custom/CustomUtils.java +++ b/src/eu/engys/core/project/custom/CustomUtils.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.custom; import java.io.File; @@ -33,8 +32,6 @@ import java.util.ArrayList; import java.util.List; import org.apache.commons.io.FileUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import eu.engys.core.dictionary.Dictionary; import eu.engys.core.project.Model; @@ -48,8 +45,6 @@ import eu.engys.core.project.zero.fields.FieldReader; public class CustomUtils { - private static final Logger logger = LoggerFactory.getLogger(CustomUtils.class); - public static List getFiles(Model model, CustomFile customFile) { openFOAMProject project = model.getProject(); List files = new ArrayList<>(); @@ -122,8 +117,8 @@ public class CustomUtils { } } - private static Dictionary getCleanBoundaryField(Field field) { - Dictionary boundaryField = field.getBoundaryField(); + public static Dictionary getCleanBoundaryField(Field field) { + Dictionary boundaryField = new Dictionary(field.getBoundaryField()); List toRemoveList = new ArrayList<>(); if (boundaryField != null) { for (Dictionary dict : boundaryField.getDictionaries()) { diff --git a/src/eu/engys/core/project/defaults/AbstractDefaultsProvider.java b/src/eu/engys/core/project/defaults/AbstractDefaultsProvider.java index 5a56a81..25e3f78 100644 --- a/src/eu/engys/core/project/defaults/AbstractDefaultsProvider.java +++ b/src/eu/engys/core/project/defaults/AbstractDefaultsProvider.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.defaults; import java.util.Map; @@ -36,6 +35,8 @@ import eu.engys.util.Util; public abstract class AbstractDefaultsProvider implements DefaultsProvider { + public static final String FIELD_MAPS = "fieldMaps"; + private static final Logger logger = LoggerFactory.getLogger(AbstractDefaultsProvider.class); @Override @@ -55,9 +56,9 @@ public abstract class AbstractDefaultsProvider implements DefaultsProvider { @Override public Dictionary getDefaultsFieldMapsFor(State state, String region) { if (region != null) { - return getDefaultsFor(state).subDict("fieldMaps"+"."+region); + return getDefaultsFor(state).subDict(FIELD_MAPS+"."+region); } else { - return getDefaultsFor(state).subDict("fieldMaps"); + return getDefaultsFor(state).subDict(FIELD_MAPS); } } diff --git a/src/eu/engys/core/project/defaults/DefaultDictDataFolder.java b/src/eu/engys/core/project/defaults/DefaultDictDataFolder.java index 999c917..bfc87b6 100644 --- a/src/eu/engys/core/project/defaults/DefaultDictDataFolder.java +++ b/src/eu/engys/core/project/defaults/DefaultDictDataFolder.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.defaults; diff --git a/src/eu/engys/core/project/defaults/Defaults.java b/src/eu/engys/core/project/defaults/Defaults.java index aed40a7..a788874 100644 --- a/src/eu/engys/core/project/defaults/Defaults.java +++ b/src/eu/engys/core/project/defaults/Defaults.java @@ -1,29 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.defaults; import javax.inject.Inject; @@ -34,109 +32,115 @@ import eu.engys.core.dictionary.Dictionary; import eu.engys.core.project.system.BlockMeshDict; import eu.engys.core.project.system.MapFieldsDict; import eu.engys.core.project.system.SnappyHexMeshDict; +import eu.engys.core.project.system.StretchMeshDict; public class Defaults extends AbstractDefaultsProvider { - private DictDataFolder dictDataFolder; - private Dictionary defaultsDictionary; + private DictDataFolder dictDataFolder; + private Dictionary defaultsDictionary; - @Inject - public Defaults(DictDataFolder folder) { - this.dictDataFolder = folder; - this.defaultsDictionary = new Dictionary(folder.getFile("caseSetupDict.defaults")).subDict("defaults"); - LoggerFactory.getLogger(Defaults.class).info("-> Defaults"); - } + @Inject + public Defaults(DictDataFolder folder) { + this.dictDataFolder = folder; + this.defaultsDictionary = new Dictionary(folder.getFile("caseSetupDict.defaults")).subDict("defaults"); + LoggerFactory.getLogger(Defaults.class).info("-> Defaults"); + } - @Override - public String getName() { - return "Main"; - } + @Override + public String getName() { + return "Main"; + } - public DictDataFolder getDictDataFolder() { - return dictDataFolder; - } + public DictDataFolder getDictDataFolder() { + return dictDataFolder; + } - private Dictionary getDefaultsDict() { - return defaultsDictionary; - } + private Dictionary getDefaultsDict() { + return defaultsDictionary; + } - @Override - public Dictionary getStates() { - return getDefaultsDict().subDict("states"); - } + @Override + public Dictionary getStates() { + return getDefaultsDict().subDict("states"); + } - @Override - public Dictionary getDefaultStateData() { - return getDefaultsDict().subDict("stateData"); - } + @Override + public Dictionary getDefaultStateData() { + return getDefaultsDict().subDict("stateData"); + } - @Override - public Dictionary getDefaultFieldsData() { - return getDefaultsDict().subDict("fields"); - } + @Override + public Dictionary getDefaultFieldsData() { + return getDefaultsDict().subDict("fields"); + } - public Dictionary getCompressibleMaterials() { - return new Dictionary(dictDataFolder.getFile("caseSetupDict.materialProperties.compressible")).subDict("materialProperties"); - } + public Dictionary getCompressibleMaterials() { + return new Dictionary(dictDataFolder.getFile("caseSetupDict.materialProperties.compressible")).subDict("materialProperties"); + } - public Dictionary getIncompressibleMaterials() { - return new Dictionary(dictDataFolder.getFile("caseSetupDict.materialProperties.incompressible")).subDict("materialProperties"); - } + public Dictionary getIncompressibleMaterials() { + return new Dictionary(dictDataFolder.getFile("caseSetupDict.materialProperties.incompressible")).subDict("materialProperties"); + } - @Override - public Dictionary getDefaultTurbulenceProperties() { - return getDefaultsDict().subDict("turbulenceProperties"); - } + @Override + public Dictionary getDefaultTurbulenceProperties() { + return getDefaultsDict().subDict("turbulenceProperties"); + } - public Dictionary getDefaultFunctions() { - return getDefaultsDict().subDict("functions"); - } + public Dictionary getDefaultFunctions() { + return getDefaultsDict().subDict("functions"); + } - public Dictionary getDefaultSchemes() { - return getDefaultsDict().subDict("schemes"); - } + public Dictionary getDefaultSchemes() { + return getDefaultsDict().subDict("schemes"); + } - public SnappyHexMeshDict getDefaultSnappyHexMeshDict() { - return new SnappyHexMeshDict(dictDataFolder.getFile("createCase.snappyHexMeshDict")); - } + public SnappyHexMeshDict getDefaultSnappyHexMeshDict() { + return new SnappyHexMeshDict(dictDataFolder.getFile("createCase.snappyHexMeshDict")); + } - public BlockMeshDict getDefaultBlockMeshDict() { - return new BlockMeshDict(dictDataFolder.getFile("createCase.blockMeshDict")); - } + public Dictionary getDefaultStretchMeshDict() { + return new StretchMeshDict(dictDataFolder.getFile("createCase.stretchMeshDict")); + } - public Dictionary getDefaultFvSchemes() { - return new Dictionary(dictDataFolder.getFile("createCase.fvSchemes")); - } + public BlockMeshDict getDefaultBlockMeshDict() { + return new BlockMeshDict(dictDataFolder.getFile("createCase.blockMeshDict")); + } - public Dictionary getDefaultFvSolution() { - return new Dictionary(dictDataFolder.getFile("createCase.fvSolution")); - } + public Dictionary getDefaultFvSchemes() { + return new Dictionary(dictDataFolder.getFile("createCase.fvSchemes")); + } - public Dictionary getDefaultFvOptions() { - return new Dictionary(""); - } + public Dictionary getDefaultFvSolution() { + return new Dictionary(dictDataFolder.getFile("createCase.fvSolution")); + } - public Dictionary getDefaultControlDict() { - return new Dictionary(dictDataFolder.getFile("createCase.controlDict")); - } + public Dictionary getDefaultFvOptions() { + return new Dictionary(""); + } - public Dictionary getDefaultRunDict() { - return new Dictionary(dictDataFolder.getFile("createCase.runDict")); - } - public MapFieldsDict getDefaultMapFieldsDict() { - return new MapFieldsDict(dictDataFolder.getFile("createCase.mapFieldsDict")); - } + public Dictionary getDefaultControlDict() { + return new Dictionary(dictDataFolder.getFile("createCase.controlDict")); + } - public Dictionary getDefaultDecomposeParDict() { - return new Dictionary(dictDataFolder.getFile("createCase.decomposeParDict")); - } + public Dictionary getDefaultRunDict() { + return new Dictionary(dictDataFolder.getFile("createCase.runDict")); + } - public Dictionary getDefaultCustomNodeDict() { - return new Dictionary(dictDataFolder.getFile("createCase.customNodeDict")); - } + public MapFieldsDict getDefaultMapFieldsDict() { + return new MapFieldsDict(dictDataFolder.getFile("createCase.mapFieldsDict")); + } - public Dictionary getDefaultShapes() { - return new Dictionary(dictDataFolder.getFile("createCase.shapes")); - } + public Dictionary getDefaultDecomposeParDict() { + return new Dictionary(dictDataFolder.getFile("createCase.decomposeParDict")); + } + + public Dictionary getDefaultCustomNodeDict() { + return new Dictionary(dictDataFolder.getFile("createCase.customNodeDict")); + } + + public Dictionary getDefaultShapes() { + return new Dictionary(dictDataFolder.getFile("createCase.shapes")); + } } diff --git a/src/eu/engys/core/project/defaults/DefaultsProvider.java b/src/eu/engys/core/project/defaults/DefaultsProvider.java index 4a14a9c..71a619a 100644 --- a/src/eu/engys/core/project/defaults/DefaultsProvider.java +++ b/src/eu/engys/core/project/defaults/DefaultsProvider.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.defaults; diff --git a/src/eu/engys/core/project/defaults/DictDataFolder.java b/src/eu/engys/core/project/defaults/DictDataFolder.java index 70df012..4d3818a 100644 --- a/src/eu/engys/core/project/defaults/DictDataFolder.java +++ b/src/eu/engys/core/project/defaults/DictDataFolder.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.defaults; diff --git a/src/eu/engys/core/project/defaults/JarDictDataFolder.java b/src/eu/engys/core/project/defaults/JarDictDataFolder.java index e84360e..5ae4fac 100644 --- a/src/eu/engys/core/project/defaults/JarDictDataFolder.java +++ b/src/eu/engys/core/project/defaults/JarDictDataFolder.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.defaults; import java.io.File; @@ -36,7 +35,6 @@ import java.nio.file.Paths; import javax.inject.Inject; import javax.inject.Named; -import org.apache.commons.io.FileUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -83,12 +81,13 @@ public class JarDictDataFolder implements DictDataFolder { } public void extractToTemp() { +// this.dictDataFolder = new File(new File(TempFolder.getTempFolder(), "dictData"), applicationFolder); this.dictDataFolder = TempFolder.get("dictData", applicationFolder); - if (dictDataFolder.exists()) { - FileUtils.deleteQuietly(dictDataFolder); - } - logger.info("Extract to temp"); - dictDataFolder.mkdirs(); +// if (dictDataFolder.exists()) { +// FileUtils.deleteQuietly(dictDataFolder); +// } + logger.info("Extract to temporary folder: {}", dictDataFolder); +// dictDataFolder.mkdirs(); Path pathToLibFile = Paths.get(getRootPath(), "lib", applicationFolder+"-data.jar"); if (Files.exists(pathToLibFile)) { logger.info("Extract to temp: File is {}", pathToLibFile); diff --git a/src/eu/engys/core/project/files/DefaultFileManager.java b/src/eu/engys/core/project/files/DefaultFileManager.java index 699c5c4..80306cd 100644 --- a/src/eu/engys/core/project/files/DefaultFileManager.java +++ b/src/eu/engys/core/project/files/DefaultFileManager.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.files; @@ -40,7 +39,7 @@ import eu.engys.util.Util; public class DefaultFileManager implements FileManager { - protected static final Logger logger = LoggerFactory.getLogger(Folder.class); + private static final Logger logger = LoggerFactory.getLogger(DefaultFileManager.class); private File file; diff --git a/src/eu/engys/core/project/files/FileManager.java b/src/eu/engys/core/project/files/FileManager.java index 457b9ee..c65a9ac 100644 --- a/src/eu/engys/core/project/files/FileManager.java +++ b/src/eu/engys/core/project/files/FileManager.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.files; diff --git a/src/eu/engys/core/project/files/Folder.java b/src/eu/engys/core/project/files/Folder.java index af9ec47..fbd4057 100644 --- a/src/eu/engys/core/project/files/Folder.java +++ b/src/eu/engys/core/project/files/Folder.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.files; diff --git a/src/eu/engys/core/project/geometry/BlockReader.java b/src/eu/engys/core/project/geometry/BlockReader.java index b12a5ed..42c3e19 100644 --- a/src/eu/engys/core/project/geometry/BlockReader.java +++ b/src/eu/engys/core/project/geometry/BlockReader.java @@ -1,34 +1,30 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.geometry; -import static eu.engys.core.project.geometry.Surface.MAX_KEY; -import static eu.engys.core.project.geometry.Surface.MIN_KEY; import static eu.engys.core.project.system.BlockMeshDict.BLOCKS_KEY; -import static eu.engys.core.project.system.BlockMeshDict.ELEMENTS_KEY; import static eu.engys.core.project.system.BlockMeshDict.PATCHES_KEY; import static eu.engys.core.project.system.BlockMeshDict.VERTICES_KEY; import static eu.engys.core.project.system.SnappyHexMeshDict.ADD_LAYERS_CONTROLS_KEY; @@ -47,9 +43,9 @@ import eu.engys.core.project.system.SnappyHexMeshDict; public class BlockReader { - private static final String DEFAULT_MAX_VALUE = "(1 1 1)"; - private static final String DEFAULT_MIN_VALUE = "(-1 -1 -1)"; - private static final String DEFAULT_ELEMENTS_VALUE = "(10 10 10)"; +// private static final String DEFAULT_MAX_VALUE = "(1 1 1)"; +// private static final String DEFAULT_MIN_VALUE = "(-1 -1 -1)"; +// private static final String DEFAULT_ELEMENTS_VALUE = "(10 10 10)"; private Geometry geometry; public BlockReader(Geometry geometry) { @@ -60,23 +56,24 @@ public class BlockReader { * Here the user has selected a block mesh of type: user defined. I need to load the data from blockMeshDict to visualise the block. */ public MultiPlane loadBlock(BlockMeshDict blockMeshDict, SnappyHexMeshDict snappyHexMeshDict) { - Dictionary blockDict = new Dictionary("block"); - MultiPlane block = null; - loadBlocksFromBlockMeshDict(blockMeshDict, blockDict); - loadVerticesFromBlockMeshDict(blockMeshDict, blockDict); + MultiPlane block = new MultiPlane("BoundingBox"); + loadBlocksFromBlockMeshDict(blockMeshDict, block); + loadVerticesFromBlockMeshDict(blockMeshDict, block); + if (blockMeshDict.found(PATCHES_KEY)) { ListField2 patches = blockMeshDict.getList2(PATCHES_KEY); String[] patchesList = extractPatches(patches); if (patchesList.length == 6) { - block = loadPatches(patchesList, blockDict); + loadPatches(patchesList, block); } else { - block = loadDefaultPatches(); + loadDefaultPatches(block); } } else { - block = loadDefaultPatches(); + loadDefaultPatches(block); } - block.setGeometryDictionary(blockDict); - + + block.updatePlanes(); + loadLayers(snappyHexMeshDict, block); geometry.setBlock(block); geometry.setCellSize(block.getDelta()); @@ -84,63 +81,50 @@ public class BlockReader { } /* - * Patches + * Blocks */ - private MultiPlane loadPatches(String[] patchesList, Dictionary blockDict) { - MultiPlane block = new MultiPlane("BoundingBox"); - for (int i = 0; i < patchesList.length; i++) { - blockDict.add("patch" + i, patchesList[i]); - block.addPlane(patchesList[i]); + private void loadBlocksFromBlockMeshDict(BlockMeshDict blockMeshDict, MultiPlane block) { + if (blockMeshDict.found(BLOCKS_KEY)) { + ListField2 blocks = blockMeshDict.getList2(BLOCKS_KEY); + block.setElements(extractElements(blocks)); + } else { + block.setElements(MultiPlane.DEFAULT_ELEMENTS); } - return block; - } - - private MultiPlane loadDefaultPatches() { - MultiPlane block = new MultiPlane("BoundingBox"); - block.addPlane("ffminx"); - block.addPlane("ffmaxx"); - block.addPlane("ffminy"); - block.addPlane("ffmaxy"); - block.addPlane("ffminz"); - block.addPlane("ffmaxz"); - return block; } /* * Vertices */ - private void loadVerticesFromBlockMeshDict(BlockMeshDict blockMeshDict, Dictionary d) { + private void loadVerticesFromBlockMeshDict(BlockMeshDict blockMeshDict, MultiPlane block) { if (blockMeshDict.found(VERTICES_KEY)) { ListField2 vertices = blockMeshDict.getList2(VERTICES_KEY); - d.add(MIN_KEY, extractMin(vertices)); - d.add(MAX_KEY, extractMax(vertices)); + block.setMin(extractMin(vertices)); + block.setMax(extractMax(vertices)); } else { - loadDefaultVertices(d); + block.setMin(MultiPlane.DEFAULT_MIN); + block.setMax(MultiPlane.DEFAULT_MAX); } } - private void loadDefaultVertices(Dictionary d) { - d.add(MIN_KEY, DEFAULT_MIN_VALUE); - d.add(MAX_KEY, DEFAULT_MAX_VALUE); - } - /* - * Blocks + * Patches */ - private void loadBlocksFromBlockMeshDict(BlockMeshDict blockMeshDict, Dictionary d) { - if (blockMeshDict.found(BLOCKS_KEY)) { - ListField2 blocks = blockMeshDict.getList2(BLOCKS_KEY); - d.add(ELEMENTS_KEY, extractElements(blocks)); - } else { - loadDefaultBlocks(d); + private void loadPatches(String[] patchesList, MultiPlane block) { + for (int i = 0; i < patchesList.length; i++) { + block.addPlane(patchesList[i]); } } - private void loadDefaultBlocks(Dictionary d) { - d.add(ELEMENTS_KEY, DEFAULT_ELEMENTS_VALUE); + private void loadDefaultPatches(MultiPlane block) { + block.addPlane("ffminx"); + block.addPlane("ffmaxx"); + block.addPlane("ffminy"); + block.addPlane("ffmaxy"); + block.addPlane("ffminz"); + block.addPlane("ffmaxz"); } private void loadLayers(SnappyHexMeshDict snappyHexMeshDict, MultiPlane block) { @@ -158,54 +142,54 @@ public class BlockReader { * Utils */ - private String extractElements(ListField2 blocks) { + public static int[] extractElements(ListField2 blocks) { if (blocks.isEmpty()) { - return DEFAULT_ELEMENTS_VALUE; + return MultiPlane.DEFAULT_ELEMENTS; } else { - StringBuffer sb = new StringBuffer("("); ListField2 element = (ListField2) blocks.getListElements().get(2); FieldElement x = ((FieldElement) element.getListElements().get(0)); FieldElement y = ((FieldElement) element.getListElements().get(1)); FieldElement z = ((FieldElement) element.getListElements().get(2)); - sb.append(x.getValue() + " "); - sb.append(y.getValue() + " "); - sb.append(z.getValue() + " "); - sb.append(")"); - return sb.toString(); + + int ix = Integer.parseInt(x.getValue()); + int iy = Integer.parseInt(y.getValue()); + int iz = Integer.parseInt(z.getValue()); + + return new int[] {ix, iy, iz}; } } - private String extractMin(ListField2 vertices) { + public static double[] extractMin(ListField2 vertices) { if (vertices.isEmpty()) { - return DEFAULT_MIN_VALUE; + return MultiPlane.DEFAULT_MIN; } else { - StringBuffer sb = new StringBuffer("("); ListField2 firstElement = (ListField2) vertices.getListElements().get(0); FieldElement x = ((FieldElement) firstElement.getListElements().get(0)); FieldElement y = ((FieldElement) firstElement.getListElements().get(1)); FieldElement z = ((FieldElement) firstElement.getListElements().get(2)); - sb.append(x.getValue() + " "); - sb.append(y.getValue() + " "); - sb.append(z.getValue() + " "); - sb.append(")"); - return sb.toString(); + + double dx = Double.parseDouble(x.getValue()); + double dy = Double.parseDouble(y.getValue()); + double dz = Double.parseDouble(z.getValue()); + + return new double[] {dx, dy, dz}; } } - private String extractMax(ListField2 vertices) { + public static double[] extractMax(ListField2 vertices) { if (vertices.isEmpty()) { - return DEFAULT_MAX_VALUE; + return MultiPlane.DEFAULT_MAX; } else { - StringBuffer sb = new StringBuffer("("); ListField2 firstElement = (ListField2) vertices.getListElements().get(vertices.getListElements().size() - 2); FieldElement x = ((FieldElement) firstElement.getListElements().get(0)); FieldElement y = ((FieldElement) firstElement.getListElements().get(1)); FieldElement z = ((FieldElement) firstElement.getListElements().get(2)); - sb.append(x.getValue() + " "); - sb.append(y.getValue() + " "); - sb.append(z.getValue() + " "); - sb.append(")"); - return sb.toString(); + + double dx = Double.parseDouble(x.getValue()); + double dy = Double.parseDouble(y.getValue()); + double dz = Double.parseDouble(z.getValue()); + + return new double[] {dx, dy, dz}; } } diff --git a/src/eu/engys/core/project/geometry/BlockSaver.java b/src/eu/engys/core/project/geometry/BlockSaver.java index c363a4a..2dc0861 100644 --- a/src/eu/engys/core/project/geometry/BlockSaver.java +++ b/src/eu/engys/core/project/geometry/BlockSaver.java @@ -1,61 +1,57 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.geometry; -import static eu.engys.core.project.geometry.Surface.MAX_KEY; -import static eu.engys.core.project.geometry.Surface.MIN_KEY; import static eu.engys.core.project.system.BlockMeshDict.BLOCKS_KEY; -import static eu.engys.core.project.system.BlockMeshDict.ELEMENTS_KEY; import static eu.engys.core.project.system.BlockMeshDict.HEX_KEY; import static eu.engys.core.project.system.BlockMeshDict.PATCHES_KEY; import static eu.engys.core.project.system.BlockMeshDict.SIMPLE_GRADING_KEY; import static eu.engys.core.project.system.BlockMeshDict.VERTICES_KEY; import static eu.engys.core.project.system.BlockMeshDict.WALL_KEY; -import eu.engys.core.dictionary.Dictionary; +import static java.lang.String.valueOf; + import eu.engys.core.dictionary.FieldElement; import eu.engys.core.dictionary.parser.ListField2; import eu.engys.core.project.Model; +import eu.engys.core.project.geometry.surface.MultiPlane; import eu.engys.core.project.geometry.surface.PlaneRegion; import eu.engys.core.project.system.BlockMeshDict; public class BlockSaver { private Model model; - private Geometry geometry; - public BlockSaver(Model model, Geometry geometry) { + public BlockSaver(Model model) { this.model = model; - this.geometry = geometry; } - public void saveAutomaticBlock() { + public void saveAutomaticBlock(double spacing, boolean shouldConsiderSpacing) { BlockMeshDict blockMeshDict = model.getProject().getSystemFolder().getBlockMeshDict(); if(blockMeshDict != null){ - blockMeshDict.setBoundingBox(model.getGeometry().computeBoundingBox()); + blockMeshDict.setBoundingBox(model.getGeometry().computeBoundingBox(), spacing, shouldConsiderSpacing); } } /* @@ -64,18 +60,18 @@ public class BlockSaver { * imported from external file I need to clean its data because there can be * stuff I cannot visualise in the GUI */ - public void saveUserDefinedBlock(Dictionary userDefinedDictionary) { + public void saveUserDefinedBlock(MultiPlane block) { BlockMeshDict blockMeshDict = model.getProject().getSystemFolder().getBlockMeshDict(); if (blockMeshDict.isFromFile()) { blockMeshDict = new BlockMeshDict(); } - saveBlocks(blockMeshDict, userDefinedDictionary); - saveVertices(blockMeshDict, userDefinedDictionary); - savePatches(blockMeshDict); + saveBlocks(blockMeshDict, block); + saveVertices(blockMeshDict, block); + savePatches(blockMeshDict, block); } - private void saveBlocks(BlockMeshDict blockMeshDict, Dictionary userDefinedDictionary) { + private void saveBlocks(BlockMeshDict blockMeshDict, MultiPlane block) { ListField2 blocksList = new ListField2(BLOCKS_KEY); // 1 @@ -88,7 +84,7 @@ public class BlockSaver { // 3 ListField2 elementsList = new ListField2(""); - int[] elements = userDefinedDictionary.lookupIntArray(ELEMENTS_KEY); + int[] elements = block.getElements(); for (int el : elements) { elementsList.add(new FieldElement("", String.valueOf(el))); } @@ -105,8 +101,8 @@ public class BlockSaver { blockMeshDict.add(blocksList); } - private void savePatches(BlockMeshDict blockMeshDict) { - PlaneRegion[] regions = geometry.getBlock().getPlanes(); + private void savePatches(BlockMeshDict blockMeshDict, MultiPlane block) { + PlaneRegion[] regions = block.getPlanes(); ListField2 patchesList = new ListField2(PATCHES_KEY); @@ -131,9 +127,9 @@ public class BlockSaver { blockMeshDict.add(patchesList); } - private void saveVertices(BlockMeshDict blockMeshDict, Dictionary d) { - String[] min = d.lookupArray(MIN_KEY); - String[] max = d.lookupArray(MAX_KEY); + private void saveVertices(BlockMeshDict blockMeshDict, MultiPlane block) { + double[] min = block.getMin(); + double[] max = block.getMax(); ListField2 verticesList = new ListField2(VERTICES_KEY); verticesList.add(getPointList(min[0], min[1], min[2])); @@ -160,9 +156,9 @@ public class BlockSaver { return valuesContainerList; } - private ListField2 getPointList(String x, String y, String z) { + private ListField2 getPointList(double x, double y, double z) { ListField2 list = new ListField2(""); - list.add(x, y, z); + list.add(valueOf(x), valueOf(y), valueOf(z)); return list; } diff --git a/src/eu/engys/core/project/geometry/BoundingBox.java b/src/eu/engys/core/project/geometry/BoundingBox.java index df85055..c0c75a4 100644 --- a/src/eu/engys/core/project/geometry/BoundingBox.java +++ b/src/eu/engys/core/project/geometry/BoundingBox.java @@ -1,34 +1,34 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.geometry; import java.util.Arrays; -import javax.vecmath.Point3d; +import org.apache.commons.lang.builder.EqualsBuilder; +import org.apache.commons.lang.builder.HashCodeBuilder; public class BoundingBox { @@ -38,11 +38,28 @@ public class BoundingBox { private double ymax = -Double.MAX_VALUE; private double zmin = Double.MAX_VALUE; private double zmax = -Double.MAX_VALUE; - private Point3d center = new Point3d(0, 0, 0); public BoundingBox() { } + public BoundingBox(double[] bounds) { + this.xmin = bounds[0]; + this.xmax = bounds[1]; + this.ymin = bounds[2]; + this.ymax = bounds[3]; + this.zmin = bounds[4]; + this.zmax = bounds[5]; + } + + public BoundingBox(double[] min, double[] max) { + this.xmin = min[0]; + this.xmax = max[0]; + this.ymin = min[1]; + this.ymax = max[1]; + this.zmin = min[2]; + this.zmax = max[2]; + } + public BoundingBox(double xmin, double xmax, double ymin, double ymax, double zmin, double zmax) { this.xmin = xmin; this.xmax = xmax; @@ -107,15 +124,15 @@ public class BoundingBox { return new double[]{centerX, centerY, centerZ}; } - public double getWidth() { + public double getDeltaX() { return xmax - xmin; } - public double getHeight() { + public double getDeltaY() { return ymax - ymin; } - public double getDepth() { + public double getDeltaZ() { return zmax - zmin; } @@ -130,11 +147,19 @@ public class BoundingBox { @Override public boolean equals(Object obj) { - if (obj instanceof BoundingBox) { - BoundingBox b = (BoundingBox) obj; - return b.getWidth() == getWidth() && b.getHeight() == getHeight(); + if (!(obj instanceof BoundingBox)) { + return false; } - return false; + if (obj == this) { + return true; + } + BoundingBox fz = (BoundingBox) obj; + return new EqualsBuilder().append(getDeltaX(), fz.getDeltaX()).append(getDeltaY(), fz.getDeltaY()).append(getDeltaZ(), fz.getDeltaZ()).append(getCenter(), fz.getCenter()).isEquals(); + } + + @Override + public int hashCode() { + return new HashCodeBuilder(17, 31).append(getDeltaX()).append(getDeltaY()).append(getDeltaZ()).append(getCenter()).toHashCode(); } } diff --git a/src/eu/engys/core/project/geometry/FeatureLine.java b/src/eu/engys/core/project/geometry/FeatureLine.java index a38c6e4..50c2d26 100644 --- a/src/eu/engys/core/project/geometry/FeatureLine.java +++ b/src/eu/engys/core/project/geometry/FeatureLine.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.geometry; import static eu.engys.core.project.system.SnappyHexMeshDict.FILE_KEY; @@ -33,9 +32,9 @@ import java.awt.Color; import java.util.ArrayList; import java.util.List; -import vtk.vtkPolyData; import eu.engys.core.dictionary.Dictionary; import eu.engys.core.project.geometry.surface.BaseSurface; +import vtk.vtkPolyData; public class FeatureLine extends BaseSurface { @@ -167,6 +166,15 @@ public class FeatureLine extends BaseSurface { this.refineOnly = Boolean.parseBoolean(d.lookup(REFINE_FEATURE_EDGES_ONLY_KEY)); } } + + @Override + public Dictionary toGeometryDictionary() { + return null; + } + + @Override + public void fromGeometryDictionary(Dictionary g) { + } public void setModified(boolean modified) { this.modified = modified; diff --git a/src/eu/engys/core/project/geometry/FeatureLines.java b/src/eu/engys/core/project/geometry/FeatureLines.java index 9a11b30..0ca3b69 100644 --- a/src/eu/engys/core/project/geometry/FeatureLines.java +++ b/src/eu/engys/core/project/geometry/FeatureLines.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.geometry; import java.util.ArrayList; diff --git a/src/eu/engys/core/project/geometry/Geometry.java b/src/eu/engys/core/project/geometry/Geometry.java index fdbb908..7768e58 100644 --- a/src/eu/engys/core/project/geometry/Geometry.java +++ b/src/eu/engys/core/project/geometry/Geometry.java @@ -1,35 +1,32 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.geometry; import java.util.ArrayList; import java.util.List; -import vtk.vtkPolyData; -import eu.engys.core.dictionary.Dictionary; import eu.engys.core.project.Model; import eu.engys.core.project.geometry.factory.GeometryFactory; import eu.engys.core.project.geometry.surface.Box; @@ -44,6 +41,7 @@ import eu.engys.core.project.system.BlockMeshDict; import eu.engys.core.project.system.SnappyHexMeshDict; import eu.engys.util.Util; import eu.engys.util.progress.ProgressMonitor; +import vtk.vtkPolyData; public class Geometry { @@ -53,7 +51,7 @@ public class Geometry { private final FeatureLines lines = new FeatureLines(); private MultiPlane block = FAKE_BLOCK; private GeometryFactory geometryFactory; - + private boolean autoBoundingBox = true; private double[] cellSize; @@ -114,6 +112,10 @@ public class Geometry { return surfaces.toArray(new Surface[surfaces.size()]); } + public List getSurfacesList() { + return surfaces; + } + public void loadGeometry(Model model, ProgressMonitor monitor) { new GeometryReader(this).loadGeometry(model, monitor); } @@ -130,12 +132,12 @@ public class Geometry { new BlockReader(this).loadBlock(blockMeshDict, snappyHexMeshDict); } - public void saveUserDefinedBlock(Model model, Dictionary d) { - new BlockSaver(model, this).saveUserDefinedBlock(d); + public void saveUserDefinedBlock(Model model, MultiPlane block) { + new BlockSaver(model).saveUserDefinedBlock(block); } - public void saveAutoBlock(Model model) { - new BlockSaver(model, this).saveAutomaticBlock(); + public void saveAutoBlock(Model model, double spacing, boolean shouldConsiderSpacing) { + new BlockSaver(model).saveAutomaticBlock(spacing, shouldConsiderSpacing); } public GeometryFactory getFactory() { @@ -203,19 +205,23 @@ public class Geometry { return geometryFactory.newSurface(Cylinder.class, getAName("cylinder")); } + public static String getAName(List names, String initialName) { + String finalName = initialName; + int counter = 0; + while (names.contains(finalName)) { + finalName = initialName + counter++; + } + + return finalName; + } + public String getAName(String name) { List surfacesNames = new ArrayList(); for (Surface surface : surfaces) { surfacesNames.add(surface.getName()); } - String finalName = name; - int counter = 0; - while (surfacesNames.contains(finalName)) { - finalName = name + counter++; - } - - return finalName; + return getAName(surfacesNames, name); } public String getALineName(String name) { @@ -224,13 +230,7 @@ public class Geometry { linesNames.add(line.getName()); } - String finalName = name; - int counter = 0; - while (linesNames.contains(finalName)) { - finalName = name + counter++; - } - - return finalName; + return getAName(linesNames, name); } public MultiPlane getBlock() { @@ -298,28 +298,26 @@ public class Geometry { } public boolean contains(String name) { + return getAllSurfacesNames().contains(name); + } + + public List getAllSurfacesNames() { + List names = new ArrayList(); for (Surface surface : surfaces) { - if (surface.getName().equals(name)) { - return true; - } + names.add(surface.getName()); if (surface.hasRegions()) { for (Surface region : surface.getRegions()) { - if (region.getName().equals(name)) { - return true; - } + names.add(region.getName()); } } } - + for (Surface region : block.getRegions()) { - if (region.getName().equals(name)) { - return true; - } + names.add(region.getName()); } - - return false; + return names; } - + public double[] getCellSize(int level) { if (cellSize != null) { return new double[] { cellSize[0] / Math.pow(2, level), cellSize[1] / Math.pow(2, level), cellSize[2] / Math.pow(2, level) }; @@ -328,7 +326,6 @@ public class Geometry { } } - public void setCellSize(double[] cellSize) { this.cellSize = cellSize; } diff --git a/src/eu/engys/core/project/geometry/GeometryReader.java b/src/eu/engys/core/project/geometry/GeometryReader.java index f6500f2..4d415df 100644 --- a/src/eu/engys/core/project/geometry/GeometryReader.java +++ b/src/eu/engys/core/project/geometry/GeometryReader.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.geometry; @@ -31,7 +30,7 @@ import static eu.engys.core.project.system.SnappyHexMeshDict.ADD_LAYERS_CONTROLS import static eu.engys.core.project.system.SnappyHexMeshDict.AUTO_BLOCK_MESH_KEY; import static eu.engys.core.project.system.SnappyHexMeshDict.BLOCK_DATA_KEY; import static eu.engys.core.project.system.SnappyHexMeshDict.CASTELLATED_MESH_CONTROLS_KEY; -import static eu.engys.core.project.system.SnappyHexMeshDict.CELL_ZONE_INSIDE; +import static eu.engys.core.project.system.SnappyHexMeshDict.CELL_ZONE_INSIDE_KEY; import static eu.engys.core.project.system.SnappyHexMeshDict.CELL_ZONE_KEY; import static eu.engys.core.project.system.SnappyHexMeshDict.FACE_TYPE_KEY; import static eu.engys.core.project.system.SnappyHexMeshDict.FACE_ZONE_KEY; @@ -166,11 +165,10 @@ public class GeometryReader { DefaultGeometryFactory.clearSTLCache(); List dictionaries = geometryDict.getDictionaries(); - final List surfaces = Collections.synchronizedList(new ArrayList()); - monitor.setTotal(dictionaries.size()); monitor.info("STLS:", 1); + final List surfaces = Collections.synchronizedList(new ArrayList()); for (int i = 0; i < dictionaries.size(); i++) { final Dictionary dict = dictionaries.get(i); surfaces.add(geometry.getFactory().loadSurface(dict, model, monitor)); @@ -233,7 +231,7 @@ public class GeometryReader { if (!surfaceDict.found(FACE_TYPE_KEY)) { surfaceDict.add(FACE_TYPE_KEY, "internal"); } - surfaceDict.add(CELL_ZONE_INSIDE, "inside"); + surfaceDict.add(CELL_ZONE_INSIDE_KEY, "inside"); Dictionary sd = surface.getSurfaceDictionary(); copyIfFound(sd, surfaceDict, LEVEL_KEY); diff --git a/src/eu/engys/core/project/geometry/GeometrySaver.java b/src/eu/engys/core/project/geometry/GeometrySaver.java index f612413..f85c70a 100644 --- a/src/eu/engys/core/project/geometry/GeometrySaver.java +++ b/src/eu/engys/core/project/geometry/GeometrySaver.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.geometry; import static eu.engys.core.dictionary.DictionaryUtils.copyIfFound; @@ -30,7 +29,7 @@ import static eu.engys.core.project.system.SnappyHexMeshDict.ADD_LAYERS_CONTROLS import static eu.engys.core.project.system.SnappyHexMeshDict.BAFFLE_KEY; import static eu.engys.core.project.system.SnappyHexMeshDict.BOUNDARY_KEY; import static eu.engys.core.project.system.SnappyHexMeshDict.CASTELLATED_MESH_CONTROLS_KEY; -import static eu.engys.core.project.system.SnappyHexMeshDict.CELL_ZONE_INSIDE; +import static eu.engys.core.project.system.SnappyHexMeshDict.CELL_ZONE_INSIDE_KEY; import static eu.engys.core.project.system.SnappyHexMeshDict.CELL_ZONE_KEY; import static eu.engys.core.project.system.SnappyHexMeshDict.DISTANCE_KEY; import static eu.engys.core.project.system.SnappyHexMeshDict.EXPANSION_RATIO_KEY; @@ -42,7 +41,7 @@ import static eu.engys.core.project.system.SnappyHexMeshDict.FINAL_LAYER_THICKNE import static eu.engys.core.project.system.SnappyHexMeshDict.GEOMETRY_KEY; import static eu.engys.core.project.system.SnappyHexMeshDict.GROWN_UP_KEY; import static eu.engys.core.project.system.SnappyHexMeshDict.INSIDE; -import static eu.engys.core.project.system.SnappyHexMeshDict.IS_CELL_ZONE; +import static eu.engys.core.project.system.SnappyHexMeshDict.IS_CELL_ZONE_KEY; import static eu.engys.core.project.system.SnappyHexMeshDict.LAYERS_KEY; import static eu.engys.core.project.system.SnappyHexMeshDict.LEVELS_KEY; import static eu.engys.core.project.system.SnappyHexMeshDict.LEVEL_KEY; @@ -66,7 +65,6 @@ import org.slf4j.LoggerFactory; import eu.engys.core.dictionary.Dictionary; import eu.engys.core.dictionary.ListField; import eu.engys.core.project.Model; -import eu.engys.core.project.geometry.stl.AffineTransform; import eu.engys.core.project.geometry.surface.Region; import eu.engys.core.project.geometry.surface.Stl; import eu.engys.core.project.system.SnappyHexMeshDict; @@ -107,15 +105,17 @@ public class GeometrySaver { private void initDictionaries(SnappyHexMeshDict snappyHexMeshDict) { geometryDict = snappyHexMeshDict.subDict(GEOMETRY_KEY); - castellatedDict = snappyHexMeshDict.subDict(CASTELLATED_MESH_CONTROLS_KEY); - refinementSurfaces = castellatedDict.subDict(REFINEMENTS_SURFACES_KEY); - refinementRegions = castellatedDict.subDict(REFINEMENTS_REGIONS_KEY); layers = snappyHexMeshDict.subDict(ADD_LAYERS_CONTROLS_KEY).subDict(LAYERS_KEY); - geometryDict.clear(); - refinementSurfaces.clear(); - refinementRegions.clear(); layers.clear(); + + castellatedDict = snappyHexMeshDict.subDict(CASTELLATED_MESH_CONTROLS_KEY); + if(castellatedDict != null){ + refinementSurfaces = castellatedDict.subDict(REFINEMENTS_SURFACES_KEY); + refinementRegions = castellatedDict.subDict(REFINEMENTS_REGIONS_KEY); + refinementSurfaces.clear(); + refinementRegions.clear(); + } } private void saveFeatureLines(Model model) { @@ -128,9 +128,6 @@ public class GeometrySaver { private void saveSurfaces(Model model) { for (Surface surface : geometry.getSurfaces()) { - if (surface.getType().isStl()) { - saveSTL((Stl) surface); - } saveToGeometry(surface); if (isACellZone(surface)) { saveToRefinementSurfacesAsCellZone(surface); @@ -145,18 +142,8 @@ public class GeometrySaver { } } - private void saveSTL(Stl stl) { - AffineTransform transformation = stl.getTransformation(); - if (stl.getTransformMode() == TransfromMode.TO_DICTIONARY) { - if (!transformation.isIdentity()) { - ListField transforms = transformation.toDictionary(); - stl.getGeometryDictionary().add(transforms); - } - } - } - private void saveToGeometry(Surface surface) { - Dictionary geometryDictionary = surface.getGeometryDictionary(); + Dictionary geometryDictionary = surface.toGeometryDictionary(); if (geometryDictionary != null && geometryDictionary.found(Dictionary.TYPE)) { geometryDict.add(geometryDictionary); } @@ -173,9 +160,9 @@ public class GeometrySaver { copyIfFound(sd, surfaceDictionary, MAX_CELLS_ACROSS_GAP_KEY); if (sd.found(FACE_ZONE_KEY)) { - sd.add(CELL_ZONE_INSIDE, INSIDE); - if (sd.found(IS_CELL_ZONE)) { - if (sd.lookup(IS_CELL_ZONE).equals("true")) { + sd.add(CELL_ZONE_INSIDE_KEY, INSIDE); + if (sd.found(IS_CELL_ZONE_KEY)) { + if (sd.lookup(IS_CELL_ZONE_KEY).equals("true")) { if (sd.found(CELL_ZONE_KEY)) { sd.add(CELL_ZONE_KEY, sd.lookup(CELL_ZONE_KEY)); } else { @@ -184,7 +171,7 @@ public class GeometrySaver { } else { sd.remove(CELL_ZONE_KEY); } - sd.remove(IS_CELL_ZONE); + sd.remove(IS_CELL_ZONE_KEY); } sd.remove(REGIONS_KEY); } diff --git a/src/eu/engys/core/project/geometry/GeometryWriter.java b/src/eu/engys/core/project/geometry/GeometryWriter.java index 4e486fa..46774e6 100644 --- a/src/eu/engys/core/project/geometry/GeometryWriter.java +++ b/src/eu/engys/core/project/geometry/GeometryWriter.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.geometry; import eu.engys.core.project.Model; diff --git a/src/eu/engys/core/project/geometry/Surface.java b/src/eu/engys/core/project/geometry/Surface.java index d5e1b60..2042a95 100644 --- a/src/eu/engys/core/project/geometry/Surface.java +++ b/src/eu/engys/core/project/geometry/Surface.java @@ -1,54 +1,59 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.geometry; +import static eu.engys.core.project.system.SnappyHexMeshDict.CELL_ZONE_KEY; import static eu.engys.core.project.system.SnappyHexMeshDict.EXPANSION_RATIO_KEY; import static eu.engys.core.project.system.SnappyHexMeshDict.FACE_TYPE_KEY; +import static eu.engys.core.project.system.SnappyHexMeshDict.FACE_ZONE_KEY; import static eu.engys.core.project.system.SnappyHexMeshDict.FINAL_LAYER_THICKNESS_KEY; import static eu.engys.core.project.system.SnappyHexMeshDict.LEVEL_KEY; import static eu.engys.core.project.system.SnappyHexMeshDict.NONE_KEY; import static eu.engys.core.project.system.SnappyHexMeshDict.N_SURFACE_LAYERS_KEY; -import vtk.vtkPolyData; -import vtk.vtkTransform; -import vtk.vtkTransformFilter; + import eu.engys.core.dictionary.Dictionary; import eu.engys.core.project.geometry.stl.AffineTransform; import eu.engys.core.project.geometry.surface.Region; import eu.engys.core.project.geometry.surface.Solid; +import eu.engys.util.bean.AbstractBean; import eu.engys.util.ui.checkboxtree.VisibleItem; +import vtk.vtkPolyData; +import vtk.vtkTransform; +import vtk.vtkTransformFilter; -public abstract class Surface implements VisibleItem { +public abstract class Surface extends AbstractBean implements VisibleItem { public static final String MAX_KEY = "max"; public static final String MIN_KEY = "min"; public static final String POINT1_KEY = "point1"; public static final String POINT2_KEY = "point2"; + public static final String P1_KEY = "p1"; + public static final String P2_KEY = "p2"; public static final String RADIUS_KEY = "radius"; public static final String CENTRE_KEY = "centre"; + public static final String BOX_KEY = "box"; public static final String OUTER_RADIUS_KEY = "outerRadius"; public static final String INNER_RADIUS_KEY = "innerRadius"; public static final String PLANE_TYPE_KEY = "planeType"; @@ -56,6 +61,7 @@ public abstract class Surface implements VisibleItem { public static final String BASE_POINT_KEY = "basePoint"; public static final String POINT_AND_NORMAL_KEY = "pointAndNormal"; public static final String POINT_AND_NORMAL_DICT_KEY = "pointAndNormalDict"; + public static final String ELEMENTS_KEY = "elements"; public static final String TRI_SURFACE_MESH_KEY = "triSurfaceMesh"; public static final String SEARCHABLE_RING_KEY = "searchableRing"; @@ -64,67 +70,39 @@ public abstract class Surface implements VisibleItem { public static final String SEARCHABLE_CYLINDER_KEY = "searchableCylinder"; public static final String SEARCHABLE_BOX_KEY = "searchableBox"; - private Dictionary geometryDictionary; private Dictionary surfaceDictionary; private Dictionary volumeDictionary; private Dictionary layerDictionary; private Dictionary zoneDictionary; protected String name; + protected boolean appendRegionName = false; private boolean visible = true; + private AffineTransform transformation; private TransfromMode transformMode; public static final Dictionary surfaceDefault = new Dictionary("") { - { - add(LEVEL_KEY, "(0 0)"); - } + { + add(LEVEL_KEY, "(0 0)"); + } }; public static final Dictionary volumeDefault = new Dictionary("") { - { - add("mode", "none"); - } + { + add("mode", "none"); + } }; public static final Dictionary zonesDefault = new Dictionary("") { - { - add(FACE_TYPE_KEY, NONE_KEY); - } + { + add(FACE_TYPE_KEY, NONE_KEY); + } }; public static final Dictionary layerDefault = new Dictionary("") { - { - add(N_SURFACE_LAYERS_KEY, "0"); - add(EXPANSION_RATIO_KEY, "1.25"); - add(FINAL_LAYER_THICKNESS_KEY, "0.4"); - } - }; - - public static final Dictionary stl = new Dictionary("name.stl") { { - add(TYPE, TRI_SURFACE_MESH_KEY); - add("name", "name"); - } - }; - public static final Dictionary box = new Dictionary("box") { - { - add(TYPE, SEARCHABLE_BOX_KEY); - add(MIN_KEY, "(0 0 0)"); - add(MAX_KEY, "(2 2 1)"); - } - }; - public static final Dictionary cylinder = new Dictionary("cylinder") { - { - add(TYPE, SEARCHABLE_CYLINDER_KEY); - add(POINT1_KEY, "(0 0 0)"); - add(POINT2_KEY, "(1 0 0)"); - add(RADIUS_KEY, "1.0"); - } - }; - public static final Dictionary sphere = new Dictionary("sphere") { - { - add(TYPE, SEARCHABLE_SPHERE_KEY); - add(CENTRE_KEY, "(0 0 0)"); - add(RADIUS_KEY, "1.0"); + add(N_SURFACE_LAYERS_KEY, 0); + add(EXPANSION_RATIO_KEY, 1.25); + add(FINAL_LAYER_THICKNESS_KEY, 0.4); } }; public static final Dictionary plane = new Dictionary("plane") { @@ -132,30 +110,11 @@ public abstract class Surface implements VisibleItem { add(TYPE, SEARCHABLE_PLANE_KEY); add(PLANE_TYPE_KEY, POINT_AND_NORMAL_KEY); Dictionary dict = new Dictionary(POINT_AND_NORMAL_DICT_KEY); -// dict.add(BASE_POINT_KEY, "(0 0 0)"); + // dict.add(BASE_POINT_KEY, "(0 0 0)"); dict.add(NORMAL_VECTOR_KEY, "(0 0 1)"); add(dict); } }; - public static final Dictionary planeWithCenter = new Dictionary("plane") { - { - add(TYPE, SEARCHABLE_PLANE_KEY); - add(PLANE_TYPE_KEY, POINT_AND_NORMAL_KEY); - Dictionary dict = new Dictionary(POINT_AND_NORMAL_DICT_KEY); - dict.add(BASE_POINT_KEY, "(0 0 0)"); - dict.add(NORMAL_VECTOR_KEY, "(0 0 1)"); - add(dict); - } - }; - public static final Dictionary ring = new Dictionary("ring") { - { - add(TYPE, SEARCHABLE_RING_KEY); - add(POINT1_KEY, "(0 0 0)"); - add(POINT2_KEY, "(0.05 0 0)"); - add(INNER_RADIUS_KEY, "0.2"); - add(OUTER_RADIUS_KEY, "0.5"); - } - }; public Surface(String name) { this.name = name; @@ -164,15 +123,15 @@ public abstract class Surface implements VisibleItem { this.volumeDictionary = new Dictionary(name, volumeDefault); this.layerDictionary = new Dictionary(name, layerDefault); this.zoneDictionary = new Dictionary(name, zonesDefault); - + this.transformation = new AffineTransform(); -// this.transformMode = TransfromMode.TO_DICTIONARY; + // this.transformMode = TransfromMode.TO_DICTIONARY; this.transformMode = TransfromMode.TO_FILE; } - public boolean isAppendRegionName() { - return geometryDictionary.found("appendRegionName") && geometryDictionary.lookup("appendRegionName").equals("true"); - } + // public boolean isAppendRegionName() { + // return geometryDictionary.found("appendRegionName") && geometryDictionary.lookup("appendRegionName").equals("true"); + // } public String getName() { return name; @@ -180,10 +139,14 @@ public abstract class Surface implements VisibleItem { public abstract String getPatchName(); - public String getZoneName() { - return zoneDictionary.lookup("cellZone"); + public String getCellZoneName() { + return zoneDictionary.lookup(CELL_ZONE_KEY); } - + + public String getFaceZoneName() { + return zoneDictionary.lookup(FACE_ZONE_KEY); + } + @Override public boolean isVisible() { return visible; @@ -194,6 +157,14 @@ public abstract class Surface implements VisibleItem { this.visible = visible; } + public void setAppendRegionName(boolean appendRegionName) { + firePropertyChange("appendRegionName", this.appendRegionName, this.appendRegionName = appendRegionName); + } + + public boolean isAppendRegionName() { + return appendRegionName; + } + public abstract Type getType(); public abstract boolean isSingleton(); @@ -213,7 +184,7 @@ public abstract class Surface implements VisibleItem { public abstract Surface cloneSurface(); protected abstract vtkPolyData getDataSet(); - + public vtkPolyData getTransformedDataSet() { vtkPolyData dataSet = getDataSet(); if (dataSet != null) { @@ -222,7 +193,7 @@ public abstract class Surface implements VisibleItem { tFilter.SetTransform(getTransformation().toVTK(new vtkTransform())); tFilter.SetInputData(dataSet); tFilter.Update(); - + return (vtkPolyData) tFilter.GetOutput(); } else { return dataSet; @@ -232,13 +203,12 @@ public abstract class Surface implements VisibleItem { } } - public void setGeometryDictionary(Dictionary geometryDictionary) { - this.geometryDictionary = geometryDictionary; - } - - public Dictionary getGeometryDictionary() { - return geometryDictionary; - } + // private void setGeometryDictionary(Dictionary geometryDictionary) { + // this.geometryDictionary = geometryDictionary; + // } + // public Dictionary getGeometryDictionary() { + // return geometryDictionary; + // } public void setSurfaceDictionary(Dictionary surfaceDictionary) { this.surfaceDictionary = surfaceDictionary; @@ -306,16 +276,6 @@ public abstract class Surface implements VisibleItem { getZoneDictionary().setName(getName()); } - public void buildGeometryDictionary(Dictionary dictionary) { - Dictionary geometryDict = new Dictionary(dictionary); - geometryDict.setName(getName()); - getSurfaceDictionary().setName(getName()); - getVolumeDictionary().setName(getName()); - getLayerDictionary().setName(getName()); - getZoneDictionary().setName(getName()); - setGeometryDictionary(geometryDict); - } - public void buildSurfaceDictionary(Dictionary dictionary) { Dictionary surfaceDict = new Dictionary(dictionary); surfaceDict.setName(getName()); @@ -345,30 +305,59 @@ public abstract class Surface implements VisibleItem { } protected void cloneSurface(Surface surface) { - if (this.geometryDictionary != null) { - surface.geometryDictionary = new Dictionary(this.geometryDictionary); - } surface.surfaceDictionary = new Dictionary(this.surfaceDictionary); surface.volumeDictionary = new Dictionary(this.volumeDictionary); surface.layerDictionary = new Dictionary(this.layerDictionary); surface.zoneDictionary = new Dictionary(this.zoneDictionary); - + surface.visible = this.visible; surface.transformation = new AffineTransform(this.transformation); - //System.out.println("Surface.cloneSurface() HASH: "+surface.hashCode()+surfaceDictionary+surface.surfaceDictionary); } public AffineTransform getTransformation() { return transformation; } + public void setTransformation(AffineTransform transformation) { this.transformation = transformation; } - + public TransfromMode getTransformMode() { return transformMode; } + public void setTransformMode(TransfromMode transformMode) { this.transformMode = transformMode; } + + public abstract Dictionary toGeometryDictionary(); + + public abstract void fromGeometryDictionary(Dictionary g); + + public void copyFrom(Surface delegate, boolean changeGeometry, boolean changeSurface, boolean changeVolume, boolean changeLayer, boolean changeZone) { + if (changeSurface) + buildSurfaceDictionary(delegate.getSurfaceDictionary()); + if (changeVolume) + buildVolumeDictionary(delegate.getVolumeDictionary()); + if (changeLayer) + buildLayerDictionary(delegate.getLayerDictionary()); + if (changeZone) + buildZoneDictionary(delegate.getZoneDictionary()); + } + + // public Dictionary toGeometryDictionary() { + // Dictionary d = new Dictionary(getName()); + // d.add("appendRegionName", Boolean.toString(appendRegionName)); + // if (surface.getType().isStl()) { + // AffineTransform transformation = stl.getTransformation(); + // if (stl.getTransformMode() == TransfromMode.TO_DICTIONARY) { + // if (!transformation.isIdentity()) { + // ListField transforms = transformation.toDictionary(); + // stl.getGeometryDictionary().add(transforms); + // } + // } + // } + // + // return d; + // } } diff --git a/src/eu/engys/core/project/geometry/TransfromMode.java b/src/eu/engys/core/project/geometry/TransfromMode.java index 8f3db8b..22ce78b 100644 --- a/src/eu/engys/core/project/geometry/TransfromMode.java +++ b/src/eu/engys/core/project/geometry/TransfromMode.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.geometry; public enum TransfromMode { diff --git a/src/eu/engys/core/project/geometry/Type.java b/src/eu/engys/core/project/geometry/Type.java index 04be117..e502f52 100644 --- a/src/eu/engys/core/project/geometry/Type.java +++ b/src/eu/engys/core/project/geometry/Type.java @@ -1,42 +1,49 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.geometry; public enum Type { - STL, BOX, CYLINDER, SPHERE, REGION, SOLID, PLANE, MULTI, RING, LINE; + STL, STL_AREA, BOX, RBOX, CYLINDER, SPHERE, REGION, SOLID, PLANE, MULTI, RING, LINE; public boolean isStl() { return equals(STL); } + public boolean isStlArea() { + return equals(STL_AREA); + } + public boolean isBox() { return equals(BOX); } + public boolean isRotatedBox() { + return equals(RBOX); + } + public boolean isCylinder() { return equals(CYLINDER); } diff --git a/src/eu/engys/core/project/geometry/factory/DefaultGeometryFactory.java b/src/eu/engys/core/project/geometry/factory/DefaultGeometryFactory.java index dcb89bb..74644cb 100644 --- a/src/eu/engys/core/project/geometry/factory/DefaultGeometryFactory.java +++ b/src/eu/engys/core/project/geometry/factory/DefaultGeometryFactory.java @@ -1,29 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.geometry.factory; import static eu.engys.core.dictionary.Dictionary.TYPE; @@ -46,13 +44,14 @@ import org.apache.commons.io.FilenameUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import vtk.vtkPolyData; import eu.engys.core.dictionary.Dictionary; import eu.engys.core.project.Model; import eu.engys.core.project.geometry.FeatureLine; import eu.engys.core.project.geometry.Surface; import eu.engys.core.project.geometry.TransfromMode; import eu.engys.core.project.geometry.stl.AffineTransform; +import eu.engys.core.project.geometry.stl.STLAreaReader; +import eu.engys.core.project.geometry.stl.STLAreaWriter; import eu.engys.core.project.geometry.stl.STLReader; import eu.engys.core.project.geometry.stl.STLWriter; import eu.engys.core.project.geometry.surface.Box; @@ -63,8 +62,10 @@ import eu.engys.core.project.geometry.surface.Ring; import eu.engys.core.project.geometry.surface.Solid; import eu.engys.core.project.geometry.surface.Sphere; import eu.engys.core.project.geometry.surface.Stl; +import eu.engys.core.project.geometry.surface.StlArea; import eu.engys.util.ColorUtil; import eu.engys.util.progress.ProgressMonitor; +import vtk.vtkPolyData; public class DefaultGeometryFactory implements GeometryFactory { @@ -73,22 +74,24 @@ public class DefaultGeometryFactory implements GeometryFactory { @Override public void deleteSurface(Model model, Surface surface) { - if(surface instanceof Stl) { - File file = model.getProject().getConstantFolder().getTriSurface().getFileManager().getFile(surface.getName()+".stl"); + if (surface instanceof Stl) { + File file = model.getProject().getConstantFolder().getTriSurface().getFileManager().getFile(surface.getName() + ".stl"); if (file.exists()) { - FileUtils.deleteQuietly(file); + FileUtils.deleteQuietly(file); } - file = model.getProject().getConstantFolder().getTriSurface().getFileManager().getFile(surface.getName()+".STL"); + file = model.getProject().getConstantFolder().getTriSurface().getFileManager().getFile(surface.getName() + ".STL"); if (file.exists()) { - FileUtils.deleteQuietly(file); + FileUtils.deleteQuietly(file); } } } - + @Override public void writeSurface(Surface surface, Model model, ProgressMonitor monitor) { if (surface.getType().isStl()) { writeSTL((Stl) surface, model, monitor); + } else if (surface.getType().isStlArea()) { + writeSTLArea((StlArea) surface, model, monitor); } else if (surface.getType().isLine()) { writeFeatureLine((FeatureLine) surface, model, monitor); } @@ -97,7 +100,7 @@ public class DefaultGeometryFactory implements GeometryFactory { private void writeFeatureLine(FeatureLine line, Model model, ProgressMonitor monitor) { String fileName = line.getName() + ".eMesh"; File file = model.getProject().getConstantFolder().getTriSurface().getFileManager().getFile(fileName); - if (!file.exists()|| line.isModified()) { + if (!file.exists() || line.isModified()) { new EMESHWriter(file, line).run(); } } @@ -106,20 +109,34 @@ public class DefaultGeometryFactory implements GeometryFactory { String fileName = stl.getFileName(); File file = model.getProject().getConstantFolder().getTriSurface().getFileManager().getFile(fileName); AffineTransform transformation = stl.getTransformation(); - + if (stl.getTransformMode() == TransfromMode.TO_DICTIONARY) { if (!file.exists() || stl.isModified()) { new STLWriter(file, stl, monitor).run(); } - } else { + } else { if (!file.exists() || !transformation.isIdentity() || stl.isModified()) { new STLWriter(file, stl, monitor).run(); } } } - - - + + private void writeSTLArea(StlArea stlArea, Model model, ProgressMonitor monitor) { + String fileName = stlArea.getFile(); + File file = model.getProject().getConstantFolder().getTriSurface().getFileManager().getFile(fileName); + AffineTransform transformation = stlArea.getTransformation(); + + if (stlArea.getTransformMode() == TransfromMode.TO_DICTIONARY) { + if (!file.exists()) { + new STLAreaWriter(file, stlArea, monitor).run(); + } + } else { + if (!file.exists() || !transformation.isIdentity()) { + new STLAreaWriter(file, stlArea, monitor).run(); + } + } + } + @Override public Surface loadSurface(Dictionary g, Model model, ProgressMonitor monitor) { Surface surface; @@ -166,44 +183,44 @@ public class DefaultGeometryFactory implements GeometryFactory { @SuppressWarnings("deprecation") protected Surface loadBox(Dictionary g) { - Surface box = new Box(g.getName()); - box.setGeometryDictionary(g); + Box box = new Box(g.getName()); + box.fromGeometryDictionary(g); return box; } @SuppressWarnings("deprecation") protected Cylinder loadCylinder(Dictionary g) { Cylinder cyl = new Cylinder(g.getName()); - cyl.setGeometryDictionary(g); + cyl.fromGeometryDictionary(g); return cyl; } @SuppressWarnings("deprecation") protected Plane loadPlane(Dictionary g) { Plane plane = new Plane(g.getName()); - plane.setGeometryDictionary(g); + plane.fromGeometryDictionary(g); return plane; } @SuppressWarnings("deprecation") protected Ring loadRing(Dictionary g) { Ring ring = new Ring(g.getName()); - ring.setGeometryDictionary(g); + ring.fromGeometryDictionary(g); return ring; } @SuppressWarnings("deprecation") protected Sphere loadSphere(Dictionary g) { Sphere sphere = new Sphere(g.getName()); - sphere.setGeometryDictionary(g); + sphere.fromGeometryDictionary(g); return sphere; } @SuppressWarnings("deprecation") protected Stl loadSTL(Dictionary g, Model model, ProgressMonitor monitor) { Stl stl = new Stl(g.lookup("name")); - stl.setGeometryDictionary(g); - + stl.setFileName(g.getName()); + loadStl(stl, model, monitor); stl.setTransformation(AffineTransform.fromGeometryDictionary(g)); @@ -211,16 +228,15 @@ public class DefaultGeometryFactory implements GeometryFactory { } private void loadStl(Stl stl, Model model, ProgressMonitor monitor) { - String fileName = stl.getGeometryDictionary().getName(); + String fileName = stl.getFileName(); File file = model.getProject().getConstantFolder().getTriSurface().getFileManager().getFile(fileName); - stl.setFileName(file); if (STLCache.containsKey(fileName)) { Stl cached = STLCache.get(fileName); Solid[] cachedSolids = cached.getSolids(); List solids = new ArrayList<>(); for (Solid cachedSolid : cachedSolids) { - solids.add((Solid)cachedSolid.cloneSurface()); + solids.add((Solid) cachedSolid.cloneSurface()); } stl.setSolids(solids); } else { @@ -229,7 +245,7 @@ public class DefaultGeometryFactory implements GeometryFactory { List solids = reader.getSolids(); stl.setSolids(solids); } - + if (!STLCache.containsKey(fileName)) { STLCache.put(fileName, stl); } @@ -239,22 +255,34 @@ public class DefaultGeometryFactory implements GeometryFactory { public Stl readSTL(File file, ProgressMonitor monitor) { String fileName = file.getName(); String name = FilenameUtils.removeExtension(fileName); - Dictionary g = new Dictionary(fileName, Surface.stl); - g.setName(fileName); - g.add("name", name); Stl stl = new Stl(name); - stl.setGeometryDictionary(g); - stl.setFileName(file); - + stl.setFileName(fileName); + STLReader reader = new STLReader(file, monitor); reader.run(); List solids = reader.getSolids(); stl.setSolids(solids); - + return stl; } + @Override + public StlArea readSTLArea(File file, ProgressMonitor monitor) { + String fileName = file.getName(); + String name = FilenameUtils.removeExtension(fileName); + + StlArea stlArea = new StlArea(name); + stlArea.setFile(fileName); + + STLAreaReader reader = new STLAreaReader(file, monitor); + reader.run(); + List solids = reader.getSolids(); + stlArea.setDataSet(solids.get(0).getDataSet()); + + return stlArea; + } + private FeatureLine loadLine(Dictionary g, Model model, ProgressMonitor monitor) { String fileName = g.lookup("file").replace("\"", ""); File file = model.getProject().getConstantFolder().getTriSurface().getFileManager().getFile(fileName); @@ -262,17 +290,17 @@ public class DefaultGeometryFactory implements GeometryFactory { line.setColor(ColorUtil.getColor(model.getGeometry().getLines().size())); return line; } - + @Override public FeatureLine readLine(File file) { FeatureLine featureLine = new FeatureLine(FilenameUtils.removeExtension(file.getName())); featureLine.setModified(false); vtkPolyData dataSet = new EMESHReader(file).run(); featureLine.setDataSet(dataSet); - + return featureLine; } - + /* * IS */ @@ -304,7 +332,7 @@ public class DefaultGeometryFactory implements GeometryFactory { public static boolean isSTL(Dictionary g) { return g.isField(TYPE) && TRI_SURFACE_MESH_KEY.equals(g.lookup(TYPE)); } - + public static void clearSTLCache() { STLCache.clear(); } diff --git a/src/eu/engys/core/project/geometry/factory/EMESHReader.java b/src/eu/engys/core/project/geometry/factory/EMESHReader.java index 4466100..9faf581 100644 --- a/src/eu/engys/core/project/geometry/factory/EMESHReader.java +++ b/src/eu/engys/core/project/geometry/factory/EMESHReader.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.geometry.factory; import java.io.File; @@ -31,14 +30,14 @@ import java.util.List; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import vtk.vtkCellArray; -import vtk.vtkLine; -import vtk.vtkPoints; -import vtk.vtkPolyData; import eu.engys.core.dictionary.Dictionary; import eu.engys.core.dictionary.DictionaryUtils; import eu.engys.core.dictionary.parser.ListField2; import eu.engys.util.VTKSettings; +import vtk.vtkCellArray; +import vtk.vtkLine; +import vtk.vtkPoints; +import vtk.vtkPolyData; public class EMESHReader { diff --git a/src/eu/engys/core/project/geometry/factory/EMESHWriter.java b/src/eu/engys/core/project/geometry/factory/EMESHWriter.java index 938a99a..b8508f0 100644 --- a/src/eu/engys/core/project/geometry/factory/EMESHWriter.java +++ b/src/eu/engys/core/project/geometry/factory/EMESHWriter.java @@ -1,40 +1,39 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.geometry.factory; import java.io.File; -import vtk.vtkIdList; -import vtk.vtkPolyData; import eu.engys.core.dictionary.Dictionary; import eu.engys.core.dictionary.DictionaryUtils; import eu.engys.core.dictionary.FieldElement; import eu.engys.core.dictionary.FoamFile; import eu.engys.core.dictionary.parser.ListField2; import eu.engys.core.project.geometry.FeatureLine; +import vtk.vtkIdList; +import vtk.vtkPolyData; public class EMESHWriter { diff --git a/src/eu/engys/core/project/geometry/factory/EngysGeometryFactory.java b/src/eu/engys/core/project/geometry/factory/EngysGeometryFactory.java index 856b5f9..7ea81cb 100644 --- a/src/eu/engys/core/project/geometry/factory/EngysGeometryFactory.java +++ b/src/eu/engys/core/project/geometry/factory/EngysGeometryFactory.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.geometry.factory; import java.io.File; @@ -42,62 +41,56 @@ public class EngysGeometryFactory extends DefaultGeometryFactory { @Override public S newSurface(Class type, String name) { S surface = super.newSurface(type, name); - setAppendRegionName(surface, true); + surface.setAppendRegionName(true); return surface; } - public void setAppendRegionName(Surface surface, boolean b) { - if (surface.getGeometryDictionary() != null) { - surface.getGeometryDictionary().add("appendRegionName", Boolean.toString(b)); - } - } - @Override protected Surface loadBox(Dictionary g) { Surface box = super.loadBox(g); - setAppendRegionName(box, true); + box.setAppendRegionName(true); return box; } @Override protected Cylinder loadCylinder(Dictionary g) { Cylinder cylinder = super.loadCylinder(g); - setAppendRegionName(cylinder, true); + cylinder.setAppendRegionName(true); return cylinder; } @Override protected Plane loadPlane(Dictionary g) { Plane plane = super.loadPlane(g); - setAppendRegionName(plane, true); + plane.setAppendRegionName(true); return plane; } @Override protected Ring loadRing(Dictionary g) { Ring ring = super.loadRing(g); - setAppendRegionName(ring, true); + ring.setAppendRegionName(true); return ring; } @Override protected Sphere loadSphere(Dictionary g) { Sphere sphere = super.loadSphere(g); - setAppendRegionName(sphere, true); + sphere.setAppendRegionName(true); return sphere; } @Override protected Stl loadSTL(Dictionary g, Model model, ProgressMonitor monitor) { Stl stl = super.loadSTL(g, model, monitor); - setAppendRegionName(stl, !stl.isSingleton()); + stl.setAppendRegionName(!stl.isSingleton()); return stl; } @Override public Stl readSTL(File file, ProgressMonitor monitor) { Stl stl = super.readSTL(file, monitor); - setAppendRegionName(stl, !stl.isSingleton()); + stl.setAppendRegionName(!stl.isSingleton()); return stl; } diff --git a/src/eu/engys/core/project/geometry/factory/GeometryFactory.java b/src/eu/engys/core/project/geometry/factory/GeometryFactory.java index 1122245..8b8f369 100644 --- a/src/eu/engys/core/project/geometry/factory/GeometryFactory.java +++ b/src/eu/engys/core/project/geometry/factory/GeometryFactory.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.geometry.factory; import java.io.File; @@ -32,6 +31,7 @@ import eu.engys.core.project.Model; import eu.engys.core.project.geometry.FeatureLine; import eu.engys.core.project.geometry.Surface; import eu.engys.core.project.geometry.surface.Stl; +import eu.engys.core.project.geometry.surface.StlArea; import eu.engys.util.progress.ProgressMonitor; public interface GeometryFactory { @@ -43,6 +43,7 @@ public interface GeometryFactory { S newSurface(Class type, String name); Stl readSTL(File file, ProgressMonitor monitor); + StlArea readSTLArea(File file, ProgressMonitor monitor); FeatureLine readLine(File file); diff --git a/src/eu/engys/core/project/geometry/stl/AffineTransform.java b/src/eu/engys/core/project/geometry/stl/AffineTransform.java index 8f5a797..94ad1ee 100644 --- a/src/eu/engys/core/project/geometry/stl/AffineTransform.java +++ b/src/eu/engys/core/project/geometry/stl/AffineTransform.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.geometry.stl; @@ -33,10 +32,13 @@ import java.util.Locale; import javax.vecmath.Matrix3d; import javax.vecmath.Vector3d; -import vtk.vtkTransform; +import org.apache.commons.lang.builder.EqualsBuilder; +import org.apache.commons.lang.builder.HashCodeBuilder; + import eu.engys.core.dictionary.DefaultElement; import eu.engys.core.dictionary.Dictionary; import eu.engys.core.dictionary.ListField; +import vtk.vtkTransform; public class AffineTransform { @@ -74,7 +76,7 @@ public class AffineTransform { public AffineTransform(AffineTransform t) { setOrigin(t.getOrigin()); setScale(t.getScale()); - setTranslate(t.getTranslation()); + setTranslation(t.getTranslation()); setRotation(t.getRotation()); } @@ -90,7 +92,7 @@ public class AffineTransform { scaleZ = scale[2]; } - public void setTranslate(double[] translate) { + public void setTranslation(double[] translate) { posX = translate[0]; posY = translate[1]; posZ = translate[2]; @@ -151,6 +153,13 @@ public class AffineTransform { return t; } + public static AffineTransform getRotate(double dx, double dy, double dz) { + AffineTransform t = new AffineTransform(); + t.rotX = dx; + t.rotY = dx; + t.rotZ = dx; + return t; + } public static AffineTransform getRotateX(double dx) { AffineTransform t = new AffineTransform(); t.rotX = dx; @@ -172,7 +181,7 @@ public class AffineTransform { transform.setOrigin(new double[]{0, 0, 0}); transform.setRotation(t.GetOrientation()); transform.setScale(t.GetScale()); - transform.setTranslate(t.GetPosition()); + transform.setTranslation(t.GetPosition()); return transform; } @@ -192,15 +201,6 @@ public class AffineTransform { return transform; } - @Override - public boolean equals(Object obj) { - if (obj instanceof AffineTransform) { - AffineTransform t = (AffineTransform) obj; - return posX == t.posX && posY == t.posY && posZ == t.posZ && scaleX == t.scaleX && scaleY == t.scaleY && scaleZ == t.scaleZ && rotX == t.rotX && rotY == t.rotY && rotZ == t.rotZ; - } - return super.equals(obj); - } - public static AffineTransform fromGeometryDictionary(Dictionary g) { AffineTransform t = new AffineTransform(); if (g.isList(TRANSFORMS_KEY)) { @@ -213,7 +213,7 @@ public class AffineTransform { switch (type) { case TRANSLATE_KEY: double[] translate = d.lookupDoubleArray(TRANSLATE_VEC_KEY); - t.setTranslate(translate); + t.setTranslation(translate); break; case ROTATE_KEY: if (d.found(N1N2_KEY)) { @@ -353,4 +353,42 @@ public class AffineTransform { return Math.toDegrees(v1_xy.angle(v2_xy)); } + + @Override + public boolean equals(Object obj) { + if (!(obj instanceof AffineTransform)) { + return false; + } + if (obj == this) { + return true; + } + + AffineTransform fz = (AffineTransform) obj; + return new EqualsBuilder() + .append(posX, fz.posX) + .append(posY, fz.posY) + .append(posZ, fz.posZ) + .append(scaleX, fz.scaleX) + .append(scaleY, fz.scaleY) + .append(scaleZ, fz.scaleZ) + .append(rotX, fz.rotX) + .append(rotY, fz.rotY) + .append(rotZ, fz.rotZ) + .isEquals(); + } + + @Override + public int hashCode() { + return new HashCodeBuilder(17, 31) + .append(posX) + .append(posY) + .append(posZ) + .append(scaleX) + .append(scaleY) + .append(scaleZ) + .append(rotX) + .append(rotY) + .append(rotZ) + .toHashCode(); + } } diff --git a/src/eu/engys/core/project/geometry/stl/ImportIGES.java b/src/eu/engys/core/project/geometry/stl/ImportIGES.java index a227909..e483701 100644 --- a/src/eu/engys/core/project/geometry/stl/ImportIGES.java +++ b/src/eu/engys/core/project/geometry/stl/ImportIGES.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.geometry.stl; import static eu.engys.core.OpenFOAMEnvironment.getEnvironment; @@ -35,6 +34,7 @@ import static eu.engys.util.OpenFOAMCommands.CAD_TOOL; import java.io.File; import java.nio.file.Paths; +import eu.engys.core.controller.Controller; import eu.engys.core.controller.ScriptBuilder; import eu.engys.core.controller.actions.AbstractRunCommand; import eu.engys.core.executor.Executor; @@ -63,8 +63,8 @@ public class ImportIGES extends AbstractRunCommand { private File logFile; private Runnable loadSTLRunnable; - public ImportIGES(Model model, Runnable loadSTLRunnable, File[] input, File[] output, boolean split, double precision) { - super(model, null); + public ImportIGES(Model model, Controller controller, Runnable loadSTLRunnable, File[] input, File[] output, boolean split, double precision) { + super(model, controller); this.input = input; this.output = output; this.split = split; @@ -82,7 +82,7 @@ public class ImportIGES extends AbstractRunCommand { public void executeClient() { File script = getScript(); - ExecutorTerminal terminal = new TerminalExecutorMonitor(logFile); + ExecutorTerminal terminal = new TerminalExecutorMonitor(controller.getTerminalManager(), logFile); ExecutorMonitor monitor = new ExecutorMonitor(); monitor.addHook(ExecutorState.FINISH, new FinishHook()); @@ -101,7 +101,7 @@ public class ImportIGES extends AbstractRunCommand { } private void writeScript(ScriptBuilder sb) { - printHeader(sb, ACTION_NAME.toUpperCase()); + printHeader(sb, ACTION_NAME); printVariables(sb); loadEnvironment(sb); writeCommand(sb); diff --git a/src/eu/engys/core/project/geometry/stl/NastranReader.java b/src/eu/engys/core/project/geometry/stl/NastranReader.java index 8a37cbd..f67b39a 100644 --- a/src/eu/engys/core/project/geometry/stl/NastranReader.java +++ b/src/eu/engys/core/project/geometry/stl/NastranReader.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.geometry.stl; diff --git a/src/eu/engys/core/project/geometry/stl/RemoveDuplicates.java b/src/eu/engys/core/project/geometry/stl/RemoveDuplicates.java index 0d66ae8..97efb89 100644 --- a/src/eu/engys/core/project/geometry/stl/RemoveDuplicates.java +++ b/src/eu/engys/core/project/geometry/stl/RemoveDuplicates.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.geometry.stl; import java.util.Arrays; diff --git a/src/eu/engys/core/project/geometry/stl/STLAreaReader.java b/src/eu/engys/core/project/geometry/stl/STLAreaReader.java new file mode 100644 index 0000000..7c06c70 --- /dev/null +++ b/src/eu/engys/core/project/geometry/stl/STLAreaReader.java @@ -0,0 +1,114 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ + +package eu.engys.core.project.geometry.stl; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import eu.engys.core.project.geometry.surface.Solid; +import eu.engys.util.VTKSettings; +import eu.engys.util.progress.ProgressMonitor; +import vtk.vtkSTLReader; + +public class STLAreaReader { + + private static final Logger logger = LoggerFactory.getLogger(STLAreaReader.class); + + private static final long CHAR_PER_ROW = 30; + private static final int SIZE = 8192; + private static final int NP = 4; + + private final File sourceFile; + private final ProgressMonitor monitor; + + private List solids; + + public STLAreaReader(File source, ProgressMonitor monitor) { + this.sourceFile = source; + this.monitor = monitor; + this.solids = new ArrayList(); + } + + public void run() { + try { + initMonitor(); + readFile(); + } catch (Exception e) { + logAnError(e); + } finally { + monitor.setCurrent(null, monitor.getTotal()); + } + } + + void initMonitor() throws IOException { + int totalLines = count(sourceFile); + monitor.setTotal(totalLines); + monitor.setIndeterminate(false); + } + + void logAnError(Exception e) { + monitor.error(e.getMessage(), 1); + logger.error("Error reading STL file ", e); + solids.clear(); + } + + void readFile() throws Exception { + try { + logger.info("Read STL " + sourceFile.getName() + " [ASCII]"); + monitor.info(sourceFile.getName() + " [ASCII]", 2); + + Solid solid = new Solid("region"); + solids.add(solid); + if (VTKSettings.librariesAreLoaded()) { + vtkSTLReader reader = new vtkSTLReader(); + reader.SetFileName(sourceFile.getAbsolutePath()); + reader.Update(); + + solid.setDataSet(reader.GetOutput()); + + reader.Delete(); + } else { + logger.info("VTK not loaded!"); + } + } finally { + } + } + + private int count(File file) throws IOException { + int i = (int) (file.length() / CHAR_PER_ROW); + return i; + } + + public List getSolids() { + return solids; + } + +} diff --git a/src/eu/engys/core/project/geometry/stl/STLAreaWriter.java b/src/eu/engys/core/project/geometry/stl/STLAreaWriter.java new file mode 100644 index 0000000..61c7ecb --- /dev/null +++ b/src/eu/engys/core/project/geometry/stl/STLAreaWriter.java @@ -0,0 +1,110 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ + +package eu.engys.core.project.geometry.stl; + +import java.io.File; +import java.io.IOException; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import eu.engys.core.project.geometry.TransfromMode; +import eu.engys.core.project.geometry.surface.StlArea; +import eu.engys.util.VTKSettings; +import eu.engys.util.progress.ProgressMonitor; +import vtk.vtkSTLWriter; +import vtk.vtkTransform; +import vtk.vtkTransformFilter; + +public class STLAreaWriter implements Runnable { + + private static final Logger logger = LoggerFactory.getLogger(STLAreaWriter.class); + + private final File targetFile; + private final ProgressMonitor monitor; + private StlArea stlArea; + + public STLAreaWriter(File target, StlArea stlArea, ProgressMonitor monitor) { + this.targetFile = target; + this.stlArea = stlArea; + this.monitor = monitor; + } + + @Override + public void run() { + try { + initMonitor(); + writeFile(); + } catch (Exception e) { + logAnError(e); + } finally { + monitor.setCurrent(null, monitor.getTotal()); + } + } + + void initMonitor() throws IOException { + monitor.setTotal(10); + monitor.setCurrent(null, 0); + monitor.setIndeterminate(false); + } + + void logAnError(Exception e) { + monitor.error(e.getMessage(), 1); + logger.error("Error writing STL file ", e); + } + + void writeFile() throws Exception { + monitor.info(targetFile.getName() + " [ASCII]", 2); + logger.info("Write STL " + targetFile.getName() + " [ASCII]"); + + if (VTKSettings.librariesAreLoaded()) { + if (stlArea.getTransformMode() == TransfromMode.TO_FILE) { + vtkTransform transform = stlArea.getTransformation().toVTK(new vtkTransform()); + + vtkTransformFilter tFilter = new vtkTransformFilter(); + tFilter.SetTransform(transform); + tFilter.SetInputData(stlArea.getDataSet()); + tFilter.Update(); + + vtkSTLWriter write = new vtkSTLWriter(); + // write.SetFileTypeToASCII(); + write.SetFileName(targetFile.getAbsolutePath()); + write.SetInputData(tFilter.GetOutput()); + write.Write(); + } else { + vtkSTLWriter write = new vtkSTLWriter(); + // write.SetFileTypeToASCII(); + write.SetFileName(targetFile.getAbsolutePath()); + write.SetInputData(stlArea.getDataSet()); + write.Write(); + } + } else { + logger.warn("Write STL SKIPPED: no 3D"); + } + + } + +} diff --git a/src/eu/engys/core/project/geometry/stl/STLJoiner.java b/src/eu/engys/core/project/geometry/stl/STLJoiner.java index abeaf41..828018e 100644 --- a/src/eu/engys/core/project/geometry/stl/STLJoiner.java +++ b/src/eu/engys/core/project/geometry/stl/STLJoiner.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.geometry.stl; diff --git a/src/eu/engys/core/project/geometry/stl/STLManager.java b/src/eu/engys/core/project/geometry/stl/STLManager.java deleted file mode 100644 index ec8c89b..0000000 --- a/src/eu/engys/core/project/geometry/stl/STLManager.java +++ /dev/null @@ -1,76 +0,0 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - - -package eu.engys.core.project.geometry.stl; - -import java.io.File; - -import javax.inject.Inject; - -import org.apache.commons.io.FilenameUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import eu.engys.core.dictionary.Dictionary; -import eu.engys.core.project.Model; -import eu.engys.core.project.constant.TriSurfaceFolder; -import eu.engys.core.project.geometry.Surface; -import eu.engys.core.project.geometry.surface.Stl; -import eu.engys.util.progress.ProgressMonitor; - -public class STLManager { - - public static final String COPY_OF_PREFIX = "CopyOf"; - - private static final Logger logger = LoggerFactory.getLogger(STLManager.class); - - private ProgressMonitor monitor; - private TriSurfaceFolder triSurface; - private Model model; - - @Inject - public STLManager(Model model, ProgressMonitor monitor) { - this.monitor = monitor; - this.model = model; - this.triSurface = model.getProject().getConstantFolder().getTriSurface(); - } - - private Stl loadFromTriSurface(String fileName) { - Dictionary g = new Dictionary(fileName, Surface.stl); - g.setName(fileName); - g.add("name", FilenameUtils.removeExtension(fileName)); - - Stl stl = (Stl) model.getGeometry().getFactory().loadSurface(g, model, monitor); - return stl; - } - - public Stl copyAndLoadFile(File file, String name, boolean overwrite) { - triSurface.getFileManager().copyHere(file, name, overwrite); - return loadFromTriSurface(name); - } - - -} diff --git a/src/eu/engys/core/project/geometry/stl/STLReader.java b/src/eu/engys/core/project/geometry/stl/STLReader.java index c988c29..e79fb73 100644 --- a/src/eu/engys/core/project/geometry/stl/STLReader.java +++ b/src/eu/engys/core/project/geometry/stl/STLReader.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.geometry.stl; @@ -43,14 +42,9 @@ import javax.vecmath.Point3f; import javax.vecmath.Vector3f; import org.apache.commons.io.FileUtils; -import org.apache.log4j.Level; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import vtk.vtkCleanPolyData; -import vtk.vtkPolyData; -import vtk.vtkSTLReader; -import eu.engys.core.LoggerUtil; import eu.engys.core.project.geometry.surface.Solid; import eu.engys.util.TempFolder; import eu.engys.util.Util; @@ -58,6 +52,7 @@ import eu.engys.util.VTKSettings; import eu.engys.util.progress.ProgressMonitor; import eu.engys.util.progress.SilentMonitor; import eu.engys.util.ui.ExecUtil; +import vtk.vtkSTLReader; public class STLReader implements Runnable { @@ -96,8 +91,7 @@ public class STLReader implements Runnable { @Override public void run() { try { - initMonitor(); - initFilesIO(); + detectType(); readFile(); } catch (Exception e) { logAnError(e); @@ -107,15 +101,32 @@ public class STLReader implements Runnable { } } - void initMonitor() throws IOException { + void initASCIIMonitor() throws IOException { int totalLines = count(sourceFile); monitor.setTotal(totalLines); monitor.setIndeterminate(false); } + + void initBINARYMonitor(int totalLines) throws IOException { + monitor.setTotal(totalLines); + monitor.setIndeterminate(false); + } - void initFilesIO() throws IOException { - reader = new BufferedReader(new FileReader(sourceFile), SIZE); - } + private void detectType() throws IOException { + try(BufferedReader reader = new BufferedReader(new FileReader(sourceFile), SIZE)) { + String line1 = reader.readLine(); + String line2 = reader.readLine(); + // If the first word is not "solid" then we consider the file is binary + // Can give us problems if the comment of the binary file begins by "solid" + // Then we check also the second line for "facet normal" or "color" + if (line1.startsWith("solid") && line2 != null && (line2.contains("facet normal") || line2.contains("color"))) { + this.setAscii(true); + } else { + this.setAscii(false); + } + } catch (Exception e) { + } + } void logAnError(Exception e) { monitor.error(e.getMessage(), 1); @@ -124,34 +135,35 @@ public class STLReader implements Runnable { } void readFile() throws Exception { - if (reader.ready()) { - String line = reader.readLine(); - detectType(line); - - try { - executor = ExecUtil.createParallelExecutor(NP); - if (isAscii()) { - logger.info("Read STL " + sourceFile.getName() + " [ASCII]"); - monitor.info(sourceFile.getName() + " [ASCII]", 2); - - parseLine(line); - while ((line = reader.readLine()) != null && !line.isEmpty()) { - parseLine(line); - increaseCounter(); - } - - } else { - logger.info("Read STL " + sourceFile.getName() + " [BINARY]"); - monitor.info(sourceFile.getName() + " [BINARY]", 2); - readBinary(); - } - ExecUtil.awaitTermination(executor); - } finally { - closeFilesIO(); + try { + executor = ExecUtil.createParallelExecutor(NP); + if (isAscii()) { + logger.info("Read STL " + sourceFile.getName() + " [ASCII]"); + monitor.info(sourceFile.getName() + " [ASCII]", 2); + readAscii(); + } else { + logger.info("Read STL " + sourceFile.getName() + " [BINARY]"); + monitor.info(sourceFile.getName() + " [BINARY]", 2); + readBinary(); } + ExecUtil.awaitTermination(executor); + } finally { + closeFilesIO(); } } + private void readAscii() throws Exception { + initASCIIMonitor(); + reader = new BufferedReader(new FileReader(sourceFile), SIZE); + if (reader.ready()) { + String line = null; + while ((line = reader.readLine()) != null && !line.isEmpty()) { + parseLine(line); + increaseCounter(); + } + } + } + private void increaseCounter() { lineCounter++; if (lineCounter % 50000 == 0) @@ -168,16 +180,6 @@ public class STLReader implements Runnable { regionWriter = null; } - private void detectType(String line) { - if (line.startsWith("solid")) { - this.setAscii(true); - } else { - // If the first word is not "solid" then we consider the file is binary - // Can give us problems if the comment of the binary file begins by "solid" - this.setAscii(false); - } - } - private String regionName = ""; private File regionFile; private Solid solid; @@ -256,48 +258,9 @@ public class STLReader implements Runnable { reader.Delete(); } this.regionFile.delete(); - } } -// public static vtkPolyData repairDataSet(vtkPolyData dataset) { -// System.out.println("STLReader.repairDataSet() POINTS: " + dataset.GetNumberOfPoints()); -// System.out.println("STLReader.repairDataSet() LINES: " + dataset.GetNumberOfLines()); -// System.out.println("STLReader.repairDataSet() CELLS: " + dataset.GetNumberOfCells()); -// -// vtkPolyData pippo = new RemoveDuplicates(dataset).execute(); -// -// System.out.println("STLReader.repairDataSet() POINTS: " + repaired.GetNumberOfPoints()); -// System.out.println("STLReader.repairDataSet() LINES: " + repaired.GetNumberOfLines()); -// System.out.println("STLReader.repairDataSet() CELLS: " + repaired.GetNumberOfCells()); -// return pippo; -// } - - public static vtkPolyData repairDataSet(vtkPolyData dataset) { - System.out.println("STLReader.repairDataSet() POINTS: " + dataset.GetNumberOfPoints()); - System.out.println("STLReader.repairDataSet() LINES: " + dataset.GetNumberOfLines()); - System.out.println("STLReader.repairDataSet() CELLS: " + dataset.GetNumberOfCells()); - - vtkCleanPolyData clean = new vtkCleanPolyData(); - // clean.ConvertLinesToPointsOff(); //def: on - // clean.ConvertPolysToLinesOff(); //def: on - // clean.ConvertStripsToPolysOff(); //def: on - // clean.PieceInvariantOff(); //def: on - // clean.PointMergingOff(); //def: on - // clean.SetAbsoluteTolerance(0); //def: 1.0 - // clean.SetTolerance(0);//def: 0.0 - // clean.ToleranceIsAbsoluteOn(); //def: off - clean.SetInputData(dataset); - clean.Update(); - - vtkPolyData repaired = clean.GetOutput(); - System.out.println("STLReader.repairDataSet() POINTS: " + repaired.GetNumberOfPoints()); - System.out.println("STLReader.repairDataSet() LINES: " + repaired.GetNumberOfLines()); - System.out.println("STLReader.repairDataSet() CELLS: " + repaired.GetNumberOfCells()); - - return repaired; - } - private void setValidRegionName(String line) { int startIndex = line.indexOf(" "); if (startIndex < 0) { @@ -360,6 +323,8 @@ public class STLReader implements Runnable { Number_faces = dataBuffer.getInt(); + initBINARYMonitor(Number_faces); + Temp_Info = new byte[50 * Number_faces]; // Each face has 50 bytes of data data.read(Temp_Info); // We get the rest of the file @@ -390,6 +355,9 @@ public class STLReader implements Runnable { dataBuffer.get(); dataBuffer.get(); } + if (i % 500 == 0) { + monitor.setCurrent(null, i); + } } catch (IOException e) { // Quit System.out.println("Format Error: iteration number " + i); @@ -440,7 +408,7 @@ public class STLReader implements Runnable { } public static void main(String[] args) { - LoggerUtil.initTestLogger(Level.DEBUG); +// LoggerUtil.initTestLogger(Level.DEBUG); VTKSettings.LoadAllNativeLibraries(); new STLReader(new File("/home/stefano/ENGYS/examples/STL/plateExchanger.stl"), new SilentMonitor()).run(); diff --git a/src/eu/engys/core/project/geometry/stl/STLReplacer.java b/src/eu/engys/core/project/geometry/stl/STLReplacer.java index 4a8b4bd..e6a2de9 100644 --- a/src/eu/engys/core/project/geometry/stl/STLReplacer.java +++ b/src/eu/engys/core/project/geometry/stl/STLReplacer.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.geometry.stl; diff --git a/src/eu/engys/core/project/geometry/stl/STLWriter.java b/src/eu/engys/core/project/geometry/stl/STLWriter.java index a8c020f..5b0cd8c 100644 --- a/src/eu/engys/core/project/geometry/stl/STLWriter.java +++ b/src/eu/engys/core/project/geometry/stl/STLWriter.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.geometry.stl; diff --git a/src/eu/engys/core/project/geometry/stl/SolidWriter.java b/src/eu/engys/core/project/geometry/stl/SolidWriter.java index 549dd73..f8eca9a 100644 --- a/src/eu/engys/core/project/geometry/stl/SolidWriter.java +++ b/src/eu/engys/core/project/geometry/stl/SolidWriter.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.geometry.stl; import java.io.File; @@ -30,12 +29,12 @@ import java.io.File; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import vtk.vtkSTLWriter; -import vtk.vtkTransform; -import vtk.vtkTransformFilter; import eu.engys.core.project.geometry.TransfromMode; import eu.engys.core.project.geometry.surface.Solid; import eu.engys.util.Util; +import vtk.vtkSTLWriter; +import vtk.vtkTransform; +import vtk.vtkTransformFilter; public class SolidWriter implements Runnable { diff --git a/src/eu/engys/core/project/geometry/stl/TransformSTL.java b/src/eu/engys/core/project/geometry/stl/TransformSTL.java new file mode 100644 index 0000000..7148e11 --- /dev/null +++ b/src/eu/engys/core/project/geometry/stl/TransformSTL.java @@ -0,0 +1,171 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ + +package eu.engys.core.project.geometry.stl; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.IOException; +import java.nio.charset.Charset; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.List; +import java.util.concurrent.Callable; + +import org.apache.commons.io.FileUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import eu.engys.core.project.geometry.surface.Solid; +import eu.engys.util.progress.ProgressMonitor; +import vtk.vtkSTLReader; +import vtk.vtkSTLWriter; +import vtk.vtkTransform; +import vtk.vtkTransformFilter; + +public class TransformSTL implements Callable { + + public static final String COPY_OF_PREFIX = "CopyOf"; + private static final Logger logger = LoggerFactory.getLogger(TransformSTL.class); + + private ProgressMonitor monitor; + + private AffineTransform t; + private File toTransformFile; + + private File sourceFile; + private File targetFile; + + public TransformSTL(File toTransformFile, AffineTransform t, ProgressMonitor monitor) { + this.toTransformFile = toTransformFile; + this.t = t; + this.monitor = monitor; + } + + @Override + public File call() { + try { + initFiles(); + } catch (IOException e2) { + logger.error("[Transform STL] ", e2); + return toTransformFile; + } + + logger.info("[Transform STL] START: {} -> {}", sourceFile, targetFile); + monitor.info("Transforming " + sourceFile + " -> " + targetFile); + monitor.setIndeterminate(true); + + try { + BufferedWriter targetWriter = Files.newBufferedWriter(targetFile.toPath(), Charset.defaultCharset()); + STLReader reader = new STLReader(sourceFile, monitor); + reader.run(); + List solids = reader.getSolids(); + + for (Solid solid : solids) { + logger.info("[Transform STL] solid: {}", solid.getName()); +// File solidFile = solid.getFile(); +// Path transformedSolidPath = transformSolid(solidFile.toPath()); +// appendToMainWriter(targetWriter, transformedSolidPath, solid.getName()); + } + targetWriter.close(); + } catch (Exception e) { + try { + // If something goes wrong + FileUtils.copyFile(sourceFile, targetFile); + } catch (IOException e1) { + logger.error("[Transform STL] ", e1); + } + logger.error("[Transform STL] ", e); + } finally { + FileUtils.deleteQuietly(sourceFile); + logger.info("[Transform STL] FINISH: {}", toTransformFile.getName()); + } + + monitor.setIndeterminate(false); + return targetFile; + } + + private void initFiles() throws IOException { + // Better not use the original file name + String newNameSource= COPY_OF_PREFIX + "_source_" + toTransformFile.getName(); + String newNameTarget= COPY_OF_PREFIX + "_target_" + toTransformFile.getName(); + + FileUtils.copyFile(toTransformFile, new File(toTransformFile.getParent(), newNameSource)); + FileUtils.copyFile(toTransformFile, new File(toTransformFile.getParent(), newNameTarget)); + + this.sourceFile = new File(toTransformFile.getParentFile(), newNameSource); + this.targetFile = new File(toTransformFile.getParentFile(), newNameTarget); + + Files.deleteIfExists(targetFile.toPath()); + Files.createFile(targetFile.toPath()); + } + + private void appendToMainWriter(BufferedWriter targetWriter, Path transformedSolidPath, String solidName) throws Exception { + logger.debug("[Transform STL] Append solid {}", solidName); + BufferedReader br = Files.newBufferedReader(transformedSolidPath, Charset.defaultCharset()); + String line; + while ((line = br.readLine()) != null) { + if (line.startsWith("solid")) { + line = "solid " + solidName; + } + targetWriter.write(line); + targetWriter.newLine(); + } + br.close(); + } + + private Path transformSolid(Path solidPath) { + Path transformedSolidPath = solidPath.resolveSibling(solidPath.getFileName() + ".buffer"); + + vtkSTLReader sr = new vtkSTLReader(); + // sr.AddObserver("ProgressEvent", new ReaderProgress(sr, new + // SilentMonitor()), "progress"); + sr.SetFileName(solidPath.toString()); + sr.Update(); + + vtkTransform transform = new vtkTransform(); + transform.Translate(t.getTranslation()); + transform.Scale(t.getScale()); + transform.RotateX(t.getRotationX()); + transform.RotateY(t.getRotationY()); + transform.RotateZ(t.getRotationZ()); + + vtkTransformFilter tFilter = new vtkTransformFilter(); + tFilter.SetTransform(transform); + tFilter.SetInputData(sr.GetOutput()); + // tFilter.AddObserver("ProgressEvent", new ReaderProgress(tFilter, monitor), "progress"); + tFilter.Update(); + + vtkSTLWriter write = new vtkSTLWriter(); + // write.SetFileTypeToASCII(); + write.SetFileName(transformedSolidPath.toString()); + write.SetInputData(tFilter.GetOutput()); + // write.AddObserver("ProgressEvent", new ReaderProgress(write, monitor), "progress"); + write.Write(); + + return transformedSolidPath; + } +} diff --git a/src/eu/engys/core/project/geometry/surface/BaseSurface.java b/src/eu/engys/core/project/geometry/surface/BaseSurface.java index 76153c0..ed81797 100644 --- a/src/eu/engys/core/project/geometry/surface/BaseSurface.java +++ b/src/eu/engys/core/project/geometry/surface/BaseSurface.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.geometry.surface; @@ -30,7 +29,7 @@ import eu.engys.core.project.geometry.Surface; public abstract class BaseSurface extends Surface { - private static final String _REGION0 = "_region0"; + public static final String _REGION0 = "_region0"; public BaseSurface(String name) { super(name); diff --git a/src/eu/engys/core/project/geometry/surface/Box.java b/src/eu/engys/core/project/geometry/surface/Box.java index f9b1f06..2b9ec5d 100644 --- a/src/eu/engys/core/project/geometry/surface/Box.java +++ b/src/eu/engys/core/project/geometry/surface/Box.java @@ -1,48 +1,80 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.geometry.surface; -import vtk.vtkCubeSource; -import vtk.vtkPolyData; +import static eu.engys.core.dictionary.Dictionary.TYPE; +import static eu.engys.util.Util.round; + +import java.util.Arrays; + +import org.apache.commons.lang.ArrayUtils; + import eu.engys.core.dictionary.Dictionary; import eu.engys.core.project.geometry.Surface; import eu.engys.core.project.geometry.Type; +import vtk.vtkCubeSource; +import vtk.vtkPolyData; +import vtk.vtkTransform; +import vtk.vtkTransformFilter; public class Box extends BaseSurface { + public static final String MIN_KEY = "min"; + public static final String MAX_KEY = "max"; + public static final String CENTER_KEY = "center"; + public static final String DELTA_KEY = "delta"; + public static final String ROTATION_KEY = "rotation"; + + public static final double[] DEFAULT_MIN = { 0, 0, 0 }; + public static final double[] DEFAULT_MAX = { 2, 2, 2 }; + public static final double[] DEFAULT_CENTER = { 1, 1, 1 }; + public static final double[] DEFAULT_DELTA = { 2, 2, 2 }; + public static final double[] DEFAULT_ROTATION = { 0, 0, 0 }; + + private double[] min = DEFAULT_MIN; + private double[] max = DEFAULT_MAX; + private double[] center = DEFAULT_CENTER; + private double[] delta = DEFAULT_DELTA; + private double[] rotation = DEFAULT_ROTATION; + + public static final Dictionary box = new Dictionary("box") { + { + add(TYPE, Surface.SEARCHABLE_BOX_KEY); + add(Surface.MIN_KEY, new double[]{0, 0, 0}); + add(Surface.MAX_KEY, new double[]{2, 2, 1}); + } + }; + + /** * @deprecated Use GeometryFactory!! */ @Deprecated public Box(String name) { super(name); - Dictionary geometryDictionary = new Dictionary(box); - geometryDictionary.setName(name); - setGeometryDictionary(geometryDictionary); } @Override @@ -51,34 +83,189 @@ public class Box extends BaseSurface { } public double[] getMin() { - if (getGeometryDictionary() != null && getGeometryDictionary().found(MIN_KEY)) - return getGeometryDictionary().lookupDoubleArray(MIN_KEY); - else - return new double[] { 0, 0, 0 }; + return min; } - - public double[] getMax() { - if (getGeometryDictionary() != null && getGeometryDictionary().found(MAX_KEY)) - return getGeometryDictionary().lookupDoubleArray(MAX_KEY); - else - return new double[] { 0, 0, 0 }; + public void setMin(double[] min) { + firePropertyChange(MIN_KEY, this.min, this.min = min); + recalculateCenterAndDelta(); + } + public void setMin(double d1, double d2, double d3) { + setMin(new double[]{d1,d2,d3}); } - @Override + public double[] getMax() { + return max; + } + public void setMax(double[] max) { + firePropertyChange(MAX_KEY, this.max, this.max = max); + recalculateCenterAndDelta(); + } + public void setMax(double d1, double d2, double d3) { + setMax(new double[]{d1,d2,d3}); + } + + public double[] getCenter() { + return center; + } + public void setCenter(double[] center) { + firePropertyChange(CENTER_KEY, this.center, this.center = center); + recalculateMinMax(); + } + public void setCenter(double d1, double d2, double d3) { + setCenter(new double[]{d1,d2,d3}); + } + + public double[] getDelta() { + return delta; + } + public void setDelta(double[] delta) { + firePropertyChange(DELTA_KEY, this.delta, this.delta = delta); + recalculateMinMax(); + } + public void setDelta(double d1, double d2, double d3) { + setDelta(new double[]{d1,d2,d3}); + } + + public double[] getRotation() { + return rotation; + } + public void setRotation(double[] rotation) { + firePropertyChange(ROTATION_KEY, this.rotation, this.rotation = rotation); + } + public void setRotation(double d1, double d2, double d3) { + setRotation(new double[]{d1,d2,d3}); + } + + private void recalculateCenterAndDelta() { + double minX = min[0]; + double minY = min[1]; + double minZ = min[2]; + + double maxX = max[0]; + double maxY = max[1]; + double maxZ = max[2]; + + this.center = new double[] { (minX + maxX)/2, (minY + maxY)/2, (minZ + maxZ)/2 }; + this.delta = new double[] { maxX - minX, maxY - minY, maxZ - minZ }; + + round(center); + round(delta); + } + + private void recalculateMinMax() { + double oX = center[0]; + double oY = center[1]; + double oZ = center[2]; + + double dX = delta[0]; + double dY = delta[1]; + double dZ = delta[2]; + + this.min = new double[] { oX - dX/2, oY - dY/2, oZ - dZ/2 }; + this.max = new double[] { oX + dX/2, oY + dY/2, oZ + dZ/2 }; + round(min); + round(max); + } + + @Override public Surface cloneSurface() { - Surface box = new Box(name); + Box box = new Box(name); + box.min = ArrayUtils.clone(min); + box.max = ArrayUtils.clone(max); cloneSurface(box); return box; } + @Override + public void copyFrom(Surface delegate, boolean changeGeometry, boolean changeSurface, boolean changeVolume, boolean changeLayer, boolean changeZone) { + if (delegate instanceof Box) { + Box box = (Box) delegate; + if (changeGeometry) { + setMin(box.getMin()); + setMax(box.getMax()); + } + super.copyFrom(delegate, changeGeometry, changeSurface, changeVolume, changeLayer, changeZone); + } + } + @Override public vtkPolyData getDataSet() { - double[] min = getMin(); - double[] max = getMax(); + if (hasRotation()) { + double oX = center[0]; + double oY = center[1]; + double oZ = center[2]; + + double deltaX = delta[0]; + double deltaY = delta[1]; + double deltaZ = delta[2]; + + double rotX = rotation[0]; + double rotY = rotation[1]; + double rotZ = rotation[2]; + + vtkCubeSource cubeSource = new vtkCubeSource(); + cubeSource.SetCenter(oX, oY, oZ); + cubeSource.SetXLength(deltaX); + cubeSource.SetYLength(deltaY); + cubeSource.SetZLength(deltaZ); + cubeSource.Update(); + + vtkTransform t = new vtkTransform(); + t.PostMultiply(); + t.Translate(-oX, -oY, -oZ); + t.RotateY(rotY); + t.RotateX(rotX); + t.RotateZ(rotZ); + t.Translate(oX, oY, oZ); + + vtkTransformFilter filter = new vtkTransformFilter(); + filter.SetInputData(cubeSource.GetOutput()); + filter.SetTransform(t); + filter.Update(); + + return (vtkPolyData) filter.GetOutput(); + } else { + double[] min = getMin(); + double[] max = getMax(); + + vtkCubeSource cubeSource = new vtkCubeSource(); + cubeSource.SetBounds(min[0], max[0], min[1], max[1], min[2], max[2]); + cubeSource.Update(); + return cubeSource.GetOutput(); + } + } + + private boolean hasRotation() { + return rotation != null && (rotation[0] != 0 || rotation[1] != 0 || rotation[2] != 0); + } + + @Override + public Dictionary toGeometryDictionary() { + Dictionary d = new Dictionary(name, box); + d.add(Surface.MIN_KEY, min); + d.add(Surface.MAX_KEY, max); + return d; + } + + @Override + public void fromGeometryDictionary(Dictionary g) { + if (g != null && g.found(TYPE) && g.lookup(TYPE).equals(SEARCHABLE_BOX_KEY) ) { + if (g.found(MIN_KEY)) + setMin(g.lookupDoubleArray(MIN_KEY)); + else + setMin(DEFAULT_MIN); + + if (g.found(MAX_KEY)) + setMax(g.lookupDoubleArray(MAX_KEY)); + else + setMax(DEFAULT_MAX); + } + } + + @Override + public String toString() { + String string = super.toString(); - vtkCubeSource cubeSource = new vtkCubeSource(); - cubeSource.SetBounds(min[0], max[0], min[1], max[1], min[2], max[2]); - cubeSource.Update(); - return cubeSource.GetOutput(); + return string + String.format("[ min: %s, max: %s] ", Arrays.toString(min), Arrays.toString(max)); } } diff --git a/src/eu/engys/core/project/geometry/surface/Cylinder.java b/src/eu/engys/core/project/geometry/surface/Cylinder.java index 2ae8d18..4a12c0c 100644 --- a/src/eu/engys/core/project/geometry/surface/Cylinder.java +++ b/src/eu/engys/core/project/geometry/surface/Cylinder.java @@ -1,49 +1,68 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.geometry.surface; -import vtk.vtkLineSource; -import vtk.vtkPolyData; -import vtk.vtkTubeFilter; +import static eu.engys.core.dictionary.Dictionary.TYPE; + +import java.util.Arrays; + +import org.apache.commons.lang.ArrayUtils; + import eu.engys.core.dictionary.Dictionary; import eu.engys.core.project.geometry.Surface; import eu.engys.core.project.geometry.Type; +import vtk.vtkLineSource; +import vtk.vtkPolyData; +import vtk.vtkTubeFilter; public class Cylinder extends BaseSurface { - /** + public static final double[] DEFAULT_P1 = {0,0,0}; + public static final double[] DEFAULT_P2 = {1,0,0}; + public static final double DEFAULT_RADIUS = 1.0; + + private double[] point1 = DEFAULT_P1; + private double[] point2 = DEFAULT_P2; + private double radius = DEFAULT_RADIUS; + + public static final Dictionary cylinder = new Dictionary("cylinder") { + { + add(TYPE, Surface.SEARCHABLE_CYLINDER_KEY); + add(Surface.POINT1_KEY, "(0 0 0)"); + add(Surface.POINT2_KEY, "(1 0 0)"); + add(Surface.RADIUS_KEY, "1.0"); + } + }; + + /** * @deprecated Use GeometryFactory!! */ @Deprecated public Cylinder(String name) { super(name); - Dictionary geometryDictionary = new Dictionary(cylinder); - geometryDictionary.setName(name); - setGeometryDictionary(geometryDictionary); } @Override @@ -52,31 +71,53 @@ public class Cylinder extends BaseSurface { } public double[] getPoint1() { - if (getGeometryDictionary() != null && getGeometryDictionary().found(POINT1_KEY)) - return getGeometryDictionary().lookupDoubleArray(POINT1_KEY); - else - return new double[] { 0, 0, 0 }; + return point1; } - + public void setPoint1(double[] point1) { + firePropertyChange("point1", this.point1, this.point1 = point1); + } + public void setPoint1(double d1, double d2, double d3) { + setPoint1(new double[]{d1,d2,d3}); + } + public double[] getPoint2() { - if (getGeometryDictionary() != null && getGeometryDictionary().found(POINT2_KEY)) - return getGeometryDictionary().lookupDoubleArray(POINT2_KEY); - else - return new double[] { 0, 0, 0 }; + return point2; } - + public void setPoint2(double[] point2) { + firePropertyChange("point2", this.point2, this.point2 = point2); + } + public void setPoint2(double d1, double d2, double d3) { + setPoint2(new double[]{d1,d2,d3}); + } + public double getRadius() { - if (getGeometryDictionary() != null && getGeometryDictionary().found(RADIUS_KEY)) - return Double.valueOf(getGeometryDictionary().lookup(RADIUS_KEY)); - else - return 0; + return radius; } + public void setRadius(double radius) { + firePropertyChange("radius", this.radius, this.radius = radius); + } @Override public Surface cloneSurface() { - Surface box = new Cylinder(name); - cloneSurface(box); - return box; + Cylinder cyl = new Cylinder(name); + cyl.point1 = ArrayUtils.clone(point1); + cyl.point2 = ArrayUtils.clone(point2); + cyl.radius = radius; + cloneSurface(cyl); + return cyl; + } + + @Override + public void copyFrom(Surface delegate, boolean changeGeometry, boolean changeSurface, boolean changeVolume, boolean changeLayer, boolean changeZone) { + if (delegate instanceof Cylinder) { + Cylinder cyl = (Cylinder) delegate; + if (changeGeometry) { + setPoint1(cyl.getPoint1()); + setPoint2(cyl.getPoint2()); + setRadius(cyl.getRadius()); + } + super.copyFrom(delegate, changeGeometry, changeSurface, changeVolume, changeLayer, changeZone); + } } @Override @@ -99,4 +140,41 @@ public class Cylinder extends BaseSurface { return tubeFilter.GetOutput(); } + + @Override + public Dictionary toGeometryDictionary() { + Dictionary d = new Dictionary(name, cylinder); + d.add(POINT1_KEY, point1); + d.add(POINT2_KEY, point2); + d.add(RADIUS_KEY, radius); + return d; + } + + @Override + public void fromGeometryDictionary(Dictionary g) { + if (g != null && g.found(TYPE) && g.lookup(TYPE).equals(SEARCHABLE_CYLINDER_KEY) ) { + if (g.found(POINT1_KEY)) + setPoint1(g.lookupDoubleArray(POINT1_KEY)); + else + setPoint1(DEFAULT_P1); + + if (g.found(POINT2_KEY)) + setPoint2(g.lookupDoubleArray(POINT2_KEY)); + else + setPoint2(DEFAULT_P2); + + if (g.found(RADIUS_KEY)) + setRadius(g.lookupDouble(RADIUS_KEY)); + else + setRadius(DEFAULT_RADIUS); + } + } + + @Override + public String toString() { + String string = super.toString(); + + return string + String.format("[ p1: %s, p2: %s, radius: %s] ", Arrays.toString(point1), Arrays.toString(point2), radius); + } + } diff --git a/src/eu/engys/core/project/geometry/surface/MultiPlane.java b/src/eu/engys/core/project/geometry/surface/MultiPlane.java index 972ff8d..0f32d70 100644 --- a/src/eu/engys/core/project/geometry/surface/MultiPlane.java +++ b/src/eu/engys/core/project/geometry/surface/MultiPlane.java @@ -1,43 +1,70 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.geometry.surface; -import static eu.engys.core.project.system.BlockMeshDict.ELEMENTS_KEY; -import vtk.vtkPolyData; import eu.engys.core.dictionary.Dictionary; import eu.engys.core.project.geometry.Surface; import eu.engys.core.project.geometry.Type; +import vtk.vtkPolyData; public class MultiPlane extends MultiRegion { + public static final double[] DEFAULT_MIN = {0,0,0}; + public static final double[] DEFAULT_MAX = {1,1,1}; + public static final int[] DEFAULT_ELEMENTS = {10,10,10}; + + private double[] min = DEFAULT_MIN; + private double[] max = DEFAULT_MAX; + private int[] elements = DEFAULT_ELEMENTS; + public MultiPlane(String name) { super(name); } + public double[] getMin() { + return min; + } + public void setMin(double[] min) { + firePropertyChange(MIN_KEY, this.min, this.min = min); + } + + public double[] getMax() { + return max; + } + public void setMax(double[] max) { + firePropertyChange(MAX_KEY, this.max, this.max = max); + } + + public int[] getElements() { + return elements; + } + public void setElements(int[] elements) { + firePropertyChange(ELEMENTS_KEY, this.elements, this.elements = elements); + } + public void addPlane(String name) { if (!regionsMap.containsKey(name)) { PlaneRegion newPlane = new PlaneRegion(name); @@ -68,23 +95,11 @@ public class MultiPlane extends MultiRegion { } @Override - public void setGeometryDictionary(Dictionary d) { - super.setGeometryDictionary(d); - - double[] min = d.lookupDoubleArray(MIN_KEY); - double[] max = d.lookupDoubleArray(MAX_KEY); - int[] res = d.lookupIntArray(ELEMENTS_KEY); - - if (regions.size() == 6) { - setPlane(regions.get(0).getName(), new double[] { min[0], min[1], min[2] }, new double[] { min[0], max[1], min[2] }, new double[] { min[0], min[1], max[2] }, res[1], res[2]); - setPlane(regions.get(1).getName(), new double[] { max[0], min[1], min[2] }, new double[] { max[0], max[1], min[2] }, new double[] { max[0], min[1], max[2] }, res[1], res[2]); - - setPlane(regions.get(2).getName(), new double[] { min[0], min[1], min[2] }, new double[] { max[0], min[1], min[2] }, new double[] { min[0], min[1], max[2] }, res[0], res[2]); - setPlane(regions.get(3).getName(), new double[] { min[0], max[1], min[2] }, new double[] { max[0], max[1], min[2] }, new double[] { min[0], max[1], max[2] }, res[0], res[2]); - - setPlane(regions.get(4).getName(), new double[] { min[0], min[1], min[2] }, new double[] { max[0], min[1], min[2] }, new double[] { min[0], max[1], min[2] }, res[0], res[1]); - setPlane(regions.get(5).getName(), new double[] { min[0], min[1], max[2] }, new double[] { max[0], min[1], max[2] }, new double[] { min[0], max[1], max[2] }, res[0], res[1]); - } + public void fromGeometryDictionary(Dictionary g) { + } + @Override + public Dictionary toGeometryDictionary() { + return null; } @Override @@ -109,17 +124,9 @@ public class MultiPlane extends MultiRegion { public double[] getDelta() { double[] delta = new double[3]; - - if (getGeometryDictionary() != null) { - double[] min = getGeometryDictionary().lookupDoubleArray(MIN_KEY); - double[] max = getGeometryDictionary().lookupDoubleArray(MAX_KEY); - int[] res = getGeometryDictionary().lookupIntArray(ELEMENTS_KEY); - - for (int i = 0; i < delta.length; i++) { - delta[i] = (max[i] - min[i]) / res[i]; - } + for (int i = 0; i < delta.length; i++) { + delta[i] = (max[i] - min[i]) / elements[i]; } - return delta; } @@ -134,4 +141,17 @@ public class MultiPlane extends MultiRegion { public vtkPolyData getDataSet() { return null; } + + public void updatePlanes() { + if (regions.size() == 6) { + setPlane(regions.get(0).getName(), new double[] { min[0], min[1], min[2] }, new double[] { min[0], max[1], min[2] }, new double[] { min[0], min[1], max[2] }, elements[1], elements[2]); + setPlane(regions.get(1).getName(), new double[] { max[0], min[1], min[2] }, new double[] { max[0], max[1], min[2] }, new double[] { max[0], min[1], max[2] }, elements[1], elements[2]); + + setPlane(regions.get(2).getName(), new double[] { min[0], min[1], min[2] }, new double[] { max[0], min[1], min[2] }, new double[] { min[0], min[1], max[2] }, elements[0], elements[2]); + setPlane(regions.get(3).getName(), new double[] { min[0], max[1], min[2] }, new double[] { max[0], max[1], min[2] }, new double[] { min[0], max[1], max[2] }, elements[0], elements[2]); + + setPlane(regions.get(4).getName(), new double[] { min[0], min[1], min[2] }, new double[] { max[0], min[1], min[2] }, new double[] { min[0], max[1], min[2] }, elements[0], elements[1]); + setPlane(regions.get(5).getName(), new double[] { min[0], min[1], max[2] }, new double[] { max[0], min[1], max[2] }, new double[] { min[0], max[1], max[2] }, elements[0], elements[1]); + } + } } diff --git a/src/eu/engys/core/project/geometry/surface/MultiRegion.java b/src/eu/engys/core/project/geometry/surface/MultiRegion.java index b5e10b5..db4e92e 100644 --- a/src/eu/engys/core/project/geometry/surface/MultiRegion.java +++ b/src/eu/engys/core/project/geometry/surface/MultiRegion.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.geometry.surface; @@ -131,4 +130,9 @@ public abstract class MultiRegion extends Surface { public boolean isModified() { return modified; } + + @Override + public void copyFrom(Surface delegate, boolean changeGeometry, boolean changeSurface, boolean changeVolume, boolean changeLayer, boolean changeZone) { + super.copyFrom(delegate, changeGeometry, changeSurface, changeVolume, changeLayer, changeZone); + } } diff --git a/src/eu/engys/core/project/geometry/surface/NullSurface.java b/src/eu/engys/core/project/geometry/surface/NullSurface.java index 3650db6..47948f7 100644 --- a/src/eu/engys/core/project/geometry/surface/NullSurface.java +++ b/src/eu/engys/core/project/geometry/surface/NullSurface.java @@ -1,33 +1,33 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.geometry.surface; -import vtk.vtkPolyData; +import eu.engys.core.dictionary.Dictionary; import eu.engys.core.project.geometry.Surface; import eu.engys.core.project.geometry.Type; +import vtk.vtkPolyData; public class NullSurface extends Surface { @@ -88,9 +88,20 @@ public class NullSurface extends Surface { public Surface cloneSurface() { return new NullSurface(name); } + + @Override + public void copyFrom(Surface delegate, boolean changeGeometry, boolean changeSurface, boolean changeVolume, boolean changeLayer, boolean changeZone) { + } @Override public vtkPolyData getDataSet() { return null; } -} + @Override + public void fromGeometryDictionary(Dictionary g) { + } + @Override + public Dictionary toGeometryDictionary() { + return null; + } +} \ No newline at end of file diff --git a/src/eu/engys/core/project/geometry/surface/Plane.java b/src/eu/engys/core/project/geometry/surface/Plane.java index 9f53e2f..118e127 100644 --- a/src/eu/engys/core/project/geometry/surface/Plane.java +++ b/src/eu/engys/core/project/geometry/surface/Plane.java @@ -1,40 +1,60 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.geometry.surface; -import vtk.vtkPlaneSource; -import vtk.vtkPolyData; +import static eu.engys.core.dictionary.Dictionary.TYPE; + +import org.apache.commons.lang.ArrayUtils; + import eu.engys.core.dictionary.Dictionary; import eu.engys.core.project.geometry.Surface; import eu.engys.core.project.geometry.Type; +import vtk.vtkPlaneSource; +import vtk.vtkPolyData; public class Plane extends BaseSurface { - private double diagonal = 1; + public static final double DEFAULT_DIAGONAL = 1; + public static final double[] DEFAULT_CENTER = {0,0,0}; + public static final double[] DEFAULT_NORMAL = {0,0,1}; + + private double[] basePoint = DEFAULT_CENTER; + private double[] normalVector = DEFAULT_NORMAL; + private double diagonal = DEFAULT_DIAGONAL; + + public static final Dictionary planeWithCenter = new Dictionary("plane") { + { + add(TYPE, SEARCHABLE_PLANE_KEY); + add(PLANE_TYPE_KEY, POINT_AND_NORMAL_KEY); + Dictionary dict = new Dictionary(POINT_AND_NORMAL_DICT_KEY); + dict.add(BASE_POINT_KEY, "(0 0 0)"); + dict.add(NORMAL_VECTOR_KEY, "(0 0 1)"); + add(dict); + } + }; /** * @deprecated Use GeometryFactory!! @@ -42,9 +62,6 @@ public class Plane extends BaseSurface { @Deprecated public Plane(String name) { super(name); - Dictionary geometryDictionary = new Dictionary(plane); - geometryDictionary.setName(name); - setGeometryDictionary(geometryDictionary); } @Override @@ -52,32 +69,18 @@ public class Plane extends BaseSurface { return Type.PLANE; } - public double[] getCenter() { - if (getGeometryDictionary() != null && getGeometryDictionary().subDict(POINT_AND_NORMAL_DICT_KEY) != null && getGeometryDictionary().subDict(POINT_AND_NORMAL_DICT_KEY).found(BASE_POINT_KEY)) - return getGeometryDictionary().subDict(POINT_AND_NORMAL_DICT_KEY).lookupDoubleArray(BASE_POINT_KEY); - else - return null; + public double[] getBasePoint() { + return basePoint; } - - public void setCenter(double[] center) { - if (getGeometryDictionary() != null && getGeometryDictionary().isDictionary(POINT_AND_NORMAL_DICT_KEY)){ - Dictionary dict = getGeometryDictionary().subDict(POINT_AND_NORMAL_DICT_KEY); - dict.add(BASE_POINT_KEY, center); - } + public void setBasePoint(double[] basePoint) { + firePropertyChange(BASE_POINT_KEY, this.basePoint, this.basePoint = basePoint); } - public double[] getNormal() { - if (getGeometryDictionary() != null && getGeometryDictionary().subDict(POINT_AND_NORMAL_DICT_KEY) != null && getGeometryDictionary().subDict(POINT_AND_NORMAL_DICT_KEY).found(NORMAL_VECTOR_KEY)) - return getGeometryDictionary().subDict(POINT_AND_NORMAL_DICT_KEY).lookupDoubleArray(NORMAL_VECTOR_KEY); - else - return null; - } - - public void setNormal(double[] normal) { - if (getGeometryDictionary() != null && getGeometryDictionary().isDictionary(POINT_AND_NORMAL_DICT_KEY)){ - Dictionary dict = getGeometryDictionary().subDict(POINT_AND_NORMAL_DICT_KEY); - dict.add(NORMAL_VECTOR_KEY, normal); - } + public double[] getNormalVector() { + return normalVector; + } + public void setNormalVector(double[] normalVector) { + firePropertyChange(NORMAL_VECTOR_KEY, this.normalVector, this.normalVector = normalVector); } public void setDiagonal(double diagonal) { @@ -93,20 +96,59 @@ public class Plane extends BaseSurface { Plane plane = new Plane(name); cloneSurface(plane); plane.diagonal = this.diagonal; + plane.basePoint = ArrayUtils.clone(basePoint); + plane.normalVector = ArrayUtils.clone(normalVector); return plane; } + @Override + public void copyFrom(Surface delegate, boolean changeGeometry, boolean changeSurface, boolean changeVolume, boolean changeLayer, boolean changeZone) { + if (delegate instanceof Plane) { + Plane plane = (Plane) delegate; + if (changeGeometry) { + setBasePoint(plane.getBasePoint()); + setNormalVector(plane.getNormalVector()); + } + super.copyFrom(delegate, changeGeometry, changeSurface, changeVolume, changeLayer, changeZone); + } + } + @Override public vtkPolyData getDataSet() { - vtkPlaneSource planeSource = new vtkPlaneSource(); planeSource.SetOrigin(0, 0, 0); planeSource.SetPoint1(diagonal, 0, 0); planeSource.SetPoint2(0, diagonal, 0); - planeSource.SetCenter(getCenter()); - planeSource.SetNormal(getNormal()); + planeSource.SetCenter(getBasePoint()); + planeSource.SetNormal(getNormalVector()); planeSource.Update(); return planeSource.GetOutput(); } + + @Override + public Dictionary toGeometryDictionary() { + Dictionary d = new Dictionary(name, planeWithCenter); + d.subDict(POINT_AND_NORMAL_DICT_KEY).add(BASE_POINT_KEY, basePoint); + d.subDict(POINT_AND_NORMAL_DICT_KEY).add(NORMAL_VECTOR_KEY, normalVector); + return d; + } + + @Override + public void fromGeometryDictionary(Dictionary g) { + if (g != null && g.found(TYPE) && g.lookup(TYPE).equals(SEARCHABLE_PLANE_KEY) ) { + if (g.isDictionary(POINT_AND_NORMAL_DICT_KEY)) { + Dictionary subDict = g.subDict(POINT_AND_NORMAL_DICT_KEY); + if (subDict.found(BASE_POINT_KEY)) + setBasePoint(subDict.lookupDoubleArray(BASE_POINT_KEY)); + else + setBasePoint(DEFAULT_CENTER); + + if (subDict.found(NORMAL_VECTOR_KEY)) + setNormalVector(subDict.lookupDoubleArray(NORMAL_VECTOR_KEY)); + else + setNormalVector(DEFAULT_NORMAL); + } + } + } } diff --git a/src/eu/engys/core/project/geometry/surface/PlaneRegion.java b/src/eu/engys/core/project/geometry/surface/PlaneRegion.java index b8c82e6..ba1fabb 100644 --- a/src/eu/engys/core/project/geometry/surface/PlaneRegion.java +++ b/src/eu/engys/core/project/geometry/surface/PlaneRegion.java @@ -1,35 +1,35 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.geometry.surface; -import vtk.vtkPlaneSource; -import vtk.vtkPolyData; +import eu.engys.core.dictionary.Dictionary; import eu.engys.core.project.geometry.Surface; import eu.engys.core.project.geometry.Type; +import vtk.vtkPlaneSource; +import vtk.vtkPolyData; public class PlaneRegion extends Region { @@ -114,4 +114,13 @@ public class PlaneRegion extends Region { return region; } + + @Override + public Dictionary toGeometryDictionary() { + return null; + } + + @Override + public void fromGeometryDictionary(Dictionary g) { + } } diff --git a/src/eu/engys/core/project/geometry/surface/Region.java b/src/eu/engys/core/project/geometry/surface/Region.java index 29c6f22..88fb802 100644 --- a/src/eu/engys/core/project/geometry/surface/Region.java +++ b/src/eu/engys/core/project/geometry/surface/Region.java @@ -1,31 +1,31 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.geometry.surface; +import eu.engys.core.project.geometry.Surface; import eu.engys.core.project.geometry.Type; public abstract class Region extends BaseSurface { @@ -58,12 +58,9 @@ public abstract class Region extends BaseSurface { return parent.getPatchName() + "_" + getName(); } } - -// @Override -// public Surface cloneSurface() { -// Surface region = new Region(name); -// cloneSurface(region); -// return region; -// } + @Override + public void copyFrom(Surface delegate, boolean changeGeometry, boolean changeSurface, boolean changeVolume, boolean changeLayer, boolean changeZone) { + super.copyFrom(delegate, changeGeometry, changeSurface, changeVolume, changeLayer, false); + } } diff --git a/src/eu/engys/core/project/geometry/surface/Ring.java b/src/eu/engys/core/project/geometry/surface/Ring.java index 50363d1..f855776 100644 --- a/src/eu/engys/core/project/geometry/surface/Ring.java +++ b/src/eu/engys/core/project/geometry/surface/Ring.java @@ -1,31 +1,37 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.geometry.surface; +import static eu.engys.core.dictionary.Dictionary.TYPE; + +import org.apache.commons.lang.ArrayUtils; + +import eu.engys.core.dictionary.Dictionary; +import eu.engys.core.project.geometry.Surface; +import eu.engys.core.project.geometry.Type; import vtk.vtkAppendPolyData; import vtk.vtkCellArray; import vtk.vtkIdList; @@ -33,21 +39,35 @@ import vtk.vtkLineSource; import vtk.vtkPolyData; import vtk.vtkPolyDataNormals; import vtk.vtkTubeFilter; -import eu.engys.core.dictionary.Dictionary; -import eu.engys.core.project.geometry.Surface; -import eu.engys.core.project.geometry.Type; public class Ring extends BaseSurface { - /** + public static final double[] DEFAULT_P1 = {0,0,0}; + public static final double[] DEFAULT_P2 = {1,0,0}; + public static final double DEFAULT_RADIUS1 = 1.0; + public static final double DEFAULT_RADIUS2 = 2.0; + + private double[] point1 = DEFAULT_P1; + private double[] point2 = DEFAULT_P2; + private double innerRadius = DEFAULT_RADIUS1; + private double outerRadius = DEFAULT_RADIUS2; + + public static final Dictionary ring = new Dictionary("ring") { + { + add(TYPE, SEARCHABLE_RING_KEY); + add(POINT1_KEY, "(0 0 0)"); + add(POINT2_KEY, "(0.05 0 0)"); + add(INNER_RADIUS_KEY, "0.2"); + add(OUTER_RADIUS_KEY, "0.5"); + } + }; + + /** * @deprecated Use GeometryFactory!! */ @Deprecated public Ring(String name) { super(name); - Dictionary geometryDictionary = new Dictionary(ring); - geometryDictionary.setName(name); - setGeometryDictionary(geometryDictionary); } @Override @@ -56,39 +76,63 @@ public class Ring extends BaseSurface { } public double[] getPoint1() { - if (getGeometryDictionary() != null && getGeometryDictionary().found(POINT1_KEY)) - return getGeometryDictionary().lookupDoubleArray(POINT1_KEY); - else - return new double[] { 0, 0, 0 }; + return point1; } + public void setPoint1(double[] point1) { + firePropertyChange(POINT1_KEY, this.point1, this.point1 = point1); + } + public void setPoint1(double d1, double d2, double d3) { + setPoint1(new double[]{d1,d2,d3}); + } public double[] getPoint2() { - if (getGeometryDictionary() != null && getGeometryDictionary().found(POINT2_KEY)) - return getGeometryDictionary().lookupDoubleArray(POINT2_KEY); - else - return new double[] { 0, 0, 0 }; + return point2; } + public void setPoint2(double[] point2) { + firePropertyChange(POINT2_KEY, this.point2, this.point2 = point2); + } + public void setPoint2(double d1, double d2, double d3) { + setPoint2(new double[]{d1,d2,d3}); + } public double getInnerRadius() { - if (getGeometryDictionary() != null && getGeometryDictionary().found(INNER_RADIUS_KEY)) - return Double.valueOf(getGeometryDictionary().lookup(INNER_RADIUS_KEY)); - else - return 0; + return innerRadius; } - + public void setInnerRadius(double innerRadius) { + firePropertyChange(INNER_RADIUS_KEY, this.innerRadius, this.innerRadius = innerRadius); + } + public double getOuterRadius() { - if (getGeometryDictionary() != null && getGeometryDictionary().found(OUTER_RADIUS_KEY)) - return Double.valueOf(getGeometryDictionary().lookup(OUTER_RADIUS_KEY)); - else - return 0; + return outerRadius; } + public void setOuterRadius(double outerRadius) { + firePropertyChange(OUTER_RADIUS_KEY, this.outerRadius, this.outerRadius = outerRadius); + } @Override public Surface cloneSurface() { - Surface box = new Ring(name); - cloneSurface(box); - return box; + Ring ring = new Ring(name); + ring.point1 = ArrayUtils.clone(point1); + ring.point2 = ArrayUtils.clone(point2); + ring.innerRadius = innerRadius; + ring.outerRadius = outerRadius; + cloneSurface(ring); + return ring; } + + @Override + public void copyFrom(Surface delegate, boolean changeGeometry, boolean changeSurface, boolean changeVolume, boolean changeLayer, boolean changeZone) { + if (delegate instanceof Ring) { + Ring ring = (Ring) delegate; + if (changeGeometry) { + setPoint1(ring.getPoint1()); + setPoint2(ring.getPoint2()); + setInnerRadius(ring.getInnerRadius()); + setOuterRadius(ring.getOuterRadius()); + } + super.copyFrom(delegate, changeGeometry, changeSurface, changeVolume, changeLayer, changeZone); + } + } @Override public vtkPolyData getDataSet() { @@ -156,4 +200,39 @@ public class Ring extends BaseSurface { return normals.GetOutput(); } + + @Override + public Dictionary toGeometryDictionary() { + Dictionary d = new Dictionary(name, ring); + d.add(POINT1_KEY, point1); + d.add(POINT2_KEY, point2); + d.add(INNER_RADIUS_KEY, innerRadius); + d.add(OUTER_RADIUS_KEY, outerRadius); + return d; + } + + @Override + public void fromGeometryDictionary(Dictionary g) { + if (g != null && g.found(TYPE) && g.lookup(TYPE).equals(SEARCHABLE_RING_KEY) ) { + if (g.found(POINT1_KEY)) + setPoint1(g.lookupDoubleArray(POINT1_KEY)); + else + setPoint1(DEFAULT_P1); + + if (g.found(POINT2_KEY)) + setPoint2(g.lookupDoubleArray(POINT2_KEY)); + else + setPoint2(DEFAULT_P2); + + if (g.found(INNER_RADIUS_KEY)) + setInnerRadius(g.lookupDouble(INNER_RADIUS_KEY)); + else + setInnerRadius(DEFAULT_RADIUS1); + + if (g.found(OUTER_RADIUS_KEY)) + setOuterRadius(g.lookupDouble(OUTER_RADIUS_KEY)); + else + setOuterRadius(DEFAULT_RADIUS1); + } + } } diff --git a/src/eu/engys/core/project/geometry/surface/RotatedBox.java b/src/eu/engys/core/project/geometry/surface/RotatedBox.java new file mode 100644 index 0000000..dccfab9 --- /dev/null +++ b/src/eu/engys/core/project/geometry/surface/RotatedBox.java @@ -0,0 +1,249 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.core.project.geometry.surface; + +import java.util.Arrays; + +import javax.vecmath.Vector2d; + +import org.apache.commons.lang.ArrayUtils; + +import eu.engys.core.dictionary.Dictionary; +import eu.engys.core.project.geometry.Surface; +import eu.engys.core.project.geometry.Type; +import vtk.vtkCellArray; +import vtk.vtkIdList; +import vtk.vtkPoints; +import vtk.vtkPolyData; + +public class RotatedBox extends BaseSurface { + + public static final String ORIGIN_KEY = "origin"; + public static final String I_KEY = "i"; + public static final String J_KEY = "j"; + public static final String K_KEY = "k"; + + public static final double[] DEFAULT_ORIGIN = { 0, 0, 0 }; + public static final double[] DEFAULT_I = { 1, 0, 0 }; + public static final double[] DEFAULT_J = { 0, 1, 0 }; + public static final double[] DEFAULT_K = { 0, 0, 1 }; + + private double[] origin = DEFAULT_ORIGIN; + private double[] i = DEFAULT_I; + private double[] j = DEFAULT_J; + private double[] k = DEFAULT_K; + + /** + * @deprecated Use GeometryFactory!! + */ + @Deprecated + public RotatedBox(String name) { + super(name); + } + + @Override + public Type getType() { + return Type.RBOX; + } + + public double[] getOrigin() { + return origin; + } + public void setOrigin(double[] origin) { + firePropertyChange(ORIGIN_KEY, this.origin, this.origin = origin); + } + public void setOrigin(double d1, double d2, double d3) { + setOrigin(new double[]{d1,d2,d3}); + } + + public double[] getI() { + return i; + } + public void setI(double[] i) { + firePropertyChange(I_KEY, this.i, this.i = i); + } + public void setI(double d1, double d2, double d3) { + setI(new double[]{d1,d2,d3}); + } + + public double[] getJ() { + return j; + } + public void setJ(double[] j) { + firePropertyChange(J_KEY, this.j, this.j = j); + } + public void setJ(double d1, double d2, double d3) { + setJ(new double[]{d1,d2,d3}); + } + + public double[] getK() { + return k; + } + public void setK(double[] k) { + firePropertyChange(K_KEY, this.k, this.k = k); + } + public void setK(double d1, double d2, double d3) { + setK(new double[]{d1,d2,d3}); + } + + @Override + public Surface cloneSurface() { + RotatedBox rbox = new RotatedBox(name); + rbox.origin = ArrayUtils.clone(origin); + rbox.i = ArrayUtils.clone(i); + rbox.j = ArrayUtils.clone(j); + rbox.k = ArrayUtils.clone(k); + cloneSurface(rbox); + return rbox; + } + + @Override + public void copyFrom(Surface delegate, boolean changeGeometry, boolean changeSurface, boolean changeVolume, boolean changeLayer, boolean changeZone) { + if (delegate instanceof RotatedBox) { + RotatedBox rbox = (RotatedBox) delegate; + if (changeGeometry) { + setOrigin(rbox.getOrigin()); + setI(rbox.getI()); + setJ(rbox.getJ()); + setK(rbox.getK()); + } + super.copyFrom(delegate, changeGeometry, changeSurface, changeVolume, changeLayer, changeZone); + } + } + + @Override + public vtkPolyData getDataSet() { + double[] origin = getOrigin(); + double[] i = getI(); + double[] j = getJ(); + double[] k = getK(); + + Vector2d v_i = new Vector2d(i); + Vector2d v_j = new Vector2d(j); + Vector2d v_k = new Vector2d(k); + + double d_i = v_i.length(); + double d_j = v_j.length(); + double d_k = v_k.length(); + + double[][] boxPoints = new double[8][3]; + boxPoints[0] = sum(origin); + boxPoints[1] = sum(origin, i); + boxPoints[2] = sum(origin, i, j); + boxPoints[3] = sum(origin, j); + boxPoints[4] = sum(origin, k); + boxPoints[5] = sum(origin, k, i); + boxPoints[6] = sum(origin, k, i, j); + boxPoints[7] = sum(origin, k, j); + + vtkPolyData dataSet = new vtkPolyData(); + vtkPoints points = new vtkPoints(); + vtkCellArray cells = new vtkCellArray(); + + points.InsertPoint(0, boxPoints[0]); + points.InsertPoint(1, boxPoints[1]); + points.InsertPoint(2, boxPoints[2]); + points.InsertPoint(3, boxPoints[3]); + + points.InsertPoint(4, boxPoints[4]); + points.InsertPoint(5, boxPoints[5]); + points.InsertPoint(6, boxPoints[6]); + points.InsertPoint(7, boxPoints[7]); + + cells.InsertNextCell(cell(0,1,2,3)); + cells.InsertNextCell(cell(0,1,5,4)); + cells.InsertNextCell(cell(1,2,6,5)); + cells.InsertNextCell(cell(2,3,7,6)); + cells.InsertNextCell(cell(3,0,4,7)); + cells.InsertNextCell(cell(4,5,6,7)); + + dataSet.SetPoints(points); + dataSet.SetPolys(cells); + + return dataSet; + } + + protected vtkIdList cell(int... i) { + vtkIdList cell = new vtkIdList(); + for (int j : i) { + cell.InsertNextId(j); + } + + return cell; + } + + +// public static void main(String[] args) { +// double[] origin = {0, 0, 0}; +// double[] i = {2, 0, 1}; +// double[] j = {0, 1, 0}; +// double[] k = {-0.5, 0, 0.5}; +// +// Point3d o = new Point3d(origin); +// Vector3d v_i = new Vector3d(i); +// Vector3d v_j = new Vector3d(j); +// Vector3d v_k = new Vector3d(k); +// +// double[][] boxPoints = new double[8][3]; +// boxPoints[0] = sum(origin); +// boxPoints[1] = sum(origin, i); +// boxPoints[2] = sum(origin, i, j); +// boxPoints[3] = sum(origin, j); +// boxPoints[4] = sum(origin, k); +// boxPoints[5] = sum(origin, k, i); +// boxPoints[6] = sum(origin, k, i, j); +// boxPoints[7] = sum(origin, k, j); +// +// for (int l = 0; l < boxPoints.length; l++) { +// System.out.println("RotatedBox.main() " + l + " = " + Arrays.toString(boxPoints[l])); +// } +// } + + private static double[] sum(double[] origin, double[]... d) { + double[] sum = origin.clone(); + for (double[] a : d) { + for (int i = 0; i < a.length; i++) { + sum[i] += a[i]; + } + } + return sum; + } + + @Override + public Dictionary toGeometryDictionary() { + return new Dictionary(name); + } + + @Override + public void fromGeometryDictionary(Dictionary g) { + } + + @Override + public String toString() { + String string = super.toString(); + + return string + String.format("[ origin: %s, max: %s] ", Arrays.toString(origin), Arrays.toString(i), Arrays.toString(j), Arrays.toString(k)); + } +} diff --git a/src/eu/engys/core/project/geometry/surface/Solid.java b/src/eu/engys/core/project/geometry/surface/Solid.java index 04534c0..a246396 100644 --- a/src/eu/engys/core/project/geometry/surface/Solid.java +++ b/src/eu/engys/core/project/geometry/surface/Solid.java @@ -1,35 +1,35 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.geometry.surface; -import vtk.vtkPolyData; +import eu.engys.core.dictionary.Dictionary; import eu.engys.core.project.geometry.Surface; import eu.engys.core.project.geometry.Type; import eu.engys.util.VTKSettings; +import vtk.vtkPolyData; public class Solid extends Region { private vtkPolyData dataSet; @@ -66,6 +66,7 @@ public class Solid extends Region { @Override public Surface cloneSurface() { Solid solid = new Solid(name); + solid.setParent(getParent()); cloneSurface(solid); if (VTKSettings.librariesAreLoaded()) { @@ -84,4 +85,14 @@ public class Solid extends Region { public vtkPolyData getDataSet() { return dataSet; } + + @Override + public Dictionary toGeometryDictionary() { + return null; + } + + @Override + public void fromGeometryDictionary(Dictionary g) { + } + } diff --git a/src/eu/engys/core/project/geometry/surface/Sphere.java b/src/eu/engys/core/project/geometry/surface/Sphere.java index 25e4fef..19b161b 100644 --- a/src/eu/engys/core/project/geometry/surface/Sphere.java +++ b/src/eu/engys/core/project/geometry/surface/Sphere.java @@ -1,48 +1,63 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.geometry.surface; -import vtk.vtkPolyData; -import vtk.vtkSphereSource; +import static eu.engys.core.dictionary.Dictionary.TYPE; + +import java.util.Arrays; + +import org.apache.commons.lang.ArrayUtils; + import eu.engys.core.dictionary.Dictionary; import eu.engys.core.project.geometry.Surface; import eu.engys.core.project.geometry.Type; +import vtk.vtkPolyData; +import vtk.vtkSphereSource; public class Sphere extends BaseSurface { - /** + public static final double[] DEFAULT_CENTER = {0,0,0}; + public static final double DEFAULT_RADIUS = 1; + + private double[] centre = DEFAULT_CENTER; + private double radius = DEFAULT_RADIUS; + public static final Dictionary sphere = new Dictionary("sphere") { + { + add(TYPE, Surface.SEARCHABLE_SPHERE_KEY); + add(Surface.CENTRE_KEY, "(0 0 0)"); + add(Surface.RADIUS_KEY, "1.0"); + } + }; + + /** * @deprecated Use GeometryFactory!! */ @Deprecated public Sphere(String name) { super(name); - Dictionary geometryDictionary = new Dictionary(sphere); - geometryDictionary.setName(name); - setGeometryDictionary(geometryDictionary); } @Override @@ -50,30 +65,47 @@ public class Sphere extends BaseSurface { return Type.SPHERE; } - public double[] getCenter() { - if (getGeometryDictionary() != null && getGeometryDictionary().found(CENTRE_KEY)) - return getGeometryDictionary().lookupDoubleArray(CENTRE_KEY); - else - return new double[] { 0, 0, 0 }; + public double[] getCentre() { + return centre; + } + public void setCentre(double[] centre) { + firePropertyChange(CENTRE_KEY, this.centre, this.centre = centre); + } + public void setCentre(double d1, double d2, double d3) { + setCentre(new double[]{d1,d2,d3}); } public double getRadius() { - if (getGeometryDictionary() != null && getGeometryDictionary().found(RADIUS_KEY)) - return Double.valueOf(getGeometryDictionary().lookup(RADIUS_KEY)); - else - return 0; + return radius; + } + public void setRadius(double radius) { + firePropertyChange(RADIUS_KEY, this.radius, this.radius = radius); } @Override public Surface cloneSurface() { - Surface box = new Sphere(name); - cloneSurface(box); - return box; + Sphere sphere = new Sphere(name); + sphere.centre = ArrayUtils.clone(centre); + sphere.radius = radius; + cloneSurface(sphere); + return sphere; + } + + @Override + public void copyFrom(Surface delegate, boolean changeGeometry, boolean changeSurface, boolean changeVolume, boolean changeLayer, boolean changeZone) { + if (delegate instanceof Sphere) { + Sphere sphere = (Sphere) delegate; + if (changeGeometry) { + setCentre(sphere.getCentre()); + setRadius(sphere.getRadius()); + } + super.copyFrom(delegate, changeGeometry, changeSurface, changeVolume, changeLayer, changeZone); + } } @Override public vtkPolyData getDataSet() { - double[] center = getCenter(); + double[] center = getCentre(); double radius = getRadius(); vtkSphereSource sphereSource = new vtkSphereSource(); @@ -85,4 +117,34 @@ public class Sphere extends BaseSurface { return sphereSource.GetOutput(); } + + @Override + public Dictionary toGeometryDictionary() { + Dictionary d = new Dictionary(name, sphere); + d.add(CENTRE_KEY, centre); + d.add(RADIUS_KEY, radius); + return d; + } + + @Override + public void fromGeometryDictionary(Dictionary g) { + if (g != null && g.found(TYPE) && g.lookup(TYPE).equals(SEARCHABLE_SPHERE_KEY) ) { + if (g.found(CENTRE_KEY)) + setCentre(g.lookupDoubleArray(CENTRE_KEY)); + else + setCentre(DEFAULT_CENTER); + + if (g.found(RADIUS_KEY)) + setRadius(g.lookupDouble(RADIUS_KEY)); + else + setRadius(DEFAULT_RADIUS); + } + } + + @Override + public String toString() { + String string = super.toString(); + + return string + String.format("[ centre: %s, radius: %s] ", Arrays.toString(centre), radius); + } } diff --git a/src/eu/engys/core/project/geometry/surface/Stl.java b/src/eu/engys/core/project/geometry/surface/Stl.java index 14f2577..6fdaf25 100644 --- a/src/eu/engys/core/project/geometry/surface/Stl.java +++ b/src/eu/engys/core/project/geometry/surface/Stl.java @@ -1,42 +1,47 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.geometry.surface; -import java.io.File; import java.util.List; -import vtk.vtkPolyData; import eu.engys.core.dictionary.Dictionary; import eu.engys.core.project.geometry.Surface; import eu.engys.core.project.geometry.TransfromMode; import eu.engys.core.project.geometry.Type; +import vtk.vtkPolyData; public class Stl extends MultiRegion { + public static final Dictionary stl = new Dictionary("name.stl") { + { + add(TYPE, TRI_SURFACE_MESH_KEY); + add("name", "name"); + } + }; + private String fileName; /** @@ -46,19 +51,14 @@ public class Stl extends MultiRegion { public Stl(String name) { super(name); this.fileName = getName() + ".stl"; - Dictionary defaultSTLDictionary = new Dictionary(stl); - defaultSTLDictionary.setName(fileName); - defaultSTLDictionary.add("name", getName()); - defaultSTLDictionary.add("appendRegionName", "false"); - setGeometryDictionary(defaultSTLDictionary); } public String getFileName() { return fileName; } - public void setFileName(File file) { - this.fileName = file.getName(); + public void setFileName(String fileName) { + this.fileName = fileName; } @Override @@ -84,21 +84,29 @@ public class Stl extends MultiRegion { @Override public void rename(String newName) { super.rename(newName); - if (getGeometryDictionary() != null && getGeometryDictionary().isField("name")) { - getGeometryDictionary().add("name", newName); - - if (getTransformMode() == TransfromMode.TO_FILE) { - String dictName = getGeometryDictionary().getName(); - if (dictName.endsWith(".stl")) { - this.fileName = newName + ".stl"; - } else if (dictName.endsWith(".STL")) { - this.fileName = newName + ".STL"; - } - - getGeometryDictionary().setName(fileName); - setModified(true); - } + if (getTransformMode() == TransfromMode.TO_FILE) { + if (fileName.endsWith(".stl")) { + this.fileName = newName + ".stl"; + } else if (fileName.endsWith(".STL")) { + this.fileName = newName + ".STL"; + } + setModified(true); } +// if (getGeometryDictionary() != null && getGeometryDictionary().isField("name")) { +// getGeometryDictionary().add("name", newName); +// +// if (getTransformMode() == TransfromMode.TO_FILE) { +// String dictName = getGeometryDictionary().getName(); +// if (dictName.endsWith(".stl")) { +// this.fileName = newName + ".stl"; +// } else if (dictName.endsWith(".STL")) { +// this.fileName = newName + ".STL"; +// } +// +// getGeometryDictionary().setName(fileName); +// setModified(true); +// } +// } } @Override @@ -121,19 +129,9 @@ public class Stl extends MultiRegion { return true; } - public void buildGeometryDictionary(Dictionary dictionary) { - Dictionary geometryDict = new Dictionary(dictionary); - geometryDict.setName(fileName); - setGeometryDictionary(geometryDict); - } - @Override public String getPatchName() { - if (getGeometryDictionary().found("name")) { - return getGeometryDictionary().lookup("name"); - } else { - return super.getPatchName(); - } + return name; } @Override @@ -148,4 +146,21 @@ public class Stl extends MultiRegion { public vtkPolyData getDataSet() { return null; } + + + @Override + public Dictionary toGeometryDictionary() { + Dictionary d = new Dictionary(stl); + d.setName(fileName); + d.add("name", getName()); + d.add("appendRegionName", "false"); + + return d; + } + + @Override + public void fromGeometryDictionary(Dictionary g) { + + } + } diff --git a/src/eu/engys/core/project/geometry/surface/StlArea.java b/src/eu/engys/core/project/geometry/surface/StlArea.java new file mode 100644 index 0000000..5afb2cf --- /dev/null +++ b/src/eu/engys/core/project/geometry/surface/StlArea.java @@ -0,0 +1,185 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.core.project.geometry.surface; + +import eu.engys.core.dictionary.Dictionary; +import eu.engys.core.project.geometry.Surface; +import eu.engys.core.project.geometry.Type; +import vtk.vtkPolyData; + +public class StlArea extends BaseSurface { + + public static final String CURVATURE = "curvature"; + public static final String NEAR_DISTANCE = "nearDistance"; + public static final String INCLUDE_OUTSIDE = "includeOutside"; + public static final String INCLUDE_INSIDE = "includeInside"; + public static final String INCLUDE_CUT = "includeCut"; + public static final String FILE = "file"; + public static final String OUTSIDE_POINT = "outsidePoint"; + + private String file; + private boolean includeCut = true; + private boolean includeInside = true; + private boolean includeOutside = false; + private double[] outsidePoint = { 0, 0, 0 }; + + private double nearDistance = -1; + private double curvature = -100; + private vtkPolyData dataSet; + + /** + * @deprecated Use GeometryFactory!! + */ + @Deprecated + public StlArea(String name) { + super(name); + } + + public String getFile() { + return file; + } + + public void setFile(String file) { + firePropertyChange(FILE, this.file, this.file = file); + } + + public double[] getOutsidePoint() { + return outsidePoint; + } + + public void setOutsidePoint(double[] outsidePoint) { + firePropertyChange(OUTSIDE_POINT, this.outsidePoint, this.outsidePoint = outsidePoint); + } + + public boolean isIncludeCut() { + return includeCut; + } + + public void setIncludeCut(boolean includeCut) { + firePropertyChange(INCLUDE_CUT, this.includeCut, this.includeCut = includeCut); + } + + public boolean isIncludeInside() { + return includeInside; + } + + public void setIncludeInside(boolean includeInside) { + firePropertyChange(INCLUDE_INSIDE, this.includeInside, this.includeInside = includeInside); + } + + public boolean isIncludeOutside() { + return includeOutside; + } + + public void setIncludeOutside(boolean includeOutside) { + firePropertyChange(INCLUDE_OUTSIDE, this.includeOutside, this.includeOutside = includeOutside); + } + + public double getNearDistance() { + return nearDistance; + } + + public void setNearDistance(double nearDistance) { + firePropertyChange(NEAR_DISTANCE, this.nearDistance, this.nearDistance = nearDistance); + } + + public double getCurvature() { + return curvature; + } + + public void setCurvature(double curvature) { + firePropertyChange(CURVATURE, this.curvature, this.curvature = curvature); + } + + @Override + public Type getType() { + return Type.STL_AREA; + } + + @Override + public void rename(String newName) { + super.rename(newName); + // if (getTransformMode() == TransfromMode.TO_FILE) { + // if (fileName.endsWith(".stl")) { + // this.fileName = newName + ".stl"; + // } else if (fileName.endsWith(".STL")) { + // this.fileName = newName + ".STL"; + // } + // setModified(true); + // } + } + + @Override + public boolean hasLayers() { + return false; + } + + @Override + public boolean hasSurfaceRefinement() { + return false; + } + + @Override + public boolean hasVolumeRefinement() { + return false; + } + + @Override + public boolean hasZones() { + return false; + } + + @Override + public String getPatchName() { + return name; + } + + @Override + public Surface cloneSurface() { + StlArea s = new StlArea(name); + s.file = this.file; + cloneSurface(s); + return s; + } + + public void setDataSet(vtkPolyData dataSet) { + this.dataSet = dataSet; + } + + @Override + public vtkPolyData getDataSet() { + return dataSet; + } + + @Override + public Dictionary toGeometryDictionary() { + return new Dictionary(file); + } + + @Override + public void fromGeometryDictionary(Dictionary g) { + } + +} diff --git a/src/eu/engys/core/project/materials/Material.java b/src/eu/engys/core/project/materials/Material.java index 29ea64e..5fd3d96 100644 --- a/src/eu/engys/core/project/materials/Material.java +++ b/src/eu/engys/core/project/materials/Material.java @@ -1,62 +1,88 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.materials; -import eu.engys.core.dictionary.Dictionary; +import eu.engys.core.project.Model; +import eu.engys.core.project.materials.compressible.CompressibleMaterial; +import eu.engys.core.project.materials.incompressible.IncompressibleMaterial; +import eu.engys.util.bean.AbstractBean; -public class Material { +public abstract class Material extends AbstractBean { - private String name; - private Dictionary dictionary; + public static final String NAME_KEY = "name"; + + private String name; +// private Dictionary dictionary; - public Material(String name, Dictionary dictionary) { - this.name = name; - this.dictionary = dictionary; + public static Material newMaterial(Model model, String name) { + return model.getState().isCompressible() ? new CompressibleMaterial(name) : new IncompressibleMaterial(name); + } + + public static Material newMaterial(String name, Material m) { + return m instanceof CompressibleMaterial ? new CompressibleMaterial(name, (CompressibleMaterial) m) : new IncompressibleMaterial(name, (IncompressibleMaterial) m); + } + + public static Material newMaterial(Material m) { + return m instanceof CompressibleMaterial ? new CompressibleMaterial((CompressibleMaterial) m) : new IncompressibleMaterial((IncompressibleMaterial) m); } - public String getName() { + public static Material newDefaultMaterial(Model model, String materialName) { + if (model.getState().isCompressible()) { + return new CompressibleMaterial(materialName, model.getMaterialsDatabase().getCompressibleMaterial(materialName)); + } else { + return new IncompressibleMaterial(materialName, model.getMaterialsDatabase().getIncompressibleMaterial(materialName)); + } + } + + protected Material() { + } + + protected Material(String name) { + this.name = name; + } + + public String getName() { return name; } - public Dictionary getDictionary() { - return dictionary; - } +// public Dictionary getDictionary() { +// return dictionary; +// } @Override public String toString() { return name; } - public void setDictionary(Dictionary d) { - this.dictionary = d; - } +// public void setDictionary(Dictionary d) { +// this.dictionary = d; +// } public void setName(String name) { - this.name = name; + firePropertyChange(NAME_KEY, this.name, this.name = name); } - + } diff --git a/src/eu/engys/core/project/materials/Materials.java b/src/eu/engys/core/project/materials/Materials.java index d3ea4b2..ae5e17c 100644 --- a/src/eu/engys/core/project/materials/Materials.java +++ b/src/eu/engys/core/project/materials/Materials.java @@ -1,40 +1,44 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.materials; import java.util.LinkedList; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import eu.engys.core.project.Model; import eu.engys.core.project.constant.ThermophysicalProperties; import eu.engys.core.project.constant.TransportProperties; import eu.engys.util.progress.ProgressMonitor; public class Materials extends LinkedList { - + + private static final Logger logger = LoggerFactory.getLogger(Materials.class); + public Materials() { super(); } @@ -64,33 +68,44 @@ public class Materials extends LinkedList { if (!model.getState().getMultiphaseModel().isMultiphase()) { if (model.getState().isIncompressible()) { - reader.readSingle_Material(this, transProp, monitor); + addIfNotNull(reader.readIncompressibleMaterial(transProp)); } else { - reader.readSingle_Material(this, thermoProp, monitor); + addIfNotNull(reader.readCompressibleMaterial(thermoProp)); } model.materialsChanged(); } } + private void addIfNotNull(Material m) { + if (m != null) { + add(m); + } + } + public void saveMaterials(Model model, MaterialsWriter writer) { TransportProperties transProp = new TransportProperties(); ThermophysicalProperties thermoProp = new ThermophysicalProperties(); if (!model.getState().getMultiphaseModel().isMultiphase()) { - if (model.getState().isIncompressible()) { - writer.writeSingle_IncompressibleMaterial(this, transProp); + if (size() == 1) { + if (model.getState().isIncompressible()) { + transProp.merge(writer.writeSingle_IncompressibleMaterial(get(0))); + } else { + thermoProp.merge(writer.writeSingle_CompressibleMaterial(get(0))); + } } else { - writer.writeSingle_CompressibleMaterial(this, thermoProp); + logger.warn("Multiphase solution choosen but '{}' materials found", size()); } model.getProject().getConstantFolder().setTransportProperties(transProp); model.getProject().getConstantFolder().setThermophysicalProperties(thermoProp); } else { // ECOMARINE if (model.getState().isIncompressible() && model.getMaterials().size() == 1) { - writer.writeSingle_IncompressibleMaterial(this, transProp); + transProp.merge(writer.writeSingle_IncompressibleMaterial(get(0))); model.getProject().getConstantFolder().setTransportProperties(transProp); model.getProject().getConstantFolder().setThermophysicalProperties(thermoProp); } else { + logger.warn("Multiphase ECOMARINE solution choosen but '{}' materials found", size()); /**/ } } diff --git a/src/eu/engys/core/project/materials/Materials200To210Converter.java b/src/eu/engys/core/project/materials/Materials200To210Converter.java index c8ca584..36d649f 100644 --- a/src/eu/engys/core/project/materials/Materials200To210Converter.java +++ b/src/eu/engys/core/project/materials/Materials200To210Converter.java @@ -1,40 +1,36 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.materials; import static eu.engys.core.project.constant.ThermophysicalProperties.AS_KEY; -import static eu.engys.core.project.constant.ThermophysicalProperties.CONSTANT_CP_KEY; -import static eu.engys.core.project.constant.ThermophysicalProperties.CONST_KEY; import static eu.engys.core.project.constant.ThermophysicalProperties.CP_KEY; import static eu.engys.core.project.constant.ThermophysicalProperties.ENERGY_KEY; import static eu.engys.core.project.constant.ThermophysicalProperties.EQUATION_OF_STATE_KEY; import static eu.engys.core.project.constant.ThermophysicalProperties.HF_KEY; import static eu.engys.core.project.constant.ThermophysicalProperties.HIGH_CP_COEFFS_KEY; -import static eu.engys.core.project.constant.ThermophysicalProperties.JANAF_KEY; import static eu.engys.core.project.constant.ThermophysicalProperties.LOW_CP_COEFFS_KEY; import static eu.engys.core.project.constant.ThermophysicalProperties.MATERIAL_NAME_KEY; import static eu.engys.core.project.constant.ThermophysicalProperties.MIXTURE_KEY; @@ -45,16 +41,20 @@ import static eu.engys.core.project.constant.ThermophysicalProperties.PR_KEY; import static eu.engys.core.project.constant.ThermophysicalProperties.PURE_MIXTURE_KEY; import static eu.engys.core.project.constant.ThermophysicalProperties.SENSIBLE_ENTHALPY_KEY; import static eu.engys.core.project.constant.ThermophysicalProperties.SPECIE_KEY; -import static eu.engys.core.project.constant.ThermophysicalProperties.SUTHERLAND_KEY; import static eu.engys.core.project.constant.ThermophysicalProperties.TCOMMON_KEY; import static eu.engys.core.project.constant.ThermophysicalProperties.THERMODYNAMICS_KEY; +import static eu.engys.core.project.constant.ThermophysicalProperties.THERMO_CONST_KEY; +import static eu.engys.core.project.constant.ThermophysicalProperties.THERMO_JANAF_KEY; import static eu.engys.core.project.constant.ThermophysicalProperties.THERMO_KEY; import static eu.engys.core.project.constant.ThermophysicalProperties.THERMO_MODEL_KEY; import static eu.engys.core.project.constant.ThermophysicalProperties.THERMO_TYPE_KEY; import static eu.engys.core.project.constant.ThermophysicalProperties.THIGH_KEY; import static eu.engys.core.project.constant.ThermophysicalProperties.TLOW_KEY; +import static eu.engys.core.project.constant.ThermophysicalProperties.TRANSPORT_CONST_KEY; import static eu.engys.core.project.constant.ThermophysicalProperties.TRANSPORT_KEY; +import static eu.engys.core.project.constant.ThermophysicalProperties.TRANSPORT_SUTHERLAND_KEY; import static eu.engys.core.project.constant.ThermophysicalProperties.TS_KEY; + import eu.engys.core.dictionary.Dictionary; import eu.engys.core.project.constant.ThermophysicalProperties; @@ -96,10 +96,10 @@ public class Materials200To210Converter { /* THERMODYNAMICS */ Dictionary thermodynamicsDict = new Dictionary(THERMODYNAMICS_KEY); - if (thermo.equals(CONSTANT_CP_KEY)) { + if (thermo.equals(THERMO_CONST_KEY)) { thermodynamicsDict.add(CP_KEY, materialGUIDict.lookup(CP_KEY)); thermodynamicsDict.add(HF_KEY, materialGUIDict.lookup(HF_KEY)); - } else if (thermo.equals(JANAF_KEY)) { + } else if (thermo.equals(THERMO_JANAF_KEY)) { thermodynamicsDict.add(TLOW_KEY, materialGUIDict.lookup(TLOW_KEY)); thermodynamicsDict.add(THIGH_KEY, materialGUIDict.lookup(THIGH_KEY)); thermodynamicsDict.add(TCOMMON_KEY, materialGUIDict.lookup(TCOMMON_KEY)); @@ -109,10 +109,10 @@ public class Materials200To210Converter { /* TRANSPORT */ Dictionary transportDict = new Dictionary(TRANSPORT_KEY); - if (transport.equals(CONST_KEY)) { + if (transport.equals(TRANSPORT_CONST_KEY)) { transportDict.add(MU_KEY, materialGUIDict.lookup(MU_KEY)); transportDict.add(PR_KEY, materialGUIDict.lookup(PR_KEY)); - } else if (transport.equals(SUTHERLAND_KEY)) { + } else if (transport.equals(TRANSPORT_SUTHERLAND_KEY)) { transportDict.add(AS_KEY, materialGUIDict.lookup(AS_KEY)); transportDict.add(TS_KEY, materialGUIDict.lookup(TS_KEY)); } diff --git a/src/eu/engys/core/project/materials/MaterialsReader.java b/src/eu/engys/core/project/materials/MaterialsReader.java index 571f09b..11c5d91 100644 --- a/src/eu/engys/core/project/materials/MaterialsReader.java +++ b/src/eu/engys/core/project/materials/MaterialsReader.java @@ -1,38 +1,36 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.materials; -import eu.engys.core.project.constant.ThermophysicalProperties; -import eu.engys.core.project.constant.TransportProperties; -import eu.engys.util.progress.ProgressMonitor; +import eu.engys.core.dictionary.Dictionary; +import eu.engys.core.project.materials.compressible.CompressibleMaterial; +import eu.engys.core.project.materials.incompressible.IncompressibleMaterial; public interface MaterialsReader { - void readSingle_Material(Materials materials, TransportProperties tpp, ProgressMonitor monitor); - - void readSingle_Material(Materials materials, ThermophysicalProperties tfp, ProgressMonitor monitor); + IncompressibleMaterial readIncompressibleMaterial(Dictionary dictionary); + CompressibleMaterial readCompressibleMaterial(Dictionary dictionary); } diff --git a/src/eu/engys/core/project/materials/MaterialsWriter.java b/src/eu/engys/core/project/materials/MaterialsWriter.java index 8379648..03237bb 100644 --- a/src/eu/engys/core/project/materials/MaterialsWriter.java +++ b/src/eu/engys/core/project/materials/MaterialsWriter.java @@ -1,37 +1,35 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.materials; -import eu.engys.core.project.constant.ThermophysicalProperties; -import eu.engys.core.project.constant.TransportProperties; +import eu.engys.core.dictionary.Dictionary; public interface MaterialsWriter { - void writeSingle_IncompressibleMaterial(Materials materials, TransportProperties tpp); + Dictionary writeSingle_IncompressibleMaterial(Material material); - void writeSingle_CompressibleMaterial(Materials materials, ThermophysicalProperties tfp); + Dictionary writeSingle_CompressibleMaterial(Material material); } diff --git a/src/eu/engys/core/project/materials/Phase.java b/src/eu/engys/core/project/materials/Phase.java index 285afc0..67806b2 100644 --- a/src/eu/engys/core/project/materials/Phase.java +++ b/src/eu/engys/core/project/materials/Phase.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.materials; diff --git a/src/eu/engys/core/project/materials/compressible/AdiabaticPerfectFluid.java b/src/eu/engys/core/project/materials/compressible/AdiabaticPerfectFluid.java new file mode 100644 index 0000000..d010ad0 --- /dev/null +++ b/src/eu/engys/core/project/materials/compressible/AdiabaticPerfectFluid.java @@ -0,0 +1,69 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.core.project.materials.compressible; + +import eu.engys.util.bean.AbstractBean; + +public class AdiabaticPerfectFluid extends AbstractBean implements EquationOfState { + public static final String RHO0_KEY = "rho0"; + public static final String B_KEY = "b"; + public static final String P0_KEY = "p0"; + public static final String GAMMA_KEY = "gamma"; + + private double rho0 = 0; + private double b = 0; + private double p0 = 0; + private double gamma = 0; + + public double getRho0() { + return rho0; + } + public void setRho0(double rho0) { + firePropertyChange(RHO0_KEY, this.rho0, this.rho0 = rho0); + this.rho0 = rho0; + } + public double getB() { + return b; + } + public void setB(double b) { + firePropertyChange(B_KEY, this.b, this.b = b); + this.b = b; + } + public double getP0() { + return p0; + } + public void setP0(double p0) { + firePropertyChange(P0_KEY, this.p0, this.p0 = p0); + } + public double getGamma() { + return gamma; + } + public void setGamma(double gamma) { + firePropertyChange(GAMMA_KEY, this.gamma, this.gamma = gamma); + } + + + +} diff --git a/src/eu/engys/core/project/materials/compressible/CompressibleMaterial.java b/src/eu/engys/core/project/materials/compressible/CompressibleMaterial.java new file mode 100644 index 0000000..db026e0 --- /dev/null +++ b/src/eu/engys/core/project/materials/compressible/CompressibleMaterial.java @@ -0,0 +1,103 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.core.project.materials.compressible; + +import eu.engys.core.project.materials.Material; + +public class CompressibleMaterial extends Material { + + public static final String N_MOLES = "nMoles"; + public static final String MOL_WEIGHT = "molWeight"; + public static final String EQ_OF_STATE = "eqOfState"; + public static final String TRANSPORT = "transport"; + public static final String THERMODYNAMIC_MODEL = "thermodynamicModel"; + + private int nMoles = 0; + private double molWeight = 0; + + private EquationOfState eqOfState = new PerfectGas(); + private Transport transport = new ConstantTransport(); + private ThermodynamicModel thermodynamicModel = new ConstantThermodynamicModel(); + + public CompressibleMaterial() { + super(); + } + + public CompressibleMaterial(String name) { + super(name); + } + + public CompressibleMaterial(CompressibleMaterial m) { + this(m.getName(), m); + } + + public CompressibleMaterial(String name, CompressibleMaterial m) { + super(name); + if (m != null) { + this.nMoles = m.nMoles; + this.molWeight = m.molWeight; + this.eqOfState = m.eqOfState; + this.transport = m.transport; + this.thermodynamicModel = m.thermodynamicModel; + } + } + + public int getnMoles() { + return nMoles; + } + public void setnMoles(int nMoles) { + firePropertyChange(N_MOLES, this.nMoles, this.nMoles = nMoles); + } + + public double getMolWeight() { + return molWeight; + } + public void setMolWeight(double molWeight) { + firePropertyChange(MOL_WEIGHT, this.molWeight, this.molWeight = molWeight); + } + + public EquationOfState getEqOfState() { + return eqOfState; + } + public void setEqOfState(EquationOfState eqOfState) { + firePropertyChange(EQ_OF_STATE, this.eqOfState, this.eqOfState = eqOfState); + } + + public Transport getTransport() { + return transport; + } + + public void setTransport(Transport transport) { + firePropertyChange(TRANSPORT, this.transport, this.transport = transport); + } + + public ThermodynamicModel getThermodynamicModel() { + return thermodynamicModel; + } + + public void setThermodynamicModel(ThermodynamicModel thermodynamicModel) { + firePropertyChange(THERMODYNAMIC_MODEL, this.thermodynamicModel, this.thermodynamicModel = thermodynamicModel); + } +} diff --git a/src/eu/engys/core/project/materials/compressible/ConstantDensity.java b/src/eu/engys/core/project/materials/compressible/ConstantDensity.java new file mode 100644 index 0000000..98d27f2 --- /dev/null +++ b/src/eu/engys/core/project/materials/compressible/ConstantDensity.java @@ -0,0 +1,42 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.core.project.materials.compressible; + +import eu.engys.util.bean.AbstractBean; + +public class ConstantDensity extends AbstractBean implements EquationOfState { + public static final String RHO_KEY = "rho"; + + private double rho = 0; + + public double getRho() { + return rho; + } + + public void setRho(double rho) { + firePropertyChange(RHO_KEY, this.rho, this.rho = rho); + } + +} diff --git a/src/eu/engys/core/project/materials/compressible/ConstantThermodynamicModel.java b/src/eu/engys/core/project/materials/compressible/ConstantThermodynamicModel.java new file mode 100644 index 0000000..c5aeabc --- /dev/null +++ b/src/eu/engys/core/project/materials/compressible/ConstantThermodynamicModel.java @@ -0,0 +1,51 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.core.project.materials.compressible; + +import eu.engys.util.bean.AbstractBean; + +public class ConstantThermodynamicModel extends AbstractBean implements ThermodynamicModel { + + public static final String CP_KEY = "cp"; + public static final String HF_KEY = "hf"; + + private double cp = 0; + private double hf = 0; + + public double getCp() { + return cp; + } + public void setCp(double cp) { + firePropertyChange(CP_KEY, this.cp, this.cp = cp); + } + public double getHf() { + return hf; + } + public void setHf(double hf) { + firePropertyChange(HF_KEY, this.hf, this.hf = hf); + } + + +} diff --git a/src/eu/engys/core/project/materials/compressible/ConstantTransport.java b/src/eu/engys/core/project/materials/compressible/ConstantTransport.java new file mode 100644 index 0000000..35428d9 --- /dev/null +++ b/src/eu/engys/core/project/materials/compressible/ConstantTransport.java @@ -0,0 +1,51 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.core.project.materials.compressible; + +import eu.engys.util.bean.AbstractBean; + +public class ConstantTransport extends AbstractBean implements Transport { + + public static final String PR_KEY = "pr"; + public static final String MU_KEY = "mu"; + + private double mu = 0; + private double pr = 0; + + public double getMu() { + return mu; + } + public void setMu(double mu) { + firePropertyChange(MU_KEY, this.mu, this.mu = mu); + } + public double getPr() { + return pr; + } + public void setPr(double pr) { + firePropertyChange(PR_KEY, this.pr, this.pr = pr); + } + + +} diff --git a/src/eu/engys/core/project/materials/compressible/EquationOfState.java b/src/eu/engys/core/project/materials/compressible/EquationOfState.java new file mode 100644 index 0000000..3c1335d --- /dev/null +++ b/src/eu/engys/core/project/materials/compressible/EquationOfState.java @@ -0,0 +1,28 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.core.project.materials.compressible; + +public interface EquationOfState { +} diff --git a/src/eu/engys/core/project/materials/compressible/IncompressiblePerfectGas.java b/src/eu/engys/core/project/materials/compressible/IncompressiblePerfectGas.java new file mode 100644 index 0000000..35e8d9c --- /dev/null +++ b/src/eu/engys/core/project/materials/compressible/IncompressiblePerfectGas.java @@ -0,0 +1,44 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.core.project.materials.compressible; + +import eu.engys.util.bean.AbstractBean; + +public class IncompressiblePerfectGas extends AbstractBean implements EquationOfState { + + public static final String P_REF_KEY = "pRef"; + + private double pRef = 0; + + public double getpRef() { + return pRef; + } + + public void setpRef(double pRef) { + firePropertyChange(P_REF_KEY, this.pRef, this.pRef = pRef); + } + + +} diff --git a/src/eu/engys/core/project/materials/compressible/JANAFThermodynamicModel.java b/src/eu/engys/core/project/materials/compressible/JANAFThermodynamicModel.java new file mode 100644 index 0000000..3a00179 --- /dev/null +++ b/src/eu/engys/core/project/materials/compressible/JANAFThermodynamicModel.java @@ -0,0 +1,85 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.core.project.materials.compressible; + +import eu.engys.util.bean.AbstractBean; + +public class JANAFThermodynamicModel extends AbstractBean implements ThermodynamicModel { + + public static final String TLOW_KEY = "tLow"; + public static final String THIGH_KEY = "tHigh"; + public static final String TCOMMON_KEY = "tCommon"; + + public static final String LOW_CP_COEFFS_KEY = "lowCpCoefficients"; + public static final String HIGH_CP_COEFFS_KEY = "highCpCoefficients"; + + private double tLow = 0; + private double tHigh = 0; + private double tCommon = 0; + + private double[] lowCpCoefficients = new double[7]; + private double[] highCpCoefficients = new double[7]; + + public double gettLow() { + return tLow; + } + + public void settLow(double tLow) { + firePropertyChange(TLOW_KEY, this.tLow, this.tLow = tLow); + } + + public double gettHigh() { + return tHigh; + } + + public void settHigh(double tHigh) { + firePropertyChange(THIGH_KEY, this.tHigh, this.tHigh = tHigh); + } + + public double gettCommon() { + return tCommon; + } + + public void settCommon(double tCommon) { + firePropertyChange(TCOMMON_KEY, this.tCommon, this.tCommon = tCommon); + } + + public double[] getLowCpCoefficients() { + return lowCpCoefficients; + } + + public void setLowCpCoefficients(double[] lowCpCoefficients) { + firePropertyChange(LOW_CP_COEFFS_KEY, this.lowCpCoefficients, this.lowCpCoefficients = lowCpCoefficients); + } + + public double[] getHighCpCoefficients() { + return highCpCoefficients; + } + + public void setHighCpCoefficients(double[] highCpCoefficients) { + firePropertyChange(HIGH_CP_COEFFS_KEY, this.highCpCoefficients, this.highCpCoefficients = highCpCoefficients); + } + +} diff --git a/src/eu/engys/core/project/materials/compressible/PerfectFluid.java b/src/eu/engys/core/project/materials/compressible/PerfectFluid.java new file mode 100644 index 0000000..dc05448 --- /dev/null +++ b/src/eu/engys/core/project/materials/compressible/PerfectFluid.java @@ -0,0 +1,52 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.core.project.materials.compressible; + +import eu.engys.util.bean.AbstractBean; + +public class PerfectFluid extends AbstractBean implements EquationOfState { + public static final String RHO0_KEY = "rho0"; + public static final String R_KEY = "r"; + + private double rho0 = 0; + private double r = 0; + + public double getRho0() { + return rho0; + } + + public void setRho0(double rho0) { + firePropertyChange(RHO0_KEY, this.rho0, this.rho0 = rho0); + } + + public double getR() { + return r; + } + + public void setR(double r) { + firePropertyChange(R_KEY, this.r, this.r = r); + } + +} diff --git a/src/eu/engys/core/project/materials/compressible/PerfectGas.java b/src/eu/engys/core/project/materials/compressible/PerfectGas.java new file mode 100644 index 0000000..0e5b0dc --- /dev/null +++ b/src/eu/engys/core/project/materials/compressible/PerfectGas.java @@ -0,0 +1,30 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.core.project.materials.compressible; + +import eu.engys.util.bean.AbstractBean; + +public class PerfectGas extends AbstractBean implements EquationOfState { +} diff --git a/src/eu/engys/core/project/materials/compressible/PolynomialEquation.java b/src/eu/engys/core/project/materials/compressible/PolynomialEquation.java new file mode 100644 index 0000000..65f19e8 --- /dev/null +++ b/src/eu/engys/core/project/materials/compressible/PolynomialEquation.java @@ -0,0 +1,41 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.core.project.materials.compressible; + +import eu.engys.util.bean.AbstractBean; + +public class PolynomialEquation extends AbstractBean implements EquationOfState { + + public static final String RHO_COEFFICIENTS = "rhoCoefficients"; + + double[] rhoCoefficients = new double[8]; + + public double[] getRhoCoefficients() { + return rhoCoefficients; + } + public void setRhoCoefficients(double[] rhoCoefficients) { + firePropertyChange(RHO_COEFFICIENTS, this.rhoCoefficients, this.rhoCoefficients = rhoCoefficients); + } +} diff --git a/src/eu/engys/core/project/materials/compressible/PolynomialThermodynamicModel.java b/src/eu/engys/core/project/materials/compressible/PolynomialThermodynamicModel.java new file mode 100644 index 0000000..5f96f03 --- /dev/null +++ b/src/eu/engys/core/project/materials/compressible/PolynomialThermodynamicModel.java @@ -0,0 +1,59 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.core.project.materials.compressible; + +import eu.engys.util.bean.AbstractBean; + +public class PolynomialThermodynamicModel extends AbstractBean implements ThermodynamicModel { + + public static final String SF_KEY = "sf"; + public static final String HF_KEY = "hf"; + public static final String CP_COEFFS_KEY = "cpCoefficients"; + + private double hf = 0; + private double sf = 0; + private double[] cpCoefficients = new double[8]; + + public double[] getCpCoefficients() { + return cpCoefficients; + } + public void setCpCoefficients(double[] cpCoefficients) { + firePropertyChange(CP_COEFFS_KEY, this.cpCoefficients, this.cpCoefficients = cpCoefficients); + } + public double getHf() { + return hf; + } + public void setHf(double hf) { + firePropertyChange(HF_KEY, this.hf, this.hf = hf); + } + public double getSf() { + return sf; + } + public void setSf(double sf) { + firePropertyChange(SF_KEY, this.sf, this.sf = sf); + } + + +} diff --git a/src/eu/engys/core/project/materials/compressible/PolynomialTransport.java b/src/eu/engys/core/project/materials/compressible/PolynomialTransport.java new file mode 100644 index 0000000..4960827 --- /dev/null +++ b/src/eu/engys/core/project/materials/compressible/PolynomialTransport.java @@ -0,0 +1,51 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.core.project.materials.compressible; + +import eu.engys.util.bean.AbstractBean; + + +public class PolynomialTransport extends AbstractBean implements Transport { + + public static final String MU_COEFFICIENTS = "muCoefficients"; + public static final String KAPPA_COEFFICIENTS = "kappaCoefficients"; + + private double[] muCoefficients = new double[8]; + private double[] kappaCoefficients = new double[8]; + + public double[] getMuCoefficients() { + return muCoefficients; + } + public void setMuCoefficients(double[] muCoefficients) { + firePropertyChange(MU_COEFFICIENTS, this.muCoefficients, this.muCoefficients = muCoefficients); + } + + public double[] getKappaCoefficients() { + return kappaCoefficients; + } + public void setKappaCoefficients(double[] kappaCoefficients) { + firePropertyChange(KAPPA_COEFFICIENTS, this.kappaCoefficients, this.kappaCoefficients = kappaCoefficients); + } +} diff --git a/src/eu/engys/core/project/materials/compressible/SutherlandTransport.java b/src/eu/engys/core/project/materials/compressible/SutherlandTransport.java new file mode 100644 index 0000000..8dde4ae --- /dev/null +++ b/src/eu/engys/core/project/materials/compressible/SutherlandTransport.java @@ -0,0 +1,51 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.core.project.materials.compressible; + +import eu.engys.util.bean.AbstractBean; + +public class SutherlandTransport extends AbstractBean implements Transport { + + public static final String AS_KEY = "as"; + public static final String TS_KEY = "ts"; + + private double as; + private double ts; + + public double getAs() { + return as; + } + public void setAs(double as) { + firePropertyChange(AS_KEY, this.as, this.as = as); + } + public double getTs() { + return ts; + } + public void setTs(double ts) { + firePropertyChange(TS_KEY, this.ts, this.ts = ts); + } + + +} diff --git a/src/eu/engys/core/project/materials/compressible/ThermodynamicModel.java b/src/eu/engys/core/project/materials/compressible/ThermodynamicModel.java new file mode 100644 index 0000000..b5ad60f --- /dev/null +++ b/src/eu/engys/core/project/materials/compressible/ThermodynamicModel.java @@ -0,0 +1,28 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.core.project.materials.compressible; + +public interface ThermodynamicModel { +} diff --git a/src/eu/engys/core/project/materials/compressible/Transport.java b/src/eu/engys/core/project/materials/compressible/Transport.java new file mode 100644 index 0000000..cd4fd75 --- /dev/null +++ b/src/eu/engys/core/project/materials/compressible/Transport.java @@ -0,0 +1,28 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.core.project.materials.compressible; + +public interface Transport { +} diff --git a/src/eu/engys/core/project/materials/incompressible/BirdCarreauTransportModel.java b/src/eu/engys/core/project/materials/incompressible/BirdCarreauTransportModel.java new file mode 100644 index 0000000..ed9adbc --- /dev/null +++ b/src/eu/engys/core/project/materials/incompressible/BirdCarreauTransportModel.java @@ -0,0 +1,68 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.core.project.materials.incompressible; + +import eu.engys.util.bean.AbstractBean; + +public class BirdCarreauTransportModel extends AbstractBean implements TransportModel { + + public static final String NU0_KEY = "nu0"; + public static final String NU_INF_KEY = "nuInf"; + public static final String K_KEY = "k"; + public static final String N_KEY = "n"; + + private double nu0 = 0; + private double nuInf = 0; + private double k = 0; + private double n = 0; + + public double getNu0() { + return nu0; + } + public void setNu0(double nu0) { + firePropertyChange(NU0_KEY, this.nu0, this.nu0 = nu0); + this.nu0 = nu0; + } + public double getNuInf() { + return nuInf; + } + public void setNuInf(double nuInf) { + firePropertyChange(NU_INF_KEY, this.nuInf, this.nuInf = nuInf); + } + public double getK() { + return k; + } + public void setK(double k) { + firePropertyChange(K_KEY, this.k, this.k = k); + } + public double getN() { + return n; + } + public void setN(double n) { + firePropertyChange(N_KEY, this.n, this.n = n); + } + + +} diff --git a/src/eu/engys/core/project/materials/incompressible/CrossPowerLawTransportModel.java b/src/eu/engys/core/project/materials/incompressible/CrossPowerLawTransportModel.java new file mode 100644 index 0000000..26375d2 --- /dev/null +++ b/src/eu/engys/core/project/materials/incompressible/CrossPowerLawTransportModel.java @@ -0,0 +1,68 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.core.project.materials.incompressible; + +import eu.engys.util.bean.AbstractBean; + +public class CrossPowerLawTransportModel extends AbstractBean implements TransportModel { + + public static final String NU0_KEY = "nu0"; + public static final String NU_INF_KEY = "nuInf"; + public static final String M_KEY = "m"; + public static final String N_KEY = "n"; + + private double nu0 = 0; + private double nuInf = 0; + private double m = 0; + private double n = 0; + + public double getNu0() { + return nu0; + } + public void setNu0(double nu0) { + firePropertyChange(NU0_KEY, this.nu0, this.nu0 = nu0); + this.nu0 = nu0; + } + public double getNuInf() { + return nuInf; + } + public void setNuInf(double nuInf) { + firePropertyChange(NU_INF_KEY, this.nuInf, this.nuInf = nuInf); + } + public double getM() { + return m; + } + public void setM(double m) { + firePropertyChange(M_KEY, this.m, this.m = m); + } + public double getN() { + return n; + } + public void setN(double n) { + firePropertyChange(N_KEY, this.n, this.n = n); + } + + +} diff --git a/src/eu/engys/core/project/materials/incompressible/HerschelBulkleyTransportModel.java b/src/eu/engys/core/project/materials/incompressible/HerschelBulkleyTransportModel.java new file mode 100644 index 0000000..4a08732 --- /dev/null +++ b/src/eu/engys/core/project/materials/incompressible/HerschelBulkleyTransportModel.java @@ -0,0 +1,66 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.core.project.materials.incompressible; + +import eu.engys.util.bean.AbstractBean; + +public class HerschelBulkleyTransportModel extends AbstractBean implements TransportModel { + + public static final String NU0_KEY = "nu0"; + public static final String TAU0_KEY = "tau0"; + public static final String K_KEY = "k"; + public static final String N_KEY = "n"; + + private double nu0 = 0; + private double tau0 = 0; + private double k = 0; + private double n = 0; + + public double getNu0() { + return nu0; + } + public void setNu0(double nu0) { + firePropertyChange(NU0_KEY, this.nu0, this.nu0 = nu0); + this.nu0 = nu0; + } + public double getTau0() { + return tau0; + } + public void setTau0(double tau0) { + firePropertyChange(TAU0_KEY, this.tau0, this.tau0 = tau0); + } + public double getK() { + return k; + } + public void setK(double k) { + firePropertyChange(K_KEY, this.k, this.k = k); + } + public double getN() { + return n; + } + public void setN(double n) { + firePropertyChange(N_KEY, this.n, this.n = n); + } +} diff --git a/src/eu/engys/core/project/materials/incompressible/IncompressibleMaterial.java b/src/eu/engys/core/project/materials/incompressible/IncompressibleMaterial.java new file mode 100644 index 0000000..203e9fb --- /dev/null +++ b/src/eu/engys/core/project/materials/incompressible/IncompressibleMaterial.java @@ -0,0 +1,165 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.core.project.materials.incompressible; + +import eu.engys.core.project.materials.Material; + +public class IncompressibleMaterial extends Material { + + public static final String PR_KEY = "pr"; + public static final String RHO_KEY = "rho"; + public static final String NU_KEY = "nu"; + public static final String MU_KEY = "mu"; + public static final String CP_KEY = "cp"; + public static final String PRT_KEY = "prt"; + public static final String LAMBDA_KEY = "lambda"; + public static final String T_REF_KEY = "tRef"; + public static final String P_REF_KEY = "pRef"; + public static final String BETA_KEY = "beta"; + public static final String TRANSPORT_MODEL_KEY = "transportModel"; + + private double rho = 0; + private double mu = 0; + private double nu = 0; + private double cp = 0; + private double prt = 0; + private double lambda = 0; + private double tRef = 0; + private double pRef = 0; + private double beta = 0; + private double pr = 0; + + private TransportModel transportModel = new NewtonianTransportModel(); + + public IncompressibleMaterial() { + super(); + } + + public IncompressibleMaterial(String name) { + super(name); + } + + public IncompressibleMaterial(IncompressibleMaterial m) { + this(m.getName(), m); + } + + public IncompressibleMaterial(String name, IncompressibleMaterial m) { + super(name); + if (m != null) { + this.rho = m.rho; + this.mu = m.mu; + this.nu = m.nu; + this.cp = m.cp; + this.prt = m.prt; + this.lambda = m.lambda; + this.tRef = m.tRef; + this.pRef = m.pRef; + this.beta = m.beta; + this.pr = m.pr; + this.transportModel = m.transportModel; + } + } + + public double getRho() { + return rho; + } + public void setRho(double rho) { + firePropertyChange(RHO_KEY, this.rho, this.rho = rho); + } + + public double getMu() { + return mu; + } + public void setMu(double mu) { + firePropertyChange(MU_KEY, this.mu, this.mu = mu); + } + + public double getNu() { + return nu; + } + public void setNu(double nu) { + firePropertyChange(NU_KEY, this.nu, this.nu = nu); + } + + public double getCp() { + return cp; + } + + public void setCp(double cp) { + firePropertyChange(CP_KEY, this.cp, this.cp = cp); + } + + public double getPrt() { + return prt; + } + + public void setPrt(double prt) { + firePropertyChange(PRT_KEY, this.prt, this.prt = prt); + } + + public double getLambda() { + return lambda; + } + public void setLambda(double lambda) { + firePropertyChange(LAMBDA_KEY, this.lambda, this.lambda = lambda); + } + + public double gettRef() { + return tRef; + } + public void settRef(double tRef) { + firePropertyChange(T_REF_KEY, this.tRef, this.tRef = tRef); + } + + public double getpRef() { + return pRef; + } + public void setpRef(double pRef) { + firePropertyChange(P_REF_KEY, this.pRef, this.pRef = pRef); + } + + public double getBeta() { + return beta; + } + public void setBeta(double beta) { + firePropertyChange(BETA_KEY, this.beta, this.beta = beta); + } + + public double getPr() { + return pr; + } + public void setPr(double pr) { + firePropertyChange(PR_KEY, this.pr, this.pr = pr); + } + + public TransportModel getTransportModel() { + return transportModel; + } + public void setTransportModel(TransportModel transportModel) { + firePropertyChange(TRANSPORT_MODEL_KEY, this.transportModel, this.transportModel = transportModel); + } + + +} diff --git a/src/eu/engys/core/project/materials/incompressible/NewtonianTransportModel.java b/src/eu/engys/core/project/materials/incompressible/NewtonianTransportModel.java new file mode 100644 index 0000000..dd68b2d --- /dev/null +++ b/src/eu/engys/core/project/materials/incompressible/NewtonianTransportModel.java @@ -0,0 +1,31 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.core.project.materials.incompressible; + +import eu.engys.util.bean.AbstractBean; + +public class NewtonianTransportModel extends AbstractBean implements TransportModel { + +} diff --git a/src/eu/engys/core/project/materials/incompressible/PowerLawTransportModel.java b/src/eu/engys/core/project/materials/incompressible/PowerLawTransportModel.java new file mode 100644 index 0000000..7c4b80d --- /dev/null +++ b/src/eu/engys/core/project/materials/incompressible/PowerLawTransportModel.java @@ -0,0 +1,65 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.core.project.materials.incompressible; + +import eu.engys.util.bean.AbstractBean; + +public class PowerLawTransportModel extends AbstractBean implements TransportModel { + + public static final String NU_MIN_KEY = "nuMin"; + public static final String NU_MAX_KEY = "nuMax"; + public static final String K_KEY = "k"; + public static final String N_KEY = "n"; + + private double nuMin = 0; + private double nuMax = 0; + private double k = 0; + private double n = 0; + + public double getNuMin() { + return nuMin; + } + public void setNuMin(double nuMin) { + firePropertyChange("nuMin", this.nuMin, this.nuMin = nuMin); + } + public double getNuMax() { + return nuMax; + } + public void setNuMax(double nuMax) { + firePropertyChange("nuMax", this.nuMax, this.nuMax = nuMax); + } + public double getK() { + return k; + } + public void setK(double k) { + firePropertyChange(K_KEY, this.k, this.k = k); + } + public double getN() { + return n; + } + public void setN(double n) { + firePropertyChange(N_KEY, this.n, this.n = n); + } +} diff --git a/src/eu/engys/core/project/materials/incompressible/TransportModel.java b/src/eu/engys/core/project/materials/incompressible/TransportModel.java new file mode 100644 index 0000000..3ed0870 --- /dev/null +++ b/src/eu/engys/core/project/materials/incompressible/TransportModel.java @@ -0,0 +1,28 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.core.project.materials.incompressible; + +public interface TransportModel { +} diff --git a/src/eu/engys/core/project/mesh/ExternalMesh.java b/src/eu/engys/core/project/mesh/ExternalMesh.java new file mode 100644 index 0000000..c824006 --- /dev/null +++ b/src/eu/engys/core/project/mesh/ExternalMesh.java @@ -0,0 +1,51 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.core.project.mesh; + +import eu.engys.core.project.geometry.BoundingBox; + +public class ExternalMesh { + + private BoundingBox bounds; + private FieldItems fieldItems; + + public ExternalMesh() { + this.fieldItems = new FieldItems(); + this.bounds = new BoundingBox(0, 0, 0, 0, 0, 0); + } + + public BoundingBox getBounds() { + return bounds; + } + + public void setBounds(BoundingBox bounds) { + this.bounds = bounds; + } + + public FieldItems getFieldItems() { + return fieldItems; + } + +} diff --git a/src/eu/engys/core/project/mesh/FieldItem.java b/src/eu/engys/core/project/mesh/FieldItem.java index 771133d..37b6407 100644 --- a/src/eu/engys/core/project/mesh/FieldItem.java +++ b/src/eu/engys/core/project/mesh/FieldItem.java @@ -1,100 +1,158 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.mesh; -import static eu.engys.core.project.mesh.ScalarBarType.BLUE_TO_RED_RAINBOW; +import static eu.engys.core.project.mesh.ScalarBarType.BLUE_TO_RED_HSV; public class FieldItem { public static final int DEFAULT_RESOLUTION = 256; public static final String SOLID = "Solid Color"; public static final String INDEXED = "Index"; - public static final String[] COMPONENTS = new String[] { "Magnitude", "X", "Y", "Z" }; - - private int component; + public static final String MAGNITUDE = "Magnitude"; + public static final String X = "X"; + public static final String Y = "Y"; + public static final String Z = "Z"; + + private int componentIndex; private String name; private DataType dataType; - private double[] range; private ScalarBarType scalarBarType; private int resolution; - private boolean automaticRange; - public FieldItem(String fieldName, DataType dataType, int component) { - this.name = fieldName; + private boolean automaticRange; + private double[] originalRange; + private double[] userDefinedRange; + private String fieldName; + + private boolean inverted; + + private boolean visible; + + public FieldItem(String name, String fieldName, DataType dataType, int componentIndex, double[] originalRange) { + this.name = name; + this.fieldName = fieldName; this.dataType = dataType; - this.component = component; - this.range = new double[] { Double.MAX_VALUE, -Double.MAX_VALUE }; - this.scalarBarType = BLUE_TO_RED_RAINBOW; + this.componentIndex = componentIndex; + this.originalRange = originalRange; + this.userDefinedRange = new double[]{Double.NaN, Double.NaN}; + this.scalarBarType = BLUE_TO_RED_HSV; this.resolution = DEFAULT_RESOLUTION; this.automaticRange = true; - } - - public int getComponent() { - return component; + this.visible = true; + this.inverted = false; } public String getName() { return name; } + public String getFieldName() { + return fieldName; + } + public DataType getDataType() { return dataType; } + + public int getComponentIndex() { + return componentIndex; + } + + public ScalarBarType getScalarBarType() { + return scalarBarType; + } + + public void setScalarBarType(ScalarBarType scalarBarType) { + this.scalarBarType = scalarBarType; + } + + public void setVisible(boolean visible) { + this.visible = visible; + } + + public boolean isVisible(){ + return visible; + } + public void setInverted(boolean inverted) { + this.inverted = inverted; + } + + public boolean isInverted() { + return inverted; + } + + public int getResolution() { + return resolution; + } + + public void setResolution(int resolution) { + this.resolution = resolution; + } + + /* + * Range + */ public void setAutomaticRange(boolean automaticRange) { this.automaticRange = automaticRange; + if(isUserDefinedRange() && Double.isNaN(userDefinedRange[0])){ + this.userDefinedRange = new double[]{originalRange[0], originalRange[1]}; + } } public boolean isAutomaticRange() { return automaticRange; } - public void setRange(double[] range) { - this.range = range; + public boolean isUserDefinedRange() { + return !automaticRange; } - public double[] getRange() { - return range; + public double[] getUserDefinedRange() { + return userDefinedRange; } - public ScalarBarType getScalarBarType() { - return scalarBarType; + public void setUserDefinedRange(double[] userDefinedRange) { + this.userDefinedRange = userDefinedRange; + } + + public void setOriginalRange(double[] originalRange) { + this.originalRange = originalRange; } - public void setScalarBarType(ScalarBarType scalarBarType) { - this.scalarBarType = scalarBarType; + public double[] range() { + return automaticRange ? originalRange : userDefinedRange; + } + + public static FieldItem solidColorItem(){ + return new FieldItem(FieldItem.SOLID, null, DataType.NONE, -1, null); } - public int getResolution() { - return resolution; - } - - public void setResolution(int resolution) { - this.resolution = resolution; + public static FieldItem indexItem(){ + return new FieldItem(FieldItem.INDEXED, null, DataType.NONE, -1, null); } public enum DataType { @@ -112,22 +170,27 @@ public class FieldItem { return this.equals(NONE); } } - + @Override public String toString() { - return name; + String range = isScalar() ? "[ " + range()[0] + ", " + range()[1] + "]" : "[ - , - ]"; + return name + " fieldName: " + fieldName + " componentIndex: " + componentIndex + " range " + range + " automatic [ " + automaticRange + " ] - resolution [" + resolution + "] - data type [" + dataType + "] - scalarbar type [" + scalarBarType + " ] - inverted [" + inverted + "]"; } public boolean isScalar() { - return ! SOLID.equals(name) && ! INDEXED.equals(name); + return !isSolid() && !isIndexed(); } public boolean isSolid() { return SOLID.equals(name); } - + public boolean isIndexed() { return INDEXED.equals(name); } - + + public double[] getOriginalRange() { + return originalRange; + } + } diff --git a/src/eu/engys/core/project/mesh/FieldItems.java b/src/eu/engys/core/project/mesh/FieldItems.java new file mode 100644 index 0000000..d3b2c79 --- /dev/null +++ b/src/eu/engys/core/project/mesh/FieldItems.java @@ -0,0 +1,201 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.core.project.mesh; + +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; + +public class FieldItems { + + private Map cellFieldMap; + private Map pointFieldMap; + + public FieldItems() { + this.cellFieldMap = new LinkedHashMap<>(); + this.pointFieldMap = new LinkedHashMap<>(); + } + + public void clear() { + cellFieldMap.clear(); + pointFieldMap.clear(); + } + + public Set cellFieldKeys() { + return cellFieldMap.keySet(); + } + + public Set pointFieldKeys() { + return pointFieldMap.keySet(); + } + + public FieldItem getCellFieldItem(String key) { + return cellFieldMap.get(key); + } + + public FieldItem getPointFieldItem(String key) { + return pointFieldMap.get(key); + } + + public void addPointFieldItem(FieldItem item) { + pointFieldMap.put(item.getName(), item); + } + + public void addCellFieldItem(FieldItem item) { + cellFieldMap.put(item.getName(), item); + } + + public List getPointFieldItems() { + List items = new ArrayList(); + for (FieldItem fi : pointFieldMap.values()) { + if (fi.isVisible()) { + items.add(fi); + } + } + return items; + } + + public List getCellFieldItems() { + List items = new ArrayList(); + for (FieldItem fi : cellFieldMap.values()) { + if (fi.isVisible()) { + items.add(fi); + } + } + return items; + } + + public boolean containsCellFieldItem(String key) { + return cellFieldMap.containsKey(key); + } + + public boolean containsPointFieldItem(String key) { + return pointFieldMap.containsKey(key); + } + + public boolean containsVisibleCellFieldItem(String key) { + boolean contains = cellFieldMap.containsKey(key); + if (contains) { + return cellFieldMap.get(key).isVisible(); + } else { + return false; + } + } + + public boolean containsVisiblePointFieldItem(String key) { + boolean contains = pointFieldMap.containsKey(key); + if (contains) { + return pointFieldMap.get(key).isVisible(); + } else { + return false; + } + } + + // For test purposes only + public Map getPointFieldMap() { + return pointFieldMap; + } + + // For test purposes only + public Map getCellFieldMap() { + return cellFieldMap; + } + + public FieldItem getEquivalentFieldItemOf(FieldItem sample) { + if (sample.getDataType().isCell()) { + if (containsVisibleCellFieldItem(sample.getName())) { + return cellFieldMap.get(sample.getName()); + } else { + return FieldItem.solidColorItem(); + } + } else if (sample.getDataType().isPoint()) { + if (containsVisiblePointFieldItem(sample.getName())) { + return pointFieldMap.get(sample.getName()); + } else { + return FieldItem.solidColorItem(); + } + } else if (sample.getDataType().isNone()) { + if (sample.isIndexed()) { + return FieldItem.indexItem(); + } else { + return FieldItem.solidColorItem(); + } + } else { + return FieldItem.solidColorItem(); + } + } + + public void addFieldItems(FieldItems fieldItems) { + for (FieldItem fieldItem : fieldItems.getCellFieldItems()) { + updateCellFieldMap(fieldItem); + } + fixCellFieldItemsVisibility(fieldItems.cellFieldKeys()); + + for (FieldItem fieldItem : fieldItems.getPointFieldItems()) { + updatePointFieldMap(fieldItem); + } + fixPointFieldItemsVisibility(fieldItems.pointFieldKeys()); + } + + private void updateCellFieldMap(FieldItem item) { + if (containsCellFieldItem(item.getName())) { + // Just update the range used in automatic calculation + FieldItem fi = getCellFieldItem(item.getName()); + fi.setOriginalRange(item.getOriginalRange()); + fi.setVisible(true); + } else { + addCellFieldItem(item); + } + } + + private void fixCellFieldItemsVisibility(Set set) { + for (String key : cellFieldKeys()) { + if (!set.contains(key)) { + getCellFieldItem(key).setVisible(false); + } + } + } + + private void updatePointFieldMap(FieldItem item) { + if (containsPointFieldItem(item.getName())) { + // Just update the range used in automatic calculation + FieldItem fi = getPointFieldItem(item.getName()); + fi.setOriginalRange(item.getOriginalRange()); + fi.setVisible(true); + } else { + addPointFieldItem(item); + } + } + + private void fixPointFieldItemsVisibility(Set list) { + for (String key : pointFieldKeys()) { + if (!list.contains(key)) { + getPointFieldItem(key).setVisible(false); + } + } + } +} diff --git a/src/eu/engys/core/project/mesh/InternalMesh.java b/src/eu/engys/core/project/mesh/InternalMesh.java new file mode 100644 index 0000000..1abd712 --- /dev/null +++ b/src/eu/engys/core/project/mesh/InternalMesh.java @@ -0,0 +1,38 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.core.project.mesh; + +public class InternalMesh { + + private FieldItems fieldItems; + + public InternalMesh() { + this.fieldItems = new FieldItems(); + } + + public FieldItems getFieldItems() { + return fieldItems; + } +} diff --git a/src/eu/engys/core/project/mesh/Mesh.java b/src/eu/engys/core/project/mesh/Mesh.java index 36d87dc..0d13ef8 100644 --- a/src/eu/engys/core/project/mesh/Mesh.java +++ b/src/eu/engys/core/project/mesh/Mesh.java @@ -1,119 +1,45 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.mesh; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.LinkedHashMap; import java.util.LinkedList; import java.util.List; -import java.util.Map; -import java.util.Stack; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import org.apache.commons.io.input.ReversedLinesFileReader; - -import eu.engys.core.controller.actions.RunMesh; -import eu.engys.core.project.Model; -import eu.engys.core.project.openFOAMProject; -import eu.engys.util.RegexpUtils; public class Mesh { - private static final String HELYXOS_MESH_START_TAG = "Layer mesh : "; - private static final String HELYX_MESH_START_TAG = "Final mesh : "; - private long numberOfPoints = 0; - private long numberOfCells = 0; - private long numberOfFaces = 0; - private double meshTime = 0; + private ExternalMesh externalMesh; + private InternalMesh internalMesh; + private MeshInfo meshInfo; - private List cellsPerRefinementLevel = new ArrayList<>(); + private List timeSteps; - private int memorySize = 0; - private double[] bounds = new double[6]; - - private List timeSteps = new LinkedList<>(); - - private Map cellFieldMap = new LinkedHashMap<>(); - private Map pointFieldMap = new LinkedHashMap<>(); - - private Map> timeStepCellFieldsMap = new HashMap>(); - private Map> timeStepPointFieldsMap = new HashMap>(); - private List regions; - - public long getNumberOfPoints() { - return numberOfPoints; - } - - public void setNumberOfPoints(int numberOfPoints) { - this.numberOfPoints = numberOfPoints; - } - - public long getNumberOfCells() { - return numberOfCells; - } - - public void setNumberOfCells(int numberOfCells) { - this.numberOfCells = numberOfCells; - } - - public long getNumberOfFaces() { - return this.numberOfFaces; - } - - public void setNumberOfFaces(int numberOfFaces) { - this.numberOfFaces = numberOfFaces; - } - - public double getMeshTime() { - return meshTime; - } - - public List getCellsPerRefinementLevel() { - return cellsPerRefinementLevel; - } - - public int getMemorySize() { - return memorySize; - } - - public void setMemorySize(int memorySize) { - this.memorySize = memorySize; - } - - public double[] getBounds() { - return bounds; - } - - public void setBounds(double[] bounds) { - this.bounds = bounds; + public Mesh() { + this.externalMesh = new ExternalMesh(); + this.internalMesh = new InternalMesh(); + this.meshInfo = new MeshInfo(); + this.timeSteps = new LinkedList<>(); } public List getTimeSteps() { @@ -124,78 +50,23 @@ public class Mesh { this.timeSteps = timeSteps; } - public List getRegions() { - return regions; - } - public void setRegions(List regions) { - this.regions = regions; - } - - public Map getCellFieldMap() { - return cellFieldMap; + public ExternalMesh getExternalMesh() { + return externalMesh; } - public Map getPointFieldMap() { - return pointFieldMap; - } - - public Map> getTimeStepCellFieldsMap() { - return timeStepCellFieldsMap; - } - - public Map> getTimeStepPointFieldsMap() { - return timeStepPointFieldsMap; + public InternalMesh getInternalMesh() { + return internalMesh; } - public void readStatistics(Model model) { - Path log = model.getProject().getBaseDir().toPath().resolve(openFOAMProject.LOG).resolve(RunMesh.LOG_NAME); - if (Files.exists(log)) { - try (ReversedLinesFileReader reader = new ReversedLinesFileReader(log.toFile())) { - Stack stack = new Stack<>(); - while (true) { - String line = reader.readLine(); - stack.push(line); - if (stack.peek().startsWith(HELYX_MESH_START_TAG)) { - read(stack, HELYX_MESH_START_TAG); - break; - } else if (stack.peek().startsWith(HELYXOS_MESH_START_TAG)) { - read(stack, HELYXOS_MESH_START_TAG); - break; - } - } - } catch (Exception e) { - } - } + public MeshInfo getMeshInfo() { + return meshInfo; } - - private void read(Stack stack, String startTag) { - while (!stack.isEmpty()) { - String line = stack.pop(); - Pattern pattern1 = Pattern.compile(startTag + "cells:(\\d+)\\s+faces:(\\d+)\\s+points:(\\d+)"); - Matcher matcher1 = pattern1.matcher(line); - if (matcher1.matches()) { - this.numberOfCells = Integer.valueOf(matcher1.group(1)); - this.numberOfFaces = Integer.valueOf(matcher1.group(2)); - this.numberOfPoints = Integer.valueOf(matcher1.group(3)); - } else if (line.startsWith("Cells per refinement level:")) { - this.cellsPerRefinementLevel.clear(); - String row = stack.pop(); - while (!row.startsWith("Writing mesh")) { - Pattern pattern2 = Pattern.compile("\\s+(\\d)\\s+(\\d+)"); - Matcher matcher2 = pattern2.matcher(row); - if (matcher2.matches()) { - this.cellsPerRefinementLevel.add(Integer.valueOf(matcher2.group(2))); - } - row = stack.pop(); - } - } else if (line.startsWith("Finished meshing in")) { - Pattern pattern3 = Pattern.compile("Finished meshing in =\\s+(" + RegexpUtils.DOUBLE + ")\\s+s."); - Matcher matcher3 = pattern3.matcher(line); - if (matcher3.matches()) { - this.meshTime = Double.valueOf(matcher3.group(1)); - } - } - } + public void setMeshInfo(MeshInfo meshInfo) { + this.meshInfo = meshInfo; + } + + public boolean isEmpty() { + return meshInfo.getCells() == 0; } } diff --git a/src/eu/engys/core/project/mesh/MeshInfo.java b/src/eu/engys/core/project/mesh/MeshInfo.java new file mode 100644 index 0000000..8bdb968 --- /dev/null +++ b/src/eu/engys/core/project/mesh/MeshInfo.java @@ -0,0 +1,201 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.core.project.mesh; + + +public class MeshInfo { + + static final String MESH_INFO = "mesh.info"; + + static final String POINTS = "points"; + static final String CELLS = "cells"; + static final String FACES = "faces"; + static final String INTERNAL_FACES = "internal faces"; + + static final String BOUNDARY_PATCHES = "boundary patches"; + static final String POINT_ZONES = "point zones"; + static final String FACE_ZONES = "face zones"; + static final String CELL_ZONES = "cell zones"; + + static final String HEXAHEDRA = "hexahedra"; + static final String PRISMS = "prisms"; + static final String WEDGES = "wedges"; + static final String PYRAMIDS = "pyramids"; + static final String TET_WEDGES = "tet wedges"; + static final String TETRAHEDRA = "tetrahedra"; + static final String POLYHEDRA = "polyhedra"; + + public static final long NONE = -1; + + private long points = NONE; + private long cells = NONE; + private long faces = NONE; + private long internalFaces = NONE; + + private long boundaryPatches = NONE; + private long pointZones = NONE; + private long faceZones = NONE; + private long cellZones = NONE; + + private long hexahedra = NONE; + private long prisms = NONE; + private long wedges = NONE; + private long pyramids = NONE; + private long tetWedges = NONE; + private long tetrahedra = NONE; + private long polyhedra = NONE; + + + private double meshTime = 0; +// private List cellsPerRefinementLevel; + +// public MeshInfo() { +// this.cellsPerRefinementLevel = new ArrayList<>(); +// } + + public long getPoints() { + return points; + } + public void setPoints(long points) { + this.points = points; + } + + public long getCells() { + return cells; + } + public void setCells(long cells) { + this.cells = cells; + } + + public long getFaces() { + return faces; + } + public void setFaces(long faces) { + this.faces = faces; + } + + public long getInternalFaces() { + return internalFaces; + } + public void setInternalFaces(long internalFaces) { + this.internalFaces = internalFaces; + } + + public long getBoundaryPatches() { + return boundaryPatches; + } + public void setBoundaryPatches(long boundaryPatches) { + this.boundaryPatches = boundaryPatches; + } + + public long getPointZones() { + return pointZones; + } + public void setPointZones(long pointZones) { + this.pointZones = pointZones; + } + + public long getFaceZones() { + return faceZones; + } + public void setFaceZones(long faceZones) { + this.faceZones = faceZones; + } + + public long getCellZones() { + return cellZones; + } + public void setCellZones(long cellZones) { + this.cellZones = cellZones; + } + + public long getHexahedra() { + return hexahedra; + } + public void setHexahedra(long hexahedra) { + this.hexahedra = hexahedra; + } + + public long getPrisms() { + return prisms; + } + public void setPrisms(long prisms) { + this.prisms = prisms; + } + + public long getWedges() { + return wedges; + } + public void setWedges(long wedges) { + this.wedges = wedges; + } + + public long getPyramids() { + return pyramids; + } + public void setPyramids(long pyramids) { + this.pyramids = pyramids; + } + + public long getTetWedges() { + return tetWedges; + } + public void setTetWedges(long tetWedges) { + this.tetWedges = tetWedges; + } + + public long getTetrahedra() { + return tetrahedra; + } + public void setTetrahedra(long tetrahedra) { + this.tetrahedra = tetrahedra; + } + + public long getPolyhedra() { + return polyhedra; + } + public void setPolyhedra(long polyhedra) { + this.polyhedra = polyhedra; + } + + public boolean isValid() { + return points > NONE; + } + +// public double getMeshTime() { +// return meshTime; +// } +// public void setMeshTime(double meshTime) { +// this.meshTime = meshTime; +// } +// +// public void setCellsPerRefinementLevel(List cellsPerRefinementLevel) { +// this.cellsPerRefinementLevel = cellsPerRefinementLevel; +// } +// public List getCellsPerRefinementLevel() { +// return cellsPerRefinementLevel; +// } + +} diff --git a/src/eu/engys/core/project/mesh/MeshInfoReader.java b/src/eu/engys/core/project/mesh/MeshInfoReader.java new file mode 100644 index 0000000..db8df62 --- /dev/null +++ b/src/eu/engys/core/project/mesh/MeshInfoReader.java @@ -0,0 +1,267 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.core.project.mesh; + +import static eu.engys.core.project.mesh.MeshInfo.BOUNDARY_PATCHES; +import static eu.engys.core.project.mesh.MeshInfo.CELLS; +import static eu.engys.core.project.mesh.MeshInfo.CELL_ZONES; +import static eu.engys.core.project.mesh.MeshInfo.FACES; +import static eu.engys.core.project.mesh.MeshInfo.FACE_ZONES; +import static eu.engys.core.project.mesh.MeshInfo.HEXAHEDRA; +import static eu.engys.core.project.mesh.MeshInfo.INTERNAL_FACES; +import static eu.engys.core.project.mesh.MeshInfo.POINTS; +import static eu.engys.core.project.mesh.MeshInfo.POINT_ZONES; +import static eu.engys.core.project.mesh.MeshInfo.POLYHEDRA; +import static eu.engys.core.project.mesh.MeshInfo.PRISMS; +import static eu.engys.core.project.mesh.MeshInfo.PYRAMIDS; +import static eu.engys.core.project.mesh.MeshInfo.TETRAHEDRA; +import static eu.engys.core.project.mesh.MeshInfo.TET_WEDGES; +import static eu.engys.core.project.mesh.MeshInfo.WEDGES; +import static eu.engys.core.project.openFOAMProject.LOG; +import static java.lang.Integer.valueOf; + +import java.io.File; +import java.util.Stack; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import org.apache.commons.io.input.ReversedLinesFileReader; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import eu.engys.core.controller.actions.RunMesh; +import eu.engys.core.dictionary.BeanToDict; +import eu.engys.core.dictionary.Dictionary; +import eu.engys.core.project.Model; +import eu.engys.core.project.system.ProjectDict; +import eu.engys.util.Util; + +public class MeshInfoReader { + + private static final int MAX_LINES = 500; + + private static final Logger logger = LoggerFactory.getLogger(MeshInfoReader.class); + + private static final String HELYXOS_SNAPPY_START_TAG = "Layer mesh : "; + private static final String HELYX_SNAPPY_START_TAG = "Final mesh : "; + private static final String HELYX_CHECKMESH_START_TAG = "Mesh stats"; + + private Model model; + + public MeshInfoReader(Model model) { + this.model = model; + } + + public void read() { + ProjectDict projectDict = model.getProject().getSystemFolder().getProjectDict(); + + File snappy = model.getProject().getBaseDir().toPath().resolve(LOG).resolve(RunMesh.LOG_NAME).toFile(); + if (projectDict != null && projectDict.getMeshInfoDict() != null && !projectDict.getMeshInfoDict().isEmpty()) { + logger.debug("Read mesh statistics from {}", projectDict.getName()); + read(projectDict.getMeshInfoDict()); + } else if (snappy.exists()) { + logger.debug("Read mesh statistics from {}", snappy); + read(snappy); + } else { + logger.warn("Unable to read mesh statistics. No suitable files"); + } + } + + private void read(Dictionary meshInfoDict) { + MeshInfo meshInfo = model.getMesh().getMeshInfo(); + BeanToDict.dictToBean(meshInfoDict, meshInfo); + } + + public void read(File log) { + MeshInfo meshInfo = model.getMesh().getMeshInfo(); + if (log.exists()) { + try (ReversedLinesFileReader reader = new ReversedLinesFileReader(log, 4096, Util.UTF_8)) { + logger.debug("Read mesh statistics from {}", log); + Stack stack = new Stack<>(); + while (true) { + String line = reader.readLine(); + stack.push(line); + if (stack.peek().startsWith(HELYX_CHECKMESH_START_TAG)) { + readMeshStats(meshInfo, stack, HELYX_CHECKMESH_START_TAG); + break; + } else if (stack.peek().startsWith(HELYX_SNAPPY_START_TAG)) { + read(meshInfo, stack, HELYX_SNAPPY_START_TAG); + break; + } else if (stack.peek().startsWith(HELYXOS_SNAPPY_START_TAG)) { + read(meshInfo, stack, HELYXOS_SNAPPY_START_TAG); + break; + } else if (stack.size() > MAX_LINES) { + logger.warn("Unable to load mesh statistics, max buffer length ({} lines) exeeded", MAX_LINES); + break; + } + } + } catch (Exception e) { + logger.warn("Unable to load mesh statistics, error is: {}", e.getMessage()); + } + } else { + logger.warn("Unable to load mesh statistics, file {} does not exist.", log.toString()); + } + } + + private static final Pattern PATTERN(String label) { + return Pattern.compile("\\s+" + label + ":\\s+(\\d+)\\s*.*"); + } + + private void readMeshStats(MeshInfo meshInfo, Stack stack, String startTag) { + while (!stack.isEmpty()) { + String line = stack.pop(); + Matcher matcher = null; + if ((matcher = PATTERN(POINTS).matcher(line)).matches()) { + meshInfo.setPoints(valueOf(matcher.group(1))); + } else if ((matcher = PATTERN(CELLS).matcher(line)).matches()) { + meshInfo.setCells(valueOf(matcher.group(1))); + } else if ((matcher = PATTERN(FACES).matcher(line)).matches()) { + meshInfo.setFaces(valueOf(matcher.group(1))); + } else if ((matcher = PATTERN(INTERNAL_FACES).matcher(line)).matches()) { + meshInfo.setInternalFaces(valueOf(matcher.group(1))); + } + + else if ((matcher = PATTERN(BOUNDARY_PATCHES).matcher(line)).matches()) { + meshInfo.setBoundaryPatches(valueOf(matcher.group(1))); + } else if ((matcher = PATTERN(POINT_ZONES).matcher(line)).matches()) { + meshInfo.setPointZones(valueOf(matcher.group(1))); + } else if ((matcher = PATTERN(FACE_ZONES).matcher(line)).matches()) { + meshInfo.setFaceZones(valueOf(matcher.group(1))); + } else if ((matcher = PATTERN(CELL_ZONES).matcher(line)).matches()) { + meshInfo.setCellZones(valueOf(matcher.group(1))); + } + + else if ((matcher = PATTERN(HEXAHEDRA).matcher(line)).matches()) { + meshInfo.setHexahedra(valueOf(matcher.group(1))); + } else if ((matcher = PATTERN(PRISMS).matcher(line)).matches()) { + meshInfo.setPrisms(valueOf(matcher.group(1))); + } else if ((matcher = PATTERN(WEDGES).matcher(line)).matches()) { + meshInfo.setWedges(valueOf(matcher.group(1))); + } else if ((matcher = PATTERN(PYRAMIDS).matcher(line)).matches()) { + meshInfo.setPyramids(valueOf(matcher.group(1))); + } else if ((matcher = PATTERN(TET_WEDGES).matcher(line)).matches()) { + meshInfo.setTetWedges(valueOf(matcher.group(1))); + } else if ((matcher = PATTERN(TETRAHEDRA).matcher(line)).matches()) { + meshInfo.setTetrahedra(valueOf(matcher.group(1))); + } else if ((matcher = PATTERN(POLYHEDRA).matcher(line)).matches()) { + meshInfo.setPolyhedra(valueOf(matcher.group(1))); + } + +// else if (line.startsWith("Finished meshing in")) { +// System.out.println("MeshInfoReader.readMeshStats() " + line); +// Pattern pattern3 = Pattern.compile("Finished meshing in =\\s+(" + RegexpUtils.DOUBLE + ")\\s+s."); +// Matcher matcher3 = pattern3.matcher(line); +// if (matcher3.matches()) { +// meshInfo.setMeshTime(Double.valueOf(matcher3.group(1))); +// } +// } + } + } + + private void read(MeshInfo meshInfo, Stack stack, String startTag) { + while (!stack.isEmpty()) { + String line = stack.pop(); + Pattern pattern1 = Pattern.compile(startTag + "cells:(\\d+)\\s+faces:(\\d+)\\s+points:(\\d+)"); + Matcher matcher1 = pattern1.matcher(line); + if (matcher1.matches()) { + meshInfo.setCells(valueOf(matcher1.group(1))); + meshInfo.setFaces(valueOf(matcher1.group(2))); + meshInfo.setPoints(valueOf(matcher1.group(3))); +// } else if (line.startsWith("Cells per refinement level:")) { +// meshInfo.getCellsPerRefinementLevel().clear(); +// String row = stack.pop(); +// while (!row.startsWith("Writing mesh")) { +// Pattern pattern2 = Pattern.compile("\\s+(\\d)\\s+(\\d+)"); +// Matcher matcher2 = pattern2.matcher(row); +// if (matcher2.matches()) { +// meshInfo.getCellsPerRefinementLevel().add(Integer.valueOf(matcher2.group(2))); +// } +// row = stack.pop(); +// } +// } else if (line.startsWith("Finished meshing in")) { +// Pattern pattern3 = Pattern.compile("Finished meshing in =\\s+(" + RegexpUtils.DOUBLE + ")\\s+s."); +// Matcher matcher3 = pattern3.matcher(line); +// if (matcher3.matches()) { +// meshInfo.setMeshTime(Double.valueOf(matcher3.group(1))); +// } + } + } + } + + /* CHECK MESH + +Mesh stats + faces per cell: 4 + boundary patches: 6 + +Overall number of cells of each type: + hexahedra: 0 + prisms: 0 + wedges: 0 + pyramids: 0 + tet wedges: 0 + tetrahedra: 608646 + polyhedra: 0 + +Mesh OK. + +End + */ + + /* SNAPPYHEXMESH + +Final Mesh Summary Report +------------------------- + +Mesh stats +---------- + + edges: 662929 + layers cells: 66012 + layer coverage: 99.9 % + boundary patches: 5 + mesh regions: 1 + domain volume: 0.0014602 + domain bounding box: ( -0.20115 -0.010411 0.053001 ) ( 0.091596 0.20405 0.2185 ) + +Overall number of cells of each type +------------------------------------ + + hexahedra: 176434 (80.449 %) + prisms: 25826 (11.8 %) + wedges: 4865 (2.22 %) + pyramids: 43 (0.0196 %) + tet wedges: 866 (0.395 %) + tetrahedra: 4555 (2.08 %) + polyhedra: 6722 (3.07 %) + +Cells per refinement level +-------------------------- + + 0 219311 (spacing: 1.99 mm) + + */ + +} diff --git a/src/eu/engys/core/project/mesh/MeshInfoWriter.java b/src/eu/engys/core/project/mesh/MeshInfoWriter.java new file mode 100644 index 0000000..27efcce --- /dev/null +++ b/src/eu/engys/core/project/mesh/MeshInfoWriter.java @@ -0,0 +1,49 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.core.project.mesh; + +import eu.engys.core.dictionary.BeanToDict; +import eu.engys.core.dictionary.Dictionary; +import eu.engys.core.project.Model; +import eu.engys.core.project.system.ProjectDict; + +public class MeshInfoWriter { + + private Model model; + + public MeshInfoWriter(Model model) { + this.model = model; + } + + public void write() { + MeshInfo mi = model.getMesh().getMeshInfo(); + Dictionary d = BeanToDict.beanToDict(mi); + if (model.getProject().getSystemFolder().getProjectDict() == null) { + model.getProject().getSystemFolder().setProjectDict(new ProjectDict()); + } + model.getProject().getSystemFolder().getProjectDict().setMeshInfoDict(d); + } + +} diff --git a/src/eu/engys/core/project/mesh/ScalarBarType.java b/src/eu/engys/core/project/mesh/ScalarBarType.java index c0371bc..3b97095 100644 --- a/src/eu/engys/core/project/mesh/ScalarBarType.java +++ b/src/eu/engys/core/project/mesh/ScalarBarType.java @@ -1,350 +1,285 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - -package eu.engys.core.project.mesh; - -import java.util.ArrayList; -import java.util.LinkedList; -import java.util.List; - -import javax.swing.Icon; - -import com.google.common.collect.Lists; - -import eu.engys.util.ui.ResourcesUtil; - -public enum ScalarBarType { - - BLUE_TO_RED_RAINBOW("Rainbow (Blue to Red)", ResourcesUtil.getIcon("scalarbar.rainbow.icon")), - RED_TO_BLUE_RAINBOW("Rainbow (Red to Blue)", ResourcesUtil.getIcon("scalarbar.rainbow.inverted.icon")), - - BLUE_TO_RED_HSV("Blue to Red (HSV)", ResourcesUtil.getIcon("scalarbar.bluetored.hsv.icon")), - RED_TO_BLUE_HSV("Red to Blue (HSV)", ResourcesUtil.getIcon("scalarbar.redtoblue.hsv.icon")), - BLUE_TO_RED_RGB("Blue to Red (RGB)", ResourcesUtil.getIcon("scalarbar.bluetored.rgb.icon")), - RED_TO_BLUE_RGB("Red to Blue (RGB)", ResourcesUtil.getIcon("scalarbar.redtoblue.rgb.icon")), - BLUE_TO_RED_DIV("Blue to Red (Diverging)", ResourcesUtil.getIcon("scalarbar.bluetored.div.icon")), - RED_TO_BLUE_DIV("Red to Blue (Diverging)", ResourcesUtil.getIcon("scalarbar.redtoblue.div.icon")), - - BLUE_TO_YELLOW_HSV("Blue to Yellow (HSV)", ResourcesUtil.getIcon("scalarbar.bluetoyellow.hsv.icon")), - YELLOW_TO_BLUE_HSV("Yellow to Blue (HSV)", ResourcesUtil.getIcon("scalarbar.yellowtoblue.hsv.icon")), - BLUE_TO_YELLOW_RGB("Blue to Yellow (RGB)", ResourcesUtil.getIcon("scalarbar.bluetoyellow.rgb.icon")), - YELLOW_TO_BLUE_RGB("Yellow to Blue (RGB)", ResourcesUtil.getIcon("scalarbar.yellowtoblue.rgb.icon")), - BLUE_TO_YELLOW_DIV("Blue to Yellow (Diverging)", ResourcesUtil.getIcon("scalarbar.bluetoyellow.div.icon")), - YELLOW_TO_BLUE_DIV("Yellow to Blue (Diverging)", ResourcesUtil.getIcon("scalarbar.yellowtoblue.div.icon")), - - BLACK_TO_WHITE("Black to White", ResourcesUtil.getIcon("scalarbar.blacktowhite.icon")), - WHITE_TO_BLACK("White to Black", ResourcesUtil.getIcon("scalarbar.whitetoblack.icon")); - - private String label; - private Icon icon; - - private ScalarBarType(String label, Icon icon) { - this.label = label; - this.icon = icon; - } - - public String getLabel() { - return label; - } - - public List getColors(int resolution) { - switch (label) { - // RAINBOW - case "Rainbow (Blue to Red)": - return getRainbowColors(); - case "Rainbow (Red to Blue)": - return getRainbowColorsInverted(); - // RED TO BLUE - case "Blue to Red (HSV)": - return getBlueToRedHSVColors(resolution); - case "Red to Blue (HSV)": - return getRedToBlueHSVColors(resolution); - case "Blue to Red (RGB)": - return getBlueToRedRGBColors(resolution); - case "Red to Blue (RGB)": - return getRedToBlueRGBColors(resolution); - case "Blue to Red (Diverging)": - return getBlueToRedDivergingColors(resolution); - case "Red to Blue (Diverging)": - return getRedToBlueDivergingColors(resolution); - // BLUE TO YELLOW - case "Blue to Yellow (HSV)": - return getBlueToYellowHSVColors(resolution); - case "Yellow to Blue (HSV)": - return getYellowToBlueHSVColors(resolution); - case "Blue to Yellow (RGB)": - return getBlueToYellowRGBColors(resolution); - case "Yellow to Blue (RGB)": - return getYellowToBlueRGBColors(resolution); - case "Blue to Yellow (Diverging)": - return getBlueToYellowDivergingColors(resolution); - case "Yellow to Blue (Diverging)": - return getYellowToBlueDivergingColors(resolution); - // GRAYSCALE - case "Black to White": - return getBlackToWhiteColors(resolution); - case "White to Black": - return getWhiteToBlackColors(resolution); - default: - return new ArrayList(); - } - } - - public Icon getIcon() { - return icon; - } - - /* - * Utils - */ - - public static Icon getIconByLabel(String label) { - ScalarBarType[] all = values(); - for (ScalarBarType type : all) { - if (type.getLabel().equals(label)) { - return type.getIcon(); - } - } - return null; - } - - public static ScalarBarType getTypeByLabel(String label) { - ScalarBarType[] all = values(); - for (ScalarBarType type : all) { - if (type.getLabel().equals(label)) { - return type; - } - } - return null; - - } - - public static String[] labels() { - ScalarBarType[] all = values(); - String[] labels = new String[all.length]; - for (int i = 0; i < labels.length; i++) { - labels[i] = all[i].getLabel(); - } - return labels; - } - - /***** COLORS *****/ - - /* - * RED TO BLUE - */ - - // HSV (rainbow) - private static List getRainbowColors() { - List colors = new ArrayList<>(); - colors.add(new double[] { 0.667, 0 }); - return colors; - } - - private static List getRainbowColorsInverted() { - List colors = new ArrayList<>(); - colors.add(new double[] { 0, 0.667 }); - return colors; - } - - // HSV (red -> pink -> blue) - private static List getBlueToRedHSVColors(int resolution) { - List colors = new LinkedList<>(); - if (resolution == 1) { - colors.add(new double[] { 0, 0, 1 }); - } else if (resolution == 2) { - colors.add(new double[] { 0, 0, 1 }); - colors.add(new double[] { 1, 0, 0 }); - } else if (resolution > 2) { - int limit1 = (resolution % 2 == 0) ? (resolution / 2) : (resolution - 1)/2; - int limit2 = (resolution - 1)/2; - colors.add(new double[] { 0, 0, 1 }); - for (float i = 1; i < limit1; i++) { - colors.add(new double[] { i / limit1, 0, 1 }); - } - colors.add(new double[] { 1, 0, 1 }); - for (float i = 1; i < limit2; i++) { - colors.add(new double[] { 1, 0, 1 - (i / limit2) }); - } - colors.add(new double[] { 1, 0, 0 }); - } - return colors; - } - - private static List getRedToBlueHSVColors(int resolution) { - return Lists.reverse(getBlueToRedHSVColors(resolution)); - } - - // RGB (red -> blue) - private static List getBlueToRedRGBColors(int resolution) { - List colors = new LinkedList<>(); - if (resolution == 1) { - colors.add(new double[] { 0, 0, 1 }); - } else if (resolution > 1) { - int limit = resolution -1; - colors.add(new double[] { 0, 0, 1 }); - for (float i = 1; i < limit; i++) { - colors.add(new double[] { i / limit, 0, 1 - (i / limit) }); - } - colors.add(new double[] { 1, 0, 0 }); - } - return colors; - } - - private static List getRedToBlueRGBColors(int resolution) { - return Lists.reverse(getBlueToRedRGBColors(resolution)); - } - - // DIVERGING (red -> white -> blue) - private static List getBlueToRedDivergingColors(int resolution) { - List colors = new LinkedList<>(); - if (resolution == 1) { - colors.add(new double[] { 0, 0, 1 }); - } else if (resolution == 2) { - colors.add(new double[] { 0, 0, 1 }); - colors.add(new double[] { 1, 0, 0 }); - } else if (resolution > 2) { - int limit1 = (resolution % 2 == 0) ? (resolution / 2) : (resolution - 1)/2; - int limit2 = (resolution - 1)/2; - colors.add(new double[] { 0, 0, 1 }); - for (float i = 1; i < limit1; i++) { - colors.add(new double[] { i / limit1, i / limit1, 1 }); - } - colors.add(new double[] { 1, 1, 1 }); - for (float i = 1; i < limit2; i++) { - colors.add(new double[] { 1, 1 - (i / limit2), 1 - (i / limit2) }); - } - colors.add(new double[] { 1, 0, 0 }); - } - return colors; - } - - private static List getRedToBlueDivergingColors(int resolution) { - return Lists.reverse(getBlueToRedDivergingColors(resolution)); - } - - /* - * BLUE TO YELLOW - */ - - // HSV (blue -> green -> yellow) - private static List getBlueToYellowHSVColors(int resolution) { - List colors = new LinkedList<>(); - if (resolution == 1) { - colors.add(new double[] { 0, 0, 1 }); - } else if (resolution == 2) { - colors.add(new double[] { 0, 0, 1 }); - colors.add(new double[] { 1, 1, 0 }); - } else if (resolution > 2) { - int limit1 = (resolution % 2 == 0) ? (resolution / 2) : (resolution - 1)/2; - int limit2 = (resolution - 1)/2; - colors.add(new double[] { 0, 0, 1 }); - for (float i = 1; i < limit1; i++) { - colors.add(new double[] { 0, i / limit1, 1 - (i / limit1) }); - } - colors.add(new double[] { 0, 1, 0 }); - for (float i = 1; i < limit2; i++) { - colors.add(new double[] { 1 - (i / limit2), 1, 0 }); - } - colors.add(new double[] { 1, 1, 0 }); - } - return colors; - } - - private static List getYellowToBlueHSVColors(int resolution) { - return Lists.reverse(getBlueToYellowHSVColors(resolution)); - } - - // RGB (blue -> yellow) - private static List getBlueToYellowRGBColors(int resolution) { - List colors = new LinkedList<>(); - if (resolution == 1) { - colors.add(new double[] { 0, 0, 1 }); - } else if (resolution > 1) { - int limit = resolution - 1; - colors.add(new double[] { 0, 0, 1 }); - for (float i = 1; i < limit; i++) { - colors.add(new double[] { i / limit, i / limit, 1 - (i / limit) }); - } - colors.add(new double[] { 1, 1, 0 }); - } - return colors; - } - - private static List getYellowToBlueRGBColors(int resolution) { - return Lists.reverse(getBlueToYellowRGBColors(resolution)); - } - - // DIVERGING (blue -> white -> yellow) - private static List getBlueToYellowDivergingColors(int resolution) { - List colors = new LinkedList<>(); - if (resolution == 1) { - colors.add(new double[] { 0, 0, 1 }); - } else if (resolution == 2) { - colors.add(new double[] { 0, 0, 1 }); - colors.add(new double[] { 1, 1, 0 }); - } else if (resolution > 2) { - int limit1 = (resolution % 2 == 0) ? (resolution / 2) : (resolution - 1)/2; - int limit2 = (resolution - 1)/2; - colors.add(new double[] { 0, 0, 1 }); - for (float i = 1; i < limit1; i++) { - colors.add(new double[] { i / limit1, i / limit1, 1 }); - } - colors.add(new double[] { 1, 1, 1 }); - for (float i = 1; i < limit2; i++) { - colors.add(new double[] { 1, 1, 1 - (i / limit2) }); - } - colors.add(new double[] { 1, 1, 0 }); - } - return colors; - } - - private static List getYellowToBlueDivergingColors(int resolution) { - return Lists.reverse(getBlueToYellowDivergingColors(resolution)); - } - - /* - * GRAYSCALE - */ - private static List getBlackToWhiteColors(int resolution) { - List colors = new LinkedList<>(); - if (resolution == 1) { - colors.add(new double[] { 0, 0, 0 }); - } else if (resolution > 1) { - int limit = resolution - 1; - colors.add(new double[] { 0, 0, 0 }); - for (float i = 1; i < limit; i++) { - colors.add(new double[] { i / (limit), i / (limit), i / (limit) }); - } - colors.add(new double[] { 1, 1, 1 }); - } - return colors; - } - - private static List getWhiteToBlackColors(int resolution) { - return Lists.reverse(getBlackToWhiteColors(resolution)); - } - -} +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.core.project.mesh; + +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; + +import javax.swing.Icon; + +import com.google.common.collect.Lists; + +import eu.engys.util.ui.ResourcesUtil; +import vtk.vtkDiscretizableColorTransferFunction; + +public enum ScalarBarType { + + BLUE_TO_RED_HSV("Blue to Red (HSV)", ResourcesUtil.getIcon("scalarbar.bluetored.hsv.icon")), + BLUE_TO_RED_RGB("Blue to Red (RGB)", ResourcesUtil.getIcon("scalarbar.bluetored.rgb.icon")), + BLUE_TO_RED_DIV("Blue to Red (Diverging)", ResourcesUtil.getIcon("scalarbar.bluetored.div.icon")), + BLUE_TO_RED_DESATURATED("Blue to Red (Desaturated)", ResourcesUtil.getIcon("scalarbar.bluetored.des.icon")), + BLUE_TO_RED_JET("Blue to Red (Jet)", ResourcesUtil.getIcon("scalarbar.bluetored.jet.icon")), + COLD_AND_HOT("Cold and Hot", ResourcesUtil.getIcon("scalarbar.bluetored.coldhot.icon")), + + BLUE_TO_YELLOW_HSV("Blue to Yellow (HSV)", ResourcesUtil.getIcon("scalarbar.bluetoyellow.hsv.icon")), + BLUE_TO_YELLOW_RGB("Blue to Yellow (RGB)", ResourcesUtil.getIcon("scalarbar.bluetoyellow.rgb.icon")), + BLUE_TO_YELLOW_DIV("Blue to Yellow (Diverging)", ResourcesUtil.getIcon("scalarbar.bluetoyellow.div.icon")), + + BLACK_TO_WHITE("Black to White", ResourcesUtil.getIcon("scalarbar.blacktowhite.icon")), + BLACK_BODY_RADIATION("Black Body Radiation", ResourcesUtil.getIcon("scalarbar.blackbodyradiation.icon")), + BLACK_BLUE_WHITE("Black Blue and White", ResourcesUtil.getIcon("scalarbar.blackbluewhite.icon")), + BLACK_ORANGE_WHITE("Black Orange and White", ResourcesUtil.getIcon("scalarbar.blackorangewhite.icon")); + + private static final int RGB = 0; + private static final int HSV = 1; + private static final int LAB = 2; + private static final int DIV = 3; + + /** + * 0 -> 0 + * 32 -> 0.125 + * 64 -> 0.25 + * 96 -> 0.375 + * 128 -> 0.5 + * 160 -> 0.625 + * 192 -> 0.75 + * 224 -> 0.875 + * 256 -> 1 + */ +// BLUE_LIGHTER,BLUE_DARKER,CYAN,GREEN_DARK,YELLOW,ORANGE,RED_DARKER,RED_LIGHTER + private static final double[] RED_DARKER = new double[]{0.375, 0, 0}; + private static final double[] RED_DARK = new double[]{0.5, 0, 0}; + private static final double[] RED = new double[]{1, 0, 0}; + private static final double[] RED_LIGHT = new double[]{1, 0.5, 0}; + private static final double[] RED_LIGHTER = new double[]{0.875, 0.375, 0.375}; + + private static final double[] BLUE_DARKER = new double[]{0, 0, 0.375}; + private static final double[] BLUE_DARK = new double[]{0, 0, 0.5}; + private static final double[] BLUE = new double[]{0, 0, 1}; + private static final double[] BLUE_LIGHT = new double[]{0, 0.5, 1}; + private static final double[] BLUE_LIGHTER = new double[]{0, 0.375, 0.875}; + + private static final double[] CYAN = new double[]{0, 1, 1}; + private static final double[] ORANGE = new double[]{1, 0.375, 0}; + private static final double[] YELLOW = new double[]{1, 1, 0}; + + private static final double[] GREEN_DARK = new double[]{0, 0.5, 0}; + private static final double[] GREEN = new double[]{0, 1, 0}; + + private static final double[] BLACK = new double[]{0, 0, 0}; + private static final double[] WHITE = new double[]{1, 1, 1}; + + private String label; + private Icon icon; + + private ScalarBarType(String label, Icon icon) { + this.label = label; + this.icon = icon; + } + + public static Icon getIconByLabel(String label) { + ScalarBarType[] all = values(); + for (ScalarBarType type : all) { + if (type.getLabel().equals(label)) { + return type.getIcon(); + } + } + return null; + } + + public static ScalarBarType getTypeByLabel(String label) { + ScalarBarType[] all = values(); + for (ScalarBarType type : all) { + if (type.getLabel().equals(label)) { + return type; + } + } + return null; + + } + + public static String[] labels() { + ScalarBarType[] all = values(); + String[] labels = new String[all.length]; + for (int i = 0; i < labels.length; i++) { + labels[i] = all[i].getLabel(); + } + return labels; + } + + public List getColors(FieldItem item) { + switch (label) { + case "Blue to Red (HSV)": + return createColors(item, Lists.newArrayList(BLUE, RED), HSV, false); + case "Blue to Red (RGB)": + return createColors(item, Lists.newArrayList(BLUE, RED), RGB, true); + case "Blue to Red (Diverging)": + return createColors(item, Lists.newArrayList(BLUE, RED), DIV, true); + case "Blue to Red (Desaturated)": + return createColors(item, Lists.newArrayList(BLUE_LIGHTER,BLUE_DARKER,CYAN,GREEN_DARK,YELLOW,ORANGE,RED_DARKER,RED_LIGHTER), LAB, true); + case "Blue to Red (Jet)": + return createJetColors(item); + case "Cold and Hot": + return createColdAndHotColors(item); + case "Blue to Yellow (HSV)": + return createColors(item, Lists.newArrayList(BLUE, YELLOW), HSV, true); + case "Blue to Yellow (RGB)": + return createColors(item, Lists.newArrayList(BLUE, YELLOW), RGB, true); + case "Blue to Yellow (Diverging)": + return createColors(item, Lists.newArrayList(BLUE, YELLOW), DIV, true); + case "Black to White": + return createColors(item, Lists.newArrayList(BLACK, WHITE), RGB, true); + case "Black Body Radiation": + return createColors(item, Lists.newArrayList(BLACK, RED, YELLOW, WHITE), RGB, true); + case "Black Blue and White": + return createColors(item, Lists.newArrayList(BLACK, BLUE_DARK, BLUE_LIGHT, WHITE), RGB, true); + case "Black Orange and White": + return createColors(item, Lists.newArrayList(BLACK, RED_DARK, RED_LIGHT, WHITE), RGB, true); + default: + return new ArrayList<>(); + } + } + + private static List createColors(FieldItem item, List colorPivots, int colorSpace, boolean hsvWrap) { + vtkDiscretizableColorTransferFunction function = new vtkDiscretizableColorTransferFunction(); + function.DiscretizeOn(); + switch (colorSpace) { + case RGB: + function.SetColorSpaceToRGB(); + break; + case HSV: + function.SetColorSpaceToHSV(); + break; + case DIV: + function.SetColorSpaceToDiverging(); + break; + case LAB: + function.SetColorSpaceToLab(); + break; + default: + function.SetColorSpaceToRGB(); + break; + } + + function.SetHSVWrap(hsvWrap ? 1 : 0); + + function.SetNumberOfValues(item.getResolution()); + for (int i = 0; i < colorPivots.size(); i++) { + double[] color = colorPivots.get(i); + double index = item.getResolution() / (colorPivots.size() - 1) * i; + function.AddRGBPoint(index, color[0], color[1], color[2]); + } + function.Build(); + + List colors = new LinkedList<>(); + for (int i = 0; i < item.getResolution(); i++) { + double[] c = new double[3]; + function.GetColor(i, c); + colors.add(c); + } + + return item.isInverted() ? Lists.reverse(colors) : colors; + } + + private static List createColdAndHotColors(FieldItem item) { + vtkDiscretizableColorTransferFunction function = new vtkDiscretizableColorTransferFunction(); + function.DiscretizeOn(); + function.SetColorSpaceToRGB(); + function.SetHSVWrap(1); + + double resolution_0 = 0.0; + double resolution_1 = (item.getResolution() / 2) - (item.getResolution() / 20D); + double resolution_2 = item.getResolution() / 2D; + double resolution_3 = (item.getResolution() / 2) + (item.getResolution() / 20D); + double resolution_4 = item.getResolution(); + + function.SetNumberOfValues(item.getResolution()); + function.AddRGBPoint(resolution_0, CYAN[0], CYAN[1], CYAN[2]); + function.AddRGBPoint(resolution_1, BLUE[0], BLUE[1], BLUE[2]); + function.AddRGBPoint(resolution_2, BLUE_DARK[0], BLUE_DARK[1], BLUE_DARK[2]); + function.AddRGBPoint(resolution_3, RED[0], RED[1], RED[2]); + function.AddRGBPoint(resolution_4, YELLOW[0], YELLOW[1], YELLOW[2]); + + function.Build(); + + List colors = new LinkedList<>(); + for (int i = 0; i < item.getResolution(); i++) { + double[] c = new double[3]; + function.GetColor(i, c); + colors.add(c); + } + + return item.isInverted() ? Lists.reverse(colors) : colors; + } + + private static List createJetColors(FieldItem item) { + vtkDiscretizableColorTransferFunction function = new vtkDiscretizableColorTransferFunction(); + function.DiscretizeOn(); + function.SetColorSpaceToRGB(); + function.SetHSVWrap(1); + + double resolution_0 = 0.0; + double resolution_1 = item.getResolution() * (1 / 10D); + double resolution_2 = item.getResolution() * (4 / 10D); + double resolution_3 = item.getResolution() * (5 / 10D); + double resolution_4 = item.getResolution() * (6 / 10D); + double resolution_5 = item.getResolution() * (9 / 10D); + double resolution_6 = item.getResolution(); + + function.SetNumberOfValues(item.getResolution()); + function.AddRGBPoint(resolution_0, BLUE_DARK[0], BLUE_DARK[1], BLUE_DARK[2]); + function.AddRGBPoint(resolution_1, BLUE[0], BLUE[1], BLUE[2]); + function.AddRGBPoint(resolution_2, CYAN[0], CYAN[1], CYAN[2]); + function.AddRGBPoint(resolution_3, GREEN[0], GREEN[1], GREEN[2]); + function.AddRGBPoint(resolution_4, YELLOW[0], YELLOW[1], YELLOW[2]); + function.AddRGBPoint(resolution_5, RED[0], RED[1], RED[2]); + function.AddRGBPoint(resolution_6, RED_DARK[0], RED_DARK[1], RED_DARK[2]); + + function.Build(); + + List colors = new LinkedList<>(); + for (int i = 0; i < item.getResolution(); i++) { + double[] c = new double[3]; + function.GetColor(i, c); + colors.add(c); + } + + return item.isInverted() ? Lists.reverse(colors) : colors; + } + + /* + * Utils + */ + + public String getLabel() { + return label; + } + + public Icon getIcon() { + return icon; + } + +} diff --git a/src/eu/engys/core/project/openFOAMProject.java b/src/eu/engys/core/project/openFOAMProject.java index 8c1311d..365e509 100644 --- a/src/eu/engys/core/project/openFOAMProject.java +++ b/src/eu/engys/core/project/openFOAMProject.java @@ -1,29 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project; import java.io.File; @@ -32,128 +30,131 @@ import eu.engys.core.project.constant.ConstantFolder; import eu.engys.core.project.defaults.Defaults; import eu.engys.core.project.system.SystemFolder; import eu.engys.core.project.zero.ZeroFolder; -import eu.engys.util.progress.ProgressMonitor; import eu.engys.util.progress.SilentMonitor; public class openFOAMProject { - + public static final String LOG = "log"; public static final String HOSTFILE = "hostfile"; public static final String POST_PROC = "postProcessing"; public static final String MACHINEFILE = "machinefile"; - - private final File baseDir; - private final boolean parallel; - private final int processors; - - private final SystemFolder system; - private final ConstantFolder constant; - private final ZeroFolder zero; - - public static openFOAMProject createProject(File baseDir, ProgressMonitor monitor) { - ProjectFolderAnalyzer pa = new ProjectFolderAnalyzer(baseDir, monitor); - ProjectFolderStructure structure = pa.checkAll(); - - return structure.isParallel() ? openFOAMProject.newParallelProject(baseDir, structure.getProcessors()) : openFOAMProject.newSerialProject(baseDir); - } - - public static openFOAMProject createProject(CaseParameters parameters) { - return parameters.isParallel() ? openFOAMProject.newParallelProject(parameters.getBaseDir(), parameters.getnProcessors()) : openFOAMProject.newSerialProject(parameters.getBaseDir()); - } - - public static openFOAMProject newSerialProject(File baseDir) { - return new openFOAMProject(baseDir, false, -1); - } - public static openFOAMProject newDefaultSerialProject(File baseDir, Defaults defaults) { - CreateCase createCase = new CreateCase(defaults, new SilentMonitor()); - CaseParameters caseParams = new CaseParameters(); - caseParams.setParallel(false); - caseParams.setnHierarchy(new int[] { 1, 1, 1 }); - caseParams.setnProcessors(1); - caseParams.setBaseDir(baseDir); - return createCase.create(caseParams); - } + private final File baseDir; + private final boolean parallel; + private final int processors; - public static openFOAMProject newParallelProject(File baseDir) { - return new openFOAMProject(baseDir, true, new ProjectFolderAnalyzer(baseDir, null).findProcessorsFolders()); - } + private final SystemFolder system; + private final ConstantFolder constant; + private final ZeroFolder zero; - public static openFOAMProject newParallelProject(File baseDir, int nProcessors) { - return new openFOAMProject(baseDir, true, nProcessors); - } + public static openFOAMProject createProject(CaseParameters parameters) { + return parameters.isParallel() ? openFOAMProject.newParallelProject(parameters.getBaseDir(), parameters.getnProcessors()) : openFOAMProject.newSerialProject(parameters.getBaseDir()); + } - public static openFOAMProject newCopy(openFOAMProject project) { - return new openFOAMProject(project); - } - - public static openFOAMProject newCopy(File baseDir, openFOAMProject project) { - return new openFOAMProject(baseDir, project); - } - - private openFOAMProject(File baseDir, boolean parallel, int processors) { - this.baseDir = baseDir; - this.parallel = parallel; - this.processors = processors; - - this.system = new SystemFolder(this); - this.constant = new ConstantFolder(this); - this.zero = new ZeroFolder(this); - } - - private openFOAMProject(File baseDir, openFOAMProject prj) { - this.baseDir = baseDir; - this.parallel = prj.parallel; - this.processors = prj.processors; - - this.system = new SystemFolder(baseDir, prj.getSystemFolder()); - this.constant = new ConstantFolder(baseDir, prj.getConstantFolder()); - this.zero = new ZeroFolder(baseDir, prj.getZeroFolder()); - } + public static openFOAMProject newSerialProject(File baseDir) { + return new openFOAMProject(baseDir, false, -1); + } - private openFOAMProject(openFOAMProject prj) { - this.baseDir = prj.baseDir; - this.parallel = prj.parallel; - this.processors = prj.processors; - - this.system = new SystemFolder(baseDir, prj.getSystemFolder()); - this.constant = new ConstantFolder(baseDir, prj.getConstantFolder()); - this.zero = new ZeroFolder(baseDir, prj.getZeroFolder()); - } - - public File getBaseDir() { - return baseDir; - } - public boolean isParallel() { - return parallel; - } - public boolean isSerial() { - return !isParallel(); - } - - public boolean isMeshOnZero() { - ProjectFolderAnalyzer analyzer = new ProjectFolderAnalyzer(getBaseDir(), null).checkSerialOrParallel(); - return analyzer.isParallel_zero() || analyzer.isSerial_zero(); - } - - public int getProcessors() { - return processors; - } + public static openFOAMProject newDefaultSerialProject(File baseDir, Defaults defaults) { + CreateCase createCase = new CreateCase(defaults, new SilentMonitor()); + CaseParameters caseParams = new CaseParameters(); + caseParams.setParallel(false); + caseParams.setnHierarchy(new int[] { 1, 1, 1 }); + caseParams.setnProcessors(1); + caseParams.setBaseDir(baseDir); + return createCase.create(caseParams); + } - public ConstantFolder getConstantFolder() { - return constant; - } - - public SystemFolder getSystemFolder() { - return system; - } + public static openFOAMProject newParallelProject(File baseDir) { + return new openFOAMProject(baseDir, true, new ProjectFolderAnalyzer(baseDir, null).findProcessorsFolders()); + } - public ZeroFolder getZeroFolder() { - return zero; - } - - @Override - public String toString() { - return "PROJECT [ basedir: " + baseDir + " ] - [ parallel: " + parallel + " ] - [ processors: " + processors + "]"; - } + public static openFOAMProject newParallelProject(File baseDir, int nProcessors) { + return new openFOAMProject(baseDir, true, nProcessors); + } + + public static openFOAMProject newCopy(openFOAMProject project) { + return new openFOAMProject(project); + } + + public static openFOAMProject newCopy(File baseDir, openFOAMProject project) { + return new openFOAMProject(baseDir, project); + } + + public openFOAMProject(String path) { + this.baseDir = new File(path); + this.parallel = false; + this.processors = 2; + this.system = new SystemFolder(this); + this.constant = new ConstantFolder(this); + this.zero = new ZeroFolder(this); + } + + private openFOAMProject(File baseDir, boolean parallel, int processors) { + this.baseDir = baseDir; + this.parallel = parallel; + this.processors = processors; + + this.system = new SystemFolder(this); + this.constant = new ConstantFolder(this); + this.zero = new ZeroFolder(this); + } + + private openFOAMProject(File baseDir, openFOAMProject prj) { + this.baseDir = baseDir; + this.parallel = prj.parallel; + this.processors = prj.processors; + + this.system = new SystemFolder(baseDir, prj.getSystemFolder()); + this.constant = new ConstantFolder(baseDir, prj.getConstantFolder()); + this.zero = new ZeroFolder(baseDir, prj.getZeroFolder()); + } + + private openFOAMProject(openFOAMProject prj) { + this.baseDir = prj.baseDir; + this.parallel = prj.parallel; + this.processors = prj.processors; + + this.system = new SystemFolder(baseDir, prj.getSystemFolder()); + this.constant = new ConstantFolder(baseDir, prj.getConstantFolder()); + this.zero = new ZeroFolder(baseDir, prj.getZeroFolder()); + } + + public File getBaseDir() { + return baseDir; + } + + public boolean isParallel() { + return parallel; + } + + public boolean isSerial() { + return !isParallel(); + } + + public boolean isMeshOnZero() { + ProjectFolderAnalyzer analyzer = new ProjectFolderAnalyzer(getBaseDir(), null).checkSerialOrParallel(); + return analyzer.isParallel_Zero() || analyzer.isSerial_Zero(); + } + + public int getProcessors() { + return processors; + } + + public ConstantFolder getConstantFolder() { + return constant; + } + + public SystemFolder getSystemFolder() { + return system; + } + + public ZeroFolder getZeroFolder() { + return zero; + } + + @Override + public String toString() { + return "PROJECT [ basedir: " + baseDir + " ] - [ parallel: " + parallel + " ] - [ processors: " + processors + "]"; + } } diff --git a/src/eu/engys/core/project/runtimefields/RuntimeField.java b/src/eu/engys/core/project/runtimefields/RuntimeField.java index 5fc19ae..dea48b3 100644 --- a/src/eu/engys/core/project/runtimefields/RuntimeField.java +++ b/src/eu/engys/core/project/runtimefields/RuntimeField.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.runtimefields; public class RuntimeField { diff --git a/src/eu/engys/core/project/runtimefields/RuntimeFields.java b/src/eu/engys/core/project/runtimefields/RuntimeFields.java index 1d4d584..2e52ca5 100644 --- a/src/eu/engys/core/project/runtimefields/RuntimeFields.java +++ b/src/eu/engys/core/project/runtimefields/RuntimeFields.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.runtimefields; import static eu.engys.core.dictionary.Dictionary.TYPE; diff --git a/src/eu/engys/core/project/state/AdjointState.java b/src/eu/engys/core/project/state/AdjointState.java new file mode 100644 index 0000000..73342a8 --- /dev/null +++ b/src/eu/engys/core/project/state/AdjointState.java @@ -0,0 +1,51 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.core.project.state; + +public class AdjointState { + + private boolean adjoint; + + public AdjointState() { + this.setAdjoint(false); + } + + public AdjointState(State state) { + this.adjoint = state.isAdjoint(); + } + + public boolean isAdjoint() { + return adjoint; + } + + public void setAdjoint(boolean adjoint) { + this.adjoint = adjoint; + } + + @Override + public String toString() { + return "Adjoint: " + (isAdjoint() ? "ON" : "OFF"); + } +} \ No newline at end of file diff --git a/src/eu/engys/core/project/state/BuoyancyBuilder.java b/src/eu/engys/core/project/state/BuoyancyBuilder.java index 4e9a147..e68dba4 100644 --- a/src/eu/engys/core/project/state/BuoyancyBuilder.java +++ b/src/eu/engys/core/project/state/BuoyancyBuilder.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.state; import eu.engys.core.dictionary.Dictionary; diff --git a/src/eu/engys/core/project/state/EngysTable15.java b/src/eu/engys/core/project/state/EngysTable15.java index d2a08bd..c4bc1d7 100644 --- a/src/eu/engys/core/project/state/EngysTable15.java +++ b/src/eu/engys/core/project/state/EngysTable15.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.state; import java.util.Set; @@ -54,8 +53,12 @@ public class EngysTable15 implements Table15 { if (state.isEnergy() || state.getMultiphaseModel().isMultiphase()) { families.add(SolverFamily.PIMPLE); } else { - families.add(SolverFamily.PIMPLE); - families.add(SolverFamily.PISO); + if(state.isAdjoint()){ + families.add(SolverFamily.PISO); + } else { + families.add(SolverFamily.PISO); + families.add(SolverFamily.PIMPLE); + } } } else { // NONE diff --git a/src/eu/engys/core/project/state/Flow.java b/src/eu/engys/core/project/state/Flow.java index 116296d..2af9987 100644 --- a/src/eu/engys/core/project/state/Flow.java +++ b/src/eu/engys/core/project/state/Flow.java @@ -1,37 +1,41 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.state; +import static eu.engys.util.ui.UiUtil.NONE_LABEL; + public enum Flow { - COMPRESSIBLE("Compressible"), INCOMPRESSIBLE("Incompressible"), NONE("None"); - private String text; + COMPRESSIBLE("compressible", "Compressible"), INCOMPRESSIBLE("incompressible", "Incompressible"), NONE("none", NONE_LABEL); - private Flow(String text) { - this.text = text; + private String key; + private String label; + + private Flow(String key, String label) { + this.key = key; + this.label = label; } public boolean isCompressible() { @@ -46,8 +50,16 @@ public enum Flow { return this == NONE; } + public String key() { + return key; + } + + public String label() { + return label; + } + @Override public String toString() { - return text; + return label; } -} +} \ No newline at end of file diff --git a/src/eu/engys/core/project/state/Mach.java b/src/eu/engys/core/project/state/Mach.java index 1e2dbee..445e617 100644 --- a/src/eu/engys/core/project/state/Mach.java +++ b/src/eu/engys/core/project/state/Mach.java @@ -1,37 +1,40 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.state; +import static eu.engys.util.ui.UiUtil.NONE_LABEL; + public enum Mach { - LOW("Low"), HIGH("High"), NONE("None"); + LOW("loMach", "Low"), HIGH("hiMach", "High"), NONE("none", NONE_LABEL); - private String text; + private String key; + private String label; - private Mach(String text) { - this.text = text; + private Mach(String key, String label) { + this.key = key; + this.label = label; } public boolean isLow() { @@ -46,8 +49,16 @@ public enum Mach { return this == NONE; } + public String key() { + return key; + } + + public String label() { + return label; + } + @Override public String toString() { - return text; + return label; } -} +} \ No newline at end of file diff --git a/src/eu/engys/core/project/state/Method.java b/src/eu/engys/core/project/state/Method.java index 386463d..9bd6b48 100644 --- a/src/eu/engys/core/project/state/Method.java +++ b/src/eu/engys/core/project/state/Method.java @@ -1,37 +1,39 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.state; public enum Method { - LES("Les"), RANS("Rans"), NONE("None"); - private String text; + LES("les", "LES/DES"), RANS("ras", "RANS"), NONE("None", "NONE"); - private Method(String text) { - this.text = text; + private String key; + private String label; + + private Method(String key, String label) { + this.key = key; + this.label = label; } public boolean isLes() { @@ -46,8 +48,16 @@ public enum Method { return this == NONE; } + public String key() { + return key; + } + + public String label() { + return label; + } + @Override public String toString() { - return text; + return label; } -} +} \ No newline at end of file diff --git a/src/eu/engys/core/project/state/MultiphaseModel.java b/src/eu/engys/core/project/state/MultiphaseModel.java index 7ae2c35..5de971d 100644 --- a/src/eu/engys/core/project/state/MultiphaseModel.java +++ b/src/eu/engys/core/project/state/MultiphaseModel.java @@ -1,38 +1,39 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.state; +import org.apache.commons.lang.builder.EqualsBuilder; +import org.apache.commons.lang.builder.HashCodeBuilder; + public class MultiphaseModel { public static final String OFF_LABEL = "Off"; public static final MultiphaseModel OFF = new MultiphaseModel(OFF_LABEL, "", false, false); - + private String label; private boolean multiphase; - private PhasesNumber phasesNumber; private boolean dynamic; private String key; @@ -46,36 +47,41 @@ public class MultiphaseModel { public String getLabel() { return label; } - + public String getKey() { return key; } - + public boolean isMultiphase() { return multiphase; } - + public boolean isDynamic() { return dynamic; } - + public boolean isOff() { return label.equals(OFF_LABEL); } public boolean isOn() { - return ! label.equals(OFF_LABEL); + return !label.equals(OFF_LABEL); } - - public PhasesNumber getPhasesNumber() { - return phasesNumber; - } - + @Override public boolean equals(Object obj) { - if (obj instanceof MultiphaseModel) { - return label.equals(((MultiphaseModel) obj).label); + if (!(obj instanceof MultiphaseModel)) { + return false; } - return super.equals(obj); + if (obj == this) { + return true; + } + MultiphaseModel fz = (MultiphaseModel) obj; + return new EqualsBuilder().append(label, fz.label).isEquals(); + } + + @Override + public int hashCode() { + return new HashCodeBuilder(17, 31).append(label).toHashCode(); } } diff --git a/src/eu/engys/core/project/state/PhaseBuilder.java b/src/eu/engys/core/project/state/PhaseBuilder.java index 72e3b84..6a0f532 100644 --- a/src/eu/engys/core/project/state/PhaseBuilder.java +++ b/src/eu/engys/core/project/state/PhaseBuilder.java @@ -1,37 +1,39 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.state; import static eu.engys.core.modules.materials.MaterialsDatabase.AIR; import static eu.engys.core.modules.materials.MaterialsDatabase.MERCURY; import static eu.engys.core.modules.materials.MaterialsDatabase.OIL; import static eu.engys.core.modules.materials.MaterialsDatabase.WATER; +import static eu.engys.core.project.materials.Material.newDefaultMaterial; + import eu.engys.core.project.Model; import eu.engys.core.project.materials.Material; import eu.engys.core.project.materials.Materials; +import eu.engys.core.project.materials.incompressible.IncompressibleMaterial; public class PhaseBuilder { @@ -47,7 +49,7 @@ public class PhaseBuilder { private static void check1Material(Model model) { Materials materials = model.getMaterials(); if (materials.isEmpty()) { - materials.add(getMaterial(model, AIR)); + materials.add(newDefaultMaterial(model, AIR)); } else if (materials.size() > 1) { int airIndex = 0; for (int i = 0; i < materials.size(); i++) { @@ -71,9 +73,9 @@ public class PhaseBuilder { Material[] knownMaterials = null; if(model.getState().isIncompressible()){ - knownMaterials = new Material[] { getMaterial(model, AIR), getMaterial(model, WATER), getMaterial(model, OIL), getMaterial(model, MERCURY) }; + knownMaterials = new Material[] { newDefaultMaterial(model, AIR), newDefaultMaterial(model, WATER), newDefaultMaterial(model, OIL), newDefaultMaterial(model, MERCURY) }; } else { - knownMaterials = new Material[] { getMaterial(model, AIR), getMaterial(model, WATER) }; + knownMaterials = new Material[] { newDefaultMaterial(model, AIR), newDefaultMaterial(model, WATER) }; } int phases = model.getState().getPhases(); @@ -82,18 +84,10 @@ public class PhaseBuilder { materials.add(knownMaterials[i]); } for (int i = Math.min(phases, knownMaterials.length); i < phases; i++) { - materials.add(new Material("Air" + i, knownMaterials[0].getDictionary())); + materials.add(new IncompressibleMaterial("Air" + i, (IncompressibleMaterial) knownMaterials[0])); } model.materialsChanged(); } - public static Material getMaterial(Model model, String materialName) { - if (model.getState().isCompressible()) { - return new Material(materialName, model.getMaterialsDatabase().getCompressibleMaterial(materialName)); - } else { - return new Material(materialName, model.getMaterialsDatabase().getIncompressibleMaterial(materialName)); - } - } - } diff --git a/src/eu/engys/core/project/state/PhasesNumber.java b/src/eu/engys/core/project/state/PhasesNumber.java index 0a1d32f..d0f46ef 100644 --- a/src/eu/engys/core/project/state/PhasesNumber.java +++ b/src/eu/engys/core/project/state/PhasesNumber.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.state; public class PhasesNumber { diff --git a/src/eu/engys/core/project/state/ServerState.java b/src/eu/engys/core/project/state/ServerState.java index c67ae7a..13cf5f4 100644 --- a/src/eu/engys/core/project/state/ServerState.java +++ b/src/eu/engys/core/project/state/ServerState.java @@ -1,32 +1,34 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.state; import java.io.Serializable; +import org.apache.commons.lang.builder.EqualsBuilder; +import org.apache.commons.lang.builder.HashCodeBuilder; + import eu.engys.core.controller.Command; import eu.engys.core.executor.ExecutorError; import eu.engys.core.project.SolverState; @@ -91,10 +93,18 @@ public class ServerState implements Serializable { @Override public boolean equals(Object obj) { - if (obj instanceof ServerState) { - ServerState state = (ServerState) obj; - return this.command.equals(state.command) && this.solverState.equals(state.solverState); + if (!(obj instanceof ServerState)) { + return false; } - return super.equals(obj); + if (obj == this) { + return true; + } + ServerState fz = (ServerState) obj; + return new EqualsBuilder().append(command, fz.command).append(solverState, fz.solverState).isEquals(); + } + + @Override + public int hashCode() { + return new HashCodeBuilder(17, 31).append(command).append(solverState).toHashCode(); } } diff --git a/src/eu/engys/core/project/state/SolutionState.java b/src/eu/engys/core/project/state/SolutionState.java index 2855250..fbf02bd 100644 --- a/src/eu/engys/core/project/state/SolutionState.java +++ b/src/eu/engys/core/project/state/SolutionState.java @@ -1,122 +1,122 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.state; -import eu.engys.util.ui.ChooserPanel; +import static eu.engys.util.ui.UiUtil.NONE_LABEL; public class SolutionState { - - public static final String NONE = "NONE"; - public static final String TRANSIENT = "Transient"; - public static final String STEADY = "Steady"; - public static final String INCOMPRESSIBLE = "Incompressible"; - public static final String COMPRESSIBLE = "Compressible"; - public static final String SEGREGATED = "Segregated"; - public static final String COUPLED = "Coupled"; - public static final String LES_DES = "LES/DES"; - public static final String RANS = "RANS"; - public static final String HI_MACH = "High"; - public static final String LO_MACH = "Low"; - + + public String solverType; public String time; public String flow; - public String turbulence; - public String solver; + public String method; public String mach; - + public SolutionState() { - this.time = NONE; - this.flow = NONE; - this.turbulence = NONE; - this.solver = NONE; - this.mach = NONE; + this.solverType = SolverType.NONE.label(); + this.time = Time.NONE.label(); + this.flow = Flow.NONE.label(); + this.method = Method.NONE.label(); + this.mach = Mach.NONE.label(); } - + public SolutionState(State state) { - this.time = state.isSteady() ? STEADY : state.isTransient() ? TRANSIENT : NONE; - this.flow = state.isCompressible() ? COMPRESSIBLE : state.isIncompressible() ? INCOMPRESSIBLE : NONE; - this.turbulence = state.isRANS() ? RANS : state.isLES() ? LES_DES : NONE; - this.solver = state.isCoupled() ? COUPLED : state.isSegregated() ? SEGREGATED : NONE; - this.mach = state.isHighMach() ? SolutionState.HI_MACH : state.isLowMach() ? SolutionState.LO_MACH : NONE; + this.solverType = state.isCoupled() ? SolverType.COUPLED.label() : state.isSegregated() ? SolverType.SEGREGATED.label() : SolverType.NONE.label(); + this.time = state.isSteady() ? Time.STEADY.label() : state.isTransient() ? Time.TRANSIENT.label() : Time.NONE.label(); + this.flow = state.isCompressible() ? Flow.COMPRESSIBLE.label() : state.isIncompressible() ? Flow.INCOMPRESSIBLE.label() : Flow.NONE.label(); + this.method = state.isRANS() ? Method.RANS.label() : state.isLES() ? Method.LES.label() : Method.NONE.label(); + this.mach = state.isHighMach() ? Mach.HIGH.label() : state.isLowMach() ? Mach.LOW.label() : Mach.NONE.label(); } public boolean areSolverTypeAndTimeAndFlowAndTurbulenceChoosen() { - boolean timeChoosen = time != ChooserPanel.NONE; - boolean flowChoosen = flow != ChooserPanel.NONE; - boolean turbulenceChoosen = turbulence != ChooserPanel.NONE; - boolean solverTypeChoosen = solver != ChooserPanel.NONE; + boolean solverTypeChoosen = solverType != NONE_LABEL; + boolean timeChoosen = time != NONE_LABEL; + boolean flowChoosen = flow != NONE_LABEL; + boolean turbulenceChoosen = method != NONE_LABEL; return solverTypeChoosen && timeChoosen && flowChoosen && turbulenceChoosen; } public boolean isLowMach() { - return mach.equals(SolutionState.LO_MACH); + return mach.equals(Mach.LOW.label()); } + public boolean isHighMach() { - return mach.equals(SolutionState.HI_MACH); + return mach.equals(Mach.HIGH.label()); } + public boolean isMachNone() { - return mach.equals(NONE); + return mach.equals(Mach.NONE.label()); } public boolean isLES() { - return turbulence.equals(SolutionState.LES_DES); + return method.equals(Method.LES.label()); } + public boolean isRANS() { - return turbulence.equals(SolutionState.RANS); + return method.equals(Method.RANS.label()); } public boolean isTransient() { - return time.equals(SolutionState.TRANSIENT); + return time.equals(Time.TRANSIENT.label()); } + public boolean isSteady() { - return time.equals(SolutionState.STEADY); + return time.equals(Time.STEADY.label()); } + public boolean isTimeNone() { - return time.equals(NONE); + return time.equals(Time.NONE.label()); } - public boolean isSegregated() { - return solver == SolutionState.SEGREGATED; - } - public boolean isCoupled() { - return solver == SolutionState.COUPLED; - } - public boolean isSolverNone() { - return solver == NONE; - } - - public boolean isIncompressible() { - return flow == SolutionState.INCOMPRESSIBLE; - } - public boolean isCompressible() { - return flow == SolutionState.COMPRESSIBLE; - } - public boolean isFlowNone() { - return flow == NONE; + return solverType.equals(SolverType.SEGREGATED.label()); } -} + public boolean isCoupled() { + return solverType.equals(SolverType.COUPLED.label()); + } + + public boolean isSolverNone() { + return solverType.equals(SolverType.NONE.label()); + } + + public boolean isIncompressible() { + return flow.equals(Flow.INCOMPRESSIBLE.label()); + } + + public boolean isCompressible() { + return flow.equals(Flow.COMPRESSIBLE.label()); + } + + public boolean isFlowNone() { + return flow.equals(Flow.NONE.label()); + } + + @Override + public String toString() { + return "SolverType: " + solverType + ", Time: " + time + ", Flow: " + flow + " Method: " + method + ", Mach: " + mach; + } + +} \ No newline at end of file diff --git a/src/eu/engys/core/project/state/Solver.java b/src/eu/engys/core/project/state/Solver.java index a0c9df3..399e859 100644 --- a/src/eu/engys/core/project/state/Solver.java +++ b/src/eu/engys/core/project/state/Solver.java @@ -1,30 +1,32 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.state; +import org.apache.commons.lang.builder.EqualsBuilder; +import org.apache.commons.lang.builder.HashCodeBuilder; + public class Solver { private final String name; @@ -50,14 +52,19 @@ public class Solver { @Override public boolean equals(Object obj) { - if (obj instanceof Solver) { - if (obj == this) { - return true; - } - Solver solver = (Solver) obj; - return solver.getName().equals(name); + if (!(obj instanceof Solver)) { + return false; } - return false; + if (obj == this) { + return true; + } + Solver solver = (Solver) obj; + return new EqualsBuilder().append(name, solver.name).isEquals(); + } + + @Override + public int hashCode() { + return new HashCodeBuilder(17, 31).append(name).toHashCode(); } } diff --git a/src/eu/engys/core/project/state/SolverFamily.java b/src/eu/engys/core/project/state/SolverFamily.java index f7923ae..432a78b 100644 --- a/src/eu/engys/core/project/state/SolverFamily.java +++ b/src/eu/engys/core/project/state/SolverFamily.java @@ -1,45 +1,43 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.state; +import static eu.engys.util.ui.UiUtil.NONE_LABEL; + public enum SolverFamily { - - COUPLED("Coupled"), - SIMPLE("Simple"), - PISO("Piso"), - PIMPLE("Pimple"), - CENTRAL("Central"), - NONE("None"); - private String text; + COUPLED("COUPLED", "Coupled"), SIMPLE("SIMPLE", "Simple"), PISO("PISO", "Piso"), PIMPLE("PIMPLE", "Pimple"), CENTRAL("CENTRAL", "Central"), NONE("NONE", NONE_LABEL); - private SolverFamily(String text) { - this.text = text; + private String key; + private String label; + + private SolverFamily(String key, String label) { + this.key = key; + this.label = label; } - + public boolean isCoupled() { return this == COUPLED; } @@ -64,12 +62,16 @@ public enum SolverFamily { return this == NONE; } - public String getKey() { - return text.toUpperCase(); + public String key() { + return key; + } + + public String label() { + return label; } @Override public String toString() { - return text; + return label; } -} +} \ No newline at end of file diff --git a/src/eu/engys/core/project/state/SolverType.java b/src/eu/engys/core/project/state/SolverType.java index 2591787..76ac735 100644 --- a/src/eu/engys/core/project/state/SolverType.java +++ b/src/eu/engys/core/project/state/SolverType.java @@ -1,37 +1,41 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.state; +import static eu.engys.util.ui.UiUtil.NONE_LABEL; + public enum SolverType { - COUPLED("Coupled"), SEGREGATED("Segregated"), NONE("None"); - private String text; + COUPLED("COUPLED", "Coupled"), SEGREGATED("SEGREGATED", "Segregated"), NONE("NONE", NONE_LABEL); - private SolverType(String text) { - this.text = text; + private String key; + private String label; + + private SolverType(String key, String label) { + this.key = key; + this.label = label; } public boolean isCoupled() { @@ -46,8 +50,16 @@ public enum SolverType { return this == NONE; } + public String key() { + return key; + } + + public String label() { + return label; + } + @Override public String toString() { - return text; + return label; } -} +} \ No newline at end of file diff --git a/src/eu/engys/core/project/state/State.java b/src/eu/engys/core/project/state/State.java index 59118ef..376fb6d 100644 --- a/src/eu/engys/core/project/state/State.java +++ b/src/eu/engys/core/project/state/State.java @@ -1,37 +1,33 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.state; import eu.engys.core.project.TurbulenceModel; public class State { - public State() { - - } private Time time = Time.NONE; private Flow flow = Flow.NONE; @@ -41,17 +37,41 @@ public class State { private SolverType solverType = SolverType.NONE; private SolverFamily solverFamily = SolverFamily.NONE; + private boolean aoa; + private boolean co2; + private boolean smoke; + private boolean humidity; + private boolean energy; private boolean buoyant; - private MultiphaseModel multiphaseModel = MultiphaseModel.OFF; + private boolean radiation; + private boolean solar; - private int phases = 1; + private boolean adjoint; private TurbulenceModel turbulenceModel; + private MultiphaseModel multiphaseModel = MultiphaseModel.OFF; + private boolean dynamic; + + private int phases = 1; + + public State() { + } @Override public String toString() { - return solver + " - " + solverFamily + " - " + time + " - " + flow + " - " + method + (energy ? " - energy" : "") + (buoyant ? " - buoyant" : "") + " - multiphase: "+ multiphaseModel.getLabel() + " with " + phases + " phases" + " - " + mach + "_MACH"; + return + solver + " - " + + solverFamily + " - " + + time + " - " + + flow + " - " + + method + " - " + + mach + "_MACH" + + (radiation ? " - radiation" : "") + (solar ? " - solar" : "") + + (energy ? " - energy" : "") + (buoyant ? " - buoyant" : "") + + " - multiphase: " + multiphaseModel.getLabel() + " with " + phases + " phases" + " - " + + " - dynamic: " + dynamic + + " - scalars: [ " + (aoa ? " AOA " : "") + (co2 ? " CO2 " : "") + (smoke ? " SMOKE " : "") + (humidity ? " HUMIDITY " : "") + "]"; } public Mach getMach() { @@ -146,14 +166,6 @@ public class State { return method.isRans(); } - public void setEnergy(boolean energy) { - this.energy = energy; - } - - public boolean isEnergy() { - return energy; - } - public void setToHighMach() { this.mach = Mach.HIGH; } @@ -169,6 +181,14 @@ public class State { public boolean isHighMach() { return mach.isHigh(); } + + public void setEnergy(boolean energy) { + this.energy = energy; + } + + public boolean isEnergy() { + return energy; + } public void setBuoyant(boolean buoyant) { this.buoyant = buoyant; @@ -178,6 +198,30 @@ public class State { return buoyant; } + public void setRadiation(boolean radiation) { + this.radiation = radiation; + } + + public boolean isRadiation() { + return radiation; + } + + public void setSolar(boolean solar) { + this.solar = solar; + } + + public boolean isSolar() { + return solar; + } + + public void setAdjoint(boolean adjoint) { + this.adjoint = adjoint; + } + + public boolean isAdjoint() { + return adjoint; + } + public TurbulenceModel getTurbulenceModel() { return turbulenceModel; } @@ -193,6 +237,14 @@ public class State { public void setMultiphaseModel(MultiphaseModel multiphase) { this.multiphaseModel = multiphase; } + + public boolean isDynamic() { + return dynamic; + } + + public void setDynamic(boolean dynamic) { + this.dynamic = dynamic; + } public int getPhases() { return phases; @@ -224,7 +276,7 @@ public class State { public void setSolverType(SolverType solverType) { this.solverType = solverType; } - + public boolean isCoupled() { return solverType.isCoupled(); } @@ -240,6 +292,38 @@ public class State { public void setSolverFamily(SolverFamily solverFamily) { this.solverFamily = solverFamily; } + + public boolean isHumidity() { + return humidity; + } + + public void setHumidity(boolean humidity) { + this.humidity = humidity; + } + + public boolean isSmoke() { + return smoke; + } + + public void setSmoke(boolean smoke) { + this.smoke = smoke; + } + + public boolean isCo2() { + return co2; + } + + public void setCo2(boolean co2) { + this.co2 = co2; + } + + public boolean isAoa() { + return aoa; + } + + public void setAoa(boolean aoa) { + this.aoa = aoa; + } public void stringToState(String string) { String[] tokens = string.replace("(", "").replace(")", "").split("\\s+"); @@ -299,10 +383,10 @@ public class State { setEnergy(true); break; -// case "multiphase": -// setMultiphase(true); -// setBuoyant(true); -// break; + // case "multiphase": + // setMultiphase(true); + // setBuoyant(true); + // break; case "ras": setMethodToRANS(); @@ -344,24 +428,24 @@ public class State { public void appendState(StringBuffer sb) { if (isSteady()) { if (solverType.isCoupled()) { - sb.append("steady"); + sb.append(Time.STEADY.key()); sb.append(SPACE); - sb.append("COUPLED"); + sb.append(SolverFamily.COUPLED.key()); } else { - sb.append("SIMPLE"); + sb.append(SolverFamily.SIMPLE.key()); } } else if (isTransient()) { if (solverType.isCoupled()) { - sb.append("transient"); + sb.append(Time.TRANSIENT.key()); sb.append(SPACE); - sb.append("COUPLED"); + sb.append(SolverFamily.COUPLED.key()); } else { if (solverFamily.isPimple()) { - sb.append("PIMPLE"); + sb.append(SolverFamily.PIMPLE.key()); } else if (solverFamily.isCentral()) { - sb.append("CENTRAL"); + sb.append(SolverFamily.CENTRAL.key()); } else if (solverFamily.isPiso()) { - sb.append("PISO"); + sb.append(SolverFamily.PISO.key()); } } } @@ -369,20 +453,20 @@ public class State { sb.append(SPACE); if (isCompressible()) - sb.append("compressible"); + sb.append(Flow.COMPRESSIBLE.key()); else if (isIncompressible()) - sb.append("incompressible"); + sb.append(Flow.INCOMPRESSIBLE.key()); sb.append(SPACE); if (isLES()) - sb.append("les"); + sb.append(Method.LES.key()); else if (isRANS()) - sb.append("ras"); + sb.append(Method.RANS.key()); if (isHighMach()) { sb.append(SPACE); - sb.append("hiMach"); + sb.append(Mach.HIGH.key()); } if (getMultiphaseModel().isOn()) { @@ -401,5 +485,11 @@ public class State { } } } + +// if(isAdjoint()){ +// sb.append(SPACE); +// sb.append("ADJOINT"); +// } } + } diff --git a/src/eu/engys/core/project/state/StateBuilder.java b/src/eu/engys/core/project/state/StateBuilder.java index f770c66..024038c 100644 --- a/src/eu/engys/core/project/state/StateBuilder.java +++ b/src/eu/engys/core/project/state/StateBuilder.java @@ -1,33 +1,33 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.state; import static eu.engys.core.project.constant.ConstantFolder.CONSTANT; import static eu.engys.core.project.constant.ConstantFolder.FREE_SURFACE_PROPERTIES; import static eu.engys.core.project.constant.ConstantFolder.G; +import static eu.engys.core.project.constant.MRFProperties.MRF_PROPERTIES; import static eu.engys.core.project.constant.ThermophysicalProperties.THERMOPHYSICAL_PROPERTIES; import static eu.engys.core.project.constant.TransportProperties.MATERIAL_NAME_KEY; import static eu.engys.core.project.constant.TransportProperties.PHASE1_KEY; @@ -35,6 +35,11 @@ import static eu.engys.core.project.constant.TransportProperties.PHASE2_KEY; import static eu.engys.core.project.constant.TransportProperties.PHASES_KEY; import static eu.engys.core.project.constant.TransportProperties.TRANSPORT_MODEL_KEY; import static eu.engys.core.project.constant.TransportProperties.TRANSPORT_PROPERTIES; +import static eu.engys.core.project.constant.TurbulenceProperties.LES_KEY; +import static eu.engys.core.project.constant.TurbulenceProperties.LES_MODEL_KEY; +import static eu.engys.core.project.constant.TurbulenceProperties.RAS_KEY; +import static eu.engys.core.project.constant.TurbulenceProperties.RAS_MODEL_KEY; +import static eu.engys.core.project.constant.TurbulenceProperties.SIMULATION_TYPE_KEY; import static eu.engys.core.project.constant.TurbulenceProperties.TURBULENCE_PROPERTIES; import static eu.engys.core.project.system.ControlDict.CONTROL_DICT; import static eu.engys.core.project.system.FvSchemes.BACKWARD; @@ -107,11 +112,11 @@ public class StateBuilder { } logger.info("Fields: loadFieldsFromDefaults"); - fields.merge(FieldsDefaults.loadFieldsFromDefaults(model.getState(), model.getDefaults(), model.getPatches(), null)); + fields.merge(FieldsDefaults.loadFieldsFromDefaults(model.getProject().getBaseDir(), model.getState(), model.getDefaults(), model.getPatches(), null)); logger.info("Modules: loadFieldsFromDefaults"); fields.merge(ModulesUtil.loadFieldsFromDefaults(modules, null)); - + fields.fixPVisibility(model.getState()); model.setFields(fields); @@ -138,11 +143,11 @@ public class StateBuilder { Fields fields = new Fields(); logger.info("Fields: loadFieldsFromDefaults"); - fields.merge(FieldsDefaults.loadFieldsFromDefaults(model.getState(), model.getDefaults(), model.getPatches(), null)); + fields.merge(FieldsDefaults.loadFieldsFromDefaults(model.getProject().getBaseDir(), model.getState(), model.getDefaults(), model.getPatches(), null)); logger.info("Modules: loadFieldsFromDefaults"); fields.merge(ModulesUtil.loadFieldsFromDefaults(modules, null)); - + fields.fixPVisibility(model.getState()); model.setFields(fields); @@ -225,6 +230,12 @@ public class StateBuilder { else prj.getConstantFolder().getTurbulenceProperties().merge(constantDict.subDict(TURBULENCE_PROPERTIES)); } + if (constantDict.isDictionary(MRF_PROPERTIES)) { + if (prj.getConstantFolder().getMrfProperties() == null) + prj.getConstantFolder().setMrfProperties(constantDict.subDict(MRF_PROPERTIES)); + else + prj.getConstantFolder().getMrfProperties().merge(constantDict.subDict(MRF_PROPERTIES)); + } } } @@ -285,18 +296,16 @@ public class StateBuilder { } private static SolverType readSolverType(FvSolution fvSolution) { + // Coupled handled in its own module if (fvSolution != null) { - if (fvSolution.found(FvSolution.COUPLED)) { - return SolverType.COUPLED; - } else { - return SolverType.SEGREGATED; - } + return SolverType.SEGREGATED; } else { return SolverType.NONE; } } private static SolverFamily readSolverFamily(State state, FvSolution fvSolution) { + // Coupled handled in its own module if (state.getSolverType().isSegregated()) { if (state.isLowMach()) { if (state.isSteady()) { @@ -333,14 +342,12 @@ public class StateBuilder { } else { return SolverFamily.NONE; } - } else if (state.getSolverType().isCoupled()) { - return SolverFamily.COUPLED; } else { return SolverFamily.NONE; } } - private static Time readTime(Model model, SolverType solverType, FvSchemes fvSchemes, ProgressMonitor monitor) { + public static Time readTime(Model model, SolverType solverType, FvSchemes fvSchemes, ProgressMonitor monitor) { if (fvSchemes != null) { Dictionary ddtSchemes = fvSchemes.getDdtSchemes(); if (ddtSchemes != null) { @@ -387,19 +394,17 @@ public class StateBuilder { private static Method readMethod(ConstantFolder constantFolder) { Dictionary turbPropDict = constantFolder.getTurbulenceProperties(); - if (turbPropDict != null && turbPropDict.found(TurbulenceProperties.SIMULATION_TYPE)) { - String turbType = turbPropDict.lookup(TurbulenceProperties.SIMULATION_TYPE); - if (turbType.startsWith(TurbulenceProperties.RAS)) { + if (turbPropDict != null && turbPropDict.found(SIMULATION_TYPE_KEY)) { + String turbType = turbPropDict.lookup(SIMULATION_TYPE_KEY); + if (turbType.startsWith(RAS_KEY)) { return Method.RANS; - } else if (turbType.startsWith(TurbulenceProperties.LES)) { + } else if (turbType.startsWith(LES_KEY)) { return Method.LES; - } else if (turbType.startsWith(TurbulenceProperties.LAMINAR)) { - Dictionary RASProperties = constantFolder.getRASProperties(); - Dictionary LESProperties = constantFolder.getLESProperties(); - if (RASProperties != null && !RASProperties.isEmpty()) { - return Method.RANS; - } else if (LESProperties != null && !LESProperties.isEmpty()) { + } else if(turbType.equals(TurbulenceProperties.LAMINAR_KEY)){ + if(turbPropDict.isDictionary(LES_KEY)){ return Method.LES; + } else { + return Method.RANS; } } } @@ -457,19 +462,14 @@ public class StateBuilder { } } - private static TurbulenceModel readTurbulenceModel(Model model, SolverType solverType, ConstantFolder constantFolder, ProgressMonitor monitor) { - if (model.getState().isLES()) { - Dictionary LESProperties = constantFolder.getLESProperties(); - if (LESProperties != null) { - String lesModel = LESProperties.lookup("LESModel"); - return readTurbulenceModelFromState(model, solverType, lesModel, monitor); - } - } else if (model.getState().isRANS()) { - Dictionary RASProperties = constantFolder.getRASProperties(); - if (RASProperties != null) { - String rasModel = RASProperties.lookup("RASModel"); - return readTurbulenceModelFromState(model, solverType, rasModel, monitor); - } + public static TurbulenceModel readTurbulenceModel(Model model, SolverType solverType, ConstantFolder constantFolder, ProgressMonitor monitor) { + Dictionary turbulenceProperties = constantFolder.getTurbulenceProperties(); + if (model.getState().isLES() && turbulenceProperties.found(LES_KEY)) { + String lesModel = turbulenceProperties.subDict(LES_KEY).lookup(LES_MODEL_KEY); + return readTurbulenceModelFromState(model, solverType, lesModel, monitor); + } else if (model.getState().isRANS() && turbulenceProperties.found(RAS_KEY)) { + String rasModel = turbulenceProperties.subDict(RAS_KEY).lookup(RAS_MODEL_KEY); + return readTurbulenceModelFromState(model, solverType, rasModel, monitor); } return null; } @@ -479,20 +479,17 @@ public class StateBuilder { Method method = model.getState().getMethod(); Flow flow = model.getState().getFlow(); logger.info("Loading Turbulence model for {} {} {}", solverType, method, flow); + List modelsForState = turbulenceModels.getModelsForState(solverType, method, flow); if (modelsForState != null && !modelsForState.isEmpty()) { - - TurbulenceModel turbulenceModel = new TurbulenceModel(); - turbulenceModel.setName(modelName); - - int index = modelsForState.indexOf(turbulenceModel); - if (index >= 0) { - return modelsForState.get(index); - } else { - TurbulenceModel firstTurbulenceModel = modelsForState.get(0); - monitor.warning(String.format("%s not found. Changed to %s", modelName, firstTurbulenceModel), 1); - return firstTurbulenceModel; + for (TurbulenceModel tm : modelsForState) { + if (tm.getName().equals(modelName)) { + return tm; + } } + TurbulenceModel firstTurbulenceModel = modelsForState.get(0); + monitor.warning(String.format("%s not found. Changed to %s", modelName, firstTurbulenceModel), 1); + return firstTurbulenceModel; } else { monitor.warning("Turbulence models not loaded", 1); return null; diff --git a/src/eu/engys/core/project/state/StateComposer.java b/src/eu/engys/core/project/state/StateComposer.java index 748bac6..ed2cf40 100644 --- a/src/eu/engys/core/project/state/StateComposer.java +++ b/src/eu/engys/core/project/state/StateComposer.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.state; import eu.engys.core.project.TurbulenceModel; @@ -39,6 +38,16 @@ public class StateComposer { return composer; } + public StateComposer dynamic() { + state.setDynamic(true); + return this; + } + + public StateComposer adjoint() { + state.setAdjoint(true); + return this; + } + public StateComposer coupled() { state.setSolverType(SolverType.COUPLED); state.setSolverFamily(SolverFamily.COUPLED); @@ -163,6 +172,11 @@ public class StateComposer { return this; } + public StateComposer spalartAllmaras_LES_OS() { + state.setTurbulenceModel(new TurbulenceModel("SpalartAllmarasDES", TurbulenceModelType.Spalart_Allmaras)); + return this; + } + public StateComposer phases(int i) { state.setPhases(i); return this; diff --git a/src/eu/engys/core/project/state/Table15.java b/src/eu/engys/core/project/state/Table15.java index 277e844..09b154f 100644 --- a/src/eu/engys/core/project/state/Table15.java +++ b/src/eu/engys/core/project/state/Table15.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.state; import java.util.Set; diff --git a/src/eu/engys/core/project/state/ThermalState.java b/src/eu/engys/core/project/state/ThermalState.java index 3fea48f..6568475 100644 --- a/src/eu/engys/core/project/state/ThermalState.java +++ b/src/eu/engys/core/project/state/ThermalState.java @@ -1,62 +1,88 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.state; - public class ThermalState { + + public static final String THERMAL = "Thermal"; + public static final String ENERGY = "Energy"; + public static final String BUOYANCY = "Buoyancy"; + private boolean energy; private boolean buoyancy; - + private boolean radiation; + private boolean solar; + public ThermalState() { this.setEnergy(false); this.setBuoyancy(false); + this.setBuoyancy(false); + this.setSolar(false); } - + public ThermalState(State state) { this.setEnergy(state.isEnergy()); this.setBuoyancy(state.isBuoyant()); + this.setRadiation(state.isRadiation()); + this.setSolar(state.isSolar()); } - + public boolean isEnergy() { return energy; } - public boolean isBuoyancy() { - return buoyancy; - } public void setEnergy(boolean energy) { this.energy = energy; } + public boolean isBuoyancy() { + return buoyancy; + } + public void setBuoyancy(boolean buoyancy) { this.buoyancy = buoyancy; } - + + public boolean isRadiation() { + return radiation; + } + + public void setRadiation(boolean radiation) { + this.radiation = radiation; + } + + public boolean isSolar() { + return solar; + } + + public void setSolar(boolean solar) { + this.solar = solar; + } + @Override public String toString() { - return "Energy: " + (isEnergy()? "ON" : "OFF") + ", Buoyancy: " + (isBuoyancy()? "ON" : "OFF"); + return "Energy: " + (isEnergy() ? "ON" : "OFF") + ", Buoyancy: " + (isBuoyancy() ? "ON" : "OFF") + ", Radiation: " + (isRadiation() ? "ON" : "OFF") + ", Solar: " + (isSolar() ? "ON" : "OFF"); } -} +} \ No newline at end of file diff --git a/src/eu/engys/core/project/state/Time.java b/src/eu/engys/core/project/state/Time.java index ade0d81..ac0b43a 100644 --- a/src/eu/engys/core/project/state/Time.java +++ b/src/eu/engys/core/project/state/Time.java @@ -1,37 +1,41 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.state; +import static eu.engys.util.ui.UiUtil.NONE_LABEL; + public enum Time { - STEADY("Steady"), TRANSIENT("Transient"), NONE("None"); - private String text; + STEADY("steady", "Steady"), TRANSIENT("transient", "Transient"), NONE("none", NONE_LABEL); - private Time(String text) { - this.text = text; + private String key; + private String label; + + private Time(String key, String label) { + this.key = key; + this.label = label; } public boolean isSteady() { @@ -46,8 +50,16 @@ public enum Time { return this == NONE; } + public String key() { + return key; + } + + public String label() { + return label; + } + @Override public String toString() { - return text; + return label; } -} +} \ No newline at end of file diff --git a/src/eu/engys/core/project/state/TurbulenceBuilder.java b/src/eu/engys/core/project/state/TurbulenceBuilder.java index 4e6912a..ad33c95 100644 --- a/src/eu/engys/core/project/state/TurbulenceBuilder.java +++ b/src/eu/engys/core/project/state/TurbulenceBuilder.java @@ -1,42 +1,48 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.state; +import static eu.engys.core.project.constant.TurbulenceProperties.DELTA1_KEY; +import static eu.engys.core.project.constant.TurbulenceProperties.DELTA_KEY; import static eu.engys.core.project.constant.TurbulenceProperties.FIELD_MAPS_KEY; -import static eu.engys.core.project.constant.TurbulenceProperties.LES; -import static eu.engys.core.project.constant.TurbulenceProperties.RAS; +import static eu.engys.core.project.constant.TurbulenceProperties.LAMINAR_KEY; +import static eu.engys.core.project.constant.TurbulenceProperties.LES_KEY; +import static eu.engys.core.project.constant.TurbulenceProperties.PRINT_COEFFS_KEY; +import static eu.engys.core.project.constant.TurbulenceProperties.RAS_KEY; +import static eu.engys.core.project.constant.TurbulenceProperties.SIMULATION_TYPE_KEY; +import static eu.engys.core.project.constant.TurbulenceProperties.TURBULENCE_KEY; import static eu.engys.core.project.constant.TurbulenceProperties.TURBULENCE_PROPERTIES; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import eu.engys.core.dictionary.Dictionary; +import eu.engys.core.dictionary.FieldElement; import eu.engys.core.project.Model; +import eu.engys.core.project.TurbulenceModel; import eu.engys.core.project.openFOAMProject; -import eu.engys.core.project.constant.ConstantFolder; import eu.engys.core.project.defaults.DefaultsProvider; public class TurbulenceBuilder { @@ -47,67 +53,76 @@ public class TurbulenceBuilder { State state = model.getState(); openFOAMProject project = model.getProject(); - Dictionary turbPropDict = new Dictionary(TURBULENCE_PROPERTIES); - String turbType = RAS; - if (state.isLES()) { - turbType = LES; - } - turbPropDict.add("simulationType", turbType + "Model"); - + Dictionary turbulenceProperties = new Dictionary(TURBULENCE_PROPERTIES); if (state.getTurbulenceModel() != null) { - String modelName = state.getTurbulenceModel().getName(); + String simulationType = state.isLES() ? LES_KEY : RAS_KEY; + if (state.getTurbulenceModel().getName().equals(LAMINAR_KEY)) { + turbulenceProperties.add(SIMULATION_TYPE_KEY, LAMINAR_KEY); + } else { + turbulenceProperties.add(SIMULATION_TYPE_KEY, simulationType); + } + Dictionary simulationDict = saveSimulationDict(defaults, state, simulationType); + turbulenceProperties.add(simulationDict); + } + project.getConstantFolder().setTurbulenceProperties(turbulenceProperties); - Dictionary turbTypeProp = new Dictionary(turbType + "Properties"); - turbTypeProp.add(turbType + "Model", modelName); - turbTypeProp.add("turbulence", "on"); - turbTypeProp.add("printCoeffs", "on"); + } + + private static Dictionary saveSimulationDict(DefaultsProvider defaults, State state, String simulationType) { + TurbulenceModel turbulenceModel = state.getTurbulenceModel(); + String modelName = turbulenceModel.getName(); + + Dictionary simulationDict = new Dictionary(simulationType); + simulationDict.add(simulationType + "Model", modelName); + + if (turbulenceModel.getType().isLaminar()) { + // do nothing + } else { + simulationDict.add(TURBULENCE_KEY, "on"); + simulationDict.add(PRINT_COEFFS_KEY, "on"); String dictName = ""; if (state.getSolverType().isCoupled()) { - dictName = "coupledIncompressibleRAS"; + dictName = (state.isRANS() ? "coupledIncompressibleRAS" : "coupledIncompressibleLES"); } else if (state.getSolverType().isSegregated()) { - dictName = (state.isCompressible() ? "compressible" : "incompressible") + turbType; + dictName = (state.isCompressible() ? "compressible" : "incompressible") + simulationType; } Dictionary tpp = defaults.getDefaultTurbulenceProperties(); if (tpp != null && tpp.isDictionary(dictName)) { - logger.info("[ {} provider ]: FOUND {} dictionary", defaults.getName(), dictName); + logger.info("[ {} provider ]: FOUND {} dictionary", defaults.getName(), dictName); Dictionary subDict = tpp.subDict(dictName); if (subDict.isDictionary(modelName + "Coeffs")) { // prendo i coefficienti del model dal file dei defaults - logger.info("[ {} provider ]: FOUND {} dictionary", defaults.getName(), modelName); + logger.info("[ {} provider ]: FOUND {} dictionary", defaults.getName(), modelName); Dictionary defCoeff = subDict.subDict(modelName + "Coeffs"); - turbTypeProp.add(new Dictionary(defCoeff)); - turbTypeProp.remove(FIELD_MAPS_KEY); + simulationDict.add(new Dictionary(defCoeff)); + simulationDict.remove(FIELD_MAPS_KEY); } else { - logger.warn("[ {} provider ]: Cannot find {} dictionary", defaults.getName(), modelName); + logger.warn("[ {} provider ]: Cannot find {} dictionary", defaults.getName(), modelName); } } else { - logger.warn("[ {} provider ]: Cannot find {} dictionary", defaults.getName(), dictName); + logger.warn("[ {} provider ]: Cannot find {} dictionary", defaults.getName(), dictName); } - if (state.isLES()) { - String deltaType = turbTypeProp.subDict(modelName + "Coeffs").lookup("delta"); - // System.out.println("TurbulenceBuilder.build() delta: "+deltaType); - turbTypeProp.add("delta", deltaType); - turbTypeProp.subDict(modelName + "Coeffs").remove("delta"); - - turbTypeProp.add(tpp.subDict(deltaType + "Coeffs")); + if (state.isLES() && simulationDict.found(modelName + "Coeffs")) { + Dictionary coeffsDict = simulationDict.subDict(modelName + "Coeffs"); + if(coeffsDict.found(DELTA_KEY) && coeffsDict.found(DELTA1_KEY)){ + FieldElement deltaType = (FieldElement) coeffsDict.remove(DELTA_KEY); + FieldElement delta1Type = (FieldElement) coeffsDict.remove(DELTA1_KEY); + simulationDict.add(DELTA_KEY, delta1Type.getValue()); + simulationDict.add(tpp.subDict(deltaType.getValue() + "Coeffs")); + simulationDict.add(tpp.subDict(delta1Type.getValue() + "Coeffs")); + } else if(coeffsDict.found(DELTA_KEY)){ + FieldElement deltaType = (FieldElement) coeffsDict.remove(DELTA_KEY); + simulationDict.add(DELTA_KEY, deltaType.getValue()); + simulationDict.add(tpp.subDict(deltaType.getValue() + "Coeffs")); + } } - - ConstantFolder constantFolder = project.getConstantFolder(); - constantFolder.setTurbulenceProperties(turbPropDict); - - if (state.isLES()) { - constantFolder.setLESProperties(turbTypeProp); - } else { - constantFolder.setRASProperties(turbTypeProp); - } - } else { - logger.error("Turbulence Model is NULL!"); } + return simulationDict; } } diff --git a/src/eu/engys/core/project/system/BlockMeshDict.java b/src/eu/engys/core/project/system/BlockMeshDict.java index 229ab40..0bf4e71 100644 --- a/src/eu/engys/core/project/system/BlockMeshDict.java +++ b/src/eu/engys/core/project/system/BlockMeshDict.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.system; import java.io.File; @@ -86,7 +85,7 @@ public class BlockMeshDict extends Dictionary { return new BlockMeshWriter(this).write(); } - public void setBoundingBox(BoundingBox boundingBox) { + public void setBoundingBox(BoundingBox boundingBox, double spacing, boolean shouldConsiderSpacing) { double xmin = boundingBox.getXmin(); double xmax = boundingBox.getXmax(); double ymin = boundingBox.getYmin(); @@ -94,9 +93,7 @@ public class BlockMeshDict extends Dictionary { double zmin = boundingBox.getZmin(); double zmax = boundingBox.getZmax(); - if (found(SPACING_KEY)) {// only HELYX-OS - double spacing = Double.valueOf(lookup(SPACING_KEY)); - + if (shouldConsiderSpacing) {// only HELYX-OS boolean emptyBoundingBox = (xmin == 0) && (xmax == 0) && (ymin == 0) && (ymax == 0) && (zmin == 0) && (zmax == 0); /* aggiungo un po'di spacing */ diff --git a/src/eu/engys/core/project/system/CaseSetupDict.java b/src/eu/engys/core/project/system/CaseSetupDict.java index fc27318..8959df5 100644 --- a/src/eu/engys/core/project/system/CaseSetupDict.java +++ b/src/eu/engys/core/project/system/CaseSetupDict.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.system; import eu.engys.core.dictionary.Dictionary; @@ -34,9 +33,34 @@ public class CaseSetupDict extends Dictionary { public static final String CASE_SETUP_DICT = "caseSetupDict"; public static final String MATERIALS_KEY = "materials"; + public static final String MATERIAL_PROPERTIES_KEY = "materialProperties"; public static final String BINARY_PAIR_DATA_KEY = "binaryPairData"; + public static final String REGION0_KEY = "region0"; + public static final String REGION_DEFAULTS_KEY = "regionDefaults"; + public static final String FIELDS_KEY = "fields"; public static final String GLOBAL_KEY = "global"; + public static final String REGIONS_KEY = "regions"; + public static final String BOUNDARY_MESH_KEY = "boundaryMesh"; + public static final String EXACT_NAMED_KEY = "exactNamed"; + public static final String PARTIAL_NAMED_KEY = "partialNamed"; + public static final String BOUNDARY_CONDITIONS_KEY = "boundaryConditions"; + + public static final String MODIFICATION_SWITCHES_KEY = "modificationSwitches"; + public static final String RESET_INTERNAL_FIELDS_KEY = "resetInternalFields"; + public static final String RESET_BOUNDARY_FIELDS_KEY = "resetBoundaryFields"; + public static final String RESET_SYSTEM_DICTS_KEY = "resetSystemDicts"; + public static final String RESET_CONST_DICTS_KEY = "resetConstDicts"; + public static final String RESET_BOUNDARY_MESH_KEY = "resetBoundaryMesh"; + public static final String DELETE_UNUSED_FIELDS_KEY = "deleteUnusedFields"; + public static final String REUSE_EXISTING_DICTS_KEY = "reuseExistingDicts"; + public static final String STRICT_PATCH_NAME_CHECKING_KEY = "strictPatchNameChecking"; + + public static final String STATE_KEY = "state"; + public static final String TURBULENCE_MODEL_KEY = "turbulenceModel"; + public static final String INITIALISATION_KEY = "initialisation"; + + public static final String FUNCTIONS_KEY = "functions"; public CaseSetupDict() { super(CASE_SETUP_DICT); diff --git a/src/eu/engys/core/project/system/ControlDict.java b/src/eu/engys/core/project/system/ControlDict.java index 70fa657..6529a34 100644 --- a/src/eu/engys/core/project/system/ControlDict.java +++ b/src/eu/engys/core/project/system/ControlDict.java @@ -1,34 +1,32 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.system; import java.io.File; -import eu.engys.core.dictionary.DefaultElement; import eu.engys.core.dictionary.Dictionary; import eu.engys.core.dictionary.DictionaryException; import eu.engys.core.dictionary.FoamFile; @@ -79,6 +77,8 @@ public class ControlDict extends Dictionary { public static final String STOP_AT_KEY = "stopAt"; public static final String RUNTIME_MODIFIABLE_KEY = "runTimeModifiable"; public static final String INCLUDE_KEY = "include"; + public static final String LIBS_KEY = "libs"; + public static final String[] START_FROM_VALUES = { FIRST_TIME_VALUE, LATEST_TIME_VALUE, START_TIME_VALUE }; public static final String[] WRITE_CONTROL_VALUES = { TIME_STEP_VALUE, RUN_TIME_VALUE, CPU_TIME_VALUE, CLOCK_TIME_VALUE }; // public static final String[] WRITE_FORMAT_VALUES = { ASCII_VALUE, BINARY_VALUE }; @@ -121,10 +121,12 @@ public class ControlDict extends Dictionary { public ControlDict() { super(CONTROL_DICT); setFoamFile(FoamFile.getDictionaryFoamFile(SystemFolder.SYSTEM, CONTROL_DICT)); +// add("libs", "( \"libLEMOS-2.2.x.so\" \"libHelyxAdjointPlus.so\" )"); } public ControlDict(ControlDict controlDict) { super(controlDict); +// add("libs", "( \"libLEMOS-2.2.x.so\" \"libHelyxAdjointPlus.so\" )"); } public ControlDict(File controlDictFile) { @@ -139,41 +141,6 @@ public class ControlDict extends Dictionary { return found("writeFormat") && lookup("writeFormat").equals("binary"); } - @Override - public void merge(Dictionary dict) { - if (dict instanceof ControlDict) { - ((ControlDict) dict).functionObjectsToDict(); - } - functionObjectsToDict(); - super.merge(dict); - functionObjectsToList(); - if (dict instanceof ControlDict) { - ((ControlDict) dict).functionObjectsToList(); - } - } - - public void functionObjectsToDict() { - if (found(FUNCTIONS_KEY) && isList(FUNCTIONS_KEY)) { - ListField functionsList = getList(FUNCTIONS_KEY); - Dictionary functionsDict = new Dictionary(FUNCTIONS_KEY); - for (DefaultElement el : functionsList.getListElements()) { - functionsDict.add(el); - } - remove(FUNCTIONS_KEY); - add(functionsDict); - } - } - - public void functionObjectsToList() { - if (found(FUNCTIONS_KEY) && isDictionary(FUNCTIONS_KEY)) { - Dictionary functionsDict = subDict(FUNCTIONS_KEY); - remove(FUNCTIONS_KEY); - for (Dictionary dict : functionsDict.getDictionaries()) { - addToList(FUNCTIONS_KEY, dict); - } - } - } - public String getValueOnFunctionObject(String foName, String key) { if (isList(FUNCTIONS_KEY)) { ListField functions = getList(FUNCTIONS_KEY); @@ -197,6 +164,6 @@ public class ControlDict extends Dictionary { public void startFromZero() { add(START_FROM_KEY, START_TIME_VALUE); - add(START_TIME_KEY, "0"); + add(START_TIME_KEY, 0); } } diff --git a/src/eu/engys/core/project/system/CustomNodeDict.java b/src/eu/engys/core/project/system/CustomNodeDict.java index 4f32cf5..076f0a6 100644 --- a/src/eu/engys/core/project/system/CustomNodeDict.java +++ b/src/eu/engys/core/project/system/CustomNodeDict.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.system; diff --git a/src/eu/engys/core/project/system/DecomposeParDict.java b/src/eu/engys/core/project/system/DecomposeParDict.java index 2f0bf62..208e917 100644 --- a/src/eu/engys/core/project/system/DecomposeParDict.java +++ b/src/eu/engys/core/project/system/DecomposeParDict.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.system; import java.io.File; diff --git a/src/eu/engys/core/project/system/FvOptions.java b/src/eu/engys/core/project/system/FvOptions.java index 18992a8..27d4c71 100644 --- a/src/eu/engys/core/project/system/FvOptions.java +++ b/src/eu/engys/core/project/system/FvOptions.java @@ -1,29 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.system; import eu.engys.core.dictionary.Dictionary; @@ -31,8 +29,25 @@ import eu.engys.core.dictionary.DictionaryException; import eu.engys.core.dictionary.FoamFile; public class FvOptions extends Dictionary { - public static final String FV_OPTIONS = "fvOptions"; - + + public static final String FV_OPTIONS = "fvOptions"; + + public static final String U_LIMITER_KEY = "Ulimiter"; + public static final String VELOCITY_LIMITER_SOURCE_KEY = "velocityLimiterSource"; + public static final String ACTIVE_KEY = "active"; + public static final String SELECTION_MODE_KEY = "selectionMode"; + public static final String ALL_KEY = "all"; + public static final String VELOCITY_LIMITER_SOURCE_COEFFS_KEY = "velocityLimiterSourceCoeffs"; + public static final String U_LIMIT_KEY = "Ulimit"; + public static final String LIMIT_MODE_KEY = "limitMode"; + public static final String DIAGONAL_KEY = "diagonal"; + public static final String DIAGONAL_MULTIPLIER_KEY = "diagonalMultiplier"; + public static final String U_LIMIT_RANGE_KEY = "UlimitRange"; + public static final String ALPHA_KEY = "alpha"; + public static final String DELTA_RELAX_KEY = "deltaRelax"; + public static final String VELOCITY_CLIP_KEY = "velocityClip"; + public static final String VERBOSE_KEY = "verbose"; + public FvOptions() { super(FV_OPTIONS); setFoamFile(FoamFile.getDictionaryFoamFile(SystemFolder.SYSTEM, FV_OPTIONS)); diff --git a/src/eu/engys/core/project/system/FvSchemes.java b/src/eu/engys/core/project/system/FvSchemes.java index 3660c94..ba8985f 100644 --- a/src/eu/engys/core/project/system/FvSchemes.java +++ b/src/eu/engys/core/project/system/FvSchemes.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.system; @@ -43,6 +42,11 @@ public class FvSchemes extends Dictionary { public static final String STEADY_STATE = "steadyState"; public static final String EULER = "Euler"; public static final String BACKWARD = "backward"; + + public static final String LIMITED = "limited"; + public static final String CORRECTED = "corrected"; + public static final String UNCORRECTED = "uncorrected"; + public static final String LOCAL_EULER_RDELTAT = "localEuler rDeltaT";//LTSInterfoam public FvSchemes() { diff --git a/src/eu/engys/core/project/system/FvSolution.java b/src/eu/engys/core/project/system/FvSolution.java index 62733ff..f3cf71e 100644 --- a/src/eu/engys/core/project/system/FvSolution.java +++ b/src/eu/engys/core/project/system/FvSolution.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.system; @@ -55,6 +54,12 @@ public class FvSolution extends Dictionary { public static final String FIELDS_KEY = "fields"; public static final String EQUATIONS_KEY = "equations"; public static final String SOLVERS_KEY = "solvers"; + + public static final String CONSTANT_LIMITER_KEY = "constantLimiter"; + public static final String HIGH_ORDER_KEY = "HighOrder"; + + public static final String POTENTIAL_FLOW_KEY = "potentialFlow"; + public static final String INITIALISE_UBCS_KEY = "initialiseUBCs "; public FvSolution() { super(FV_SOLUTION); diff --git a/src/eu/engys/core/project/system/MapFieldsDict.java b/src/eu/engys/core/project/system/MapFieldsDict.java index 5108da5..baf550c 100644 --- a/src/eu/engys/core/project/system/MapFieldsDict.java +++ b/src/eu/engys/core/project/system/MapFieldsDict.java @@ -1,29 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.system; import static eu.engys.core.project.system.SystemFolder.SYSTEM; diff --git a/src/eu/engys/core/project/system/ProjectDict.java b/src/eu/engys/core/project/system/ProjectDict.java new file mode 100644 index 0000000..94b0c44 --- /dev/null +++ b/src/eu/engys/core/project/system/ProjectDict.java @@ -0,0 +1,77 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ + +package eu.engys.core.project.system; + +import java.io.File; + +import eu.engys.core.dictionary.Dictionary; +import eu.engys.core.dictionary.DictionaryException; +import eu.engys.core.dictionary.FoamFile; + +public class ProjectDict extends Dictionary { + public static final String PROJECT_DICT = "projectDict"; + public static final String MESH_INFO_DICT = "meshInfo"; + + public ProjectDict() { + super(PROJECT_DICT); + setFoamFile(FoamFile.getDictionaryFoamFile(SystemFolder.SYSTEM, PROJECT_DICT)); + } + + public ProjectDict(File projectDictFile) { + this(); + readDictionary(projectDictFile); + } + + @Override + public void check() throws DictionaryException { + } + + public void setRunDict(Dictionary d) { + RunDict runDict = new RunDict(); + runDict.merge(d); + add(runDict); + } + + public Dictionary getRunDict() { + return subDict(RunDict.RUN_DICT); + } + + public void setMeshInfoDict(Dictionary d) { + MeshInfoDict meshInfoDict = new MeshInfoDict(); + meshInfoDict.merge(d); + add(meshInfoDict); + } + + public Dictionary getMeshInfoDict() { + return subDict(MESH_INFO_DICT); + } + + class MeshInfoDict extends Dictionary { + public MeshInfoDict() { + super(MESH_INFO_DICT); + } + } +} diff --git a/src/eu/engys/core/project/system/RunDict.java b/src/eu/engys/core/project/system/RunDict.java index b83a2d4..b5dc9d0 100644 --- a/src/eu/engys/core/project/system/RunDict.java +++ b/src/eu/engys/core/project/system/RunDict.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.system; @@ -31,7 +30,6 @@ import java.io.File; import eu.engys.core.dictionary.BeanToDict; import eu.engys.core.dictionary.Dictionary; import eu.engys.core.dictionary.DictionaryException; -import eu.engys.core.dictionary.FoamFile; import eu.engys.core.project.SolverModel; public class RunDict extends Dictionary { @@ -51,7 +49,6 @@ public class RunDict extends Dictionary { public RunDict() { super(RUN_DICT); - setFoamFile(FoamFile.getDictionaryFoamFile(SystemFolder.SYSTEM, RUN_DICT)); } public RunDict(SolverModel solverModel) { diff --git a/src/eu/engys/core/project/system/SetFieldsDict.java b/src/eu/engys/core/project/system/SetFieldsDict.java index 744ab07..cb7f5b6 100644 --- a/src/eu/engys/core/project/system/SetFieldsDict.java +++ b/src/eu/engys/core/project/system/SetFieldsDict.java @@ -1,29 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.system; import static eu.engys.core.project.system.SystemFolder.SYSTEM; @@ -40,6 +38,7 @@ public class SetFieldsDict extends Dictionary { public static final String CELL_SET_KEY = "cellSet"; public static final String VOL_SCALAR_FIELD_VALUE_KEY = "volScalarFieldValue"; + public static final String VOL_VECTOR_FIELD_VALUE_KEY = "volVectorFieldValue"; public static final String FIELD_VALUES_KEY = "fieldValues"; public static final String REGIONS_KEY = "regions"; public static final String SET_SOURCES_KEY = "setSources"; @@ -47,9 +46,20 @@ public class SetFieldsDict extends Dictionary { public static final String DEFAULT_VALUE_KEY = "defaultValue"; public static final String BOX_TO_CELL_KEY ="boxToCell"; + public static final String ROTATED_BOX_TO_CELL_KEY ="rotatedBoxToCell"; public static final String SPHERE_TO_CELL_KEY ="sphereToCell"; public static final String CYLINDER_TO_CELL_KEY ="cylinderToCell"; - public static final String RING_TO_CELL_KEY ="ringToCell"; + public static final String RING_TO_CELL_KEY = "ringToCell"; + public static final String CYLINDER_ANNULUS_TO_CELL_KEY = "cylinderAnnulusToCell"; + public static final String SURFACE_TO_CELL_KEY = "surfaceToCell"; + + public static final String CURVATURE_KEY = "curvature"; + public static final String NEAR_DISTANCE_KEY = "nearDistance"; + public static final String INCLUDE_OUTSIDE_KEY = "includeOutside"; + public static final String INCLUDE_INSIDE_KEY = "includeInside"; + public static final String INCLUDE_CUT_KEY = "includeCut"; + public static final String FILE_KEY = "file"; + public static final String OUTSIDE_POINTS_KEY = "outsidePoints"; public SetFieldsDict() { super(SET_FIELDS_DICT); diff --git a/src/eu/engys/core/project/system/SnappyHexMeshDict.java b/src/eu/engys/core/project/system/SnappyHexMeshDict.java index 5975651..8e565b4 100644 --- a/src/eu/engys/core/project/system/SnappyHexMeshDict.java +++ b/src/eu/engys/core/project/system/SnappyHexMeshDict.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.system; @@ -229,8 +228,8 @@ public class SnappyHexMeshDict extends Dictionary { public static final String REGIONS_KEY = "regions"; public static final String CELL_ZONE_KEY = "cellZone"; public static final String FACE_ZONE_KEY = "faceZone"; - public static final String CELL_ZONE_INSIDE = "cellZoneInside"; - public static final String IS_CELL_ZONE = "isCellZone"; + public static final String CELL_ZONE_INSIDE_KEY = "cellZoneInside"; + public static final String IS_CELL_ZONE_KEY = "isCellZone"; public static final String INTERNAL_KEY = "internal"; public static final String BOUNDARY_KEY = "boundary"; diff --git a/src/eu/engys/core/project/system/StretchMeshDict.java b/src/eu/engys/core/project/system/StretchMeshDict.java new file mode 100644 index 0000000..df73ece --- /dev/null +++ b/src/eu/engys/core/project/system/StretchMeshDict.java @@ -0,0 +1,65 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.core.project.system; + +import static eu.engys.core.project.system.SystemFolder.SYSTEM; + +import java.io.File; + +import eu.engys.core.dictionary.Dictionary; +import eu.engys.core.dictionary.DictionaryException; +import eu.engys.core.dictionary.FoamFile; + +public class StretchMeshDict extends Dictionary { + + public static final String STRETCH_MESH_DICT = "stretchMeshDict"; + + public static final String BASE_POINT_KEY = "basePoint"; + public static final String STRETCH_DIRECTION_KEY = "stretchDirection"; + public static final String INITIAL_LENGTH_KEY = "initialLength"; + public static final String STRETCH_LENGTH_KEY = "stretchLength"; + public static final String EXPANSION_RATIO_KEY = "expansionRatio"; + public static final String DELTA_KEY = "delta"; + public static final String SYMMETRIC_KEY = "symmetric"; + + public StretchMeshDict() { + super(STRETCH_MESH_DICT); + setFoamFile(FoamFile.getDictionaryFoamFile(SYSTEM, STRETCH_MESH_DICT)); + } + + public StretchMeshDict(File file) { + super(file); + } + + public StretchMeshDict(Dictionary dict) { + super(dict); + setFoamFile(FoamFile.getDictionaryFoamFile(SYSTEM, STRETCH_MESH_DICT)); + } + + @Override + public void check() throws DictionaryException { + } + +} diff --git a/src/eu/engys/core/project/system/SystemFolder.java b/src/eu/engys/core/project/system/SystemFolder.java index 0778f4e..cde3fc4 100644 --- a/src/eu/engys/core/project/system/SystemFolder.java +++ b/src/eu/engys/core/project/system/SystemFolder.java @@ -1,31 +1,32 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.system; +import static eu.engys.core.project.system.ControlDict.INCLUDE_KEY; +import static eu.engys.core.project.system.ControlDict.LIBS_KEY; + import java.io.File; import java.util.Set; @@ -42,21 +43,22 @@ import eu.engys.core.project.system.monitoringfunctionobjects.MonitoringFunction import eu.engys.util.progress.ProgressMonitor; public class SystemFolder implements Folder { - + public static final String SYSTEM = "system"; - - //ECOMARINE + + // ECOMARINE public static final String REGION_KEY = "region"; public static final String PATCHES_KEY = "patches"; public static final String EXTRUDE_TO_REGION_MESH_DICT = "extrudeToRegionMeshDict"; private BlockMeshDict blockMeshDict; private SnappyHexMeshDict snappyHexMeshDict; + private StretchMeshDict stretchMeshDict; private FvSchemes fvSchemes; private FvSolution fvSolution; private FvOptions fvOptions; private ControlDict controlDict; - private RunDict runDict; + private ProjectDict projectDict; private SetFieldsDict setFieldsDict; private MapFieldsDict mapFieldsDict; private DecomposeParDict decomposeParDict; @@ -73,12 +75,12 @@ public class SystemFolder implements Folder { fileManager = new DefaultFileManager(new File(baseDir, SYSTEM)); setBlockMeshDict(systemFolder.getBlockMeshDict()); setSnappyHexMeshDict(systemFolder.getSnappyHexMeshDict()); + setStretchMeshDict(systemFolder.getStretchMeshDict()); setFvSchemes(systemFolder.getFvSchemes()); setFvSolution(systemFolder.getFvSolution()); setFvOptions(systemFolder.getFvOptions()); setControlDict(systemFolder.getControlDict()); - setRunDict(systemFolder.getRunDict()); -// setSetFieldsDict(systemFolder.getSetFieldsDict()); + setProjectDict(systemFolder.getProjectDict()); setMapFieldsDict(systemFolder.getMapFieldsDict()); setDecomposeParDict(systemFolder.getDecomposeParDict()); setCustomNodeDict(systemFolder.getCustomNodeDict()); @@ -105,12 +107,21 @@ public class SystemFolder implements Folder { public SnappyHexMeshDict getSnappyHexMeshDict() { return snappyHexMeshDict; } - + public void setSnappyHexMeshDict(Dictionary dict) throws DictionaryException { this.snappyHexMeshDict = new SnappyHexMeshDict(); snappyHexMeshDict.merge(dict); } + public StretchMeshDict getStretchMeshDict() { + return stretchMeshDict; + } + + public void setStretchMeshDict(Dictionary dict) { + this.stretchMeshDict = new StretchMeshDict(); + stretchMeshDict.merge(dict); + } + public FvSchemes getFvSchemes() { return fvSchemes; } @@ -150,14 +161,14 @@ public class SystemFolder implements Folder { controlDict.check(); } - public RunDict getRunDict() { - return runDict; + public ProjectDict getProjectDict() { + return projectDict; } - public void setRunDict(Dictionary dict) { - this.runDict = new RunDict(); - runDict.merge(dict); - runDict.check(); + public void setProjectDict(Dictionary dict) { + this.projectDict = new ProjectDict(); + projectDict.merge(dict); + projectDict.check(); } public SetFieldsDict getSetFieldsDict() { @@ -166,6 +177,7 @@ public class SystemFolder implements Folder { public void setSetFieldsDict(Dictionary dict) { this.setFieldsDict = new SetFieldsDict(dict); + setFieldsDict.check(); } public MapFieldsDict getMapFieldsDict() { @@ -185,6 +197,7 @@ public class SystemFolder implements Folder { public void setDecomposeParDict(Dictionary dict) throws DictionaryException { this.decomposeParDict = new DecomposeParDict(); decomposeParDict.merge(dict); + decomposeParDict.check(); } public CustomNodeDict getCustomNodeDict() { @@ -202,20 +215,51 @@ public class SystemFolder implements Folder { writeBlockMeshDict(monitor); DictionaryUtils.writeDictionary(systemDir, snappyHexMeshDict, monitor); DictionaryUtils.writeDictionary(systemDir, decomposeParDict, monitor); - writeControlDict(monitor); + DictionaryUtils.writeDictionary(systemDir, stretchMeshDict, monitor); + writeControlDict(model, monitor); DictionaryUtils.writeDictionary(systemDir, fvSolution, monitor); DictionaryUtils.writeDictionary(systemDir, fvSchemes, monitor); DictionaryUtils.writeDictionary(systemDir, fvOptions, monitor); DictionaryUtils.writeDictionary(systemDir, setFieldsDict, monitor); - DictionaryUtils.writeDictionary(systemDir, runDict, monitor); + writeProjectDict(monitor); DictionaryUtils.writeDictionary(systemDir, customDict, monitor); DictionaryUtils.writeDictionary(systemDir, mapFieldsDict, monitor); } - public void writeControlDict(ProgressMonitor monitor) { + public void writeControlDict(Model model, ProgressMonitor monitor) { + // applyHELYXFixes(model);NOT FOR HELYXOS DictionaryUtils.writeDictionary(fileManager.getFile(), controlDict, monitor); } + private void applyHELYXFixes(Model model) { + if (model.getState().getSolverType().isCoupled()) { + if (controlDict.found(INCLUDE_KEY)) { + controlDict.remove(INCLUDE_KEY); + } + } else { + if (!controlDict.found(INCLUDE_KEY)) { + controlDict.add(INCLUDE_KEY, "\"$FOAM_CONFIG/controlDict.libs\""); + } + } + StringBuilder sb = new StringBuilder(); + sb.append("( \"libLEMOS-2.2.x.so\" "); + if (model.getState().isAdjoint() && model.getState().isTransient()) { + sb.append("\"libHelyxAdjointPlus.so\""); + } else if (model.getState().isAdjoint() && model.getState().isSteady()) { + sb.append("\"libHelyxAdjoint.so\""); + } + sb.append(" )"); + + if (controlDict.found(LIBS_KEY)) { + controlDict.remove(LIBS_KEY); + } + controlDict.add(LIBS_KEY, sb.toString()); + } + + public void writeProjectDict(ProgressMonitor monitor) { + DictionaryUtils.writeDictionary(fileManager.getFile(), projectDict, monitor); + } + public void writeBlockMeshDict(ProgressMonitor monitor) { if (!blockMeshDict.isFromFile()) { DictionaryUtils.writeDictionary(fileManager.getFile(), blockMeshDict, monitor); @@ -225,7 +269,7 @@ public class SystemFolder implements Folder { public void read(Model model, Set ffoTypes, Set mfoTypes, ProgressMonitor monitor) { File systemFolder = new File(model.getProject().getBaseDir(), SYSTEM); if (systemFolder.exists() && systemFolder.isDirectory()) { - + readControlDict(model, monitor, systemFolder); readFvSolution(model, monitor, systemFolder); @@ -236,6 +280,8 @@ public class SystemFolder implements Folder { readSnappyHexMeshDict(model, monitor, systemFolder); + readStretchMeshDict(model, monitor, systemFolder); + readBlockMeshDict(model, monitor, systemFolder); readDecomposeParDict(model, monitor, systemFolder); @@ -244,13 +290,13 @@ public class SystemFolder implements Folder { readMapFiedsDict(model, monitor, systemFolder); - readRunDict(model, monitor, systemFolder); + readProjectDict(model, monitor, systemFolder); readCustomDict(model, monitor, systemFolder); model.getRuntimeFields().load(controlDict, monitor); model.runtimeFieldsChanged(); - + model.getFieldManipulationFunctionObjects().load(controlDict, ffoTypes, monitor); model.fieldManipulationFunctionObjectsChanged(); @@ -275,7 +321,6 @@ public class SystemFolder implements Folder { } catch (DictionaryException e) { monitor.warning(e.getMessage(), 1); } - getControlDict().functionObjectsToDict(); } else { setControlDict(model.getDefaults().getDefaultControlDict()); monitor.warning(ControlDict.CONTROL_DICT + " not found, the default one will be used", 1); @@ -336,7 +381,7 @@ public class SystemFolder implements Folder { private void readSnappyHexMeshDict(Model model, ProgressMonitor monitor, File systemFolder) { File snappyHexMeshFile = new File(systemFolder, SnappyHexMeshDict.SNAPPY_DICT); SnappyHexMeshDict snappy = model.getDefaults().getDefaultSnappyHexMeshDict(); - + if (snappyHexMeshFile.exists()) { SnappyHexMeshDict snappyFromFile = new SnappyHexMeshDict(snappyHexMeshFile); snappy.merge(snappyFromFile); @@ -353,6 +398,22 @@ public class SystemFolder implements Folder { } } + private void readStretchMeshDict(Model model, ProgressMonitor monitor, File systemFolder) { + File stretchMeshDictFile = new File(systemFolder, StretchMeshDict.STRETCH_MESH_DICT); + if (stretchMeshDictFile.exists()) { + Dictionary dict = new StretchMeshDict(stretchMeshDictFile); + try { + setStretchMeshDict(dict); + monitor.info(StretchMeshDict.STRETCH_MESH_DICT, 1); + } catch (DictionaryException e) { + monitor.warning(e.getMessage(), 1); + } + } else { + setStretchMeshDict(model.getDefaults().getDefaultStretchMeshDict()); + monitor.warning(StretchMeshDict.STRETCH_MESH_DICT + " not found, the default one will be used", 1); + } + } + private void readBlockMeshDict(Model model, ProgressMonitor monitor, File systemFolder) { File blockMeshFile = new File(systemFolder, BlockMeshDict.BLOCK_DICT); if (blockMeshFile.exists()) { @@ -384,14 +445,13 @@ public class SystemFolder implements Folder { Dictionary dict = new DecomposeParDict(decomposeParFile); try { setDecomposeParDict(dict); - decomposeParDict.check(); monitor.info(DecomposeParDict.DECOMPOSE_PAR_DICT, 1); } catch (DictionaryException e) { monitor.warning(e.getMessage(), 1); } } else { setDecomposeParDict(model.getDefaults().getDefaultDecomposeParDict()); - monitor.warning(DecomposeParDict.DECOMPOSE_PAR_DICT+ " not found, the default one will be used", 1); + monitor.warning(DecomposeParDict.DECOMPOSE_PAR_DICT + " not found, the default one will be used", 1); } } @@ -401,7 +461,6 @@ public class SystemFolder implements Folder { Dictionary dict = new SetFieldsDict(setFieldsDictFile); try { setSetFieldsDict(dict); - setFieldsDict.check(); monitor.info(SetFieldsDict.SET_FIELDS_DICT, 1); } catch (DictionaryException e) { monitor.warning(e.getMessage(), 1); @@ -417,7 +476,6 @@ public class SystemFolder implements Folder { Dictionary dict = new MapFieldsDict(mapFieldsDictFile); try { setMapFieldsDict(dict); - mapFieldsDict.check(); monitor.info(MapFieldsDict.MAP_FIELDS_DICT, 1); } catch (DictionaryException e) { monitor.warning(e.getMessage(), 1); @@ -428,19 +486,33 @@ public class SystemFolder implements Folder { } } - private void readRunDict(Model model, ProgressMonitor monitor, File systemFolder) { - File runDictFile = new File(systemFolder, RunDict.RUN_DICT); + // private void readRunDict(Model model, ProgressMonitor monitor, File systemFolder) { + // File runDictFile = new File(systemFolder, RunDict.RUN_DICT); + // if (runDictFile.exists()) { + // RunDict dict = new RunDict(runDictFile); + // try { + //// setRunDict(dict); + // monitor.info(RunDict.RUN_DICT, 1); + // } catch (DictionaryException e) { + // monitor.warning(e.getMessage(), 1); + // } + // } else { + // monitor.warning(RunDict.RUN_DICT + " NOT FOUND", 1); + // } + // } + + public void readProjectDict(Model model, ProgressMonitor monitor, File systemFolder) { + File runDictFile = new File(systemFolder, ProjectDict.PROJECT_DICT); if (runDictFile.exists()) { - RunDict dict = new RunDict(runDictFile); + ProjectDict dict = new ProjectDict(runDictFile); try { - setRunDict(dict); - runDict.check(); - monitor.info(RunDict.RUN_DICT, 1); + setProjectDict(dict); + monitor.info(ProjectDict.PROJECT_DICT, 1); } catch (DictionaryException e) { monitor.warning(e.getMessage(), 1); } } else { - monitor.warning(RunDict.RUN_DICT + " NOT FOUND", 1); + monitor.warning(ProjectDict.PROJECT_DICT + " NOT FOUND", 1); } } diff --git a/src/eu/engys/core/project/system/fieldmanipulationfunctionobjects/FieldManipulationFunctionObject.java b/src/eu/engys/core/project/system/fieldmanipulationfunctionobjects/FieldManipulationFunctionObject.java index 88c491c..b20d80f 100644 --- a/src/eu/engys/core/project/system/fieldmanipulationfunctionobjects/FieldManipulationFunctionObject.java +++ b/src/eu/engys/core/project/system/fieldmanipulationfunctionobjects/FieldManipulationFunctionObject.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.system.fieldmanipulationfunctionobjects; diff --git a/src/eu/engys/core/project/system/fieldmanipulationfunctionobjects/FieldManipulationFunctionObjectPanel.java b/src/eu/engys/core/project/system/fieldmanipulationfunctionobjects/FieldManipulationFunctionObjectPanel.java index 88d7516..bc5f310 100644 --- a/src/eu/engys/core/project/system/fieldmanipulationfunctionobjects/FieldManipulationFunctionObjectPanel.java +++ b/src/eu/engys/core/project/system/fieldmanipulationfunctionobjects/FieldManipulationFunctionObjectPanel.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.system.fieldmanipulationfunctionobjects; diff --git a/src/eu/engys/core/project/system/fieldmanipulationfunctionobjects/FieldManipulationFunctionObjectType.java b/src/eu/engys/core/project/system/fieldmanipulationfunctionobjects/FieldManipulationFunctionObjectType.java index bfe6bab..1e6a46b 100644 --- a/src/eu/engys/core/project/system/fieldmanipulationfunctionobjects/FieldManipulationFunctionObjectType.java +++ b/src/eu/engys/core/project/system/fieldmanipulationfunctionobjects/FieldManipulationFunctionObjectType.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.system.fieldmanipulationfunctionobjects; import eu.engys.core.dictionary.Dictionary; diff --git a/src/eu/engys/core/project/system/fieldmanipulationfunctionobjects/FieldManipulationFunctionObjects.java b/src/eu/engys/core/project/system/fieldmanipulationfunctionobjects/FieldManipulationFunctionObjects.java index 02ff6bc..3145d49 100644 --- a/src/eu/engys/core/project/system/fieldmanipulationfunctionobjects/FieldManipulationFunctionObjects.java +++ b/src/eu/engys/core/project/system/fieldmanipulationfunctionobjects/FieldManipulationFunctionObjects.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.system.fieldmanipulationfunctionobjects; import static eu.engys.core.dictionary.Dictionary.TYPE; @@ -58,7 +57,6 @@ public class FieldManipulationFunctionObjects extends ArrayList types, ProgressMonitor monitor) { ControlDict controlDict = model.getProject().getSystemFolder().getControlDict(); - controlDict.functionObjectsToDict(); Dictionary newFunctions = new Dictionary(FUNCTIONS_KEY); if (controlDict.found(FUNCTIONS_KEY)) { @@ -76,7 +74,6 @@ public class FieldManipulationFunctionObjects extends ArrayList types, Dictionary oldFunctions, Dictionary newFunctions) { diff --git a/src/eu/engys/core/project/system/monitoringfunctionobjects/FakeParser.java b/src/eu/engys/core/project/system/monitoringfunctionobjects/FakeParser.java index 0e0ab76..db76c55 100644 --- a/src/eu/engys/core/project/system/monitoringfunctionobjects/FakeParser.java +++ b/src/eu/engys/core/project/system/monitoringfunctionobjects/FakeParser.java @@ -1,29 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.system.monitoringfunctionobjects; import java.io.File; @@ -42,11 +40,6 @@ public class FakeParser implements Parser { public TimeBlocks updateParsing() throws Exception { return null; } - - @Override - public boolean checkTimeBlockConsistency(TimeBlocks newTimeBlocks) { - return true; - } @Override public void clear() { @@ -56,7 +49,7 @@ public class FakeParser implements Parser { public File getFile() { return null; } - + @Override public boolean isValidTimeRow(String row) { return false; diff --git a/src/eu/engys/core/project/system/monitoringfunctionobjects/MonitoringFunctionObject.java b/src/eu/engys/core/project/system/monitoringfunctionobjects/MonitoringFunctionObject.java index 5a4450e..51cdc49 100644 --- a/src/eu/engys/core/project/system/monitoringfunctionobjects/MonitoringFunctionObject.java +++ b/src/eu/engys/core/project/system/monitoringfunctionobjects/MonitoringFunctionObject.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.system.monitoringfunctionobjects; diff --git a/src/eu/engys/core/project/system/monitoringfunctionobjects/MonitoringFunctionObjectPanel.java b/src/eu/engys/core/project/system/monitoringfunctionobjects/MonitoringFunctionObjectPanel.java index 00052b9..d407a04 100644 --- a/src/eu/engys/core/project/system/monitoringfunctionobjects/MonitoringFunctionObjectPanel.java +++ b/src/eu/engys/core/project/system/monitoringfunctionobjects/MonitoringFunctionObjectPanel.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.system.monitoringfunctionobjects; diff --git a/src/eu/engys/core/project/system/monitoringfunctionobjects/MonitoringFunctionObjectType.java b/src/eu/engys/core/project/system/monitoringfunctionobjects/MonitoringFunctionObjectType.java index b832921..a183eb0 100644 --- a/src/eu/engys/core/project/system/monitoringfunctionobjects/MonitoringFunctionObjectType.java +++ b/src/eu/engys/core/project/system/monitoringfunctionobjects/MonitoringFunctionObjectType.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.system.monitoringfunctionobjects; import eu.engys.core.dictionary.Dictionary; diff --git a/src/eu/engys/core/project/system/monitoringfunctionobjects/MonitoringFunctionObjects.java b/src/eu/engys/core/project/system/monitoringfunctionobjects/MonitoringFunctionObjects.java index 6aff8e1..0aaf7c8 100644 --- a/src/eu/engys/core/project/system/monitoringfunctionobjects/MonitoringFunctionObjects.java +++ b/src/eu/engys/core/project/system/monitoringfunctionobjects/MonitoringFunctionObjects.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.system.monitoringfunctionobjects; @@ -62,7 +61,6 @@ public class MonitoringFunctionObjects extends ArrayList types, ProgressMonitor monitor) { ControlDict controlDict = model.getProject().getSystemFolder().getControlDict(); - controlDict.functionObjectsToDict(); Dictionary newFunctions = new Dictionary(FUNCTIONS_KEY); if (controlDict.found(FUNCTIONS_KEY)) { @@ -81,7 +79,6 @@ public class MonitoringFunctionObjects extends ArrayList types, Dictionary oldFunctions, Dictionary newFunctions) { diff --git a/src/eu/engys/core/project/system/monitoringfunctionobjects/Parser.java b/src/eu/engys/core/project/system/monitoringfunctionobjects/Parser.java index f84510d..a69ec4f 100644 --- a/src/eu/engys/core/project/system/monitoringfunctionobjects/Parser.java +++ b/src/eu/engys/core/project/system/monitoringfunctionobjects/Parser.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.system.monitoringfunctionobjects; @@ -46,6 +45,4 @@ public interface Parser { String getKey(); - boolean checkTimeBlockConsistency(TimeBlocks newTimeBlocks); - } diff --git a/src/eu/engys/core/project/system/monitoringfunctionobjects/ParserFactory.java b/src/eu/engys/core/project/system/monitoringfunctionobjects/ParserFactory.java index efe831a..42c23f4 100644 --- a/src/eu/engys/core/project/system/monitoringfunctionobjects/ParserFactory.java +++ b/src/eu/engys/core/project/system/monitoringfunctionobjects/ParserFactory.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.system.monitoringfunctionobjects; diff --git a/src/eu/engys/core/project/system/monitoringfunctionobjects/ParserView.java b/src/eu/engys/core/project/system/monitoringfunctionobjects/ParserView.java index 53e5bfa..6898724 100644 --- a/src/eu/engys/core/project/system/monitoringfunctionobjects/ParserView.java +++ b/src/eu/engys/core/project/system/monitoringfunctionobjects/ParserView.java @@ -1,35 +1,34 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.system.monitoringfunctionobjects; import java.util.List; import javax.swing.JComponent; +import eu.engys.core.project.state.State; import eu.engys.core.report.Exporter; public interface ParserView { @@ -40,6 +39,7 @@ public interface ParserView { public void handleSolverStarted(); void clearData(); + public void handleStateChanged(State state); public void handleFunctionObjectChanged(); public JComponent getPanel(); @@ -56,18 +56,16 @@ public interface ParserView { void showLogFile(); - void setCrosshairVisibile(boolean visible); - + void deleteLogFiles(); + void exportToExcel(); void exportToCSV(); void exportToPNG(); - List gerReportParsersList(); + List getReportParsersList(); Exporter getExporter(); - - } diff --git a/src/eu/engys/core/project/system/monitoringfunctionobjects/TimeBlock.java b/src/eu/engys/core/project/system/monitoringfunctionobjects/TimeBlock.java index bbdff86..bbd1b29 100644 --- a/src/eu/engys/core/project/system/monitoringfunctionobjects/TimeBlock.java +++ b/src/eu/engys/core/project/system/monitoringfunctionobjects/TimeBlock.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.system.monitoringfunctionobjects; diff --git a/src/eu/engys/core/project/system/monitoringfunctionobjects/TimeBlockUnit.java b/src/eu/engys/core/project/system/monitoringfunctionobjects/TimeBlockUnit.java index d5175b3..9c28e75 100644 --- a/src/eu/engys/core/project/system/monitoringfunctionobjects/TimeBlockUnit.java +++ b/src/eu/engys/core/project/system/monitoringfunctionobjects/TimeBlockUnit.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.system.monitoringfunctionobjects; diff --git a/src/eu/engys/core/project/system/monitoringfunctionobjects/TimeBlocks.java b/src/eu/engys/core/project/system/monitoringfunctionobjects/TimeBlocks.java index a2b84d6..eeb95b2 100644 --- a/src/eu/engys/core/project/system/monitoringfunctionobjects/TimeBlocks.java +++ b/src/eu/engys/core/project/system/monitoringfunctionobjects/TimeBlocks.java @@ -1,31 +1,32 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.system.monitoringfunctionobjects; import java.io.Serializable; +import java.util.Collections; +import java.util.Comparator; import java.util.Iterator; import java.util.LinkedList; import java.util.List; @@ -137,22 +138,18 @@ public class TimeBlocks implements Iterable, Serializable { return get(list.size() - 1); } - public TimeBlock removeLast() { - return remove(list.size() - 1); - } - public Iterator iterator() { synchronized (mutex) { return list.iterator(); } } - // private void writeObject(java.io.ObjectOutputStream out) throws - // IOException { - // - // } - // private void readObject(java.io.ObjectInputStream in) throws IOException, - // ClassNotFoundException { - // - // } + public void orderAscending() { + Collections.sort(list, new Comparator() { + @Override + public int compare(TimeBlock o1, TimeBlock o2) { + return o1.getTime().compareTo(o2.getTime()); + } + }); + } } diff --git a/src/eu/engys/core/project/zero/MeshRegion.java b/src/eu/engys/core/project/zero/MeshRegion.java index 0357077..ab7c507 100644 --- a/src/eu/engys/core/project/zero/MeshRegion.java +++ b/src/eu/engys/core/project/zero/MeshRegion.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.zero; import eu.engys.core.project.zero.fields.Fields; diff --git a/src/eu/engys/core/project/zero/ParallelZeroFileManager.java b/src/eu/engys/core/project/zero/ParallelZeroFileManager.java index 7cb2293..9a069f8 100644 --- a/src/eu/engys/core/project/zero/ParallelZeroFileManager.java +++ b/src/eu/engys/core/project/zero/ParallelZeroFileManager.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.zero; import static eu.engys.core.project.zero.ZeroFolderUtil.clearFiles; @@ -37,12 +36,18 @@ import static eu.engys.core.project.zero.ZeroFolderUtil.newZeroDir; import java.io.File; import java.io.FilenameFilter; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import eu.engys.core.project.files.DefaultFileManager; import eu.engys.core.project.system.ControlDict; public class ParallelZeroFileManager extends DefaultFileManager implements ZeroFileManager { + + private static final Logger logger = LoggerFactory.getLogger(ParallelZeroFileManager.class); public ParallelZeroFileManager(File file, int nProcessors) { super(file); @@ -67,7 +72,7 @@ public class ParallelZeroFileManager extends DefaultFileManager implements ZeroF public void clearZeroDirs(String timeStep) { logger.debug("Clear zero folder!"); for (File file : getZeroDirs(timeStep)) { - clearFiles(file); + clearFiles(null, file); } } @@ -184,16 +189,31 @@ public class ParallelZeroFileManager extends DefaultFileManager implements ZeroF File[] boundaryFiles = getBoundaryFiles(polyMeshes); if (ZeroFolderUtil.exists(boundaryFiles)) { + logger.info("Found mesh in ZERO"); check.setBoundaryFieldInZero(true); - } else { - File[] constantDirs = getConstantDirs(); - polyMeshes = getPolyMeshDirs(constantDirs); - boundaryFiles = getBoundaryFiles(polyMeshes); + } - if (ZeroFolderUtil.exists(boundaryFiles)) { - check.setBoundaryFieldInConstant(true); - } + String[] regionNames = ZeroFolderUtil.getRegions(zeroDirs); + if (regionNames != null && regionNames.length > 0) { + logger.info("Found MULTIREGION mesh in ZERO: {}", Arrays.toString(regionNames)); + check.setBoundaryFieldInZeroMultiRegion(true); + } + + File[] constantDirs = getConstantDirs(); + polyMeshes = getPolyMeshDirs(constantDirs); + boundaryFiles = getBoundaryFiles(polyMeshes); + + if (ZeroFolderUtil.exists(boundaryFiles)) { + logger.info("Found mesh in CONSTANT"); + check.setBoundaryFieldInConstant(true); } + + regionNames = ZeroFolderUtil.getRegions(constantDirs); + if (regionNames != null && regionNames.length > 0) { + logger.info("Found MULTIREGION mesh in CONSTANT: {}", Arrays.toString(regionNames)); + check.setBoundaryFieldInConstantMultiRegion(true); + } + return check; } @@ -226,17 +246,20 @@ public class ParallelZeroFileManager extends DefaultFileManager implements ZeroF @Override public void removeZeroDirs(String timeStep) { + logger.debug("Deleting 'zero' folders"); File[] zeroDirs = getZeroDirs(timeStep); delete(zeroDirs); } public void removeConstantDirs() { + logger.debug("Deleting 'constant' folders"); File[] constantDirs = getConstantDirs(); delete(constantDirs); } @Override public void removeNonZeroDirs(String timeStep) { + logger.debug("Deleting 'non zero' folders"); File[] nonZeroDirs = getNonZeroDirs(timeStep); delete(nonZeroDirs); } diff --git a/src/eu/engys/core/project/zero/SerialZeroFileManager.java b/src/eu/engys/core/project/zero/SerialZeroFileManager.java index 6e80c32..7b8ed05 100644 --- a/src/eu/engys/core/project/zero/SerialZeroFileManager.java +++ b/src/eu/engys/core/project/zero/SerialZeroFileManager.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.zero; import static eu.engys.core.project.zero.ZeroFolderUtil.clearFiles; @@ -38,14 +37,19 @@ import static eu.engys.core.project.zero.ZeroFolderUtil.newZeroDir; import java.io.File; import java.io.FilenameFilter; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import org.apache.commons.io.FileUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import eu.engys.core.project.files.DefaultFileManager; import eu.engys.core.project.system.ControlDict; public class SerialZeroFileManager extends DefaultFileManager implements ZeroFileManager { + + private static final Logger logger = LoggerFactory.getLogger(SerialZeroFileManager.class); public SerialZeroFileManager(File file) { super(file); @@ -62,7 +66,7 @@ public class SerialZeroFileManager extends DefaultFileManager implements ZeroFil @Override public void clearZeroDirs(String timeStep) { for (File file : getZeroDirs(timeStep)) { - clearFiles(file); + clearFiles(null, file); } } @@ -87,7 +91,7 @@ public class SerialZeroFileManager extends DefaultFileManager implements ZeroFil File zeroDir = zeroDirs[0]; return arrayOf(getRegionDir(zeroDir, region)); } else { - throw new RuntimeException(""); + throw new RuntimeException("Size should be 1 instead is " + zeroDirs.length); } } @@ -97,7 +101,7 @@ public class SerialZeroFileManager extends DefaultFileManager implements ZeroFil File zeroDir = zeroDirs[0]; return arrayOf(getPolyMeshDir(zeroDir)); } else { - throw new RuntimeException(""); + throw new RuntimeException("Size should be 1 instead is " + zeroDirs.length); } } @@ -107,7 +111,7 @@ public class SerialZeroFileManager extends DefaultFileManager implements ZeroFil File polyMesh = polyMeshDirs[0]; return arrayOf(getBoundaryFile(polyMesh)); } else { - throw new RuntimeException(""); + throw new RuntimeException("Size should be 1 instead is " + polyMeshDirs.length); } } @@ -117,7 +121,7 @@ public class SerialZeroFileManager extends DefaultFileManager implements ZeroFil File polyMesh = polyMeshDirs[0]; return arrayOf(getCellZonesFile(polyMesh)); } else { - throw new RuntimeException(""); + throw new RuntimeException("Size should be 1 instead is " + polyMeshDirs.length); } } @@ -127,7 +131,7 @@ public class SerialZeroFileManager extends DefaultFileManager implements ZeroFil File polyMesh = polyMeshDirs[0]; return arrayOf(getFaceZonesFile(polyMesh)); } else { - throw new RuntimeException(""); + throw new RuntimeException("Size should be 1 instead is " + polyMeshDirs.length); } } @@ -150,15 +154,29 @@ public class SerialZeroFileManager extends DefaultFileManager implements ZeroFil File boundaryFile = getBoundaryFile(polyMesh); if (boundaryFile.exists()) { + logger.info("Found mesh in ZERO"); check.setBoundaryFieldInZero(true); - } else { - File constantDir = getConstantDir(getFile()); - polyMesh = getPolyMeshDir(constantDir); - boundaryFile = getBoundaryFile(polyMesh); + } + + String[] regionNames = ZeroFolderUtil.getRegions(zeroDir); + if (regionNames != null && regionNames.length > 0) { + logger.info("Found MULTIREGION mesh in ZERO: {}", Arrays.toString(regionNames)); + check.setBoundaryFieldInZeroMultiRegion(true); + } + + File constantDir = getConstantDir(getFile()); + polyMesh = getPolyMeshDir(constantDir); + boundaryFile = getBoundaryFile(polyMesh); + + if (boundaryFile.exists()) { + logger.info("Found mesh in CONSTANT"); + check.setBoundaryFieldInConstant(true); + } - if (boundaryFile.exists()) { - check.setBoundaryFieldInConstant(true); - } + regionNames = ZeroFolderUtil.getRegions(constantDir); + if (regionNames != null && regionNames.length > 0) { + logger.info("Found MULTIREGION mesh in CONSTANT: {}", Arrays.toString(regionNames)); + check.setBoundaryFieldInConstantMultiRegion(true); } return check; @@ -211,7 +229,7 @@ public class SerialZeroFileManager extends DefaultFileManager implements ZeroFil @Override public File[] getNonZeroDirs(String timeStep) { - List nonZeroFolders = new ArrayList(); + List nonZeroFolders = new ArrayList<>(); File[] foldersWithANumberName = getFile().listFiles(new FilenameFilter() { @Override public boolean accept(File dir, String name) { diff --git a/src/eu/engys/core/project/zero/ZeroFileManager.java b/src/eu/engys/core/project/zero/ZeroFileManager.java index a3aeb79..4a78905 100644 --- a/src/eu/engys/core/project/zero/ZeroFileManager.java +++ b/src/eu/engys/core/project/zero/ZeroFileManager.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.zero; import java.io.File; diff --git a/src/eu/engys/core/project/zero/ZeroFolder.java b/src/eu/engys/core/project/zero/ZeroFolder.java index 9e92dd0..ecddcd1 100644 --- a/src/eu/engys/core/project/zero/ZeroFolder.java +++ b/src/eu/engys/core/project/zero/ZeroFolder.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.zero; import java.io.File; @@ -39,7 +38,6 @@ import eu.engys.core.modules.ModulesUtil; import eu.engys.core.project.Model; import eu.engys.core.project.openFOAMProject; import eu.engys.core.project.defaults.DefaultsProvider; -import eu.engys.core.project.files.FileManager; import eu.engys.core.project.files.Folder; import eu.engys.core.project.state.State; import eu.engys.core.project.zero.cellzones.CellZones; @@ -62,6 +60,9 @@ import eu.engys.util.progress.ProgressMonitor; public class ZeroFolder implements Folder { + public static final String ZERO = "0"; + public static final String POLY_MESH = "polyMesh"; + private static final Logger logger = LoggerFactory.getLogger(ZeroFolder.class); private ZeroFileManager zeroFileManager; @@ -88,6 +89,8 @@ public class ZeroFolder implements Folder { try { timeValue = zeroFileManager.findTimeValue(model.getProject().getSystemFolder().getControlDict()); + monitor.info("Time: " + timeValue, 1); + File[] zeroDirs = zeroFileManager.getZeroDirs("0"); File[] timeDirs = zeroFileManager.getZeroDirs(timeValue); File[] polyMeshes = zeroFileManager.getPolyMeshDirs(zeroDirs); @@ -107,7 +110,7 @@ public class ZeroFolder implements Folder { monitor.setIndeterminate(false); - model.setPatches(readPatches(monitor, boundaryFiles)); + model.setPatches(readPatches(model, monitor, boundaryFiles)); model.setCellZones(readCellZones(model, builder, monitor, cellZonesFiles, modules)); model.setFaceZones(readFaceZones(monitor, faceZonesFiles)); model.setFields(readFields(null, model.getProject(), model.getState(), model.getDefaults(), model.getPatches(), modules, initialisations, monitor, timeDirs, boundaryFiles)); @@ -139,7 +142,7 @@ public class ZeroFolder implements Folder { faceZonesFiles = zeroFileManager.getFaceZonesFiles(polyMeshes); } - Patches patches = readPatches(monitor, boundaryFiles); + Patches patches = readPatches(model, monitor, boundaryFiles); Fields fields = readFields(regionName, model.getProject(), model.getState(), model.getDefaults(), patches, modules, initialisations, monitor, regionTimeDirs, boundaryFiles); MeshRegion region = new MeshRegion(); region.setPatches(patches); @@ -158,7 +161,7 @@ public class ZeroFolder implements Folder { model.faceZonesChanged(); } - public Patches readPatches() { + public Patches readPatches(Model model) { File[] zeroDirs = zeroFileManager.getZeroDirs("0"); File[] polyMeshes = zeroFileManager.getPolyMeshDirs(zeroDirs); File[] boundaryFiles = zeroFileManager.getBoundaryFiles(polyMeshes); @@ -169,10 +172,10 @@ public class ZeroFolder implements Folder { boundaryFiles = zeroFileManager.getBoundaryFiles(polyMeshes); } - return readPatches(new ConsoleMonitor(), boundaryFiles); + return readPatches(model, new ConsoleMonitor(), boundaryFiles); } - public Patches readPatches(String regionName) { + public Patches readPatches(Model model, String regionName) { File[] zeroDirs = zeroFileManager.getZeroDirs("0"); File[] regionDirs = zeroFileManager.getRegionDirs(regionName, zeroDirs); File[] polyMeshes = zeroFileManager.getPolyMeshDirs(regionDirs); @@ -185,13 +188,13 @@ public class ZeroFolder implements Folder { boundaryFiles = zeroFileManager.getBoundaryFiles(polyMeshes); } - return readPatches(new ConsoleMonitor(), boundaryFiles); + return readPatches(model, new ConsoleMonitor(), boundaryFiles); } - private Patches readPatches(ProgressMonitor monitor, File[] boundaryFiles) { + private Patches readPatches(Model model, ProgressMonitor monitor, File[] boundaryFiles) { if (ZeroFolderUtil.exists(boundaryFiles)) { monitor.setCurrent("Reading patches", 0, boundaryFiles.length, 1); - Patches patches = new PatchesReader(monitor).read(boundaryFiles); + Patches patches = new PatchesReader(model, monitor).read(boundaryFiles); monitor.info("Patches: " + patches.filterProcBoundary().patchesNames().toString(), 1); return patches; } else { @@ -228,24 +231,36 @@ public class ZeroFolder implements Folder { } private Fields readFields(String region, openFOAMProject prj, State state, DefaultsProvider defaults, Patches patches, Set modules, Initialisations initialisations, ProgressMonitor monitor, File[] timeDirs, File[] boundaryFiles) { - if (initialisations != null && ZeroFolderUtil.exists(timeDirs) && ZeroFolderUtil.exists(boundaryFiles)) { - Fields fields = new Fields(); - if (prj.isParallel()) { - fields.newParallelFields(prj.getProcessors()); - } - logger.debug("Loading fields from defaults"); - fields.merge(FieldsDefaults.loadFieldsFromDefaults(state, defaults, patches, region)); - logger.debug("Loading fields from MODULE defaults"); - fields.merge(ModulesUtil.loadFieldsFromDefaults(modules, region)); - logger.debug("Reading field from case"); - fields.merge(new FieldsReader(initialisations, monitor).read(fields.keySet(), timeDirs)); - fields.fixPVisibility(state); + if (initialisations != null) { + if (ZeroFolderUtil.exists(timeDirs)) { + if (ZeroFolderUtil.exists(boundaryFiles)) { + Fields fields = new Fields(); + if (prj.isParallel()) { + fields.newParallelFields(prj.getProcessors()); + } + logger.debug("Loading fields from defaults"); + fields.merge(FieldsDefaults.loadFieldsFromDefaults(prj.getBaseDir(), state, defaults, patches, region)); + logger.debug("Loading fields from MODULE defaults"); + fields.merge(ModulesUtil.loadFieldsFromDefaults(modules, region)); + logger.debug("Reading field from case"); + fields.merge(new FieldsReader(initialisations, monitor).read(fields.keySet(), timeDirs)); + fields.fixPVisibility(state); - monitor.info("Fields: " + fields.fieldNames().toString(), 1); - return fields; + monitor.info("Fields: " + fields.fieldNames().toString(), 1); + return fields; + } else { + monitor.warning("Missing fields", 1); + logger.warn("Boundary Files " + Arrays.toString(boundaryFiles) + " does not exist"); + return new Fields(); + } + } else { + monitor.warning("Missing fields", 1); + logger.warn("Time Folders " + Arrays.toString(timeDirs) + " does not exist"); + return new Fields(); + } } else { monitor.warning("Missing fields", 1); - logger.warn(Arrays.toString(timeDirs) + " does not exist"); + logger.warn("No initialisation"); return new Fields(); } } @@ -387,7 +402,7 @@ public class ZeroFolder implements Folder { } @Override - public FileManager getFileManager() { + public ZeroFileManager getFileManager() { return zeroFileManager; } @@ -399,12 +414,13 @@ public class ZeroFolder implements Folder { } } - protected boolean avoidSave(Model model) { - return model.getCellZones().isEmpty() && model.getPatches().isEmpty() && model.getFields().isEmpty(); + public void deleteFields() { + zeroFileManager.clearZeroDirs("0"); + zeroFileManager.removeNonZeroDirs("0"); } - public void clearFields() { - zeroFileManager.clearZeroDirs(timeValue); + protected boolean avoidSave(Model model) { + return model.getCellZones().isEmpty() && model.getPatches().isEmpty() && model.getFields().isEmpty(); } public void removeNonZeroTimeFolders_GreaterThanActualTimeStep() { @@ -428,10 +444,6 @@ public class ZeroFolder implements Folder { this.timeValue = timeValue; } - public ZeroFileManager getZeroFileManager() { - return zeroFileManager; - } - public boolean hasRegions() { return !regions.isEmpty(); } diff --git a/src/eu/engys/core/project/zero/ZeroFolderStructure.java b/src/eu/engys/core/project/zero/ZeroFolderStructure.java index 75e7154..97563a1 100644 --- a/src/eu/engys/core/project/zero/ZeroFolderStructure.java +++ b/src/eu/engys/core/project/zero/ZeroFolderStructure.java @@ -1,34 +1,35 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.zero; public class ZeroFolderStructure { private boolean boundaryFieldInZero; private boolean boundaryFieldInConstant; + private boolean boundaryFieldInZeroMultiRegion; + private boolean boundaryFieldInConstantMultiRegion; public boolean isBoundaryFieldInZero() { return boundaryFieldInZero; @@ -46,4 +47,23 @@ public class ZeroFolderStructure { this.boundaryFieldInConstant = boundaryFieldInConstant; } + public boolean isBoundaryFieldInZeroMultiRegion() { + return boundaryFieldInZeroMultiRegion; + } + + public void setBoundaryFieldInZeroMultiRegion(boolean boundaryFieldInZeroMultiRegion) { + this.boundaryFieldInZeroMultiRegion = boundaryFieldInZeroMultiRegion; + } + + public boolean isBoundaryFieldInConstantMultiRegion() { + return boundaryFieldInConstantMultiRegion; + } + + public void setBoundaryFieldInConstantMultiRegion(boolean boundaryFieldInConstantMultiRegion) { + this.boundaryFieldInConstantMultiRegion = boundaryFieldInConstantMultiRegion; + } + + + + } diff --git a/src/eu/engys/core/project/zero/ZeroFolderUtil.java b/src/eu/engys/core/project/zero/ZeroFolderUtil.java index fffad45..9f1fc77 100644 --- a/src/eu/engys/core/project/zero/ZeroFolderUtil.java +++ b/src/eu/engys/core/project/zero/ZeroFolderUtil.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.zero; import static eu.engys.core.project.system.ControlDict.START_FROM_KEY; @@ -36,6 +35,7 @@ import java.io.IOException; import java.io.OutputStream; import java.util.Arrays; import java.util.Comparator; +import java.util.List; import java.util.zip.GZIPInputStream; import org.apache.commons.io.FileUtils; @@ -63,13 +63,13 @@ public class ZeroFolderUtil { return PROCESSOR + i; } - public static void clearFiles(File parent) { + public static void clearFiles(List names, File parent) { + logger.debug("Deleting {}", names); if (parent.list().length != 0) { File[] files = parent.listFiles(); for (File file : files) { - if (file.isFile()) { - logger.debug("Deleting {}", file); - file.delete(); + if (file.isFile() && (names == null || names.contains(file.getName()))) { + FileUtils.deleteQuietly(file); } } } @@ -160,22 +160,32 @@ public class ZeroFolderUtil { String startFrom = controlDict.lookup(START_FROM_KEY); String time = "0"; switch (startFrom) { - case ControlDict.FIRST_TIME_VALUE: - time = getFirstFolderName(proc0); - break; - case ControlDict.LATEST_TIME_VALUE: - time = getLastFolderName(proc0); - break; - case ControlDict.START_TIME_VALUE: - time = controlDict.lookup(START_TIME_VALUE); - break; - default: - time = getFirstFolderName(proc0); - break; + case ControlDict.FIRST_TIME_VALUE: + time = getFirstFolderName(proc0); + break; + case ControlDict.LATEST_TIME_VALUE: + time = getLastFolderName(proc0); + break; + case ControlDict.START_TIME_VALUE: + time = getRealFolderName(proc0, controlDict.lookup(START_TIME_VALUE)); + break; + default: + time = getFirstFolderName(proc0); + break; } logger.info("Start From: " + startFrom + " T: " + time); return time; } + + private static String getRealFolderName(File proc0, String time){ + String[] directories = getDirectories(proc0); + for (String d : directories) { + if(Double.parseDouble(d) == Double.parseDouble(time)){ + return d; + } + } + return time; + } private static String getFirstFolderName(File proc0) { String[] directories = getDirectories(proc0); @@ -283,10 +293,14 @@ public class ZeroFolderUtil { public static String getTimeStepString(String timeStep) { try { - Integer i = Integer.valueOf(timeStep); - return String.valueOf(i); + double d = Double.parseDouble(timeStep); + if (d == (int) d) { + return String.valueOf((int) d); + } else { + return timeStep; + } } catch (NumberFormatException e) { - return timeStep; + return "0"; } } @@ -308,4 +322,5 @@ public class ZeroFolderUtil { } } } + } diff --git a/src/eu/engys/core/project/zero/cellzones/CellZone.java b/src/eu/engys/core/project/zero/cellzones/CellZone.java index 26c6285..71315c5 100644 --- a/src/eu/engys/core/project/zero/cellzones/CellZone.java +++ b/src/eu/engys/core/project/zero/cellzones/CellZone.java @@ -1,34 +1,35 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.zero.cellzones; import java.util.HashSet; import java.util.Set; +import org.apache.commons.lang.builder.EqualsBuilder; +import org.apache.commons.lang.builder.HashCodeBuilder; + import eu.engys.core.dictionary.Dictionary; import eu.engys.util.ui.checkboxtree.LoadableItem; import eu.engys.util.ui.checkboxtree.VisibleItem; @@ -81,7 +82,7 @@ public class CellZone implements VisibleItem, LoadableItem { public boolean isLoaded() { return loaded; } - + @Override public void setLoaded(boolean loaded) { this.loaded = loaded; @@ -123,15 +124,25 @@ public class CellZone implements VisibleItem, LoadableItem { return sb.toString(); } - @Override - public boolean equals(Object obj) { - if (obj instanceof CellZone) { - return ((CellZone) obj).getName().equals(name); - } - return super.equals(obj); - } - public boolean hasType(String key) { return types.contains(key); } + + @Override + public boolean equals(Object obj) { + if (!(obj instanceof CellZone)) { + return false; + } + if (obj == this) { + return true; + } + CellZone fz = (CellZone) obj; + return new EqualsBuilder().append(name, fz.name).isEquals(); + } + + @Override + public int hashCode() { + return new HashCodeBuilder(17, 31).append(name).toHashCode(); + } + } diff --git a/src/eu/engys/core/project/zero/cellzones/CellZoneType.java b/src/eu/engys/core/project/zero/cellzones/CellZoneType.java index f9bc96d..627cd60 100644 --- a/src/eu/engys/core/project/zero/cellzones/CellZoneType.java +++ b/src/eu/engys/core/project/zero/cellzones/CellZoneType.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.zero.cellzones; import eu.engys.core.dictionary.Dictionary; @@ -34,7 +33,8 @@ public interface CellZoneType extends Comparable { public static final String POROUS_KEY = "porous"; public static final String THERMAL_KEY = "thermal"; public static final String HUMIDITY_KEY = "humidity"; - public static final String SLIDING_MESH_KEY = "sliding"; + public static final String DYNAMIC_MESH_KEY = "dynamic"; + public static final String HEAT_EXCHANGER_KEY = "heatExchanger"; public abstract String getKey(); diff --git a/src/eu/engys/core/project/zero/cellzones/CellZones.java b/src/eu/engys/core/project/zero/cellzones/CellZones.java index 866ceef..ead2145 100644 --- a/src/eu/engys/core/project/zero/cellzones/CellZones.java +++ b/src/eu/engys/core/project/zero/cellzones/CellZones.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.zero.cellzones; @@ -76,9 +75,9 @@ public class CellZones extends ArrayList { return false; } - public boolean hasSliding() { + public boolean hasDynamic() { for (CellZone zone : this) { - if (zone.getTypes().contains(CellZoneType.SLIDING_MESH_KEY)) { + if (zone.getTypes().contains(CellZoneType.DYNAMIC_MESH_KEY)) { return true; } } diff --git a/src/eu/engys/core/project/zero/cellzones/CellZones200To210Converter.java b/src/eu/engys/core/project/zero/cellzones/CellZones200To210Converter.java index 3989549..dbc1d89 100644 --- a/src/eu/engys/core/project/zero/cellzones/CellZones200To210Converter.java +++ b/src/eu/engys/core/project/zero/cellzones/CellZones200To210Converter.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.zero.cellzones; import java.util.ArrayList; diff --git a/src/eu/engys/core/project/zero/cellzones/CellZonesBuilder.java b/src/eu/engys/core/project/zero/cellzones/CellZonesBuilder.java index 206d32b..ffd5eb3 100644 --- a/src/eu/engys/core/project/zero/cellzones/CellZonesBuilder.java +++ b/src/eu/engys/core/project/zero/cellzones/CellZonesBuilder.java @@ -1,39 +1,39 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.zero.cellzones; import eu.engys.core.project.Model; +import eu.engys.core.project.constant.MRFProperties; import eu.engys.core.project.state.State; import eu.engys.core.project.system.FvOptions; public interface CellZonesBuilder { public void loadMRFDictionary(Model model); - public void loadMRFDictionary(CellZones cellZones, FvOptions fvOptions); - public void saveMRFDictionary(CellZones cellZones, FvOptions fvOptions); + public void loadMRFDictionary(CellZones cellZones, FvOptions fvOptions, MRFProperties mrfProperties); + public void saveMRFDictionary(CellZones cellZones, FvOptions fvOptions, MRFProperties mrfProperties); public void saveMRFDictionary(Model model); public void loadPorousDictionary(CellZones cellZones, FvOptions fvOptions); @@ -46,5 +46,10 @@ public interface CellZonesBuilder { public void loadThermalDictionary(CellZones cellZones, FvOptions fvOptions, State state); public void saveThermalDictionary(CellZones cellZones, FvOptions fvOptions, State state); public void saveThermalDictionary(Model model); + + public void loadHeatExchangerDictionary(Model model); + public void loadHeatExchangerDictionary(CellZones cellZones, FvOptions fvOptions); + public void saveHeatExchangerDictionary(CellZones cellZones, FvOptions fvOptions); + public void saveHeatExchangerDictionary(Model model); } diff --git a/src/eu/engys/core/project/zero/cellzones/CellZonesReader.java b/src/eu/engys/core/project/zero/cellzones/CellZonesReader.java index 98571a2..428cb79 100644 --- a/src/eu/engys/core/project/zero/cellzones/CellZonesReader.java +++ b/src/eu/engys/core/project/zero/cellzones/CellZonesReader.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.zero.cellzones; @@ -40,6 +39,7 @@ import org.slf4j.LoggerFactory; import eu.engys.core.modules.ApplicationModule; import eu.engys.core.modules.ModulesUtil; import eu.engys.core.project.Model; +import eu.engys.core.project.constant.MRFProperties; import eu.engys.core.project.system.FvOptions; import eu.engys.util.IOUtils; import eu.engys.util.progress.ProgressMonitor; @@ -80,9 +80,11 @@ public class CellZonesReader { private void readCellZoneTypeAndDictionary(CellZones cellZones) { FvOptions fvOptions = model.getProject().getSystemFolder().getFvOptions(); - builder.loadMRFDictionary(cellZones, fvOptions); + MRFProperties mrfProperties = model.getProject().getConstantFolder().getMrfProperties(); + builder.loadMRFDictionary(cellZones, fvOptions, mrfProperties); builder.loadPorousDictionary(cellZones, fvOptions); builder.loadThermalDictionary(cellZones, fvOptions, model.getState()); + builder.loadHeatExchangerDictionary(cellZones, fvOptions); ModulesUtil.updateCellZonesFromModel(modules, cellZones); } @@ -140,13 +142,14 @@ public class CellZonesReader { CellZone cz = new CellZone(zoneName); cz.setName(zoneName); - cz.setVisible(true); +// cz.setVisible(true); + cz.setVisible(false); zones.add(cz); } } if (Integer.parseInt(nZones) != zonesCounter) { - monitor.error(String.format("Number of read patches (%d) is invalid (expected %d).", zonesCounter, nZones), 2); + monitor.error(String.format("Number of read patches (%s) is invalid (expected %s).", zonesCounter, nZones), 2); } } } diff --git a/src/eu/engys/core/project/zero/cellzones/CellZonesUtils.java b/src/eu/engys/core/project/zero/cellzones/CellZonesUtils.java index 317141f..9c48c5e 100644 --- a/src/eu/engys/core/project/zero/cellzones/CellZonesUtils.java +++ b/src/eu/engys/core/project/zero/cellzones/CellZonesUtils.java @@ -1,30 +1,31 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.zero.cellzones; +import static eu.engys.core.project.constant.ConstantFolder.CONSTANT; + public class CellZonesUtils { /* @@ -67,6 +68,7 @@ public class CellZonesUtils { public static final String FIXED_TEMPERATURE_CONSTRAINT_KEY = "fixedTemperatureConstraint"; public static final String EXPONENTIAL_THERMAL_SOURCE_KEY = "exponentialThermalSource"; public static final String SCALAR_SEMI_IMPLICT_SOURCE_KEY = "scalarSemiImplicitSource"; + public static final String SCALAR_FIXED_VALUE_CONSTRAINT_KEY = "scalarFixedValueConstraint"; public static final String SCALAR_EXPLICIT_SET_VALUE_KEY = "scalarExplicitSetValue"; public static final String TEMPERATURE_KEY = "temperature"; public static final String CE_KEY = "Ce"; @@ -77,28 +79,46 @@ public class CellZonesUtils { public static final String PLACE_HOLDER_KEY = "placeHolder"; public static final String H_KEY = "h"; public static final String T_KEY = "T"; + public static final String FIELD_VALUES_KEY = "fieldValues"; public static final String INJECTION_RATE_KEY = "injectionRate"; public static final String INJECTION_RATE_SU_SP_KEY = "injectionRateSuSp"; public static final String SPECIFIC_KEY = "specific"; public static final String UNIFORM_KEY = "uniform"; + /* + * Heat Exchanger + */ + public static final String EFFECTIVENESS_HEAT_EXCHANGER_SOURCE_KEY = "effectivenessHeatExchangerSource"; + public static final String EFFECTIVENESS_HEAT_EXCHANGER_SOURCE_COEFFS_KEY = EFFECTIVENESS_HEAT_EXCHANGER_SOURCE_KEY+"Coeffs"; + public static final String FIELD_NAMES_KEY = "fieldNames"; + public static final String PRIMARY_INLET_T_KEY = "primaryInletT"; + public static final String SECONDARY_INLET_T_KEY = "secondaryInletT"; + public static final String SECONDARY_MASS_FLOW_RATE_KEY = "secondaryMassFlowRate"; + public static final String FACE_ZONE_KEY = "faceZone"; + public static final String OUT_OF_BOUNDS_KEY = "outOfBounds"; + public static final String CLAMP_KEY = "clamp"; + public static final String FILE_NAME_KEY = "fileName"; + public static final String FILE_NAME_VALUE = "heatExchangerTable"; + public static final String FILE_NAME_FILE_VALUE = "\""+CONSTANT+"/"+FILE_NAME_VALUE+"\""; + /* * Humidity */ public static final String W_KEY = "w"; /* - * Sliding + * Dynamic */ - public static final String t0_KEY = "t0"; - public static final String THETA_KEY = "theta"; - public static final String PERIOD_KEY = "period"; - public static final String ABSOLUTE_KEY = "absolute"; - public static final String[] VOLUME_MODE_KEYS = new String[] { ABSOLUTE_KEY, SPECIFIC_KEY }; + // see DynamicMeshDict + /* * OTHER KEYS */ + public static final String PERIOD_KEY = "period"; + public static final String ABSOLUTE_KEY = "absolute"; + public static final String[] VOLUME_MODE_KEYS = new String[] { ABSOLUTE_KEY, SPECIFIC_KEY }; + public static final String COEFFS_KEY = "Coeffs"; public static final String ACTIVE_KEY = "active"; public static final String SELECTION_MODE_KEY = "selectionMode"; diff --git a/src/eu/engys/core/project/zero/cellzones/CellZonesWriter.java b/src/eu/engys/core/project/zero/cellzones/CellZonesWriter.java index c48445d..cfbf53f 100644 --- a/src/eu/engys/core/project/zero/cellzones/CellZonesWriter.java +++ b/src/eu/engys/core/project/zero/cellzones/CellZonesWriter.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.zero.cellzones; @@ -37,11 +36,13 @@ import java.util.regex.Pattern; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import eu.engys.core.dictionary.DefaultElement; import eu.engys.core.dictionary.DictionaryWriter; import eu.engys.core.dictionary.FoamFile; import eu.engys.core.modules.ApplicationModule; import eu.engys.core.modules.ModulesUtil; import eu.engys.core.project.Model; +import eu.engys.core.project.constant.MRFProperties; import eu.engys.core.project.system.FvOptions; import eu.engys.util.IOUtils; import eu.engys.util.progress.ProgressMonitor; @@ -65,12 +66,21 @@ public class CellZonesWriter { public void writeFvOptions(Model model) { FvOptions fvOptions = model.getProject().getSystemFolder().getFvOptions(); + MRFProperties mrfProperties = model.getProject().getConstantFolder().getMrfProperties(); + DefaultElement uLimiter = fvOptions.remove(FvOptions.U_LIMITER_KEY); if(fvOptions != null){ fvOptions.clear(); } + if(mrfProperties != null){ + mrfProperties.clear(); + } + if(uLimiter != null){ + fvOptions.add(uLimiter); + } builder.saveMRFDictionary(model); builder.savePorousDictionary(model); builder.saveThermalDictionary(model); + builder.saveHeatExchangerDictionary(model); ModulesUtil.updateModelFromCellZones(modules); } diff --git a/src/eu/engys/core/project/zero/facezones/FaceZone.java b/src/eu/engys/core/project/zero/facezones/FaceZone.java index a26c15c..e7a365a 100644 --- a/src/eu/engys/core/project/zero/facezones/FaceZone.java +++ b/src/eu/engys/core/project/zero/facezones/FaceZone.java @@ -1,98 +1,109 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.zero.facezones; +import org.apache.commons.lang.builder.EqualsBuilder; +import org.apache.commons.lang.builder.HashCodeBuilder; + import eu.engys.core.dictionary.Dictionary; import eu.engys.util.ui.checkboxtree.LoadableItem; import eu.engys.util.ui.checkboxtree.VisibleItem; public class FaceZone implements VisibleItem, LoadableItem { - private final String originalName; - private String name; - private boolean visible; - private boolean loaded; - private Dictionary dictionary; + private final String originalName; + private String name; + private boolean visible; + private boolean loaded; + private Dictionary dictionary; - public FaceZone(String originalName) { - this.originalName = originalName; - this.name = originalName; - } + public FaceZone(String originalName) { + this.originalName = originalName; + this.name = originalName; + } - public String getOriginalName() { - return originalName; - } + public String getOriginalName() { + return originalName; + } - public String getName() { - return name; - } + public String getName() { + return name; + } - public void setName(String name) { - this.name = name; - } + public void setName(String name) { + this.name = name; + } - @Override - public boolean isVisible() { - return visible; - } + @Override + public boolean isVisible() { + return visible; + } - @Override - public void setVisible(boolean selected) { - this.visible = selected; - } + @Override + public void setVisible(boolean selected) { + this.visible = selected; + } @Override public boolean isLoaded() { return loaded; } - + @Override public void setLoaded(boolean loaded) { this.loaded = loaded; } - public void setDictionary(Dictionary d) { - this.dictionary = d; - } + public void setDictionary(Dictionary d) { + this.dictionary = d; + } - public Dictionary getDictionary() { - return dictionary; - } + public Dictionary getDictionary() { + return dictionary; + } - @Override - public String toString() { - return name + " [" + getName() + ", " + visible + "]"; - } + @Override + public String toString() { + return name + " [" + getName() + ", " + visible + "]"; + } + + @Override + public boolean equals(Object obj) { + if (!(obj instanceof FaceZone)) { + return false; + } + if (obj == this) { + return true; + } + FaceZone fz = (FaceZone) obj; + return new EqualsBuilder().append(name, fz.name).isEquals(); + } + + @Override + public int hashCode() { + return new HashCodeBuilder(17, 31).append(name).toHashCode(); + } - @Override - public boolean equals(Object obj) { - if (obj instanceof FaceZone) { - return ((FaceZone) obj).getName().equals(name); - } - return super.equals(obj); - } } diff --git a/src/eu/engys/core/project/zero/facezones/FaceZones.java b/src/eu/engys/core/project/zero/facezones/FaceZones.java index 9807fce..70f152f 100644 --- a/src/eu/engys/core/project/zero/facezones/FaceZones.java +++ b/src/eu/engys/core/project/zero/facezones/FaceZones.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.zero.facezones; diff --git a/src/eu/engys/core/project/zero/facezones/FaceZonesReader.java b/src/eu/engys/core/project/zero/facezones/FaceZonesReader.java index 3953e81..951cb54 100644 --- a/src/eu/engys/core/project/zero/facezones/FaceZonesReader.java +++ b/src/eu/engys/core/project/zero/facezones/FaceZonesReader.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.zero.facezones; @@ -124,7 +123,7 @@ public class FaceZonesReader { } } if (Integer.parseInt(nZones) != zonesCounter) { - monitor.error(String.format("Number of read patches (%d) is invalid (expected %d).", zonesCounter, nZones), 2); + monitor.error(String.format("Number of read patches (%s) is invalid (expected %s).", zonesCounter, nZones), 2); } } } diff --git a/src/eu/engys/core/project/zero/fields/AbstractInitialisations.java b/src/eu/engys/core/project/zero/fields/AbstractInitialisations.java index 220374b..4fdedf5 100644 --- a/src/eu/engys/core/project/zero/fields/AbstractInitialisations.java +++ b/src/eu/engys/core/project/zero/fields/AbstractInitialisations.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.zero.fields; @@ -33,7 +32,6 @@ import java.util.Map; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import eu.engys.core.dictionary.Dictionary; import eu.engys.core.project.Model; import eu.engys.util.ArchiveUtils; import eu.engys.util.progress.ProgressMonitor; @@ -42,15 +40,20 @@ public abstract class AbstractInitialisations implements Initialisations { private static Logger logger = LoggerFactory.getLogger(AbstractInitialisations.class); - protected Map map = new HashMap<>(); + protected Map map = new HashMap<>(); protected final Model model; public AbstractInitialisations(Model model) { this.model = model; } + + @Override + public void clear(){ + map.clear(); + } - public Dictionary getInitializationFor(String field) { + public Initialisation getInitializationFor(String field) { return map.get(field); } @@ -73,7 +76,7 @@ public abstract class AbstractInitialisations implements Initialisations { } // For test purpouse only! - public Map getMap() { + public Map getMap() { return map; } diff --git a/src/eu/engys/core/project/zero/fields/ArrayInternalField.java b/src/eu/engys/core/project/zero/fields/ArrayInternalField.java index 19fc83b..7022e67 100644 --- a/src/eu/engys/core/project/zero/fields/ArrayInternalField.java +++ b/src/eu/engys/core/project/zero/fields/ArrayInternalField.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.zero.fields; import java.io.File; diff --git a/src/eu/engys/core/project/zero/fields/BoundaryValueInitialisation.java b/src/eu/engys/core/project/zero/fields/BoundaryValueInitialisation.java new file mode 100644 index 0000000..e64bdfc --- /dev/null +++ b/src/eu/engys/core/project/zero/fields/BoundaryValueInitialisation.java @@ -0,0 +1,53 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.core.project.zero.fields; + +import eu.engys.util.bean.AbstractBean; + +public class BoundaryValueInitialisation extends AbstractBean implements Initialisation { + + public static final String PATCH_KEY = "patch"; + private String patch; + + public BoundaryValueInitialisation() {} + + public BoundaryValueInitialisation(String patch) { + this.patch = patch; + } + + public String toString() { + return "Boundary Value"; + } + + public String getPatch() { + return patch; + } + + public void setPatch(String patch) { + firePropertyChange(PATCH_KEY, this.patch, this.patch = patch); + } + + +} diff --git a/src/eu/engys/core/project/zero/fields/CellSetInitialisation.java b/src/eu/engys/core/project/zero/fields/CellSetInitialisation.java new file mode 100644 index 0000000..3f8e8de --- /dev/null +++ b/src/eu/engys/core/project/zero/fields/CellSetInitialisation.java @@ -0,0 +1,68 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.core.project.zero.fields; + +import eu.engys.core.project.geometry.Surface; +import eu.engys.util.bean.AbstractBean; + +public abstract class CellSetInitialisation extends AbstractBean implements Initialisation { + public static final String DEFAULT_VALUE_KEY = "defaultValue"; + + public static class ScalarSurface { + private Surface surface; + private double value; + + public ScalarSurface(Surface surface, double value) { + this.surface = surface; + this.value = value; + } + + public Surface getSurface() { + return surface; + } + + public double getValue() { + return value; + } + } + + public static class VectorSurface { + private Surface surface; + private double[] value; + + public VectorSurface(Surface surface, double[] value) { + this.surface = surface; + this.value = value; + } + + public Surface getSurface() { + return surface; + } + + public double[] getValue() { + return value; + } + } +} diff --git a/src/eu/engys/core/project/zero/fields/DefaultInitialisation.java b/src/eu/engys/core/project/zero/fields/DefaultInitialisation.java new file mode 100644 index 0000000..0e80088 --- /dev/null +++ b/src/eu/engys/core/project/zero/fields/DefaultInitialisation.java @@ -0,0 +1,34 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.core.project.zero.fields; + +import eu.engys.util.bean.AbstractBean; + +public class DefaultInitialisation extends AbstractBean implements Initialisation { + + public String toString() { + return "Default"; + } +} diff --git a/src/eu/engys/core/project/zero/fields/Field.java b/src/eu/engys/core/project/zero/fields/Field.java index c6fc81b..2f51937 100644 --- a/src/eu/engys/core/project/zero/fields/Field.java +++ b/src/eu/engys/core/project/zero/fields/Field.java @@ -1,35 +1,37 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.zero.fields; +import static eu.engys.core.project.zero.fields.Fields.U; + import java.io.File; import java.util.Arrays; import eu.engys.core.dictionary.Dictionary; +import eu.engys.core.project.state.State; import eu.engys.util.progress.ProgressMonitor; public class Field { @@ -40,43 +42,11 @@ public class Field { public static final String DIMENSIONS = "dimensions"; public static final String INTERNAL_FIELD = "internalField"; - public enum FieldType { - - SCALAR, VECTOR, POINT; - - public static FieldType getType(String string) { - switch (string) { - case "scalar": - return SCALAR; - case "vector": - return VECTOR; - case "point": - return POINT; - default: - return null; - } - } - - public boolean isScalar() { - return this == SCALAR; - } - - public boolean isVector() { - return this == VECTOR; - } - - public boolean isPoint() { - return this == POINT; - } - } - private InternalField internalField; private Dictionary boundaryField; - - private FieldType fieldType; private String[] initialisationMethods; - private Dictionary initialisation = new Dictionary(INITIALISATION_KEY); + private Initialisation initialisation = new DefaultInitialisation(); private Dictionary definition = new Dictionary(FIELD_DEFINITION_KEY); private String name; private String dimensions; @@ -106,25 +76,17 @@ public class Field { this.name = name; } - public String getInitialisationType() { - return initialisation.lookup(Dictionary.TYPE); - } - - public FieldType getFieldType() { - return fieldType; - } - - public void setFieldType(FieldType fieldType) { - this.fieldType = fieldType; - } - - public Dictionary getInitialisation() { + public Initialisation getInitialisation() { return initialisation; } - public void setInitialisation(Dictionary initialisation) { + public void setInitialisation(Initialisation initialisation) { this.initialisation = initialisation; } + + public boolean isScalar(){ + return !name.startsWith(U); + } public void setInitialisationMethods(String[] initMethods) { this.initialisationMethods = initMethods; @@ -200,14 +162,11 @@ public class Field { if (field.dimensions != null) { setDimensions(field.dimensions); } - if (field.fieldType != null) { - setFieldType(field.fieldType); - } if (field.initialisation != null) { // if (this.initialisation != null) { // this.initialisation.merge(field.initialisation); // } else { - setInitialisation(new Dictionary(field.initialisation)); + setInitialisation(field.initialisation); // } } if (field.initialisationMethods != null) { @@ -218,12 +177,35 @@ public class Field { } setVisible(field.visible); - + } + + public double getInternalFieldScalarValue(State state) { + if (state.isCompressible() || state.isBuoyant()) { + if (getInternalField() instanceof ScalarInternalField) { + return ((ScalarInternalField) getInternalField()).getValue()[0][0]; + } else { + return 0; + } + } else { + return 0; + } + } + + public double[] getInternalFieldArrayValue(State state) { + if (state.isCompressible() || state.isBuoyant()) { + if (getInternalField() instanceof ArrayInternalField) { + return ((ArrayInternalField) getInternalField()).getValue()[0]; + } else { + return new double[] { 0, 0, 0 }; + } + } else { + return new double[] { 0, 0, 0 }; + } } @Override public String toString() { - return name + " " + fieldType + " " + Arrays.toString(initialisationMethods) + " " + initialisation + definition; + return name + " " + Fields.getFieldTypeByName(name) + " " + Arrays.toString(initialisationMethods) + " " + initialisation + definition; } public static void main(String[] args) { diff --git a/src/eu/engys/core/project/zero/fields/FieldFilter.java b/src/eu/engys/core/project/zero/fields/FieldFilter.java index e289bfd..65157c1 100644 --- a/src/eu/engys/core/project/zero/fields/FieldFilter.java +++ b/src/eu/engys/core/project/zero/fields/FieldFilter.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.zero.fields; public interface FieldFilter { diff --git a/src/eu/engys/core/project/zero/fields/FieldReader.java b/src/eu/engys/core/project/zero/fields/FieldReader.java index a6289ee..bb53f83 100644 --- a/src/eu/engys/core/project/zero/fields/FieldReader.java +++ b/src/eu/engys/core/project/zero/fields/FieldReader.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.zero.fields; import static eu.engys.core.project.zero.fields.Fields.ALPHA; diff --git a/src/eu/engys/core/project/zero/fields/FieldType.java b/src/eu/engys/core/project/zero/fields/FieldType.java new file mode 100644 index 0000000..e8ab9b9 --- /dev/null +++ b/src/eu/engys/core/project/zero/fields/FieldType.java @@ -0,0 +1,55 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.core.project.zero.fields; + +public enum FieldType { + + SCALAR, VECTOR, POINT; + + public static FieldType getType(String string) { + switch (string) { + case "scalar": + return SCALAR; + case "vector": + return VECTOR; + case "point": + return POINT; + default: + return null; + } + } + + public boolean isScalar() { + return this == SCALAR; + } + + public boolean isVector() { + return this == VECTOR; + } + + public boolean isPoint() { + return this == POINT; + } +} \ No newline at end of file diff --git a/src/eu/engys/core/project/zero/fields/FieldWriter.java b/src/eu/engys/core/project/zero/fields/FieldWriter.java index ba5fa91..de37d24 100644 --- a/src/eu/engys/core/project/zero/fields/FieldWriter.java +++ b/src/eu/engys/core/project/zero/fields/FieldWriter.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.zero.fields; import java.io.File; diff --git a/src/eu/engys/core/project/zero/fields/Fields.java b/src/eu/engys/core/project/zero/fields/Fields.java index 0ce26f6..002efce 100644 --- a/src/eu/engys/core/project/zero/fields/Fields.java +++ b/src/eu/engys/core/project/zero/fields/Fields.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.zero.fields; import java.util.LinkedHashMap; @@ -33,43 +32,74 @@ import eu.engys.core.project.state.State; public class Fields extends LinkedHashMap { - public static final String SMOKE = "smoke"; - public static final String DT_SMOKE = "Dtsmoke"; - public static final String CO2 = "CO2"; - public static final String DT_CO2 = "DtCO2"; - public static final String AOA = "AoA"; - public static final String DT_AOA = "DtAoA"; - public static final String W = "w"; - public static final String DT_W = "Dtw"; + public static final String U = "U"; + public static final String P = "p"; + public static final String P_RGH = "p_rgh"; public static final String T = "T"; + public static final String K = "k"; + public static final String OMEGA = "omega"; + public static final String EPSILON = "epsilon"; + public static final String NU_TILDA = "nuTilda"; + public static final String NUT = "nut"; + public static final String MUT = "mut"; + public static final String RHO = "rho"; public static final String MU_SGS = "muSgs"; public static final String ALPHA_1 = "alpha1"; public static final String ALPHA_SGS = "alphaSgs"; public static final String ALPHA_T = "alphat"; public static final String ALPHA_S = "alphas"; - public static final String NU_TILDA = "nuTilda"; - public static final String EPSILON = "epsilon"; - public static final String OMEGA = "omega"; - public static final String K = "k"; - public static final String P_RGH = "p_rgh"; - public static final String P = "p"; - public static final String U = "U"; public static final String IDEFAULT = "IDefault"; public static final String NU_SGS = "nuSgs"; - public static final String NUT = "nut"; - public static final String MUT = "mut"; - public static final String RHO = "rho"; public static final String ILAMBDA = "ILambda"; - public static final String FINAL = "Final"; - public static final String ALPHA = "alpha"; public static final String ETA = "eta"; + public static final String FINAL = "Final"; + + public static final String P_CORR = "pcorr"; + public static final String POINT_MOTION_U = "pointMotionU"; + public static final String POINT_DISPLACEMENT = "pointDisplacement"; + public static final String CELL_MOTION_U = "cellMotionU"; + public static final String CELL_DISPLACEMENT = "cellDisplacement"; + + /* + * Passive scalars + */ + public static final String AOA = "AoA"; + public static final String D_AOA = "DAoA"; + public static final String DT_AOA = "DtAoA"; + public static final String SCT_AOA = "SctAoA"; + + public static final String CO2 = "CO2"; + public static final String D_CO2 = "DCO2"; + public static final String DT_CO2 = "DtCO2"; + public static final String SCT_CO2 = "SctCO2"; + + public static final String SMOKE = "smoke"; + public static final String D_SMOKE = "Dsmoke"; + public static final String DT_SMOKE = "Dtsmoke"; + public static final String SCT_SMOKE = "Sctsmoke"; + + public static final String W = "w"; + public static final String D_W = "Dw"; + public static final String DT_W = "Dtw"; + public static final String SCT_W = "Sctw"; + public static final String CP_W = "Cpw"; private Fields[] parallelFields; public static final String EDITABLE_FIELDS[] = new String[] { U, P, P_RGH, K, OMEGA, EPSILON, NU_TILDA, T, W, AOA, CO2, SMOKE }; private static final String PASSIVE_SCALARS[] = new String[] { W, AOA, CO2, SMOKE }; + public static FieldType getFieldTypeByName(String name) { + if (name.startsWith(U) || name.equals(POINT_DISPLACEMENT)) { + return FieldType.VECTOR; + } else if (name.equals(POINT_MOTION_U)) { + return FieldType.POINT; + } else { + return FieldType.SCALAR; + } + } + public List listFields(FieldFilter filter) { List list = new LinkedList(); for (Field field : orderedFields()) { @@ -105,6 +135,24 @@ public class Fields extends LinkedHashMap { return list; } + public List orderedScalarFields() { + List list = new LinkedList(); + for (Field f : orderedFields()) { + if (f.isScalar()) { + list.add(f); + } + } + return list; + } + + public List orderedFieldsScalarNames() { + List list = new LinkedList<>(); + for (Field field : orderedScalarFields()) { + list.add(field.getName()); + } + return list; + } + public List orderedFieldsNames() { List list = new LinkedList<>(); for (Field field : orderedFields()) { @@ -167,6 +215,30 @@ public class Fields extends LinkedHashMap { } } + public boolean hasCellSetInitialisationField() { + for (Field f : values()) { + if (f.getInitialisation() instanceof CellSetInitialisation) { + return true; + } + } + return false; + } + + public boolean hasPotentialFlowInitialisationField() { + Field uField = get(Fields.U); + if (uField != null) { + return uField.getInitialisation() instanceof PotentialFlowInitialisation; + } + return false; + } + + public boolean hasInitialiseUBCsField() { + if(hasPotentialFlowInitialisationField()){ + return ((PotentialFlowInitialisation)get(Fields.U).getInitialisation()).isInitUBCS(); + } + return false; + } + @Override public void clear() { super.clear(); @@ -229,4 +301,23 @@ public class Fields extends LinkedHashMap { } } } + + public void resetInternalFields() { + _resetInternalFields(this); + if (parallelFields != null) { + for (Fields fields : parallelFields) { + _resetInternalFields(fields); + } + } + } + + private void _resetInternalFields(Fields fields) { + for (Field field : fields.values()) { + if (field.getName().equals(Fields.U)) { + field.setInternalField(new ArrayInternalField(new double[3])); + } else { + field.setInternalField(new ScalarInternalField(0)); + } + } + } } diff --git a/src/eu/engys/core/project/zero/fields/FieldsDefaults.java b/src/eu/engys/core/project/zero/fields/FieldsDefaults.java index 477d1be..c5d14ee 100644 --- a/src/eu/engys/core/project/zero/fields/FieldsDefaults.java +++ b/src/eu/engys/core/project/zero/fields/FieldsDefaults.java @@ -1,34 +1,37 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.zero.fields; +import static eu.engys.core.dictionary.Dictionary.TYPE; +import static eu.engys.core.dictionary.Dictionary.VALUE; import static eu.engys.core.project.constant.TurbulenceProperties.FIELD_MAPS_KEY; -import static eu.engys.core.project.constant.TurbulenceProperties.LES; -import static eu.engys.core.project.constant.TurbulenceProperties.RAS; +import static eu.engys.core.project.constant.TurbulenceProperties.LES_KEY; +import static eu.engys.core.project.constant.TurbulenceProperties.RAS_KEY; +import static eu.engys.core.project.zero.patches.BoundaryType.CYCLIC_AMI_KEY; +import java.io.File; import java.util.HashMap; import java.util.Map; @@ -39,15 +42,15 @@ import eu.engys.core.dictionary.Dictionary; import eu.engys.core.dictionary.FieldElement; import eu.engys.core.project.defaults.DefaultsProvider; import eu.engys.core.project.state.State; -import eu.engys.core.project.zero.fields.Field.FieldType; import eu.engys.core.project.zero.patches.BoundaryType; import eu.engys.core.project.zero.patches.Patch; import eu.engys.core.project.zero.patches.Patches; +import eu.engys.util.progress.SilentMonitor; public class FieldsDefaults { private static final Logger logger = LoggerFactory.getLogger(FieldsDefaults.class); - private static Map oldInitialisations = new HashMap(); + private static Map oldInitialisations = new HashMap<>(); private DefaultsProvider defaults; @@ -70,31 +73,31 @@ public class FieldsDefaults { private static void applySavedInitialization(Field field) { if (oldInitialisations.containsKey(field.getName())) { - Dictionary initialisation = oldInitialisations.get(field.getName()); - field.setInitialisation(new Dictionary(initialisation)); + Initialisation initialisation = oldInitialisations.get(field.getName()); + field.setInitialisation(initialisation); } } - public static Fields loadFieldsFromDefaults(State state, DefaultsProvider defaults, Patches patches, String region) { - return new FieldsDefaults(defaults).loadDefaultFields(state, patches, region); + public static Fields loadFieldsFromDefaults(File baseDir, State state, DefaultsProvider defaults, Patches patches, String region) { + return new FieldsDefaults(defaults).loadDefaultFields(baseDir, state, patches, region); } - public static Field loadFieldFromDefaults(String name, DefaultsProvider defaults, Patches patches) { - return new FieldsDefaults(defaults).loadDefaultField(name, name, patches); + public static Field loadFieldFromDefaults(File baseDir, State state, String name, DefaultsProvider defaults, Patches patches) { + return new FieldsDefaults(defaults).loadDefaultField(baseDir, state, name, name, patches); } - private Field loadDefaultField(String name, String value, Patches patches) { - return newFieldFromDefaults(name, value, patches); + private Field loadDefaultField(File baseDir, State state, String name, String value, Patches patches) { + return newFieldFromDefaults(baseDir, state, name, value, patches); } - private Fields loadDefaultFields(State state, Patches patches, String region) { + private Fields loadDefaultFields(File baseDir, State state, Patches patches, String region) { Dictionary defaultFields = getDefaultFieldMaps(state, region); - Fields fields = addNewFields(defaultFields, patches); + Fields fields = addNewFields(baseDir, state, defaultFields, patches); if (patches.getParallelPatches() != null) { Fields[] parallelFields = new Fields[patches.getParallelPatches().length]; for (int i = 0; i < parallelFields.length; i++) { - parallelFields[i] = addNewFields(defaultFields, patches); + parallelFields[i] = addNewFields(baseDir, state, defaultFields, patches); } fields.setParallelFields(parallelFields); } @@ -103,10 +106,10 @@ public class FieldsDefaults { } private Dictionary getDefaultFieldMaps(State state, String region) { - Dictionary fieldMaps = new Dictionary(FIELD_MAPS_KEY); - fieldMaps.merge(getTurbulenceFieldMaps(state, defaults, region)); - fieldMaps.merge(getStateFieldMaps(state, defaults, region)); - return fieldMaps; + Dictionary fieldsMap = new Dictionary(FIELD_MAPS_KEY); + fieldsMap.merge(getTurbulenceFieldMaps(state, defaults, region)); + fieldsMap.merge(getStateFieldMaps(state, defaults, region)); + return fieldsMap; } private Dictionary getStateFieldMaps(State state, DefaultsProvider defaults, String region) { @@ -117,7 +120,7 @@ public class FieldsDefaults { if (state.getTurbulenceModel() != null && !state.getFlow().isNone() && !state.getMethod().isNone() && !state.getSolverType().isNone()) { String modelName = state.getTurbulenceModel().getName(); String compType = state.getSolverType().isCoupled() ? "coupledIncompressible" : state.isCompressible() ? "compressible" : "incompressible"; - String turbType = state.isLES() ? LES : RAS; + String turbType = state.isLES() ? LES_KEY : RAS_KEY; String modelCoeffs = modelName + "Coeffs"; Dictionary fieldMaps = new Dictionary(FIELD_MAPS_KEY); @@ -127,8 +130,8 @@ public class FieldsDefaults { if (tpp.subDict(compType + turbType).isDictionary(modelCoeffs)) { Dictionary defCoeff = tpp.subDict(compType + turbType).subDict(modelCoeffs); if (region != null) { - if (defCoeff.found(FIELD_MAPS_KEY+"."+region)) { - fieldMaps.merge(defCoeff.subDict(FIELD_MAPS_KEY+"."+region)); + if (defCoeff.found(FIELD_MAPS_KEY + "." + region)) { + fieldMaps.merge(defCoeff.subDict(FIELD_MAPS_KEY + "." + region)); } } else { if (defCoeff.found(FIELD_MAPS_KEY)) { @@ -142,13 +145,13 @@ public class FieldsDefaults { return new Dictionary(""); } - private Fields addNewFields(Dictionary defaultFieldsMap, Patches patches) { + private Fields addNewFields(File baseDir, State state, Dictionary defaultFieldsMap, Patches patches) { Fields fields = new Fields(); for (FieldElement element : defaultFieldsMap.getFields()) { String name = element.getName(); String value = element.getValue(); - Field field = newFieldFromDefaults(name, value, patches); + Field field = newFieldFromDefaults(baseDir, state, name, value, patches); applySavedInitialization(field); @@ -157,23 +160,24 @@ public class FieldsDefaults { return fields; } - private Field newFieldFromDefaults(String name, String value, Patches patches) { + private Field newFieldFromDefaults(File baseDir, State state, String name, String value, Patches patches) { Dictionary defaultsDictionary = getDefaultsDictionary(value); Field field = new Field(name); - if (defaultsDictionary.found("initialisation")) { - field.setInitialisation(new Dictionary(defaultsDictionary.subDict("initialisation"))); - } if (defaultsDictionary.found("allowedFieldInitialisationMethods")) { field.setInitialisationMethods(defaultsDictionary.lookupArray("allowedFieldInitialisationMethods")); } if (defaultsDictionary.found("fieldDefinition")) { Dictionary definition = new Dictionary(defaultsDictionary.subDict("fieldDefinition")); field.setDefinition(definition); - field.setFieldType(FieldType.getType(definition.lookup(Dictionary.TYPE))); field.setDimensions(definition.lookup("dimensions")); field.setInternalField("internalField " + definition.lookup("internalField")); - field.setBoundaryField(getBoundaryConditionsFromDefaults(field.getFieldType(), patches, definition)); + field.setBoundaryField(getBoundaryConditionsFromDefaults(Fields.getFieldTypeByName(field.getName()), patches, definition)); + } + if (defaultsDictionary.found("initialisation")) { + LoadSaveInitialisation loader = new LoadSaveInitialisation(baseDir, state, new SilentMonitor()); + Initialisation initialisation = loader.load(defaultsDictionary.subDict("initialisation"), Fields.getFieldTypeByName(field.getName())); + field.setInitialisation(initialisation); } return field; @@ -199,7 +203,7 @@ public class FieldsDefaults { } private static Dictionary getDefaultBoundaryCondition(FieldType fieldType, Dictionary regionDefaults, Patch patch) { - String patchType = patch.getPhisicalType() == BoundaryType.OPENING ? BoundaryType.PATCH_KEY : patch.getPhisicalType().getKey(); + String patchType = patch.getPhysicalType() == BoundaryType.OPENING ? BoundaryType.PATCH_KEY : patch.getPhysicalType().getKey(); String patchName = patch.getName(); if (regionDefaults.found(patchType)) { @@ -207,14 +211,14 @@ public class FieldsDefaults { Dictionary fieldPatch = new Dictionary(patchName); fieldPatch.merge(defaultDictionary); return fieldPatch; - } else if (patch.getPhisicalType().isCyclicAMI()) { + } else if (patch.getPhysicalType().isCyclicAMI()) { Dictionary fieldPatch = new Dictionary(patchName); - fieldPatch.add(Dictionary.TYPE, BoundaryType.CYCLIC_AMI_KEY); - fieldPatch.add(Dictionary.VALUE, fieldType == FieldType.SCALAR ? "uniform 0" : "uniform (0 0 0)"); + fieldPatch.add(TYPE, CYCLIC_AMI_KEY); + fieldPatch.add(VALUE, fieldType == FieldType.SCALAR ? "uniform 0" : "uniform (0 0 0)"); return fieldPatch; } else { Dictionary fieldPatch = new Dictionary(patchName); - fieldPatch.add(Dictionary.TYPE, patchType); + fieldPatch.add(TYPE, patchType); return fieldPatch; } } @@ -224,11 +228,11 @@ public class FieldsDefaults { String fieldName = field.getName(); try { - if(field.getDefinition() != null && !field.getDefinition().isEmpty()){ + if (field.getDefinition() != null && !field.getDefinition().isEmpty()) { Dictionary boundaryField = field.getBoundaryField(); Dictionary regionDefaults = field.getDefinition().subDict("boundaryConditions").subDict("regionDefaults"); - - Dictionary defaultDictionary = getDefaultBoundaryCondition(field.getFieldType(), regionDefaults, patch); + + Dictionary defaultDictionary = getDefaultBoundaryCondition(Fields.getFieldTypeByName(field.getName()), regionDefaults, patch); if (boundaryField.found(patchName) && !fieldName.equals("U")) { Dictionary fieldPatch = boundaryField.subDict(patchName); fieldPatch.clear(); diff --git a/src/eu/engys/core/project/zero/fields/FieldsReader.java b/src/eu/engys/core/project/zero/fields/FieldsReader.java index 2b443b8..c458b12 100644 --- a/src/eu/engys/core/project/zero/fields/FieldsReader.java +++ b/src/eu/engys/core/project/zero/fields/FieldsReader.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.zero.fields; import java.io.File; @@ -34,10 +33,11 @@ import org.slf4j.LoggerFactory; import eu.engys.core.dictionary.Dictionary; import eu.engys.util.progress.ProgressMonitor; +import eu.engys.util.ui.ExecUtil; public class FieldsReader { - private static final Logger logger = LoggerFactory.getLogger(FieldsReader.class); + private static final Logger logger = LoggerFactory.getLogger(Fields.class); private Initialisations initialisations; private ProgressMonitor monitor; @@ -48,26 +48,40 @@ public class FieldsReader { } public Fields read(final Set fieldNames, File... zeroDirs) { - Fields fields = creteNewFields(zeroDirs); + Fields fields = creteNewFields(zeroDirs.length); - Fields[] parallelFields = fields.getParallelFields(); + final Fields[] parallelFields = fields.getParallelFields(); int total = zeroDirs.length * fieldNames.size(); monitor.setCurrent("Reading fields", 0, total, 1); + + _read(fieldNames, parallelFields, zeroDirs); - for (int i = 0; i < parallelFields.length; i++) { - final Fields pFields = parallelFields[i]; - final File zeroDir = zeroDirs[i]; - readFields(pFields, fieldNames, zeroDir); - } copyFields(parallelFields[0], fields); return fields; } - private Fields creteNewFields(File... zeroDirs) { + public void _read(final Set fieldNames, final Fields[] parallelFields, File... zeroDirs) { + Runnable[] runnables = new Runnable[zeroDirs.length]; + for (int i = 0; i < zeroDirs.length; i++) { + final Fields pFields = parallelFields[i]; + final File zeroDir = zeroDirs[i]; + + runnables[i] = new Runnable() { + @Override + public void run() { + readFields(pFields, fieldNames, zeroDir); + } + }; + } + ExecUtil.execSerial(runnables); +// ExecUtil.execParallelAndWait(runnables); + } + + private Fields creteNewFields(int numberOfFields) { Fields fields = new Fields(); - Fields[] parallelFields = new Fields[zeroDirs.length]; + Fields[] parallelFields = new Fields[numberOfFields]; for (int i = 0; i < parallelFields.length; i++) { parallelFields[i] = new Fields(); } @@ -77,13 +91,14 @@ public class FieldsReader { } private void readFields(Fields fields, Set fieldNames, File zeroDir) { - logger.debug("----------Reading fields from {}", zeroDir); + logger.info("READ: Fields from {}", zeroDir); for (String fieldName : fieldNames) { fields.put(fieldName, new Field(fieldName)); } if (initialisations != null) { + initialisations.clear(); for (int i = 0; i < fields.size(); i++) { Field field = new ArrayList<>(fields.values()).get(i); initialisations.readInitialisationFromFile(field); @@ -98,9 +113,8 @@ public class FieldsReader { Field target = new Field(source.getName()); target.setDefinition(new Dictionary(source.getDefinition())); target.setDimensions(source.getDimensions()); - target.setInitialisation(new Dictionary(source.getInitialisation())); + target.setInitialisation(source.getInitialisation()); target.setInitialisationMethods(source.getInitialisationMethods()); - target.setFieldType(source.getFieldType()); target.setInternalField(source.getInternalField()); targets.put(target.getName(), target); diff --git a/src/eu/engys/core/project/zero/fields/FieldsWriter.java b/src/eu/engys/core/project/zero/fields/FieldsWriter.java index e8ac8c5..b696071 100644 --- a/src/eu/engys/core/project/zero/fields/FieldsWriter.java +++ b/src/eu/engys/core/project/zero/fields/FieldsWriter.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.zero.fields; import java.io.File; @@ -72,7 +71,7 @@ public class FieldsWriter { }; } ExecUtil.execSerial(runnables); - // ExecUtil.execInParallelAndWait(runnables); +// ExecUtil.execParallelAndWait(runnables); } private void _write(Fields fields, final File zeroDir) { @@ -80,7 +79,7 @@ public class FieldsWriter { logger.info("WRITE: Fields -> none", 2); } else { bufferInternalFields(fields, zeroDir); - ZeroFolderUtil.clearFiles(zeroDir); + ZeroFolderUtil.clearFiles(fields.orderedFieldsNames(), zeroDir); writeFields(zeroDir, fields); } } @@ -97,7 +96,7 @@ public class FieldsWriter { }; } ExecUtil.execSerial(runnablesForBuffer); - // ExecUtil.execInParallelAndWait(runnablesForBuffer); +// ExecUtil.execParallelAndWait(runnablesForBuffer); } private void writeFields(final File zeroDir, Fields fields) { @@ -112,6 +111,6 @@ public class FieldsWriter { }; } ExecUtil.execSerial(runnablesForWrite); - // ExecUtil.execInParallelAndWait(runnablesForWrite); +// ExecUtil.execParallelAndWait(runnablesForWrite); } } diff --git a/src/eu/engys/core/project/zero/fields/FixedScalarInitialisation.java b/src/eu/engys/core/project/zero/fields/FixedScalarInitialisation.java new file mode 100644 index 0000000..abad957 --- /dev/null +++ b/src/eu/engys/core/project/zero/fields/FixedScalarInitialisation.java @@ -0,0 +1,53 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.core.project.zero.fields; + +import eu.engys.util.bean.AbstractBean; + +public class FixedScalarInitialisation extends AbstractBean implements Initialisation { + + public static final String VALUE_KEY = "value"; + private double value = 0; + + public FixedScalarInitialisation() {} + + public FixedScalarInitialisation(double value) { + this.value = value; + } + + public double getValue() { + return value; + } + + public void setValue(double value) { + firePropertyChange(VALUE_KEY, this.value, this.value = value); + } + + public String toString() { + return "Fixed Value"; + } + + +} diff --git a/src/eu/engys/core/project/zero/fields/FixedVectorInitialisation.java b/src/eu/engys/core/project/zero/fields/FixedVectorInitialisation.java new file mode 100644 index 0000000..8215979 --- /dev/null +++ b/src/eu/engys/core/project/zero/fields/FixedVectorInitialisation.java @@ -0,0 +1,51 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.core.project.zero.fields; + +import eu.engys.util.bean.AbstractBean; + +public class FixedVectorInitialisation extends AbstractBean implements Initialisation { + + public static final String VALUE_KEY = "value"; + public static final double[] DEFAULT_VALUE = {0,0,0}; + private double[] value = DEFAULT_VALUE; + + public FixedVectorInitialisation() {} + + public FixedVectorInitialisation(double v1, double v2, double v3) { + this.value = new double[]{v1, v2, v3}; + } + + public double[] getValue() { + return value; + } + public void setValue(double[] value) { + firePropertyChange(VALUE_KEY, this.value, this.value = value); + } + + public String toString() { + return "Fixed Value"; + } +} diff --git a/src/eu/engys/core/project/zero/fields/Initialisation.java b/src/eu/engys/core/project/zero/fields/Initialisation.java new file mode 100644 index 0000000..45d6c25 --- /dev/null +++ b/src/eu/engys/core/project/zero/fields/Initialisation.java @@ -0,0 +1,29 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.core.project.zero.fields; + +public interface Initialisation { + +} diff --git a/src/eu/engys/core/project/zero/fields/Initialisations.java b/src/eu/engys/core/project/zero/fields/Initialisations.java index dcecf17..3378682 100644 --- a/src/eu/engys/core/project/zero/fields/Initialisations.java +++ b/src/eu/engys/core/project/zero/fields/Initialisations.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.zero.fields; @@ -32,18 +31,27 @@ import eu.engys.util.progress.ProgressMonitor; public interface Initialisations { + public static final String TYPE_KEY = "type"; public static final String DEFAULT_KEY = "default"; public static final String FIXED_VALUE_KEY = "fixedValue"; public static final String POTENTIAL_FLOW_KEY = "potentialFlow"; public static final String PRANDTL_KEY = "Prandtl"; public static final String TURBULENT_IL_KEY = "turbulentIL"; + public static final String I_KEY = "I"; + public static final String L_KEY = "L"; + public static final String UREF_KEY = "Uref"; public static final String BOUNDARY_VALUE_KEY = "boundaryValue"; public static final String CELL_SET_KEY = "cellSet"; + public static final String DEFAULT_VALUE_KEY = "defaultValue"; public static final String INITIALISE_UBCS_KEY = "initialiseUBCs"; + public static final String RHO_REF_KEY = "rhoRef"; public static final String PATCH_KEY = "patch"; + public static final String SET_SOURCES_KEY = "setSources"; public void readInitialisationFromFile(Field field); public void loadInitialisation(File zeroDir, Field field, ProgressMonitor monitor); + public void clear(); + } diff --git a/src/eu/engys/core/project/zero/fields/InternalField.java b/src/eu/engys/core/project/zero/fields/InternalField.java index 59cf2db..b9432d3 100644 --- a/src/eu/engys/core/project/zero/fields/InternalField.java +++ b/src/eu/engys/core/project/zero/fields/InternalField.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.zero.fields; import java.io.File; diff --git a/src/eu/engys/core/project/zero/fields/LoadSaveInitialisation.java b/src/eu/engys/core/project/zero/fields/LoadSaveInitialisation.java new file mode 100644 index 0000000..713b286 --- /dev/null +++ b/src/eu/engys/core/project/zero/fields/LoadSaveInitialisation.java @@ -0,0 +1,241 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.core.project.zero.fields; + +import static eu.engys.core.dictionary.Dictionary.TYPE; +import static eu.engys.core.dictionary.Dictionary.VALUE; +import static eu.engys.core.dictionary.DictionaryBuilder.newDictionary; +import static eu.engys.core.project.system.FvSolution.N_NON_ORTHOGONAL_CORRECTORS_KEY; +import static eu.engys.core.project.zero.fields.Field.INITIALISATION_KEY; +import static eu.engys.core.project.zero.fields.Initialisations.BOUNDARY_VALUE_KEY; +import static eu.engys.core.project.zero.fields.Initialisations.CELL_SET_KEY; +import static eu.engys.core.project.zero.fields.Initialisations.DEFAULT_KEY; +import static eu.engys.core.project.zero.fields.Initialisations.DEFAULT_VALUE_KEY; +import static eu.engys.core.project.zero.fields.Initialisations.FIXED_VALUE_KEY; +import static eu.engys.core.project.zero.fields.Initialisations.INITIALISE_UBCS_KEY; +import static eu.engys.core.project.zero.fields.Initialisations.I_KEY; +import static eu.engys.core.project.zero.fields.Initialisations.L_KEY; +import static eu.engys.core.project.zero.fields.Initialisations.PATCH_KEY; +import static eu.engys.core.project.zero.fields.Initialisations.POTENTIAL_FLOW_KEY; +import static eu.engys.core.project.zero.fields.Initialisations.PRANDTL_KEY; +import static eu.engys.core.project.zero.fields.Initialisations.RHO_REF_KEY; +import static eu.engys.core.project.zero.fields.Initialisations.SET_SOURCES_KEY; +import static eu.engys.core.project.zero.fields.Initialisations.TURBULENT_IL_KEY; +import static eu.engys.core.project.zero.fields.Initialisations.TYPE_KEY; +import static eu.engys.core.project.zero.fields.Initialisations.UREF_KEY; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; + +import eu.engys.core.dictionary.Dictionary; +import eu.engys.core.dictionary.ListField; +import eu.engys.core.project.geometry.Surface; +import eu.engys.core.project.state.State; +import eu.engys.core.project.zero.fields.CellSetInitialisation.ScalarSurface; +import eu.engys.core.project.zero.fields.CellSetInitialisation.VectorSurface; +import eu.engys.util.progress.ProgressMonitor; + +public class LoadSaveInitialisation { + + private ProgressMonitor monitor; + private File baseDir; + private State state; + + public LoadSaveInitialisation(File baseDir, State state, ProgressMonitor monitor) { + this.baseDir = baseDir; + this.state = state; + this.monitor = monitor; + } + + public Initialisation load(Dictionary dict, FieldType fieldType) { + // System.out.println("LoadSaveInitialisation.load() " + fieldType); + String type = dict.lookup(TYPE_KEY); + switch (type) { + case POTENTIAL_FLOW_KEY: + PotentialFlowInitialisation pfi = new PotentialFlowInitialisation(); + if (dict.found(INITIALISE_UBCS_KEY)) { + pfi.setInitUBCS(dict.lookupBoolean(INITIALISE_UBCS_KEY)); + } + if (dict.found(RHO_REF_KEY)) { + pfi.setRhoRef(dict.lookupDouble(RHO_REF_KEY)); + } + if (dict.found(N_NON_ORTHOGONAL_CORRECTORS_KEY)) { + pfi.setnNonOrthogonalCorrectors(dict.lookupInt(N_NON_ORTHOGONAL_CORRECTORS_KEY)); + } + return pfi; + + case BOUNDARY_VALUE_KEY: + BoundaryValueInitialisation bvi = new BoundaryValueInitialisation(); + if (dict.found(PATCH_KEY)) { + bvi.setPatch(dict.lookup(PATCH_KEY)); + } + return bvi; + + case PRANDTL_KEY: + return new PrandtlInitialisation(); + + case TURBULENT_IL_KEY: + TurbulentILInitialisation ti = new TurbulentILInitialisation(); + if (dict.found(I_KEY)) { + ti.setI(dict.lookupDouble(I_KEY)); + } + if (dict.found(L_KEY)) { + ti.setL(dict.lookupDouble(L_KEY)); + } + if (dict.found(UREF_KEY)) { + ti.setUref(dict.lookupDouble(UREF_KEY)); + } + return ti; + + case DEFAULT_KEY: + return new DefaultInitialisation(); + + case FIXED_VALUE_KEY: + if (fieldType == FieldType.SCALAR) { + FixedScalarInitialisation init = new FixedScalarInitialisation(); + if (dict.found(VALUE)) { + init.setValue(dict.lookupDoubleUniform(VALUE)); + } + return init; + } else if (fieldType == FieldType.VECTOR || fieldType == FieldType.POINT) { + FixedVectorInitialisation init = new FixedVectorInitialisation(); + if (dict.found(VALUE)) { + init.setValue(dict.lookupDoubleArray(VALUE)); + } + return init; + } else { + return new DefaultInitialisation(); + } + + case CELL_SET_KEY: + if (fieldType == FieldType.SCALAR) { + ScalarCellSetInitialisation scsi = new ScalarCellSetInitialisation(); + scsi.setDefaultValue(dict.lookupDoubleUniform(DEFAULT_VALUE_KEY)); + List surfaces = new ArrayList<>(); + ListField list = dict.getList(SET_SOURCES_KEY); + TopoSetReader tsr = new TopoSetReader(baseDir, monitor); + for (Dictionary d : list.getDictionaries()) { + if (d.found(VALUE)) { + surfaces.add(new ScalarSurface(tsr.read(d), d.lookupDouble(VALUE))); + } + } + scsi.setSurfaces(surfaces); + return scsi; + } else if (fieldType == FieldType.VECTOR || fieldType == FieldType.POINT) { + VectorCellSetInitialisation vcsi = new VectorCellSetInitialisation(); + vcsi.setDefaultValue(dict.lookupDoubleArray(DEFAULT_VALUE_KEY)); + List surfaces = new ArrayList<>(); + ListField list = dict.getList(SET_SOURCES_KEY); + TopoSetReader tsr = new TopoSetReader(baseDir, monitor); + for (Dictionary d : list.getDictionaries()) { + if (d.found(VALUE)) { + surfaces.add(new VectorSurface(tsr.read(d), d.lookupDoubleArray(VALUE))); + } + } + vcsi.setSurfaces(surfaces); + return vcsi; + } else { + return new DefaultInitialisation(); + } + + default: + return new DefaultInitialisation(); + } + } + + public Dictionary save(Initialisation initialisation, FieldType fieldType) { + if (initialisation instanceof PotentialFlowInitialisation) { + PotentialFlowInitialisation pfi = (PotentialFlowInitialisation) initialisation; + if (fieldType == FieldType.VECTOR) { + if (state.isCompressible()) { + return newDictionary(INITIALISATION_KEY).field(TYPE, POTENTIAL_FLOW_KEY).field(INITIALISE_UBCS_KEY, pfi.isInitUBCS()).field(RHO_REF_KEY, pfi.getRhoRef()).done(); + } else { + return newDictionary(INITIALISATION_KEY).field(TYPE, POTENTIAL_FLOW_KEY).field(INITIALISE_UBCS_KEY, pfi.isInitUBCS()).done(); + } + } else { + return newDictionary(INITIALISATION_KEY).field(TYPE, POTENTIAL_FLOW_KEY).done(); + } + + } else if (initialisation instanceof BoundaryValueInitialisation) { + BoundaryValueInitialisation bvi = (BoundaryValueInitialisation) initialisation; + return newDictionary(INITIALISATION_KEY).field(TYPE, BOUNDARY_VALUE_KEY).field(PATCH_KEY, bvi.getPatch()).done(); + } else if (initialisation instanceof PrandtlInitialisation) { + PrandtlInitialisation pi = (PrandtlInitialisation) initialisation; + return newDictionary(INITIALISATION_KEY).field(TYPE, PRANDTL_KEY).done(); + } else if (initialisation instanceof TurbulentILInitialisation) { + TurbulentILInitialisation ti = (TurbulentILInitialisation) initialisation; + return newDictionary(INITIALISATION_KEY).field(TYPE, TURBULENT_IL_KEY).field(I_KEY, ti.getI()).field(L_KEY, ti.getL()).field(UREF_KEY, ti.getUref()).done(); + } else if (initialisation instanceof DefaultInitialisation) { + DefaultInitialisation di = (DefaultInitialisation) initialisation; + return newDictionary(INITIALISATION_KEY).field(TYPE, DEFAULT_KEY).done(); + } else if (initialisation instanceof FixedScalarInitialisation) { + FixedScalarInitialisation fsi = (FixedScalarInitialisation) initialisation; + return newDictionary(INITIALISATION_KEY).field(TYPE, FIXED_VALUE_KEY).fieldUniform(VALUE, fsi.getValue()).done(); + } else if (initialisation instanceof FixedVectorInitialisation) { + FixedVectorInitialisation fvi = (FixedVectorInitialisation) initialisation; + return newDictionary(INITIALISATION_KEY).field(TYPE, FIXED_VALUE_KEY).fieldUniform(VALUE, fvi.getValue()).done(); + } else if (initialisation instanceof ScalarCellSetInitialisation) { + ScalarCellSetInitialisation scsi = (ScalarCellSetInitialisation) initialisation; + return newDictionary(INITIALISATION_KEY).field(TYPE, CELL_SET_KEY).fieldUniform(DEFAULT_VALUE_KEY, scsi.getDefaultValue()).list(SET_SOURCES_KEY, getDictionaries(scsi)).done(); + } else if (initialisation instanceof VectorCellSetInitialisation) { + VectorCellSetInitialisation vcsi = (VectorCellSetInitialisation) initialisation; + return newDictionary(INITIALISATION_KEY).field(TYPE, CELL_SET_KEY).fieldUniform(DEFAULT_VALUE_KEY, vcsi.getDefaultValue()).list(SET_SOURCES_KEY, getDictionaries(vcsi)).done(); + } else { + return newDictionary(INITIALISATION_KEY).field(TYPE, DEFAULT_KEY).done(); + } + } + + private Dictionary[] getDictionaries(ScalarCellSetInitialisation scsi) { + List surfaces = scsi.getSurfaces(); + Dictionary[] dicts = new Dictionary[surfaces.size()]; + TopoSetWriter tsw = new TopoSetWriter(baseDir, monitor); + for (int i = 0; i < dicts.length; i++) { + Surface s = surfaces.get(i).getSurface(); + double value = surfaces.get(i).getValue(); + dicts[i] = tsw.write(s); + dicts[i].add(VALUE, value); + } + return dicts; + } + + private Dictionary[] getDictionaries(VectorCellSetInitialisation vcsi) { + List surfaces = vcsi.getSurfaces(); + Dictionary[] dicts = new Dictionary[surfaces.size()]; + TopoSetWriter tsw = new TopoSetWriter(baseDir, monitor); + for (int i = 0; i < dicts.length; i++) { + Surface s = surfaces.get(i).getSurface(); + double[] value = surfaces.get(i).getValue(); + dicts[i] = tsw.write(s); + dicts[i].add(VALUE, value); + } + return dicts; + } + + // For tests only + public void setState(State state) { + this.state = state; + } +} diff --git a/src/eu/engys/core/project/zero/fields/MatrixInternalField.java b/src/eu/engys/core/project/zero/fields/MatrixInternalField.java index 9cbc7b2..0aef242 100644 --- a/src/eu/engys/core/project/zero/fields/MatrixInternalField.java +++ b/src/eu/engys/core/project/zero/fields/MatrixInternalField.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.zero.fields; import java.io.File; diff --git a/src/eu/engys/core/project/zero/fields/PotentialFlowInitialisation.java b/src/eu/engys/core/project/zero/fields/PotentialFlowInitialisation.java new file mode 100644 index 0000000..8043522 --- /dev/null +++ b/src/eu/engys/core/project/zero/fields/PotentialFlowInitialisation.java @@ -0,0 +1,86 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.core.project.zero.fields; + +import eu.engys.util.bean.AbstractBean; + +public class PotentialFlowInitialisation extends AbstractBean implements Initialisation { + + public static final String INIT_UBCS = "initUBCS"; + public static final String RHO_REF = "rhoRef"; + public static final String N_NON_ORTHOGONAL_CORRECTORS = "nNonOrthogonalCorrectors"; + + private boolean initUBCS = true; + // EE + private double rhoRef = 1; + // OS + private int nNonOrthogonalCorrectors = 10; + + public PotentialFlowInitialisation() { + } + + public PotentialFlowInitialisation(boolean initUBCS) { + this.initUBCS = initUBCS; + } + + public PotentialFlowInitialisation(boolean initUBCS, double rhoRef) { + this.initUBCS = initUBCS; + this.rhoRef = rhoRef; + } + + public PotentialFlowInitialisation(boolean initUBCS, int nNonOrthogonalCorrectors) { + this.initUBCS = initUBCS; + this.nNonOrthogonalCorrectors = nNonOrthogonalCorrectors; + } + + public boolean isInitUBCS() { + return initUBCS; + } + + public void setInitUBCS(boolean initUBCS) { + firePropertyChange(INIT_UBCS, this.initUBCS, this.initUBCS = initUBCS); + } + + public double getRhoRef() { + return rhoRef; + } + + public void setRhoRef(double rhoRef) { + firePropertyChange(RHO_REF, this.rhoRef, this.rhoRef = rhoRef); + } + + public int getnNonOrthogonalCorrectors() { + return nNonOrthogonalCorrectors; + } + + public void setnNonOrthogonalCorrectors(int nNonOrthogonalCorrectors) { + firePropertyChange(N_NON_ORTHOGONAL_CORRECTORS, this.nNonOrthogonalCorrectors, this.nNonOrthogonalCorrectors = nNonOrthogonalCorrectors); + } + + public String toString() { + return "Potential Flow"; + } + +} diff --git a/src/eu/engys/core/project/zero/fields/PrandtlInitialisation.java b/src/eu/engys/core/project/zero/fields/PrandtlInitialisation.java new file mode 100644 index 0000000..a85f519 --- /dev/null +++ b/src/eu/engys/core/project/zero/fields/PrandtlInitialisation.java @@ -0,0 +1,34 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.core.project.zero.fields; + +import eu.engys.util.bean.AbstractBean; + +public class PrandtlInitialisation extends AbstractBean implements Initialisation { + + public String toString() { + return "Prandtl"; + } +} diff --git a/src/eu/engys/core/project/zero/fields/ScalarCellSetInitialisation.java b/src/eu/engys/core/project/zero/fields/ScalarCellSetInitialisation.java new file mode 100644 index 0000000..eb68b56 --- /dev/null +++ b/src/eu/engys/core/project/zero/fields/ScalarCellSetInitialisation.java @@ -0,0 +1,66 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.core.project.zero.fields; + +import java.util.ArrayList; +import java.util.List; + +public class ScalarCellSetInitialisation extends CellSetInitialisation { + + private static final int DEFAULT_DEFAULT_VALUE = 0; + + private double defaultValue = DEFAULT_DEFAULT_VALUE; + private List surfaces = new ArrayList<>(); + + public ScalarCellSetInitialisation() {super();} + + public ScalarCellSetInitialisation(double defaulValue) { + super(); + this.defaultValue = defaulValue; + } + + public ScalarCellSetInitialisation(double defaulValue, List surfaces) { + this.defaultValue = defaulValue; + this.surfaces.addAll(surfaces); + } + + public double getDefaultValue() { + return defaultValue; + } + public void setDefaultValue(double defaultValue) { + firePropertyChange(DEFAULT_VALUE_KEY, this.defaultValue, this.defaultValue = defaultValue); + } + + public List getSurfaces() { + return surfaces; + } + public void setSurfaces(List surfaces) { + this.surfaces = surfaces; + } + + public String toString() { + return "ScalarCellSet: " + surfaces; + } +} diff --git a/src/eu/engys/core/project/zero/fields/ScalarInternalField.java b/src/eu/engys/core/project/zero/fields/ScalarInternalField.java index dcdd542..8046023 100644 --- a/src/eu/engys/core/project/zero/fields/ScalarInternalField.java +++ b/src/eu/engys/core/project/zero/fields/ScalarInternalField.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.zero.fields; import java.io.File; diff --git a/src/eu/engys/core/project/zero/fields/TopoSetReader.java b/src/eu/engys/core/project/zero/fields/TopoSetReader.java new file mode 100644 index 0000000..f744910 --- /dev/null +++ b/src/eu/engys/core/project/zero/fields/TopoSetReader.java @@ -0,0 +1,252 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.core.project.zero.fields; + +import static eu.engys.core.project.geometry.Surface.BOX_KEY; +import static eu.engys.core.project.geometry.Surface.CENTRE_KEY; +import static eu.engys.core.project.geometry.Surface.INNER_RADIUS_KEY; +import static eu.engys.core.project.geometry.Surface.OUTER_RADIUS_KEY; +import static eu.engys.core.project.geometry.Surface.P1_KEY; +import static eu.engys.core.project.geometry.Surface.P2_KEY; +import static eu.engys.core.project.geometry.Surface.RADIUS_KEY; +import static eu.engys.core.project.system.SetFieldsDict.BOX_TO_CELL_KEY; +import static eu.engys.core.project.system.SetFieldsDict.CURVATURE_KEY; +import static eu.engys.core.project.system.SetFieldsDict.CYLINDER_ANNULUS_TO_CELL_KEY; +import static eu.engys.core.project.system.SetFieldsDict.CYLINDER_TO_CELL_KEY; +import static eu.engys.core.project.system.SetFieldsDict.FILE_KEY; +import static eu.engys.core.project.system.SetFieldsDict.INCLUDE_CUT_KEY; +import static eu.engys.core.project.system.SetFieldsDict.INCLUDE_INSIDE_KEY; +import static eu.engys.core.project.system.SetFieldsDict.INCLUDE_OUTSIDE_KEY; +import static eu.engys.core.project.system.SetFieldsDict.NEAR_DISTANCE_KEY; +import static eu.engys.core.project.system.SetFieldsDict.OUTSIDE_POINTS_KEY; +import static eu.engys.core.project.system.SetFieldsDict.ROTATED_BOX_TO_CELL_KEY; +import static eu.engys.core.project.system.SetFieldsDict.SPHERE_TO_CELL_KEY; +import static eu.engys.core.project.system.SetFieldsDict.SURFACE_TO_CELL_KEY; + +import java.io.File; +import java.util.List; + +import org.apache.commons.math3.geometry.euclidean.threed.CardanEulerSingularityException; +import org.apache.commons.math3.geometry.euclidean.threed.Rotation; +import org.apache.commons.math3.geometry.euclidean.threed.RotationOrder; +import org.apache.commons.math3.geometry.euclidean.threed.Vector3D; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import eu.engys.core.dictionary.Dictionary; +import eu.engys.core.project.geometry.Surface; +import eu.engys.core.project.geometry.Type; +import eu.engys.core.project.geometry.stl.STLAreaReader; +import eu.engys.core.project.geometry.surface.Box; +import eu.engys.core.project.geometry.surface.Cylinder; +import eu.engys.core.project.geometry.surface.Ring; +import eu.engys.core.project.geometry.surface.RotatedBox; +import eu.engys.core.project.geometry.surface.Solid; +import eu.engys.core.project.geometry.surface.Sphere; +import eu.engys.core.project.geometry.surface.StlArea; +import eu.engys.util.Util; +import eu.engys.util.progress.ProgressMonitor; +import vtk.vtkPolyData; + +public class TopoSetReader { + + private static final Logger logger = LoggerFactory.getLogger(TopoSetReader.class); + private ProgressMonitor monitor; + private File baseDir; + + public TopoSetReader(File baseDir, ProgressMonitor monitor) { + this.baseDir = baseDir; + this.monitor = monitor; + } + + public Surface read(Dictionary d) { + switch (d.getName()) { + case BOX_TO_CELL_KEY: + return readBox(d); + case ROTATED_BOX_TO_CELL_KEY: + return readRotatedBox(d); + case SPHERE_TO_CELL_KEY: + return readSphere(d); + case CYLINDER_TO_CELL_KEY: + return readCylinder(d); + case CYLINDER_ANNULUS_TO_CELL_KEY: + return readRing(d); + case SURFACE_TO_CELL_KEY: + return readSurfaceToCell(d); + default: + return null; + } + } + + @SuppressWarnings("deprecation") + private Surface readBox(Dictionary d) { + if (d.found(BOX_KEY)) { + String boxValue = d.lookup("box"); + String min = boxValue.substring(0, boxValue.indexOf(")") + 1).trim(); + String max = boxValue.replace(min, "").trim(); + + Box box = new Box(getANameFor(Type.BOX)); + box.setMin(Dictionary.toDouble(Dictionary.toArray(min))); + box.setMax(Dictionary.toDouble(Dictionary.toArray(max))); + + return box; + } else { + logger.warn("Missing key '{}'", BOX_KEY); + return null; + } + } + + private String getANameFor(Type type) { + return type + Util.generateID(); + } + + @SuppressWarnings("deprecation") + private Surface readRotatedBox(Dictionary d) { + if (d.found(RotatedBox.ORIGIN_KEY) && d.found(RotatedBox.I_KEY) && d.found(RotatedBox.J_KEY) && d.found(RotatedBox.K_KEY)) { + + double[] o = d.lookupDoubleArray(RotatedBox.ORIGIN_KEY); + double[] i = d.lookupDoubleArray(RotatedBox.I_KEY); + double[] j = d.lookupDoubleArray(RotatedBox.J_KEY); + double[] k = d.lookupDoubleArray(RotatedBox.K_KEY); + + Vector3D v1 = new Vector3D(i); + Vector3D v2 = new Vector3D(j); + Vector3D v3 = new Vector3D(k); + Vector3D vo = new Vector3D(o); + + double s1 = Vector3D.dotProduct(v1, v2); + double s2 = Vector3D.dotProduct(v2, v3); + double s3 = Vector3D.dotProduct(v3, v1); + + if (s1 == 0 && s2 == 0 && s3 == 0) { + double[] delta = { v1.getNorm(), v2.getNorm(), v3.getNorm() }; + Vector3D vc = vo.add(v1.scalarMultiply(0.5)).add(v2.scalarMultiply(0.5)).add(v3.scalarMultiply(0.5)); + double[] center = vc.toArray(); + double[] rotation = { 0, 0, 0 }; + try { + Rotation rot = new Rotation(Vector3D.PLUS_I, Vector3D.PLUS_J, v1, v2); + rotation = rot.getAngles(RotationOrder.XYZ); + } catch (CardanEulerSingularityException e) { + } + + Box box = new Box(getANameFor(Type.BOX)); + box.setCenter(center); + box.setDelta(delta); + box.setRotation(rotation); + + return box; + } else { + RotatedBox rbox = new RotatedBox(getANameFor(Type.RBOX)); + rbox.setOrigin(o); + rbox.setI(i); + rbox.setJ(j); + rbox.setK(k); + return rbox; + } + } else { + logger.warn("Missing any keys '{}' '{}' '{}' '{}'", RotatedBox.ORIGIN_KEY, RotatedBox.I_KEY, RotatedBox.J_KEY, RotatedBox.K_KEY); + return null; + } + } + + @SuppressWarnings("deprecation") + private Surface readSphere(Dictionary d) { + if (d.found(CENTRE_KEY) && d.found(RADIUS_KEY)) { + Sphere sphere = new Sphere(getANameFor(Type.SPHERE)); + sphere.setCentre(d.lookupDoubleArray(CENTRE_KEY)); + sphere.setRadius(d.lookupDouble(RADIUS_KEY)); + return sphere; + } else { + logger.warn("Missing any keys '{}' '{}'", Sphere.CENTRE_KEY, Sphere.RADIUS_KEY); + return null; + } + } + + @SuppressWarnings("deprecation") + private Cylinder readCylinder(Dictionary d) { + if (d.found(P1_KEY) && d.found(P2_KEY) && d.found(RADIUS_KEY)) { + Cylinder cylinder = new Cylinder(getANameFor(Type.CYLINDER)); + cylinder.setPoint1(d.lookupDoubleArray(P1_KEY)); + cylinder.setPoint2(d.lookupDoubleArray(P2_KEY)); + cylinder.setRadius(d.lookupDouble(RADIUS_KEY)); + return cylinder; + } else { + logger.warn("Missing any keys '{}' '{}' '{}'", Cylinder.POINT1_KEY, Cylinder.POINT2_KEY, Cylinder.RADIUS_KEY); + return null; + } + } + + @SuppressWarnings("deprecation") + private Ring readRing(Dictionary d) { + if (d.found(P1_KEY) && d.found(P2_KEY) && d.found(INNER_RADIUS_KEY) && d.found(OUTER_RADIUS_KEY)) { + Ring ring = new Ring(getANameFor(Type.RING)); + ring.setPoint1(d.lookupDoubleArray(P1_KEY)); + ring.setPoint2(d.lookupDoubleArray(P2_KEY)); + ring.setInnerRadius(d.lookupDouble(INNER_RADIUS_KEY)); + ring.setOuterRadius(d.lookupDouble(OUTER_RADIUS_KEY)); + return ring; + } else { + logger.warn("Missing any keys '{}' '{}' '{}' '{}'", Ring.POINT1_KEY, Ring.POINT2_KEY, Ring.INNER_RADIUS_KEY, Ring.OUTER_RADIUS_KEY); + return null; + } + } + + @SuppressWarnings("deprecation") + private StlArea readSurfaceToCell(Dictionary d) { + if (d.found(FILE_KEY)) { + StlArea stlArea = new StlArea(getANameFor(Type.STL_AREA)); + stlArea.setFile(d.lookup(FILE_KEY).replace("\"", "")); + stlArea.setIncludeCut(d.lookupBoolean(INCLUDE_CUT_KEY)); + stlArea.setIncludeInside(d.lookupBoolean(INCLUDE_INSIDE_KEY)); + stlArea.setIncludeOutside(d.lookupBoolean(INCLUDE_OUTSIDE_KEY)); + + double[][] outsidePoints = d.lookupDoubleMatrix(OUTSIDE_POINTS_KEY); + if (outsidePoints.length == 0) { + stlArea.setOutsidePoint(new double[] { 0, 0, 0 }); + } else { + stlArea.setOutsidePoint(outsidePoints[0]); + } + stlArea.setNearDistance(d.lookupDouble(NEAR_DISTANCE_KEY)); + stlArea.setCurvature(d.lookupDouble(CURVATURE_KEY)); + + File file = new File(baseDir, stlArea.getFile()); + if (file.exists()) { + stlArea.setDataSet(readDataSet(file, monitor)); + } + + return stlArea; + } else { + logger.warn("Missing key '{}'", FILE_KEY); + return null; + } + } + + private vtkPolyData readDataSet(File file, ProgressMonitor monitor) { + STLAreaReader reader = new STLAreaReader(file, monitor); + reader.run(); + List solids = reader.getSolids(); + return solids.get(0).getDataSet(); + } +} diff --git a/src/eu/engys/core/project/zero/fields/TopoSetWriter.java b/src/eu/engys/core/project/zero/fields/TopoSetWriter.java new file mode 100644 index 0000000..542bd9d --- /dev/null +++ b/src/eu/engys/core/project/zero/fields/TopoSetWriter.java @@ -0,0 +1,219 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.core.project.zero.fields; + +import static eu.engys.core.project.geometry.Surface.CENTRE_KEY; +import static eu.engys.core.project.geometry.Surface.INNER_RADIUS_KEY; +import static eu.engys.core.project.geometry.Surface.OUTER_RADIUS_KEY; +import static eu.engys.core.project.geometry.Surface.P1_KEY; +import static eu.engys.core.project.geometry.Surface.P2_KEY; +import static eu.engys.core.project.geometry.Surface.RADIUS_KEY; +import static eu.engys.core.project.system.SetFieldsDict.BOX_TO_CELL_KEY; +import static eu.engys.core.project.system.SetFieldsDict.CYLINDER_ANNULUS_TO_CELL_KEY; +import static eu.engys.core.project.system.SetFieldsDict.CYLINDER_TO_CELL_KEY; +import static eu.engys.core.project.system.SetFieldsDict.ROTATED_BOX_TO_CELL_KEY; +import static eu.engys.core.project.system.SetFieldsDict.SPHERE_TO_CELL_KEY; + +import java.io.File; + +import org.apache.commons.math3.geometry.euclidean.threed.Rotation; +import org.apache.commons.math3.geometry.euclidean.threed.RotationOrder; +import org.apache.commons.math3.geometry.euclidean.threed.Vector3D; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import eu.engys.core.dictionary.Dictionary; +import eu.engys.core.project.geometry.Surface; +import eu.engys.core.project.geometry.TransfromMode; +import eu.engys.core.project.geometry.stl.AffineTransform; +import eu.engys.core.project.geometry.stl.STLAreaWriter; +import eu.engys.core.project.geometry.surface.Box; +import eu.engys.core.project.geometry.surface.Cylinder; +import eu.engys.core.project.geometry.surface.Ring; +import eu.engys.core.project.geometry.surface.RotatedBox; +import eu.engys.core.project.geometry.surface.Sphere; +import eu.engys.core.project.geometry.surface.StlArea; +import eu.engys.core.project.system.SetFieldsDict; +import eu.engys.util.Util; +import eu.engys.util.progress.ProgressMonitor; + +public class TopoSetWriter { + + private static final Logger logger = LoggerFactory.getLogger(TopoSetWriter.class); + private ProgressMonitor monitor; + private File baseDir; + + public TopoSetWriter(File baseDir, ProgressMonitor monitor) { + this.baseDir = baseDir; + this.monitor = monitor; + } + + public Dictionary write(Surface surface) { + switch (surface.getType()) { + case BOX: + return writeBox(surface); + case RBOX: + return writeRotatedBox(surface); + case SPHERE: + return writeSphere(surface); + case CYLINDER: + return writeCylinder(surface); + case RING: + return writeRing(surface); + case STL_AREA: + return writeStlArea(surface); + default: + logger.error("Unknown type {}", surface.getType()); + return null; + } + } + + private Dictionary writeStlArea(Surface surface) { + StlArea stlArea = (StlArea) surface; + + Dictionary surfaceToPoint = new Dictionary(SetFieldsDict.SURFACE_TO_CELL_KEY); + surfaceToPoint.add(SetFieldsDict.FILE_KEY, "\"" + stlArea.getFile() + "\""); + surfaceToPoint.add(SetFieldsDict.OUTSIDE_POINTS_KEY, new double[][] { stlArea.getOutsidePoint() }); + surfaceToPoint.add(SetFieldsDict.INCLUDE_CUT_KEY, stlArea.isIncludeCut()); + surfaceToPoint.add(SetFieldsDict.INCLUDE_INSIDE_KEY, stlArea.isIncludeInside()); + surfaceToPoint.add(SetFieldsDict.INCLUDE_OUTSIDE_KEY, stlArea.isIncludeOutside()); + surfaceToPoint.add(SetFieldsDict.NEAR_DISTANCE_KEY, stlArea.getNearDistance()); + surfaceToPoint.add(SetFieldsDict.CURVATURE_KEY, stlArea.getCurvature()); + + _writeStlArea(baseDir, stlArea, monitor); + + return surfaceToPoint; + } + + private void _writeStlArea(File baseDir, StlArea stlArea, ProgressMonitor monitor) { + File file = new File(baseDir, stlArea.getFile()); + + if (stlArea.getTransformMode() == TransfromMode.TO_DICTIONARY) { + if (!file.exists()) { + new STLAreaWriter(file, stlArea, monitor).run(); + } + } else { + AffineTransform transformation = stlArea.getTransformation(); + if (!file.exists() || !transformation.isIdentity()) { + new STLAreaWriter(file, stlArea, monitor).run(); + } + } + } + + private Dictionary writeBox(Surface surface) { + Box box = (Box) surface; + double[] rotation = box.getRotation(); + if (rotation[0] != 0 || rotation[1] != 0 || rotation[2] != 0) { + double[] center = box.getCenter(); + double[] delta = box.getDelta(); + + double[] origin = { -delta[0] / 2, -delta[1] / 2, -delta[2] / 2 }; + double[] i = { delta[0], 0, 0 }; + double[] j = { 0, delta[1], 0 }; + double[] k = { 0, 0, delta[2] }; + + Vector3D v_i = new Vector3D(i); + Vector3D v_j = new Vector3D(j); + Vector3D v_k = new Vector3D(k); + Vector3D v_origin = new Vector3D(origin); + Vector3D v_center = new Vector3D(center); + + Rotation rot = new Rotation(RotationOrder.XYZ, rotation[0], rotation[1], rotation[2]); + v_i = rot.applyTo(v_i); + v_j = rot.applyTo(v_j); + v_k = rot.applyTo(v_k); + v_origin = rot.applyTo(v_origin); + + i = v_i.toArray(); + j = v_j.toArray(); + k = v_k.toArray(); + origin = v_origin.add(v_center).toArray(); + + Util.round(i); + Util.round(j); + Util.round(k); + Util.round(origin); + + Dictionary rboxToCell = new Dictionary(ROTATED_BOX_TO_CELL_KEY); + String originString = Dictionary.toString(origin); + String iString = Dictionary.toString(i); + String jString = Dictionary.toString(j); + String kString = Dictionary.toString(k); + rboxToCell.add(RotatedBox.ORIGIN_KEY, originString); + rboxToCell.add(RotatedBox.I_KEY, iString); + rboxToCell.add(RotatedBox.J_KEY, jString); + rboxToCell.add(RotatedBox.K_KEY, kString); + return rboxToCell; + } else { + Dictionary boxToCell = new Dictionary(BOX_TO_CELL_KEY); + String min = Dictionary.toString(box.getMin()); + String max = Dictionary.toString(box.getMax()); + boxToCell.add(Surface.BOX_KEY, min + " " + max); + return boxToCell; + } + } + + private Dictionary writeRotatedBox(Surface surface) { + RotatedBox rbox = (RotatedBox) surface; + Dictionary rboxToCell = new Dictionary(ROTATED_BOX_TO_CELL_KEY); + String origin = Dictionary.toString(rbox.getOrigin()); + String i = Dictionary.toString(rbox.getI()); + String j = Dictionary.toString(rbox.getJ()); + String k = Dictionary.toString(rbox.getK()); + rboxToCell.add(RotatedBox.ORIGIN_KEY, origin); + rboxToCell.add(RotatedBox.I_KEY, i); + rboxToCell.add(RotatedBox.J_KEY, j); + rboxToCell.add(RotatedBox.K_KEY, k); + return rboxToCell; + } + + private Dictionary writeSphere(Surface surface) { + Sphere sphere = (Sphere) surface; + Dictionary sphereToCell = new Dictionary(SPHERE_TO_CELL_KEY); + sphereToCell.add(CENTRE_KEY, sphere.getCentre()); + sphereToCell.add(RADIUS_KEY, sphere.getRadius()); + return sphereToCell; + } + + private Dictionary writeCylinder(Surface surface) { + Cylinder cyl = (Cylinder) surface; + Dictionary cylinderToCell = new Dictionary(CYLINDER_TO_CELL_KEY); + cylinderToCell.add(P1_KEY, cyl.getPoint1()); + cylinderToCell.add(P2_KEY, cyl.getPoint2()); + cylinderToCell.add(RADIUS_KEY, cyl.getRadius()); + return cylinderToCell; + } + + private Dictionary writeRing(Surface surface) { + Ring ring = (Ring) surface; + Dictionary ringToCell = new Dictionary(CYLINDER_ANNULUS_TO_CELL_KEY); + ringToCell.add(P1_KEY, ring.getPoint1()); + ringToCell.add(P2_KEY, ring.getPoint2()); + ringToCell.add(INNER_RADIUS_KEY, ring.getInnerRadius()); + ringToCell.add(OUTER_RADIUS_KEY, ring.getOuterRadius()); + return ringToCell; + } + +} diff --git a/src/eu/engys/core/project/zero/fields/TurbulentILInitialisation.java b/src/eu/engys/core/project/zero/fields/TurbulentILInitialisation.java new file mode 100644 index 0000000..6d30e13 --- /dev/null +++ b/src/eu/engys/core/project/zero/fields/TurbulentILInitialisation.java @@ -0,0 +1,72 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.core.project.zero.fields; + +import eu.engys.util.bean.AbstractBean; + +public class TurbulentILInitialisation extends AbstractBean implements Initialisation { + + public static final String I_KEY = "i"; + public static final String UREF_KEY = "uref"; + public static final String L_KEY = "l"; + + private double i = 0.0; + private double l = 0.0; + private double uref = 0.0; + + public TurbulentILInitialisation() {} + + public TurbulentILInitialisation(double I, double L, double Uref) { + this.i = I; + this.l = L; + this.uref = Uref; + } + + public double getI() { + return i; + } + public void setI(double i) { + firePropertyChange(I_KEY, this.i, this.i = i); + } + + public double getL() { + return l; + } + public void setL(double l) { + firePropertyChange(L_KEY, this.l, this.l = l); + } + + public double getUref() { + return uref; + } + + public void setUref(double uref) { + firePropertyChange(UREF_KEY, this.uref, this.uref = uref); + } + + public String toString() { + return "Turbulent IL"; + } +} diff --git a/src/eu/engys/core/project/zero/fields/VectorCellSetInitialisation.java b/src/eu/engys/core/project/zero/fields/VectorCellSetInitialisation.java new file mode 100644 index 0000000..bb24b03 --- /dev/null +++ b/src/eu/engys/core/project/zero/fields/VectorCellSetInitialisation.java @@ -0,0 +1,69 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.core.project.zero.fields; + +import java.util.ArrayList; +import java.util.List; + +public class VectorCellSetInitialisation extends CellSetInitialisation { + + private static final double[] DEFAULT_DEFAULT_VALUE = {0,0,0}; + + private double[] defaultValue = DEFAULT_DEFAULT_VALUE; + private List surfaces = new ArrayList<>(); + + public VectorCellSetInitialisation() { + super(); + } + + public VectorCellSetInitialisation(double[] defaulValue) { + super(); + this.defaultValue = defaulValue; + } + + public VectorCellSetInitialisation(double[] defaultValue, List surfaces) { + this.defaultValue = defaultValue; + this.surfaces.addAll(surfaces); + } + + public double[] getDefaultValue() { + return defaultValue; + } + public void setDefaultValue(double[] defaultValue) { + firePropertyChange(DEFAULT_VALUE_KEY, this.defaultValue, this.defaultValue = defaultValue); + } + + public List getSurfaces() { + return surfaces; + } + public void setSurfaces(List surfaces) { + this.surfaces = surfaces; + } + + public String toString() { + return "VectorCellSet: " + surfaces; + } + +} diff --git a/src/eu/engys/core/project/zero/fields/VectorInternalField.java b/src/eu/engys/core/project/zero/fields/VectorInternalField.java index 7754523..03c2df0 100644 --- a/src/eu/engys/core/project/zero/fields/VectorInternalField.java +++ b/src/eu/engys/core/project/zero/fields/VectorInternalField.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.zero.fields; import java.io.File; diff --git a/src/eu/engys/core/project/zero/patches/BoundaryConditions.java b/src/eu/engys/core/project/zero/patches/BoundaryConditions.java index 13a909b..be0a62c 100644 --- a/src/eu/engys/core/project/zero/patches/BoundaryConditions.java +++ b/src/eu/engys/core/project/zero/patches/BoundaryConditions.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.zero.patches; @@ -46,6 +45,7 @@ import static eu.engys.core.project.zero.fields.Fields.NU_SGS; import static eu.engys.core.project.zero.fields.Fields.NU_TILDA; import static eu.engys.core.project.zero.fields.Fields.OMEGA; import static eu.engys.core.project.zero.fields.Fields.P; +import static eu.engys.core.project.zero.fields.Fields.POINT_DISPLACEMENT; import static eu.engys.core.project.zero.fields.Fields.P_RGH; import static eu.engys.core.project.zero.fields.Fields.SMOKE; import static eu.engys.core.project.zero.fields.Fields.T; @@ -61,44 +61,45 @@ import eu.engys.core.dictionary.Dictionary; import eu.engys.core.project.zero.fields.Fields; public class BoundaryConditions { - - private static final Logger logger = LoggerFactory.getLogger(BoundaryConditions.class); - - public static final String[] PLACE_HOLDER_KEYS = {"value", "refValue", "inletValue", "gradient"}; - public static void replaceNonUniformVector(Dictionary d) { - for (String ph : PLACE_HOLDER_KEYS) { - if(isNonUniform(d, ph)){ - d.add(ph, "uniform (0 0 0)"); + private static final Logger logger = LoggerFactory.getLogger(BoundaryConditions.class); + + public static final String[] PLACE_HOLDER_KEYS = { "value", "refValue", "inletValue", "gradient", "inletDirection" }; + + public static void replaceNonUniformVector(Dictionary d) { + for (String ph : PLACE_HOLDER_KEYS) { + if (isNonUniform(d, ph)) { + d.add(ph, "uniform (0 0 0)"); logger.warn("Nonuniform field {} replaced with {}", ph, d.lookup(ph)); - } - } - } - public static void replaceNonUniformScalar(Dictionary d) { - for (String ph : PLACE_HOLDER_KEYS) { - if(isNonUniform(d, ph)){ - d.add(ph, "uniform 0"); - logger.warn("Nonuniform field {} replaced with {}", ph, d.lookup(ph)); - } - } - } - + } + } + } + + public static void replaceNonUniformScalar(Dictionary d) { + for (String ph : PLACE_HOLDER_KEYS) { + if (isNonUniform(d, ph)) { + d.add(ph, "uniform 0"); + logger.warn("Nonuniform field {} replaced with {}", ph, d.lookup(ph)); + } + } + } + public static boolean isNonUniform(Dictionary d) { - for (String ph : PLACE_HOLDER_KEYS) { - if(isNonUniform(d, ph)){ - return true; - } - } - return false; + for (String ph : PLACE_HOLDER_KEYS) { + if (isNonUniform(d, ph)) { + return true; + } + } + return false; } public static boolean isPlaceHolder(Dictionary d) { - for (String ph : PLACE_HOLDER_KEYS) { - if(isPlaceHolder(d, ph)){ - return true; - } - } - return false; + for (String ph : PLACE_HOLDER_KEYS) { + if (isPlaceHolder(d, ph)) { + return true; + } + } + return false; } private static boolean isPlaceHolder(Dictionary d, String key) { @@ -109,6 +110,17 @@ public class BoundaryConditions { return (d.isField(key) && d.lookup(key).contains("nonuniform List")) || (d.isList2(key) && d.getList2(key).isNonuniform()); } + private static final String BOUNDARY_CONDITIONS = "boundaryConditions"; + private static final String MOMENTUM = "momentum"; + private static final String TURBULENCE = "turbulence"; + private static final String THERMAL = "thermal"; + private static final String HUMIDITY = "humidity"; + private static final String RADIATION = "radiation"; + private static final String PASSIVE_SCALARS = "passiveScalars"; + private static final String PHASE = "phase"; + private static final String ROUGHNESS = "roughness"; + private static final String DISPLACEMENT = "displacement"; + private Dictionary momentum; private Dictionary turbulence; private Dictionary thermal; @@ -117,16 +129,18 @@ public class BoundaryConditions { private Dictionary passiveScalars; private Dictionary phase; private Dictionary roughness; + private Dictionary displacement; public BoundaryConditions() { - setMomentum(new Dictionary("momentum")); - setTurbulence(new Dictionary("turbulence")); - setThermal(new Dictionary("thermal")); - setHumidity(new Dictionary("humidity")); - setRadiation(new Dictionary("radiation")); - setPassiveScalars(new Dictionary("passiveScalars")); - setPhase(new Dictionary("phase")); - setRoughness(new Dictionary("roughness")); + setMomentum(new Dictionary(MOMENTUM)); + setTurbulence(new Dictionary(TURBULENCE)); + setThermal(new Dictionary(THERMAL)); + setHumidity(new Dictionary(HUMIDITY)); + setRadiation(new Dictionary(RADIATION)); + setPassiveScalars(new Dictionary(PASSIVE_SCALARS)); + setPhase(new Dictionary(PHASE)); + setRoughness(new Dictionary(ROUGHNESS)); + setDisplacement(new Dictionary(DISPLACEMENT)); } public BoundaryConditions(BoundaryConditions defaults) { @@ -140,11 +154,12 @@ public class BoundaryConditions { getPassiveScalars().merge(defaults.getPassiveScalars()); getPhase().merge(defaults.getPhase()); getRoughness().merge(defaults.getRoughness()); + getDisplacement().merge(defaults.getDisplacement()); } } public Dictionary toDictionary() { - Dictionary dict = new Dictionary("boundaryConditions"); + Dictionary dict = new Dictionary(BOUNDARY_CONDITIONS); dict.merge(getMomentum()); dict.merge(getTurbulence()); dict.merge(getThermal()); @@ -153,6 +168,7 @@ public class BoundaryConditions { dict.merge(getPassiveScalars()); dict.merge(getPhase()); dict.merge(getRoughness()); + dict.merge(getDisplacement()); return dict; } @@ -188,17 +204,24 @@ public class BoundaryConditions { getPhase().add(dictionary); } else if (isRoughness(name)) { getRoughness().add(dictionary); + } else if (isDisplacement(name)) { + getDisplacement().add(dictionary); } else { } } private boolean isRoughness(String name) { - String[] list = new String[] { NUT, MUT, NU_SGS, MU_SGS }; - return Arrays.asList(list).contains(name); - } + String[] list = new String[] { NUT, MUT, NU_SGS, MU_SGS }; + return Arrays.asList(list).contains(name); + } - public static boolean isPassiveScalar(String name) { + private boolean isDisplacement(String name) { + String[] list = new String[] { POINT_DISPLACEMENT }; + return Arrays.asList(list).contains(name); + } + + public static boolean isPassiveScalar(String name) { String[] list = new String[] { AOA, DT_AOA, CO2, DT_CO2, SMOKE, DT_SMOKE }; return Arrays.asList(list).contains(name); } @@ -220,7 +243,7 @@ public class BoundaryConditions { } public static boolean isTurbulence(String name) { - String[] list = new String[] { K, OMEGA, EPSILON, NU_TILDA, /*NUT, NU_SGS, MUT, MU_SGS, */ALPHA_SGS, ALPHA_T }; + String[] list = new String[] { K, OMEGA, EPSILON, NU_TILDA, /* NUT, NU_SGS, MUT, MU_SGS, */ALPHA_SGS, ALPHA_T }; return Arrays.asList(list).contains(name); } @@ -291,13 +314,21 @@ public class BoundaryConditions { return phase; } - public Dictionary getRoughness() { - return roughness; - } - - public void setRoughness(Dictionary roughness) { - this.roughness = roughness; - } + public Dictionary getRoughness() { + return roughness; + } + + public void setRoughness(Dictionary roughness) { + this.roughness = roughness; + } + + public Dictionary getDisplacement() { + return displacement; + } + + public void setDisplacement(Dictionary displacement) { + this.displacement = displacement; + } public static BoundaryConditions toMomentumRoughness(Dictionary dict) { BoundaryConditions bc = new BoundaryConditions(); diff --git a/src/eu/engys/core/project/zero/patches/BoundaryConditionsDefaults.java b/src/eu/engys/core/project/zero/patches/BoundaryConditionsDefaults.java index 44975e5..1ec2cc9 100644 --- a/src/eu/engys/core/project/zero/patches/BoundaryConditionsDefaults.java +++ b/src/eu/engys/core/project/zero/patches/BoundaryConditionsDefaults.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.zero.patches; @@ -94,7 +93,6 @@ public class BoundaryConditionsDefaults { } return new Dictionary(def); } - public static Dictionary getRoughness() { BoundaryConditions boundaryConditions = BoundaryConditionsDefaults.get(BoundaryType.WALL_KEY); @@ -107,6 +105,17 @@ public class BoundaryConditionsDefaults { return null; } + public static Dictionary getDisplacement() { + BoundaryConditions boundaryConditions = BoundaryConditionsDefaults.get(BoundaryType.WALL_KEY); + if (boundaryConditions != null) { + Dictionary displacement = boundaryConditions.getDisplacement(); + if (displacement != null) { + return new Dictionary(displacement); + } + } + return null; + } + public static void loadBoundaryConditionsFromFields(Patches patches, Fields fields) { patches.clearBoundaryConditions(); @@ -130,7 +139,7 @@ public class BoundaryConditionsDefaults { } } - public static void fieldToBoundaryConditions(Field field, Patches patches) { + private static void fieldToBoundaryConditions(Field field, Patches patches) { Map patchesMap = patches.toMap(); Dictionary boundaryField = field.getBoundaryField(); diff --git a/src/eu/engys/core/project/zero/patches/BoundaryType.java b/src/eu/engys/core/project/zero/patches/BoundaryType.java index f60f4f1..3c58b29 100644 --- a/src/eu/engys/core/project/zero/patches/BoundaryType.java +++ b/src/eu/engys/core/project/zero/patches/BoundaryType.java @@ -1,29 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.zero.patches; import java.util.Collections; @@ -33,193 +31,233 @@ import java.util.Map; import javax.swing.Icon; import javax.swing.ImageIcon; +import org.apache.commons.lang.builder.EqualsBuilder; +import org.apache.commons.lang.builder.HashCodeBuilder; + public class BoundaryType { - + public static final String MAPPED_PATCH_KEY = "mappedPatch"; - public static final String MAPPED_WALL_KEY = "mappedWall"; + public static final String MAPPED_WALL_KEY = "mappedWall"; public static final String CYCLIC_KEY = "cyclic"; - public static final String CYCLIC_AMI_KEY = "cyclicAMI"; - public static final String EMPTY_KEY = "empty"; - public static final String INLET_KEY = "inlet"; - public static final String OPENING_KEY = "opening"; - public static final String OUTLET_KEY = "outlet"; - public static final String PATCH_KEY = "patch"; - public static final String PROCESSOR_KEY = "processor"; - public static final String PROCESSOR_CYCLIC_KEY = "processorCyclic"; - public static final String SYMMETRY_KEY = "symmetry"; - public static final String SYMMETRY_PLANE_KEY = "symmetryPlane"; - public static final String WALL_KEY = "wall"; - public static final String WEDGE_KEY = "wedge"; - public static final String FREE_SURFACE_KEY = "freeSurface"; + public static final String CYCLIC_AMI_KEY = "cyclicAMI"; + public static final String EMPTY_KEY = "empty"; + public static final String INLET_KEY = "inlet"; + public static final String OPENING_KEY = "opening"; + public static final String OUTLET_KEY = "outlet"; + public static final String PATCH_KEY = "patch"; + public static final String PROCESSOR_KEY = "processor"; + public static final String PROCESSOR_CYCLIC_KEY = "processorCyclic"; + public static final String SYMMETRY_KEY = "symmetry"; + public static final String SYMMETRY_PLANE_KEY = "symmetryPlane"; + public static final String WALL_KEY = "wall"; + public static final String WEDGE_KEY = "wedge"; + public static final String FREE_SURFACE_KEY = "freeSurface"; - public static final String CYCLIC_LABEL = "Cyclic"; - public static final String CYCLIC_AMI_LABEL = "Cyclic AMI"; - public static final String EMPTY_LABEL = "Empty"; - public static final String INLET_LABEL = "Inlet"; - public static final String OPENING_LABEL = "Opening"; - public static final String OUTLET_LABEL = "Outlet"; - public static final String PATCH_LABEL = "Patch"; - public static final String PROCESSOR_LABEL = "Processor"; - public static final String PROCESSOR_CYCLIC_LABEL = "Processor Cyclic"; - public static final String SYMMETRY_LABEL = "Symmetry"; - public static final String SYMMETRY_PLANE_LABEL = "Symmetry Plane"; - public static final String WALL_LABEL = "Wall"; - public static final String WEDGE_LABEL = "Wedge"; - public static final String FREE_SURFACE_LABEL = "Free Surface"; + public static final String CYCLIC_LABEL = "Cyclic"; + public static final String CYCLIC_AMI_LABEL = "Cyclic AMI"; + public static final String EMPTY_LABEL = "Empty"; + public static final String INLET_LABEL = "Inlet"; + public static final String OPENING_LABEL = "Opening"; + public static final String OUTLET_LABEL = "Outlet"; + public static final String PATCH_LABEL = "Patch"; + public static final String PROCESSOR_LABEL = "Processor"; + public static final String PROCESSOR_CYCLIC_LABEL = "Processor Cyclic"; + public static final String SYMMETRY_LABEL = "Symmetry"; + public static final String SYMMETRY_PLANE_LABEL = "Symmetry Plane"; + public static final String WALL_LABEL = "Wall"; + public static final String WEDGE_LABEL = "Wedge"; + public static final String FREE_SURFACE_LABEL = "Free Surface"; - public static final BoundaryType INLET = new BoundaryType(INLET_KEY, INLET_LABEL, true); - public static final BoundaryType OUTLET = new BoundaryType(OUTLET_KEY, OUTLET_LABEL, true); - public static final BoundaryType OPENING = new BoundaryType(OPENING_KEY, OPENING_LABEL, true); - public static final BoundaryType WALL = new BoundaryType(WALL_KEY, WALL_LABEL, true); - public static final BoundaryType PATCH = new BoundaryType(PATCH_KEY, PATCH_LABEL, true); - public static final BoundaryType SYMMETRY = new BoundaryType(SYMMETRY_KEY, SYMMETRY_LABEL, false); - public static final BoundaryType SYMMETRY_PLANE = new BoundaryType(SYMMETRY_PLANE_KEY, SYMMETRY_PLANE_LABEL, false); - public static final BoundaryType CYCLIC = new BoundaryType(CYCLIC_KEY, CYCLIC_LABEL, true); - public static final BoundaryType CYCLIC_AMI = new BoundaryType(CYCLIC_AMI_KEY, CYCLIC_AMI_LABEL, true); - public static final BoundaryType EMPTY = new BoundaryType(EMPTY_KEY, EMPTY_LABEL, false); - public static final BoundaryType WEDGE = new BoundaryType(WEDGE_KEY, WEDGE_LABEL, false); - public static final BoundaryType PROCESSOR = new BoundaryType(PROCESSOR_KEY, PROCESSOR_LABEL, false); - public static final BoundaryType PROCESSOR_CYCLIC = new BoundaryType(PROCESSOR_CYCLIC_KEY, PROCESSOR_CYCLIC_LABEL, false); - public static final BoundaryType FREE_SURFACE = new BoundaryType(FREE_SURFACE_KEY, FREE_SURFACE_LABEL, true); + public static final BoundaryType INLET = new BoundaryType(INLET_KEY, INLET_LABEL, true, true); + public static final BoundaryType OUTLET = new BoundaryType(OUTLET_KEY, OUTLET_LABEL, true, true); + public static final BoundaryType OPENING = new BoundaryType(OPENING_KEY, OPENING_LABEL, true, true); + public static final BoundaryType WALL = new BoundaryType(WALL_KEY, WALL_LABEL, true, true); + public static final BoundaryType PATCH = new BoundaryType(PATCH_KEY, PATCH_LABEL, true, true); + public static final BoundaryType SYMMETRY = new BoundaryType(SYMMETRY_KEY, SYMMETRY_LABEL, false, true); + public static final BoundaryType SYMMETRY_PLANE = new BoundaryType(SYMMETRY_PLANE_KEY, SYMMETRY_PLANE_LABEL, false, true); + public static final BoundaryType CYCLIC = new BoundaryType(CYCLIC_KEY, CYCLIC_LABEL, true, true); + public static final BoundaryType CYCLIC_AMI = new BoundaryType(CYCLIC_AMI_KEY, CYCLIC_AMI_LABEL, true, true); + public static final BoundaryType EMPTY = new BoundaryType(EMPTY_KEY, EMPTY_LABEL, false, true); + public static final BoundaryType WEDGE = new BoundaryType(WEDGE_KEY, WEDGE_LABEL, false, true); + public static final BoundaryType FREE_SURFACE = new BoundaryType(FREE_SURFACE_KEY, FREE_SURFACE_LABEL, true, true); - private static Map registeredTypes = new LinkedHashMap<>(); - private static Map registeredTypesIcon = new LinkedHashMap<>(); + public static final BoundaryType PROCESSOR = new BoundaryType(PROCESSOR_KEY, PROCESSOR_LABEL, false, false); + public static final BoundaryType PROCESSOR_CYCLIC = new BoundaryType(PROCESSOR_CYCLIC_KEY, PROCESSOR_CYCLIC_LABEL, false, false); - public static void registerBoundaryType(BoundaryType type) { - registeredTypes.put(type.getKey(), type); - registeredTypesIcon.put(type.getKey(), getIcon("eu/engys/resources/images/" + type.getKey() + "16.png")); - } + private static Map registeredTypes = new LinkedHashMap<>(); + private static Map registeredTypesIcon = new LinkedHashMap<>(); - public static void unregisterBoundaryType(BoundaryType type) { - registeredTypes.remove(type.getKey()); - registeredTypesIcon.remove(type.getKey()); - } - - private static Icon getIcon(String string) { - try { - return new ImageIcon(BoundaryType.class.getClassLoader().getResource(string)); - } catch (Exception e) { - return null; - } - } - - public static Map getRegisteredBoundaryTypes() { - return Collections.unmodifiableMap(registeredTypes); - } - - public static boolean isPatch(String key) { - return key.equals(PATCH_KEY); - } - - public static boolean isWall(String key) { - return key.equals(WALL_KEY); - } - - public static boolean isMappedWall(String key) { - return key.equals(MAPPED_WALL_KEY); - } - - public static boolean isMappedPatch(String key) { - return key.equals(MAPPED_PATCH_KEY); - } - - public static boolean isOpening(String key) { - return key.equals(OPENING_KEY); - } - - public static boolean isPatchPhysicalType(String key) { - return key.equals(INLET_KEY) || key.equals(OUTLET_KEY) || key.equals(OPENING_KEY); - } - - public static boolean isWallPhysicalType(String key) { - return key.equals(FREE_SURFACE_KEY); - } - - public static boolean isCoupledSymmetryPlaneType(String patchType) { - return patchType.equals(SYMMETRY_PLANE_KEY); + public static void registerBoundaryType(BoundaryType type) { + registeredTypes.put(type.getKey(), type); + registeredTypesIcon.put(type.getKey(), getIcon("eu/engys/resources/images/" + type.getKey() + "16.png")); } - public static boolean isProcessor(String key) { - return key.equals(PROCESSOR_KEY); - } + public static void unregisterBoundaryType(BoundaryType type) { + registeredTypes.remove(type.getKey()); + registeredTypesIcon.remove(type.getKey()); + } - public static boolean isProcessorCyclic(String key) { - return key.equals(PROCESSOR_CYCLIC_KEY); - } + public static void unregisterAll() { + registeredTypes.clear(); + registeredTypesIcon.clear(); + } - public static boolean isCyclicAMI(String key) { - return key.equals(CYCLIC_AMI_KEY); - } + private static Icon getIcon(String string) { + try { + return new ImageIcon(BoundaryType.class.getClassLoader().getResource(string)); + } catch (Exception e) { + return null; + } + } - public static boolean isInlet(Patch patch) { - return patch.getPhisicalType().getKey().equals(INLET_KEY); - } + public static Map getRegisteredBoundaryTypes() { + return Collections.unmodifiableMap(registeredTypes); + } - public static boolean isKnown(String key) { - return registeredTypes.containsKey(key); - } + public static boolean isPatch(String key) { + return key.equals(PATCH_KEY); + } - public static BoundaryType getDefaultType() { - return WALL; - } + public static boolean isWall(String key) { + return key.equals(WALL_KEY); + } - public static String getDefaultKey() { - return WALL_KEY; - } + public static boolean isMappedWall(String key) { + return key.equals(MAPPED_WALL_KEY); + } - public static BoundaryType getType(String key) { - return registeredTypes.get(key); - } + public static boolean isMappedPatch(String key) { + return key.equals(MAPPED_PATCH_KEY); + } - private String label; - private String key; - private boolean hasBoundaryConditions; + public static boolean isOpening(String key) { + return key.equals(OPENING_KEY); + } - private BoundaryType(String key, String label, boolean hasBoundaryConditions) { - this.key = key; - this.label = label; - this.hasBoundaryConditions = hasBoundaryConditions; - } + public static boolean isPatchPhysicalType(String key) { + return key.equals(INLET_KEY) || key.equals(OUTLET_KEY) || key.equals(OPENING_KEY); + } - public String getLabel() { - return label; - } + public static boolean isFreeSurfacePhysicalType(String key) { + return key.equals(FREE_SURFACE_KEY); + } - public String getKey() { - return key; - } + public static boolean isSymmetryPlanePhysicalType(String key) { + return key.equals(SYMMETRY_PLANE_KEY); + } - public boolean hasBoundaryConditions() { - return hasBoundaryConditions; - } + public static boolean isSymmetryPhysicalType(String key) { + return key.equals(SYMMETRY_KEY); + } - public Icon getIcon() { - return registeredTypesIcon.get(key); - } + public static boolean isProcessor(String key) { + return key.equals(PROCESSOR_KEY); + } - @Override - public String toString() { - return getKey(); - } + public static boolean isProcessorCyclic(String key) { + return key.equals(PROCESSOR_CYCLIC_KEY); + } - @Override - public boolean equals(Object obj) { - return toString().equals(obj.toString()); - } + public static boolean isCyclicAMI(String key) { + return key.equals(CYCLIC_AMI_KEY); + } - public boolean isProcessor() { - return this == PROCESSOR; - } + public static boolean isCyclic(String key) { + return key.equals(CYCLIC_KEY); + } - public boolean isProcessorCyclic() { - return this == PROCESSOR_CYCLIC; - } + public static boolean isInlet(Patch patch) { + return patch.getPhysicalType().getKey().equals(INLET_KEY); + } - public boolean isCyclicAMI() { - return this == CYCLIC_AMI; - } + public static boolean isKnown(String key) { + return registeredTypes.containsKey(key); + } - public boolean isPatch() { - return this == PATCH; - } -}; + public static BoundaryType getDefaultType() { + return WALL; + } + + public static String getDefaultKey() { + return WALL_KEY; + } + + public static BoundaryType getType(String key) { + return registeredTypes.get(key); + } + + private String label; + private String key; + private boolean hasBoundaryConditions; + private boolean editable; + + private BoundaryType(String key, String label, boolean hasBoundaryConditions, boolean editable) { + this.key = key; + this.label = label; + this.hasBoundaryConditions = hasBoundaryConditions; + this.editable = editable; + } + + public String getLabel() { + return label; + } + + public String getKey() { + return key; + } + + public boolean hasBoundaryConditions() { + return hasBoundaryConditions; + } + + public boolean isEditable() { + return editable; + } + + public Icon getIcon() { + return registeredTypesIcon.get(key); + } + + @Override + public String toString() { + return getKey(); + } + + public boolean isOutlet() { + return this == OUTLET; + } + + public boolean isProcessor() { + return this == PROCESSOR; + } + + public boolean isProcessorCyclic() { + return this == PROCESSOR_CYCLIC; + } + + public boolean isCyclicAMI() { + return this == CYCLIC_AMI; + } + + public boolean isPatch() { + return this == PATCH; + } + + @Override + public boolean equals(Object obj) { + if (!(obj instanceof BoundaryType)) { + return false; + } + if (obj == this) { + return true; + } + BoundaryType type = (BoundaryType) obj; + return new EqualsBuilder().append(key, type.key).isEquals(); + } + + @Override + public int hashCode() { + return new HashCodeBuilder(17, 31).append(key).toHashCode(); + } + +} diff --git a/src/eu/engys/core/project/zero/patches/MergeBoundaryConditions.java b/src/eu/engys/core/project/zero/patches/MergeBoundaryConditions.java index 69580a8..38abdf1 100644 --- a/src/eu/engys/core/project/zero/patches/MergeBoundaryConditions.java +++ b/src/eu/engys/core/project/zero/patches/MergeBoundaryConditions.java @@ -1,29 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.zero.patches; import static eu.engys.core.project.zero.fields.Fields.ALPHA_SGS; @@ -45,6 +43,7 @@ import static eu.engys.core.project.zero.fields.Fields.NU_SGS; import static eu.engys.core.project.zero.fields.Fields.NU_TILDA; import static eu.engys.core.project.zero.fields.Fields.OMEGA; import static eu.engys.core.project.zero.fields.Fields.P; +import static eu.engys.core.project.zero.fields.Fields.POINT_DISPLACEMENT; import static eu.engys.core.project.zero.fields.Fields.SMOKE; import static eu.engys.core.project.zero.fields.Fields.T; import static eu.engys.core.project.zero.fields.Fields.U; @@ -62,6 +61,8 @@ import eu.engys.core.project.zero.fields.Fields; public class MergeBoundaryConditions { private static final Logger logger = LoggerFactory.getLogger(MergeBoundaryConditions.class); + + private static final boolean VERBOSE = false; private Patches patches; private Fields fields; @@ -74,7 +75,7 @@ public class MergeBoundaryConditions { public void execute() { for (Patch patch : patches) { String name = patch.getName(); - logger.info("Merging boundary condition for patch {}", name); + logger.debug("Merging boundary condition for patch {}", name); // System.out.println("*** patch "+name+" ***"); Patches[] parallelPatches = patches.getParallelPatches(); if (parallelPatches != null) { @@ -99,6 +100,18 @@ public class MergeBoundaryConditions { } private void merge(BoundaryConditions source, BoundaryConditions target) { + mergeMomentum(source, target); + mergeTurbulence(source, target); + mergeRoughness(source, target); + mergeThermal(source, target); + mergeHumidity(source, target); + mergeRadiation(source, target); + mergePassiveScalars(source, target); + mergePhase(source, target); + mergeDisplacement(source, target); + } + + private void mergeMomentum(BoundaryConditions source, BoundaryConditions target) { if (!source.getMomentum().isEmpty()) { mergeField(source.getMomentum(), target.getMomentum(), U); for (Field U : fields.getMultiphaseUFields()) { @@ -106,6 +119,9 @@ public class MergeBoundaryConditions { } mergeField(source.getMomentum(), target.getMomentum(), P); } + } + + private void mergeTurbulence(BoundaryConditions source, BoundaryConditions target) { if (!source.getTurbulence().isEmpty()) { mergeField(source.getTurbulence(), target.getTurbulence(), K); mergeField(source.getTurbulence(), target.getTurbulence(), OMEGA); @@ -118,22 +134,37 @@ public class MergeBoundaryConditions { mergeField(source.getTurbulence(), target.getTurbulence(), ALPHA_T); mergeField(source.getTurbulence(), target.getTurbulence(), ALPHA_SGS); } + } + + private void mergeRoughness(BoundaryConditions source, BoundaryConditions target) { if (!source.getRoughness().isEmpty()) { mergeField(source.getRoughness(), target.getRoughness(), NUT); mergeField(source.getRoughness(), target.getRoughness(), NU_SGS); mergeField(source.getRoughness(), target.getRoughness(), MUT); mergeField(source.getRoughness(), target.getRoughness(), MU_SGS); } + } + + private void mergeThermal(BoundaryConditions source, BoundaryConditions target) { if (!source.getThermal().isEmpty()) { mergeField(source.getThermal(), target.getThermal(), T); } + } + + private void mergeHumidity(BoundaryConditions source, BoundaryConditions target) { if (!source.getHumidity().isEmpty()) { mergeField(source.getHumidity(), target.getHumidity(), W); mergeField(source.getHumidity(), target.getHumidity(), DT_W); } + } + + private void mergeRadiation(BoundaryConditions source, BoundaryConditions target) { if (!source.getRadiation().isEmpty()) { mergeField(source.getRadiation(), target.getRadiation(), IDEFAULT); } + } + + private void mergePassiveScalars(BoundaryConditions source, BoundaryConditions target) { if (!source.getPassiveScalars().isEmpty()) { mergeField(source.getPassiveScalars(), target.getPassiveScalars(), AOA); mergeField(source.getPassiveScalars(), target.getPassiveScalars(), DT_AOA); @@ -142,6 +173,9 @@ public class MergeBoundaryConditions { mergeField(source.getPassiveScalars(), target.getPassiveScalars(), SMOKE); mergeField(source.getPassiveScalars(), target.getPassiveScalars(), DT_SMOKE); } + } + + private void mergePhase(BoundaryConditions source, BoundaryConditions target) { if (!source.getPhase().isEmpty()) { mergeField(source.getPhase(), target.getPhase(), ETA); for (Field af : fields.getAlphaFields()) { @@ -149,23 +183,29 @@ public class MergeBoundaryConditions { } } } + + private void mergeDisplacement(BoundaryConditions source, BoundaryConditions target) { + if (!source.getDisplacement().isEmpty()) { + mergeField(source.getDisplacement(), target.getDisplacement(), POINT_DISPLACEMENT); + } + } - private void mergeField(Dictionary source, Dictionary target, String field) { + static void mergeField(Dictionary source, Dictionary target, String field) { if (source.isDictionary(field) /* && target.isDictionary(field) */) { Dictionary fieldSource = source.subDict(field); // Dictionary fieldTarget = target.subDict(field); if (BoundaryConditions.isPlaceHolder(fieldSource)) { - // System.out.println("\t\t"+field+" PH"); + info("\t\t"+field+" PH"); /* DO NOTHING */ } else { - // System.out.println("\t\t"+field+" UN"); + info("\t\t"+field+" UN"); target.add(new Dictionary(fieldSource)); } } else if (source.isDictionary(field)) { - // System.err.println("ERROR: missing TARGET "+field+" dictionary"); + info("ERROR: missing TARGET "+field+" dictionary"); } else { - // System.err.println("ERROR: missing SOURCE "+field+" dictionary"); + info("ERROR: missing SOURCE "+field+" dictionary"); // System.out.println(""+source+target); } } @@ -196,6 +236,9 @@ public class MergeBoundaryConditions { mergeExcludingNonUniform(source.getRoughness(), target.getRoughness(), MUT); mergeExcludingNonUniform(source.getRoughness(), target.getRoughness(), MU_SGS); } + if (!source.getDisplacement().isEmpty()) { + mergeExcludingNonUniform(source.getDisplacement(), target.getDisplacement(), POINT_DISPLACEMENT); + } if (!source.getThermal().isEmpty()) { mergeExcludingNonUniform(source.getThermal(), target.getThermal(), T); } @@ -275,6 +318,9 @@ public class MergeBoundaryConditions { excludeNonUniform(target.getRoughness(), MUT); excludeNonUniform(target.getRoughness(), MU_SGS); } + if (!target.getDisplacement().isEmpty()) { + excludeNonUniform(target.getDisplacement(), POINT_DISPLACEMENT); + } if (!target.getThermal().isEmpty()) { excludeNonUniform(target.getThermal(), T); } @@ -302,7 +348,7 @@ public class MergeBoundaryConditions { } private void excludeNonUniform(Dictionary target, String field) { - if (target.isDictionary(field) && target.isDictionary(field)) { + if (target.isDictionary(field)) { Dictionary fieldTarget = target.subDict(field); if (BoundaryConditions.isNonUniform(fieldTarget)) { if (field.equals(Fields.U)) { @@ -313,5 +359,9 @@ public class MergeBoundaryConditions { } } } + + private static void info(String msg) { + if (VERBOSE) System.err.println(msg); + } } diff --git a/src/eu/engys/core/project/zero/patches/Patch.java b/src/eu/engys/core/project/zero/patches/Patch.java index 4061310..62d28ca 100644 --- a/src/eu/engys/core/project/zero/patches/Patch.java +++ b/src/eu/engys/core/project/zero/patches/Patch.java @@ -1,42 +1,49 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.zero.patches; -import vtk.vtkPolyData; +import org.apache.commons.lang.builder.EqualsBuilder; +import org.apache.commons.lang.builder.HashCodeBuilder; + import eu.engys.core.dictionary.Dictionary; import eu.engys.util.ui.checkboxtree.LoadableItem; import eu.engys.util.ui.checkboxtree.VisibleItem; +import vtk.vtkPolyData; public class Patch implements VisibleItem, LoadableItem { + + public static final String TYPE_KEY = "type"; + public static final String N_FACES_KEY = "nFaces"; + public static final String OFFSETS_KEY = "offsets"; + public static final String PHYSICAL_TYPE_KEY = "physicalType"; + public static final String START_FACE_KEY = "startFace"; public static final int NONE = -1; private final String originalName; private String name; - private BoundaryType phisicalType; + private BoundaryType physicalType; private String type; private boolean visible; private boolean loaded; @@ -50,41 +57,44 @@ public class Patch implements VisibleItem, LoadableItem { } public Patch(Patch patch) { - this.originalName = patch.originalName; - this.name = patch.name; - this.phisicalType = patch.phisicalType; - this.type = patch.type; - this.visible = patch.visible; - this.loaded = patch.loaded; - this.boundaryConditions = new BoundaryConditions(patch.boundaryConditions); - this.dictionary = new Dictionary(patch.getDictionary()); - } + this.originalName = patch.originalName; + this.name = patch.name; + this.physicalType = patch.physicalType; + this.type = patch.type; + this.visible = patch.visible; + this.loaded = patch.loaded; + this.boundaryConditions = new BoundaryConditions(patch.boundaryConditions); + this.dictionary = new Dictionary(patch.getDictionary()); + } - public String getOriginalName() { + public String getOriginalName() { return originalName; } public String getName() { return name; } + public void setName(String name) { this.name = name; } - public BoundaryType getPhisicalType() { - return phisicalType; + public BoundaryType getPhysicalType() { + return physicalType; } - public void setPhisicalType(BoundaryType type) { - this.phisicalType = type; + + public void setPhysicalType(BoundaryType type) { + this.physicalType = type; } public String getType() { return type; } + public void setType(String type) { this.type = type; } - + @Override public boolean isVisible() { return visible; @@ -99,7 +109,7 @@ public class Patch implements VisibleItem, LoadableItem { public boolean isLoaded() { return loaded; } - + @Override public void setLoaded(boolean loaded) { this.loaded = loaded; @@ -115,16 +125,7 @@ public class Patch implements VisibleItem, LoadableItem { @Override public String toString() { - return name + " [ type: " + phisicalType.getLabel() + ", visible: " + visible + ", loaded: " + loaded + "]"; - } - - @Override - public boolean equals(Object obj) { - if (obj instanceof Patch) { - return getName().equals(((Patch) obj).getName()); - } else { - return super.equals(obj); - } + return name + " [ type: " + physicalType.getLabel() + ", visible: " + visible + ", loaded: " + loaded + "]"; } public void setEmpty(boolean b) { @@ -146,9 +147,32 @@ public class Patch implements VisibleItem, LoadableItem { public vtkPolyData getDataSet() { return dataSet; } - + public void setDataSet(vtkPolyData dataSet) { this.dataSet = dataSet; } + public void resetToDefault(){ + setPhysicalType(BoundaryType.getDefaultType()); + setDictionary(new Dictionary("")); + setBoundaryConditions(new BoundaryConditions(BoundaryConditionsDefaults.get(BoundaryType.getDefaultKey()))); + } + + @Override + public boolean equals(Object obj) { + if (!(obj instanceof Patch)) { + return false; + } + if (obj == this) { + return true; + } + Patch patch = (Patch) obj; + return new EqualsBuilder().append(name, patch.name).isEquals(); + } + + @Override + public int hashCode() { + return new HashCodeBuilder(17, 31).append(name).toHashCode(); + } + } diff --git a/src/eu/engys/core/project/zero/patches/Patches.java b/src/eu/engys/core/project/zero/patches/Patches.java index f41a571..bd201bd 100644 --- a/src/eu/engys/core/project/zero/patches/Patches.java +++ b/src/eu/engys/core/project/zero/patches/Patches.java @@ -1,29 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.zero.patches; import java.util.ArrayList; @@ -37,127 +35,153 @@ import eu.engys.util.PrefUtil; public class Patches extends ArrayList { - private Patches[] parallelPatches; + private Patches[] parallelPatches; - public Patches() { - super(); - } + public Patches() { + super(); + } - public Map toMap() { - Map patchesMap = new HashMap(); - for (Patch patch : this) { - patchesMap.put(patch.getName(), patch); - } - return Collections.unmodifiableMap(patchesMap); - } + public Map toMap() { + Map patchesMap = new HashMap(); + for (Patch patch : this) { + patchesMap.put(patch.getName(), patch); + } + return Collections.unmodifiableMap(patchesMap); + } - public void print() { - for (Patch patch : this) { - System.err.println(" >>>>>>>>>> " + patch.getName()+", hash: "+patch.hashCode()); - System.err.println(patch.getBoundaryConditions().toDictionary()); - } - } + public void print() { + for (Patch patch : this) { + System.err.println(" >>>>>>>>>> " + patch.getName() + ", hash: " + patch.hashCode()); + System.err.println(patch.getBoundaryConditions().toDictionary()); + } + } - public Patches filterProcBoundary() { - Patches nonProcPatches = new Patches(); - for (Patch p : this) { - if (!p.getPhisicalType().isProcessor() && !p.getPhisicalType().isProcessorCyclic()) { - nonProcPatches.add(p); - } - } - return nonProcPatches; - } + public Patches filterProcBoundary() { + Patches nonProcPatches = new Patches(); + for (Patch p : this) { + if (!p.getPhysicalType().isProcessor() && !p.getPhysicalType().isProcessorCyclic()) { + nonProcPatches.add(p); + } + } + return nonProcPatches; + } - public Patches patchesToDisplay() { - Patches patches = new Patches(); - for (Patch patch : this) { - Boolean hideEmptyPatches = PrefUtil.getBoolean(PrefUtil.HIDE_EMPTY_PATCHES); - if ( (patch.isEmpty() && hideEmptyPatches) || patch.getPhisicalType().isProcessor() || patch.getPhisicalType().isProcessorCyclic()) { - continue; - } - patches.add(patch); - } - return patches; - } + public Patches getOutlets() { + Patches outletPatches = new Patches(); + for (Patch p : this) { + if (p.getPhysicalType().isOutlet()) { + outletPatches.add(p); + } + } + return outletPatches; + } - public void printBoundaryConditions(int procIndex, int patchIndex) { - if (procIndex < 0) { - for (int i = 0; i < parallelPatches.length; i++) { - Patch patch = parallelPatches[i].get(patchIndex); - System.out.println("PATCHES PRINT BOUNDARY CONDITIONS processor " + i + ", patch: " + patch.getName() + " " + patch.getBoundaryConditions().toDictionary()); - } - } else { - Patch patch = parallelPatches[procIndex].get(patchIndex); - System.out.println("PATCHES PRINT BOUNDARY CONDITIONS processor " + procIndex + ", patch: " + patch.getName() + " " + patch.getBoundaryConditions().toDictionary()); - } - } + public Patches patchesToDisplay() { + Patches patches = new Patches(); + for (Patch patch : this) { + Boolean hideEmptyPatches = PrefUtil.getBoolean(PrefUtil.HIDE_EMPTY_PATCHES); + Boolean hideProcessorPatches = PrefUtil.getBoolean(PrefUtil.HIDE_PROCESSOR_PATCHES); + Boolean hideProcessorCyclicPatches = PrefUtil.getBoolean(PrefUtil.HIDE_PROCESSOR_CYCLIC_PATCHES); - public void setParallelPatches(Patches[] parallelPatches) { - this.parallelPatches = parallelPatches; - } + boolean shouldSkip1 = patch.isEmpty() && hideEmptyPatches; + boolean shouldSkip2 = patch.getPhysicalType().isProcessor() && hideProcessorPatches; + boolean shouldSkip3 = patch.getPhysicalType().isProcessorCyclic() && hideProcessorCyclicPatches; - public Patches[] getParallelPatches() { - return parallelPatches; - } + if (shouldSkip1 || shouldSkip2 || shouldSkip3) { + continue; + } + patches.add(patch); + } + return patches; + } - public Patches getPatchesOfProcessor(int processor) { - return parallelPatches[processor]; - } + public void printBoundaryConditions(int procIndex, int patchIndex) { + if (procIndex < 0) { + for (int i = 0; i < parallelPatches.length; i++) { + Patch patch = parallelPatches[i].get(patchIndex); + System.out.println("PATCHES PRINT BOUNDARY CONDITIONS processor " + i + ", patch: " + patch.getName() + " " + patch.getBoundaryConditions().toDictionary()); + } + } else { + Patch patch = parallelPatches[procIndex].get(patchIndex); + System.out.println("PATCHES PRINT BOUNDARY CONDITIONS processor " + procIndex + ", patch: " + patch.getName() + " " + patch.getBoundaryConditions().toDictionary()); + } + } - public void clearBoundaryConditions() { - for (Patch patch : this) { - patch.setBoundaryConditions(new BoundaryConditions()); - } - if (parallelPatches != null) { - for (Patches patches : parallelPatches) { - patches.clearBoundaryConditions(); - } - } - } - - public boolean addPatches(Collection c) { - if (parallelPatches != null) { - for (Patches patches : parallelPatches) { - for (Patch patch : c) { - patches.add(new Patch(patch)); - } - } - } - return super.addAll(c); - } + public void setParallelPatches(Patches[] parallelPatches) { + this.parallelPatches = parallelPatches; + } - public void newParallelPatches(int processors) { - parallelPatches = new Patches[processors]; - for (int i = 0; i < parallelPatches.length; i++) { - parallelPatches[i] = new Patches(); - } - } - - public List patchesNames() { - List names = new ArrayList<>(); - for (Patch patch : this) { + public Patches[] getParallelPatches() { + return parallelPatches; + } + + public Patches getPatchesOfProcessor(int processor) { + return parallelPatches[processor]; + } + + public void clearBoundaryConditions() { + for (Patch patch : this) { + patch.setBoundaryConditions(new BoundaryConditions()); + } + if (parallelPatches != null) { + for (Patches patches : parallelPatches) { + patches.clearBoundaryConditions(); + } + } + } + + public boolean addPatches(Collection c) { + if (parallelPatches != null) { + for (Patches patches : parallelPatches) { + for (Patch patch : c) { + patches.add(new Patch(patch)); + } + } + } + return super.addAll(c); + } + + public void newParallelPatches(int processors) { + parallelPatches = new Patches[processors]; + for (int i = 0; i < parallelPatches.length; i++) { + parallelPatches[i] = new Patches(); + } + } + + public List patchesNames() { + List names = new ArrayList<>(); + for (Patch patch : this) { names.add(patch.getName()); } return names; } - public List patchesNames(BoundaryType type) { - List names = new ArrayList<>(); - for (Patch patch : this) { - if (patch.getPhisicalType().equals(type)) { - names.add(patch.getName()); - } - } - return names; - } - - @Override - public String toString() { - StringBuffer sb = new StringBuffer(); - for (Patch patch : this) { - sb.append(patch.getName() + " - "); - } - return sb.toString(); - } + public List patchesNames(BoundaryType type) { + List names = new ArrayList<>(); + for (Patch patch : this) { + if (patch.getPhysicalType().equals(type)) { + names.add(patch.getName()); + } + } + return names; + } + + @Override + public String toString() { + StringBuffer sb = new StringBuffer(); + for (Patch patch : this) { + sb.append(patch.getName() + " - "); + } + return sb.toString(); + } + + public Patch getPatchByName(String name) { + for (Patch patch : this) { + if (patch.getName().equals(name)) { + return patch; + } + } + return null; + } } diff --git a/src/eu/engys/core/project/zero/patches/PatchesReader.java b/src/eu/engys/core/project/zero/patches/PatchesReader.java index 63ac7a8..00b5caf 100644 --- a/src/eu/engys/core/project/zero/patches/PatchesReader.java +++ b/src/eu/engys/core/project/zero/patches/PatchesReader.java @@ -1,30 +1,39 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.zero.patches; +import static eu.engys.core.project.zero.patches.BoundaryType.OPENING; +import static eu.engys.core.project.zero.patches.BoundaryType.OPENING_KEY; +import static eu.engys.core.project.zero.patches.BoundaryType.PATCH; +import static eu.engys.core.project.zero.patches.BoundaryType.PROCESSOR; +import static eu.engys.core.project.zero.patches.BoundaryType.PROCESSOR_CYCLIC; +import static eu.engys.core.project.zero.patches.BoundaryType.WALL; +import static eu.engys.core.project.zero.patches.Patch.N_FACES_KEY; +import static eu.engys.core.project.zero.patches.Patch.PHYSICAL_TYPE_KEY; +import static eu.engys.core.project.zero.patches.Patch.TYPE_KEY; + import java.io.File; import java.util.ArrayList; import java.util.List; @@ -36,6 +45,7 @@ import org.slf4j.LoggerFactory; import eu.engys.core.dictionary.Dictionary; import eu.engys.core.dictionary.DictionaryUtils; +import eu.engys.core.project.Model; import eu.engys.util.IOUtils; import eu.engys.util.progress.ProgressMonitor; import eu.engys.util.ui.ExecUtil; @@ -44,8 +54,10 @@ public class PatchesReader { private static final Logger logger = LoggerFactory.getLogger(Patches.class); private ProgressMonitor monitor; + private Model model; - public PatchesReader(ProgressMonitor monitor) { + public PatchesReader(Model model, ProgressMonitor monitor) { + this.model = model; this.monitor = monitor; } @@ -53,7 +65,7 @@ public class PatchesReader { Patches patches = new Patches(); final Patches[] parallelPatches = new Patches[boundaryFiles.length]; - + Runnable[] runnables = new Runnable[boundaryFiles.length]; for (int i = 0; i < boundaryFiles.length; i++) { final File boundary = boundaryFiles[i]; @@ -100,14 +112,15 @@ public class PatchesReader { String patchesString = matcher.group(2); Dictionary dict = DictionaryUtils.readDictionary(patchesString); List notKnownPatches = new ArrayList(); - for (Dictionary patch : dict.getDictionaries()) { - Patch bm = dictToPatch(notKnownPatches, patch); + for (Dictionary patchDict : dict.getDictionaries()) { + Patch bm = dictToPatch(model, notKnownPatches, patchDict); patches.add(bm); } monitor.setCurrent(null, monitor.getCurrent() + 1, 2); if (!nPatch.isEmpty() && Integer.parseInt(nPatch) != patches.size()) { monitor.error("Number of read patches (" + patches.size() + ") is invalid (expected " + nPatch + ").", 2); + logger.error("Number of read patches (" + patches.size() + ") is invalid (expected " + nPatch + ")."); } else if (!notKnownPatches.isEmpty()) { StringBuilder sb = new StringBuilder(); sb.append("Unknown patches type: \n"); @@ -115,6 +128,7 @@ public class PatchesReader { sb.append("\t " + string + "\n"); } monitor.warning(sb.toString(), 2); + logger.warn(sb.toString()); } } } @@ -129,55 +143,63 @@ public class PatchesReader { return patches; } - public static Patch dictToPatch(List notKnownPatches, Dictionary patch) { - String patchName = patch.getName(); - String patchType = patch.lookup("type"); - String physicalType = patch.lookup("physicalType"); - String nFaces = patch.lookup("nFaces"); + public static Patch dictToPatch(Model model, List notKnownPatches, Dictionary d) { + String patchName = d.getName(); + String patchType = d.lookup(TYPE_KEY); + String physicalType = d.lookup(PHYSICAL_TYPE_KEY); + String nFaces = d.lookup(N_FACES_KEY); - Patch bm = new Patch(patchName); - bm.setDictionary(patch); - bm.setName(patchName); - bm.setVisible(true); - bm.setEmpty(nFaces != null && Integer.valueOf(nFaces) == 0); - bm.setType(patchType); + Patch patch = new Patch(patchName); + patch.setDictionary(d); + patch.setName(patchName); + patch.setVisible(true); + patch.setEmpty(nFaces != null && Integer.valueOf(nFaces) == 0); + patch.setType(patchType); if (BoundaryType.isPatch(patchType)) { - if (BoundaryType.isKnown(physicalType)) { - bm.setPhisicalType(BoundaryType.getType(physicalType)); - } else if (BoundaryType.isKnown(BoundaryType.OPENING_KEY)) { - bm.setPhisicalType(BoundaryType.OPENING); + boolean isCoupled = model.getState() != null && model.getState().isCoupled(); + if (isCoupled && BoundaryType.isSymmetryPhysicalType(physicalType)) { + patch.setPhysicalType(BoundaryType.SYMMETRY_PLANE); + } else if (BoundaryType.isKnown(physicalType)) { + patch.setPhysicalType(BoundaryType.getType(physicalType)); } else { - bm.setPhisicalType(BoundaryType.PATCH); + if (BoundaryType.isKnown(OPENING_KEY)) { + patch.setPhysicalType(OPENING); + } else { + patch.setPhysicalType(PATCH); + } } } else if (BoundaryType.isWall(patchType)) { if (BoundaryType.isKnown(physicalType)) { - bm.setPhisicalType(BoundaryType.getType(physicalType)); + patch.setPhysicalType(BoundaryType.getType(physicalType)); } else { - bm.setPhisicalType(BoundaryType.WALL); + patch.setPhysicalType(WALL); } } else if (BoundaryType.isMappedPatch(patchType)) { if (BoundaryType.isKnown(physicalType)) { - bm.setPhisicalType(BoundaryType.getType(physicalType)); + patch.setPhysicalType(BoundaryType.getType(physicalType)); } else { - bm.setPhisicalType(BoundaryType.WALL); + patch.setPhysicalType(WALL); } } else if (BoundaryType.isMappedWall(patchType)) { if (BoundaryType.isKnown(physicalType)) { - bm.setPhisicalType(BoundaryType.getType(physicalType)); + patch.setPhysicalType(BoundaryType.getType(physicalType)); } else { - bm.setPhisicalType(BoundaryType.WALL); + patch.setPhysicalType(WALL); } } else if (BoundaryType.isKnown(patchType)) { - bm.setPhisicalType(BoundaryType.getType(patchType)); + patch.setPhysicalType(BoundaryType.getType(patchType)); } else if (BoundaryType.isProcessor(patchType)) { - bm.setPhisicalType(BoundaryType.PROCESSOR); + patch.setPhysicalType(PROCESSOR); } else if (BoundaryType.isProcessorCyclic(patchType)) { - bm.setPhisicalType(BoundaryType.PROCESSOR_CYCLIC); + patch.setPhysicalType(PROCESSOR_CYCLIC); } else { notKnownPatches.add(patchName + ": " + patchType); - bm.setPhisicalType(BoundaryType.getDefaultType()); + patch.setPhysicalType(BoundaryType.getDefaultType()); } - return bm; + + logger.debug("[PATCH] name: {}, type: {}, physicaltype: {}", patch.getName(), patch.getType(), patch.getPhysicalType()); + + return patch; } } diff --git a/src/eu/engys/core/project/zero/patches/PatchesWriter.java b/src/eu/engys/core/project/zero/patches/PatchesWriter.java index 1437e22..e0f4058 100644 --- a/src/eu/engys/core/project/zero/patches/PatchesWriter.java +++ b/src/eu/engys/core/project/zero/patches/PatchesWriter.java @@ -1,31 +1,43 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.zero.patches; import static eu.engys.core.dictionary.Dictionary.TYPE; +import static eu.engys.core.project.zero.patches.BoundaryType.CYCLIC_AMI_KEY; +import static eu.engys.core.project.zero.patches.BoundaryType.CYCLIC_KEY; +import static eu.engys.core.project.zero.patches.BoundaryType.MAPPED_PATCH_KEY; +import static eu.engys.core.project.zero.patches.BoundaryType.MAPPED_WALL_KEY; +import static eu.engys.core.project.zero.patches.BoundaryType.PATCH_KEY; +import static eu.engys.core.project.zero.patches.BoundaryType.PROCESSOR_CYCLIC_KEY; +import static eu.engys.core.project.zero.patches.BoundaryType.PROCESSOR_KEY; +import static eu.engys.core.project.zero.patches.BoundaryType.SYMMETRY_KEY; +import static eu.engys.core.project.zero.patches.Patch.N_FACES_KEY; +import static eu.engys.core.project.zero.patches.Patch.OFFSETS_KEY; +import static eu.engys.core.project.zero.patches.Patch.PHYSICAL_TYPE_KEY; +import static eu.engys.core.project.zero.patches.Patch.START_FACE_KEY; +import static eu.engys.core.project.zero.patches.Patch.TYPE_KEY; import java.io.File; import java.io.FileWriter; @@ -49,12 +61,6 @@ import eu.engys.util.ui.ExecUtil; public class PatchesWriter { - public static final String OFFSETS_KEY = "offsets"; - public static final String TYPE_KEY = "type"; - public static final String PHYSICAL_TYPE_KEY = "physicalType"; - public static final String START_FACE_KEY = "startFace"; - public static final String N_FACES_KEY = "nFaces"; - private static final Logger logger = LoggerFactory.getLogger(Patches.class); private ProgressMonitor monitor; @@ -77,7 +83,7 @@ public class PatchesWriter { } }; } -// ExecUtil.execInParallelAndWait(runnables); + // ExecUtil.execInParallelAndWait(runnables); ExecUtil.execSerial(runnables); } @@ -85,13 +91,13 @@ public class PatchesWriter { monitor.setCurrent(null, monitor.getCurrent() + 1, 2); logger.info("WRITE: Boundary {}", boundaryFile.getAbsolutePath()); - Map originalNames = new HashMap(); - Map phisicalTypes = new HashMap(); - Map types = new HashMap(); - Map dictionaries = new HashMap(); + Map originalNames = new HashMap<>(); + Map phisicalTypes = new HashMap<>(); + Map types = new HashMap<>(); + Map dictionaries = new HashMap<>(); for (Patch patch : patches) { - phisicalTypes.put(patch.getName(), patch.getPhisicalType().getKey()); + phisicalTypes.put(patch.getName(), patch.getPhysicalType().getKey()); types.put(patch.getName(), patch.getType()); originalNames.put(patch.getOriginalName(), patch.getName()); dictionaries.put(patch.getName(), new Dictionary(patch.getDictionary())); @@ -127,20 +133,22 @@ public class PatchesWriter { patchDict.add(START_FACE_KEY, originalPatchDict.lookup(START_FACE_KEY)); if (phisicalTypes.containsKey(newName)) { - String phisicalType = phisicalTypes.get(newName); String type = types.get(newName); + String physicalType = phisicalTypes.get(newName); + + boolean isCoupled = model.getState() != null && model.getState().isCoupled(); - if (BoundaryType.isPatchPhysicalType(phisicalType)) { - patchDict.add(TYPE_KEY, "patch"); - patchDict.add(PHYSICAL_TYPE_KEY, phisicalType); - } else if (BoundaryType.isCoupledSymmetryPlaneType(phisicalType) && model.getState().getSolverType().isCoupled()) { - patchDict.add(TYPE_KEY, "patch"); - patchDict.add(PHYSICAL_TYPE_KEY, phisicalType); - } else if (BoundaryType.isWallPhysicalType(phisicalType)) { + if (BoundaryType.isPatchPhysicalType(physicalType)) { + patchDict.add(TYPE_KEY, PATCH_KEY); + patchDict.add(PHYSICAL_TYPE_KEY, physicalType); + } else if (isCoupled && BoundaryType.isSymmetryPlanePhysicalType(physicalType)) { + patchDict.add(TYPE_KEY, PATCH_KEY); + patchDict.add(PHYSICAL_TYPE_KEY, SYMMETRY_KEY); + } else if (BoundaryType.isFreeSurfacePhysicalType(physicalType)) { patchDict.add(TYPE_KEY, type); - patchDict.add(PHYSICAL_TYPE_KEY, phisicalType); + patchDict.add(PHYSICAL_TYPE_KEY, physicalType); - if (type.equals("mappedPatch") || type.equals("mappedWall")) { + if (type.equals(MAPPED_PATCH_KEY) || type.equals(MAPPED_WALL_KEY)) { patchDict.add(OFFSETS_KEY, originalPatchDict.lookup(OFFSETS_KEY)); Dictionary dictionary = dictionaries.get(newName); if (dictionary.found(N_FACES_KEY)) @@ -153,10 +161,10 @@ public class PatchesWriter { patchDict.merge(dictionary); } } else { - patchDict.add(TYPE, phisicalType); + patchDict.add(TYPE, physicalType); } - if (phisicalType.equals("cyclic") || phisicalType.equals("cyclicAMI") || phisicalType.equals("processor")) { + if (physicalType.equals(CYCLIC_KEY) || physicalType.equals(CYCLIC_AMI_KEY) || physicalType.equals(PROCESSOR_KEY) || physicalType.equals(PROCESSOR_CYCLIC_KEY)) { Dictionary dictionary = dictionaries.get(newName); if (dictionary.found(N_FACES_KEY)) dictionary.remove(N_FACES_KEY); diff --git a/src/eu/engys/core/project/zero/patches/SplitBoundaryConditions.java b/src/eu/engys/core/project/zero/patches/SplitBoundaryConditions.java index 29d2f1d..9bf335d 100644 --- a/src/eu/engys/core/project/zero/patches/SplitBoundaryConditions.java +++ b/src/eu/engys/core/project/zero/patches/SplitBoundaryConditions.java @@ -1,31 +1,32 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.project.zero.patches; +import static eu.engys.core.project.zero.fields.Fields.P; +import static eu.engys.core.project.zero.fields.Fields.U; + import java.util.Map; import org.slf4j.Logger; @@ -38,155 +39,193 @@ import eu.engys.core.project.zero.fields.Fields; public class SplitBoundaryConditions { public static boolean VERBOSE = false; - + private static final Logger logger = LoggerFactory.getLogger(SplitBoundaryConditions.class); - + private Patches patches; - private Fields fields; + private Fields fields; - public SplitBoundaryConditions(Patches patches, Fields fields) { - this.patches = patches; - this.fields = fields; - } + public SplitBoundaryConditions(Patches patches, Fields fields) { + this.patches = patches; + this.fields = fields; + } - public void execute() { - for (Patch patch : patches) { - String patchName = patch.getName(); + public void execute() { + for (Patch patch : patches) { + String patchName = patch.getName(); logger.info("Splitting boundary condition for patch {}", patchName); - // System.out.println("*** patch " + patchName + " *** " + - // patch.getBoundaryConditions().toDictionary()); - Patches[] parallelPatches = patches.getParallelPatches(); - if (parallelPatches != null) { - for (int i = 0; i < parallelPatches.length; i++) { - info("\t processor " + i); - Map patchesMap = parallelPatches[i].toMap(); - if (patchesMap.containsKey(patchName)) { - Patch parallelPatch = patchesMap.get(patchName); - parallelPatch.setPhisicalType(patch.getPhisicalType()); - if (patch.getBoundaryConditions() != null && parallelPatch.getBoundaryConditions() != null) { - // System.out.println("SplitBoundaryConditions.execute() split BEFORE "+patchName+parallelPatch.getBoundaryConditions().toDictionary()); - splitTo(patch.getBoundaryConditions(), parallelPatch.getBoundaryConditions()); - //System.out.println("SplitBoundaryConditions.execute() split AFTER "+patchName+parallelPatch.getBoundaryConditions().toDictionary()); - } else if (patch.getBoundaryConditions() == null) { - // System.out.println("SplitBoundaryConditions.execute() GUI patch "+patch.getName()+" has null BC"); - parallelPatch.setBoundaryConditions(null); - } else if (parallelPatch.getBoundaryConditions() == null) { - // System.out.println("SplitBoundaryConditions.execute() parallel patch "+patch.getName()+" has null BC"); - /* do nothing ? */ - } - } - } - } - } - } + // System.out.println("*** patch " + patchName + " *** " + patch.getBoundaryConditions().toDictionary()); + Patches[] parallelPatches = patches.getParallelPatches(); + if (parallelPatches != null) { + for (int i = 0; i < parallelPatches.length; i++) { + info("\t processor " + i); + Map patchesMap = parallelPatches[i].toMap(); + if (patchesMap.containsKey(patchName)) { + Patch parallelPatch = patchesMap.get(patchName); + parallelPatch.setPhysicalType(patch.getPhysicalType()); + if (patch.getBoundaryConditions() != null && parallelPatch.getBoundaryConditions() != null) { + // System.out.println("SplitBoundaryConditions.execute() split BEFORE "+patchName+parallelPatch.getBoundaryConditions().toDictionary()); + splitTo(patch.getBoundaryConditions(), parallelPatch.getBoundaryConditions()); + // System.out.println("SplitBoundaryConditions.execute() split AFTER "+patchName+parallelPatch.getBoundaryConditions().toDictionary()); + } else if (patch.getBoundaryConditions() == null) { + // System.out.println("SplitBoundaryConditions.execute() GUI patch "+patch.getName()+" has null BC"); + parallelPatch.setBoundaryConditions(null); + } else if (parallelPatch.getBoundaryConditions() == null) { + // System.out.println("SplitBoundaryConditions.execute() parallel patch "+patch.getName()+" has null BC"); + /* do nothing ? */ + } + } + } + } + } + } - public void splitTo(BoundaryConditions source, BoundaryConditions target) { - if (target.getMomentum() != null) { - splitField(source.getMomentum(), target.getMomentum(), Fields.U); + private void splitTo(BoundaryConditions source, BoundaryConditions target) { + splitMomentum(source, target); + splitTurbulence(source, target); + splitRoughness(source, target); + splitThermal(source, target); + splitHumidity(source, target); + splitRadiation(source, target); + splitPassiveScalars(source, target); + splitPhase(source, target); + splitDisplacement(source, target); + } + + private void splitMomentum(BoundaryConditions source, BoundaryConditions target) { + if (target.getMomentum() != null) { + splitField(source.getMomentum(), target.getMomentum(), U); for (Field U : fields.getMultiphaseUFields()) { splitField(source.getMomentum(), target.getMomentum(), U.getName()); } - splitField(source.getMomentum(), target.getMomentum(), Fields.P); - } - if (target.getTurbulence() != null) { - splitField(source.getTurbulence(), target.getTurbulence(), Fields.K); - splitField(source.getTurbulence(), target.getTurbulence(), Fields.OMEGA); - splitField(source.getTurbulence(), target.getTurbulence(), Fields.EPSILON); - splitField(source.getTurbulence(), target.getTurbulence(), Fields.NU_TILDA); - splitField(source.getTurbulence(), target.getTurbulence(), Fields.NUT); - splitField(source.getTurbulence(), target.getTurbulence(), Fields.NU_SGS); - splitField(source.getTurbulence(), target.getTurbulence(), Fields.MUT); - splitField(source.getTurbulence(), target.getTurbulence(), Fields.MU_SGS); - splitField(source.getTurbulence(), target.getTurbulence(), Fields.ALPHA_T); - splitField(source.getTurbulence(), target.getTurbulence(), Fields.ALPHA_SGS); - } - if (target.getRoughness() != null) { - splitField(source.getRoughness(), target.getRoughness(), Fields.NUT); - splitField(source.getRoughness(), target.getRoughness(), Fields.NU_SGS); - splitField(source.getRoughness(), target.getRoughness(), Fields.MUT); - splitField(source.getRoughness(), target.getRoughness(), Fields.MU_SGS); - } - if (target.getThermal() != null) { - splitField(source.getThermal(), target.getThermal(), Fields.T); - } - if (target.getHumidity() != null) { - splitField(source.getHumidity(), target.getHumidity(), Fields.W); - splitField(source.getHumidity(), target.getHumidity(), Fields.DT_W); - } - if (target.getRadiation() != null) { - splitField(source.getRadiation(), target.getRadiation(), Fields.IDEFAULT); - } - if (target.getPassiveScalars() != null) { - splitField(source.getPassiveScalars(), target.getPassiveScalars(), Fields.AOA); - splitField(source.getPassiveScalars(), target.getPassiveScalars(), Fields.DT_AOA); - splitField(source.getPassiveScalars(), target.getPassiveScalars(), Fields.CO2); - splitField(source.getPassiveScalars(), target.getPassiveScalars(), Fields.DT_CO2); - splitField(source.getPassiveScalars(), target.getPassiveScalars(), Fields.SMOKE); - splitField(source.getPassiveScalars(), target.getPassiveScalars(), Fields.DT_SMOKE); - } - if (target.getPhase() != null) { + splitField(source.getMomentum(), target.getMomentum(), P); + } + } + + private void splitTurbulence(BoundaryConditions source, BoundaryConditions target) { + if (target.getTurbulence() != null) { + splitField(source.getTurbulence(), target.getTurbulence(), Fields.K); + splitField(source.getTurbulence(), target.getTurbulence(), Fields.OMEGA); + splitField(source.getTurbulence(), target.getTurbulence(), Fields.EPSILON); + splitField(source.getTurbulence(), target.getTurbulence(), Fields.NU_TILDA); + splitField(source.getTurbulence(), target.getTurbulence(), Fields.NUT); + splitField(source.getTurbulence(), target.getTurbulence(), Fields.NU_SGS); + splitField(source.getTurbulence(), target.getTurbulence(), Fields.MUT); + splitField(source.getTurbulence(), target.getTurbulence(), Fields.MU_SGS); + splitField(source.getTurbulence(), target.getTurbulence(), Fields.ALPHA_T); + splitField(source.getTurbulence(), target.getTurbulence(), Fields.ALPHA_SGS); + } + } + + private void splitRoughness(BoundaryConditions source, BoundaryConditions target) { + if (target.getRoughness() != null) { + splitField(source.getRoughness(), target.getRoughness(), Fields.NUT); + splitField(source.getRoughness(), target.getRoughness(), Fields.NU_SGS); + splitField(source.getRoughness(), target.getRoughness(), Fields.MUT); + splitField(source.getRoughness(), target.getRoughness(), Fields.MU_SGS); + } + } + + private void splitThermal(BoundaryConditions source, BoundaryConditions target) { + if (target.getThermal() != null) { + splitField(source.getThermal(), target.getThermal(), Fields.T); + } + } + + private void splitHumidity(BoundaryConditions source, BoundaryConditions target) { + if (target.getHumidity() != null) { + splitField(source.getHumidity(), target.getHumidity(), Fields.W); + splitField(source.getHumidity(), target.getHumidity(), Fields.DT_W); + } + } + + private void splitRadiation(BoundaryConditions source, BoundaryConditions target) { + if (target.getRadiation() != null) { + splitField(source.getRadiation(), target.getRadiation(), Fields.IDEFAULT); + } + } + + private void splitPassiveScalars(BoundaryConditions source, BoundaryConditions target) { + if (target.getPassiveScalars() != null) { + splitField(source.getPassiveScalars(), target.getPassiveScalars(), Fields.AOA); + splitField(source.getPassiveScalars(), target.getPassiveScalars(), Fields.DT_AOA); + splitField(source.getPassiveScalars(), target.getPassiveScalars(), Fields.CO2); + splitField(source.getPassiveScalars(), target.getPassiveScalars(), Fields.DT_CO2); + splitField(source.getPassiveScalars(), target.getPassiveScalars(), Fields.SMOKE); + splitField(source.getPassiveScalars(), target.getPassiveScalars(), Fields.DT_SMOKE); + } + } + + private void splitPhase(BoundaryConditions source, BoundaryConditions target) { + if (target.getPhase() != null) { splitField(source.getPhase(), target.getPhase(), Fields.ETA); - for (Field af : fields.getAlphaFields()) { - splitField(source.getPhase(), target.getPhase(), af.getName()); - } - } - } + for (Field af : fields.getAlphaFields()) { + splitField(source.getPhase(), target.getPhase(), af.getName()); + } + } + } - private void splitField(Dictionary source, Dictionary target, String field) { - if (source.isDictionary(field) && target.isDictionary(field)) { - Dictionary fieldSource = source.subDict(field); - Dictionary fieldTarget = target.subDict(field); - if (haveSameType(fieldSource, fieldTarget)) { - if (BoundaryConditions.isPlaceHolder(fieldTarget)) { - if (BoundaryConditions.isPlaceHolder(fieldSource)) { - /* DO NOTHING */ - info("\t\t "+field+" (PH + PH) DO NOTHING"); - } else { - /* DO NOTHING */ - info("\t\t "+field+" (UN + PH) SAVE EXCLUDING UNIFORM"+target); - fieldTarget.merge(fieldSource, BoundaryConditions.PLACE_HOLDER_KEYS); - } - } else { - if (BoundaryConditions.isPlaceHolder(fieldSource)) { - /* BOH? */ - info("\t\t "+field+" (PH + UN) BOH?"+fieldSource+fieldTarget); - } else { - /* SAVE */ - if (BoundaryConditions.isNonUniform(fieldSource)) { - /* DO NOTHING */ - info("\t\t "+field+" (NUN + UN) DO NOTHING"); - fieldTarget.merge(fieldSource, BoundaryConditions.PLACE_HOLDER_KEYS); - } else { - info("\t\t "+field+" (UN + UN) SAVE"); - // System.out.println("SplitBoundaryConditions.splitField() SOURCE BEFORE "+fieldSource); - // System.out.println("SplitBoundaryConditions.splitField() TARGET BEFORE "+fieldTarget); - fieldTarget.clear(); - fieldTarget.merge(fieldSource); - // System.out.println("SplitBoundaryConditions.splitField() SOURCE AFTER "+fieldSource); - // System.out.println("SplitBoundaryConditions.splitField() TARGET AFTER "+fieldTarget); - } - } - } - } else { - // System.err.println("ERROR: different type for "+field+" dictionary"); - fieldTarget.clear(); - fieldTarget.merge(fieldSource); - } - } else if (source.isDictionary(field) && !target.isDictionary(field)) { - // System.err.println("ERROR: missing target "+field+" dictionary"); - } else if (!source.isDictionary(field) && target.isDictionary(field)) { - // System.err.println("ERROR: missing source "+field+" dictionary"); - } else { - // System.err.println("ERROR: missing both "+field+" dictionary"); - } - } + private void splitDisplacement(BoundaryConditions source, BoundaryConditions target) { + if (target.getDisplacement() != null) { + splitField(source.getDisplacement(), target.getDisplacement(), Fields.POINT_DISPLACEMENT); + } + } - private static void info(String msg) { + static void splitField(Dictionary source, Dictionary target, String field) { + if (source.isDictionary(field) && target.isDictionary(field)) { + Dictionary fieldSource = source.subDict(field); + Dictionary fieldTarget = target.subDict(field); + if (haveSameType(fieldSource, fieldTarget)) { + if (BoundaryConditions.isPlaceHolder(fieldTarget)) { + if (BoundaryConditions.isPlaceHolder(fieldSource)) { + /* DO NOTHING */ + info("\t\t " + field + " (PH + PH) DO NOTHING"); + } else { + /* DO NOTHING */ + info("\t\t " + field + " (UN + PH) SAVE EXCLUDING UNIFORM" + target); + fieldTarget.merge(fieldSource, BoundaryConditions.PLACE_HOLDER_KEYS); + } + } else { + if (BoundaryConditions.isPlaceHolder(fieldSource)) { + /* BOH? */ + info("\t\t " + field + " (PH + UN) BOH?" + fieldSource + fieldTarget); + } else { + /* SAVE */ + if (BoundaryConditions.isNonUniform(fieldSource)) { + /* DO NOTHING */ + info("\t\t " + field + " (NUN + UN) DO NOTHING"); + fieldTarget.merge(fieldSource, BoundaryConditions.PLACE_HOLDER_KEYS); + } else { + info("\t\t " + field + " (UN + UN) SAVE"); + // System.out.println("SplitBoundaryConditions.splitField() SOURCE BEFORE "+fieldSource); + // System.out.println("SplitBoundaryConditions.splitField() TARGET BEFORE "+fieldTarget); + fieldTarget.clear(); + fieldTarget.merge(fieldSource); + // System.out.println("SplitBoundaryConditions.splitField() SOURCE AFTER "+fieldSource); + // System.out.println("SplitBoundaryConditions.splitField() TARGET AFTER "+fieldTarget); + } + } + } + } else { + // System.err.println("ERROR: different type for "+field+" dictionary"); + fieldTarget.clear(); + fieldTarget.merge(fieldSource); + } + } else if (source.isDictionary(field) && !target.isDictionary(field)) { + // System.err.println("ERROR: missing target "+field+" dictionary"); + } else if (!source.isDictionary(field) && target.isDictionary(field)) { + // System.err.println("ERROR: missing source "+field+" dictionary"); + } else { + // System.err.println("ERROR: missing both "+field+" dictionary"); + } + } + + private static void info(String msg) { if (VERBOSE) System.err.println(msg); } - private boolean haveSameType(Dictionary d1, Dictionary d2) { - return d1.isField("type") && d2.isField("type") && d1.lookup("type").equals(d2.lookup("type")); - } + private static boolean haveSameType(Dictionary d1, Dictionary d2) { + return d1.isField("type") && d2.isField("type") && d1.lookup("type").equals(d2.lookup("type")); + } } diff --git a/src/eu/engys/core/report/Exporter.java b/src/eu/engys/core/report/Exporter.java index b3b5f37..82fdb33 100644 --- a/src/eu/engys/core/report/Exporter.java +++ b/src/eu/engys/core/report/Exporter.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.report; import java.io.File; @@ -57,14 +56,18 @@ public abstract class Exporter { monitor.setTotal(parsers.size()); TimeBlocks blocks = new TimeBlocks(); - for (int i = 0; i < parsers.size(); i++) { - Parser parser = parsers.get(i); + for (Parser parser : parsers) { monitor.info(PARSING_LOG_FILE + parser.getFile(), 1); parser.init(); - blocks.addAll(parser.updateParsing()); + TimeBlocks parsedBlocks = parser.updateParsing(); + blocks.setKey(parsedBlocks.getKey()); + blocks.addAll(parsedBlocks); parser.end(); monitor.setCurrent(null, monitor.getCurrent() + 1); } + + blocks.orderAscending(); + return blocks; } @@ -102,9 +105,7 @@ public abstract class Exporter { exporter.show(reportFile); } - protected void populateCSVFile(CSVWriter writer) throws Exception { - - } + protected abstract void populateCSVFile(CSVWriter writer) throws Exception; protected void addRow(CSVWriter writer, String string) { writer.writeNext(new String[] { string }); diff --git a/src/eu/engys/core/report/excel/CSVExporter.java b/src/eu/engys/core/report/excel/CSVExporter.java index ad771a0..191cea9 100644 --- a/src/eu/engys/core/report/excel/CSVExporter.java +++ b/src/eu/engys/core/report/excel/CSVExporter.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.report.excel; import java.io.File; diff --git a/src/eu/engys/core/report/excel/CSVUtils.java b/src/eu/engys/core/report/excel/CSVUtils.java new file mode 100644 index 0000000..2e9044d --- /dev/null +++ b/src/eu/engys/core/report/excel/CSVUtils.java @@ -0,0 +1,75 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.core.report.excel; + +import java.io.File; +import java.io.FileReader; +import java.util.List; + +import javax.swing.Icon; + +import org.apache.commons.lang.math.NumberUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import au.com.bytecode.opencsv.CSVReader; +import eu.engys.util.ui.ResourcesUtil; + +public class CSVUtils { + + public static final String IMPORT_CSV_LABEL = "import.csv.button"; + public static final String IMPORT_CSV_TOOLTIP = "Import data from a comma-separated values file"; + public static final Icon IMPORT_CSV_ICON = ResourcesUtil.getIcon("file.icon"); + + private static final Logger logger = LoggerFactory.getLogger(CSVUtils.class); + + public static Double[][] readDoubleMatrix(File file, int colSize) { + try (CSVReader reader = new CSVReader(new FileReader(file))) { + List dataRead = reader.readAll(); + Double[][] data = new Double[dataRead.size()][colSize]; + for (int i = 0; i < dataRead.size(); i++) { + String[] stringRow = dataRead.get(i); + Double[] doubleRow = new Double[colSize]; + for (int j = 0; j < colSize; j++) { + if (stringRow.length < colSize && j >= stringRow.length) { + doubleRow[j] = 0.0; + } else { + if (NumberUtils.isNumber(stringRow[j])) { + doubleRow[j] = Double.valueOf(stringRow[j]); + } else { + doubleRow[j] = 0.0; + } + } + } + data[i] = doubleRow; + } + return data; + } catch (Exception e) { + logger.error("Error reading file", e); + } + return new Double[0][0]; + } + +} diff --git a/src/eu/engys/core/report/excel/ExcelExporter.java b/src/eu/engys/core/report/excel/ExcelExporter.java index f924b85..9c5c291 100644 --- a/src/eu/engys/core/report/excel/ExcelExporter.java +++ b/src/eu/engys/core/report/excel/ExcelExporter.java @@ -1,41 +1,35 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.report.excel; -import static eu.engys.util.ui.FileChooserUtils.EXCEL_EXTENSION_NEW; - import java.io.File; import java.io.FileOutputStream; import java.util.ArrayList; import java.util.List; -import org.apache.commons.io.FilenameUtils; -import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.ss.usermodel.Workbook; -import org.apache.poi.xssf.usermodel.XSSFWorkbook; import eu.engys.core.executor.FileManagerSupport; import eu.engys.core.project.system.monitoringfunctionobjects.Parser; @@ -58,12 +52,7 @@ public abstract class ExcelExporter { } public void create(File reportFile) throws Exception { - Workbook workbook = null; - if (FilenameUtils.getExtension(reportFile.getAbsolutePath()).equals(EXCEL_EXTENSION_NEW)) { - workbook = new XSSFWorkbook(); - } else { - workbook = new HSSFWorkbook(); - } + Workbook workbook = ExcelUtils.getWoorkBook(reportFile); populate(workbook); end(workbook, reportFile); } diff --git a/src/eu/engys/core/report/excel/ExcelUtils.java b/src/eu/engys/core/report/excel/ExcelUtils.java index b2483af..9f57b31 100644 --- a/src/eu/engys/core/report/excel/ExcelUtils.java +++ b/src/eu/engys/core/report/excel/ExcelUtils.java @@ -1,32 +1,42 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.core.report.excel; +import static eu.engys.util.ui.FileChooserUtils.EXCEL_EXTENSION_NEW; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; + +import javax.swing.Icon; import javax.vecmath.Point3d; +import org.apache.commons.io.FilenameUtils; +import org.apache.poi.hssf.usermodel.HSSFCell; +import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.CellStyle; import org.apache.poi.ss.usermodel.Font; @@ -34,51 +44,189 @@ import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.ss.util.CellRangeAddress; +import org.apache.poi.xssf.usermodel.XSSFWorkbook; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import eu.engys.util.ui.ResourcesUtil; public class ExcelUtils { - public static void addHeaderCell(Workbook workbook, Row row, int col, String value) { - Cell cell = row.createCell(col); - cell.setCellValue(value); + public static final String IMPORT_XLS_LABEL = "import.xls.button"; + public static final String IMPORT_XLS_TOOLTIP = "Import data from an Excel file"; + public static final Icon IMPORT_XLS_ICON = ResourcesUtil.getIcon("file.excel"); - Font font = workbook.createFont(); - font.setBoldweight(Font.BOLDWEIGHT_BOLD); + private static final Logger logger = LoggerFactory.getLogger(ExcelUtils.class); - CellStyle cellStyle = workbook.createCellStyle(); - cellStyle.setFont(font); - cellStyle.setAlignment(CellStyle.ALIGN_CENTER); - cellStyle.setVerticalAlignment(CellStyle.VERTICAL_CENTER); - cell.setCellStyle(cellStyle); - } + public static Workbook getWoorkBook(File excelFile) { + if (FilenameUtils.getExtension(excelFile.getAbsolutePath()).equals(EXCEL_EXTENSION_NEW)) { + return new XSSFWorkbook(); + } else { + return new HSSFWorkbook(); + } + } - public static void addEmptyCell(Workbook workbook, Row row, int col) { - row.createCell(col).setCellValue(""); - } + public static Workbook getWoorkBook(File excelFile, FileInputStream inputStream) throws IOException { + if (FilenameUtils.getExtension(excelFile.getAbsolutePath()).equals(EXCEL_EXTENSION_NEW)) { + return new XSSFWorkbook(inputStream); + } else { + return new HSSFWorkbook(inputStream); + } + } - public static void addDoubleCell(Sheet sheet, int row, int col, double value) { - sheet.getRow(row + 1).createCell(col + 1).setCellValue(value); - } + public static void addHeaderCell(Workbook workbook, Row row, int col, String value) { + Cell cell = row.createCell(col); + cell.setCellValue(value); - public static void addPointCells(Sheet sheet, int row, int col, Point3d point) { - sheet.getRow(row + 1).createCell(col + 1).setCellValue(point.getX()); - sheet.getRow(row + 1).createCell(col + 2).setCellValue(point.getY()); - sheet.getRow(row + 1).createCell(col + 3).setCellValue(point.getZ()); - } + Font font = workbook.createFont(); + font.setBoldweight(Font.BOLDWEIGHT_BOLD); - public static void mergeColumnsOnRow(Sheet sheet, int firstRow, int firstColumn, int lastColumn) { - sheet.addMergedRegion(new CellRangeAddress(firstRow, firstRow, firstColumn, lastColumn)); - } + CellStyle cellStyle = workbook.createCellStyle(); + cellStyle.setFont(font); + cellStyle.setAlignment(CellStyle.ALIGN_CENTER); + cellStyle.setVerticalAlignment(CellStyle.VERTICAL_CENTER); + cell.setCellStyle(cellStyle); + } - public static void autoSizeColumns(Sheet sheet) { - // header row - for (int i = 0; i < sheet.getRow(0).getLastCellNum(); i++) { - sheet.autoSizeColumn(i, true); - } + public static void addEmptyCell(Workbook workbook, Row row, int col) { + row.createCell(col).setCellValue(""); + } - // table row - for (int i = 0; i < sheet.getRow(1).getLastCellNum(); i++) { - sheet.autoSizeColumn(i, true); - } - } + public static void addDoubleCell(Sheet sheet, int row, int col, double value) { + sheet.getRow(row + 1).createCell(col + 1).setCellValue(value); + } + + public static void addPointCells(Sheet sheet, int row, int col, Point3d point) { + sheet.getRow(row + 1).createCell(col + 1).setCellValue(point.getX()); + sheet.getRow(row + 1).createCell(col + 2).setCellValue(point.getY()); + sheet.getRow(row + 1).createCell(col + 3).setCellValue(point.getZ()); + } + + public static void mergeColumnsOnRow(Sheet sheet, int firstRow, int firstColumn, int lastColumn) { + sheet.addMergedRegion(new CellRangeAddress(firstRow, firstRow, firstColumn, lastColumn)); + } + + public static void autoSizeColumns(Sheet sheet) { + // header row + for (int i = 0; i < sheet.getRow(0).getLastCellNum(); i++) { + sheet.autoSizeColumn(i, true); + } + + // table row + for (int i = 0; i < sheet.getRow(1).getLastCellNum(); i++) { + sheet.autoSizeColumn(i, true); + } + } + + public static void writeDoubleMatrix(File file, double[][] data) { + Workbook wb = getWoorkBook(file); + Sheet sheet = wb.createSheet(); + + int rows = data.length; + for (int r = 0; r < rows; r++) { + Row row = sheet.createRow(r); + int cells = data[r].length; + for (int c = 0; c < cells; c++) { + Cell cell = row.createCell(c, HSSFCell.CELL_TYPE_NUMERIC); + cell.setCellValue(data[r][c]); + } + } + + try (FileOutputStream os = new FileOutputStream(file)) { + wb.write(os); + } catch (Exception e) { + logger.error("Error reading file", e); + } + } + + public static void writeObjectMatrix(File file, Object[][] data) { + Workbook wb = getWoorkBook(file); + Sheet sheet = wb.createSheet(); + + int rows = data.length; + for (int r = 0; r < rows; r++) { + Row row = sheet.createRow(r); + int cells = data[r].length; + for (int c = 0; c < cells; c++) { + Cell cell = row.createCell(c, HSSFCell.CELL_TYPE_NUMERIC); + Object d = data[r][c]; + if (d instanceof Double) { + cell.setCellValue((Double) d); + } else { + cell.setCellValue(String.valueOf(d)); + } + } + } + + try (FileOutputStream os = new FileOutputStream(file)) { + wb.write(os); + } catch (Exception e) { + logger.error("Error reading file", e); + } + } + + public static Double[][] readDoubleMatrix(File file, int sheetIndex, int colSize) { + try (FileInputStream is = new FileInputStream(file)) { + Workbook wb = getWoorkBook(file, is); + + Sheet sheet = wb.getSheetAt(sheetIndex); + int rows = sheet.getPhysicalNumberOfRows(); + + logger.debug("Sheet {} \"{}\" has {} row(s).", sheetIndex, wb.getSheetName(sheetIndex), rows); + Double[][] matrix = new Double[rows][colSize]; + for (int r = 0; r < rows; r++) { + + Double[] matrixRow = getEmptyRow(colSize); + + Row row = sheet.getRow(r); + if (row == null) { + continue; + } + + int cells = row.getPhysicalNumberOfCells(); + logger.debug("ROW {} has {} cell(s).", row.getRowNum(), cells); + + for (int c = 0; c < colSize; c++) { + if (cells < colSize && c >= cells) { + matrixRow[c] = 0.0; + } else { + Cell cell = row.getCell(c); + if(cell != null){ + switch (cell.getCellType()) { + case HSSFCell.CELL_TYPE_FORMULA: + matrixRow[c] = 0.0; + break; + case HSSFCell.CELL_TYPE_NUMERIC: + matrixRow[c] = cell.getNumericCellValue(); + break; + case HSSFCell.CELL_TYPE_STRING: + matrixRow[c] = 0.0; + break; + default: + matrixRow[c] = 0.0; + } + } else { + matrixRow[c] = 0.0; + } + } + } + matrix[r] = matrixRow; + } + + return matrix; + } catch (Exception e) { + logger.error("Error reading file", e); + } + + return new Double[0][0]; + } + + private static Double[] getEmptyRow(int colSize) { + Double[] emptyArray = new Double[colSize]; + for (int i = 0; i < emptyArray.length; i++) { + emptyArray[i] = 0.0; + } + return emptyArray; + } } diff --git a/src/eu/engys/core/report/pdf/PDFImage.java b/src/eu/engys/core/report/pdf/PDFImage.java deleted file mode 100644 index 76718ae..0000000 --- a/src/eu/engys/core/report/pdf/PDFImage.java +++ /dev/null @@ -1,46 +0,0 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - -package eu.engys.core.report.pdf; - -public class PDFImage { - - private String title; - private String name; - - public PDFImage(String name, String title) { - this.name = name; - this.title = title; - } - - public String getTitle() { - return title; - } - - public String getName() { - return name; - } - -} diff --git a/src/eu/engys/core/report/pdf/PDFPage.java b/src/eu/engys/core/report/pdf/PDFPage.java deleted file mode 100644 index 379888f..0000000 --- a/src/eu/engys/core/report/pdf/PDFPage.java +++ /dev/null @@ -1,36 +0,0 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - -package eu.engys.core.report.pdf; - -import com.lowagie.text.Element; - -public interface PDFPage { - - public abstract String getTitle(); - - public abstract Element getElement(); - -} diff --git a/src/eu/engys/core/report/pdf/PDFPageEvent.java b/src/eu/engys/core/report/pdf/PDFPageEvent.java deleted file mode 100644 index 6ecb85e..0000000 --- a/src/eu/engys/core/report/pdf/PDFPageEvent.java +++ /dev/null @@ -1,79 +0,0 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - -package eu.engys.core.report.pdf; - -import java.io.IOException; -import java.net.MalformedURLException; -import java.net.URL; - -import com.lowagie.text.BadElementException; -import com.lowagie.text.Document; -import com.lowagie.text.DocumentException; -import com.lowagie.text.Image; -import com.lowagie.text.pdf.PdfContentByte; -import com.lowagie.text.pdf.PdfPageEventHelper; -import com.lowagie.text.pdf.PdfWriter; - -public class PDFPageEvent extends PdfPageEventHelper { - - private static final int FRONT_PAGE_INDEX = 1; - private URL frontPagewatermarkImage; - private URL watermarkImage; - - public PDFPageEvent(URL frontPagewatermarkImage, URL watermarkImage) { - this.frontPagewatermarkImage = frontPagewatermarkImage; - this.watermarkImage = watermarkImage; - } - - @Override - public void onEndPage(PdfWriter writer, Document document) { - try { - _addWatermark(writer, document); - } catch (Exception e) { - e.printStackTrace(); - } - } - - private void _addWatermark(PdfWriter writer, Document document) throws BadElementException, MalformedURLException, IOException, DocumentException { - PdfContentByte canvas = writer.getDirectContentUnder(); - Image image = null; - if (document.getPageNumber() == FRONT_PAGE_INDEX) { - image = Image.getInstance(frontPagewatermarkImage); - } else { - image = Image.getInstance(watermarkImage); - } - image.setAlignment(Image.MIDDLE); - float x = (document.getPageSize().getWidth() - image.getWidth()) / 2; - float y = (document.getPageSize().getHeight() - image.getHeight()) / 2; - if (document.getPageNumber() == FRONT_PAGE_INDEX) { - image.setAbsolutePosition(x, y - 30); - } else { - image.setAbsolutePosition(x, y); - } - canvas.addImage(image); - - } -} diff --git a/src/eu/engys/core/report/pdf/PDFReport.java b/src/eu/engys/core/report/pdf/PDFReport.java deleted file mode 100644 index c1112d8..0000000 --- a/src/eu/engys/core/report/pdf/PDFReport.java +++ /dev/null @@ -1,107 +0,0 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - -package eu.engys.core.report.pdf; - -import java.io.File; -import java.io.FileOutputStream; -import java.net.URL; -import java.util.LinkedList; -import java.util.List; - -import com.lowagie.text.Document; -import com.lowagie.text.Element; -import com.lowagie.text.HeaderFooter; -import com.lowagie.text.Phrase; -import com.lowagie.text.Rectangle; -import com.lowagie.text.pdf.PdfWriter; - -import eu.engys.core.project.Model; - -public abstract class PDFReport { - - protected Model model; - - private Document document; - private PdfWriter writer; - private File reportFile; - - private List pages = new LinkedList<>(); - - public PDFReport(Model model, File reportFile) { - this.model = model; - this.reportFile = reportFile; - } - - public void create() throws Exception { - document = new Document(); - writer = PdfWriter.getInstance(document, new FileOutputStream(reportFile)); - writer.setPageEvent(new PDFPageEvent(getFrontPageWaterMarkImage(), getWaterMarkImage())); - document.open(); - addFooter(); - populate(); - end(); - } - - private void addFooter() { - HeaderFooter headerFooter = new HeaderFooter(new Phrase(getFooter()), false); - headerFooter.setAlignment(Element.ALIGN_CENTER); - headerFooter.setBorder(Rectangle.TOP); - document.setFooter(headerFooter); - } - - protected abstract void populate() throws Exception; - - public abstract URL getWaterMarkImage(); - - public abstract URL getFrontPageWaterMarkImage(); - - public abstract String getFooter(); - - protected void addPage(PDFPage page) { - pages.add(page); - } - - private void end() throws Exception { - for (PDFPage page : pages) { - document.add(page.getElement()); - } - document.close(); - writer.close(); - } - - public Model getModel() { - return model; - } - - public PdfWriter getWriter() { - return writer; - } - - public Document getDocument() { - return document; - } - -} diff --git a/src/eu/engys/core/report/pdf/PDFUtils.java b/src/eu/engys/core/report/pdf/PDFUtils.java deleted file mode 100644 index 8de6769..0000000 --- a/src/eu/engys/core/report/pdf/PDFUtils.java +++ /dev/null @@ -1,213 +0,0 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - -package eu.engys.core.report.pdf; - -import java.awt.Color; -import java.io.File; -import java.io.IOException; -import java.net.MalformedURLException; -import java.net.URL; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.lowagie.text.BadElementException; -import com.lowagie.text.Document; -import com.lowagie.text.Element; -import com.lowagie.text.Font; -import com.lowagie.text.Image; -import com.lowagie.text.Paragraph; -import com.lowagie.text.Phrase; -import com.lowagie.text.Rectangle; -import com.lowagie.text.pdf.PdfPCell; -import com.lowagie.text.pdf.PdfPTable; - -import eu.engys.core.project.Model; - -public class PDFUtils { - - private static final Logger logger = LoggerFactory.getLogger(PDFUtils.class); - - private static final int DEFAULT_FONT = Font.HELVETICA; - public static final String POSTPRO = "POSTPRO"; - - public static final int MEDIUM_FONT = 18; - public static final int BIG_FONT = 25; - - public static final int SMALL_LINE_SPACING = 10; - public static final int MEDIUM_LINE_SPACING = 20; - public static final int LARGE_LINE_SPACING = 50; - public static final int HUGE_LINE_SPACING = 100; - - public static final String NO_VALUE = "-"; - - public static Paragraph createParagraph() { - return createParagraph(MEDIUM_LINE_SPACING); - } - - public static Paragraph createParagraph(int lineSpacing) { - return createParagraph(lineSpacing, Element.ALIGN_CENTER); - } - - public static Paragraph createParagraph(int lineSpacing, int align) { - Paragraph paragraph = new Paragraph(); - paragraph.setLeading(lineSpacing); - paragraph.setAlignment(align); - paragraph.setSpacingBefore(10); - return paragraph; - } - - public static Phrase createLine(String text) { - return createLine(text, MEDIUM_FONT, false, Color.BLACK); - } - - public static Phrase createLine(String text, int fontSize) { - return createLine(text, fontSize, false, Color.BLACK); - } - - public static Phrase createLine(String text, int fontSize, boolean bold) { - return createLine(text, fontSize, bold, Color.BLACK); - } - - public static Phrase createLine(String text, int fontSize, boolean bold, Color color) { - Font font = new Font(DEFAULT_FONT, fontSize, bold ? Font.BOLD : Font.NORMAL, color); - Phrase phrase = new Phrase(text + "\n", font); - return phrase; - } - - public static PdfPTable createTableKeyValue(String[][] data) { - PdfPTable table = new PdfPTable(data[0].length); - for (String[] row : data) { - String key = row[0]; - String value = row[1]; - - Paragraph keyParagraph = new Paragraph(key); - keyParagraph.getFont().setStyle(Font.BOLD); - - PdfPCell keyCell = new PdfPCell(keyParagraph); - keyCell.setPadding(5); - keyCell.setHorizontalAlignment(PdfPCell.LEFT); - keyCell.setBorderWidth(1); - keyCell.setBorderColor(Color.GRAY); - table.addCell(keyCell); - - PdfPCell valueCell = new PdfPCell(new Paragraph(value)); - valueCell.setPadding(5); - valueCell.setHorizontalAlignment(PdfPCell.LEFT); - valueCell.setBorderWidth(1); - valueCell.setBorderColor(Color.GRAY); - table.addCell(valueCell); - - } - return table; - } - - public static PdfPTable createTable(String[][] data) { - PdfPTable table = new PdfPTable(data[0].length); - for (String[] row : data) { - for (String value : row) { - PdfPCell cell = new PdfPCell(new Paragraph(value)); - cell.setPadding(5); - cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); - cell.setBorderWidth(1); - cell.setBorderColor(Color.GRAY); - if (table.getRows().size() % 2 == 0) { - cell.setBackgroundColor(new Color(245, 245, 245)); - } else { - cell.setBackgroundColor(new Color(230, 250, 250)); - } - table.addCell(cell); - } - } - return table; - } - - public static Image createImage(Document document, URL url) throws BadElementException, MalformedURLException, IOException { - Image image = Image.getInstance(url); - image.setAlignment(Image.MIDDLE); - float ratio = image.getWidth() / (document.getPageSize().getWidth() - 100); - image.scaleAbsolute((image.getWidth() / ratio), (image.getHeight() / ratio)); - return image; - } - - public static PdfPTable createImagePage(Model model, PDFImage[] images) { - File postProFolder = new File(model.getProject().getBaseDir(), POSTPRO); - if (postProFolder.exists()) { - PdfPTable table = new PdfPTable(1); - table.getDefaultCell().setBorder(Rectangle.BOX); - - for (PDFImage image : images) { - File file = new File(postProFolder, image.getName()); - addImageToTable(table, file); - addTitleToTable(table, image.getTitle()); - addEmptyCellToTable(table); - } - table.setWidthPercentage(70); - table.setKeepTogether(true); - - return table; - } else { - return new PdfPTable(1); - } - } - - private static void addEmptyCellToTable(PdfPTable table) { - PdfPCell emptyCell = new PdfPCell(new Phrase("")); - emptyCell.setBorder(Rectangle.NO_BORDER); - table.addCell(emptyCell); - } - - private static void addTitleToTable(PdfPTable table, String title) { - if (title.isEmpty()) { - return; - } - PdfPCell textCell = new PdfPCell(new Phrase(title)); - textCell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); - table.addCell(textCell); - } - - private static void addImageToTable(PdfPTable table, File imageFile) { - try { - if (imageFile.exists()) { - Image image = Image.getInstance(imageFile.toURI().toURL()); - image.setAlignment(Image.MIDDLE); - table.addCell(image); - } else { - PdfPCell missingImageText = new PdfPCell(new Phrase("Missing Image")); - missingImageText.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); - table.addCell(missingImageText); - } - } catch (BadElementException | IOException e) { - logger.error(e.getMessage()); - } - } - - public static Paragraph createImagesBlock(Model model, PDFImage... images) { - Paragraph p = createParagraph(); - p.add(createImagePage(model, images)); - return p; - } -} diff --git a/src/eu/engys/dynamic/DynamicCaseSetupReader.java b/src/eu/engys/dynamic/DynamicCaseSetupReader.java new file mode 100644 index 0000000..befd3e8 --- /dev/null +++ b/src/eu/engys/dynamic/DynamicCaseSetupReader.java @@ -0,0 +1,85 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.dynamic; + +import static eu.engys.core.project.zero.cellzones.CellZoneType.DYNAMIC_MESH_KEY; +import static eu.engys.dynamic.DynamicMeshDict.DYNAMIC_MESH_DICT; +import static eu.engys.dynamic.DynamicMeshDict.MULTI_SOLID_BODY_MOTION_FV_MESH_COEFFS_KEY; + +import eu.engys.core.dictionary.Dictionary; +import eu.engys.core.modules.CaseSetupReader; +import eu.engys.core.project.Model; +import eu.engys.core.project.state.State; +import eu.engys.core.project.zero.cellzones.CellZone; +import eu.engys.dynamic.data.DynamicDataReader; + +public class DynamicCaseSetupReader implements CaseSetupReader { + + private DynamicModule module; + + public DynamicCaseSetupReader(Model model, DynamicModule module) { + this.module = module; + } + + @Override + public void readFromState(State state, String stateString) { + if (stateString.contains(DynamicModule.DYNAMIC_KEY)) { + state.setDynamic(true); + } + } + + @Override + public void readFromSystem(Dictionary system) { + } + + @Override + public void readFromConstant(Model loadedModel, Dictionary constant) { + if (constant.isDictionary(DYNAMIC_MESH_DICT)) { + Dictionary dynamicMeshDict = new Dictionary(constant.subDict(DYNAMIC_MESH_DICT)); + module.setDynamicMeshDict(dynamicMeshDict); + module.getDynamicData().setAlgorithm(new DynamicDataReader().readAlgorithm(dynamicMeshDict)); + + if (module.getDynamicData().getAlgorithm().getType().isMultiRigidBody()) { + if (dynamicMeshDict.found(MULTI_SOLID_BODY_MOTION_FV_MESH_COEFFS_KEY)) { + Dictionary coeffsDict = dynamicMeshDict.subDict(MULTI_SOLID_BODY_MOTION_FV_MESH_COEFFS_KEY); + addCellZones(loadedModel, coeffsDict); + } + } + } + } + + private void addCellZones(Model loadedModel, Dictionary coeffsDict) { + for (Dictionary d : coeffsDict.getDictionaries()) { + CellZone cz = new CellZone(d.getName()); + cz.setDictionary(DYNAMIC_MESH_KEY, new Dictionary("")); + cz.getTypes().add(DYNAMIC_MESH_KEY); + loadedModel.getCellZones().add(cz); + } + } + + @Override + public void readMaterials(Model model, Dictionary globals) { + } +} diff --git a/src/eu/engys/dynamic/DynamicCaseSetupWriter.java b/src/eu/engys/dynamic/DynamicCaseSetupWriter.java new file mode 100644 index 0000000..0d5fe45 --- /dev/null +++ b/src/eu/engys/dynamic/DynamicCaseSetupWriter.java @@ -0,0 +1,69 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.dynamic; + +import static eu.engys.dynamic.DynamicModule.DYNAMIC_KEY; + +import eu.engys.core.dictionary.Dictionary; +import eu.engys.core.modules.CaseSetupWriter; +import eu.engys.core.project.Model; +import eu.engys.core.project.materials.Materials; +import eu.engys.core.project.state.State; +import eu.engys.dynamic.data.DynamicDataWriter; + +public class DynamicCaseSetupWriter implements CaseSetupWriter { + + private Model model; + private DynamicModule module; + + public DynamicCaseSetupWriter(Model model, DynamicModule module) { + this.model = model; + this.module = module; + } + + @Override + public void addState(State state, StringBuffer sb) { + if (state.isDynamic()) + sb.append(" " + DYNAMIC_KEY); + } + + @Override + public void addToSystem(State state, Dictionary system) { + } + + @Override + public void addToConstant(State state, Dictionary constant) { + if (state.isDynamic()) { + Dictionary dynamicMeshDict = new DynamicDataWriter(model).writeAlgorithm(module.getDynamicData().getAlgorithm()); + module.setDynamicMeshDict(dynamicMeshDict); + constant.add(new Dictionary(dynamicMeshDict)); + } + } + + @Override + public void addToMaterials(Materials materials, Dictionary materialsProperties) { + } + +} diff --git a/src/eu/engys/dynamic/DynamicMeshDict.java b/src/eu/engys/dynamic/DynamicMeshDict.java new file mode 100644 index 0000000..f78f6de --- /dev/null +++ b/src/eu/engys/dynamic/DynamicMeshDict.java @@ -0,0 +1,181 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.dynamic; + +import eu.engys.core.dictionary.Dictionary; +import eu.engys.core.dictionary.FoamFile; + +public class DynamicMeshDict extends Dictionary { + + public static final String COEFFS_KEY = "Coeffs"; + + public static final String DYNAMIC_MESH_DICT = "dynamicMeshDict"; + + public static final String DYNAMIC_FV_MESH_KEY = "dynamicFvMesh"; + public static final String STATIC_FV_MESH_KEY = "staticFvMesh"; + public static final String SOLID_BODY_MOTION_FV_MESH_KEY = "solidBodyMotionFvMesh"; + public static final String DYNAMIC_MOTION_SOLVER_FV_MESH_KEY = "dynamicMotionSolverFvMesh"; + public static final String DYNAMIC_REFINE_FV_MESH_KEY = "dynamicRefineFvMesh"; + public static final String MULTI_SOLID_BODY_MOTION_FV_MESH_KEY = "multiSolidBodyMotionFvMesh"; + public static final String SOLID_BODY_MOTION_FV_MESH_COEFFS_KEY = SOLID_BODY_MOTION_FV_MESH_KEY + COEFFS_KEY; + public static final String MULTI_SOLID_BODY_MOTION_FV_MESH_COEFFS_KEY = MULTI_SOLID_BODY_MOTION_FV_MESH_KEY + COEFFS_KEY; + public static final String DYNAMIC_REFINE_FV_MESH_COEFFS_KEY = DYNAMIC_REFINE_FV_MESH_KEY + COEFFS_KEY; + + /* + * SOLID BODY MOTION FUNCTIONS + */ + public static final String SOLID_BODY_MOTION_FUNCTION_KEY = "solidBodyMotionFunction"; + + // Linear Motion + public static final String LINEAR_MOTION_KEY = "linearMotion"; + public static final String LINEAR_MOTION_COEFFS_KEY = LINEAR_MOTION_KEY + COEFFS_KEY; + + // Rotating motion + public static final String ROTATING_MOTION_KEY = "rotatingMotion"; + public static final String ROTATING_MOTION_COEFFS_KEY = ROTATING_MOTION_KEY + COEFFS_KEY; + public static final String T0_KEY = "t0"; + + // Axis rotation motion + public static final String AXIS_ROTATION_MOTION_KEY = "axisRotationMotion"; + public static final String AXIS_ROTATION_MOTION_COEFFS_KEY = AXIS_ROTATION_MOTION_KEY + COEFFS_KEY; + public static final String RADIAL_VELOCITY_KEY = "radialVelocity"; + + // Oscillating Linear Motion + public static final String OSCILLATING_LINEAR_MOTION_KEY = "oscillatingLinearMotion"; + public static final String OSCILLATING_LINEAR_MOTION_COEFFS_KEY = OSCILLATING_LINEAR_MOTION_KEY + COEFFS_KEY; + + // Oscillating Rotating Motion + public static final String OSCILLATING_ROTATING_MOTION_KEY = "oscillatingRotatingMotion"; + public static final String OSCILLATING_ROTATING_MOTION_COEFFS_KEY = OSCILLATING_ROTATING_MOTION_KEY + COEFFS_KEY; + + // SDA + public static final String SDA_KEY = "SDA"; + public static final String SDA_COEFFS_KEY = SDA_KEY + COEFFS_KEY; + public static final String TPN_KEY = "Tpn"; + public static final String TP_KEY = "Tp"; + public static final String SWAY_A_KEY = "swayA"; + public static final String ROLL_A_MIN_KEY = "rollAmin"; + public static final String Q_KEY = "Q"; + public static final String LAMDA_KEY = "lamda"; + public static final String HEAVE_A_KEY = "heaveA"; + public static final String DTI_KEY = "dTi"; + public static final String ROLL_A_MAX_KEY = "rollAmax"; + public static final String DTP_KEY = "dTp"; + public static final String COFG_KEY = "CofG"; + + // Rotating Step Motion + public static final String ROTATING_STEP_MOTION_KEY = "rotatingStepMotion"; + public static final String ROTATING_STEP_MOTION_COEFFS_KEY = "rotatingStepMotionCoeffs"; + public static final String THETA_KEY = "theta"; + public static final String PERIOD_KEY = "period"; + + /* + * Dynamic Refine + */ + public static final String REFINE_INTERVAL_KEY = "refineInterval"; + public static final String FIELD_KEY = "field"; + public static final String LOWER_REFINE_LEVEL_KEY = "lowerRefineLevel"; + public static final String UPPER_REFINE_LEVEL_KEY = "upperRefineLevel"; + public static final String UNREFINE_LEVEL_KEY = "unrefineLevel"; + public static final String N_BUFFER_LAYERS_KEY = "nBufferLayers"; + public static final String MAX_REFINEMENT_KEY = "maxRefinement"; + public static final String MAX_CELLS_KEY = "maxCells"; + public static final String CORRECT_FLUXES_KEY = "correctFluxes"; + public static final String CORRECT_FLUXES_VALUE = "( (phi none) (phiAbs U) (phiAbs_0 U_0) (nHatf none) (rho*phi none) (ghf none) (phi_0 none) (rhoPhi none) (\"(flux(alpha1)-flux(alpha1))\" none) )"; + public static final String DUMP_LEVEL_KEY = "dumpLevel"; + + /* + * 6DOF + */ + public static final String SOLVER_KEY = "solver"; + + public static final String SIX_DOF_RIGID_BODY_MOTION_KEY = "sixDoFRigidBodyMotion"; + public static final String SIX_DOF_RIGID_BODY_MOTION_COEFFS_KEY = SIX_DOF_RIGID_BODY_MOTION_KEY+COEFFS_KEY; + + public static final String MASS_KEY = "mass"; + public static final String PATCHES_KEY = "patches"; + public static final String ACCELERATION_RELAXATION_KEY = "accelerationRelaxation"; + public static final String REPORT_KEY = "report"; + public static final String MOMENT_OF_INERTIA_KEY = "momentOfInertia"; + public static final String CENTRE_OF_MASS_KEY = "centreOfMass"; + public static final String OUTER_DISTANCE_KEY = "outerDistance"; + public static final String INNER_DISTANCE_KEY = "innerDistance"; + public static final String RHO_KEY = "rho"; + public static final String RHO_NAME_KEY = "rhoName"; + public static final String RHO_INF_KEY = "rhoInf"; + public static final String NEWMARK_KEY = "Newmark"; + + //CONSTRAINTS + public static final String CONSTRAINTS_KEY = "constraints"; + + public static final String SIX_DOF_RIGID_BODY_MOTION_CONSTRAINT_KEY = "sixDoFRigidBodyMotionConstraint"; + + public static final String ROTATION_CONSTRAINT_KEY = "rotationConstraint"; + public static final String ORIENTATION_KEY = "orientation"; + + public static final String TRANSLATION_CONSTRAINT_KEY = "translationConstraint"; + public static final String PLANE_KEY = "plane"; + public static final String NORMAL_KEY = "normal"; + public static final String LINE_KEY = "line"; + public static final String DIRECTION_KEY = "direction"; + public static final String POINT_KEY = "point"; + public static final String CENTRE_OF_ROTATION_KEY = "centreOfRotation";//used by of+ + + //RESTRAINTS + public static final String RESTRAINTS_KEY = "restraints"; + public static final String LINEAR_RESTRAINT_KEY = "linearRestraint"; + public static final String ANGULAR_RESTRAINT_KEY = "angularRestraint"; + public static final String SIX_DOF_RIGID_BODY_MOTION_RESTRAINT_KEY = "sixDoFRigidBodyMotionRestraint"; + public static final String LINEAR_DAMPER_KEY = "linearDamper"; + public static final String LINEAR_SPRING_KEY = "linearSpring"; + public static final String COEFF_KEY = "coeff"; + public static final String SPHERICAL_ANGULAR_SPRING_KEY = "sphericalAngularSpring"; + public static final String SPHERICAL_ANGULAR_DAMPER_KEY = "sphericalAngularDamper"; + public static final String STIFFNESS_KEY = "stiffness"; + public static final String DAMPING_KEY = "damping"; + public static final String REF_ATTACHMENT_PT_KEY = "refAttachmentPt"; + public static final String REST_LENGTH_KEY = "restLength"; + public static final String ANCHOR_KEY = "anchor"; + + // Common + public static final String ORIGIN_KEY = "origin"; + public static final String OMEGA_KEY = "omega"; + public static final String AMPLITUDE_KEY = "amplitude"; + public static final String AXIS_KEY = "axis"; + public static final String VELOCITY_KEY = "velocity"; + + /* + * Other + */ + public static final String MOTION_SOLVER_LIBS_KEY = "motionSolverLibs"; + public static final String MULTIBODY_DYNAMIC_LIBRARIES = "( \"libfvMotionSolvers.so\" )"; + public static final String SIX_DOF_DYNAMIC_LIBRARIES = "( \"libfvMotionSolvers.so\" \"libsixDoFRigidBodyMotion.so\" )"; + + public DynamicMeshDict() { + super(DYNAMIC_MESH_DICT); + setFoamFile(FoamFile.getDictionaryFoamFile(CONSTANT, DYNAMIC_MESH_DICT)); + } + +} diff --git a/src/eu/engys/dynamic/DynamicModule.java b/src/eu/engys/dynamic/DynamicModule.java new file mode 100644 index 0000000..9160810 --- /dev/null +++ b/src/eu/engys/dynamic/DynamicModule.java @@ -0,0 +1,282 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.dynamic; + +import static eu.engys.core.dictionary.Dictionary.TYPE; +import static eu.engys.core.project.zero.fields.Fields.POINT_DISPLACEMENT; +import static eu.engys.core.project.zero.fields.Fields.U; +import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.CALCULATED_KEY; +import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.FIXED_VALUE_KEY; +import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.MOVING_WALL_VELOCITY_KEY; + +import java.util.HashSet; +import java.util.Set; + +import javax.inject.Inject; + +import eu.engys.core.dictionary.Dictionary; +import eu.engys.core.modules.ApplicationModuleAdapter; +import eu.engys.core.modules.CaseSetupReader; +import eu.engys.core.modules.CaseSetupWriter; +import eu.engys.core.modules.ModuleDefaults; +import eu.engys.core.modules.ModulePanel; +import eu.engys.core.modules.cellzones.CellZonesView; +import eu.engys.core.modules.solutionmodelling.SolutionView; +import eu.engys.core.modules.tree.TreeView; +import eu.engys.core.project.Model; +import eu.engys.core.project.defaults.DefaultsProvider; +import eu.engys.core.project.state.Solver; +import eu.engys.core.project.state.SolverFamily; +import eu.engys.core.project.state.State; +import eu.engys.core.project.state.StateBuilder; +import eu.engys.core.project.zero.fields.Field; +import eu.engys.core.project.zero.fields.Fields; +import eu.engys.core.project.zero.fields.FieldsDefaults; +import eu.engys.core.project.zero.patches.BoundaryConditions; +import eu.engys.dynamic.cellzones.DynamicCellZonesView; +import eu.engys.dynamic.data.DynamicData; +import eu.engys.dynamic.domain.MeshRefineDynamicPanel; +import eu.engys.dynamic.domain.SixDoFDynamicPanel; +import eu.engys.dynamic.domain.SolidBodyDynamicPanel; +import eu.engys.gui.DefaultGUIPanel; + +public class DynamicModule extends ApplicationModuleAdapter { + + public static final String DYNAMIC_KEY = "dynamic"; + public static final String PIMPLE_DYM_FOAM = "pimpleDyMFoam"; + public static final String RHO_PIMPLE_DYM_FOAM = "rhoPimpleDyMFoam"; + public static final String RHO_CENTRAL_DYM_FOAM = "rhoCentralDyMFoam"; + + protected SolutionView solutionView; + protected CellZonesView cellZonesView; + + private Model model; + private DefaultsProvider defaults; + private Dictionary dynamicMeshDict; + + private CaseSetupReader caseSetupReader; + private CaseSetupWriter caseSetupWriter; + + private DynamicReader reader; + + private DynamicData dynamicData; + protected TreeView treeView; + protected DefaultGUIPanel sixDoFPanel; + protected DefaultGUIPanel solidBodyPanel; + private DefaultGUIPanel refinePanel; + + @Inject + public DynamicModule(Model model) { + this.model = model; + this.dynamicData = new DynamicData(); + + this.solutionView = new DynamicSolutionView(model, this); + this.cellZonesView = new DynamicCellZonesView(model, this); + + this.defaults = new ModuleDefaults(this, model.getDefaults(), null); + + this.reader = new DynamicReader(model, this); + this.reader.readDynamicMeshDict(); + + this.caseSetupReader = new DynamicCaseSetupReader(model, this); + this.caseSetupWriter = new DynamicCaseSetupWriter(model, this); + + this.sixDoFPanel = new SixDoFDynamicPanel(model, this); + this.solidBodyPanel = new SolidBodyDynamicPanel(model, this); + this.refinePanel = new MeshRefineDynamicPanel(model, this); + + this.treeView = new DynamicTreeView(this, sixDoFPanel, solidBodyPanel, refinePanel); + } + + @Override + public String getName() { + return DYNAMIC_KEY; + } + + @Override + public void updateSolverFamilies(State state, Set families) { + if (state.isDynamic()) { + if (state.getSolverType().isSegregated()) { + if (state.isLowMach()) { + if (state.isTransient()) { + if (state.isIncompressible()) { + if (state.isEnergy() || state.getMultiphaseModel().isMultiphase()) { + // NONE + } else { + if (families.contains(SolverFamily.PISO)) { + families.remove(SolverFamily.PISO); + } + } + } + } + } + } + } + } + + @Override + public void updateSolver(State state) { + if (!state.getMultiphaseModel().isMultiphase()) { + if (state.getSolverFamily().isPimple()) { + if (state.isCompressible()) { + if (!state.isBuoyant()) { + if (state.isDynamic()) { + if (state.isHighMach()) { + state.setSolver(new Solver(RHO_CENTRAL_DYM_FOAM)); + } else { + state.setSolver(new Solver(RHO_PIMPLE_DYM_FOAM)); + } + } + } + } else if (state.isIncompressible()) { + if (!state.isEnergy()) { + if (state.isDynamic()) { + state.setSolver(new Solver(PIMPLE_DYM_FOAM)); + } + } + } + } else if (state.getSolverFamily().isCentral()) { + if (state.isDynamic()) { + if (state.isHighMach()) { + state.setSolver(new Solver(RHO_CENTRAL_DYM_FOAM)); + } else { + state.setSolver(new Solver(PIMPLE_DYM_FOAM)); + } + } + } + } + } + + @Override + public CellZonesView getCellZonesView() { + return cellZonesView; + } + + @Override + public void loadState() { + reader.loadState(); + } + + @Override + public void save() { + } + + @Override + public void read() { + reader.readDynamicMeshDict(); + } + + @Override + public void write() { + new DynamicWriter(model, this).write(); + } + + @Override + public CaseSetupReader getCaseSetupReader() { + return caseSetupReader; + } + + @Override + public CaseSetupWriter getCaseSetupWriter() { + return caseSetupWriter; + } + + @Override + public void saveDefaultsToProject() { + if (model.getState().isDynamic()) { + StateBuilder.saveDefaultsToProject(model, defaults); + } + } + + @Override + public void saveToBoundaryConditions(BoundaryConditions bc) { + if (dynamicData.getAlgorithm().getType().is6DOF()) { + boolean isMovingWallVelocity = bc.getMomentum().found(U) && bc.getMomentum().subDict(U).found(TYPE) && bc.getMomentum().subDict(U).lookupString(TYPE).equals(MOVING_WALL_VELOCITY_KEY); + if (isMovingWallVelocity) { + bc.getDisplacement().subDict(POINT_DISPLACEMENT).add(TYPE, CALCULATED_KEY); + } else { + boolean isCalculated = bc.getDisplacement().found(POINT_DISPLACEMENT) && bc.getDisplacement().subDict(POINT_DISPLACEMENT).found(TYPE) && bc.getDisplacement().subDict(POINT_DISPLACEMENT).lookupString(TYPE).equals(CALCULATED_KEY); + if(isCalculated){ + bc.getDisplacement().subDict(POINT_DISPLACEMENT).add(TYPE, FIXED_VALUE_KEY); + } + } + } else { + boolean isCalculated = bc.getDisplacement().found(POINT_DISPLACEMENT) && bc.getDisplacement().subDict(POINT_DISPLACEMENT).found(TYPE) && bc.getDisplacement().subDict(POINT_DISPLACEMENT).lookupString(TYPE).equals(CALCULATED_KEY); + if(isCalculated){ + bc.getDisplacement().subDict(POINT_DISPLACEMENT).add(TYPE, FIXED_VALUE_KEY); + } + } + + } + + @Override + public Set getCaseSetupPanels() { + Set panels = new HashSet<>(); + panels.add(sixDoFPanel); + panels.add(solidBodyPanel); + panels.add(refinePanel); + return panels; + } + + @Override + public TreeView getTreeView() { + return treeView; + } + + @Override + public Fields loadDefaultsFields(String region) { + if (model.getState().isDynamic()) { + return FieldsDefaults.loadFieldsFromDefaults(model.getProject().getBaseDir(), model.getState(), defaults, model.getPatches(), region); + } else { + return new Fields(); + } + } + + @Override + public SolutionView getSolutionView() { + return solutionView; + } + + public DynamicData getDynamicData() { + return dynamicData; + } + + public void setDynamicData(DynamicData dynamicData) { + this.dynamicData = dynamicData; + } + + public Dictionary getDynamicMeshDict() { + return dynamicMeshDict; + } + + public void setDynamicMeshDict(Dictionary dynamicMeshDict) { + this.dynamicMeshDict = dynamicMeshDict; + } + + @Override + public boolean isFieldInitialisationVetoed(Field field) { + return field.getName().equals(Fields.P_RGH) && model.getState().isDynamic() && !model.getState().getMultiphaseModel().isMultiphase(); + } +} diff --git a/src/eu/engys/dynamic/DynamicReader.java b/src/eu/engys/dynamic/DynamicReader.java new file mode 100644 index 0000000..73c3491 --- /dev/null +++ b/src/eu/engys/dynamic/DynamicReader.java @@ -0,0 +1,91 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.dynamic; + +import static eu.engys.core.project.constant.ConstantFolder.CONSTANT; +import static eu.engys.dynamic.DynamicMeshDict.DYNAMIC_FV_MESH_KEY; +import static eu.engys.dynamic.DynamicMeshDict.DYNAMIC_MESH_DICT; + +import java.io.File; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; + +import eu.engys.core.dictionary.Dictionary; +import eu.engys.core.dictionary.DictionaryUtils; +import eu.engys.core.modules.ModulesUtil; +import eu.engys.core.project.Model; +import eu.engys.dynamic.data.DynamicAlgorithmType; +import eu.engys.dynamic.data.DynamicDataReader; +import eu.engys.util.progress.SilentMonitor; + +public class DynamicReader { + + private Model model; + private DynamicModule module; + + public DynamicReader(Model model, DynamicModule module) { + this.model = model; + this.module = module; + } + + public void readDynamicMeshDict() { + Dictionary dynamicMeshDict; + if (dynamicMeshDictExists()) { + dynamicMeshDict = readFromFile(); + } else { + dynamicMeshDict = readFromDefaults(); + } + module.setDynamicMeshDict(dynamicMeshDict); + module.getDynamicData().setAlgorithm(new DynamicDataReader().readAlgorithm(module.getDynamicMeshDict())); + } + + private boolean dynamicMeshDictExists() { + if (model.getProject() == null) { + return false; + } + return Files.exists(Paths.get(model.getProject().getBaseDir().getAbsolutePath(), CONSTANT, DYNAMIC_MESH_DICT)); + } + + public void loadState() { + if (module.getDynamicMeshDict().found(DYNAMIC_FV_MESH_KEY)) { + DynamicAlgorithmType data = DynamicAlgorithmType.byKey(module.getDynamicMeshDict().lookupString(DYNAMIC_FV_MESH_KEY)); + model.getState().setDynamic(data.isOn()); + } else { + model.getState().setDynamic(false); + } + } + + private Dictionary readFromFile() { + Path dynamicMeshDictPath = Paths.get(model.getProject().getBaseDir().getAbsolutePath(), CONSTANT, DYNAMIC_MESH_DICT); + File file = dynamicMeshDictPath.toFile(); + return DictionaryUtils.readDictionary(file, new SilentMonitor()); + } + + private Dictionary readFromDefaults() { + return ModulesUtil.readDictionary(module, null, DynamicMeshDict.DYNAMIC_MESH_DICT); + } + +} diff --git a/src/eu/engys/dynamic/DynamicSolutionView.java b/src/eu/engys/dynamic/DynamicSolutionView.java new file mode 100644 index 0000000..6d3456e --- /dev/null +++ b/src/eu/engys/dynamic/DynamicSolutionView.java @@ -0,0 +1,201 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.dynamic; + +import javax.swing.AbstractButton; +import javax.swing.JRadioButton; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import eu.engys.core.modules.solutionmodelling.AbstractSolutionView; +import eu.engys.core.project.Model; +import eu.engys.core.project.state.MultiphaseModel; +import eu.engys.core.project.state.SolutionState; +import eu.engys.core.project.state.State; +import eu.engys.core.project.state.ThermalState; +import eu.engys.dynamic.data.DynamicAlgorithmType; +import eu.engys.dynamic.data.multibody.MultiBodyAlgorithm; +import eu.engys.dynamic.data.off.StaticAlgorithm; +import eu.engys.dynamic.data.refine.MeshRefineAlgorithm; +import eu.engys.dynamic.data.singlebody.SolidBodyAlgorithm; +import eu.engys.dynamic.data.sixdof.SixDoFDAlgorithm; +import eu.engys.util.ui.ChooserPanel; +import eu.engys.util.ui.builder.PanelBuilder; + +public class DynamicSolutionView extends AbstractSolutionView { + + private static final Logger logger = LoggerFactory.getLogger(DynamicSolutionView.class); + + public static final String OFF_LABEL = "Off"; + public static final String SIX_DOF_LABEL = "6 DOF Domain Motion"; + public static final String SOLID_RIGID_BODY_LABEL = "Rigid Body Domain Motion"; + public static final String MULTI_RIGID_BODY_LABEL = "Rigid Body Cell Zone Motion"; + public static final String DYNAMIC_REFINE_FV_MESH_LABEL = "Dynamic Mesh Refinement"; + + public static final String DYNAMIC_OFF_NAME = "Dynamic" + OFF_LABEL; + + private Model model; + private DynamicModule module; + protected DynamicPanel panel; + + public DynamicSolutionView(Model model, DynamicModule module) { + this.model = model; + this.module = module; + } + + @Override + public void buildDynamic(PanelBuilder builder) { + this.panel = new DynamicPanel(); + builder.addFill(panel); + } + + @Override + public boolean hasChanged(State state) { + DynamicAlgorithmType dynamicAlgorithmType = DynamicAlgorithmType.byLabel(panel.getSelectedState()); + if (module.getDynamicData().getAlgorithm().getType() != dynamicAlgorithmType) { + logger.info("DYNAMIC [{} -> {}]", module.getDynamicData().getAlgorithm(), dynamicAlgorithmType); + return true; + } + return false; + } + + @Override + public void updateGUIFromState(State state) { + panel.updateFromState(state, module.getDynamicData().getAlgorithm().getType()); + super.updateGUIFromState(state); + } + + @Override + public void updateStateFromGUI(State state) { + DynamicAlgorithmType dynamicAlgorithmType = panel.getDynamicModel(); + if (state.isDynamic() != dynamicAlgorithmType.isOn()) { + state.setDynamic(dynamicAlgorithmType.isOn()); + } + if (module.getDynamicData().getAlgorithm().getType() != dynamicAlgorithmType) { + if(dynamicAlgorithmType.isSolidRigidBody()){ + module.getDynamicData().setAlgorithm(new SolidBodyAlgorithm()); + } else if(dynamicAlgorithmType.isMultiRigidBody()){ + module.getDynamicData().setAlgorithm(new MultiBodyAlgorithm()); + } else if(dynamicAlgorithmType.is6DOF()){ + module.getDynamicData().setAlgorithm(new SixDoFDAlgorithm()); + } else if(dynamicAlgorithmType.isMeshRefine()){ + module.getDynamicData().setAlgorithm(new MeshRefineAlgorithm()); + } else { + module.getDynamicData().setAlgorithm(new StaticAlgorithm()); + } + } + } + + @Override + public void fixSolutionState(SolutionState ss) { + if (ss.areSolverTypeAndTimeAndFlowAndTurbulenceChoosen()) { + if ((ss.isSegregated() && ss.isSteady()) || ss.isHighMach()) { + panel.select(DynamicAlgorithmType.OFF.getLabel()); + panel.setEnabled(false); + } else { + panel.setEnabled(true); + if(ss.isCoupled()){ + panel.disableChoice(SIX_DOF_LABEL); + panel.disableChoice(SOLID_RIGID_BODY_LABEL); + } else { + panel.enableChoice(SIX_DOF_LABEL); + panel.enableChoice(SOLID_RIGID_BODY_LABEL); + } + + if(model.getCellZones().isEmpty()){ + panel.disableChoice(MULTI_RIGID_BODY_LABEL); + } else { + panel.enableChoice(MULTI_RIGID_BODY_LABEL); + } + } + } else { + panel.select(DynamicAlgorithmType.OFF.getLabel()); + panel.setEnabled(false); + } + } + + @Override + public void fixMultiphase(MultiphaseModel mm) { + if (mm.isOn() && !mm.isDynamic()) { + panel.select(DynamicAlgorithmType.OFF.getLabel()); + panel.setEnabled(false); + } + } + + @Override + public void fixThermal(SolutionState ss, ThermalState ts) { + if (ts.isBuoyancy()) { + panel.select(DynamicAlgorithmType.OFF.getLabel()); + panel.setEnabled(false); + } + } + + public class DynamicPanel extends ChooserPanel { + + public DynamicPanel() { + super(""); + addChoices(); + } + + protected void addChoices() { + JRadioButton offChoice = addChoice(OFF_LABEL); + offChoice.setName(DYNAMIC_OFF_NAME); + addChoice(SIX_DOF_LABEL); + addChoice(SOLID_RIGID_BODY_LABEL); + addChoice(MULTI_RIGID_BODY_LABEL); + addChoice(DYNAMIC_REFINE_FV_MESH_LABEL); + } + + public void updateFromState(State state, DynamicAlgorithmType dynamicData) { + select(dynamicData.getLabel()); + } + + public DynamicAlgorithmType getDynamicModel() { + return DynamicAlgorithmType.byLabel(getSelectedState()); + } + + public void enableChoice(String label) { + AbstractButton button = getButton(label); + if (button != null){ + if (!button.isEnabled() && panel.isEnabled()) { + button.setEnabled(true); + } + } + } + + public void disableChoice(String label) { + AbstractButton button = getButton(label); + if (button != null){ + if (button.isSelected()) { + select(OFF_LABEL); + } + if (button.isEnabled()) { + button.setEnabled(false); + } + } + } + } +} diff --git a/src/eu/engys/dynamic/DynamicTreeView.java b/src/eu/engys/dynamic/DynamicTreeView.java new file mode 100644 index 0000000..99ac535 --- /dev/null +++ b/src/eu/engys/dynamic/DynamicTreeView.java @@ -0,0 +1,70 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.dynamic; + +import eu.engys.core.modules.tree.AbstractTreeViewAdapter; +import eu.engys.core.modules.tree.ModuleElementPanel; +import eu.engys.gui.GUIPanel; + +public class DynamicTreeView extends AbstractTreeViewAdapter { + + private DynamicModule module; + + private GUIPanel sixDoFPanel; + private GUIPanel solidBodyPanel; + private GUIPanel refinePanel; + + public DynamicTreeView(DynamicModule module, GUIPanel sixDoFPanel, GUIPanel solidBodyPanel, GUIPanel refinePanel) { + this.module = module; + this.sixDoFPanel = sixDoFPanel; + this.solidBodyPanel = solidBodyPanel; + this.refinePanel = refinePanel; + } + + @Override + public void updateCaseSetupTree(ModuleElementPanel viewElementPanel) { + if (module.getDynamicData().getAlgorithm().getType().isSolidRigidBody()) { + viewElementPanel.removePanel(sixDoFPanel); + viewElementPanel.removePanel(refinePanel); + viewElementPanel.addPanel(solidBodyPanel); + solidBodyPanel.load(); + } else if (module.getDynamicData().getAlgorithm().getType().is6DOF()) { + viewElementPanel.removePanel(solidBodyPanel); + viewElementPanel.removePanel(refinePanel); + viewElementPanel.addPanel(sixDoFPanel); + sixDoFPanel.load(); + } else if (module.getDynamicData().getAlgorithm().getType().isMeshRefine()) { + viewElementPanel.removePanel(solidBodyPanel); + viewElementPanel.removePanel(sixDoFPanel); + viewElementPanel.addPanel(refinePanel); + refinePanel.load(); + } else { + viewElementPanel.removePanel(solidBodyPanel); + viewElementPanel.removePanel(sixDoFPanel); + viewElementPanel.removePanel(refinePanel); + } + } + +} diff --git a/src/eu/engys/dynamic/DynamicWriter.java b/src/eu/engys/dynamic/DynamicWriter.java new file mode 100644 index 0000000..bdd5c6d --- /dev/null +++ b/src/eu/engys/dynamic/DynamicWriter.java @@ -0,0 +1,56 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.dynamic; + +import static eu.engys.core.project.constant.ConstantFolder.CONSTANT; + +import java.io.File; +import java.nio.file.Paths; + +import eu.engys.core.dictionary.Dictionary; +import eu.engys.core.dictionary.DictionaryUtils; +import eu.engys.core.project.Model; +import eu.engys.dynamic.data.DynamicDataWriter; +import eu.engys.util.progress.SilentMonitor; + +public class DynamicWriter { + + private Model model; + private DynamicModule module; + + public DynamicWriter(Model model, DynamicModule module) { + this.model = model; + this.module = module; + } + + public void write() { + Dictionary dynamicMeshDict = new DynamicDataWriter(model).writeAlgorithm(module.getDynamicData().getAlgorithm()); + module.setDynamicMeshDict(dynamicMeshDict); + + File constDir = Paths.get(model.getProject().getBaseDir().getAbsolutePath(), CONSTANT).toFile(); + DictionaryUtils.writeDictionary(constDir, DictionaryUtils.header(CONSTANT, dynamicMeshDict), new SilentMonitor()); + } + +} diff --git a/src/eu/engys/dynamic/cellzones/DynamicCellZonesView.java b/src/eu/engys/dynamic/cellzones/DynamicCellZonesView.java new file mode 100644 index 0000000..49ca337 --- /dev/null +++ b/src/eu/engys/dynamic/cellzones/DynamicCellZonesView.java @@ -0,0 +1,75 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.dynamic.cellzones; + +import static eu.engys.core.project.zero.cellzones.CellZoneType.DYNAMIC_MESH_KEY; + +import java.util.ArrayList; +import java.util.List; + +import eu.engys.core.dictionary.Dictionary; +import eu.engys.core.modules.cellzones.CellZonesView; +import eu.engys.core.project.Model; +import eu.engys.core.project.zero.cellzones.CellZone; +import eu.engys.core.project.zero.cellzones.CellZoneType; +import eu.engys.core.project.zero.cellzones.CellZones; +import eu.engys.dynamic.DynamicModule; +import eu.engys.dynamic.data.multibody.MultiBodyAlgorithm; + +public class DynamicCellZonesView implements CellZonesView { + + protected Model model; + protected DynamicModule module; + + public DynamicCellZonesView(Model model, DynamicModule module) { + this.model = model; + this.module = module; + } + + @Override + public List getCellZoneTypes() { + List types = new ArrayList(); + types.add(new DynamicMesh(model, module)); + return types; + } + + @Override + public void updateCellZonesFromModel(CellZones cellZones) { + if (module.getDynamicData().getAlgorithm().getType().isMultiRigidBody()) { + MultiBodyAlgorithm multiBody = (MultiBodyAlgorithm) module.getDynamicData().getAlgorithm(); + for (CellZone cz : cellZones) { + if (multiBody.getSingleBodyAlgorithms().containsKey(cz.getName())) { + cz.setDictionary(DYNAMIC_MESH_KEY, new Dictionary("")); + cz.getTypes().add(CellZoneType.DYNAMIC_MESH_KEY); + } + } + } + } + + @Override + public void updateModelFromCellZones() { + } + +} diff --git a/src/eu/engys/dynamic/cellzones/DynamicMesh.java b/src/eu/engys/dynamic/cellzones/DynamicMesh.java new file mode 100644 index 0000000..59399aa --- /dev/null +++ b/src/eu/engys/dynamic/cellzones/DynamicMesh.java @@ -0,0 +1,101 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.dynamic.cellzones; + +import eu.engys.core.dictionary.Dictionary; +import eu.engys.core.modules.cellzones.CellZonePanel; +import eu.engys.core.project.Model; +import eu.engys.core.project.zero.cellzones.CellZoneType; +import eu.engys.dynamic.DynamicModule; + +public class DynamicMesh implements CellZoneType { + + public static final String DYNAMIC_MESH_LABEL = "Dynamic Mesh"; + + private boolean enabled; + + private CellZonePanel panel; + + protected Model model; + protected DynamicModule module; + + public DynamicMesh(Model model, DynamicModule module) { + this.model = model; + this.module = module; + this.enabled = false; + this.panel = createCellZonePanel(); + } + + protected CellZonePanel createCellZonePanel(){ + return new MultiBodyDynamicMeshPanel(model, module); + } + + @Override + public String getKey() { + return CellZoneType.DYNAMIC_MESH_KEY; + } + + @Override + public String getLabel() { + return DYNAMIC_MESH_LABEL; + } + + @Override + public void updateStatusByState() { + setEnabled(module.getDynamicData().getAlgorithm().getType().isMultiRigidBody()); + panel.stateChanged(); + } + + @Override + public Dictionary getDefaultDictionary() { + return new Dictionary(""); + } + + @Override + public boolean isEnabled() { + return enabled; + } + + @Override + public void setEnabled(boolean enabled) { + this.enabled = enabled; + } + + @Override + public CellZonePanel getPanel() { + return panel; + } + + @Override + public String toString() { + return getKey(); + } + + @Override + public int compareTo(CellZoneType type) { + return getLabel().compareTo(type.getLabel()); + } + +} diff --git a/src/eu/engys/dynamic/cellzones/MultiBodyDynamicMeshPanel.java b/src/eu/engys/dynamic/cellzones/MultiBodyDynamicMeshPanel.java new file mode 100644 index 0000000..5c5593c --- /dev/null +++ b/src/eu/engys/dynamic/cellzones/MultiBodyDynamicMeshPanel.java @@ -0,0 +1,103 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.dynamic.cellzones; + +import static eu.engys.dynamic.cellzones.DynamicMesh.DYNAMIC_MESH_LABEL; + +import java.awt.BorderLayout; + +import javax.swing.BorderFactory; +import javax.swing.JComponent; +import javax.swing.JPanel; + +import eu.engys.core.dictionary.Dictionary; +import eu.engys.core.modules.cellzones.CellZonePanel; +import eu.engys.core.project.Model; +import eu.engys.dynamic.DynamicModule; +import eu.engys.dynamic.data.DynamicAlgorithm; +import eu.engys.dynamic.data.multibody.MultiBodyAlgorithm; +import eu.engys.dynamic.data.singlebody.SolidBodyAlgorithm; +import eu.engys.dynamic.domain.SolidBodyDynamicPanel; + +public class MultiBodyDynamicMeshPanel extends JPanel implements CellZonePanel { + + private SolidBodyDynamicPanel solidBodyPanel; + protected Model model; + protected DynamicModule module; + + public MultiBodyDynamicMeshPanel(Model model, DynamicModule module) { + super(new BorderLayout()); + this.model = model; + this.module = module; + setName(DYNAMIC_MESH_LABEL); + this.solidBodyPanel = createSolidBodyPanel(); + } + + protected SolidBodyDynamicPanel createSolidBodyPanel() { + return new SolidBodyDynamicPanel(model, module); + } + + @Override + public void layoutPanel() { + JPanel panel = (JPanel) solidBodyPanel.layoutComponents(); + panel.setBorder(BorderFactory.createTitledBorder(DYNAMIC_MESH_LABEL)); + add(panel, BorderLayout.CENTER); + } + + @Override + public void stateChanged() { + solidBodyPanel.stateChanged(); + } + + @Override + public JComponent getPanel() { + return this; + } + + @Override + public void loadFromDictionary(String cellZoneName, Dictionary cellZoneDictionary) { + // Dynamic cell zones are read from DynamicMeshDict as a bean no need to use dictionaries here + DynamicAlgorithm algo = module.getDynamicData().getAlgorithm(); + if (algo.getType().isMultiRigidBody()) { + MultiBodyAlgorithm mba = (MultiBodyAlgorithm) algo; + SolidBodyAlgorithm singleBodyAlgo = mba.getSingleBodyAlgorithms().get(cellZoneName); + if (singleBodyAlgo != null) { + solidBodyPanel.getMainModel().setBean(singleBodyAlgo.copy()); + } + } + } + + @Override + public Dictionary saveToDictionary(String czName) { + // Dynamic cell zones are saved by the module inside DynamicMeshDict using a bean + DynamicAlgorithm algo = module.getDynamicData().getAlgorithm(); + if (algo.getType().isMultiRigidBody()) { + MultiBodyAlgorithm mba = (MultiBodyAlgorithm) algo; + mba.getSingleBodyAlgorithms().put(czName, solidBodyPanel.getMainModel().getBean().copy()); + } + return new Dictionary(""); + } + +} diff --git a/src/eu/engys/dynamic/data/DynamicAlgorithm.java b/src/eu/engys/dynamic/data/DynamicAlgorithm.java new file mode 100644 index 0000000..24ef7e4 --- /dev/null +++ b/src/eu/engys/dynamic/data/DynamicAlgorithm.java @@ -0,0 +1,34 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.dynamic.data; + +import eu.engys.util.bean.AbstractBean; + +public abstract class DynamicAlgorithm extends AbstractBean { + + public abstract DynamicAlgorithmType getType(); + + public abstract DynamicAlgorithm copy(); +} diff --git a/src/eu/engys/dynamic/data/DynamicAlgorithmType.java b/src/eu/engys/dynamic/data/DynamicAlgorithmType.java new file mode 100644 index 0000000..43fc0e3 --- /dev/null +++ b/src/eu/engys/dynamic/data/DynamicAlgorithmType.java @@ -0,0 +1,124 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.dynamic.data; + +import static eu.engys.dynamic.DynamicMeshDict.DYNAMIC_MOTION_SOLVER_FV_MESH_KEY; +import static eu.engys.dynamic.DynamicMeshDict.DYNAMIC_REFINE_FV_MESH_KEY; +import static eu.engys.dynamic.DynamicMeshDict.MULTI_SOLID_BODY_MOTION_FV_MESH_KEY; +import static eu.engys.dynamic.DynamicMeshDict.SOLID_BODY_MOTION_FV_MESH_KEY; +import static eu.engys.dynamic.DynamicMeshDict.STATIC_FV_MESH_KEY; +import static eu.engys.dynamic.DynamicSolutionView.DYNAMIC_REFINE_FV_MESH_LABEL; +import static eu.engys.dynamic.DynamicSolutionView.MULTI_RIGID_BODY_LABEL; +import static eu.engys.dynamic.DynamicSolutionView.OFF_LABEL; +import static eu.engys.dynamic.DynamicSolutionView.SIX_DOF_LABEL; +import static eu.engys.dynamic.DynamicSolutionView.SOLID_RIGID_BODY_LABEL; + +public enum DynamicAlgorithmType { + + OFF(STATIC_FV_MESH_KEY, OFF_LABEL), + SOLID_RIGID_BODY(SOLID_BODY_MOTION_FV_MESH_KEY, SOLID_RIGID_BODY_LABEL), + MULTI_RIGID_BODY(MULTI_SOLID_BODY_MOTION_FV_MESH_KEY, MULTI_RIGID_BODY_LABEL), + SIX_DOF(DYNAMIC_MOTION_SOLVER_FV_MESH_KEY, SIX_DOF_LABEL), + MESH_REFINE(DYNAMIC_REFINE_FV_MESH_KEY, DYNAMIC_REFINE_FV_MESH_LABEL); + + private String label; + private String key; + + DynamicAlgorithmType(String key, String label) { + this.key = key; + this.label = label; + } + + public String getKey() { + return key; + } + + public String getLabel() { + return label; + } + + public boolean isOff() { + return this == OFF; + } + + public boolean isOn() { + return !isOff(); + } + + public boolean isDomainLevel() { + return isOn() && !isMultiRigidBody(); + } + + public boolean is6DOF() { + return this == SIX_DOF; + } + + public boolean isSolidRigidBody() { + return this == SOLID_RIGID_BODY; + } + + public boolean isMultiRigidBody() { + return this == MULTI_RIGID_BODY; + } + + public boolean isMeshRefine() { + return this == MESH_REFINE; + } + + public static DynamicAlgorithmType byKey(String key) { + if (key == null) + return OFF; + switch (key) { + case DYNAMIC_MOTION_SOLVER_FV_MESH_KEY: + return SIX_DOF; + case SOLID_BODY_MOTION_FV_MESH_KEY: + return SOLID_RIGID_BODY; + case MULTI_SOLID_BODY_MOTION_FV_MESH_KEY: + return MULTI_RIGID_BODY; + case DYNAMIC_REFINE_FV_MESH_KEY: + return MESH_REFINE; + default: + return OFF; + } + } + + public static DynamicAlgorithmType byLabel(String label) { + if (label == null) + return OFF; + switch (label) { + case SIX_DOF_LABEL: + return SIX_DOF; + case SOLID_RIGID_BODY_LABEL: + return SOLID_RIGID_BODY; + case MULTI_RIGID_BODY_LABEL: + return MULTI_RIGID_BODY; + case DYNAMIC_REFINE_FV_MESH_LABEL: + return MESH_REFINE; + default: + return OFF; + } + } + +} diff --git a/src/eu/engys/dynamic/data/DynamicData.java b/src/eu/engys/dynamic/data/DynamicData.java new file mode 100644 index 0000000..02a5acd --- /dev/null +++ b/src/eu/engys/dynamic/data/DynamicData.java @@ -0,0 +1,48 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.dynamic.data; + +import eu.engys.dynamic.data.off.StaticAlgorithm; + +public class DynamicData { + + private DynamicAlgorithm algorithm = new StaticAlgorithm(); + + public DynamicData() { + } + + public DynamicData(DynamicAlgorithm algorithm) { + this.algorithm = algorithm; + } + + public DynamicAlgorithm getAlgorithm() { + return algorithm; + } + + public void setAlgorithm(DynamicAlgorithm algorithm) { + this.algorithm = algorithm; + } + +} diff --git a/src/eu/engys/dynamic/data/DynamicDataReader.java b/src/eu/engys/dynamic/data/DynamicDataReader.java new file mode 100644 index 0000000..1d5f79a --- /dev/null +++ b/src/eu/engys/dynamic/data/DynamicDataReader.java @@ -0,0 +1,551 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.dynamic.data; + +import static eu.engys.dynamic.DynamicMeshDict.ACCELERATION_RELAXATION_KEY; +import static eu.engys.dynamic.DynamicMeshDict.AMPLITUDE_KEY; +import static eu.engys.dynamic.DynamicMeshDict.ANCHOR_KEY; +import static eu.engys.dynamic.DynamicMeshDict.AXIS_KEY; +import static eu.engys.dynamic.DynamicMeshDict.CENTRE_OF_MASS_KEY; +import static eu.engys.dynamic.DynamicMeshDict.CENTRE_OF_ROTATION_KEY; +import static eu.engys.dynamic.DynamicMeshDict.COEFF_KEY; +import static eu.engys.dynamic.DynamicMeshDict.COFG_KEY; +import static eu.engys.dynamic.DynamicMeshDict.CONSTRAINTS_KEY; +import static eu.engys.dynamic.DynamicMeshDict.DAMPING_KEY; +import static eu.engys.dynamic.DynamicMeshDict.DIRECTION_KEY; +import static eu.engys.dynamic.DynamicMeshDict.DTI_KEY; +import static eu.engys.dynamic.DynamicMeshDict.DTP_KEY; +import static eu.engys.dynamic.DynamicMeshDict.DYNAMIC_FV_MESH_KEY; +import static eu.engys.dynamic.DynamicMeshDict.DYNAMIC_REFINE_FV_MESH_COEFFS_KEY; +import static eu.engys.dynamic.DynamicMeshDict.FIELD_KEY; +import static eu.engys.dynamic.DynamicMeshDict.HEAVE_A_KEY; +import static eu.engys.dynamic.DynamicMeshDict.INNER_DISTANCE_KEY; +import static eu.engys.dynamic.DynamicMeshDict.LAMDA_KEY; +import static eu.engys.dynamic.DynamicMeshDict.LOWER_REFINE_LEVEL_KEY; +import static eu.engys.dynamic.DynamicMeshDict.MASS_KEY; +import static eu.engys.dynamic.DynamicMeshDict.MAX_CELLS_KEY; +import static eu.engys.dynamic.DynamicMeshDict.MAX_REFINEMENT_KEY; +import static eu.engys.dynamic.DynamicMeshDict.MOMENT_OF_INERTIA_KEY; +import static eu.engys.dynamic.DynamicMeshDict.MULTI_SOLID_BODY_MOTION_FV_MESH_COEFFS_KEY; +import static eu.engys.dynamic.DynamicMeshDict.NORMAL_KEY; +import static eu.engys.dynamic.DynamicMeshDict.N_BUFFER_LAYERS_KEY; +import static eu.engys.dynamic.DynamicMeshDict.OMEGA_KEY; +import static eu.engys.dynamic.DynamicMeshDict.ORIGIN_KEY; +import static eu.engys.dynamic.DynamicMeshDict.OUTER_DISTANCE_KEY; +import static eu.engys.dynamic.DynamicMeshDict.PATCHES_KEY; +import static eu.engys.dynamic.DynamicMeshDict.PERIOD_KEY; +import static eu.engys.dynamic.DynamicMeshDict.POINT_KEY; +import static eu.engys.dynamic.DynamicMeshDict.Q_KEY; +import static eu.engys.dynamic.DynamicMeshDict.RADIAL_VELOCITY_KEY; +import static eu.engys.dynamic.DynamicMeshDict.REFINE_INTERVAL_KEY; +import static eu.engys.dynamic.DynamicMeshDict.REF_ATTACHMENT_PT_KEY; +import static eu.engys.dynamic.DynamicMeshDict.RESTRAINTS_KEY; +import static eu.engys.dynamic.DynamicMeshDict.REST_LENGTH_KEY; +import static eu.engys.dynamic.DynamicMeshDict.ROLL_A_MAX_KEY; +import static eu.engys.dynamic.DynamicMeshDict.ROLL_A_MIN_KEY; +import static eu.engys.dynamic.DynamicMeshDict.SIX_DOF_RIGID_BODY_MOTION_COEFFS_KEY; +import static eu.engys.dynamic.DynamicMeshDict.SIX_DOF_RIGID_BODY_MOTION_CONSTRAINT_KEY; +import static eu.engys.dynamic.DynamicMeshDict.SIX_DOF_RIGID_BODY_MOTION_RESTRAINT_KEY; +import static eu.engys.dynamic.DynamicMeshDict.SOLID_BODY_MOTION_FUNCTION_KEY; +import static eu.engys.dynamic.DynamicMeshDict.SOLID_BODY_MOTION_FV_MESH_COEFFS_KEY; +import static eu.engys.dynamic.DynamicMeshDict.STIFFNESS_KEY; +import static eu.engys.dynamic.DynamicMeshDict.SWAY_A_KEY; +import static eu.engys.dynamic.DynamicMeshDict.T0_KEY; +import static eu.engys.dynamic.DynamicMeshDict.THETA_KEY; +import static eu.engys.dynamic.DynamicMeshDict.TPN_KEY; +import static eu.engys.dynamic.DynamicMeshDict.TP_KEY; +import static eu.engys.dynamic.DynamicMeshDict.UNREFINE_LEVEL_KEY; +import static eu.engys.dynamic.DynamicMeshDict.UPPER_REFINE_LEVEL_KEY; +import static eu.engys.dynamic.DynamicMeshDict.VELOCITY_KEY; + +import org.apache.commons.math3.util.MathArrays; + +import eu.engys.core.dictionary.Dictionary; +import eu.engys.dynamic.DynamicMeshDict; +import eu.engys.dynamic.data.multibody.MultiBodyAlgorithm; +import eu.engys.dynamic.data.off.StaticAlgorithm; +import eu.engys.dynamic.data.refine.MeshRefineAlgorithm; +import eu.engys.dynamic.data.singlebody.SolidBodyAlgorithm; +import eu.engys.dynamic.data.singlebody.SolidBodyMotionFunction; +import eu.engys.dynamic.data.singlebody.SolidBodyMotionFunctionType; +import eu.engys.dynamic.data.singlebody.functions.AxisRotationMotionFunction; +import eu.engys.dynamic.data.singlebody.functions.LinearMotionFunction; +import eu.engys.dynamic.data.singlebody.functions.OscillatingLinearMotionFunction; +import eu.engys.dynamic.data.singlebody.functions.OscillatingRotatingMotionFunction; +import eu.engys.dynamic.data.singlebody.functions.RotatingMotionFunction; +import eu.engys.dynamic.data.singlebody.functions.RotatingStepMotionFunction; +import eu.engys.dynamic.data.singlebody.functions.SDAMotionFunction; +import eu.engys.dynamic.data.sixdof.SixDoFDAlgorithm; +import eu.engys.dynamic.data.sixdof.constraint.rotation.AxisRotationConstraint; +import eu.engys.dynamic.data.sixdof.constraint.rotation.FixOrientationRotationConstraint; +import eu.engys.dynamic.data.sixdof.constraint.rotation.NoneRotationConstraint; +import eu.engys.dynamic.data.sixdof.constraint.rotation.RotationConstraint; +import eu.engys.dynamic.data.sixdof.constraint.rotation.RotationConstraintType; +import eu.engys.dynamic.data.sixdof.constraint.translation.LineTranslationConstraint; +import eu.engys.dynamic.data.sixdof.constraint.translation.NoneTranslationConstraint; +import eu.engys.dynamic.data.sixdof.constraint.translation.PlaneTranslationConstraint; +import eu.engys.dynamic.data.sixdof.constraint.translation.PointTranslationConstraint; +import eu.engys.dynamic.data.sixdof.constraint.translation.TranslationConstraint; +import eu.engys.dynamic.data.sixdof.constraint.translation.TranslationConstraintType; +import eu.engys.dynamic.data.sixdof.restraint.angular.AngularRestraint; +import eu.engys.dynamic.data.sixdof.restraint.angular.AngularRestraintType; +import eu.engys.dynamic.data.sixdof.restraint.angular.DamperAngularRestraint; +import eu.engys.dynamic.data.sixdof.restraint.angular.NoneAngularRestraint; +import eu.engys.dynamic.data.sixdof.restraint.angular.SpringAngularRestraint; +import eu.engys.dynamic.data.sixdof.restraint.linear.DamperLinearRestraint; +import eu.engys.dynamic.data.sixdof.restraint.linear.LinearRestraint; +import eu.engys.dynamic.data.sixdof.restraint.linear.LinearRestraintType; +import eu.engys.dynamic.data.sixdof.restraint.linear.NoneLinearRestraint; +import eu.engys.dynamic.data.sixdof.restraint.linear.SpringLinearRestraint; + +public class DynamicDataReader { + + public DynamicAlgorithm readAlgorithm(Dictionary dynamicMeshDict) { + String key = dynamicMeshDict.lookupString(DYNAMIC_FV_MESH_KEY); + DynamicAlgorithmType type = DynamicAlgorithmType.byKey(key); + switch (type) { + case SOLID_RIGID_BODY: + return readSingleBodyAlgorithm(dynamicMeshDict); + case MULTI_RIGID_BODY: + return readMultiBodyAlgorithm(dynamicMeshDict); + case SIX_DOF: + return readSixDofAlgorithm(dynamicMeshDict); + case MESH_REFINE: + return readDynamicRefineAlgorithm(dynamicMeshDict); + default: + return new StaticAlgorithm(); + } + } + + DynamicAlgorithm readDynamicRefineAlgorithm(Dictionary dynamicMeshDict) { + MeshRefineAlgorithm algo = new MeshRefineAlgorithm(); + if (dynamicMeshDict.found(DYNAMIC_REFINE_FV_MESH_COEFFS_KEY)) { + Dictionary coeffsDict = dynamicMeshDict.subDict(DYNAMIC_REFINE_FV_MESH_COEFFS_KEY); + if (coeffsDict.found(REFINE_INTERVAL_KEY)) { + algo.setRefineInterval(coeffsDict.lookupInt(REFINE_INTERVAL_KEY)); + } + if (coeffsDict.found(FIELD_KEY)) { + algo.setField(coeffsDict.lookupString(FIELD_KEY)); + } + if (coeffsDict.found(LOWER_REFINE_LEVEL_KEY)) { + algo.setLowerRefineLevel(coeffsDict.lookupDouble(LOWER_REFINE_LEVEL_KEY)); + } + if (coeffsDict.found(UPPER_REFINE_LEVEL_KEY)) { + algo.setUpperRefineLevel(coeffsDict.lookupDouble(UPPER_REFINE_LEVEL_KEY)); + } + if (coeffsDict.found(UNREFINE_LEVEL_KEY)) { + algo.setUnrefineLevel(coeffsDict.lookupInt(UNREFINE_LEVEL_KEY)); + } + if (coeffsDict.found(N_BUFFER_LAYERS_KEY)) { + algo.setnBufferLayers(coeffsDict.lookupInt(N_BUFFER_LAYERS_KEY)); + } + if (coeffsDict.found(MAX_REFINEMENT_KEY)) { + algo.setMaxRefinement(coeffsDict.lookupInt(MAX_REFINEMENT_KEY)); + } + if (coeffsDict.found(MAX_CELLS_KEY)) { + algo.setMaxCells(coeffsDict.lookupInt(MAX_CELLS_KEY)); + } + } + return algo; + } + + DynamicAlgorithm readSixDofAlgorithm(Dictionary dynamicMeshDict) { + SixDoFDAlgorithm algo = new SixDoFDAlgorithm(); + if (dynamicMeshDict.found(SIX_DOF_RIGID_BODY_MOTION_COEFFS_KEY)) { + Dictionary coeffsDict = dynamicMeshDict.subDict(SIX_DOF_RIGID_BODY_MOTION_COEFFS_KEY); + if (coeffsDict.found(MASS_KEY)) { + algo.setMass(coeffsDict.lookupDouble(MASS_KEY)); + } + if (coeffsDict.found(PATCHES_KEY)) { + if (coeffsDict.isList(PATCHES_KEY)) { + algo.setPatches(new String[0]); + } else { + algo.setPatches(coeffsDict.lookupArray(PATCHES_KEY)); + } + + } + if (coeffsDict.found(ACCELERATION_RELAXATION_KEY)) { + algo.setAccelerationRelaxation(coeffsDict.lookupDouble(ACCELERATION_RELAXATION_KEY)); + } + if (coeffsDict.found(VELOCITY_KEY)) { + algo.setVelocity(coeffsDict.lookupDoubleArray(VELOCITY_KEY)); + } + if (coeffsDict.found(MOMENT_OF_INERTIA_KEY)) { + algo.setMomentOfInertia(coeffsDict.lookupDoubleArray(MOMENT_OF_INERTIA_KEY)); + } + if (coeffsDict.found(CENTRE_OF_MASS_KEY)) { + algo.setCentreOfMass(coeffsDict.lookupDoubleArray(CENTRE_OF_MASS_KEY)); + } + if (coeffsDict.found(OUTER_DISTANCE_KEY)) { + algo.setOuterDistance(coeffsDict.lookupDouble(OUTER_DISTANCE_KEY)); + } + if (coeffsDict.found(INNER_DISTANCE_KEY)) { + algo.setInnerDistance(coeffsDict.lookupDouble(INNER_DISTANCE_KEY)); + } + if (coeffsDict.found(CONSTRAINTS_KEY)) { + Dictionary constraintsDict = coeffsDict.subDict(CONSTRAINTS_KEY); + if (constraintsDict.getDictionaries().size() == 1) { + readConstraint(algo, constraintsDict.getDictionaries().get(0)); + } else if (constraintsDict.getDictionaries().size() >= 2) { + readConstraint(algo, constraintsDict.getDictionaries().get(0)); + readConstraint(algo, constraintsDict.getDictionaries().get(1)); + } + } + if (coeffsDict.found(RESTRAINTS_KEY)) { + Dictionary restraintsDict = coeffsDict.subDict(RESTRAINTS_KEY); + if (restraintsDict.getDictionaries().size() == 1) { + readRestraint(algo, restraintsDict.getDictionaries().get(0)); + } else if (restraintsDict.getDictionaries().size() >= 2) { + readRestraint(algo, restraintsDict.getDictionaries().get(0)); + readRestraint(algo, restraintsDict.getDictionaries().get(1)); + } + } + + } + return algo; + } + + private void readConstraint(SixDoFDAlgorithm algo, Dictionary dict) { + if (TranslationConstraintType.isTranslationContraintDict(dict)) { + algo.setTranslationConstraint(readTranslationConstraint(dict)); + } else if (RotationConstraintType.isRotationContraintDict(dict)) { + algo.setRotationConstraint(readRotationConstraint(dict)); + } + } + + private void readRestraint(SixDoFDAlgorithm algo, Dictionary dict) { + if (LinearRestraintType.isLinearRestraintDict(dict)) { + algo.setLinearRestraint(readLinearRestraint(dict)); + } else if (AngularRestraintType.isAngularRestraintDict(dict)) { + algo.setAngularRestraint(readAngularRestraint(dict)); + } + } + + TranslationConstraint readTranslationConstraint(Dictionary translationDict) { + TranslationConstraintType type = TranslationConstraintType.byKey(translationDict.lookupString(SIX_DOF_RIGID_BODY_MOTION_CONSTRAINT_KEY)); + switch (type) { + case POINT: { + PointTranslationConstraint r = new PointTranslationConstraint(); + if (translationDict.found(POINT_KEY)) { + r.setPoint(translationDict.lookupDoubleArray(POINT_KEY)); + } + // used by of+ + if (translationDict.found(CENTRE_OF_ROTATION_KEY)) { + r.setPoint(translationDict.lookupDoubleArray(CENTRE_OF_ROTATION_KEY)); + } + return r; + } + case LINE: { + LineTranslationConstraint r = new LineTranslationConstraint(); + if (translationDict.found(DIRECTION_KEY)) { + r.setDirection(translationDict.lookupDoubleArray(DIRECTION_KEY)); + } + return r; + } + case PLANE: { + PlaneTranslationConstraint r = new PlaneTranslationConstraint(); + if (translationDict.found(NORMAL_KEY)) { + r.setNormal(translationDict.lookupDoubleArray(NORMAL_KEY)); + } + return r; + } + default: + return new NoneTranslationConstraint(); + } + } + + RotationConstraint readRotationConstraint(Dictionary rotationDict) { + RotationConstraintType type = RotationConstraintType.byKey(rotationDict.lookupString(SIX_DOF_RIGID_BODY_MOTION_CONSTRAINT_KEY)); + switch (type) { + case AXIS: { + AxisRotationConstraint r = new AxisRotationConstraint(); + if (rotationDict.found(AXIS_KEY)) { + r.setAxis(rotationDict.lookupDoubleArray(AXIS_KEY)); + } + return r; + } + case FIX_ORIENTATION: { + return new FixOrientationRotationConstraint(); + } + default: + return new NoneRotationConstraint(); + } + + } + + LinearRestraint readLinearRestraint(Dictionary linearDict) { + LinearRestraintType type = LinearRestraintType.byKey(linearDict.lookupString(SIX_DOF_RIGID_BODY_MOTION_RESTRAINT_KEY)); + switch (type) { + case SPRING: { + SpringLinearRestraint r = new SpringLinearRestraint(); + if (linearDict.found(STIFFNESS_KEY)) { + r.setStiffness(linearDict.lookupDouble(STIFFNESS_KEY)); + } + if (linearDict.found(DAMPING_KEY)) { + r.setDamping(linearDict.lookupDouble(DAMPING_KEY)); + } + if (linearDict.found(REF_ATTACHMENT_PT_KEY)) { + r.setRefAttachmentPt(linearDict.lookupDoubleArray(REF_ATTACHMENT_PT_KEY)); + } + if (linearDict.found(REST_LENGTH_KEY)) { + r.setRestLength(linearDict.lookupDouble(REST_LENGTH_KEY)); + } + if (linearDict.found(ANCHOR_KEY)) { + r.setAnchor(linearDict.lookupDoubleArray(ANCHOR_KEY)); + } + return r; + } + case DAMPER: { + DamperLinearRestraint r = new DamperLinearRestraint(); + if (linearDict.found(COEFF_KEY)) { + r.setCoeff(linearDict.lookupDouble(COEFF_KEY)); + } + return r; + } + default: + return new NoneLinearRestraint(); + } + } + + AngularRestraint readAngularRestraint(Dictionary angularDict) { + AngularRestraintType type = AngularRestraintType.byKey(angularDict.lookupString(SIX_DOF_RIGID_BODY_MOTION_RESTRAINT_KEY)); + switch (type) { + case SPRING: { + SpringAngularRestraint r = new SpringAngularRestraint(); + if (angularDict.found(STIFFNESS_KEY)) { + r.setStiffness(angularDict.lookupDouble(STIFFNESS_KEY)); + } + if (angularDict.found(DAMPING_KEY)) { + r.setDamping(angularDict.lookupDouble(DAMPING_KEY)); + } + return r; + } + case DAMPER: { + DamperAngularRestraint r = new DamperAngularRestraint(); + if (angularDict.found(COEFF_KEY)) { + r.setCoeff(angularDict.lookupDouble(COEFF_KEY)); + } + return r; + } + default: + return new NoneAngularRestraint(); + } + } + + DynamicAlgorithm readMultiBodyAlgorithm(Dictionary dynamicMeshDict) { + MultiBodyAlgorithm algo = new MultiBodyAlgorithm(); + if (dynamicMeshDict.found(MULTI_SOLID_BODY_MOTION_FV_MESH_COEFFS_KEY)) { + Dictionary coeffsDict = dynamicMeshDict.subDict(MULTI_SOLID_BODY_MOTION_FV_MESH_COEFFS_KEY); + for (Dictionary d : coeffsDict.getDictionaries()) { + if (d.found(SOLID_BODY_MOTION_FUNCTION_KEY)) { + String function = d.lookupString(SOLID_BODY_MOTION_FUNCTION_KEY); + SolidBodyMotionFunctionType functionType = SolidBodyMotionFunctionType.byKey(function); + String functionCoeffsName = function + DynamicMeshDict.COEFFS_KEY; + if (d.found(functionCoeffsName)) { + Dictionary dict = d.subDict(functionCoeffsName); + algo.getSingleBodyAlgorithms().put(d.getName(), new SolidBodyAlgorithm(readSingleBodyFunction(dict, functionType))); + } + } + } + } + return algo; + } + + DynamicAlgorithm readSingleBodyAlgorithm(Dictionary dynamicMeshDict) { + SolidBodyAlgorithm algo = new SolidBodyAlgorithm(); + if (dynamicMeshDict.found(SOLID_BODY_MOTION_FV_MESH_COEFFS_KEY)) { + Dictionary coeffsDict = dynamicMeshDict.subDict(SOLID_BODY_MOTION_FV_MESH_COEFFS_KEY); + if (coeffsDict.found(SOLID_BODY_MOTION_FUNCTION_KEY)) { + String function = coeffsDict.lookupString(SOLID_BODY_MOTION_FUNCTION_KEY); + SolidBodyMotionFunctionType functionType = SolidBodyMotionFunctionType.byKey(function); + if (coeffsDict.found(function + DynamicMeshDict.COEFFS_KEY)) { + algo.setFunction(readSingleBodyFunction(coeffsDict.subDict(function + DynamicMeshDict.COEFFS_KEY), functionType)); + } + } + } + return algo; + } + + private SolidBodyMotionFunction readSingleBodyFunction(Dictionary d, SolidBodyMotionFunctionType functionType) { + SolidBodyMotionFunction function; + switch (functionType) { + case LINEAR_MOTION: { + function = readLinear(d); + break; + } + case ROTATING_MOTION: { + function = readRotating(d); + break; + } + case ROTATING_STEP_MOTION: { + function = readRotatingStep(d); + break; + } + case AXIS_ROTATION_MOTION: { + function = readAxisRotation(d); + break; + } + case OSCILLATING_LINEAR_MOTION: { + function = readOscillatingLinear(d); + break; + } + case OSCILLATING_ROTATING_MOTION: { + function = readOscillatingRotating(d); + break; + } + case SDA_MOTION: { + function = readSDA(d); + break; + } + default: + function = new LinearMotionFunction(); + break; + } + return function; + } + + SolidBodyMotionFunction readLinear(Dictionary d) { + LinearMotionFunction motion = new LinearMotionFunction(); + if (d.found(VELOCITY_KEY)) { + motion.setVelocity(d.lookupDoubleArray(VELOCITY_KEY)); + } + return motion; + + } + + SolidBodyMotionFunction readRotating(Dictionary d) { + RotatingMotionFunction motion = new RotatingMotionFunction(); + if (d.found(ORIGIN_KEY)) { + motion.setOrigin(d.lookupDoubleArray(ORIGIN_KEY)); + } + if (d.found(AXIS_KEY)) { + motion.setAxis(d.lookupDoubleArray(AXIS_KEY)); + } + if (d.found(OMEGA_KEY)) { + motion.setOmega(d.lookupDouble(OMEGA_KEY)); + } + if (d.found(T0_KEY)) { + motion.setT0(d.lookupDouble(T0_KEY)); + } + return motion; + } + + SolidBodyMotionFunction readRotatingStep(Dictionary d) { + RotatingStepMotionFunction motion = new RotatingStepMotionFunction(); + if (d.found(ORIGIN_KEY)) { + motion.setOrigin(d.lookupDoubleArray(ORIGIN_KEY)); + } + if (d.found(AXIS_KEY)) { + motion.setAxis(d.lookupDoubleArray(AXIS_KEY)); + } + if (d.found(THETA_KEY)) { + motion.setTheta(d.lookupDouble(THETA_KEY)); + } + if (d.found(PERIOD_KEY)) { + motion.setPeriod(d.lookupInt(PERIOD_KEY)); + } + return motion; + } + + SolidBodyMotionFunction readAxisRotation(Dictionary d) { + AxisRotationMotionFunction motion = new AxisRotationMotionFunction(); + if (d.found(ORIGIN_KEY)) { + motion.setOrigin(d.lookupDoubleArray(ORIGIN_KEY)); + } + if (d.found(RADIAL_VELOCITY_KEY)) { + double[] rv = d.lookupDoubleArray(RADIAL_VELOCITY_KEY); + double omega = Math.sqrt(Math.pow(rv[0], 2) + Math.pow(rv[1], 2) + Math.pow(rv[2], 2)); + double[] axis = omega > 0 ? MathArrays.scale(1 / omega, rv) : new double[] { 0, 0, 0 }; + + motion.setAxis(axis); + motion.setOmega(Math.toRadians(omega)); + } + return motion; + } + + SolidBodyMotionFunction readOscillatingLinear(Dictionary d) { + OscillatingLinearMotionFunction motion = new OscillatingLinearMotionFunction(); + if (d.found(AMPLITUDE_KEY)) { + motion.setAmplitude(d.lookupDoubleArray(AMPLITUDE_KEY)); + } + if (d.found(OMEGA_KEY)) { + motion.setOmega(d.lookupDouble(OMEGA_KEY)); + } + return motion; + } + + SolidBodyMotionFunction readOscillatingRotating(Dictionary d) { + OscillatingRotatingMotionFunction motion = new OscillatingRotatingMotionFunction(); + if (d.found(ORIGIN_KEY)) { + motion.setOrigin(d.lookupDoubleArray(ORIGIN_KEY)); + } + if (d.found(AMPLITUDE_KEY)) { + motion.setAmplitude(d.lookupDoubleArray(AMPLITUDE_KEY)); + } + if (d.found(OMEGA_KEY)) { + motion.setOmega(d.lookupDouble(OMEGA_KEY)); + } + return motion; + } + + SolidBodyMotionFunction readSDA(Dictionary d) { + SDAMotionFunction motion = new SDAMotionFunction(); + if (d.found(TPN_KEY)) { + motion.setTpn(d.lookupDouble(TPN_KEY)); + } + if (d.found(TP_KEY)) { + motion.setTp(d.lookupDouble(TP_KEY)); + } + if (d.found(SWAY_A_KEY)) { + motion.setSwayA(d.lookupDouble(SWAY_A_KEY)); + } + if (d.found(ROLL_A_MIN_KEY)) { + motion.setRollAmin(d.lookupDouble(ROLL_A_MIN_KEY)); + } + if (d.found(Q_KEY)) { + motion.setQ(d.lookupDouble(Q_KEY)); + } + if (d.found(LAMDA_KEY)) { + motion.setLambda(d.lookupDouble(LAMDA_KEY)); + } + if (d.found(HEAVE_A_KEY)) { + motion.setHeaveA(d.lookupDouble(HEAVE_A_KEY)); + } + if (d.found(DTI_KEY)) { + motion.setDti(d.lookupDouble(DTI_KEY)); + } + if (d.found(ROLL_A_MAX_KEY)) { + motion.setRollAmax(d.lookupDouble(ROLL_A_MAX_KEY)); + } + if (d.found(DTP_KEY)) { + motion.setDtp(d.lookupDouble(DTP_KEY)); + } + if (d.found(COFG_KEY)) { + motion.setCofg(d.lookupDoubleArray(COFG_KEY)); + } + return motion; + } + +} diff --git a/src/eu/engys/dynamic/data/DynamicDataWriter.java b/src/eu/engys/dynamic/data/DynamicDataWriter.java new file mode 100644 index 0000000..00c6d21 --- /dev/null +++ b/src/eu/engys/dynamic/data/DynamicDataWriter.java @@ -0,0 +1,488 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.dynamic.data; + +import static eu.engys.core.dictionary.Dictionary.TYPE; +import static eu.engys.dynamic.DynamicMeshDict.ACCELERATION_RELAXATION_KEY; +import static eu.engys.dynamic.DynamicMeshDict.AMPLITUDE_KEY; +import static eu.engys.dynamic.DynamicMeshDict.ANCHOR_KEY; +import static eu.engys.dynamic.DynamicMeshDict.ANGULAR_RESTRAINT_KEY; +import static eu.engys.dynamic.DynamicMeshDict.AXIS_KEY; +import static eu.engys.dynamic.DynamicMeshDict.AXIS_ROTATION_MOTION_COEFFS_KEY; +import static eu.engys.dynamic.DynamicMeshDict.AXIS_ROTATION_MOTION_KEY; +import static eu.engys.dynamic.DynamicMeshDict.CENTRE_OF_MASS_KEY; +import static eu.engys.dynamic.DynamicMeshDict.CENTRE_OF_ROTATION_KEY; +import static eu.engys.dynamic.DynamicMeshDict.COEFF_KEY; +import static eu.engys.dynamic.DynamicMeshDict.COFG_KEY; +import static eu.engys.dynamic.DynamicMeshDict.CONSTRAINTS_KEY; +import static eu.engys.dynamic.DynamicMeshDict.CORRECT_FLUXES_KEY; +import static eu.engys.dynamic.DynamicMeshDict.CORRECT_FLUXES_VALUE; +import static eu.engys.dynamic.DynamicMeshDict.DAMPING_KEY; +import static eu.engys.dynamic.DynamicMeshDict.DIRECTION_KEY; +import static eu.engys.dynamic.DynamicMeshDict.DTI_KEY; +import static eu.engys.dynamic.DynamicMeshDict.DTP_KEY; +import static eu.engys.dynamic.DynamicMeshDict.DUMP_LEVEL_KEY; +import static eu.engys.dynamic.DynamicMeshDict.DYNAMIC_FV_MESH_KEY; +import static eu.engys.dynamic.DynamicMeshDict.DYNAMIC_MESH_DICT; +import static eu.engys.dynamic.DynamicMeshDict.DYNAMIC_MOTION_SOLVER_FV_MESH_KEY; +import static eu.engys.dynamic.DynamicMeshDict.DYNAMIC_REFINE_FV_MESH_COEFFS_KEY; +import static eu.engys.dynamic.DynamicMeshDict.DYNAMIC_REFINE_FV_MESH_KEY; +import static eu.engys.dynamic.DynamicMeshDict.FIELD_KEY; +import static eu.engys.dynamic.DynamicMeshDict.HEAVE_A_KEY; +import static eu.engys.dynamic.DynamicMeshDict.INNER_DISTANCE_KEY; +import static eu.engys.dynamic.DynamicMeshDict.LAMDA_KEY; +import static eu.engys.dynamic.DynamicMeshDict.LINEAR_DAMPER_KEY; +import static eu.engys.dynamic.DynamicMeshDict.LINEAR_MOTION_COEFFS_KEY; +import static eu.engys.dynamic.DynamicMeshDict.LINEAR_MOTION_KEY; +import static eu.engys.dynamic.DynamicMeshDict.LINEAR_RESTRAINT_KEY; +import static eu.engys.dynamic.DynamicMeshDict.LINEAR_SPRING_KEY; +import static eu.engys.dynamic.DynamicMeshDict.LINE_KEY; +import static eu.engys.dynamic.DynamicMeshDict.LOWER_REFINE_LEVEL_KEY; +import static eu.engys.dynamic.DynamicMeshDict.MASS_KEY; +import static eu.engys.dynamic.DynamicMeshDict.MAX_CELLS_KEY; +import static eu.engys.dynamic.DynamicMeshDict.MAX_REFINEMENT_KEY; +import static eu.engys.dynamic.DynamicMeshDict.MOMENT_OF_INERTIA_KEY; +import static eu.engys.dynamic.DynamicMeshDict.MOTION_SOLVER_LIBS_KEY; +import static eu.engys.dynamic.DynamicMeshDict.MULTIBODY_DYNAMIC_LIBRARIES; +import static eu.engys.dynamic.DynamicMeshDict.MULTI_SOLID_BODY_MOTION_FV_MESH_COEFFS_KEY; +import static eu.engys.dynamic.DynamicMeshDict.MULTI_SOLID_BODY_MOTION_FV_MESH_KEY; +import static eu.engys.dynamic.DynamicMeshDict.NEWMARK_KEY; +import static eu.engys.dynamic.DynamicMeshDict.NORMAL_KEY; +import static eu.engys.dynamic.DynamicMeshDict.N_BUFFER_LAYERS_KEY; +import static eu.engys.dynamic.DynamicMeshDict.OMEGA_KEY; +import static eu.engys.dynamic.DynamicMeshDict.ORIENTATION_KEY; +import static eu.engys.dynamic.DynamicMeshDict.ORIGIN_KEY; +import static eu.engys.dynamic.DynamicMeshDict.OSCILLATING_LINEAR_MOTION_COEFFS_KEY; +import static eu.engys.dynamic.DynamicMeshDict.OSCILLATING_LINEAR_MOTION_KEY; +import static eu.engys.dynamic.DynamicMeshDict.OSCILLATING_ROTATING_MOTION_COEFFS_KEY; +import static eu.engys.dynamic.DynamicMeshDict.OSCILLATING_ROTATING_MOTION_KEY; +import static eu.engys.dynamic.DynamicMeshDict.OUTER_DISTANCE_KEY; +import static eu.engys.dynamic.DynamicMeshDict.PATCHES_KEY; +import static eu.engys.dynamic.DynamicMeshDict.PERIOD_KEY; +import static eu.engys.dynamic.DynamicMeshDict.PLANE_KEY; +import static eu.engys.dynamic.DynamicMeshDict.POINT_KEY; +import static eu.engys.dynamic.DynamicMeshDict.Q_KEY; +import static eu.engys.dynamic.DynamicMeshDict.RADIAL_VELOCITY_KEY; +import static eu.engys.dynamic.DynamicMeshDict.REFINE_INTERVAL_KEY; +import static eu.engys.dynamic.DynamicMeshDict.REF_ATTACHMENT_PT_KEY; +import static eu.engys.dynamic.DynamicMeshDict.REPORT_KEY; +import static eu.engys.dynamic.DynamicMeshDict.RESTRAINTS_KEY; +import static eu.engys.dynamic.DynamicMeshDict.REST_LENGTH_KEY; +import static eu.engys.dynamic.DynamicMeshDict.RHO_INF_KEY; +import static eu.engys.dynamic.DynamicMeshDict.RHO_KEY; +import static eu.engys.dynamic.DynamicMeshDict.ROLL_A_MAX_KEY; +import static eu.engys.dynamic.DynamicMeshDict.ROLL_A_MIN_KEY; +import static eu.engys.dynamic.DynamicMeshDict.ROTATING_MOTION_COEFFS_KEY; +import static eu.engys.dynamic.DynamicMeshDict.ROTATING_MOTION_KEY; +import static eu.engys.dynamic.DynamicMeshDict.ROTATING_STEP_MOTION_COEFFS_KEY; +import static eu.engys.dynamic.DynamicMeshDict.ROTATING_STEP_MOTION_KEY; +import static eu.engys.dynamic.DynamicMeshDict.ROTATION_CONSTRAINT_KEY; +import static eu.engys.dynamic.DynamicMeshDict.SDA_COEFFS_KEY; +import static eu.engys.dynamic.DynamicMeshDict.SDA_KEY; +import static eu.engys.dynamic.DynamicMeshDict.SIX_DOF_DYNAMIC_LIBRARIES; +import static eu.engys.dynamic.DynamicMeshDict.SIX_DOF_RIGID_BODY_MOTION_COEFFS_KEY; +import static eu.engys.dynamic.DynamicMeshDict.SIX_DOF_RIGID_BODY_MOTION_CONSTRAINT_KEY; +import static eu.engys.dynamic.DynamicMeshDict.SIX_DOF_RIGID_BODY_MOTION_KEY; +import static eu.engys.dynamic.DynamicMeshDict.SIX_DOF_RIGID_BODY_MOTION_RESTRAINT_KEY; +import static eu.engys.dynamic.DynamicMeshDict.SOLID_BODY_MOTION_FUNCTION_KEY; +import static eu.engys.dynamic.DynamicMeshDict.SOLID_BODY_MOTION_FV_MESH_COEFFS_KEY; +import static eu.engys.dynamic.DynamicMeshDict.SOLID_BODY_MOTION_FV_MESH_KEY; +import static eu.engys.dynamic.DynamicMeshDict.SOLVER_KEY; +import static eu.engys.dynamic.DynamicMeshDict.SPHERICAL_ANGULAR_DAMPER_KEY; +import static eu.engys.dynamic.DynamicMeshDict.SPHERICAL_ANGULAR_SPRING_KEY; +import static eu.engys.dynamic.DynamicMeshDict.STATIC_FV_MESH_KEY; +import static eu.engys.dynamic.DynamicMeshDict.STIFFNESS_KEY; +import static eu.engys.dynamic.DynamicMeshDict.SWAY_A_KEY; +import static eu.engys.dynamic.DynamicMeshDict.T0_KEY; +import static eu.engys.dynamic.DynamicMeshDict.THETA_KEY; +import static eu.engys.dynamic.DynamicMeshDict.TPN_KEY; +import static eu.engys.dynamic.DynamicMeshDict.TP_KEY; +import static eu.engys.dynamic.DynamicMeshDict.TRANSLATION_CONSTRAINT_KEY; +import static eu.engys.dynamic.DynamicMeshDict.UNREFINE_LEVEL_KEY; +import static eu.engys.dynamic.DynamicMeshDict.UPPER_REFINE_LEVEL_KEY; +import static eu.engys.dynamic.DynamicMeshDict.VELOCITY_KEY; + +import org.apache.commons.math3.util.MathArrays; + +import eu.engys.core.dictionary.Dictionary; +import eu.engys.core.project.Model; +import eu.engys.dynamic.data.multibody.MultiBodyAlgorithm; +import eu.engys.dynamic.data.refine.MeshRefineAlgorithm; +import eu.engys.dynamic.data.singlebody.SolidBodyAlgorithm; +import eu.engys.dynamic.data.singlebody.SolidBodyMotionFunction; +import eu.engys.dynamic.data.singlebody.functions.AxisRotationMotionFunction; +import eu.engys.dynamic.data.singlebody.functions.LinearMotionFunction; +import eu.engys.dynamic.data.singlebody.functions.OscillatingLinearMotionFunction; +import eu.engys.dynamic.data.singlebody.functions.OscillatingRotatingMotionFunction; +import eu.engys.dynamic.data.singlebody.functions.RotatingMotionFunction; +import eu.engys.dynamic.data.singlebody.functions.RotatingStepMotionFunction; +import eu.engys.dynamic.data.singlebody.functions.SDAMotionFunction; +import eu.engys.dynamic.data.sixdof.SixDoFDAlgorithm; +import eu.engys.dynamic.data.sixdof.constraint.rotation.AxisRotationConstraint; +import eu.engys.dynamic.data.sixdof.constraint.rotation.RotationConstraint; +import eu.engys.dynamic.data.sixdof.constraint.translation.LineTranslationConstraint; +import eu.engys.dynamic.data.sixdof.constraint.translation.PlaneTranslationConstraint; +import eu.engys.dynamic.data.sixdof.constraint.translation.PointTranslationConstraint; +import eu.engys.dynamic.data.sixdof.constraint.translation.TranslationConstraint; +import eu.engys.dynamic.data.sixdof.restraint.angular.AngularRestraint; +import eu.engys.dynamic.data.sixdof.restraint.angular.DamperAngularRestraint; +import eu.engys.dynamic.data.sixdof.restraint.angular.SpringAngularRestraint; +import eu.engys.dynamic.data.sixdof.restraint.linear.DamperLinearRestraint; +import eu.engys.dynamic.data.sixdof.restraint.linear.LinearRestraint; +import eu.engys.dynamic.data.sixdof.restraint.linear.SpringLinearRestraint; + +public class DynamicDataWriter { + + private Model model; + + public DynamicDataWriter(Model model) { + this.model = model; + } + + public Dictionary writeAlgorithm(DynamicAlgorithm algo) { + Dictionary dynamicMeshDict = new Dictionary(DYNAMIC_MESH_DICT); + switch (algo.getType()) { + case SOLID_RIGID_BODY: + writeSingleBodyAlgorithm(algo, dynamicMeshDict); + break; + case MULTI_RIGID_BODY: + writeMultiBodyAlgorithm(algo, dynamicMeshDict); + break; + case SIX_DOF: + writeSixDofAlgorithm(algo, dynamicMeshDict); + break; + case MESH_REFINE: + writeDynamicRefineAlgorithm(algo, dynamicMeshDict); + break; + default: + writeStaticAlgorithm(algo, dynamicMeshDict); + break; + } + return dynamicMeshDict; + } + + private void writeStaticAlgorithm(DynamicAlgorithm algo, Dictionary dynamicMeshDict) { + dynamicMeshDict.add(DYNAMIC_FV_MESH_KEY, STATIC_FV_MESH_KEY); + } + + void writeSingleBodyAlgorithm(DynamicAlgorithm a, Dictionary dynamicMeshDict) { + SolidBodyAlgorithm algo = (SolidBodyAlgorithm) a; + + Dictionary coeffsDict = new Dictionary(SOLID_BODY_MOTION_FV_MESH_COEFFS_KEY); + writeSingleBodyFunction(algo.getFunction(), coeffsDict); + + dynamicMeshDict.add(DYNAMIC_FV_MESH_KEY, SOLID_BODY_MOTION_FV_MESH_KEY); + dynamicMeshDict.add(coeffsDict); + } + + private void writeSingleBodyFunction(SolidBodyMotionFunction function, Dictionary coeffsDict) { + switch (function.getFunctionType()) { + case LINEAR_MOTION: { + writeLinear(function, coeffsDict); + break; + } + case ROTATING_MOTION: { + writeRotating(function, coeffsDict); + break; + } + case ROTATING_STEP_MOTION: { + writeRotatingStep(function, coeffsDict); + break; + } + case AXIS_ROTATION_MOTION: { + writeAxisRotation(function, coeffsDict); + break; + } + case OSCILLATING_LINEAR_MOTION: { + writeOscillatingLinear(function, coeffsDict); + break; + } + case OSCILLATING_ROTATING_MOTION: { + writeOscillatingRotating(function, coeffsDict); + break; + } + case SDA_MOTION: { + writeSDA(function, coeffsDict); + break; + } + default: + break; + } + } + + void writeLinear(SolidBodyMotionFunction function, Dictionary coeffsDict) { + LinearMotionFunction f = (LinearMotionFunction) function; + Dictionary functionDict = new Dictionary(LINEAR_MOTION_COEFFS_KEY); + functionDict.add(VELOCITY_KEY, f.getVelocity()); + + coeffsDict.add(SOLID_BODY_MOTION_FUNCTION_KEY, LINEAR_MOTION_KEY); + coeffsDict.add(functionDict); + } + + void writeRotating(SolidBodyMotionFunction function, Dictionary coeffsDict) { + RotatingMotionFunction f = (RotatingMotionFunction) function; + Dictionary functionDict = new Dictionary(ROTATING_MOTION_COEFFS_KEY); + functionDict.add(ORIGIN_KEY, f.getOrigin()); + functionDict.add(AXIS_KEY, f.getAxis()); + functionDict.add(OMEGA_KEY, f.getOmega()); + functionDict.add(T0_KEY, f.getT0()); + + coeffsDict.add(SOLID_BODY_MOTION_FUNCTION_KEY, ROTATING_MOTION_KEY); + coeffsDict.add(functionDict); + } + + void writeRotatingStep(SolidBodyMotionFunction function, Dictionary coeffsDict) { + RotatingStepMotionFunction f = (RotatingStepMotionFunction) function; + Dictionary functionDict = new Dictionary(ROTATING_STEP_MOTION_COEFFS_KEY); + functionDict.add(ORIGIN_KEY, f.getOrigin()); + functionDict.add(AXIS_KEY, f.getAxis()); + functionDict.add(THETA_KEY, f.getTheta()); + functionDict.add(PERIOD_KEY, f.getPeriod()); + + coeffsDict.add(SOLID_BODY_MOTION_FUNCTION_KEY, ROTATING_STEP_MOTION_KEY); + coeffsDict.add(functionDict); + } + + void writeAxisRotation(SolidBodyMotionFunction function, Dictionary coeffsDict) { + AxisRotationMotionFunction f = (AxisRotationMotionFunction) function; + Dictionary functionDict = new Dictionary(AXIS_ROTATION_MOTION_COEFFS_KEY); + functionDict.add(ORIGIN_KEY, f.getOrigin()); + functionDict.add(RADIAL_VELOCITY_KEY, MathArrays.scale(Math.toDegrees(f.getOmega()), f.getAxis())); + + coeffsDict.add(SOLID_BODY_MOTION_FUNCTION_KEY, AXIS_ROTATION_MOTION_KEY); + coeffsDict.add(functionDict); + } + + void writeOscillatingLinear(SolidBodyMotionFunction function, Dictionary coeffsDict) { + OscillatingLinearMotionFunction f = (OscillatingLinearMotionFunction) function; + Dictionary functionDict = new Dictionary(OSCILLATING_LINEAR_MOTION_COEFFS_KEY); + functionDict.add(AMPLITUDE_KEY, f.getAmplitude()); + functionDict.add(OMEGA_KEY, f.getOmega()); + + coeffsDict.add(SOLID_BODY_MOTION_FUNCTION_KEY, OSCILLATING_LINEAR_MOTION_KEY); + coeffsDict.add(functionDict); + } + + void writeOscillatingRotating(SolidBodyMotionFunction function, Dictionary coeffsDict) { + OscillatingRotatingMotionFunction f = (OscillatingRotatingMotionFunction) function; + Dictionary functionDict = new Dictionary(OSCILLATING_ROTATING_MOTION_COEFFS_KEY); + functionDict.add(AMPLITUDE_KEY, f.getAmplitude()); + functionDict.add(OMEGA_KEY, f.getOmega()); + functionDict.add(ORIGIN_KEY, f.getOrigin()); + + coeffsDict.add(SOLID_BODY_MOTION_FUNCTION_KEY, OSCILLATING_ROTATING_MOTION_KEY); + coeffsDict.add(functionDict); + } + + void writeSDA(SolidBodyMotionFunction function, Dictionary coeffsDict) { + SDAMotionFunction f = (SDAMotionFunction) function; + Dictionary functionDict = new Dictionary(SDA_COEFFS_KEY); + functionDict.add(TPN_KEY, f.getTpn()); + functionDict.add(TP_KEY, f.getTp()); + functionDict.add(SWAY_A_KEY, f.getSwayA()); + functionDict.add(ROLL_A_MIN_KEY, f.getRollAmin()); + functionDict.add(Q_KEY, f.getQ()); + functionDict.add(LAMDA_KEY, f.getLambda()); + functionDict.add(HEAVE_A_KEY, f.getHeaveA()); + functionDict.add(DTI_KEY, f.getDti()); + functionDict.add(ROLL_A_MAX_KEY, f.getRollAmax()); + functionDict.add(DTP_KEY, f.getDtp()); + functionDict.add(COFG_KEY, f.getCofg()); + + coeffsDict.add(SOLID_BODY_MOTION_FUNCTION_KEY, SDA_KEY); + coeffsDict.add(functionDict); + } + + void writeMultiBodyAlgorithm(DynamicAlgorithm a, Dictionary dynamicMeshDict) { + MultiBodyAlgorithm algo = (MultiBodyAlgorithm) a; + + Dictionary coeffsDict = new Dictionary(MULTI_SOLID_BODY_MOTION_FV_MESH_COEFFS_KEY); + + for (String czName : algo.getSingleBodyAlgorithms().keySet()) { + Dictionary czDict = new Dictionary(czName); + writeSingleBodyFunction(algo.getSingleBodyAlgorithms().get(czName).getFunction(), czDict); + coeffsDict.add(czDict); + } + + dynamicMeshDict.add(DYNAMIC_FV_MESH_KEY, MULTI_SOLID_BODY_MOTION_FV_MESH_KEY); + dynamicMeshDict.add(coeffsDict); + dynamicMeshDict.add(MOTION_SOLVER_LIBS_KEY, MULTIBODY_DYNAMIC_LIBRARIES); + } + + void writeSixDofAlgorithm(DynamicAlgorithm a, Dictionary dynamicMeshDict) { + SixDoFDAlgorithm algo = (SixDoFDAlgorithm) a; + + Dictionary coeffsDict = new Dictionary(SIX_DOF_RIGID_BODY_MOTION_COEFFS_KEY); + coeffsDict.add(MASS_KEY, algo.getMass()); + coeffsDict.add(PATCHES_KEY, algo.getPatches()); + coeffsDict.add(ACCELERATION_RELAXATION_KEY, algo.getAccelerationRelaxation()); + coeffsDict.add(REPORT_KEY, true); + coeffsDict.add(VELOCITY_KEY, algo.getVelocity()); + coeffsDict.add(MOMENT_OF_INERTIA_KEY, algo.getMomentOfInertia()); + coeffsDict.add(CENTRE_OF_MASS_KEY, algo.getCentreOfMass()); + coeffsDict.add(OUTER_DISTANCE_KEY, algo.getOuterDistance()); + coeffsDict.add(INNER_DISTANCE_KEY, algo.getInnerDistance()); + + if (model.getState().isCompressible() || model.getState().getMultiphaseModel().isMultiphase()) { + coeffsDict.add(RHO_INF_KEY, 1); + } else if (model.getState().isIncompressible()) { + coeffsDict.add(RHO_KEY, RHO_INF_KEY); + coeffsDict.add(RHO_INF_KEY, 1); + } + + + //OS + coeffsDict.add(new Dictionary(SOLVER_KEY)); + coeffsDict.subDict(SOLVER_KEY).add(TYPE, NEWMARK_KEY); + + Dictionary constraintsDict = new Dictionary(CONSTRAINTS_KEY); + writeTranslationConstraint(algo.getTranslationConstraint(), constraintsDict); + writeRotationConstraint(algo.getRotationConstraint(), constraintsDict); + coeffsDict.add(constraintsDict); + + Dictionary restraintsDict = new Dictionary(RESTRAINTS_KEY); + writeLinearRestraint(algo.getLinearRestraint(), restraintsDict); + writeAngularRestraint(algo.getAngularRestraint(), restraintsDict); + coeffsDict.add(restraintsDict); + + dynamicMeshDict.add(DYNAMIC_FV_MESH_KEY, DYNAMIC_MOTION_SOLVER_FV_MESH_KEY); + dynamicMeshDict.add(SOLVER_KEY, SIX_DOF_RIGID_BODY_MOTION_KEY); + dynamicMeshDict.add(coeffsDict); + dynamicMeshDict.add(MOTION_SOLVER_LIBS_KEY, SIX_DOF_DYNAMIC_LIBRARIES); + } + + void writeDynamicRefineAlgorithm(DynamicAlgorithm a, Dictionary dynamicMeshDict) { + MeshRefineAlgorithm algo = (MeshRefineAlgorithm) a; + + Dictionary coeffsDict = new Dictionary(DYNAMIC_REFINE_FV_MESH_COEFFS_KEY); + coeffsDict.add(REFINE_INTERVAL_KEY, algo.getRefineInterval()); + coeffsDict.add(FIELD_KEY, algo.getField()); + coeffsDict.add(LOWER_REFINE_LEVEL_KEY, algo.getLowerRefineLevel()); + coeffsDict.add(UPPER_REFINE_LEVEL_KEY, algo.getUpperRefineLevel()); + coeffsDict.add(UNREFINE_LEVEL_KEY, algo.getUnrefineLevel()); + coeffsDict.add(N_BUFFER_LAYERS_KEY, algo.getnBufferLayers()); + coeffsDict.add(MAX_REFINEMENT_KEY, algo.getMaxRefinement()); + coeffsDict.add(MAX_CELLS_KEY, algo.getMaxCells()); + coeffsDict.add(CORRECT_FLUXES_KEY, CORRECT_FLUXES_VALUE); + coeffsDict.add(DUMP_LEVEL_KEY, true); + + dynamicMeshDict.add(DYNAMIC_FV_MESH_KEY, DYNAMIC_REFINE_FV_MESH_KEY); + dynamicMeshDict.add(coeffsDict); + } + + void writeTranslationConstraint(TranslationConstraint constraint, Dictionary constraintsDict) { + if (constraint.getType().isNone()) { + // do nothing + } else { + Dictionary translationDict = new Dictionary(TRANSLATION_CONSTRAINT_KEY); + switch (constraint.getType()) { + case POINT: + translationDict.add(SIX_DOF_RIGID_BODY_MOTION_CONSTRAINT_KEY, POINT_KEY); + translationDict.add(POINT_KEY, ((PointTranslationConstraint) constraint).getPoint()); + translationDict.add(CENTRE_OF_ROTATION_KEY, ((PointTranslationConstraint) constraint).getPoint());//used by of+ + break; + case LINE: + translationDict.add(SIX_DOF_RIGID_BODY_MOTION_CONSTRAINT_KEY, LINE_KEY); + translationDict.add(DIRECTION_KEY, ((LineTranslationConstraint) constraint).getDirection()); + break; + case PLANE: + translationDict.add(SIX_DOF_RIGID_BODY_MOTION_CONSTRAINT_KEY, PLANE_KEY); + translationDict.add(NORMAL_KEY, ((PlaneTranslationConstraint) constraint).getNormal()); + break; + default: + break; + } + constraintsDict.add(translationDict); + } + } + + void writeRotationConstraint(RotationConstraint constraint, Dictionary constraintsDict) { + if (constraint.getType().isNone()) { + // do nothing + } else { + Dictionary rotationDict = new Dictionary(ROTATION_CONSTRAINT_KEY); + switch (constraint.getType()) { + case AXIS: + rotationDict.add(SIX_DOF_RIGID_BODY_MOTION_CONSTRAINT_KEY, AXIS_KEY); + rotationDict.add(AXIS_KEY, ((AxisRotationConstraint) constraint).getAxis()); + break; + case FIX_ORIENTATION: + rotationDict.add(SIX_DOF_RIGID_BODY_MOTION_CONSTRAINT_KEY, ORIENTATION_KEY); + break; + default: + break; + } + constraintsDict.add(rotationDict); + } + } + + void writeLinearRestraint(LinearRestraint restraint, Dictionary constraintsDict) { + if (restraint.getType().isNone()) { + // do nothing + } else { + Dictionary linearDict = new Dictionary(LINEAR_RESTRAINT_KEY); + switch (restraint.getType()) { + case DAMPER: + linearDict.add(SIX_DOF_RIGID_BODY_MOTION_RESTRAINT_KEY, LINEAR_DAMPER_KEY); + linearDict.add(COEFF_KEY, ((DamperLinearRestraint) restraint).getCoeff()); + break; + case SPRING: + linearDict.add(SIX_DOF_RIGID_BODY_MOTION_RESTRAINT_KEY, LINEAR_SPRING_KEY); + linearDict.add(STIFFNESS_KEY, ((SpringLinearRestraint) restraint).getStiffness()); + linearDict.add(DAMPING_KEY, ((SpringLinearRestraint) restraint).getDamping()); + linearDict.add(REF_ATTACHMENT_PT_KEY, ((SpringLinearRestraint) restraint).getRefAttachmentPt()); + linearDict.add(REST_LENGTH_KEY, ((SpringLinearRestraint) restraint).getRestLength()); + linearDict.add(ANCHOR_KEY, ((SpringLinearRestraint) restraint).getAnchor()); + break; + default: + break; + } + constraintsDict.add(linearDict); + } + } + + void writeAngularRestraint(AngularRestraint restraint, Dictionary constraintsDict) { + if (restraint.getType().isNone()) { + // do nothing + } else { + Dictionary angularDict = new Dictionary(ANGULAR_RESTRAINT_KEY); + switch (restraint.getType()) { + case DAMPER: + angularDict.add(SIX_DOF_RIGID_BODY_MOTION_RESTRAINT_KEY, SPHERICAL_ANGULAR_DAMPER_KEY); + angularDict.add(COEFF_KEY, ((DamperAngularRestraint) restraint).getCoeff()); + break; + case SPRING: + angularDict.add(SIX_DOF_RIGID_BODY_MOTION_RESTRAINT_KEY, SPHERICAL_ANGULAR_SPRING_KEY); + angularDict.add(STIFFNESS_KEY, ((SpringAngularRestraint) restraint).getStiffness()); + angularDict.add(DAMPING_KEY, ((SpringAngularRestraint) restraint).getDamping()); + break; + default: + break; + } + constraintsDict.add(angularDict); + } + } + +} diff --git a/src/eu/engys/dynamic/data/multibody/MultiBodyAlgorithm.java b/src/eu/engys/dynamic/data/multibody/MultiBodyAlgorithm.java new file mode 100644 index 0000000..edbb9d6 --- /dev/null +++ b/src/eu/engys/dynamic/data/multibody/MultiBodyAlgorithm.java @@ -0,0 +1,59 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.dynamic.data.multibody; + +import java.util.LinkedHashMap; +import java.util.Map; + +import eu.engys.dynamic.data.DynamicAlgorithm; +import eu.engys.dynamic.data.DynamicAlgorithmType; +import eu.engys.dynamic.data.singlebody.SolidBodyAlgorithm; + +public class MultiBodyAlgorithm extends DynamicAlgorithm { + + private Map singleBodyAlgorithms = new LinkedHashMap<>(); + + public MultiBodyAlgorithm() { + } + + @Override + public DynamicAlgorithm copy() { + MultiBodyAlgorithm copy = new MultiBodyAlgorithm(); + for (String k : singleBodyAlgorithms.keySet()) { + copy.getSingleBodyAlgorithms().put(k, singleBodyAlgorithms.get(k).copy()); + } + return copy; + } + + @Override + public DynamicAlgorithmType getType() { + return DynamicAlgorithmType.MULTI_RIGID_BODY; + } + + public Map getSingleBodyAlgorithms() { + return singleBodyAlgorithms; + } + +} diff --git a/src/eu/engys/dynamic/data/off/StaticAlgorithm.java b/src/eu/engys/dynamic/data/off/StaticAlgorithm.java new file mode 100644 index 0000000..6761132 --- /dev/null +++ b/src/eu/engys/dynamic/data/off/StaticAlgorithm.java @@ -0,0 +1,42 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.dynamic.data.off; + +import eu.engys.dynamic.data.DynamicAlgorithm; +import eu.engys.dynamic.data.DynamicAlgorithmType; + +public class StaticAlgorithm extends DynamicAlgorithm { + + @Override + public DynamicAlgorithmType getType() { + return DynamicAlgorithmType.OFF; + } + + @Override + public DynamicAlgorithm copy() { + return new StaticAlgorithm(); + } + +} diff --git a/src/eu/engys/dynamic/data/refine/MeshRefineAlgorithm.java b/src/eu/engys/dynamic/data/refine/MeshRefineAlgorithm.java new file mode 100644 index 0000000..6a73be2 --- /dev/null +++ b/src/eu/engys/dynamic/data/refine/MeshRefineAlgorithm.java @@ -0,0 +1,133 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.dynamic.data.refine; + +import eu.engys.dynamic.data.DynamicAlgorithm; +import eu.engys.dynamic.data.DynamicAlgorithmType; + +public class MeshRefineAlgorithm extends DynamicAlgorithm { + + public static final String REFINE_INTERVAL = "refineInterval"; + public static final String FIELD = "field"; + public static final String LOWER_REFINE_LEVEL = "lowerRefineLevel"; + public static final String UPPER_REFINE_LEVEL = "upperRefineLevel"; + public static final String UNREFINE_LEVEL = "unrefineLevel"; + public static final String N_BUFFER_LAYERS = "nBufferLayers"; + public static final String MAX_REFINEMENT = "maxRefinement"; + public static final String MAX_CELLS = "maxCells"; + + private int refineInterval = 1; + private String field = ""; + private double lowerRefineLevel = 0.001; + private double upperRefineLevel = 0.999; + private int unrefineLevel = 10; + private int nBufferLayers = 1; + private int maxRefinement = 2; + private int maxCells = 200_000; + + @Override + public DynamicAlgorithmType getType() { + return DynamicAlgorithmType.MESH_REFINE; + } + + @Override + public DynamicAlgorithm copy() { + MeshRefineAlgorithm copy = new MeshRefineAlgorithm(); + copy.refineInterval = this.refineInterval; + copy.field = this.field; + copy.lowerRefineLevel = this.lowerRefineLevel; + copy.upperRefineLevel = this.upperRefineLevel; + copy.unrefineLevel = this.unrefineLevel; + copy.nBufferLayers = this.nBufferLayers; + copy.maxRefinement = this.maxRefinement; + copy.maxCells = this.maxCells; + return copy; + } + + public int getRefineInterval() { + return refineInterval; + } + + public void setRefineInterval(int refineInterval) { + firePropertyChange(REFINE_INTERVAL, this.refineInterval, this.refineInterval = refineInterval); + } + + public String getField() { + return field; + } + + public void setField(String field) { + firePropertyChange(FIELD, this.field, this.field = field); + } + + public double getLowerRefineLevel() { + return lowerRefineLevel; + } + + public void setLowerRefineLevel(double lowerRefineLevel) { + firePropertyChange(LOWER_REFINE_LEVEL, this.lowerRefineLevel, this.lowerRefineLevel = lowerRefineLevel); + } + + public double getUpperRefineLevel() { + return upperRefineLevel; + } + + public void setUpperRefineLevel(double upperRefineLevel) { + firePropertyChange(UPPER_REFINE_LEVEL, this.upperRefineLevel, this.upperRefineLevel = upperRefineLevel); + } + + public int getUnrefineLevel() { + return unrefineLevel; + } + + public void setUnrefineLevel(int unrefineLevel) { + firePropertyChange(UNREFINE_LEVEL, this.unrefineLevel, this.unrefineLevel = unrefineLevel); + } + + public int getnBufferLayers() { + return nBufferLayers; + } + + public void setnBufferLayers(int nBufferLayers) { + firePropertyChange(N_BUFFER_LAYERS, this.nBufferLayers, this.nBufferLayers = nBufferLayers); + } + + public int getMaxRefinement() { + return maxRefinement; + } + + public void setMaxRefinement(int maxRefinement) { + firePropertyChange(MAX_REFINEMENT, this.maxRefinement, this.maxRefinement = maxRefinement); + } + + public int getMaxCells() { + return maxCells; + } + + public void setMaxCells(int maxCells) { + firePropertyChange(MAX_CELLS, this.maxCells, this.maxCells = maxCells); + } + +} diff --git a/src/eu/engys/dynamic/data/singlebody/SolidBodyAlgorithm.java b/src/eu/engys/dynamic/data/singlebody/SolidBodyAlgorithm.java new file mode 100644 index 0000000..5e41a5e --- /dev/null +++ b/src/eu/engys/dynamic/data/singlebody/SolidBodyAlgorithm.java @@ -0,0 +1,61 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.dynamic.data.singlebody; + +import eu.engys.dynamic.data.DynamicAlgorithm; +import eu.engys.dynamic.data.DynamicAlgorithmType; +import eu.engys.dynamic.data.singlebody.functions.LinearMotionFunction; + +public class SolidBodyAlgorithm extends DynamicAlgorithm { + + public static final String FUNCTION = "function"; + private SolidBodyMotionFunction function = new LinearMotionFunction(); + + public SolidBodyAlgorithm() { + } + + public SolidBodyAlgorithm(SolidBodyMotionFunction function) { + this.function = function; + } + + @Override + public SolidBodyAlgorithm copy() { + return new SolidBodyAlgorithm(function.copy()); + } + + @Override + public DynamicAlgorithmType getType() { + return DynamicAlgorithmType.SOLID_RIGID_BODY; + } + + public SolidBodyMotionFunction getFunction() { + return function; + } + + public void setFunction(SolidBodyMotionFunction function) { + firePropertyChange(FUNCTION, this.function, this.function = function); + } + +} diff --git a/src/eu/engys/dynamic/data/singlebody/SolidBodyMotionFunction.java b/src/eu/engys/dynamic/data/singlebody/SolidBodyMotionFunction.java new file mode 100644 index 0000000..3a0f5bc --- /dev/null +++ b/src/eu/engys/dynamic/data/singlebody/SolidBodyMotionFunction.java @@ -0,0 +1,35 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.dynamic.data.singlebody; + +import eu.engys.util.bean.AbstractBean; + +public abstract class SolidBodyMotionFunction extends AbstractBean { + + public abstract SolidBodyMotionFunction copy(); + + public abstract SolidBodyMotionFunctionType getFunctionType(); + +} diff --git a/src/eu/engys/dynamic/data/singlebody/SolidBodyMotionFunctionType.java b/src/eu/engys/dynamic/data/singlebody/SolidBodyMotionFunctionType.java new file mode 100644 index 0000000..24139c8 --- /dev/null +++ b/src/eu/engys/dynamic/data/singlebody/SolidBodyMotionFunctionType.java @@ -0,0 +1,123 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.dynamic.data.singlebody; + +import static eu.engys.dynamic.DynamicMeshDict.AXIS_ROTATION_MOTION_KEY; +import static eu.engys.dynamic.DynamicMeshDict.LINEAR_MOTION_KEY; +import static eu.engys.dynamic.DynamicMeshDict.OSCILLATING_LINEAR_MOTION_KEY; +import static eu.engys.dynamic.DynamicMeshDict.OSCILLATING_ROTATING_MOTION_KEY; +import static eu.engys.dynamic.DynamicMeshDict.ROTATING_MOTION_KEY; +import static eu.engys.dynamic.DynamicMeshDict.ROTATING_STEP_MOTION_KEY; +import static eu.engys.dynamic.DynamicMeshDict.SDA_KEY; +import static eu.engys.dynamic.domain.SolidBodyDynamicPanel.AXIS_ROTATION_MOTION_LABEL; +import static eu.engys.dynamic.domain.SolidBodyDynamicPanel.LINEAR_MOTION_LABEL; +import static eu.engys.dynamic.domain.SolidBodyDynamicPanel.OSCILLATING_LINEAR_MOTION_LABEL; +import static eu.engys.dynamic.domain.SolidBodyDynamicPanel.OSCILLATING_ROTATING_MOTION_LABEL; +import static eu.engys.dynamic.domain.SolidBodyDynamicPanel.ROTATING_MOTION_LABEL; +import static eu.engys.dynamic.domain.SolidBodyDynamicPanel.ROTATING_STEP_MOTION_LABEL; +import static eu.engys.dynamic.domain.SolidBodyDynamicPanel.SDA_LABEL; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public enum SolidBodyMotionFunctionType { + + LINEAR_MOTION(LINEAR_MOTION_KEY, LINEAR_MOTION_LABEL), + ROTATING_MOTION(ROTATING_MOTION_KEY, ROTATING_MOTION_LABEL), + ROTATING_STEP_MOTION(ROTATING_STEP_MOTION_KEY, ROTATING_STEP_MOTION_LABEL), + AXIS_ROTATION_MOTION(AXIS_ROTATION_MOTION_KEY, AXIS_ROTATION_MOTION_LABEL), + OSCILLATING_LINEAR_MOTION(OSCILLATING_LINEAR_MOTION_KEY, OSCILLATING_LINEAR_MOTION_LABEL), + OSCILLATING_ROTATING_MOTION(OSCILLATING_ROTATING_MOTION_KEY, OSCILLATING_ROTATING_MOTION_LABEL), + SDA_MOTION(SDA_KEY, SDA_LABEL); + + private static final Logger logger = LoggerFactory.getLogger(SolidBodyMotionFunctionType.class); + + private String label; + private String key; + + SolidBodyMotionFunctionType(String key, String label) { + this.key = key; + this.label = label; + } + + public String getKey() { + return key; + } + + public String getLabel() { + return label; + } + + public boolean isLinearMotion() { + return this == LINEAR_MOTION; + } + + public boolean isRotatingMotion() { + return this == ROTATING_MOTION; + } + + public boolean isRotatingStepMotion() { + return this == ROTATING_STEP_MOTION; + } + + public boolean isAxisRotationMotion() { + return this == AXIS_ROTATION_MOTION; + } + + public boolean isOscillatingLinearMotion() { + return this == OSCILLATING_LINEAR_MOTION; + } + + public boolean isOscillatingRotatingMotion() { + return this == OSCILLATING_ROTATING_MOTION; + } + + public boolean isSDAMotion() { + return this == SDA_MOTION; + } + + public static SolidBodyMotionFunctionType byKey(String key) { + switch (key) { + case LINEAR_MOTION_KEY: + return LINEAR_MOTION; + case ROTATING_MOTION_KEY: + return ROTATING_MOTION; + case ROTATING_STEP_MOTION_KEY: + return ROTATING_STEP_MOTION; + case AXIS_ROTATION_MOTION_KEY: + return AXIS_ROTATION_MOTION; + case OSCILLATING_LINEAR_MOTION_KEY: + return OSCILLATING_LINEAR_MOTION; + case OSCILLATING_ROTATING_MOTION_KEY: + return OSCILLATING_ROTATING_MOTION; + case SDA_KEY: + return SDA_MOTION; + default: + logger.error("Unknown type {}, reset to linear motion", key); + return LINEAR_MOTION; + } + } + +} diff --git a/src/eu/engys/dynamic/data/singlebody/functions/AxisRotationMotionFunction.java b/src/eu/engys/dynamic/data/singlebody/functions/AxisRotationMotionFunction.java new file mode 100644 index 0000000..e95ff65 --- /dev/null +++ b/src/eu/engys/dynamic/data/singlebody/functions/AxisRotationMotionFunction.java @@ -0,0 +1,81 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.dynamic.data.singlebody.functions; + +import eu.engys.dynamic.data.singlebody.SolidBodyMotionFunction; +import eu.engys.dynamic.data.singlebody.SolidBodyMotionFunctionType; + +public class AxisRotationMotionFunction extends SolidBodyMotionFunction { + + public static final String ORIGIN = "origin"; + public static final String AXIS = "axis"; + public static final String OMEGA = "omega"; + + private double[] origin = new double[] { 0, 0, 0 }; + private double[] axis = new double[] { 0, 0, 1 }; + private double omega = 1; + + public AxisRotationMotionFunction() { + } + + @Override + public SolidBodyMotionFunction copy() { + AxisRotationMotionFunction function = new AxisRotationMotionFunction(); + function.origin = new double[] { origin[0], origin[1], origin[2] }; + function.axis = new double[] { axis[0], axis[1], axis[2] }; + function.omega = this.omega; + return function; + } + + @Override + public SolidBodyMotionFunctionType getFunctionType() { + return SolidBodyMotionFunctionType.AXIS_ROTATION_MOTION; + } + + public double[] getOrigin() { + return origin; + } + + public void setOrigin(double[] origin) { + firePropertyChange(ORIGIN, this.origin, this.origin = origin); + } + + public double[] getAxis() { + return axis; + } + + public void setAxis(double[] axis) { + firePropertyChange(AXIS, this.axis, this.axis = axis); + } + + public double getOmega() { + return omega; + } + + public void setOmega(double omega) { + firePropertyChange(OMEGA, this.omega, this.omega = omega); + } + +} diff --git a/src/eu/engys/dynamic/data/singlebody/functions/LinearMotionFunction.java b/src/eu/engys/dynamic/data/singlebody/functions/LinearMotionFunction.java new file mode 100644 index 0000000..f40f9c2 --- /dev/null +++ b/src/eu/engys/dynamic/data/singlebody/functions/LinearMotionFunction.java @@ -0,0 +1,64 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.dynamic.data.singlebody.functions; + +import eu.engys.dynamic.data.singlebody.SolidBodyMotionFunction; +import eu.engys.dynamic.data.singlebody.SolidBodyMotionFunctionType; + +public class LinearMotionFunction extends SolidBodyMotionFunction { + + public static final String VELOCITY = "velocity"; + + private double[] velocity = new double[] { 1, 0, 0 }; + + public LinearMotionFunction() { + } + + @Override + public SolidBodyMotionFunction copy() { + LinearMotionFunction function = new LinearMotionFunction(); + function.velocity = new double[] { velocity[0], velocity[1], velocity[2] }; + return function; + + } + + public LinearMotionFunction(double[] velocity) { + this.velocity = velocity; + } + + @Override + public SolidBodyMotionFunctionType getFunctionType() { + return SolidBodyMotionFunctionType.LINEAR_MOTION; + } + + public double[] getVelocity() { + return velocity; + } + + public void setVelocity(double[] velocity) { + firePropertyChange(VELOCITY, this.velocity, this.velocity = velocity); + } + +} diff --git a/src/eu/engys/dynamic/data/singlebody/functions/OscillatingLinearMotionFunction.java b/src/eu/engys/dynamic/data/singlebody/functions/OscillatingLinearMotionFunction.java new file mode 100644 index 0000000..c4da3d9 --- /dev/null +++ b/src/eu/engys/dynamic/data/singlebody/functions/OscillatingLinearMotionFunction.java @@ -0,0 +1,71 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.dynamic.data.singlebody.functions; + +import eu.engys.dynamic.data.singlebody.SolidBodyMotionFunction; +import eu.engys.dynamic.data.singlebody.SolidBodyMotionFunctionType; + +public class OscillatingLinearMotionFunction extends SolidBodyMotionFunction { + + public static final String AMPLITUDE = "amplitude"; + public static final String OMEGA = "omega"; + + private double[] amplitude = new double[] { 0, 0, 0 }; + private double omega = 100; + + public OscillatingLinearMotionFunction() { + } + + @Override + public SolidBodyMotionFunction copy() { + OscillatingLinearMotionFunction function = new OscillatingLinearMotionFunction(); + function.amplitude = new double[] { amplitude[0], amplitude[1], amplitude[2] }; + function.omega = this.omega; + return function; + + } + + @Override + public SolidBodyMotionFunctionType getFunctionType() { + return SolidBodyMotionFunctionType.OSCILLATING_LINEAR_MOTION; + } + + public double[] getAmplitude() { + return amplitude; + } + + public void setAmplitude(double[] amplitude) { + firePropertyChange(AMPLITUDE, this.amplitude, this.amplitude = amplitude); + } + + public double getOmega() { + return omega; + } + + public void setOmega(double omega) { + firePropertyChange(OMEGA, this.omega, this.omega = omega); + } + +} diff --git a/src/eu/engys/dynamic/data/singlebody/functions/OscillatingRotatingMotionFunction.java b/src/eu/engys/dynamic/data/singlebody/functions/OscillatingRotatingMotionFunction.java new file mode 100644 index 0000000..aea9f0d --- /dev/null +++ b/src/eu/engys/dynamic/data/singlebody/functions/OscillatingRotatingMotionFunction.java @@ -0,0 +1,88 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.dynamic.data.singlebody.functions; + +import eu.engys.dynamic.data.singlebody.SolidBodyMotionFunction; +import eu.engys.dynamic.data.singlebody.SolidBodyMotionFunctionType; + +public class OscillatingRotatingMotionFunction extends SolidBodyMotionFunction { + + public static final String ORIGIN = "origin"; + public static final String AMPLITUDE = "amplitude"; + public static final String OMEGA = "omega"; + + private double[] origin = new double[] { 0, 0, 0 }; + private double[] amplitude = new double[] { 0, 0, 30 }; + private double omega = 100; + + public OscillatingRotatingMotionFunction() { + } + + public OscillatingRotatingMotionFunction(double[] origin, double[]amplitude, double omega) { + this.origin = origin; + this.amplitude = amplitude; + this.omega = omega; + } + + @Override + public SolidBodyMotionFunction copy() { + OscillatingRotatingMotionFunction function = new OscillatingRotatingMotionFunction(); + function.origin = new double[] { origin[0], origin[1], origin[2] }; + function.amplitude = new double[] { amplitude[0], amplitude[1], amplitude[2] }; + function.omega = this.omega; + return function; + + } + + @Override + public SolidBodyMotionFunctionType getFunctionType() { + return SolidBodyMotionFunctionType.OSCILLATING_ROTATING_MOTION; + } + + public double[] getOrigin() { + return origin; + } + + public void setOrigin(double[] origin) { + firePropertyChange(ORIGIN, this.origin, this.origin = origin); + } + + public double[] getAmplitude() { + return amplitude; + } + + public void setAmplitude(double[] amplitude) { + firePropertyChange(AMPLITUDE, this.amplitude, this.amplitude = amplitude); + } + + public double getOmega() { + return omega; + } + + public void setOmega(double omega) { + firePropertyChange(OMEGA, this.omega, this.omega = omega); + } + +} diff --git a/src/eu/engys/dynamic/data/singlebody/functions/RotatingMotionFunction.java b/src/eu/engys/dynamic/data/singlebody/functions/RotatingMotionFunction.java new file mode 100644 index 0000000..bd98c1d --- /dev/null +++ b/src/eu/engys/dynamic/data/singlebody/functions/RotatingMotionFunction.java @@ -0,0 +1,94 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.dynamic.data.singlebody.functions; + +import eu.engys.dynamic.data.singlebody.SolidBodyMotionFunction; +import eu.engys.dynamic.data.singlebody.SolidBodyMotionFunctionType; + +public class RotatingMotionFunction extends SolidBodyMotionFunction { + + public static final String ORIGIN = "origin"; + public static final String AXIS = "axis"; + public static final String OMEGA = "omega"; + public static final String T0 = "t0"; + + private double[] origin = new double[] { 0, 0, 0 }; + private double[] axis = new double[] { 0, 0, 1 }; + private double omega = 1; + private double t0 = 0; + + public RotatingMotionFunction() { + } + + @Override + public SolidBodyMotionFunction copy() { + RotatingMotionFunction function = new RotatingMotionFunction(); + function.origin = new double[] { origin[0], origin[1], origin[2] }; + function.axis = new double[] { axis[0], axis[1], axis[2] }; + function.omega = this.omega; + function.t0 = this.t0; + return function; + + } + + @Override + public SolidBodyMotionFunctionType getFunctionType() { + return SolidBodyMotionFunctionType.ROTATING_MOTION; + } + + public double[] getOrigin() { + return origin; + } + + public void setOrigin(double[] origin) { + firePropertyChange(ORIGIN, this.origin, this.origin = origin); + } + + public double[] getAxis() { + return axis; + } + + public void setAxis(double[] axis) { + firePropertyChange(AXIS, this.axis, this.axis = axis); + } + + public double getOmega() { + return omega; + } + + public void setOmega(double omega) { + firePropertyChange(OMEGA, this.omega, this.omega = omega); + } + + public double getT0() { + return t0; + } + + public void setT0(double t0) { + firePropertyChange(T0, this.t0, this.t0 = t0); + } + + +} diff --git a/src/eu/engys/dynamic/data/singlebody/functions/RotatingStepMotionFunction.java b/src/eu/engys/dynamic/data/singlebody/functions/RotatingStepMotionFunction.java new file mode 100644 index 0000000..bd03d8f --- /dev/null +++ b/src/eu/engys/dynamic/data/singlebody/functions/RotatingStepMotionFunction.java @@ -0,0 +1,93 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.dynamic.data.singlebody.functions; + +import eu.engys.dynamic.data.singlebody.SolidBodyMotionFunction; +import eu.engys.dynamic.data.singlebody.SolidBodyMotionFunctionType; + +public class RotatingStepMotionFunction extends SolidBodyMotionFunction { + + public static final String ORIGIN = "origin"; + public static final String AXIS = "axis"; + public static final String THETA = "theta"; + public static final String PERIOD = "period"; + + private double[] origin = new double[] { 0, 0, 0 }; + private double[] axis = new double[] { 0, 0, 1 }; + private double theta = -60; + private int period = 150; + + public RotatingStepMotionFunction() { + } + + @Override + public SolidBodyMotionFunction copy() { + RotatingStepMotionFunction function = new RotatingStepMotionFunction(); + function.origin = new double[] { origin[0], origin[1], origin[2] }; + function.axis = new double[] { axis[0], axis[1], axis[2] }; + function.theta = this.theta; + function.period = this.period; + return function; + + } + + @Override + public SolidBodyMotionFunctionType getFunctionType() { + return SolidBodyMotionFunctionType.ROTATING_STEP_MOTION; + } + + public double[] getOrigin() { + return origin; + } + + public void setOrigin(double[] origin) { + firePropertyChange(ORIGIN, this.origin, this.origin = origin); + } + + public double[] getAxis() { + return axis; + } + + public void setAxis(double[] axis) { + firePropertyChange(AXIS, this.axis, this.axis = axis); + } + + public double getTheta() { + return theta; + } + + public void setTheta(double theta) { + firePropertyChange(THETA, this.theta, this.theta = theta); + } + + public int getPeriod() { + return period; + } + + public void setPeriod(int period) { + firePropertyChange(PERIOD, this.period, this.period = period); + } + +} diff --git a/src/eu/engys/dynamic/data/singlebody/functions/SDAMotionFunction.java b/src/eu/engys/dynamic/data/singlebody/functions/SDAMotionFunction.java new file mode 100644 index 0000000..47345e0 --- /dev/null +++ b/src/eu/engys/dynamic/data/singlebody/functions/SDAMotionFunction.java @@ -0,0 +1,170 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.dynamic.data.singlebody.functions; + +import eu.engys.dynamic.data.singlebody.SolidBodyMotionFunction; +import eu.engys.dynamic.data.singlebody.SolidBodyMotionFunctionType; + +public class SDAMotionFunction extends SolidBodyMotionFunction { + + public static final String TPN = "tpn"; + public static final String TP = "tp"; + public static final String SWAY_A = "swayA"; + public static final String ROLL_AMIN = "rollAmin"; + public static final String Q = "q"; + public static final String LAMBDA = "lambda"; + public static final String HEAVE_A = "heaveA"; + public static final String DTI = "dti"; + public static final String ROLL_AMAX = "rollAmax"; + public static final String DTP = "dtp"; + public static final String COFG = "cofg"; + + private double tpn = 1; + private double tp = 1; + private double swayA = 1; + private double rollAmin = 1; + private double q = 0; + private double lambda = 1; + private double heaveA = 1; + private double dti = 1; + private double rollAmax = 1; + private double dtp = 1; + private double[] cofg = new double[] { 0, 0, 0 }; + + public SDAMotionFunction() { + } + + @Override + public SolidBodyMotionFunction copy() { + SDAMotionFunction function = new SDAMotionFunction(); + function.tpn = this.tpn; + function.tp = this.tp; + function.swayA = this.swayA; + function.rollAmin = this.rollAmin; + function.q = this.q; + function.lambda = this.lambda; + function.heaveA = this.heaveA; + function.dti = this.dti; + function.rollAmax = this.rollAmax; + function.dtp = this.dtp; + function.cofg = new double[] { cofg[0], cofg[1], cofg[2] }; + return function; + + } + + @Override + public SolidBodyMotionFunctionType getFunctionType() { + return SolidBodyMotionFunctionType.SDA_MOTION; + } + + public double getTpn() { + return tpn; + } + + public void setTpn(double tpn) { + firePropertyChange(TPN, this.tpn, this.tpn = tpn); + } + + public double getTp() { + return tp; + } + + public void setTp(double tp) { + firePropertyChange(TP, this.tp, this.tp = tp); + } + + public double getSwayA() { + return swayA; + } + + public void setSwayA(double swayA) { + firePropertyChange(SWAY_A, this.swayA, this.swayA = swayA); + } + + public double getRollAmin() { + return rollAmin; + } + + public void setRollAmin(double rollAmin) { + firePropertyChange(ROLL_AMIN, this.rollAmin, this.rollAmin = rollAmin); + } + + public double getQ() { + return q; + } + + public void setQ(double q) { + firePropertyChange(Q, this.q, this.q = q); + } + + public double getLambda() { + return lambda; + } + + public void setLambda(double lambda) { + firePropertyChange(LAMBDA, this.lambda, this.lambda = lambda); + } + + public double getHeaveA() { + return heaveA; + } + + public void setHeaveA(double heaveA) { + firePropertyChange(HEAVE_A, this.heaveA, this.heaveA = heaveA); + } + + public double getDti() { + return dti; + } + + public void setDti(double dti) { + firePropertyChange(DTI, this.dti, this.dti = dti); + } + + public double getRollAmax() { + return rollAmax; + } + + public void setRollAmax(double rollAmax) { + firePropertyChange(ROLL_AMAX, this.rollAmax, this.rollAmax = rollAmax); + } + + public double getDtp() { + return dtp; + } + + public void setDtp(double dtp) { + firePropertyChange(DTP, this.dtp, this.dtp = dtp); + } + + public double[] getCofg() { + return cofg; + } + + public void setCofg(double[] cofg) { + firePropertyChange(COFG, this.cofg, this.cofg = cofg); + } + +} diff --git a/src/eu/engys/dynamic/data/sixdof/SixDoFDAlgorithm.java b/src/eu/engys/dynamic/data/sixdof/SixDoFDAlgorithm.java new file mode 100644 index 0000000..c5c6e0d --- /dev/null +++ b/src/eu/engys/dynamic/data/sixdof/SixDoFDAlgorithm.java @@ -0,0 +1,198 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.dynamic.data.sixdof; + +import eu.engys.dynamic.data.DynamicAlgorithm; +import eu.engys.dynamic.data.DynamicAlgorithmType; +import eu.engys.dynamic.data.sixdof.constraint.rotation.NoneRotationConstraint; +import eu.engys.dynamic.data.sixdof.constraint.rotation.RotationConstraint; +import eu.engys.dynamic.data.sixdof.constraint.translation.NoneTranslationConstraint; +import eu.engys.dynamic.data.sixdof.constraint.translation.TranslationConstraint; +import eu.engys.dynamic.data.sixdof.restraint.angular.AngularRestraint; +import eu.engys.dynamic.data.sixdof.restraint.angular.NoneAngularRestraint; +import eu.engys.dynamic.data.sixdof.restraint.linear.LinearRestraint; +import eu.engys.dynamic.data.sixdof.restraint.linear.NoneLinearRestraint; + +public class SixDoFDAlgorithm extends DynamicAlgorithm { + + public static final String MASS = "mass"; + public static final String PATCHES = "patches"; + public static final String ACCELERATION_RELAXATION = "accelerationRelaxation"; + public static final String VELOCITY = "velocity"; + public static final String MOMENT_OF_INERTIA = "momentOfInertia"; + public static final String CENTRE_OF_MASS = "centreOfMass"; + public static final String OUTER_DISTANCE = "outerDistance"; + public static final String INNER_DISTANCE = "innerDistance"; + public static final String TRANSLATION_CONSTRAINT = "translationConstraint"; + public static final String ROTATION_CONSTRAINT = "rotationConstraint"; + public static final String LINEAR_RESTRAINT = "linearRestraint"; + public static final String ANGULAR_RESTRAINT = "angularRestraint"; + + private String[] patches = new String[0]; + private double innerDistance = 0.5; + private double outerDistance = 1.0; + private double mass = 1.0; + private double[] centreOfMass = new double[] { 0.0, 0.0, 0.0 }; + private double[] momentOfInertia = new double[] { 1.0, 1.0, 1.0 }; + private double[] velocity = new double[] { 0.0, 0.0, 0.0 }; + private double accelerationRelaxation = 0.8; + private TranslationConstraint translationConstraint = new NoneTranslationConstraint(); + private RotationConstraint rotationConstraint = new NoneRotationConstraint(); + private LinearRestraint linearRestraint = new NoneLinearRestraint(); + private AngularRestraint angularRestraint = new NoneAngularRestraint(); + + public SixDoFDAlgorithm() { + } + + @Override + public DynamicAlgorithm copy() { + SixDoFDAlgorithm copy = new SixDoFDAlgorithm(); + String copyPatches[] = new String[patches.length]; + for (int i = 0; i < patches.length; i++) { + copyPatches[i] = patches[i]; + } + copy.patches = copyPatches; + copy.innerDistance = this.innerDistance; + copy.outerDistance = this.outerDistance; + copy.mass = this.mass; + copy.centreOfMass[0] = centreOfMass[0]; + copy.centreOfMass[1] = centreOfMass[1]; + copy.centreOfMass[2] = centreOfMass[2]; + copy.momentOfInertia[0] = momentOfInertia[0]; + copy.momentOfInertia[1] = momentOfInertia[1]; + copy.momentOfInertia[2] = momentOfInertia[2]; + copy.velocity[0] = velocity[0]; + copy.velocity[1] = velocity[1]; + copy.velocity[2] = velocity[2]; + copy.accelerationRelaxation = this.accelerationRelaxation; + copy.translationConstraint = this.translationConstraint.copy(); + copy.rotationConstraint = this.rotationConstraint.copy(); + copy.linearRestraint = this.linearRestraint.copy(); + copy.angularRestraint = this.angularRestraint.copy(); + return copy; + } + + @Override + public DynamicAlgorithmType getType() { + return DynamicAlgorithmType.SIX_DOF; + } + + public double getMass() { + return mass; + } + + public void setMass(double mass) { + firePropertyChange(MASS, this.mass, this.mass = mass); + } + + public String[] getPatches() { + return patches; + } + + public void setPatches(String[] patches) { + firePropertyChange(PATCHES, this.patches, this.patches = patches); + } + + public double getAccelerationRelaxation() { + return accelerationRelaxation; + } + + public void setAccelerationRelaxation(double accelerationRelaxation) { + firePropertyChange(ACCELERATION_RELAXATION, this.accelerationRelaxation, this.accelerationRelaxation = accelerationRelaxation); + } + + public double[] getVelocity() { + return velocity; + } + + public void setVelocity(double[] velocity) { + firePropertyChange(VELOCITY, this.velocity, this.velocity = velocity); + } + + public double[] getMomentOfInertia() { + return momentOfInertia; + } + + public void setMomentOfInertia(double[] momentOfInertia) { + firePropertyChange(MOMENT_OF_INERTIA, this.momentOfInertia, this.momentOfInertia = momentOfInertia); + } + + public double[] getCentreOfMass() { + return centreOfMass; + } + + public void setCentreOfMass(double[] centreOfMass) { + firePropertyChange(CENTRE_OF_MASS, this.centreOfMass, this.centreOfMass = centreOfMass); + } + + public double getOuterDistance() { + return outerDistance; + } + + public void setOuterDistance(double outerDistance) { + firePropertyChange(OUTER_DISTANCE, this.outerDistance, this.outerDistance = outerDistance); + } + + public double getInnerDistance() { + return innerDistance; + } + + public void setInnerDistance(double innerDistance) { + firePropertyChange(INNER_DISTANCE, this.innerDistance, this.innerDistance = innerDistance); + } + + public TranslationConstraint getTranslationConstraint() { + return translationConstraint; + } + + public void setTranslationConstraint(TranslationConstraint translationConstraint) { + firePropertyChange(TRANSLATION_CONSTRAINT, this.translationConstraint, this.translationConstraint = translationConstraint); + } + + public RotationConstraint getRotationConstraint() { + return rotationConstraint; + } + + public void setRotationConstraint(RotationConstraint rotationConstraint) { + firePropertyChange(ROTATION_CONSTRAINT, this.rotationConstraint, this.rotationConstraint = rotationConstraint); + } + + public LinearRestraint getLinearRestraint() { + return linearRestraint; + } + + public void setLinearRestraint(LinearRestraint linearRestraint) { + firePropertyChange(LINEAR_RESTRAINT, this.linearRestraint, this.linearRestraint = linearRestraint); + } + + public AngularRestraint getAngularRestraint() { + return angularRestraint; + } + + public void setAngularRestraint(AngularRestraint angularRestraint) { + firePropertyChange(ANGULAR_RESTRAINT, this.angularRestraint, this.angularRestraint = angularRestraint); + } + +} diff --git a/src/eu/engys/dynamic/data/sixdof/constraint/rotation/AxisRotationConstraint.java b/src/eu/engys/dynamic/data/sixdof/constraint/rotation/AxisRotationConstraint.java new file mode 100644 index 0000000..98b71e2 --- /dev/null +++ b/src/eu/engys/dynamic/data/sixdof/constraint/rotation/AxisRotationConstraint.java @@ -0,0 +1,57 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.dynamic.data.sixdof.constraint.rotation; + +public class AxisRotationConstraint extends RotationConstraint { + + public static final String AXIS = "axis"; + private double[] axis = new double[] { 0, 0, 1 }; + + public AxisRotationConstraint() { + } + + public AxisRotationConstraint(double[] axis) { + this.axis = axis; + } + + @Override + public RotationConstraint copy() { + return new AxisRotationConstraint(new double[]{axis[0], axis[1], axis[2]}); + } + + @Override + public RotationConstraintType getType() { + return RotationConstraintType.AXIS; + } + + public double[] getAxis() { + return axis; + } + + public void setAxis(double[] axis) { + firePropertyChange(AXIS, this.axis, this.axis = axis); + } + +} diff --git a/src/eu/engys/dynamic/data/sixdof/constraint/rotation/FixOrientationRotationConstraint.java b/src/eu/engys/dynamic/data/sixdof/constraint/rotation/FixOrientationRotationConstraint.java new file mode 100644 index 0000000..0772091 --- /dev/null +++ b/src/eu/engys/dynamic/data/sixdof/constraint/rotation/FixOrientationRotationConstraint.java @@ -0,0 +1,42 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.dynamic.data.sixdof.constraint.rotation; + +public class FixOrientationRotationConstraint extends RotationConstraint { + + public FixOrientationRotationConstraint() { + } + + @Override + public RotationConstraint copy() { + return new FixOrientationRotationConstraint(); + } + + @Override + public RotationConstraintType getType() { + return RotationConstraintType.FIX_ORIENTATION; + } + +} diff --git a/src/eu/engys/dynamic/data/sixdof/constraint/rotation/NoneRotationConstraint.java b/src/eu/engys/dynamic/data/sixdof/constraint/rotation/NoneRotationConstraint.java new file mode 100644 index 0000000..fb4417e --- /dev/null +++ b/src/eu/engys/dynamic/data/sixdof/constraint/rotation/NoneRotationConstraint.java @@ -0,0 +1,42 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.dynamic.data.sixdof.constraint.rotation; + +public class NoneRotationConstraint extends RotationConstraint { + + public NoneRotationConstraint() { + } + + @Override + public RotationConstraint copy() { + return new NoneRotationConstraint(); + } + + @Override + public RotationConstraintType getType() { + return RotationConstraintType.NONE; + } + +} diff --git a/src/eu/engys/dynamic/data/sixdof/constraint/rotation/RotationConstraint.java b/src/eu/engys/dynamic/data/sixdof/constraint/rotation/RotationConstraint.java new file mode 100644 index 0000000..5e969f7 --- /dev/null +++ b/src/eu/engys/dynamic/data/sixdof/constraint/rotation/RotationConstraint.java @@ -0,0 +1,34 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.dynamic.data.sixdof.constraint.rotation; + +import eu.engys.util.bean.AbstractBean; + +public abstract class RotationConstraint extends AbstractBean{ + + public abstract RotationConstraintType getType(); + + public abstract RotationConstraint copy(); +} diff --git a/src/eu/engys/dynamic/data/sixdof/constraint/rotation/RotationConstraintType.java b/src/eu/engys/dynamic/data/sixdof/constraint/rotation/RotationConstraintType.java new file mode 100644 index 0000000..52731f3 --- /dev/null +++ b/src/eu/engys/dynamic/data/sixdof/constraint/rotation/RotationConstraintType.java @@ -0,0 +1,94 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.dynamic.data.sixdof.constraint.rotation; + +import static eu.engys.dynamic.DynamicMeshDict.AXIS_KEY; +import static eu.engys.dynamic.DynamicMeshDict.ORIENTATION_KEY; +import static eu.engys.dynamic.DynamicMeshDict.SIX_DOF_RIGID_BODY_MOTION_CONSTRAINT_KEY; +import static eu.engys.dynamic.domain.SixDoFDynamicPanel.AXIS_LABEL; +import static eu.engys.dynamic.domain.SixDoFDynamicPanel.FIX_ORIENTATION_LABEL; +import static eu.engys.dynamic.domain.SixDoFDynamicPanel.NONE_LABEL; + +import eu.engys.core.dictionary.Dictionary; + +public enum RotationConstraintType { + + NONE("", NONE_LABEL), + AXIS(AXIS_KEY, AXIS_LABEL), + FIX_ORIENTATION(ORIENTATION_KEY, FIX_ORIENTATION_LABEL); + +// sixDoFRigidBodyMotionConstraint axis; +// axis (0.0 0.0 1.0); + +// sixDoFRigidBodyMotionConstraint orientation; + + private String label; + private String key; + + RotationConstraintType(String key, String label) { + this.key = key; + this.label = label; + } + + public String getKey() { + return key; + } + + public String getLabel() { + return label; + } + + public boolean isNone() { + return this == NONE; + } + + public boolean isAxis() { + return this == AXIS; + } + + public boolean isFixOrientation() { + return this == FIX_ORIENTATION; + } + + public static RotationConstraintType byKey(String key) { + switch (key) { + case AXIS_KEY: + return AXIS; + case ORIENTATION_KEY: + return FIX_ORIENTATION; + default: + return NONE; + } + } + + public static boolean isRotationContraintDict(Dictionary dict){ + if(dict.found(SIX_DOF_RIGID_BODY_MOTION_CONSTRAINT_KEY)){ + RotationConstraintType type = RotationConstraintType.byKey(dict.lookupString(SIX_DOF_RIGID_BODY_MOTION_CONSTRAINT_KEY)); + return !type.isNone(); + } + return false; + } + +} diff --git a/src/eu/engys/dynamic/data/sixdof/constraint/translation/LineTranslationConstraint.java b/src/eu/engys/dynamic/data/sixdof/constraint/translation/LineTranslationConstraint.java new file mode 100644 index 0000000..47e9db7 --- /dev/null +++ b/src/eu/engys/dynamic/data/sixdof/constraint/translation/LineTranslationConstraint.java @@ -0,0 +1,56 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.dynamic.data.sixdof.constraint.translation; + +public class LineTranslationConstraint extends TranslationConstraint { + + public static final String DIRECTION = "direction"; + private double[] direction = new double[] { 0, 0, 1 }; + + public LineTranslationConstraint() { + } + + public LineTranslationConstraint(double[] direction) { + this.direction = direction; + } + + @Override + public TranslationConstraint copy() { + return new LineTranslationConstraint(new double[]{direction[0], direction[1], direction[2]}); + } + + @Override + public TranslationConstraintType getType() { + return TranslationConstraintType.LINE; + } + + public double[] getDirection() { + return direction; + } + + public void setDirection(double[] direction) { + firePropertyChange(DIRECTION, this.direction, this.direction = direction); + } +} diff --git a/src/eu/engys/dynamic/data/sixdof/constraint/translation/NoneTranslationConstraint.java b/src/eu/engys/dynamic/data/sixdof/constraint/translation/NoneTranslationConstraint.java new file mode 100644 index 0000000..259173d --- /dev/null +++ b/src/eu/engys/dynamic/data/sixdof/constraint/translation/NoneTranslationConstraint.java @@ -0,0 +1,42 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.dynamic.data.sixdof.constraint.translation; + +public class NoneTranslationConstraint extends TranslationConstraint { + + public NoneTranslationConstraint() { + } + + @Override + public TranslationConstraint copy() { + return new NoneTranslationConstraint(); + } + + @Override + public TranslationConstraintType getType() { + return TranslationConstraintType.NONE; + } + +} diff --git a/src/eu/engys/dynamic/data/sixdof/constraint/translation/PlaneTranslationConstraint.java b/src/eu/engys/dynamic/data/sixdof/constraint/translation/PlaneTranslationConstraint.java new file mode 100644 index 0000000..8ff57c1 --- /dev/null +++ b/src/eu/engys/dynamic/data/sixdof/constraint/translation/PlaneTranslationConstraint.java @@ -0,0 +1,57 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.dynamic.data.sixdof.constraint.translation; + +public class PlaneTranslationConstraint extends TranslationConstraint { + + public static final String NORMAL = "normal"; + private double[] normal = new double[] { 0, 0, 1 }; + + public PlaneTranslationConstraint() { + } + + public PlaneTranslationConstraint(double[] normal) { + this.normal = normal; + } + + @Override + public TranslationConstraint copy() { + return new PlaneTranslationConstraint(new double[] { normal[0], normal[1], normal[2] }); + } + + @Override + public TranslationConstraintType getType() { + return TranslationConstraintType.PLANE; + } + + public double[] getNormal() { + return normal; + } + + public void setNormal(double[] normal) { + firePropertyChange(NORMAL, this.normal, this.normal = normal); + } + +} diff --git a/src/eu/engys/dynamic/data/sixdof/constraint/translation/PointTranslationConstraint.java b/src/eu/engys/dynamic/data/sixdof/constraint/translation/PointTranslationConstraint.java new file mode 100644 index 0000000..4339791 --- /dev/null +++ b/src/eu/engys/dynamic/data/sixdof/constraint/translation/PointTranslationConstraint.java @@ -0,0 +1,57 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.dynamic.data.sixdof.constraint.translation; + +public class PointTranslationConstraint extends TranslationConstraint { + + public static final String POINT = "point"; + private double[] point = new double[] { 0, 0, 0 }; + + public PointTranslationConstraint() { + } + + public PointTranslationConstraint(double[] point) { + this.point = point; + } + + @Override + public TranslationConstraint copy() { + return new PointTranslationConstraint(new double[] { point[0], point[1], point[2] }); + } + + @Override + public TranslationConstraintType getType() { + return TranslationConstraintType.POINT; + } + + public double[] getPoint() { + return point; + } + + public void setPoint(double[] point) { + firePropertyChange(POINT, this.point, this.point = point); + } + +} diff --git a/src/eu/engys/dynamic/data/sixdof/constraint/translation/TranslationConstraint.java b/src/eu/engys/dynamic/data/sixdof/constraint/translation/TranslationConstraint.java new file mode 100644 index 0000000..1d48775 --- /dev/null +++ b/src/eu/engys/dynamic/data/sixdof/constraint/translation/TranslationConstraint.java @@ -0,0 +1,34 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.dynamic.data.sixdof.constraint.translation; + +import eu.engys.util.bean.AbstractBean; + +public abstract class TranslationConstraint extends AbstractBean{ + + public abstract TranslationConstraintType getType(); + + public abstract TranslationConstraint copy(); +} diff --git a/src/eu/engys/dynamic/data/sixdof/constraint/translation/TranslationConstraintType.java b/src/eu/engys/dynamic/data/sixdof/constraint/translation/TranslationConstraintType.java new file mode 100644 index 0000000..6351ada --- /dev/null +++ b/src/eu/engys/dynamic/data/sixdof/constraint/translation/TranslationConstraintType.java @@ -0,0 +1,107 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.dynamic.data.sixdof.constraint.translation; + +import static eu.engys.dynamic.DynamicMeshDict.LINE_KEY; +import static eu.engys.dynamic.DynamicMeshDict.PLANE_KEY; +import static eu.engys.dynamic.DynamicMeshDict.POINT_KEY; +import static eu.engys.dynamic.DynamicMeshDict.SIX_DOF_RIGID_BODY_MOTION_CONSTRAINT_KEY; +import static eu.engys.dynamic.domain.SixDoFDynamicPanel.LINE_LABEL; +import static eu.engys.dynamic.domain.SixDoFDynamicPanel.NONE_LABEL; +import static eu.engys.dynamic.domain.SixDoFDynamicPanel.PLANE_LABEL; +import static eu.engys.dynamic.domain.SixDoFDynamicPanel.POINT_LABEL; + +import eu.engys.core.dictionary.Dictionary; + +public enum TranslationConstraintType { + + NONE("", NONE_LABEL), + PLANE(PLANE_KEY, PLANE_LABEL), + LINE(LINE_KEY, LINE_LABEL), + POINT(POINT_KEY, POINT_LABEL); + + // sixDoFRigidBodyMotionConstraint plane; + // normal (0.0 0.0 1.0); + + // sixDoFRigidBodyMotionConstraint line; + // direction (0.0 0.0 1.0); + + // sixDoFRigidBodyMotionConstraint point; + // point (0.0 0.0 0.0); + + private String label; + private String key; + + TranslationConstraintType(String key, String label) { + this.key = key; + this.label = label; + } + + public String getKey() { + return key; + } + + public String getLabel() { + return label; + } + + public boolean isNone() { + return this == NONE; + } + + public boolean isPlane() { + return this == PLANE; + } + + public boolean isLine() { + return this == LINE; + } + + public boolean isPoint() { + return this == POINT; + } + + public static TranslationConstraintType byKey(String key) { + switch (key) { + case PLANE_KEY: + return PLANE; + case LINE_KEY: + return LINE; + case POINT_KEY: + return POINT; + default: + return NONE; + } + } + + public static boolean isTranslationContraintDict(Dictionary dict){ + if(dict.found(SIX_DOF_RIGID_BODY_MOTION_CONSTRAINT_KEY)){ + TranslationConstraintType type = TranslationConstraintType.byKey(dict.lookupString(SIX_DOF_RIGID_BODY_MOTION_CONSTRAINT_KEY)); + return !type.isNone(); + } + return false; + } + +} diff --git a/src/eu/engys/dynamic/data/sixdof/restraint/angular/AngularRestraint.java b/src/eu/engys/dynamic/data/sixdof/restraint/angular/AngularRestraint.java new file mode 100644 index 0000000..37e1bde --- /dev/null +++ b/src/eu/engys/dynamic/data/sixdof/restraint/angular/AngularRestraint.java @@ -0,0 +1,34 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.dynamic.data.sixdof.restraint.angular; + +import eu.engys.util.bean.AbstractBean; + +public abstract class AngularRestraint extends AbstractBean { + + public abstract AngularRestraintType getType(); + + public abstract AngularRestraint copy(); +} diff --git a/src/eu/engys/dynamic/data/sixdof/restraint/angular/AngularRestraintType.java b/src/eu/engys/dynamic/data/sixdof/restraint/angular/AngularRestraintType.java new file mode 100644 index 0000000..e699a6b --- /dev/null +++ b/src/eu/engys/dynamic/data/sixdof/restraint/angular/AngularRestraintType.java @@ -0,0 +1,103 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.dynamic.data.sixdof.restraint.angular; + +import static eu.engys.dynamic.DynamicMeshDict.SIX_DOF_RIGID_BODY_MOTION_RESTRAINT_KEY; +import static eu.engys.dynamic.DynamicMeshDict.SPHERICAL_ANGULAR_DAMPER_KEY; +import static eu.engys.dynamic.DynamicMeshDict.SPHERICAL_ANGULAR_SPRING_KEY; + +import eu.engys.core.dictionary.Dictionary; + +public enum AngularRestraintType { + + NONE("", ""), + DAMPER(SPHERICAL_ANGULAR_DAMPER_KEY, ""), + SPRING(SPHERICAL_ANGULAR_SPRING_KEY, ""); + + + +// angularRestraint +// { +// sixDoFRigidBodyMotionRestraint sphericalAngularSpring; +// stiffness 0.0; +// damping 0.0; +// } + +// angularRestraint +// { +// sixDoFRigidBodyMotionRestraint sphericalAngularDamper; +// coeff 0.0; +// } + + + + private String label; + private String key; + + AngularRestraintType(String key, String label) { + this.key = key; + this.label = label; + } + + public String getKey() { + return key; + } + + public String getLabel() { + return label; + } + + public boolean isNone() { + return this == NONE; + } + + public boolean isDamper() { + return this == DAMPER; + } + + public boolean isSpring() { + return this == SPRING; + } + + public static AngularRestraintType byKey(String key) { + switch (key) { + case SPHERICAL_ANGULAR_DAMPER_KEY: + return DAMPER; + case SPHERICAL_ANGULAR_SPRING_KEY: + return SPRING; + default: + return NONE; + } + } + + public static boolean isAngularRestraintDict(Dictionary dict){ + if(dict.found(SIX_DOF_RIGID_BODY_MOTION_RESTRAINT_KEY)){ + AngularRestraintType type = AngularRestraintType.byKey(dict.lookupString(SIX_DOF_RIGID_BODY_MOTION_RESTRAINT_KEY)); + return !type.isNone(); + } + return false; + } + +} diff --git a/src/eu/engys/dynamic/data/sixdof/restraint/angular/DamperAngularRestraint.java b/src/eu/engys/dynamic/data/sixdof/restraint/angular/DamperAngularRestraint.java new file mode 100644 index 0000000..021ceff --- /dev/null +++ b/src/eu/engys/dynamic/data/sixdof/restraint/angular/DamperAngularRestraint.java @@ -0,0 +1,57 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.dynamic.data.sixdof.restraint.angular; + +public class DamperAngularRestraint extends AngularRestraint { + + public static final String COEFF = "coeff"; + private double coeff = 0.0; + + public DamperAngularRestraint() { + } + + public DamperAngularRestraint(double coeff) { + this.coeff = coeff; + } + + @Override + public AngularRestraint copy() { + return new DamperAngularRestraint(coeff); + } + + @Override + public AngularRestraintType getType() { + return AngularRestraintType.DAMPER; + } + + public double getCoeff() { + return coeff; + } + + public void setCoeff(double coeff) { + firePropertyChange(COEFF, this.coeff, this.coeff = coeff); + } + +} diff --git a/src/eu/engys/dynamic/data/sixdof/restraint/angular/NoneAngularRestraint.java b/src/eu/engys/dynamic/data/sixdof/restraint/angular/NoneAngularRestraint.java new file mode 100644 index 0000000..3781b4e --- /dev/null +++ b/src/eu/engys/dynamic/data/sixdof/restraint/angular/NoneAngularRestraint.java @@ -0,0 +1,42 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.dynamic.data.sixdof.restraint.angular; + +public class NoneAngularRestraint extends AngularRestraint { + + public NoneAngularRestraint() { + } + + @Override + public AngularRestraint copy() { + return new NoneAngularRestraint(); + } + + @Override + public AngularRestraintType getType() { + return AngularRestraintType.NONE; + } + +} diff --git a/src/eu/engys/dynamic/data/sixdof/restraint/angular/SpringAngularRestraint.java b/src/eu/engys/dynamic/data/sixdof/restraint/angular/SpringAngularRestraint.java new file mode 100644 index 0000000..c496362 --- /dev/null +++ b/src/eu/engys/dynamic/data/sixdof/restraint/angular/SpringAngularRestraint.java @@ -0,0 +1,69 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.dynamic.data.sixdof.restraint.angular; + +public class SpringAngularRestraint extends AngularRestraint { + + public static final String STIFFNESS = "stiffness"; + public static final String DAMPING = "damping"; + + private double stiffness = 0.0; + private double damping = 0.0; + + public SpringAngularRestraint() { + } + + public SpringAngularRestraint(double stiffness, double damping) { + this.stiffness = stiffness; + this.damping = damping; + } + + @Override + public AngularRestraint copy() { + return new SpringAngularRestraint(stiffness, damping); + } + + @Override + public AngularRestraintType getType() { + return AngularRestraintType.SPRING; + } + + public double getStiffness() { + return stiffness; + } + + public void setStiffness(double stiffness) { + firePropertyChange(STIFFNESS, this.stiffness, this.stiffness = stiffness); + } + + public double getDamping() { + return damping; + } + + public void setDamping(double damping) { + firePropertyChange(DAMPING, this.damping, this.damping = damping); + } + +} diff --git a/src/eu/engys/dynamic/data/sixdof/restraint/linear/DamperLinearRestraint.java b/src/eu/engys/dynamic/data/sixdof/restraint/linear/DamperLinearRestraint.java new file mode 100644 index 0000000..e97dfa1 --- /dev/null +++ b/src/eu/engys/dynamic/data/sixdof/restraint/linear/DamperLinearRestraint.java @@ -0,0 +1,57 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.dynamic.data.sixdof.restraint.linear; + +public class DamperLinearRestraint extends LinearRestraint { + + public static final String COEFF = "coeff"; + private double coeff = 0.0; + + public DamperLinearRestraint() { + } + + public DamperLinearRestraint(double coeff) { + this.coeff = coeff; + } + + @Override + public LinearRestraint copy() { + return new DamperLinearRestraint(coeff); + } + + @Override + public LinearRestraintType getType() { + return LinearRestraintType.DAMPER; + } + + public double getCoeff() { + return coeff; + } + + public void setCoeff(double coeff) { + firePropertyChange(COEFF, this.coeff, this.coeff = coeff); + } + +} diff --git a/src/eu/engys/dynamic/data/sixdof/restraint/linear/LinearRestraint.java b/src/eu/engys/dynamic/data/sixdof/restraint/linear/LinearRestraint.java new file mode 100644 index 0000000..bace225 --- /dev/null +++ b/src/eu/engys/dynamic/data/sixdof/restraint/linear/LinearRestraint.java @@ -0,0 +1,34 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.dynamic.data.sixdof.restraint.linear; + +import eu.engys.util.bean.AbstractBean; + +public abstract class LinearRestraint extends AbstractBean { + + public abstract LinearRestraintType getType(); + + public abstract LinearRestraint copy(); +} diff --git a/src/eu/engys/dynamic/data/sixdof/restraint/linear/LinearRestraintType.java b/src/eu/engys/dynamic/data/sixdof/restraint/linear/LinearRestraintType.java new file mode 100644 index 0000000..a42d10e --- /dev/null +++ b/src/eu/engys/dynamic/data/sixdof/restraint/linear/LinearRestraintType.java @@ -0,0 +1,103 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.dynamic.data.sixdof.restraint.linear; + +import static eu.engys.dynamic.DynamicMeshDict.LINEAR_DAMPER_KEY; +import static eu.engys.dynamic.DynamicMeshDict.LINEAR_SPRING_KEY; +import static eu.engys.dynamic.DynamicMeshDict.SIX_DOF_RIGID_BODY_MOTION_RESTRAINT_KEY; +import static eu.engys.dynamic.domain.SixDoFDynamicPanel.DAMPER_LABEL; +import static eu.engys.dynamic.domain.SixDoFDynamicPanel.NONE_LABEL; +import static eu.engys.dynamic.domain.SixDoFDynamicPanel.SPRING_LABEL; + +import eu.engys.core.dictionary.Dictionary; + +public enum LinearRestraintType { + + NONE("", NONE_LABEL), DAMPER(LINEAR_DAMPER_KEY, DAMPER_LABEL), SPRING(LINEAR_SPRING_KEY, SPRING_LABEL); + + // linearRestraint + // { + // sixDoFRigidBodyMotionRestraint linearDamper; + // coeff 0.0; + // } + + // linearRestraint + // { + // sixDoFRigidBodyMotionRestraint linearSpring; + // stiffness 0.0; + // damping 0.0; + // refAttachmentPt (0.0 0.0 0.0); + // restLength 0.0; + // anchor (0.0 0.0 0.0); + // } + + private String label; + private String key; + + LinearRestraintType(String key, String label) { + this.key = key; + this.label = label; + } + + public String getKey() { + return key; + } + + public String getLabel() { + return label; + } + + public boolean isNone() { + return this == NONE; + } + + public boolean isDamper() { + return this == DAMPER; + } + + public boolean isSpring() { + return this == SPRING; + } + + public static LinearRestraintType byKey(String key) { + switch (key) { + case LINEAR_DAMPER_KEY: + return DAMPER; + case LINEAR_SPRING_KEY: + return SPRING; + default: + return NONE; + } + } + + public static boolean isLinearRestraintDict(Dictionary dict) { + if (dict.found(SIX_DOF_RIGID_BODY_MOTION_RESTRAINT_KEY)) { + LinearRestraintType type = LinearRestraintType.byKey(dict.lookupString(SIX_DOF_RIGID_BODY_MOTION_RESTRAINT_KEY)); + return !type.isNone(); + } + return false; + } + +} diff --git a/src/eu/engys/dynamic/data/sixdof/restraint/linear/NoneLinearRestraint.java b/src/eu/engys/dynamic/data/sixdof/restraint/linear/NoneLinearRestraint.java new file mode 100644 index 0000000..decf657 --- /dev/null +++ b/src/eu/engys/dynamic/data/sixdof/restraint/linear/NoneLinearRestraint.java @@ -0,0 +1,42 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.dynamic.data.sixdof.restraint.linear; + +public class NoneLinearRestraint extends LinearRestraint { + + public NoneLinearRestraint() { + } + + @Override + public LinearRestraint copy() { + return new NoneLinearRestraint(); + } + + @Override + public LinearRestraintType getType() { + return LinearRestraintType.NONE; + } + +} diff --git a/src/eu/engys/dynamic/data/sixdof/restraint/linear/SpringLinearRestraint.java b/src/eu/engys/dynamic/data/sixdof/restraint/linear/SpringLinearRestraint.java new file mode 100644 index 0000000..c648e99 --- /dev/null +++ b/src/eu/engys/dynamic/data/sixdof/restraint/linear/SpringLinearRestraint.java @@ -0,0 +1,104 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.dynamic.data.sixdof.restraint.linear; + +public class SpringLinearRestraint extends LinearRestraint { + + public static final String STIFFNESS = "stiffness"; + public static final String DAMPING = "damping"; + public static final String REF_ATTACHMENT_PT = "refAttachmentPt"; + public static final String REST_LENGTH = "restLength"; + public static final String ANCHOR = "anchor"; + + private double[] anchor = new double[] { 0, 0, 0 }; + private double[] refAttachmentPt = new double[] { 0, 0, 0 }; + private double stiffness = 0.0; + private double damping = 0.0; + private double restLength = 0.0; + + public SpringLinearRestraint() { + } + + @Override + public LinearRestraint copy() { + SpringLinearRestraint copy = new SpringLinearRestraint(); + copy.stiffness = this.stiffness; + copy.damping = this.damping; + copy.refAttachmentPt[0] = this.refAttachmentPt[0]; + copy.refAttachmentPt[1] = this.refAttachmentPt[1]; + copy.refAttachmentPt[2] = this.refAttachmentPt[2]; + copy.restLength = this.restLength; + copy.anchor[0] = this.anchor[0]; + copy.anchor[1] = this.anchor[1]; + copy.anchor[2] = this.anchor[2]; + return copy; + } + + @Override + public LinearRestraintType getType() { + return LinearRestraintType.SPRING; + } + + public double getStiffness() { + return stiffness; + } + + public void setStiffness(double stiffness) { + firePropertyChange(STIFFNESS, this.stiffness, this.stiffness = stiffness); + } + + public double getDamping() { + return damping; + } + + public void setDamping(double damping) { + firePropertyChange(DAMPING, this.damping, this.damping = damping); + } + + public double[] getRefAttachmentPt() { + return refAttachmentPt; + } + + public void setRefAttachmentPt(double[] refAttachmentPt) { + firePropertyChange(REF_ATTACHMENT_PT, this.refAttachmentPt, this.refAttachmentPt = refAttachmentPt); + } + + public double getRestLength() { + return restLength; + } + + public void setRestLength(double restLength) { + firePropertyChange(REST_LENGTH, this.restLength, this.restLength = restLength); + } + + public double[] getAnchor() { + return anchor; + } + + public void setAnchor(double[] anchor) { + firePropertyChange(ANCHOR, this.anchor, this.anchor = anchor); + } + +} diff --git a/src/eu/engys/dynamic/domain/AbstractDynamicPanel.java b/src/eu/engys/dynamic/domain/AbstractDynamicPanel.java new file mode 100644 index 0000000..03ef1e8 --- /dev/null +++ b/src/eu/engys/dynamic/domain/AbstractDynamicPanel.java @@ -0,0 +1,41 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.dynamic.domain; + +import eu.engys.core.project.Model; +import eu.engys.gui.DefaultGUIPanel; + +public abstract class AbstractDynamicPanel extends DefaultGUIPanel { + + public AbstractDynamicPanel(Model model, String dynamicType) { + super(dynamicType, model); + } + + @Override + public int getIndex() { + return model.getState().getMultiphaseModel().isOn() ? 4 : 3; + } + +} diff --git a/src/eu/engys/dynamic/domain/MeshRefineDynamicPanel.java b/src/eu/engys/dynamic/domain/MeshRefineDynamicPanel.java new file mode 100644 index 0000000..5bc477e --- /dev/null +++ b/src/eu/engys/dynamic/domain/MeshRefineDynamicPanel.java @@ -0,0 +1,108 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.dynamic.domain; + +import static eu.engys.dynamic.data.DynamicAlgorithmType.MESH_REFINE; +import static eu.engys.dynamic.data.refine.MeshRefineAlgorithm.FIELD; +import static eu.engys.dynamic.data.refine.MeshRefineAlgorithm.LOWER_REFINE_LEVEL; +import static eu.engys.dynamic.data.refine.MeshRefineAlgorithm.MAX_CELLS; +import static eu.engys.dynamic.data.refine.MeshRefineAlgorithm.MAX_REFINEMENT; +import static eu.engys.dynamic.data.refine.MeshRefineAlgorithm.N_BUFFER_LAYERS; +import static eu.engys.dynamic.data.refine.MeshRefineAlgorithm.REFINE_INTERVAL; +import static eu.engys.dynamic.data.refine.MeshRefineAlgorithm.UNREFINE_LEVEL; +import static eu.engys.dynamic.data.refine.MeshRefineAlgorithm.UPPER_REFINE_LEVEL; + +import javax.swing.JComboBox; +import javax.swing.JComponent; + +import eu.engys.core.project.Model; +import eu.engys.dynamic.DynamicModule; +import eu.engys.dynamic.data.refine.MeshRefineAlgorithm; +import eu.engys.gui.ListBuilderFactory; +import eu.engys.gui.ReloadableListModel; +import eu.engys.util.bean.BeanModel; +import eu.engys.util.ui.builder.PanelBuilder; + +public class MeshRefineDynamicPanel extends AbstractDynamicPanel { + + public static final String REFINE_INTERVAL_LABEL = "Refine Interval"; + public static final String FIELD_LABEL = "Field"; + public static final String LOWER_REFINE_LEVEL_LABEL = "Lower Refine Level"; + public static final String UPPER_REFINE_LEVEL_LABEL = "Upper Refine Level"; + public static final String UNREFINE_LEVEL_LABEL = "Unrefine Level"; + public static final String N_BUFFER_LAYERS_LABEL = "Buffer Layers"; + public static final String MAX_REFINEMENT_LABEL = "Max Refinement"; + public static final String MAX_CELLS_LABEL = "Max Cells"; + + private BeanModel beanModel; + + private JComboBox fieldCombo; + private ReloadableListModel fieldModel; + private DynamicModule module; + + public MeshRefineDynamicPanel(Model model, DynamicModule module) { + super(model, MESH_REFINE.getLabel()); + this.module = module; + this.beanModel = new BeanModel(new MeshRefineAlgorithm()); + } + + @Override + protected JComponent layoutComponents() { + PanelBuilder builder = new PanelBuilder(); + builder.addComponent(FIELD_LABEL, fieldCombo = beanModel.bindSelection(FIELD, fieldModel = ListBuilderFactory.getScalarFieldsListModel(model))); + builder.addComponent(REFINE_INTERVAL_LABEL, beanModel.bindInteger(REFINE_INTERVAL)); + builder.addComponent(LOWER_REFINE_LEVEL_LABEL, beanModel.bindDouble(LOWER_REFINE_LEVEL)); + builder.addComponent(UPPER_REFINE_LEVEL_LABEL, beanModel.bindDouble(UPPER_REFINE_LEVEL)); + builder.addComponent(UNREFINE_LEVEL_LABEL, beanModel.bindInteger(UNREFINE_LEVEL)); + builder.addComponent(N_BUFFER_LAYERS_LABEL, beanModel.bindInteger(N_BUFFER_LAYERS)); + builder.addComponent(MAX_REFINEMENT_LABEL, beanModel.bindInteger(MAX_REFINEMENT)); + builder.addComponent(MAX_CELLS_LABEL, beanModel.bindInteger(MAX_CELLS)); + + return builder.removeMargins().getPanel(); + } + + @Override + public void stateChanged() { + Object selection = fieldCombo.getModel().getSelectedItem(); + fieldModel.reload(); + fieldCombo.getModel().setSelectedItem(selection); + } + + @Override + public void load() { + fieldModel.reload(); + if (module.getDynamicData().getAlgorithm().getType().isMeshRefine()) { + beanModel.setBean((MeshRefineAlgorithm) module.getDynamicData().getAlgorithm().copy()); + } + } + + @Override + public void save() { + if (module.getDynamicData().getAlgorithm().getType().isMeshRefine()) { + module.getDynamicData().setAlgorithm(beanModel.getBean().copy()); + } + } + +} diff --git a/src/eu/engys/dynamic/domain/SixDoFDynamicPanel.java b/src/eu/engys/dynamic/domain/SixDoFDynamicPanel.java new file mode 100644 index 0000000..bceedc4 --- /dev/null +++ b/src/eu/engys/dynamic/domain/SixDoFDynamicPanel.java @@ -0,0 +1,301 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.dynamic.domain; + +import static eu.engys.dynamic.data.DynamicAlgorithmType.SIX_DOF; +import static eu.engys.dynamic.data.sixdof.SixDoFDAlgorithm.ACCELERATION_RELAXATION; +import static eu.engys.dynamic.data.sixdof.SixDoFDAlgorithm.ANGULAR_RESTRAINT; +import static eu.engys.dynamic.data.sixdof.SixDoFDAlgorithm.CENTRE_OF_MASS; +import static eu.engys.dynamic.data.sixdof.SixDoFDAlgorithm.INNER_DISTANCE; +import static eu.engys.dynamic.data.sixdof.SixDoFDAlgorithm.LINEAR_RESTRAINT; +import static eu.engys.dynamic.data.sixdof.SixDoFDAlgorithm.MASS; +import static eu.engys.dynamic.data.sixdof.SixDoFDAlgorithm.MOMENT_OF_INERTIA; +import static eu.engys.dynamic.data.sixdof.SixDoFDAlgorithm.OUTER_DISTANCE; +import static eu.engys.dynamic.data.sixdof.SixDoFDAlgorithm.PATCHES; +import static eu.engys.dynamic.data.sixdof.SixDoFDAlgorithm.ROTATION_CONSTRAINT; +import static eu.engys.dynamic.data.sixdof.SixDoFDAlgorithm.TRANSLATION_CONSTRAINT; +import static eu.engys.dynamic.data.sixdof.SixDoFDAlgorithm.VELOCITY; +import static eu.engys.dynamic.data.sixdof.constraint.translation.LineTranslationConstraint.DIRECTION; +import static eu.engys.dynamic.data.sixdof.constraint.translation.PlaneTranslationConstraint.NORMAL; +import static eu.engys.dynamic.data.sixdof.constraint.translation.PointTranslationConstraint.POINT; +import static eu.engys.dynamic.data.sixdof.restraint.linear.SpringLinearRestraint.ANCHOR; +import static eu.engys.dynamic.data.sixdof.restraint.linear.SpringLinearRestraint.REF_ATTACHMENT_PT; +import static eu.engys.dynamic.data.sixdof.restraint.linear.SpringLinearRestraint.REST_LENGTH; + +import java.util.LinkedList; +import java.util.List; + +import javax.swing.JComponent; + +import eu.engys.core.project.Model; +import eu.engys.dynamic.DynamicModule; +import eu.engys.dynamic.data.sixdof.SixDoFDAlgorithm; +import eu.engys.dynamic.data.sixdof.constraint.rotation.AxisRotationConstraint; +import eu.engys.dynamic.data.sixdof.constraint.rotation.FixOrientationRotationConstraint; +import eu.engys.dynamic.data.sixdof.constraint.rotation.NoneRotationConstraint; +import eu.engys.dynamic.data.sixdof.constraint.translation.LineTranslationConstraint; +import eu.engys.dynamic.data.sixdof.constraint.translation.NoneTranslationConstraint; +import eu.engys.dynamic.data.sixdof.constraint.translation.PlaneTranslationConstraint; +import eu.engys.dynamic.data.sixdof.constraint.translation.PointTranslationConstraint; +import eu.engys.dynamic.data.sixdof.restraint.angular.DamperAngularRestraint; +import eu.engys.dynamic.data.sixdof.restraint.angular.NoneAngularRestraint; +import eu.engys.dynamic.data.sixdof.restraint.angular.SpringAngularRestraint; +import eu.engys.dynamic.data.sixdof.restraint.linear.DamperLinearRestraint; +import eu.engys.dynamic.data.sixdof.restraint.linear.NoneLinearRestraint; +import eu.engys.dynamic.data.sixdof.restraint.linear.SpringLinearRestraint; +import eu.engys.gui.ListBuilderFactory; +import eu.engys.util.Symbols; +import eu.engys.util.bean.BeanModel; +import eu.engys.util.bean.BeanPanelBuilder; +import eu.engys.util.ui.builder.PanelBuilder; + +public class SixDoFDynamicPanel extends AbstractDynamicPanel { + + public static final String PATCHES_LABEL = "Moving Boundaries"; + public static final String INNER_DISTANCE_LABEL = "Inner Distance " + Symbols.M; + public static final String OUTER_DISTANCE_LABEL = "Outer Distance " + Symbols.M; + public static final String MASS_LABEL = "Mass " + Symbols.KG; + public static final String CENTRE_OF_MASS_LABEL = "Centre of Mass " + Symbols.M; + public static final String MOMENT_OF_INERTIA_LABEL = "Moment of Inertia " + Symbols.KGM2; + public static final String VELOCITY_LABEL = "Velocity " + Symbols.M_S; + public static final String ACCELERATION_RELAXATION_LABEL = "Acceleration Relaxation"; + + public static final String TRANSLATION_CONSTRAINT_LABEL = "Translation Constraint"; + public static final String POINT_LABEL = "Point"; + public static final String LINE_LABEL = "Line"; + public static final String PLANE_LABEL = "Plane"; + public static final String NORMAL_LABEL = "Normal"; + public static final String DIRECTION_LABEL = "Direction"; + + public static final String ROTATION_CONSTRAINT_LABEL = "Rotation Constraint"; + public static final String AXIS_LABEL = "Axis"; + public static final String FIX_ORIENTATION_LABEL = "Fix Orientation"; + + public static final String LINEAR_RESTRAINT_LABEL = "Linear Restraint"; + public static final String COEFF_LINEAR_LABEL = "Damping " + Symbols.NS_M; + public static final String STIFFNESS_LINEAR_LABEL = "Stiffness " + Symbols.N_M; + public static final String DAMPING_LINEAR_LABEL = "Damping " + Symbols.NS_M; + public static final String REF_ATTACHMENT_PT_LABEL = "Point of Attachment " + Symbols.M; + public static final String REST_LENGTH_LABEL = "Rest Length " + Symbols.M; + public static final String ANCHOR_LABEL = "Anchor " + Symbols.M; + + public static final String ANGULAR_RESTRAINT_LABEL = "Angular Restraint"; + public static final String COEFF_ANGULAR_LABEL = "Damping " + Symbols.NMS_RAD; + public static final String STIFFNESS_ANGULAR_LABEL = "Stiffness " + Symbols.NM_RAD; + public static final String DAMPING_ANGULAR_LABEL = "Damping " + Symbols.NMS_RAD; + + public static final String DAMPER_LABEL = "Damper"; + public static final String SPRING_LABEL = "Spring"; + public static final String NONE_LABEL = "None"; + + private BeanModel beanModel; + private BeanModel noneTranslationConstraintBeanModel; + private BeanModel pointTranslationConstraintBeanModel; + private BeanModel lineTranslationConstraintBeanModel; + private BeanModel planeTranslationConstraintBeanModel; + + private BeanModel noneRotationConstraintBeanModel; + private BeanModel axisRotationConstraintBeanModel; + private BeanModel fixOrientationRotationConstraintBeanModel; + + private BeanModel noneLinearRestraintBeanModel; + private BeanModel damperLinearRestraintBeanModel; + private BeanModel springLinearRestraintBeanModel; + + private BeanModel noneAngularRestraintBeanModel; + private BeanModel damperAngularRestraintBeanModel; + private BeanModel springAngularRestraintBeanModel; + + private DynamicModule module; + + public SixDoFDynamicPanel(Model model, DynamicModule module) { + super(model, SIX_DOF.getLabel()); + this.module = module; + this.beanModel = new BeanModel(new SixDoFDAlgorithm()); + + this.noneTranslationConstraintBeanModel = new BeanModel(new NoneTranslationConstraint()); + this.pointTranslationConstraintBeanModel = new BeanModel(new PointTranslationConstraint()); + this.lineTranslationConstraintBeanModel = new BeanModel(new LineTranslationConstraint()); + this.planeTranslationConstraintBeanModel = new BeanModel(new PlaneTranslationConstraint()); + + this.noneRotationConstraintBeanModel = new BeanModel(new NoneRotationConstraint()); + this.axisRotationConstraintBeanModel = new BeanModel(new AxisRotationConstraint()); + this.fixOrientationRotationConstraintBeanModel = new BeanModel(new FixOrientationRotationConstraint()); + + this.noneLinearRestraintBeanModel = new BeanModel(new NoneLinearRestraint()); + this.damperLinearRestraintBeanModel = new BeanModel(new DamperLinearRestraint()); + this.springLinearRestraintBeanModel = new BeanModel(new SpringLinearRestraint()); + + this.noneAngularRestraintBeanModel = new BeanModel(new NoneAngularRestraint()); + this.damperAngularRestraintBeanModel = new BeanModel(new DamperAngularRestraint()); + this.springAngularRestraintBeanModel = new BeanModel(new SpringAngularRestraint()); + } + + @Override + protected JComponent layoutComponents() { + PanelBuilder builder = new PanelBuilder(); + builder.addComponent(PATCHES_LABEL, beanModel.bindList(PATCHES, ListBuilderFactory.getPatchesListBuilder(model))); + builder.addComponent(INNER_DISTANCE_LABEL, beanModel.bindDouble(INNER_DISTANCE)); + builder.addComponent(OUTER_DISTANCE_LABEL, beanModel.bindDouble(OUTER_DISTANCE)); + builder.addComponent(MASS_LABEL, beanModel.bindDouble(MASS)); + builder.addComponent(CENTRE_OF_MASS_LABEL, beanModel.bindPoint(CENTRE_OF_MASS)); + builder.addComponent(MOMENT_OF_INERTIA_LABEL, beanModel.bindPoint(MOMENT_OF_INERTIA)); + builder.addComponent(VELOCITY_LABEL, beanModel.bindPoint(VELOCITY)); + builder.addComponent(ACCELERATION_RELAXATION_LABEL, beanModel.bindDouble(ACCELERATION_RELAXATION)); + + buildTranslationConstraintPanel(builder); + buildRotationConstraintPanel(builder); + buildLinearRestraintPanel(builder); + buildAngularRestraintPanel(builder); + + return builder.removeMargins().getPanel(); + } + + @SuppressWarnings("unchecked") + private void buildTranslationConstraintPanel(PanelBuilder builder) { + BeanPanelBuilder translationBuilder = new BeanPanelBuilder(); + + translationBuilder.startChoiceNoLabel(TRANSLATION_CONSTRAINT_LABEL, beanModel.bindComboController(TRANSLATION_CONSTRAINT, noneTranslationConstraintBeanModel, pointTranslationConstraintBeanModel, lineTranslationConstraintBeanModel, planeTranslationConstraintBeanModel)); + + translationBuilder.startBean(NONE_LABEL, noneTranslationConstraintBeanModel); + translationBuilder.endBean(); + + translationBuilder.startBean(POINT_LABEL, pointTranslationConstraintBeanModel); + translationBuilder.addComponent(POINT_LABEL, POINT_LABEL, pointTranslationConstraintBeanModel.bindPoint(POINT)); + translationBuilder.endBean(); + + translationBuilder.startBean(LINE_LABEL, lineTranslationConstraintBeanModel); + translationBuilder.addComponent(DIRECTION_LABEL, DIRECTION_LABEL, lineTranslationConstraintBeanModel.bindPoint(DIRECTION)); + translationBuilder.endBean(); + + translationBuilder.startBean(PLANE_LABEL, planeTranslationConstraintBeanModel); + translationBuilder.addComponent(NORMAL_LABEL, NORMAL_LABEL, planeTranslationConstraintBeanModel.bindPoint(NORMAL)); + translationBuilder.endBean(); + + translationBuilder.endChoice(); + + builder.addFill(translationBuilder.withTitle(TRANSLATION_CONSTRAINT_LABEL).getPanel()); + } + + @SuppressWarnings("unchecked") + private void buildRotationConstraintPanel(PanelBuilder builder) { + BeanPanelBuilder rotationBuilder = new BeanPanelBuilder(); + + rotationBuilder.startChoiceNoLabel(ROTATION_CONSTRAINT_LABEL, beanModel.bindComboController(ROTATION_CONSTRAINT, noneRotationConstraintBeanModel, axisRotationConstraintBeanModel, fixOrientationRotationConstraintBeanModel)); + + rotationBuilder.startBean(NONE_LABEL, noneRotationConstraintBeanModel); + rotationBuilder.endBean(); + + rotationBuilder.startBean(AXIS_LABEL, axisRotationConstraintBeanModel); + rotationBuilder.addComponent(AXIS_LABEL, AXIS_LABEL, axisRotationConstraintBeanModel.bindPoint(AxisRotationConstraint.AXIS)); + rotationBuilder.endBean(); + + rotationBuilder.startBean(FIX_ORIENTATION_LABEL, fixOrientationRotationConstraintBeanModel); + rotationBuilder.endBean(); + + rotationBuilder.endChoice(); + + builder.addFill(rotationBuilder.withTitle(ROTATION_CONSTRAINT_LABEL).getPanel()); + } + + @SuppressWarnings("unchecked") + private void buildLinearRestraintPanel(PanelBuilder builder) { + BeanPanelBuilder linearBuilder = new BeanPanelBuilder(); + + linearBuilder.startChoiceNoLabel(LINEAR_RESTRAINT_LABEL, beanModel.bindComboController(LINEAR_RESTRAINT, noneLinearRestraintBeanModel, damperLinearRestraintBeanModel, springLinearRestraintBeanModel)); + + linearBuilder.startBean(NONE_LABEL, noneLinearRestraintBeanModel); + linearBuilder.endBean(); + + linearBuilder.startBean(DAMPER_LABEL, damperLinearRestraintBeanModel); + linearBuilder.addComponent(COEFF_LINEAR_LABEL, COEFF_LINEAR_LABEL, damperLinearRestraintBeanModel.bindDouble(DamperLinearRestraint.COEFF)); + linearBuilder.endBean(); + + linearBuilder.startBean(SPRING_LABEL, springLinearRestraintBeanModel); + linearBuilder.addComponent(ANCHOR_LABEL, ANCHOR_LABEL, springLinearRestraintBeanModel.bindPoint(ANCHOR)); + linearBuilder.addComponent(REF_ATTACHMENT_PT_LABEL, REF_ATTACHMENT_PT_LABEL, springLinearRestraintBeanModel.bindPoint(REF_ATTACHMENT_PT)); + linearBuilder.addComponent(STIFFNESS_LINEAR_LABEL, STIFFNESS_LINEAR_LABEL, springLinearRestraintBeanModel.bindDouble(SpringLinearRestraint.STIFFNESS)); + linearBuilder.addComponent(DAMPING_LINEAR_LABEL, DAMPING_LINEAR_LABEL, springLinearRestraintBeanModel.bindDouble(SpringLinearRestraint.DAMPING)); + linearBuilder.addComponent(REST_LENGTH_LABEL, REST_LENGTH_LABEL, springLinearRestraintBeanModel.bindDouble(REST_LENGTH)); + linearBuilder.endBean(); + + linearBuilder.endChoice(); + + builder.addFill(linearBuilder.withTitle(LINEAR_RESTRAINT_LABEL).getPanel()); + } + + @SuppressWarnings("unchecked") + private void buildAngularRestraintPanel(PanelBuilder builder) { + BeanPanelBuilder angularBuilder = new BeanPanelBuilder(); + + angularBuilder.startChoiceNoLabel(ANGULAR_RESTRAINT_LABEL, beanModel.bindComboController(ANGULAR_RESTRAINT, noneAngularRestraintBeanModel, damperAngularRestraintBeanModel, springAngularRestraintBeanModel)); + + angularBuilder.startBean(NONE_LABEL, noneAngularRestraintBeanModel); + angularBuilder.endBean(); + + angularBuilder.startBean(DAMPER_LABEL, damperAngularRestraintBeanModel); + angularBuilder.addComponent(COEFF_ANGULAR_LABEL, COEFF_ANGULAR_LABEL, damperAngularRestraintBeanModel.bindDouble(DamperAngularRestraint.COEFF)); + angularBuilder.endBean(); + + angularBuilder.startBean(SPRING_LABEL, springAngularRestraintBeanModel); + angularBuilder.addComponent(STIFFNESS_ANGULAR_LABEL, STIFFNESS_ANGULAR_LABEL, springAngularRestraintBeanModel.bindDouble(SpringAngularRestraint.STIFFNESS)); + angularBuilder.addComponent(DAMPING_ANGULAR_LABEL, DAMPING_ANGULAR_LABEL, springAngularRestraintBeanModel.bindDouble(SpringAngularRestraint.DAMPING)); + angularBuilder.endBean(); + + angularBuilder.endChoice(); + + builder.addFill(angularBuilder.withTitle(ANGULAR_RESTRAINT_LABEL).getPanel()); + + } + + @Override + public void load() { + if (module.getDynamicData().getAlgorithm().getType().is6DOF()) { + SixDoFDAlgorithm algo = (SixDoFDAlgorithm) module.getDynamicData().getAlgorithm().copy(); + fixPatches(algo); + beanModel.setBean(algo); + } + } + + private void fixPatches(SixDoFDAlgorithm algo) { + List fixedPatches = new LinkedList(); + for (String p : algo.getPatches()) { + if (model.getPatches().getPatchByName(p) != null) { + fixedPatches.add(p); + } + } + if (fixedPatches.size() != algo.getPatches().length) { + algo.setPatches(fixedPatches.toArray(new String[0])); + } + } + + @Override + public void save() { + if (module.getDynamicData().getAlgorithm().getType().is6DOF()) { + module.getDynamicData().setAlgorithm(beanModel.getBean().copy()); + } + } + +} diff --git a/src/eu/engys/dynamic/domain/SolidBodyDynamicPanel.java b/src/eu/engys/dynamic/domain/SolidBodyDynamicPanel.java new file mode 100644 index 0000000..90a3dbe --- /dev/null +++ b/src/eu/engys/dynamic/domain/SolidBodyDynamicPanel.java @@ -0,0 +1,203 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.dynamic.domain; + +import static eu.engys.dynamic.data.DynamicAlgorithmType.SOLID_RIGID_BODY; +import static eu.engys.dynamic.data.singlebody.SolidBodyAlgorithm.FUNCTION; + +import javax.swing.JComponent; + +import eu.engys.core.project.Model; +import eu.engys.dynamic.DynamicModule; +import eu.engys.dynamic.data.singlebody.SolidBodyAlgorithm; +import eu.engys.dynamic.data.singlebody.functions.AxisRotationMotionFunction; +import eu.engys.dynamic.data.singlebody.functions.LinearMotionFunction; +import eu.engys.dynamic.data.singlebody.functions.OscillatingLinearMotionFunction; +import eu.engys.dynamic.data.singlebody.functions.OscillatingRotatingMotionFunction; +import eu.engys.dynamic.data.singlebody.functions.RotatingMotionFunction; +import eu.engys.dynamic.data.singlebody.functions.RotatingStepMotionFunction; +import eu.engys.dynamic.data.singlebody.functions.SDAMotionFunction; +import eu.engys.util.Symbols; +import eu.engys.util.bean.BeanModel; +import eu.engys.util.bean.BeanPanelBuilder; +import eu.engys.util.ui.JComboBoxWithItemsSupport; + +public class SolidBodyDynamicPanel extends AbstractDynamicPanel { + + public static final String TYPE_LABEL = "Type"; + public static final String TYPE_TOOLTIP = "Rigid Body Motion Type"; + + public static final String LINEAR_MOTION_LABEL = "Linear Motion"; + public static final String ROTATING_MOTION_LABEL = "Rotating Motion"; + public static final String ROTATING_STEP_MOTION_LABEL = "Rotating Step Motion"; + public static final String AXIS_ROTATION_MOTION_LABEL = "Axis Rotation Motion"; + public static final String OSCILLATING_LINEAR_MOTION_LABEL = "Oscillating Linear Motion"; + public static final String OSCILLATING_ROTATING_MOTION_LABEL = "Oscillating Rotating Motion"; + public static final String SDA_LABEL = "Ship Tank Sloshing"; + + public static final String VELOCITY_LABEL = "Velocity " + Symbols.M_S; + public static final String AMPLITUDE_LABEL = "Amplitude " + Symbols.M; + public static final String CENTRE_OF_ROTATION_LABEL = "Centre of Rotation " + Symbols.M; + public static final String AXIS_OF_ROTATION_LABEL = "Axis of Rotation " + Symbols.M; + public static final String ROTATIONAL_SPEED_RAD_S_LABEL = "Rotational Speed " + Symbols.OMEGA_SYMBOL_RAD; + public static final String STARTING_TIME_LABEL = "Starting Time " + Symbols.S; + + public static final String THETA_LABEL = "Phase " + Symbols.DEG; + public static final String PERIOD_LABEL = "Period " + Symbols.S; + + public static final String LAMBDA_LABEL = "Model Scale Ratio"; + public static final String ROLL_AMIN_LABEL = "Min Roll Amplitude " + Symbols.RAD; + public static final String ROLL_AMAX_LABEL = "Max Roll Amplitude " + Symbols.RAD; + public static final String SWAY_A_LABEL = "Sway Amplitude " + Symbols.M; + public static final String HEAVE_A_LABEL = "Heave Amplitude " + Symbols.M; + public static final String TP_LABEL = "Time Period for Liquid " + Symbols.S; + public static final String TPN_LABEL = "Natural Period of Ship " + Symbols.S; + public static final String DTI_LABEL = "Current Roll Period " + Symbols.S; + public static final String DTP_LABEL = "Increment"; + public static final String Q_LABEL = "Damping Coefficient"; + public static final String COFG_LABEL = "Centre of Gravity " + Symbols.M; + + protected BeanModel mainModel; + protected BeanModel linearMotionModel; + protected BeanModel rotatingMotionModel; + private BeanModel rotatingStepMotionModel; + private BeanModel axisRotationMotionModel; + protected BeanModel oscillatingLinearMotionModel; + protected BeanModel oscillatingRotatingMotionModel; + protected BeanModel sdaMotionModel; + + protected Model model; + private DynamicModule module; + protected JComboBoxWithItemsSupport typeCombo; + + public SolidBodyDynamicPanel(Model model, DynamicModule module) { + super(model, SOLID_RIGID_BODY.getLabel()); + this.model = model; + this.module = module; + this.mainModel = new BeanModel(new SolidBodyAlgorithm()); + this.linearMotionModel = new BeanModel(new LinearMotionFunction()); + this.rotatingMotionModel = new BeanModel(new RotatingMotionFunction()); + this.rotatingStepMotionModel = new BeanModel(new RotatingStepMotionFunction()); + this.axisRotationMotionModel = new BeanModel(new AxisRotationMotionFunction()); + this.oscillatingLinearMotionModel = new BeanModel(new OscillatingLinearMotionFunction()); + this.oscillatingRotatingMotionModel = new BeanModel(new OscillatingRotatingMotionFunction()); + this.sdaMotionModel = new BeanModel(new SDAMotionFunction()); + } + + protected BeanModel[] getBeanModels(){ + BeanModel[] models = new BeanModel[7]; + models[0] = linearMotionModel; + models[1] = rotatingMotionModel; + models[2] = rotatingStepMotionModel; + models[3] = axisRotationMotionModel; + models[4] = oscillatingLinearMotionModel; + models[5] = oscillatingRotatingMotionModel; + models[6] = sdaMotionModel; + return models; + } + + @SuppressWarnings("unchecked") + @Override + public JComponent layoutComponents() { + BeanPanelBuilder builder = new BeanPanelBuilder(); + typeCombo = (JComboBoxWithItemsSupport) builder.startChoice(TYPE_LABEL, mainModel.bindComboController(FUNCTION, getBeanModels()), TYPE_TOOLTIP); + + builder.startBean(LINEAR_MOTION_LABEL, linearMotionModel); + builder.addComponent(VELOCITY_LABEL, linearMotionModel.bindPoint(LinearMotionFunction.VELOCITY)); + builder.endBean(); + + builder.startBean(ROTATING_MOTION_LABEL, rotatingMotionModel); + builder.addComponent(CENTRE_OF_ROTATION_LABEL, rotatingMotionModel.bindPoint(RotatingMotionFunction.ORIGIN)); + builder.addComponent(AXIS_OF_ROTATION_LABEL, rotatingMotionModel.bindPoint(RotatingMotionFunction.AXIS)); + builder.addComponent(ROTATIONAL_SPEED_RAD_S_LABEL, rotatingMotionModel.bindDouble(RotatingMotionFunction.OMEGA)); + builder.addComponent(STARTING_TIME_LABEL, rotatingMotionModel.bindDouble(RotatingMotionFunction.T0)); + builder.endBean(); + + addEngysTypes(builder); + + builder.startBean(OSCILLATING_LINEAR_MOTION_LABEL, oscillatingLinearMotionModel); + builder.addComponent(AMPLITUDE_LABEL, oscillatingLinearMotionModel.bindPoint(OscillatingLinearMotionFunction.AMPLITUDE)); + builder.addComponent(ROTATIONAL_SPEED_RAD_S_LABEL, oscillatingLinearMotionModel.bindDouble(OscillatingLinearMotionFunction.OMEGA)); + builder.endBean(); + + builder.startBean(OSCILLATING_ROTATING_MOTION_LABEL, oscillatingRotatingMotionModel); + builder.addComponent(CENTRE_OF_ROTATION_LABEL, oscillatingRotatingMotionModel.bindPoint(OscillatingRotatingMotionFunction.ORIGIN)); + builder.addComponent(AMPLITUDE_LABEL, oscillatingRotatingMotionModel.bindPoint(OscillatingRotatingMotionFunction.AMPLITUDE)); + builder.addComponent(ROTATIONAL_SPEED_RAD_S_LABEL, oscillatingRotatingMotionModel.bindDouble(OscillatingRotatingMotionFunction.OMEGA)); + builder.endBean(); + + builder.startBean(SDA_LABEL, sdaMotionModel); + builder.addComponent(LAMBDA_LABEL, sdaMotionModel.bindDouble(SDAMotionFunction.LAMBDA)); + builder.addComponent(ROLL_AMIN_LABEL, sdaMotionModel.bindDouble(SDAMotionFunction.ROLL_AMIN)); + builder.addComponent(ROLL_AMAX_LABEL, sdaMotionModel.bindDouble(SDAMotionFunction.ROLL_AMAX)); + builder.addComponent(SWAY_A_LABEL, sdaMotionModel.bindDouble(SDAMotionFunction.SWAY_A)); + builder.addComponent(HEAVE_A_LABEL, sdaMotionModel.bindDouble(SDAMotionFunction.HEAVE_A)); + builder.addComponent(TP_LABEL, sdaMotionModel.bindDouble(SDAMotionFunction.TP)); + builder.addComponent(TPN_LABEL, sdaMotionModel.bindDouble(SDAMotionFunction.TPN)); + builder.addComponent(DTI_LABEL, sdaMotionModel.bindDouble(SDAMotionFunction.DTI)); + builder.addComponent(DTP_LABEL, sdaMotionModel.bindDouble(SDAMotionFunction.DTP)); + builder.addComponent(Q_LABEL, sdaMotionModel.bindDouble(SDAMotionFunction.Q)); + builder.addComponent(COFG_LABEL, sdaMotionModel.bindPoint(SDAMotionFunction.COFG)); + builder.endBean(); + + builder.endChoice(); + + return builder.removeMargins().getPanel(); + } + + protected void addEngysTypes(BeanPanelBuilder builder) { + builder.startBean(ROTATING_STEP_MOTION_LABEL, rotatingStepMotionModel); + builder.addComponent(CENTRE_OF_ROTATION_LABEL, rotatingStepMotionModel.bindPoint(RotatingStepMotionFunction.ORIGIN)); + builder.addComponent(AXIS_OF_ROTATION_LABEL, rotatingStepMotionModel.bindPoint(RotatingStepMotionFunction.AXIS)); + builder.addComponent(THETA_LABEL, rotatingStepMotionModel.bindDouble(RotatingStepMotionFunction.THETA)); + builder.addComponent(PERIOD_LABEL, rotatingStepMotionModel.bindInteger(RotatingStepMotionFunction.PERIOD)); + builder.endBean(); + + builder.startBean(AXIS_ROTATION_MOTION_LABEL, axisRotationMotionModel); + builder.addComponent(CENTRE_OF_ROTATION_LABEL, axisRotationMotionModel.bindPoint(AxisRotationMotionFunction.ORIGIN)); + builder.addComponent(AXIS_OF_ROTATION_LABEL, axisRotationMotionModel.bindPoint(AxisRotationMotionFunction.AXIS)); + builder.addComponent(ROTATIONAL_SPEED_RAD_S_LABEL, axisRotationMotionModel.bindDouble(AxisRotationMotionFunction.OMEGA)); + builder.endBean(); + } + + public BeanModel getMainModel() { + return mainModel; + } + + @Override + public void load() { + if(module.getDynamicData().getAlgorithm().getType().isSolidRigidBody()){ + mainModel.setBean((SolidBodyAlgorithm) module.getDynamicData().getAlgorithm().copy()); + } + } + + @Override + public void save() { + if(module.getDynamicData().getAlgorithm().getType().isSolidRigidBody()){ + module.getDynamicData().setAlgorithm(mainModel.getBean().copy()); + } + } + +} diff --git a/src/eu/engys/dynamic/resources/dynamic.fields b/src/eu/engys/dynamic/resources/dynamic.fields new file mode 100644 index 0000000..3e7602e --- /dev/null +++ b/src/eu/engys/dynamic/resources/dynamic.fields @@ -0,0 +1,179 @@ +displacement +{ + allowedFieldInitialisationMethods (fixedValue); + + initialisation + { + type fixedValue; + value uniform (0 0 0); + } + + + fieldDefinition + { + type vector; + meshType point; + dimensions [ 0 1 0 0 0 0 0 ]; + internalField uniform (0 0 0); + + boundaryConditions + { + regionDefaults + { + wall + { + type fixedValue; + value uniform (0 0 0); + } + + mappedWall + { + type fixedValue; + value uniform (0 0 0); + } + + outlet + { + type fixedValue; + value uniform (0 0 0); + } + + inlet + { + type fixedValue; + value uniform (0 0 0); + } + + patch + { + type fixedValue; + value uniform (0 0 0); + } + } + + partialNamed {} + + exactNamed{} + } + } +} +motion +{ + allowedFieldInitialisationMethods (fixedValue); + + initialisation + { + type fixedValue; + value uniform (0 0 0); + } + + + fieldDefinition + { + type point; + meshType point; + dimensions [ 0 1 -1 0 0 0 0 ]; + internalField uniform (0 0 0); + + boundaryConditions + { + regionDefaults + { + wall + { + type fixedValue; + value uniform (0 0 0); + } + + mappedWall + { + type fixedValue; + value uniform (0 0 0); + } + + outlet + { + type fixedValue; + value uniform (0 0 0); + } + + inlet + { + type fixedValue; + value uniform (0 0 0); + } + + patch + { + type fixedValue; + value uniform (0 0 0); + } + } + + partialNamed {} + + exactNamed{} + } + } +} +pmultiphaseDyM +{ + allowedFieldInitialisationMethods (default fixedValue potentialFlow boundaryValue cellSet ); + + initialisation + { + type default; + } + + + fieldDefinition + { + type scalar; + dimensions [ 1 -1 -2 0 0 0 0 ]; + internalField uniform 0; + + boundaryConditions + { + regionDefaults + { + wall + { + type zeroGradient; + //type fixedFluxPressure; + //value uniform 0; + //phi phiAbs; + } + mappedWall + { + type zeroGradient; + //type fixedFluxPressure; + //value uniform 0; + //phi phiAbs; + } + + outlet {type fixedValue; value uniform 0;} + + inlet + { + type zeroGradient; + //type fixedFluxPressure; + //value uniform 0; + //phi phiAbs; + } + + patch + { + type totalPressure; + p0 uniform 0; + U U; + value uniform 0; + gamma 1.4; + } + } + + partialNamed {} + + exactNamed{} + } + } +} \ No newline at end of file diff --git a/src/eu/engys/dynamic/resources/dynamic.stateData b/src/eu/engys/dynamic/resources/dynamic.stateData new file mode 100644 index 0000000..5c0dbfd --- /dev/null +++ b/src/eu/engys/dynamic/resources/dynamic.stateData @@ -0,0 +1,104 @@ +states +{ + pimpleFoamRAS (PIMPLE incompressible ras); + pimpleFoamLES (PIMPLE incompressible les); + + rhoPimpleFoamRAS (PIMPLE compressible ras); + rhoPimpleFoamLES (PIMPLE compressible les); + + interFoamRAS (PIMPLE incompressible ras VOF); + interFoamLES (PIMPLE incompressible les VOF); + + siCoupled (steady COUPLED incompressible ras); + tiCoupled (transient COUPLED incompressible ras); + tiCoupled2 (transient COUPLED incompressible les); +} + +"pimpleFoam.*" {$dynamic;} +"rhoPimpleFoam.*" {$dynamic;} +"rhoCentralFoam.*" {$dynamic;} +"interFoam.*" {$dynamic;} +"siCoupled.*" {$dynamic;} +"tiCoupled.*" {$dynamic;} + +dynamic +{ + fieldMaps + { + pointMotionU motion; + pointDisplacement displacement; + p_rgh pmultiphaseDyM; + } + + system + { + fvSchemes + { + laplacianSchemes + { + laplacian(diffusivity,cellDisplacement) Gauss linear uncorrected; + laplacian(diffusivity,cellMotionU) Gauss linear uncorrected; + } + fluxRequired + { + pcorr ; + } + } + fvSolution + { + solvers + { + pcorr + { + solver GAMG; + agglomerator faceAreaPair; + mergeLevels 1; + cacheAgglomeration true; + nCellsInCoarsestLevel 200; + tolerance 1e-10; + relTol 0.01; + smoother GaussSeidel; + nPreSweeps 0; + nPostSweeps 2; + nFinestSweeps 2; + minIter 1; + } + cellMotionU + { + solver PCG; + preconditioner DIC; + tolerance 1e-08; + relTol 0; + minIter 1; + } + cellDisplacement + { + solver GAMG; + tolerance 1e-08; + relTol 0; + smoother GaussSeidel; + cacheAgglomeration true; + nCellsInCoarsestLevel 10; + agglomerator faceAreaPair; + mergeLevels 1; + minIter 1; + } + + } + + PIMPLE + { + correctPhi true; + turbOnFinalIterOnly false; + //ddtPhiCorr true; + } + } + + controlDict + { + } + } + + constant {} + +} \ No newline at end of file diff --git a/src/eu/engys/dynamic/resources/dynamicMeshDict b/src/eu/engys/dynamic/resources/dynamicMeshDict new file mode 100644 index 0000000..a39c62b --- /dev/null +++ b/src/eu/engys/dynamic/resources/dynamicMeshDict @@ -0,0 +1 @@ +dynamicFvMesh staticFvMesh; diff --git a/src/eu/engys/gui/AboutWindow.java b/src/eu/engys/gui/AboutWindow.java index 79ce270..763e359 100644 --- a/src/eu/engys/gui/AboutWindow.java +++ b/src/eu/engys/gui/AboutWindow.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui; @@ -120,21 +119,19 @@ public class AboutWindow { infoPanel.add(vers, new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(30, 10, 0, 10), 0, 0)); infoPanel.add(copy, new GridBagConstraints(0, 1, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 10, 30, 10), 0, 0)); - final JButton sitebutton = createOpenSiteButton(); + JButton sitebutton = createOpenSiteButton(); JPanel siteButtonPanel = new JPanel(new GridBagLayout()); siteButtonPanel.setBackground(Color.WHITE); siteButtonPanel.add(sitebutton, new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 10, 20, 10), 0, 0)); JPanel mainPanel = new JPanel(new BorderLayout()); mainPanel.add(infoPanel, BorderLayout.NORTH); - // mainPanel.add(new JPanel(), BorderLayout.CENTER); mainPanel.add(siteButtonPanel, BorderLayout.CENTER); return mainPanel; } private JButton createOpenSiteButton() { - final JButton button = new JButton(new AbstractAction(ApplicationInfo.getSite()) { - + JButton button = UiUtil.createURLOpenerButton(new AbstractAction(ApplicationInfo.getSite()) { @Override public void actionPerformed(ActionEvent e) { try { @@ -144,7 +141,6 @@ public class AboutWindow { } } }); - button.setForeground(Color.BLUE); return button; } diff --git a/src/eu/engys/gui/AbstractGUIPanel.java b/src/eu/engys/gui/AbstractGUIPanel.java index 6c7f402..c985437 100644 --- a/src/eu/engys/gui/AbstractGUIPanel.java +++ b/src/eu/engys/gui/AbstractGUIPanel.java @@ -1,36 +1,33 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui; import java.awt.BorderLayout; import java.awt.Font; -import javax.inject.Inject; import javax.swing.BorderFactory; -import javax.swing.Box; import javax.swing.JComponent; import javax.swing.JLabel; import javax.swing.JPanel; @@ -42,8 +39,9 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import eu.engys.core.project.Model; +import eu.engys.core.project.system.monitoringfunctionobjects.MonitoringFunctionObject; +import eu.engys.core.project.zero.patches.BoundaryType; import eu.engys.gui.view3D.CanvasPanel; -import eu.engys.util.progress.ProgressMonitor; import eu.engys.util.ui.UiUtil; import eu.engys.util.ui.builder.PanelBuilder; @@ -51,9 +49,6 @@ public abstract class AbstractGUIPanel extends JPanel implements GUIPanel, Model private static final Logger logger = LoggerFactory.getLogger(GUIPanel.class); - @Inject - protected ProgressMonitor monitor; - private final String title; protected final Model model; @@ -75,7 +70,7 @@ public abstract class AbstractGUIPanel extends JPanel implements GUIPanel, Model public void install(CanvasPanel view3D) { this.view3D = view3D; } - + @Override public void layoutPanel() { JComponent titleComponent = createTitle(title); @@ -97,12 +92,14 @@ public abstract class AbstractGUIPanel extends JPanel implements GUIPanel, Model Font font = titleLabel.getFont(); titleLabel.setFont(font.deriveFont(font.getSize2D() + 2).deriveFont(Font.BOLD)); - titleToolbar = UiUtil.getToolbar("view.gui.toolbar"); - titleToolbar.add(titleLabel); - titleToolbar.add(Box.createHorizontalGlue()); + titleToolbar = UiUtil.getToolbarWrapped("view.gui.toolbar"); + + JPanel p = new JPanel(new BorderLayout()); + p.add(titleLabel, BorderLayout.CENTER); + p.add(titleToolbar, BorderLayout.EAST); PanelBuilder pb = new PanelBuilder(); - pb.addComponent(titleToolbar); + pb.addComponent(p); pb.addComponent(new JSeparator()); return pb.removeMargins().getPanel(); @@ -186,6 +183,10 @@ public abstract class AbstractGUIPanel extends JPanel implements GUIPanel, Model public void fieldManipulationFunctionObjectsChanged() { } + @Override + public void monitoringFunctionObjectChanged(MonitoringFunctionObject fo) { + } + @Override public void monitoringFunctionObjectsChanged() { } @@ -197,11 +198,19 @@ public abstract class AbstractGUIPanel extends JPanel implements GUIPanel, Model @Override public void runtimeFieldsChanged() { } - + @Override public void fieldsChanged() { } - + + @Override + public void boundaryTypeChanged(BoundaryType arg) { + } + + @Override + public void geometryChanged() { + } + @Override public void solverChanged() { } @@ -219,14 +228,6 @@ public abstract class AbstractGUIPanel extends JPanel implements GUIPanel, Model return -1; } - public ProgressMonitor getMonitor() { - return monitor; - } - - public void setMonitor(ProgressMonitor monitor) { - this.monitor = monitor; - } - @Override public String toString() { return title; diff --git a/src/eu/engys/gui/Actions.java b/src/eu/engys/gui/Actions.java index d9c0259..adcbfd0 100644 --- a/src/eu/engys/gui/Actions.java +++ b/src/eu/engys/gui/Actions.java @@ -1,35 +1,35 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui; import javax.swing.JToolBar; public interface Actions { + public static final String TOOLBAR_NAME = "view.element.toolbar"; + public JToolBar toolbar(); public void update(); diff --git a/src/eu/engys/gui/DefaultGUIPanel.java b/src/eu/engys/gui/DefaultGUIPanel.java index 178649d..a332d07 100644 --- a/src/eu/engys/gui/DefaultGUIPanel.java +++ b/src/eu/engys/gui/DefaultGUIPanel.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui; diff --git a/src/eu/engys/core/dictionary/DictionaryEditor.java b/src/eu/engys/gui/DictionaryEditor.java similarity index 73% rename from src/eu/engys/core/dictionary/DictionaryEditor.java rename to src/eu/engys/gui/DictionaryEditor.java index 756fe39..77b042c 100644 --- a/src/eu/engys/core/dictionary/DictionaryEditor.java +++ b/src/eu/engys/gui/DictionaryEditor.java @@ -1,30 +1,31 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.gui; - -package eu.engys.core.dictionary; +import static eu.engys.util.ui.UiUtil.DIALOG_CANCEL_LABEL; +import static eu.engys.util.ui.UiUtil.DIALOG_OK_LABEL; import java.awt.BorderLayout; import java.awt.Color; @@ -49,6 +50,8 @@ import org.fife.ui.rsyntaxtextarea.RSyntaxTextArea; import org.fife.ui.rsyntaxtextarea.SyntaxConstants; import org.fife.ui.rtextarea.RTextScrollPane; +import eu.engys.core.dictionary.Dictionary; +import eu.engys.core.dictionary.DictionaryReader; import eu.engys.core.dictionary.parser.DictionaryReader2; import eu.engys.core.project.system.BlockMeshDict; import eu.engys.util.ui.ExecUtil; @@ -176,10 +179,10 @@ public class DictionaryEditor { JPanel panel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); okButton = new JButton(new OKAction()); - okButton.setName("OK"); + okButton.setName(DIALOG_OK_LABEL); JButton cancelButton = new JButton(new CancelAction()); - cancelButton.setName("Cancel"); + cancelButton.setName(DIALOG_CANCEL_LABEL); panel.add(okButton); panel.add(cancelButton); @@ -226,7 +229,7 @@ public class DictionaryEditor { private class OKAction extends AbstractAction { public OKAction() { - super("OK"); + super(DIALOG_OK_LABEL); } @Override @@ -241,7 +244,7 @@ public class DictionaryEditor { private class CancelAction extends AbstractAction { public CancelAction() { - super("Cancel"); + super(DIALOG_CANCEL_LABEL); } @Override diff --git a/src/eu/engys/core/dictionary/FileEditor.java b/src/eu/engys/gui/FileEditor.java similarity index 76% rename from src/eu/engys/core/dictionary/FileEditor.java rename to src/eu/engys/gui/FileEditor.java index 4cc76a1..246198a 100644 --- a/src/eu/engys/core/dictionary/FileEditor.java +++ b/src/eu/engys/gui/FileEditor.java @@ -1,30 +1,29 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ - -package eu.engys.core.dictionary; +package eu.engys.gui; import java.awt.BorderLayout; import java.awt.Color; diff --git a/src/eu/engys/gui/GUIError.java b/src/eu/engys/gui/GUIError.java index 4b7d9cf..8c82726 100644 --- a/src/eu/engys/gui/GUIError.java +++ b/src/eu/engys/gui/GUIError.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui; diff --git a/src/eu/engys/gui/GUIPanel.java b/src/eu/engys/gui/GUIPanel.java index 4a68a7e..aef2f00 100644 --- a/src/eu/engys/gui/GUIPanel.java +++ b/src/eu/engys/gui/GUIPanel.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui; import javax.swing.JComponent; @@ -60,4 +59,5 @@ public interface GUIPanel extends ModulePanel { public void layoutPanel(); public void install(CanvasPanel view3D); + } diff --git a/src/eu/engys/gui/GlassPane.java b/src/eu/engys/gui/GlassPane.java index 7841ba6..4cfb1c9 100644 --- a/src/eu/engys/gui/GlassPane.java +++ b/src/eu/engys/gui/GlassPane.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui; import java.awt.event.MouseEvent; diff --git a/src/eu/engys/gui/ListBuilderFactory.java b/src/eu/engys/gui/ListBuilderFactory.java index 77c2b5f..bc7f697 100644 --- a/src/eu/engys/gui/ListBuilderFactory.java +++ b/src/eu/engys/gui/ListBuilderFactory.java @@ -1,147 +1,272 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import eu.engys.core.controller.GeometryToMesh; import eu.engys.core.project.Model; import eu.engys.core.project.runtimefields.RuntimeField; +import eu.engys.core.project.zero.cellzones.CellZone; +import eu.engys.core.project.zero.cellzones.CellZones; import eu.engys.core.project.zero.facezones.FaceZone; import eu.engys.core.project.zero.facezones.FaceZones; import eu.engys.core.project.zero.fields.Field; +import eu.engys.core.project.zero.fields.Fields; import eu.engys.core.project.zero.patches.Patch; import eu.engys.core.project.zero.patches.Patches; import eu.engys.util.ui.ListBuilder; public class ListBuilderFactory { - public static ListBuilder getPatchesListBuilder(final Model model) { - ListBuilder listBuilder = new ListBuilder() { + /* + * List Model + */ - @Override - public String getTitle() { - return "Select Patches"; - } + public static ReloadableListModel getPatchesListModel(final Model model) { + return new ReloadableListModel() { + { + reload(); + } - @Override - public String[] getSourceElements() { - Patches patches = model.getPatches(); - List elements = new ArrayList<>(); - if (patches != null) { - for (Patch patch : patches.patchesToDisplay()) { - elements.add(patch.getName()); - } - } - return elements.toArray(new String[0]); - } + @Override + public void reload() { + Patches patches = model.getPatches(); + List elements = new ArrayList<>(); + if (patches != null) { + for (Patch patch : patches.patchesToDisplay()) { + elements.add(patch.getName()); + } + } + this.elements = elements.toArray(new String[0]); + } + }; + } - @Override - public int getSelectionMode() { - return ListBuilder.MULTIPLE_SELECTION; - } - }; - return listBuilder; - } + public static ReloadableListModel getFieldsListModel(final Model model) { + return new ReloadableListModel() { + { + reload(); + } - public static ListBuilder getFaceZonesListBuilder(final Model model) { - ListBuilder listBuilder = new ListBuilder() { + @Override + public void reload() { + Fields fields = model.getFields(); + List elements = new ArrayList<>(); + if (fields != null) { + for (Field field : fields.orderedFields()) { + elements.add(field.getName()); + } + } + this.elements = elements.toArray(new String[0]); + } + }; + } - @Override - public String getTitle() { - return "Select Face Zone"; - } + public static ReloadableListModel getScalarFieldsListModel(final Model model) { + return new ReloadableListModel() { + { + reload(); + } - @Override - public String[] getSourceElements() { - FaceZones faceZones = model.getFaceZones(); - List elements = new ArrayList<>(); - if (faceZones != null) { - for (FaceZone zone : faceZones) { - elements.add(zone.getName()); - } - } - return elements.toArray(new String[0]); - } + @Override + public void reload() { + Fields fields = model.getFields(); + List elements = new ArrayList<>(); + if (fields != null) { + for (Field field : fields.orderedScalarFields()) { + elements.add(field.getName()); + } + } + this.elements = elements.toArray(new String[0]); + } + }; + } + + public static ReloadableListModel getFaceZonesListModel(final Model model) { + return new ReloadableListModel() { + { + reload(); + } - @Override - public int getSelectionMode() { - return ListBuilder.MULTIPLE_SELECTION; - } - }; - return listBuilder; - } + @Override + public void reload() { + FaceZones faceZones = model.getFaceZones(); + List elements = new ArrayList<>(); + if (faceZones != null) { + for (FaceZone zone : faceZones) { + elements.add(zone.getName()); + } + } + this.elements = elements.toArray(new String[0]); + } + }; + } - public static ListBuilder getFieldsListBuilder(final Model model) { - ListBuilder fieldsListBuilder = new ListBuilder() { + /* + * List Builder + */ - @Override - public String getTitle() { - return "Select Fields"; - } - - @Override - public String[] getSourceElements() { - List fields = model.getFields().orderedFields(); - List runTimeFields = model.getRuntimeFields().fields(); - - List elements = new ArrayList<>(); - if (fields != null) { - for (Field f : fields) { - elements.add(f.getName()); - } - for (RuntimeField rtf : runTimeFields) { - elements.add(rtf.getName()); - } - } - return elements.toArray(new String[0]); - } - - @Override - public int getSelectionMode() { - return ListBuilder.MULTIPLE_SELECTION; - } - }; - return fieldsListBuilder; - } - - public static ListBuilder getAdvancedMeshPatchesListBuilder(final Model model, final String title) { + public static ListBuilder getPatchesListBuilder(final Model model) { ListBuilder listBuilder = new ListBuilder() { - + + @Override + public String getTitle() { + return "Select Patches"; + } + + @Override + public String[] getSourceElements() { + Patches patches = model.getPatches(); + List elements = new ArrayList<>(); + if (patches != null) { + for (Patch patch : patches.patchesToDisplay()) { + elements.add(patch.getName()); + } + } + return elements.toArray(new String[0]); + } + + @Override + public int getSelectionMode() { + return ListBuilder.MULTIPLE_SELECTION; + } + }; + return listBuilder; + } + + public static ListBuilder getCellZonesListBuilder(final Model model, final ListBuilder... additionalBuilders) { + ListBuilder listBuilder = new ListBuilder() { + + @Override + public String getTitle() { + return "Select Cell Zone"; + } + + @Override + public String[] getSourceElements() { + CellZones cellZones = model.getCellZones(); + List elements = new ArrayList<>(); + if (cellZones != null) { + for (CellZone zone : cellZones) { + elements.add(zone.getName()); + } + } + for (ListBuilder listBuilder : additionalBuilders) { + elements.addAll(Arrays.asList(listBuilder.getSourceElements())); + } + return elements.toArray(new String[0]); + } + + @Override + public int getSelectionMode() { + return ListBuilder.MULTIPLE_SELECTION; + } + }; + return listBuilder; + } + + public static ListBuilder getFaceZonesListBuilder(final Model model) { + ListBuilder listBuilder = new ListBuilder() { + + @Override + public String getTitle() { + return "Select Face Zone"; + } + + @Override + public String[] getSourceElements() { + FaceZones faceZones = model.getFaceZones(); + List elements = new ArrayList<>(); + if (faceZones != null) { + for (FaceZone zone : faceZones) { + elements.add(zone.getName()); + } + } + return elements.toArray(new String[0]); + } + + @Override + public int getSelectionMode() { + return ListBuilder.MULTIPLE_SELECTION; + } + }; + return listBuilder; + } + + public static ListBuilder getFieldsListBuilder(final Model model, final ListBuilder... additionalBuilders) { + ListBuilder fieldsListBuilder = new ListBuilder() { + + @Override + public String getTitle() { + return "Select Fields"; + } + + @Override + public String[] getSourceElements() { + List fields = model.getFields().orderedFields(); + List runTimeFields = model.getRuntimeFields().fields(); + + List elements = new ArrayList<>(); + if (fields != null) { + for (Field f : fields) { + elements.add(f.getName()); + } + for (RuntimeField rtf : runTimeFields) { + elements.add(rtf.getName()); + } + for (ListBuilder listBuilder : additionalBuilders) { + elements.addAll(Arrays.asList(listBuilder.getSourceElements())); + } + } + return elements.toArray(new String[0]); + } + + @Override + public int getSelectionMode() { + return ListBuilder.MULTIPLE_SELECTION; + } + }; + return fieldsListBuilder; + } + + public static ListBuilder getAdvancedMeshPatchesListBuilder(final Model model, final String title) { + ListBuilder listBuilder = new ListBuilder() { + @Override public String getTitle() { return title; } - + @Override public String[] getSourceElements() { return new GeometryToMesh(model).listPatches(); } - + @Override public int getSelectionMode() { return ListBuilder.MULTIPLE_SELECTION; diff --git a/src/eu/engys/gui/MenuBar.java b/src/eu/engys/gui/MenuBar.java index 976a010..35623b6 100644 --- a/src/eu/engys/gui/MenuBar.java +++ b/src/eu/engys/gui/MenuBar.java @@ -1,30 +1,35 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui; +import static eu.engys.gui.view.View.EXIT; +import static eu.engys.gui.view.View.NEW_CASE; +import static eu.engys.gui.view.View.OPEN_CASE; +import static eu.engys.gui.view.View.SAVE_AS_CASE; +import static eu.engys.gui.view.View.SAVE_CASE; + import java.awt.event.ActionEvent; import java.io.File; import java.util.ArrayList; @@ -42,6 +47,8 @@ import org.apache.commons.io.comparator.NameFileComparator; import org.apache.commons.io.filefilter.FileFilterUtils; import org.apache.commons.io.filefilter.IOFileFilter; +import eu.engys.core.controller.Controller.OpenMode; +import eu.engys.core.controller.OpenOptions; import eu.engys.core.executor.FileManagerSupport; import eu.engys.core.presentation.ActionManager; import eu.engys.core.project.Model; @@ -54,12 +61,19 @@ import eu.engys.util.ui.ResourcesUtil; public class MenuBar extends JMenuBar implements RecentItemsObserver { + public static final String FILE_MENU = "File"; + public static final String EDIT_MENU = "Edit"; + public static final String DICTIONARIES_MENU = "Dictionaries"; + public static final String HELP_MENU = "Help"; + + private static final String OPEN_RECENT_MENU = "Open Recent"; + public static final Icon OPEN_ICON = ResourcesUtil.getIcon("application.open.icon"); - public static final Icon FILE_ICON = ResourcesUtil.getIcon("file"); + public static final Icon FILE_ICON = ResourcesUtil.getIcon("file.icon"); private JMenu fileMenu; private JMenu editMenu; - // private JMenu dictionariesMenu; + private JMenu dictionariesMenu; private JMenu helpMenu; // private JMenu viewMenu; private JMenu recentCasesMenu; @@ -70,29 +84,38 @@ public class MenuBar extends JMenuBar implements RecentItemsObserver { super(); this.view = view; StartUpMonitor.info("Loading Menu Bar"); - fileMenu = new JMenu("File"); - fileMenu.add(ActionManager.getInstance().get("application.create")); - fileMenu.add(ActionManager.getInstance().get("application.open")); + fileMenu = new JMenu(FILE_MENU); - recentCasesMenu = new JMenu("Open Recent"); + if (ActionManager.getInstance().contains(NEW_CASE)) { + fileMenu.add(ActionManager.getInstance().get(NEW_CASE)); + } + fileMenu.add(ActionManager.getInstance().get(OPEN_CASE)); + + recentCasesMenu = new JMenu(OPEN_RECENT_MENU); recentCasesMenu.setIcon(OPEN_ICON); fileMenu.add(recentCasesMenu); - fileMenu.add(ActionManager.getInstance().get("application.save")); - fileMenu.add(ActionManager.getInstance().get("application.saveAs")); - fileMenu.addSeparator(); - fileMenu.add(ActionManager.getInstance().get("application.exit")); + if (ActionManager.getInstance().contains(SAVE_CASE)) { + fileMenu.add(ActionManager.getInstance().get(SAVE_CASE)); + } + if (ActionManager.getInstance().contains(SAVE_AS_CASE)) { + fileMenu.add(ActionManager.getInstance().get(SAVE_AS_CASE)); + } + if (ActionManager.getInstance().contains(EXIT)) { + fileMenu.addSeparator(); + fileMenu.add(ActionManager.getInstance().get(EXIT)); + } - editMenu = new JMenu("Edit"); + editMenu = new JMenu(EDIT_MENU); editMenu.setName("Application Edit"); - // dictionariesMenu = new JMenu("Dictionaries"); + dictionariesMenu = new JMenu(DICTIONARIES_MENU); - helpMenu = new JMenu("Help"); + helpMenu = new JMenu(HELP_MENU); add(fileMenu); add(editMenu); - // add(dictionariesMenu); +// add(dictionariesMenu); add(helpMenu); RecentItems.getInstance().addObserver(this); @@ -106,6 +129,10 @@ public class MenuBar extends JMenuBar implements RecentItemsObserver { return editMenu; } + public JMenu getDictionariesMenu() { + return dictionariesMenu; + } + public JMenu getHelpMenu() { return helpMenu; } @@ -125,7 +152,7 @@ public class MenuBar extends JMenuBar implements RecentItemsObserver { @Override public void actionPerformed(ActionEvent e) { if (view.getController().allowActionsOnRunning(false)) { - view.getController().openCase(new File(item)); + view.getController().openCase(OpenOptions.file(new File(item), OpenMode.CHECK_FOLDER_ASK_USER)); } } }); @@ -144,22 +171,25 @@ public class MenuBar extends JMenuBar implements RecentItemsObserver { ExecUtil.invokeLater(new Runnable() { @Override public void run() { - // dictionariesMenu.removeAll(); - if (model.hasProject()) { - File baseDir = model.getProject().getBaseDir(); - IOFileFilter fileFilter = FileFilterUtils.or(FileFilterUtils.suffixFileFilter("Dict"), FileFilterUtils.suffixFileFilter("Properties"), FileFilterUtils.prefixFileFilter("fv")); - List files = new ArrayList(FileUtils.listFiles(baseDir, fileFilter, FileFilterUtils.directoryFileFilter())); - Collections.sort(files, NameFileComparator.NAME_INSENSITIVE_COMPARATOR); - for (final File file : files) { - JMenuItem menuItem = new JMenuItem(new AbstractAction(file.getName(), FILE_ICON) { - @Override - public void actionPerformed(ActionEvent e) { - FileManagerSupport.open(file); - } - }); - menuItem.setToolTipText(file.getAbsolutePath()); - // dictionariesMenu.add(menuItem); + try{ + view.getMenuBar().getDictionariesMenu().removeAll(); + if (model.hasProject()) { + File baseDir = model.getProject().getBaseDir(); + IOFileFilter fileFilter = FileFilterUtils.or(FileFilterUtils.suffixFileFilter("Dict"), FileFilterUtils.suffixFileFilter("Properties"), FileFilterUtils.prefixFileFilter("fv")); + List files = new ArrayList(FileUtils.listFiles(baseDir, fileFilter, FileFilterUtils.directoryFileFilter())); + Collections.sort(files, NameFileComparator.NAME_INSENSITIVE_COMPARATOR); + for (final File file : files) { + JMenuItem menuItem = new JMenuItem(new AbstractAction(file.getName(), FILE_ICON) { + @Override + public void actionPerformed(ActionEvent e) { + FileManagerSupport.open(file); + } + }); + menuItem.setToolTipText(file.getAbsolutePath()); + view.getMenuBar().getDictionariesMenu().add(menuItem); + } } + } catch(Exception e){ } } }); diff --git a/src/eu/engys/gui/ModelObserver.java b/src/eu/engys/gui/ModelObserver.java index 284b788..1edca3d 100644 --- a/src/eu/engys/gui/ModelObserver.java +++ b/src/eu/engys/gui/ModelObserver.java @@ -1,40 +1,48 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui; +import eu.engys.core.project.system.monitoringfunctionobjects.MonitoringFunctionObject; +import eu.engys.core.project.zero.patches.BoundaryType; + public interface ModelObserver { void fieldManipulationFunctionObjectsChanged(); void monitoringFunctionObjectsChanged(); + + void monitoringFunctionObjectChanged(MonitoringFunctionObject fo); void stateChanged(); void fieldsChanged(); + void boundaryTypeChanged(BoundaryType arg); + + void geometryChanged(); + void runtimeFieldsChanged(); void solverChanged(); @@ -44,4 +52,5 @@ public interface ModelObserver { void projectChanged(); String getTitle(); + } diff --git a/src/eu/engys/gui/PreferencesBean.java b/src/eu/engys/gui/PreferencesBean.java new file mode 100644 index 0000000..4e6069b --- /dev/null +++ b/src/eu/engys/gui/PreferencesBean.java @@ -0,0 +1,113 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.gui; + +public class PreferencesBean { + + private boolean os; + + private boolean paraview; + private boolean paraviewBatch; + private boolean fieldview; + private boolean ensight; + + private boolean pathPreferences; + private boolean batchPreferences; + private boolean vtkPreferences; + private boolean miscPreferences; + + public boolean isOS() { + return os; + } + + public void setOS(boolean os) { + this.os = os; + } + + public boolean isParaview() { + return paraview; + } + + public void setParaview(boolean paraview) { + this.paraview = paraview; + } + + public boolean isParaviewBatch() { + return paraviewBatch; + } + + public void setParaviewBatch(boolean paraviewBatch) { + this.paraviewBatch = paraviewBatch; + } + + public boolean isFieldview() { + return fieldview; + } + + public void setFieldview(boolean fieldview) { + this.fieldview = fieldview; + } + + public boolean isEnsight() { + return ensight; + } + + public void setEnsight(boolean ensight) { + this.ensight = ensight; + } + + public boolean isPathPreferences() { + return pathPreferences; + } + + public void setPathPreferences(boolean pathPreferences) { + this.pathPreferences = pathPreferences; + } + + public boolean isBatchPreferences() { + return batchPreferences; + } + + public void setBatchPreferences(boolean batchPreferences) { + this.batchPreferences = batchPreferences; + } + + public boolean isVtkPreferences() { + return vtkPreferences; + } + + public void setVtkPreferences(boolean vtkPreferences) { + this.vtkPreferences = vtkPreferences; + } + + public boolean isMiscPreferences() { + return miscPreferences; + } + + public void setMiscPreferences(boolean miscPreferences) { + this.miscPreferences = miscPreferences; + } + +} diff --git a/src/eu/engys/gui/PreferencesDialog.java b/src/eu/engys/gui/PreferencesDialog.java index 6127ddd..e21481e 100644 --- a/src/eu/engys/gui/PreferencesDialog.java +++ b/src/eu/engys/gui/PreferencesDialog.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui; import static eu.engys.util.ui.ComponentsFactory.checkField; @@ -51,8 +50,6 @@ import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JScrollPane; -import net.java.dev.designgridlayout.Componentizer; - import org.apache.commons.io.FileUtils; import eu.engys.core.OpenFOAMEnvironment; @@ -61,6 +58,7 @@ import eu.engys.core.project.defaults.DictDataFolder; import eu.engys.util.ApplicationInfo; import eu.engys.util.PrefUtil; import eu.engys.util.Util; +import eu.engys.util.Util.ScriptStyle; import eu.engys.util.filechooser.util.SelectionMode; import eu.engys.util.ui.ComponentsFactory; import eu.engys.util.ui.FileFieldPanel; @@ -70,6 +68,7 @@ import eu.engys.util.ui.builder.PanelBuilder; import eu.engys.util.ui.textfields.DoubleField; import eu.engys.util.ui.textfields.IntegerField; import eu.engys.util.ui.textfields.StringField; +import net.java.dev.designgridlayout.Componentizer; public class PreferencesDialog { @@ -80,8 +79,10 @@ public class PreferencesDialog { private static final String OPENFOAM_TOOLTIP_WINDOWS = "e.g. \\%s\\OpenFOAM-x.x_engysEdition-x.x"; private static final String OPENFOAM_TOOLTIP_LINUX_OS = "e.g. /%s/OpenFOAM-x.x.x"; private static final String OPENFOAM_TOOLTIP_WINDOWS_OS = "e.g. \\%s\\OpenFOAM-x.x.x"; - private static final String PARAVIEW_TOOLTIP_LINUX = "e.g. /ParaView x.x.x/bin/paraview"; - private static final String PARAVIEW_TOOLTIP_WINDOWS = "e.g. \\ParaView x.x.x\\bin\\paraview.exe"; + private static final String PARAVIEW_TOOLTIP_LINUX = "e.g. /ParaView-x.x.x/bin/paraview"; + private static final String PARAVIEW_TOOLTIP_WINDOWS = "e.g. \\ParaView-x.x.x\\bin\\paraview.exe"; + private static final String PARAVIEW_BATCH_TOOLTIP_LINUX = "e.g. /ParaView-x.x.x.osmesa/bin/pvbatch"; + private static final String PARAVIEW_BATCH_TOOLTIP_WINDOWS = "platform not supported"; private static final String FIELDVIEW_TOOLTIP_LINUX = "e.g. /fv/bin/fv"; private static final String FIELDVIEW_TOOLTIP_WINDOWS = "e.g. \\Intelligent Light\\FVWINxx\\bin\\fv.bat"; private static final String ENSIGHT_TOOLTIP_LINUX = "e.g. /CEI/bin/ensight100"; @@ -93,13 +94,15 @@ public class PreferencesDialog { // private static final String FILE_OPENER_TOOLTIP = // "Override system file opener, e.g. 'gnome-open'"; + private static final int ROW_SIZE = 20; /* * Labels */ private static final String PATHS_LABEL = "Paths"; public static final String CORE_FOLDER_LABEL = "Core Folder"; - public static final String PARA_VIEW_EXECUTABLE_LABEL = "ParaView Executable"; + public static final String PARAVIEW_EXECUTABLE_LABEL = "ParaView Executable"; + public static final String PARAVIEW_BATCH_EXECUTABLE_LABEL = "ParaView Batch Executable"; public static final String FIELD_VIEW_EXECUTABLE_LABEL = "FieldView Executable"; public static final String EN_SIGHT_EXECUTABLE_LABEL = "EnSight Executable"; @@ -121,23 +124,27 @@ public class PreferencesDialog { public static final String MAX_LOG_LINES_LABEL = "Max Log Lines"; // public static final String MAX_CHART_LINES_LABEL = "Max Chart Lines"; public static final String HIDE_EMPTY_PATCHES_LABEL = "Hide Empty Patches"; + public static final String HIDE_PROCESSOR_PATCHES_LABEL = "Hide Processor Patches"; + public static final String HIDE_PROCESSOR_CYCLIC_PATCHES_LABEL = "Hide Processor Cyclic Patches"; public static final String CUSTOM_FILE_MANAGER_LABEL = "Custom File Manager"; public static final String CUSTOM_TERMINAL_COMMAND_LABEL = "Custom Terminal Command"; public static final String DEFAULT_HOSTFILE_NONE_LABEL = "Default Hostfile Off (needs restart)"; + public static final String USE_DOCKER_LABEL = "Use Docker"; + public static final String DOCKER_IMAGE_LABEL = "Docker Image"; + private JDialog dialog; private FileFieldPanel fieldViewPanel; private FileFieldPanel ensightPanel; private FileFieldPanel paraViewPanel; + private FileFieldPanel paraViewBatchPanel; private FileFieldPanel openFoamPanel; private IntegerField connectionTries; private IntegerField connectionRefresh; - private IntegerField waitForStopTime; private IntegerField waitForRunTime; private IntegerField scriptRefresh; private IntegerField waiForKillTime; - private IntegerField logWaitTime; private IntegerField interactiveMemory; private IntegerField interactiveTime; @@ -145,31 +152,25 @@ public class PreferencesDialog { private StringField defaultTerminal; private StringField defaultFileManager; - private StringField defaultFileOpener; private JCheckBox defaultHostFile; private JCheckBox hideEmptyPatches; + private JCheckBox hideProcessorPatches; + private JCheckBox hideProcessorCyclicPatches; - private IntegerField maxChartRows; private IntegerField maxLogRows; - private final boolean isOS; - private final boolean paraview; - private final boolean fieldview; - private final boolean ensight; - private final boolean hasSolverPreferences; + private JCheckBox useDocker; + private StringField dockerImage; private JLabel errorLabel; private JButton okButton; private JButton openDefaults; private DictDataFolder dictDataFolder; + private PreferencesBean bean; - public PreferencesDialog(boolean isOS, boolean paraview, boolean fieldview, boolean ensight, boolean hasSolverPreferences, DictDataFolder dictDataFolder) { - this.isOS = isOS; - this.paraview = paraview;// HELYX-OS or Windows OS - this.fieldview = fieldview;// HELYX-SAS and HELYX - this.ensight = ensight;// HELYX - this.hasSolverPreferences = hasSolverPreferences; + public PreferencesDialog(PreferencesBean bean, DictDataFolder dictDataFolder) { + this.bean = bean; this.dictDataFolder = dictDataFolder; initDialog(); @@ -188,7 +189,12 @@ public class PreferencesDialog { dialog = new JDialog(UiUtil.getActiveWindow(), "Preferences", ModalityType.APPLICATION_MODAL); dialog.getContentPane().setLayout(new BorderLayout()); dialog.getContentPane().add(mainPanel); - dialog.setSize(800, 600); + + int dialogOffset = 150; + int pathSize = ROW_SIZE + (bean.isParaview() ? ROW_SIZE : 0) + (bean.isEnsight() ? ROW_SIZE : 0) + (bean.isFieldview() ? ROW_SIZE : 0); + int size = dialogOffset + pathSize + (bean.isBatchPreferences() ? ROW_SIZE * 5 : 0) + (bean.isVtkPreferences() ? ROW_SIZE * 3 : 0) + (bean.isMiscPreferences() ? ROW_SIZE * 8 : 0); + + dialog.setSize(800, size); dialog.setLocationRelativeTo(null); dialog.setName("PreferencesDialog"); dialog.getRootPane().setDefaultButton(okButton); @@ -222,22 +228,32 @@ public class PreferencesDialog { */ public void load() { - loadPathProperties(); - loadBatchProperties(); - loadVTKProperties(); - loadMiscProperties(); - + if (bean.isPathPreferences()) { + loadPathProperties(); + } + if (bean.isBatchPreferences()) { + loadBatchProperties(); + } + if (bean.isVtkPreferences()) { + loadVTKProperties(); + } + if (bean.isMiscPreferences()) { + loadMiscProperties(); + } } private void loadPathProperties() { openFoamPanel.setFile(PrefUtil.getOpenFoamEntry()); - if (paraview) { + if (bean.isParaview()) { paraViewPanel.setFile(PrefUtil.getParaViewEntry()); } - if (fieldview) { + if (bean.isParaviewBatch()) { + paraViewBatchPanel.setFile(PrefUtil.getParaViewBatchEntry()); + } + if (bean.isFieldview()) { fieldViewPanel.setFile(PrefUtil.getFieldViewEntry()); } - if (ensight) { + if (bean.isEnsight()) { ensightPanel.setFile(PrefUtil.getEnsightEntry()); } @@ -274,7 +290,16 @@ public class PreferencesDialog { defaultHostFile.setSelected(PrefUtil.getBoolean(PrefUtil.DEFAULT_HOSTFILE_NONE)); } hideEmptyPatches.setSelected(PrefUtil.getBoolean(PrefUtil.HIDE_EMPTY_PATCHES)); + hideProcessorPatches.setSelected(PrefUtil.getBoolean(PrefUtil.HIDE_PROCESSOR_PATCHES)); + hideProcessorCyclicPatches.setSelected(PrefUtil.getBoolean(PrefUtil.HIDE_PROCESSOR_CYCLIC_PATCHES)); maxLogRows.setIntValue(PrefUtil.getInt(PrefUtil.BATCH_MONITOR_DIALOG_MAX_ROW)); + + useDocker.setSelected(PrefUtil.getBoolean(PrefUtil.USE_DOCKER)); + dockerImage.setStringValue(PrefUtil.getString(PrefUtil.DOCKER_IMAGE)); + + if(useDocker.isSelected() && Util.isWindows()){ + Util.setScriptStyle(ScriptStyle.LINUX); + } } /* @@ -283,21 +308,33 @@ public class PreferencesDialog { // public for test purposes only public void save() { - savePathProperties(); - saveBatchProperties(); - saveVTKProperties(); - saveMiscProperties(); + if (bean.isPathPreferences()) { + savePathProperties(); + } + if (bean.isBatchPreferences()) { + saveBatchProperties(); + } + if (bean.isVtkPreferences()) { + saveVTKProperties(); + } + if (bean.isMiscPreferences()) { + saveMiscProperties(); + } + } private void savePathProperties() { PrefUtil.setOpenFoamEntry(openFoamPanel.getFile()); - if (paraview) { + if (bean.isParaview()) { PrefUtil.setParaViewEntry(paraViewPanel.getFile()); } - if (fieldview) { + if (bean.isParaviewBatch()) { + PrefUtil.setParaViewBatchEntry(paraViewBatchPanel.getFile()); + } + if (bean.isFieldview()) { PrefUtil.setFieldViewEntry(fieldViewPanel.getFile()); } - if (ensight) { + if (bean.isEnsight()) { PrefUtil.setEnsightEntry(ensightPanel.getFile()); } } @@ -324,7 +361,18 @@ public class PreferencesDialog { PrefUtil.putBoolean(PrefUtil.DEFAULT_HOSTFILE_NONE, defaultHostFile.isSelected()); } PrefUtil.putBoolean(PrefUtil.HIDE_EMPTY_PATCHES, hideEmptyPatches.isSelected()); + PrefUtil.putBoolean(PrefUtil.HIDE_PROCESSOR_PATCHES, hideProcessorPatches.isSelected()); + PrefUtil.putBoolean(PrefUtil.HIDE_PROCESSOR_CYCLIC_PATCHES, hideProcessorCyclicPatches.isSelected()); PrefUtil.putInt(PrefUtil.BATCH_MONITOR_DIALOG_MAX_ROW, maxLogRows.getIntValue()); + + PrefUtil.putBoolean(PrefUtil.USE_DOCKER, useDocker.isSelected()); + PrefUtil.putString(PrefUtil.DOCKER_IMAGE, dockerImage.getStringValue()); + + if(useDocker.isSelected() && Util.isWindows()){ + Util.setScriptStyle(ScriptStyle.LINUX); + } else { + Util.initScriptStyle(); + } } /* @@ -338,12 +386,18 @@ public class PreferencesDialog { JPanel miscPanel = createMiscPanel(); PanelBuilder builder = new PanelBuilder(); - builder.addComponent(pathsPanel); - if (hasSolverPreferences) { + if (bean.isPathPreferences()) { + builder.addComponent(pathsPanel); + } + if (bean.isBatchPreferences()) { builder.addComponent(batchPanel); } - builder.addComponent(vtkPanel); - builder.addComponent(miscPanel); + if (bean.isVtkPreferences()) { + builder.addComponent(vtkPanel); + } + if (bean.isMiscPreferences()) { + builder.addComponent(miscPanel); + } JPanel container = new JPanel(new BorderLayout()); container.setOpaque(false); @@ -358,13 +412,13 @@ public class PreferencesDialog { private JPanel createPathsPanel() { String ofPrompt = ""; if (Util.isWindows()) { - if (isOS) { + if (bean.isOS()) { ofPrompt = String.format(OPENFOAM_TOOLTIP_WINDOWS_OS, ApplicationInfo.getVendor()); } else { ofPrompt = String.format(OPENFOAM_TOOLTIP_WINDOWS, ApplicationInfo.getVendor()); } } else { - if (isOS) { + if (bean.isOS()) { ofPrompt = String.format(OPENFOAM_TOOLTIP_LINUX_OS, ApplicationInfo.getVendor()); } else { ofPrompt = String.format(OPENFOAM_TOOLTIP_LINUX, ApplicationInfo.getVendor()); @@ -377,16 +431,25 @@ public class PreferencesDialog { addResettableComponent(pathBuilder, CORE_FOLDER_LABEL, openFoamPanel = ComponentsFactory.fileField(SelectionMode.DIRS_ONLY, ofTooltip, ofPrompt, true), PrefUtil.OPENFOAM_KEY); openFoamPanel.addPropertyChangeListener(new UpdateErrorLabelListener()); - if (paraview) { + if (bean.isParaview()) { String pvPrompt = Util.isWindows() ? PARAVIEW_TOOLTIP_WINDOWS : PARAVIEW_TOOLTIP_LINUX; String pvTooltip = PREFIX_FOR_TOOLTIP + pvPrompt; paraViewPanel = ComponentsFactory.fileField(SelectionMode.FILES_ONLY, pvTooltip, pvPrompt, true); paraViewPanel.addPropertyChangeListener(new UpdateErrorLabelListener()); - addResettableComponent(pathBuilder, PARA_VIEW_EXECUTABLE_LABEL, paraViewPanel, PrefUtil.PARAVIEW_KEY); + addResettableComponent(pathBuilder, PARAVIEW_EXECUTABLE_LABEL, paraViewPanel, PrefUtil.PARAVIEW_KEY); } - if (fieldview) { + if (bean.isParaviewBatch()) { + String pvBatchPrompt = Util.isWindows() ? PARAVIEW_BATCH_TOOLTIP_WINDOWS : PARAVIEW_BATCH_TOOLTIP_LINUX; + String pvBatchTooltip = PREFIX_FOR_TOOLTIP + pvBatchPrompt; + + paraViewBatchPanel = ComponentsFactory.fileField(SelectionMode.FILES_ONLY, pvBatchTooltip, pvBatchPrompt, true); + paraViewBatchPanel.addPropertyChangeListener(new UpdateErrorLabelListener()); + addResettableComponent(pathBuilder, PARAVIEW_BATCH_EXECUTABLE_LABEL, paraViewBatchPanel, PrefUtil.PARAVIEW_BATCH_KEY); + } + + if (bean.isFieldview()) { String fvPrompt = Util.isWindows() ? FIELDVIEW_TOOLTIP_WINDOWS : FIELDVIEW_TOOLTIP_LINUX; String fvTooltip = PREFIX_FOR_TOOLTIP + fvPrompt; @@ -394,7 +457,7 @@ public class PreferencesDialog { fieldViewPanel.addPropertyChangeListener(new UpdateErrorLabelListener()); addResettableComponent(pathBuilder, FIELD_VIEW_EXECUTABLE_LABEL, fieldViewPanel, PrefUtil.FIELDVIEW_KEY); } - if (ensight) { + if (bean.isEnsight()) { String fvPrompt = Util.isWindows() ? ENSIGHT_TOOLTIP_WINDOWS : ENSIGHT_TOOLTIP_LINUX; String fvTooltip = PREFIX_FOR_TOOLTIP + fvPrompt; @@ -429,7 +492,7 @@ public class PreferencesDialog { private JPanel createMiscPanel() { PanelBuilder miscBuilder = new PanelBuilder(); - if (Util.isUnix()) { + if (!Util.isWindows()) { addResettableComponent(miscBuilder, CUSTOM_TERMINAL_COMMAND_LABEL, defaultTerminal = stringField(), PrefUtil.HELYX_DEFAULT_TERMINAL); defaultTerminal.setPrompt(TERMINAL_TOOLTIP); @@ -440,7 +503,17 @@ public class PreferencesDialog { defaultHostFile.setToolTipText(DEFAULT_HOSTFILE_TOOLTIP); } addResettableComponent(miscBuilder, HIDE_EMPTY_PATCHES_LABEL, hideEmptyPatches = checkField(), PrefUtil.HIDE_EMPTY_PATCHES); + addResettableComponent(miscBuilder, HIDE_PROCESSOR_PATCHES_LABEL, hideProcessorPatches = checkField(), PrefUtil.HIDE_PROCESSOR_PATCHES); + addResettableComponent(miscBuilder, HIDE_PROCESSOR_CYCLIC_PATCHES_LABEL, hideProcessorCyclicPatches = checkField(), PrefUtil.HIDE_PROCESSOR_CYCLIC_PATCHES); addResettableComponent(miscBuilder, MAX_LOG_LINES_LABEL, maxLogRows = intField(), PrefUtil.BATCH_MONITOR_DIALOG_MAX_ROW); + + useDocker = checkField(); + dockerImage = stringField(false, false); + + if(!Util.isWindows()){ + addResettableComponent(miscBuilder, USE_DOCKER_LABEL, useDocker, PrefUtil.USE_DOCKER); + addResettableComponent(miscBuilder, DOCKER_IMAGE_LABEL, dockerImage, PrefUtil.DOCKER_IMAGE); + } openDefaults = new JButton(new AbstractAction("Show Files") { @Override @@ -454,7 +527,7 @@ public class PreferencesDialog { @Override public void actionPerformed(ActionEvent e) { try { - FileUtils.forceDeleteOnExit(new File(ApplicationInfo.getHome(), "dictData")); + FileUtils.forceDeleteOnExit(new File(new File(ApplicationInfo.getHome(), ApplicationInfo.getVersion()), "dictData")); } catch (IOException e1) { } finally { JOptionPane.showMessageDialog(UiUtil.getActiveWindow(), "Restart " + ApplicationInfo.getName() + " to complete this action."); @@ -489,7 +562,7 @@ public class PreferencesDialog { } else if (compToAdd instanceof DoubleField) { resetDoubleField(compToAdd, value); } else if (compToAdd instanceof FileFieldPanel) { - if(key.equals(PrefUtil.OPENFOAM_KEY)){ + if (key.equals(PrefUtil.OPENFOAM_KEY)) { resetOpenFoamFileField(compToAdd); } else { resetFileField(compToAdd); @@ -502,7 +575,7 @@ public class PreferencesDialog { } private void resetOpenFoamFileField(final JComponent compToAdd) { - File[] openFoamDir = OpenFOAMEnvironment.getOpenFoamDir(); + File[] openFoamDir = (bean.isOS() && Util.isUnix()) ? OpenFOAMEnvironment.getOpenFoamDirOS_onUnix() : OpenFOAMEnvironment.getOpenFoamDir(); if (Util.isVarArgsNotNullAndOfSize(1, openFoamDir)) { ((FileFieldPanel) compToAdd).setFile(openFoamDir[0]); } else { @@ -553,21 +626,28 @@ public class PreferencesDialog { */ private boolean isParaViewOk() { - if (paraview) { + if (bean.isParaview()) { return paraViewPanel.hasExistingFile(); } return true; } + private boolean isParaViewBatchOk() { + if (bean.isParaviewBatch()) { + return paraViewBatchPanel.hasExistingFile(); + } + return true; + } + private boolean isEnsightOk() { - if (ensight) { + if (bean.isEnsight()) { return ensightPanel.hasExistingFile(); } return true; } private boolean isFieldViewOk() { - if (fieldview) { + if (bean.isFieldview()) { return fieldViewPanel.hasExistingFile(); } return true; diff --git a/src/eu/engys/gui/RecentItems.java b/src/eu/engys/gui/RecentItems.java index 7ff76ce..51bd57d 100644 --- a/src/eu/engys/gui/RecentItems.java +++ b/src/eu/engys/gui/RecentItems.java @@ -1,27 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui; import java.io.File; diff --git a/src/eu/engys/gui/ReloadableListModel.java b/src/eu/engys/gui/ReloadableListModel.java new file mode 100644 index 0000000..ed81fbd --- /dev/null +++ b/src/eu/engys/gui/ReloadableListModel.java @@ -0,0 +1,66 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.gui; + +import javax.swing.ListModel; +import javax.swing.event.ListDataListener; + +public abstract class ReloadableListModel implements ListModel { + + protected String[] elements; + + public abstract void reload(); + + @Override + public int getSize() { + return elements.length; + } + + @Override + public String getElementAt(int index) { + return elements[index]; + } + + public int getIndexOf(String e) { + if (e == null) + return -1; + for (int i = 0; i < elements.length; i++) { + if (elements[i].equals(e)) { + return i; + } + } + return -1; + } + + @Override + public void addListDataListener(ListDataListener l) { + } + + @Override + public void removeListDataListener(ListDataListener l) { + } + + +} diff --git a/src/eu/engys/gui/StandardScriptFactory.java b/src/eu/engys/gui/StandardScriptFactory.java index 75d3409..3b89902 100644 --- a/src/eu/engys/gui/StandardScriptFactory.java +++ b/src/eu/engys/gui/StandardScriptFactory.java @@ -1,29 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui; import static eu.engys.core.OpenFOAMEnvironment.loadEnvironment; @@ -31,6 +29,8 @@ import static eu.engys.core.OpenFOAMEnvironment.printHeader; import static eu.engys.core.OpenFOAMEnvironment.printVariables; import static eu.engys.util.OpenFOAMCommands.CHECK_MESH_PARALLEL; import static eu.engys.util.OpenFOAMCommands.CHECK_MESH_SERIAL; +import static eu.engys.util.OpenFOAMCommands.POTENTIAL_FOAM_PARALLEL; +import static eu.engys.util.OpenFOAMCommands.POTENTIAL_FOAM_SERIAL; import static eu.engys.util.OpenFOAMCommands.SET_FIELDS_PARALLEL; import static eu.engys.util.OpenFOAMCommands.SET_FIELDS_SERIAL; @@ -44,16 +44,19 @@ import eu.engys.core.project.Model; public class StandardScriptFactory extends DefaultScriptFactory { - @Inject + public static final String WRAPPER_PARALLEL_WORKS = "Parallel Works"; + + @Inject public StandardScriptFactory(Model model) { - super(model); + super(model); } - protected boolean performBlockMesh() { - return true; - } - - @Override + @Override + protected boolean performBlockMesh() { + return true; + } + + @Override protected List getSerialCheckMeshScript() { ScriptBuilder sb = new ScriptBuilder(); printHeader(sb, CHECK_MESH); @@ -76,7 +79,7 @@ public class StandardScriptFactory extends DefaultScriptFactory { sb.newLine(); return sb.getLines(); } - + @Override protected List getSerialInitialiseScript() { ScriptBuilder sb = new ScriptBuilder(); @@ -84,7 +87,8 @@ public class StandardScriptFactory extends DefaultScriptFactory { printVariables(sb); loadEnvironment(sb); sb.newLine(); - sb.append(SET_FIELDS_SERIAL()); + sb.appendIf(model.getFields().hasCellSetInitialisationField(), SET_FIELDS_SERIAL()); + sb.appendIf(model.getFields().hasPotentialFlowInitialisationField(), POTENTIAL_FOAM_SERIAL(model.getFields().hasInitialiseUBCsField())); sb.newLine(); return sb.getLines(); } @@ -96,9 +100,10 @@ public class StandardScriptFactory extends DefaultScriptFactory { printVariables(sb); loadEnvironment(sb); sb.newLine(); - sb.append(SET_FIELDS_PARALLEL()); + sb.appendIf(model.getFields().hasCellSetInitialisationField(), SET_FIELDS_PARALLEL()); + sb.appendIf(model.getFields().hasPotentialFlowInitialisationField(), POTENTIAL_FOAM_PARALLEL(model.getFields().hasInitialiseUBCsField())); sb.newLine(); return sb.getLines(); } - + } diff --git a/src/eu/engys/gui/StartPanel.java b/src/eu/engys/gui/StartPanel.java index c8064fd..1ba0f4b 100644 --- a/src/eu/engys/gui/StartPanel.java +++ b/src/eu/engys/gui/StartPanel.java @@ -1,33 +1,37 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui; +import static eu.engys.gui.view.View.EXIT; +import static eu.engys.gui.view.View.NEW_CASE; +import static eu.engys.gui.view.View.OPEN_CASE; +import static eu.engys.util.SystemEnv.LICENSE_ERROR_MESSAGE; + import java.awt.BorderLayout; import java.awt.Color; +import java.awt.Component; import java.awt.Dimension; import java.awt.Graphics; import java.awt.GridBagConstraints; @@ -48,8 +52,11 @@ import javax.swing.JButton; import javax.swing.JComponent; import javax.swing.JLabel; import javax.swing.JPanel; +import javax.swing.SwingUtilities; import eu.engys.application.Application; +import eu.engys.core.controller.Controller.OpenMode; +import eu.engys.core.controller.OpenOptions; import eu.engys.core.presentation.ActionManager; import eu.engys.gui.view.View; import eu.engys.util.ApplicationInfo; @@ -75,15 +82,19 @@ public class StartPanel extends JPanel { private List createActions() { List actions = new ArrayList(); - - actions.add(ActionManager.getInstance().get("application.create")); - actions.add(ActionManager.getInstance().get("application.open")); - actions.add(ActionManager.getInstance().get("application.exit")); + if(ActionManager.getInstance().contains(NEW_CASE)){ + actions.add(ActionManager.getInstance().get(NEW_CASE)); + } + actions.add(ActionManager.getInstance().get(OPEN_CASE)); + + if(ActionManager.getInstance().contains(EXIT)){ + actions.add(ActionManager.getInstance().get(EXIT)); + } return actions; } - private void layoutComponents() { + public void layoutComponents() { JPanel topPanel = new JPanel(new BorderLayout()); JPanel bottomPanel = new JPanel(new BorderLayout()); @@ -147,7 +158,8 @@ public class StartPanel extends JPanel { @Override public void actionPerformed(ActionEvent e) { if (view.getController().allowActionsOnRunning(false)) { - view.getController().openCase(new File(item)); + SwingUtilities.getWindowAncestor((Component) e.getSource()).dispose(); + view.getController().openCase(OpenOptions.file(new File(item), OpenMode.CHECK_FOLDER_ASK_USER)); } } })); @@ -170,7 +182,7 @@ public class StartPanel extends JPanel { } private JLabel getDemoLabel() { - String licenseErrorMessage = System.getProperty("license.error.message", null); + String licenseErrorMessage = System.getProperty(LICENSE_ERROR_MESSAGE, null); if (licenseErrorMessage != null && !licenseErrorMessage.isEmpty()) { JLabel label = new JLabel("" + licenseErrorMessage + "
" + DEMO_START + ""); label.setForeground(new Color(0xff0000)); diff --git a/src/eu/engys/gui/casesetup/CaseSetup.java b/src/eu/engys/gui/casesetup/CaseSetup.java index fdaf894..f894a59 100644 --- a/src/eu/engys/gui/casesetup/CaseSetup.java +++ b/src/eu/engys/gui/casesetup/CaseSetup.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.casesetup; diff --git a/src/eu/engys/gui/casesetup/CaseSetup3DElement.java b/src/eu/engys/gui/casesetup/CaseSetup3DElement.java index 5e79917..635b864 100644 --- a/src/eu/engys/gui/casesetup/CaseSetup3DElement.java +++ b/src/eu/engys/gui/casesetup/CaseSetup3DElement.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.casesetup; diff --git a/src/eu/engys/gui/casesetup/CaseSetupElement.java b/src/eu/engys/gui/casesetup/CaseSetupElement.java index fd761d3..5b23778 100644 --- a/src/eu/engys/gui/casesetup/CaseSetupElement.java +++ b/src/eu/engys/gui/casesetup/CaseSetupElement.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.casesetup; @@ -74,7 +73,7 @@ public class CaseSetupElement extends AbstractViewElement { @Override protected Set getModulePanels() { - Set allPanels = new HashSet(); + Set allPanels = new HashSet<>(); for (ModulePanel panel : ModulesUtil.getCaseSetupPanels(modules)) { allPanels.add((GUIPanel) panel); } @@ -104,13 +103,13 @@ public class CaseSetupElement extends AbstractViewElement { @Override public void load(Model model) { super.load(model); - ModulesUtil.updateTree(modules, getPanel()); + ModulesUtil.updateCaseSetupTree(modules, getPanel()); } @Override public void changeObserved(Object arg) { if (arg instanceof State) { - ModulesUtil.updateTree(modules, getPanel()); + ModulesUtil.updateCaseSetupTree(modules, getPanel()); getActions().update(); } super.changeObserved(arg); diff --git a/src/eu/engys/gui/casesetup/DictionaryTableAndChartPanel.java b/src/eu/engys/gui/casesetup/DictionaryTableAndChartPanel.java new file mode 100644 index 0000000..4ad7fa6 --- /dev/null +++ b/src/eu/engys/gui/casesetup/DictionaryTableAndChartPanel.java @@ -0,0 +1,209 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.gui.casesetup; + +import static eu.engys.core.report.excel.CSVUtils.IMPORT_CSV_ICON; +import static eu.engys.core.report.excel.CSVUtils.IMPORT_CSV_LABEL; +import static eu.engys.core.report.excel.CSVUtils.IMPORT_CSV_TOOLTIP; +import static eu.engys.core.report.excel.ExcelUtils.IMPORT_XLS_ICON; +import static eu.engys.core.report.excel.ExcelUtils.IMPORT_XLS_LABEL; +import static eu.engys.core.report.excel.ExcelUtils.IMPORT_XLS_TOOLTIP; + +import java.awt.BorderLayout; +import java.awt.event.ActionEvent; +import java.io.File; +import java.io.FileInputStream; + +import javax.swing.AbstractButton; +import javax.swing.Box; +import javax.swing.Icon; +import javax.swing.JComponent; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.JToolBar; + +import org.apache.commons.io.IOUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import eu.engys.core.dictionary.Dictionary; +import eu.engys.core.report.excel.CSVUtils; +import eu.engys.core.report.excel.ExcelUtils; +import eu.engys.util.filechooser.AbstractFileChooser.ReturnValue; +import eu.engys.util.filechooser.HelyxFileChooser; +import eu.engys.util.filechooser.util.SelectionMode; +import eu.engys.util.ui.ExecUtil; +import eu.engys.util.ui.FileChooserUtils; +import eu.engys.util.ui.ResourcesUtil; +import eu.engys.util.ui.UiUtil; +import eu.engys.util.ui.ViewAction; + +public abstract class DictionaryTableAndChartPanel extends TableAndChartPanel { + + private static final Logger logger = LoggerFactory.getLogger(DictionaryTableAndChartPanel.class); + + public static final String IMPORT_OF_LABEL = "import.of.button"; + public static final String IMPORT_OF_TOOLTIP = "Import data from an OpenFoam table data file"; + public static final Icon IMPORT_OF_ICON = ResourcesUtil.getIcon("file.openfoam"); + + protected Double[][] data; + private String[] columnNames; + + public DictionaryTableAndChartPanel(String title, String name, String domainAxisLabel, String rangeAxisLabel, boolean editable, String[] columnNames) { + super(title, name, domainAxisLabel, rangeAxisLabel, editable); + this.columnNames = columnNames; + } + + @Override + protected JComponent createTableButtons() { + JToolBar rightPanel = UiUtil.getToolbarWrapped(); + + rightPanel.add(Box.createHorizontalGlue()); + AbstractButton importOFButton = UiUtil.createToolBarButton(new ViewAction(IMPORT_OF_ICON, IMPORT_OF_TOOLTIP) { + @Override + public void actionPerformed(ActionEvent e) { + importFromOpenFoam(); + } + }); + rightPanel.add(importOFButton); + importOFButton.setName(IMPORT_OF_LABEL); + + AbstractButton importXLSButton = UiUtil.createToolBarButton(new ViewAction(IMPORT_XLS_ICON, IMPORT_XLS_TOOLTIP) { + @Override + public void actionPerformed(ActionEvent e) { + importFromExcel(); + } + }); + importXLSButton.setName(IMPORT_XLS_LABEL); + rightPanel.add(importXLSButton); + + AbstractButton importCSVButton = UiUtil.createToolBarButton(new ViewAction(IMPORT_CSV_ICON, IMPORT_CSV_TOOLTIP) { + @Override + public void actionPerformed(ActionEvent e) { + importFromCSV(); + } + }); + importCSVButton.setName(IMPORT_CSV_LABEL); + rightPanel.add(importCSVButton); + + JPanel p = new JPanel(new BorderLayout()); + p.add(super.createTableButtons(), BorderLayout.CENTER); + p.add(rightPanel, BorderLayout.EAST); + + return p; + } + + private boolean checkDataStructure() { + String msg = null; + if (data == null || data.length == 0) { + msg = "No data read."; + } else if (data[0] == null || data[0].length == 0) { + msg = "No data read."; + } else if (data[0].length <= columnNames.length) { + msg = "Too few columns of data read."; + } else if (data[0].length > columnNames.length + 1) { + msg = "Too much columns of data read: only " + (columnNames.length + 1) + " are taken."; + } + if (msg != null) { + JOptionPane.showMessageDialog(dialog, msg, "Import Error", JOptionPane.WARNING_MESSAGE); + return false; + } + return true; + } + + private void importFromOpenFoam() { + HelyxFileChooser chooser = new HelyxFileChooser(); + chooser.setParent(dialog); + chooser.setSelectionMode(SelectionMode.FILES_ONLY); + + ReturnValue retVal = chooser.showOpenDialog(); + if (retVal.isApprove()) { + File file = chooser.getSelectedFile(); + + try (FileInputStream is = new FileInputStream(file)) { + String data = IOUtils.toString(is); + data = data.trim(); + data = data.replace("\n", Dictionary.SPACER); + data = data.replace(";", Dictionary.SPACER).trim(); + data = data.replace("(", Dictionary.SPACER + "(" + Dictionary.SPACER); + data = data.replace(")", Dictionary.SPACER + ")" + Dictionary.SPACER); + data = data.replaceAll("\\s+", Dictionary.SPACER).trim(); + + this.data = toObject(data); + + if (checkDataStructure()) { + ExecUtil.invokeLater(new Runnable() { + @Override + public void run() { + loadTableAndChart(); + } + }); + } + } catch (Exception e) { + logger.error("Error reading file", e); + } + } + } + + private void importFromExcel() { + HelyxFileChooser chooser = new HelyxFileChooser(); + chooser.setParent(dialog); + chooser.setSelectionMode(SelectionMode.FILES_ONLY); + + ReturnValue retVal = chooser.showOpenDialog(FileChooserUtils.XLS_FILTER); + if (retVal.isApprove()) { + File file = chooser.getSelectedFile(); + this.data = ExcelUtils.readDoubleMatrix(file, 0,(columnNames.length + 1)); + ExecUtil.invokeLater(new Runnable() { + @Override + public void run() { + loadTableAndChart(); + } + }); + } + } + + private void importFromCSV() { + HelyxFileChooser chooser = new HelyxFileChooser(); + chooser.setParent(dialog); + chooser.setSelectionMode(SelectionMode.FILES_ONLY); + + ReturnValue retVal = chooser.showOpenDialog(FileChooserUtils.CSV_FILTER); + if (retVal.isApprove()) { + File file = chooser.getSelectedFile(); + this.data = CSVUtils.readDoubleMatrix(file, (columnNames.length + 1)); + ExecUtil.invokeLater(new Runnable() { + @Override + public void run() { + loadTableAndChart(); + } + }); + } + } + + protected abstract String toPrimitive(); + + protected abstract Double[][] toObject(String tableData); +} diff --git a/src/eu/engys/gui/casesetup/RuntimeControlsPanel.java b/src/eu/engys/gui/casesetup/RuntimeControlsPanel.java index a44a390..f251bd2 100644 --- a/src/eu/engys/gui/casesetup/RuntimeControlsPanel.java +++ b/src/eu/engys/gui/casesetup/RuntimeControlsPanel.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.casesetup; import static eu.engys.core.project.system.ControlDict.ADJUSTABLE_RUN_TIME_KEY; @@ -93,11 +92,11 @@ public class RuntimeControlsPanel extends DefaultGUIPanel { public static final String WRITE_FORMAT_LABEL = "Write Format"; public static final String PURGE_WRITE_LABEL = "Purge Write"; public static final String WRITE_CONTROL_LABEL = "Write Control"; - public static final String MAX_TIME_STEP_LABEL = "Max Time Step"; + public static final String MAX_TIME_STEP_LABEL = "Max Time Step " + Symbols.S; public static final String MAX_COURANT_ALPHA_LABEL = "Max Courant Alpha"; public static final String MAX_COURANT_NUMBER_LABEL = "Max Courant Number"; public static final String ADJUSTABLE_TIME_STEP_LABEL = "Adjustable Time Step"; - public static final String DELTA_T_LABEL = Symbols.DELTA_T + "(s)"; + public static final String DELTA_T_LABEL = Symbols.DELTA_T + Symbols.S; public static final String END_TIME_LABEL = "End Time"; public static final String START_FROM_LABEL = "Start From"; @@ -325,17 +324,18 @@ public class RuntimeControlsPanel extends DefaultGUIPanel { boolean isSteadyMultiphase = state.isSteady() && state.getMultiphaseModel().isMultiphase(); boolean isSteadyCoupled = state.isSteady() && state.getSolverType().isCoupled(); - if (isTransient || isSteadyMultiphase || isSteadyCoupled) { + boolean okState = isTransient || isSteadyMultiphase || isSteadyCoupled; + if (okState) { deltaT.setEnabled(true); } else { deltaT.setEnabled(false); deltaT.setDoubleValue(1); } - adjustableTime.setEnabled((isTransient || isSteadyMultiphase) && !isSonic(state)); - maxCourantNumber.setEnabled((isTransient || isSteadyMultiphase) && adjustableTime.isSelected()); - maxAlphaCourant.setEnabled((isTransient || isSteadyMultiphase) && adjustableTime.isSelected() && state.getMultiphaseModel().isMultiphase()); - maxTimeStep.setEnabled((isTransient || isSteadyMultiphase) && adjustableTime.isSelected()); + adjustableTime.setEnabled(okState && !isSonic(state)); + maxCourantNumber.setEnabled(okState && adjustableTime.isSelected()); + maxAlphaCourant.setEnabled(okState && adjustableTime.isSelected() && state.getMultiphaseModel().isMultiphase()); + maxTimeStep.setEnabled(okState && adjustableTime.isSelected()); } }); } diff --git a/src/eu/engys/gui/casesetup/StandardSolverSettingsPanel.java b/src/eu/engys/gui/casesetup/StandardSolverSettingsPanel.java new file mode 100644 index 0000000..bf8e08d --- /dev/null +++ b/src/eu/engys/gui/casesetup/StandardSolverSettingsPanel.java @@ -0,0 +1,49 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.gui.casesetup; + +import java.util.Set; + +import javax.inject.Inject; +import javax.swing.JPanel; + +import eu.engys.core.modules.ApplicationModule; +import eu.engys.core.project.Model; +import eu.engys.core.project.state.Table15; +import eu.engys.gui.casesetup.solver.AbstractSolverSettingsPanel; + +public class StandardSolverSettingsPanel extends AbstractSolverSettingsPanel { + + @Inject + public StandardSolverSettingsPanel(Model model, Table15 solversTable, Set modules) { + super(model, solversTable, modules); + } + + @Override + protected JPanel getLimiterPanel() { + return new JPanel(); + } + +} diff --git a/src/eu/engys/gui/casesetup/TableAndChartPanel.java b/src/eu/engys/gui/casesetup/TableAndChartPanel.java new file mode 100644 index 0000000..87404c1 --- /dev/null +++ b/src/eu/engys/gui/casesetup/TableAndChartPanel.java @@ -0,0 +1,374 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.gui.casesetup; + +import java.awt.BorderLayout; +import java.awt.Component; +import java.awt.Dialog.ModalityType; +import java.awt.FlowLayout; +import java.awt.GridLayout; +import java.awt.Insets; +import java.awt.event.ActionEvent; +import java.awt.event.KeyEvent; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; +import java.text.NumberFormat; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.EventObject; +import java.util.List; + +import javax.swing.AbstractAction; +import javax.swing.BorderFactory; +import javax.swing.DefaultCellEditor; +import javax.swing.Icon; +import javax.swing.JButton; +import javax.swing.JComponent; +import javax.swing.JDialog; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JSplitPane; +import javax.swing.JTable; +import javax.swing.JToolBar; +import javax.swing.RowSorter; +import javax.swing.SortOrder; +import javax.swing.event.ListSelectionEvent; +import javax.swing.event.ListSelectionListener; +import javax.swing.event.TableModelEvent; +import javax.swing.event.TableModelListener; +import javax.swing.table.DefaultTableCellRenderer; +import javax.swing.table.DefaultTableModel; +import javax.swing.table.TableCellRenderer; +import javax.swing.table.TableModel; +import javax.swing.table.TableRowSorter; +import javax.swing.text.JTextComponent; + +import eu.engys.core.modules.AbstractChart; +import eu.engys.core.project.system.monitoringfunctionobjects.TimeBlocks; +import eu.engys.util.ui.ComponentsFactory; +import eu.engys.util.ui.CopyPasteSupport; +import eu.engys.util.ui.ResourcesUtil; +import eu.engys.util.ui.UiUtil; +import eu.engys.util.ui.ViewAction; +import eu.engys.util.ui.textfields.DoubleField; + +public abstract class TableAndChartPanel extends JPanel { + + private static final int SIZE = 600; + + private static final String ADD_TOOLTIP = "Add a row to the table"; + private static final String REM_TOOLTIP = "Remove selected rows"; + private static final Icon ADD_ICON = ResourcesUtil.getResourceIcon("eu/engys/resources/images/table_add16.png"); + private static final Icon REM_ICON = ResourcesUtil.getResourceIcon("eu/engys/resources/images/table_delete16.png"); + public static final String ADD_ROW_BUTTON = "add.row.button"; + public static final String REM_ROW_BUTTON = "rem.row.button"; + public static final String OK_BUTTON_LABEL = "OK"; + public static final String CANCEL_BUTTON_LABEL = "Cancel"; + + private JButton okButton; + + private String title; + private String name; + protected JDialog dialog; + + protected JTable table; + protected AbstractChart chart; + + private TableRowSorter sorter; + + private JButton removeButton; + + public TableAndChartPanel(String title, String name, String domainAxisLabel, String rangeAxisLabel, boolean editable) { + super(new BorderLayout()); + this.title = title; + this.name = name; + setName(name); + layoutComponents(domainAxisLabel, rangeAxisLabel, editable); + } + + private void layoutComponents(String domainAxisLabel, String rangeAxisLabel, boolean editable) { + setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); + + JSplitPane splitPane = createSplitPane(); + JPanel topPanel = new JPanel(new BorderLayout()); + JPanel bottomPanel = new JPanel(new BorderLayout()); + + splitPane.setTopComponent(topPanel); + splitPane.setBottomComponent(bottomPanel); + + table = createTable(); + + if (editable) { + JComponent tableButtons = createTableButtons(); + topPanel.add(tableButtons, BorderLayout.NORTH); + } + + chart = createChart(domainAxisLabel, rangeAxisLabel); + + topPanel.add(new JScrollPane(table), BorderLayout.CENTER); + if (chart != null) { + bottomPanel.add(chart.getPanel(), BorderLayout.CENTER); + } + + add(splitPane, BorderLayout.CENTER); + + JPanel buttonsPanel = createDialogButtons(); + bottomPanel.add(buttonsPanel, BorderLayout.SOUTH); + + dialog = createDialog(); + } + + private JDialog createDialog() { + JDialog dialog = new JDialog(UiUtil.getActiveWindow(), title, ModalityType.APPLICATION_MODAL); + dialog.setName(name); + dialog.addWindowListener(new WindowAdapter() { + @Override + public void windowClosing(WindowEvent e) { + handleDialogClose_Cancel(); + } + }); + + dialog.add(this); + dialog.setSize(SIZE, SIZE); + dialog.setLocationRelativeTo(null); + dialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE); + dialog.getRootPane().setDefaultButton(okButton); + return dialog; + + } + + private JSplitPane createSplitPane() { + JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT); + splitPane.setOneTouchExpandable(false); + splitPane.setDividerLocation(SIZE/2); + splitPane.setResizeWeight(0.5); + return splitPane; + } + + private JPanel createDialogButtons() { + JPanel rightButtonsPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); + okButton = new JButton(new AbstractAction("OK") { + + @Override + public void actionPerformed(ActionEvent e) { + handleDialogClose_OK(); + } + }); + JButton cancelButton = new JButton(new AbstractAction(CANCEL_BUTTON_LABEL) { + + @Override + public void actionPerformed(ActionEvent e) { + handleDialogClose_Cancel(); + } + }); + okButton.setName(OK_BUTTON_LABEL); + rightButtonsPanel.add(okButton); + rightButtonsPanel.add(cancelButton); + + JPanel leftButtonsPanel = createLeftButtonsPanel(); + + JPanel buttonsPanel = new JPanel(new GridLayout(1, 2)); + buttonsPanel.add(leftButtonsPanel); + buttonsPanel.add(rightButtonsPanel); + + return buttonsPanel; + } + + protected JPanel createLeftButtonsPanel() { + return new JPanel(); + } + + private JTable createTable() { + JTable table = new JTable() { + public boolean editCellAt(int row, int column, EventObject e) { + boolean result = super.editCellAt(row, column, e); + final Component editor = getEditorComponent(); + if (e instanceof KeyEvent && editor instanceof JTextComponent) { + ((JTextComponent) editor).selectAll(); + } + + return result; + } + + }; + ((DefaultTableCellRenderer) table.getTableHeader().getDefaultRenderer()).setHorizontalAlignment(JLabel.CENTER); + + setupEditors(table); + + CopyPasteSupport.addSupportTo(table); + return table; + } + + protected JComponent createTableButtons() { + JToolBar buttonsPanel = UiUtil.getToolbarWrapped(); + JButton addButton = new JButton(new ViewAction(ADD_ICON, ADD_TOOLTIP) { + @Override + public void actionPerformed(ActionEvent e) { + addRow(); + } + }); + addButton.setName(ADD_ROW_BUTTON); + buttonsPanel.add(addButton); + removeButton = new JButton(new ViewAction(REM_ICON, REM_TOOLTIP) { + + @Override + public void actionPerformed(ActionEvent e) { + removeRows(); + } + }); + buttonsPanel.add(removeButton); + removeButton.setName(REM_ROW_BUTTON); + removeButton.setEnabled(false); + + return buttonsPanel; + } + + private void addRow() { + ((DefaultTableModel) table.getModel()).addRow(getEmptyRowData()); + updateChart(); + } + + protected Object[] getEmptyRowData() { + return new Object[0]; + } + + private void removeRows() { + int[] selectedRow = table.getSelectedRows(); + int[] selectedModelRow = new int[selectedRow.length]; + + for (int i = 0; i < selectedModelRow.length; i++) { + selectedModelRow[i] = table.convertRowIndexToModel(selectedRow[i]); + } + + Arrays.sort(selectedModelRow); + + for (int i = selectedModelRow.length - 1; i >= 0; i--) { + ((DefaultTableModel) table.getModel()).removeRow(selectedModelRow[i]); + updateChart(); + } + } + + protected abstract AbstractChart createChart(String domainAxisLabel, String rangeAxisLabel); + + protected abstract TableModel createTableModel(); + + private void setupEditors(JTable table) { + final DoubleField doubleTextField = ComponentsFactory.doubleField(); + doubleTextField.setMargin(new Insets(0, 0, 0, 0)); + + DefaultCellEditor doubleEditor = new DefaultCellEditor(doubleTextField) { + @Override + public Object getCellEditorValue() { + try { + return Double.valueOf(Double.parseDouble((String) super.getCellEditorValue())); + } catch (NumberFormatException e) { + return Double.valueOf(doubleTextField.getDoubleValue()); + } + } + }; + table.setDefaultEditor(Double.class, doubleEditor); + + final TableCellRenderer r = table.getDefaultRenderer(Double.class); + table.setDefaultRenderer(Double.class, new TableCellRenderer() { + private NumberFormat formatter; + + { + formatter = DoubleField.getFormatForDISPLAY(10); + } + + @Override + public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { + JLabel label = (JLabel) r.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); + if (value instanceof Double) { + label.setText(formatter.format(value)); + } + return label; + } + }); + + } + + protected void updateChart() { + if (chart != null) { + chart.clear(); + chart.addToDataSet(convertTableDataToTimeBlocks()); + } + }; + + protected abstract TimeBlocks convertTableDataToTimeBlocks(); + + protected void loadTableAndChart() { + TableModel tableModel = createTableModel(); + tableModel.addTableModelListener(new TableModelListener() { + @Override + public void tableChanged(TableModelEvent e) { + if (e.getType() == TableModelEvent.UPDATE) { + updateChart(); + sorter.sort(); + } + } + }); + table.getSelectionModel().addListSelectionListener(new ListSelectionListener() { + @Override + public void valueChanged(ListSelectionEvent e) { + if (removeButton != null) { + removeButton.setEnabled(table.getSelectedRowCount() > 0); + } + } + }); + table.setModel(tableModel); + + table.setAutoCreateRowSorter(true); + + sorter = new TableRowSorter<>(table.getModel()); + table.setRowSorter(sorter); + + List sortKeys = new ArrayList<>(); + sortKeys.add(new RowSorter.SortKey(0, SortOrder.ASCENDING)); + sorter.setSortKeys(sortKeys); + + updateChart(); + } + + /** + * public for test purposes only do not call it directly + */ + public abstract void saveOnDialogClose(); + + public void showDialog() { + dialog.setVisible(true); + } + + private void handleDialogClose_Cancel() { + dialog.setVisible(false); + } + + private void handleDialogClose_OK() { + saveOnDialogClose(); + dialog.setVisible(false); + } + +} diff --git a/src/eu/engys/gui/casesetup/actions/DecomposeCaseAction.java b/src/eu/engys/gui/casesetup/actions/DecomposeCaseAction.java deleted file mode 100644 index d0aa40c..0000000 --- a/src/eu/engys/gui/casesetup/actions/DecomposeCaseAction.java +++ /dev/null @@ -1,129 +0,0 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - -package eu.engys.gui.casesetup.actions; - -import static eu.engys.core.project.openFOAMProject.LOG; - -import java.awt.event.ActionEvent; -import java.io.File; -import java.nio.file.Paths; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; - -import javax.swing.Icon; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import eu.engys.core.OpenFOAMEnvironment; -import eu.engys.core.controller.Controller; -import eu.engys.core.controller.actions.RunCommand; -import eu.engys.core.executor.TerminalExecutorMonitor; -import eu.engys.core.project.Model; -import eu.engys.util.IOUtils; -import eu.engys.util.ui.ResourcesUtil; -import eu.engys.util.ui.UiUtil; -import eu.engys.util.ui.ViewAction; - -public class DecomposeCaseAction extends ViewAction { - - private static final Logger logger = LoggerFactory.getLogger(DecomposeCaseAction.class); - - private static final Icon DECOMPOSE_ICON = ResourcesUtil.getIcon("decompose.icon"); - private static final String DECOMPOSE_LABEL = ResourcesUtil.getString("casesetup.decompose.label"); - private static final String DECOMPOSE_TOOLTIP = ResourcesUtil.getString("casesetup.decompose.tooltip"); - - public static final String ACTION_NAME = "Decompose"; - public static final String LOG_NAME = "decomposeCase.log"; - - private Model model; - private Controller controller; - - private boolean shouldUseWithZeroFlag; - - public DecomposeCaseAction(Model model, Controller controller, boolean shouldUseWithZeroFlag) { - super(DECOMPOSE_LABEL, DECOMPOSE_ICON, DECOMPOSE_TOOLTIP); - this.model = model; - this.controller = controller; - this.shouldUseWithZeroFlag = shouldUseWithZeroFlag; - } - - @Override - public void actionPerformed(ActionEvent e) { - if (controller.isDemo()) { - UiUtil.showDemoMessage(); - } else { - if (OpenFOAMEnvironment.isEnvironementLoaded()) { - _actionPerformed(); - } else { - UiUtil.showCoreEnvironmentNotLoadedWarning(); - } - } - } - - private void _actionPerformed() { - DecomposeCasePanel panel = new DecomposeCasePanel(model); - panel.showDialog(); - if (panel.getStatus().isOK()) { - controller.saveCase(model.getProject().getBaseDir()); - decompose(); - } - } - - private void decompose() { - if (model.getProject().isParallel()) { - decomposeParallelCase(); - } else { - decomposeSerialCase(); - } - } - - private void decomposeSerialCase() { - RunCommand command = new DecomposeCase(model, controller, ACTION_NAME, LOG_NAME); - command.beforeExecute(); - command.executeClient(); - } - - private void decomposeParallelCase() { - File logFile = Paths.get(model.getProject().getBaseDir().getAbsolutePath(), LOG, LOG_NAME).toFile(); - - IOUtils.clearFile(logFile); - - TerminalExecutorMonitor terminal = new TerminalExecutorMonitor(logFile); - ExecutorService service = Executors.newSingleThreadExecutor(); - - RunCommand reconstructCase = new ReconstructCase(model, controller, shouldUseWithZeroFlag, ACTION_NAME, LOG_NAME); - reconstructCase.inService(service); - reconstructCase.inTerminal(terminal); - reconstructCase.executeClient(); - - RunCommand decomposeCase = new DecomposeCase(model, controller, ACTION_NAME, LOG_NAME); - decomposeCase.inService(service); - decomposeCase.inTerminal(terminal); - decomposeCase.executeClient(); - } - -} diff --git a/src/eu/engys/gui/casesetup/actions/DefaultCaseSetupActions.java b/src/eu/engys/gui/casesetup/actions/DefaultCaseSetupActions.java index c71bb41..c05017b 100644 --- a/src/eu/engys/gui/casesetup/actions/DefaultCaseSetupActions.java +++ b/src/eu/engys/gui/casesetup/actions/DefaultCaseSetupActions.java @@ -1,70 +1,48 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.casesetup.actions; -import java.awt.Component; -import java.util.List; - -import javax.swing.JToolBar; +import static eu.engys.core.controller.AbstractController.DECOMPOSE; import eu.engys.core.controller.Controller; +import eu.engys.core.presentation.ActionManager; import eu.engys.core.project.Model; import eu.engys.gui.Actions; -import eu.engys.util.ui.UiUtil; +import eu.engys.util.ui.ViewAction; public abstract class DefaultCaseSetupActions implements Actions { - + protected Model model; protected Controller controller; - protected DecomposeCaseAction decomposeCaseAction; + protected ViewAction decomposeCaseAction; public DefaultCaseSetupActions(Model model, Controller controller) { this.model = model; this.controller = controller; - this.decomposeCaseAction = new DecomposeCaseAction(model, controller, shouldUseWithZeroFlag()); + this.decomposeCaseAction = ActionManager.getInstance().get(DECOMPOSE); } - - protected abstract List getToolbarComponents(); - - protected abstract boolean shouldUseWithZeroFlag(); - - @Override - public JToolBar toolbar() { - JToolBar toolbar = UiUtil.getToolbar("view.element.toolbar"); - for (Component c : getToolbarComponents()) { - if (c == null) { - toolbar.addSeparator(); - } else { - toolbar.add(c); - } - } - return toolbar; - } - @Override public void update() { diff --git a/src/eu/engys/gui/casesetup/actions/ReconstructCase.java b/src/eu/engys/gui/casesetup/actions/ReconstructCase.java deleted file mode 100644 index 1b2f07b..0000000 --- a/src/eu/engys/gui/casesetup/actions/ReconstructCase.java +++ /dev/null @@ -1,128 +0,0 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - -package eu.engys.gui.casesetup.actions; - -import static eu.engys.core.OpenFOAMEnvironment.getEnvironment; -import static eu.engys.core.OpenFOAMEnvironment.loadEnvironment; -import static eu.engys.core.OpenFOAMEnvironment.printHeader; -import static eu.engys.core.OpenFOAMEnvironment.printVariables; -import static eu.engys.core.project.openFOAMProject.LOG; -import static eu.engys.util.OpenFOAMCommands.RECONSTRUCT_PAR; -import static eu.engys.util.OpenFOAMCommands.RECONSTRUCT_PAR_ALLREGIONS; -import static eu.engys.util.OpenFOAMCommands.RECONSTRUCT_PAR_MESH; -import static eu.engys.util.OpenFOAMCommands.RECONSTRUCT_PAR_MESH_ALLREGIONS; -import static eu.engys.util.OpenFOAMCommands.RECONSTRUCT_PAR_MESH_CONSTANT; -import static eu.engys.util.OpenFOAMCommands.RECONSTRUCT_PAR_MESH_CONSTANT_ALLREGIONS; - -import java.io.File; -import java.nio.file.Paths; -import java.util.concurrent.Executors; - -import eu.engys.core.controller.Controller; -import eu.engys.core.controller.ScriptBuilder; -import eu.engys.core.controller.actions.AbstractRunCommand; -import eu.engys.core.executor.Executor; -import eu.engys.core.executor.TerminalExecutorMonitor; -import eu.engys.core.project.Model; -import eu.engys.util.IOUtils; -import eu.engys.util.Util; - -public class ReconstructCase extends AbstractRunCommand { - - private static final String RECONSTRUCT_CASE_RUN = "reconstructCase.run"; - private static final String RECONSTRUCT_CASE_BAT = "reconstructCase.bat"; - - private String actionName; - private String logName; - private File logFile; - private boolean shouldUseWithZeroFlag; - - public ReconstructCase(Model model, Controller controller, boolean shouldUseWithZeroFlag, String actionName, String logName) { - super(model, controller); - this.shouldUseWithZeroFlag = shouldUseWithZeroFlag; - this.actionName = actionName; - this.logName = logName; - this.logFile = Paths.get(model.getProject().getBaseDir().getAbsolutePath(), LOG, logName).toFile(); - } - - @Override - public void executeClient() { - File script = getScript(); - File baseDir = model.getProject().getBaseDir(); - - if (terminal == null) { - this.terminal = new TerminalExecutorMonitor(logFile); - } - if (service == null) { - this.service = Executors.newSingleThreadExecutor(); - } - - this.executor = Executor.script(script).description(actionName).inFolder(baseDir).inTerminal(terminal).inService(service).env(getEnvironment(model, logName)); - executor.exec(); - } - - private File getScript() { - File file = new File(model.getProject().getBaseDir(), Util.isWindows() ? RECONSTRUCT_CASE_BAT : RECONSTRUCT_CASE_RUN); - ScriptBuilder sb = new ScriptBuilder(); - writeScript(sb); - IOUtils.writeLinesToFile(file, sb.getLines()); - file.setExecutable(true); - return file; - } - - private void writeScript(ScriptBuilder sb) { - printHeader(sb, actionName.toUpperCase()); - printVariables(sb); - loadEnvironment(sb); - writeCommand(sb); - } - - private void writeCommand(ScriptBuilder sb) { - boolean meshOnZero = model.getProject().isMeshOnZero(); - - if (meshOnZero) { - if (model.getProject().getZeroFolder().hasRegions()) { - sb.append(RECONSTRUCT_PAR_MESH_ALLREGIONS()); - } else { - sb.append(RECONSTRUCT_PAR_MESH()); - } - } else { - if (model.getProject().getZeroFolder().hasRegions()) { - sb.append(RECONSTRUCT_PAR_MESH_CONSTANT_ALLREGIONS()); - } else { - sb.append(RECONSTRUCT_PAR_MESH_CONSTANT()); - } - } - - if (model.getProject().getZeroFolder().hasRegions()) { - sb.append(RECONSTRUCT_PAR_ALLREGIONS(shouldUseWithZeroFlag)); - } else { - sb.append(RECONSTRUCT_PAR(shouldUseWithZeroFlag)); - } - - } - -} diff --git a/src/eu/engys/gui/casesetup/actions/StandardCaseSetupActions.java b/src/eu/engys/gui/casesetup/actions/StandardCaseSetupActions.java index 15ac948..ff7f0d1 100644 --- a/src/eu/engys/gui/casesetup/actions/StandardCaseSetupActions.java +++ b/src/eu/engys/gui/casesetup/actions/StandardCaseSetupActions.java @@ -1,58 +1,50 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.casesetup.actions; import static eu.engys.util.ui.UiUtil.createToolBarButton; -import java.awt.Component; -import java.util.ArrayList; -import java.util.List; - import javax.inject.Inject; +import javax.swing.JToolBar; import eu.engys.core.controller.Controller; import eu.engys.core.project.Model; -import eu.engys.util.progress.ProgressMonitor; +import eu.engys.util.ui.UiUtil; public class StandardCaseSetupActions extends DefaultCaseSetupActions { @Inject - public StandardCaseSetupActions(Model model, Controller controller, ProgressMonitor monitor) { + public StandardCaseSetupActions(Model model, Controller controller) { super(model, controller); } @Override - protected List getToolbarComponents() { - List components = new ArrayList<>(); - components.add(createToolBarButton(decomposeCaseAction)); - return components; - } - - @Override - protected boolean shouldUseWithZeroFlag() { - return true; + public JToolBar toolbar() { + JToolBar toolbar = UiUtil.getToolbarWrapped(TOOLBAR_NAME); + toolbar.add(createToolBarButton(decomposeCaseAction)); +// toolbar.add(Box.createHorizontalGlue()); + return toolbar; } } diff --git a/src/eu/engys/gui/casesetup/boundaryconditions/AbstractInterpolationTable.java b/src/eu/engys/gui/casesetup/boundaryconditions/AbstractInterpolationTable.java deleted file mode 100644 index 00b3ac9..0000000 --- a/src/eu/engys/gui/casesetup/boundaryconditions/AbstractInterpolationTable.java +++ /dev/null @@ -1,405 +0,0 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - -package eu.engys.gui.casesetup.boundaryconditions; - -import static eu.engys.util.RegexpUtils.CLOSED_BRACKET; -import static eu.engys.util.RegexpUtils.DOUBLE; -import static eu.engys.util.RegexpUtils.OPEN_BRACKET; -import static eu.engys.util.RegexpUtils.POINT; -import static eu.engys.util.RegexpUtils.SPACES; - -import java.awt.BorderLayout; -import java.awt.Component; -import java.awt.Dialog.ModalityType; -import java.awt.FlowLayout; -import java.awt.Insets; -import java.awt.event.ActionEvent; -import java.awt.event.KeyEvent; -import java.awt.event.WindowAdapter; -import java.awt.event.WindowEvent; -import java.text.NumberFormat; -import java.util.ArrayList; -import java.util.EventObject; -import java.util.List; -import java.util.regex.Matcher; -import java.util.regex.Pattern; -import java.util.regex.PatternSyntaxException; - -import javax.swing.AbstractAction; -import javax.swing.BorderFactory; -import javax.swing.DefaultCellEditor; -import javax.swing.JButton; -import javax.swing.JDialog; -import javax.swing.JLabel; -import javax.swing.JPanel; -import javax.swing.JScrollPane; -import javax.swing.JSplitPane; -import javax.swing.JTable; -import javax.swing.event.ListSelectionEvent; -import javax.swing.event.ListSelectionListener; -import javax.swing.event.TableModelEvent; -import javax.swing.event.TableModelListener; -import javax.swing.table.DefaultTableCellRenderer; -import javax.swing.table.DefaultTableModel; -import javax.swing.table.TableCellRenderer; -import javax.swing.text.JTextComponent; - -import eu.engys.core.project.system.monitoringfunctionobjects.TimeBlock; -import eu.engys.core.project.system.monitoringfunctionobjects.TimeBlocks; -import eu.engys.gui.solver.postprocessing.data.DoubleTimeBlockUnit; -import eu.engys.util.ui.ComponentsFactory; -import eu.engys.util.ui.CopyPasteSupport; -import eu.engys.util.ui.UiUtil; -import eu.engys.util.ui.textfields.DoubleField; - -public abstract class AbstractInterpolationTable extends JPanel { - - private static final String VALUE_VAR = "Value"; - private static final String Z_VAR = "Z"; - private static final String Y_VAR = "Y"; - private static final String X_VAR = "X"; - private static final String VECTOR_PATTERN = OPEN_BRACKET + SPACES + DOUBLE + SPACES + POINT + SPACES + CLOSED_BRACKET; - private static final String SCALAR_PATTERN = OPEN_BRACKET + SPACES + DOUBLE + SPACES + DOUBLE + SPACES + CLOSED_BRACKET; - - private JTable table; - private DefaultTableModel tableModel; - private InterpolationChartPanel chart; - protected String[] columnNames; - private JButton removeButton; - private JSplitPane splitPane; - private JPanel topPanel; - private JPanel bottomPanel; - private JDialog dialog; - private JButton okButton; - protected String[] names; - - public AbstractInterpolationTable(String[] names) { - super(new BorderLayout()); - this.names = names; - setName("interpolation.table"); - setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); - setupColumnNames(); - layoutComponents(); - } - - public abstract void load(); - - public boolean isVector() { - return names.length == 3; - } - - public StringBuilder save() { - StringBuilder sb = new StringBuilder(); - sb.append("(\n"); - for (int row = 0; row < table.getRowCount(); row++) { - if (isVector()) { - Double distance = ((Double) table.getValueAt(row, 0)); - double x = ((Double) table.getValueAt(row, 1)); - double y = ((Double) table.getValueAt(row, 2)); - double z = ((Double) table.getValueAt(row, 3)); - String interpolationRow = "( " + distance + " ( " + x + " " + y + " " + z + " ) )"; - sb.append(interpolationRow + "\n"); - } else { - Double time = ((Double) table.getValueAt(row, 0)); - double value = ((Double) table.getValueAt(row, 1)); - String interpolationRow = "( " + time + " " + value + " )"; - sb.append(interpolationRow + "\n"); - } - } - sb.append(")"); - return sb; - } - - protected void loadTable(String tableData) { - if (tableData.startsWith("(") && tableData.endsWith(")")) { - tableData = tableData.substring(1, tableData.length() - 1).trim(); - try { - Pattern regex = Pattern.compile(isVector() ? VECTOR_PATTERN : SCALAR_PATTERN); - Matcher regexMatcher = regex.matcher(tableData); - while (regexMatcher.find()) { - addRow(parseRows(regexMatcher.group(0))); - } - } catch (PatternSyntaxException ex) { - ex.printStackTrace(); - } - } - } - - private Double[] parseRows(String row) { - Pattern innerRegex = Pattern.compile(DOUBLE); - Matcher innerRegexMatcher = innerRegex.matcher(row); - Double[] values = isVector() ? new Double[4] : new Double[2]; - int internalCount = 0; - while (innerRegexMatcher.find()) { - values[internalCount++] = Double.parseDouble(innerRegexMatcher.group(0)); - } - return values; - } - - /* - * GUI - */ - - protected abstract void setupColumnNames(); - - private void layoutComponents() { - createSplitPane(); - add(splitPane, BorderLayout.CENTER); - createTableButtons(); - createTable(); - createChart(); - createDialogButtons(); - createDialog(); - } - - private void createDialog() { - dialog = new JDialog(UiUtil.getActiveWindow(), "Interpolation Table", ModalityType.MODELESS); - dialog.setName("interpolation.dialog"); - dialog.addWindowListener(new WindowAdapter() { - @Override - public void windowClosing(WindowEvent e) { - handleDialogClose_Cancel(); - } - }); - - dialog.add(this); - dialog.setSize(600, 600); - dialog.setLocationRelativeTo(null); - dialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE); - dialog.getRootPane().setDefaultButton(okButton); - } - - public void showDialog() { - load(); - dialog.setVisible(true); - } - - private void handleDialogClose_Cancel() { - dialog.setVisible(false); - } - - private void handleDialogClose_OK() { - save(); - dialog.setVisible(false); - } - - private void createSplitPane() { - this.splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT); - this.splitPane.setOneTouchExpandable(false); - this.topPanel = new JPanel(new BorderLayout()); - this.bottomPanel = new JPanel(new BorderLayout()); - this.splitPane.setTopComponent(topPanel); - this.splitPane.setBottomComponent(bottomPanel); - this.splitPane.setResizeWeight(0.5); - } - - private void createTableButtons() { - JPanel buttonsPanel = new JPanel(new FlowLayout(FlowLayout.CENTER)); - JButton addButton = new JButton(new AbstractAction("+") { - - @Override - public void actionPerformed(ActionEvent e) { - addRow(); - } - }); - addButton.setName("add.row.button"); - buttonsPanel.add(addButton); - removeButton = new JButton(new AbstractAction("-") { - - @Override - public void actionPerformed(ActionEvent e) { - removeRows(); - } - }); - buttonsPanel.add(removeButton); - removeButton.setName("rem.row.button"); - removeButton.setEnabled(false); - - topPanel.add(buttonsPanel, BorderLayout.NORTH); - } - - private void createDialogButtons() { - JPanel buttonsPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); - okButton = new JButton(new AbstractAction("OK") { - - @Override - public void actionPerformed(ActionEvent e) { - handleDialogClose_OK(); - } - }); - okButton.setName("OK"); - JButton cancelButton = new JButton(new AbstractAction("Cancel") { - - @Override - public void actionPerformed(ActionEvent e) { - handleDialogClose_Cancel(); - } - }); - buttonsPanel.add(okButton); - buttonsPanel.add(cancelButton); - bottomPanel.add(buttonsPanel, BorderLayout.SOUTH); - } - - private void createTable() { - tableModel = new DefaultTableModel(columnNames, 0) { - @Override - public Class getColumnClass(int columnIndex) { - return Double.class; - } - }; - table = new JTable() { - public boolean editCellAt(int row, int column, EventObject e) { - boolean result = super.editCellAt(row, column, e); - final Component editor = getEditorComponent(); - if (e instanceof KeyEvent && editor instanceof JTextComponent) { - ((JTextComponent) editor).selectAll(); - } - - return result; - } - - }; - ((DefaultTableCellRenderer) table.getTableHeader().getDefaultRenderer()).setHorizontalAlignment(JLabel.CENTER); - table.setModel(tableModel); - tableModel.addTableModelListener(new TableModelListener() { - @Override - public void tableChanged(TableModelEvent e) { - if (e.getType() == TableModelEvent.UPDATE) { - updateChart(); - } - } - }); - table.getSelectionModel().addListSelectionListener(new ListSelectionListener() { - @Override - public void valueChanged(ListSelectionEvent e) { - removeButton.setEnabled(table.getSelectedRowCount() > 0); - } - }); - setupEditors(table); - - CopyPasteSupport.addSupportTo(table); - topPanel.add(new JScrollPane(table), BorderLayout.CENTER); - } - - private void createChart() { - this.chart = new InterpolationChartPanel(getVariablesList(), columnNames[0]); - chart.layoutComponents(); - chart.initSeries(); - bottomPanel.add(chart, BorderLayout.CENTER); - } - - private List getVariablesList() { - List variables = new ArrayList<>(); - if (isVector()) { - variables.add(X_VAR); - variables.add(Y_VAR); - variables.add(Z_VAR); - } else { - variables.add(VALUE_VAR); - } - return variables; - } - - private void setupEditors(JTable table) { - final DoubleField doubleTextField = ComponentsFactory.doubleField(); - doubleTextField.setMargin(new Insets(0, 0, 0, 0)); - - DefaultCellEditor doubleEditor = new DefaultCellEditor(doubleTextField) { - @Override - public Object getCellEditorValue() { - try { - return Double.valueOf(Double.parseDouble((String) super.getCellEditorValue())); - } catch (NumberFormatException e) { - return Double.valueOf(doubleTextField.getDoubleValue()); - } - } - }; - table.setDefaultEditor(Double.class, doubleEditor); - - final TableCellRenderer r = table.getDefaultRenderer(Double.class); - table.setDefaultRenderer(Double.class, new TableCellRenderer() { - private NumberFormat formatter; - - { - formatter = NumberFormat.getInstance(); - formatter.setMaximumFractionDigits(10); - } - - @Override - public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { - JLabel label = (JLabel) r.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); - if (value instanceof Double) { - label.setText(formatter.format(value)); - } - return label; - } - }); - - } - - private void addRow() { - Object[] scalarRow = new Object[] { 0.0, 0.0 }; - Object[] vectorRow = new Object[] { 0.0, 0.0, 0.0, 0.0 }; - tableModel.addRow(isVector() ? vectorRow : scalarRow); - updateChart(); - } - - private void addRow(Object[] row) { - tableModel.addRow(row); - updateChart(); - } - - private void removeRows() { - int[] selectedRow = table.getSelectedRows(); - for (int i = selectedRow.length - 1; i >= 0; i--) { - tableModel.removeRow(selectedRow[i]); - updateChart(); - } - } - - private void updateChart() { - chart.clearData(); - TimeBlocks tbs = new TimeBlocks(); - for (int row = 0; row < table.getRowCount(); row++) { - TimeBlock timeBlock = new TimeBlock(((Double) table.getValueAt(row, 0))); - if (isVector()) { - timeBlock.getUnitsMap().put(X_VAR, new DoubleTimeBlockUnit(X_VAR, ((Double) table.getValueAt(row, 1)))); - timeBlock.getUnitsMap().put(Y_VAR, new DoubleTimeBlockUnit(Y_VAR, ((Double) table.getValueAt(row, 2)))); - timeBlock.getUnitsMap().put(Z_VAR, new DoubleTimeBlockUnit(Z_VAR, ((Double) table.getValueAt(row, 3)))); - } else { - timeBlock.getUnitsMap().put(VALUE_VAR, new DoubleTimeBlockUnit(VALUE_VAR, ((Double) table.getValueAt(row, 1)))); - } - tbs.add(timeBlock); - } - chart.addToDataSet(tbs); - } - - protected void clear() { - tableModel.setRowCount(0); - chart.clearData(); - } - -} diff --git a/src/eu/engys/gui/casesetup/boundaryconditions/InterpolationChartPanel.java b/src/eu/engys/gui/casesetup/boundaryconditions/InterpolationChartPanel.java deleted file mode 100644 index 43bab73..0000000 --- a/src/eu/engys/gui/casesetup/boundaryconditions/InterpolationChartPanel.java +++ /dev/null @@ -1,100 +0,0 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - -package eu.engys.gui.casesetup.boundaryconditions; - -import java.util.List; - -import org.jfree.chart.ChartFactory; -import org.jfree.chart.axis.NumberAxis; -import org.jfree.chart.plot.PlotOrientation; -import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer; -import org.jfree.data.xy.XYSeries; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import eu.engys.core.project.system.monitoringfunctionobjects.TimeBlock; -import eu.engys.core.project.system.monitoringfunctionobjects.TimeBlockUnit; -import eu.engys.gui.solver.postprocessing.data.DoubleTimeBlockUnit; -import eu.engys.gui.solver.postprocessing.panels.HistoryChartPanel; -import eu.engys.util.ui.textfields.DoubleField; - -public class InterpolationChartPanel extends HistoryChartPanel { - - private static final Logger logger = LoggerFactory.getLogger(InterpolationChartPanel.class); - - public InterpolationChartPanel(List seriesNames, String domainAxisLabel) { - super("", seriesNames, domainAxisLabel, "", false); - } - - @Override - protected void createChart() { - this.chart = ChartFactory.createXYLineChart("", "", "", dataset, PlotOrientation.VERTICAL, true, true, false); - - NumberAxis domainAxis = new NumberAxis(domainAxisLabel); - domainAxis.setAutoRangeStickyZero(false); - domainAxis.setAutoRangeIncludesZero(true); - - NumberAxis rangeAxis = new NumberAxis(rangeAxisLabel); - rangeAxis.setNumberFormatOverride(DoubleField.getFormatForDISPLAY(10)); - - chart.getXYPlot().setDomainAxis(domainAxis); - chart.getXYPlot().setRangeAxis(rangeAxis); - - XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) chart.getXYPlot().getRenderer(); - renderer.setDrawOutlines(true); - renderer.setUseFillPaint(true); - } - - @Override - protected void addTimeBlock(final TimeBlock block) { - for (TimeBlockUnit unit : block.getUnitsMap().values()) { - if (unit instanceof DoubleTimeBlockUnit) { - addTimeUnit(block.getTime(), unit); - } - } - } - - private void addTimeUnit(double time, TimeBlockUnit unit) { - String varName = unit.getVarName(); - if (dataset.getSeriesIndex(varName) != -1) { - XYSeries xyserie = dataset.getSeries(varName); - DoubleTimeBlockUnit doubleUnit = (DoubleTimeBlockUnit) unit; - xyserie.add(time, doubleUnit.getValue()); - } else { - logger.error("Series not found for {}", varName); - } - } - - @Override - public void initSeries() { - super.initSeries(); - XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) chart.getXYPlot().getRenderer(); - for (String varName : seriesNames) { - renderer.setSeriesShapesVisible(dataset.getSeriesIndex(varName), true); - } - } - -} diff --git a/src/eu/engys/gui/casesetup/boundaryconditions/NonUniformComboBoxController.java b/src/eu/engys/gui/casesetup/boundaryconditions/NonUniformComboBoxController.java deleted file mode 100644 index 264fa9f..0000000 --- a/src/eu/engys/gui/casesetup/boundaryconditions/NonUniformComboBoxController.java +++ /dev/null @@ -1,71 +0,0 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - -package eu.engys.gui.casesetup.boundaryconditions; - -import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.DATA_KEY; -import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.FILE_KEY; -import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.FILE_NAME_KEY; - -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; - -import eu.engys.core.dictionary.Dictionary; -import eu.engys.core.dictionary.model.DictionaryModel; -import eu.engys.core.dictionary.model.DictionaryModel.DictionaryError; -import eu.engys.core.dictionary.model.DictionaryModel.DictionaryListener; -import eu.engys.util.ui.builder.JComboBoxController; - -public class NonUniformComboBoxController extends JComboBoxController { - private DictionaryModel model; - - public NonUniformComboBoxController(DictionaryModel model) { - super(); - this.model = model; - model.addDictionaryListener(new DictionaryListener() { - @Override - public void dictionaryChanged() throws DictionaryError { - Dictionary dict = NonUniformComboBoxController.this.model.getDictionary(); - if (dict != null && dict.found(FILE_NAME_KEY) && dict.lookup(FILE_NAME_KEY).length() > 2) { - setSelectedKey(FILE_KEY); - } else { - setSelectedKey(DATA_KEY); - } - } - }); - addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - Dictionary dict = NonUniformComboBoxController.this.model.getDictionary(); - String key = getSelectedKey(); - if (key.equals(DATA_KEY) && dict.found(FILE_NAME_KEY)) { - dict.remove(FILE_NAME_KEY); - } else if (key.equals(FILE_KEY) && !dict.found(FILE_NAME_KEY)) { - dict.add(FILE_NAME_KEY, "\"\""); - } - } - }); - } -} diff --git a/src/eu/engys/gui/casesetup/boundaryconditions/NonUniformInterpolationTable.java b/src/eu/engys/gui/casesetup/boundaryconditions/NonUniformInterpolationTable.java deleted file mode 100644 index c2b9e06..0000000 --- a/src/eu/engys/gui/casesetup/boundaryconditions/NonUniformInterpolationTable.java +++ /dev/null @@ -1,76 +0,0 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - -package eu.engys.gui.casesetup.boundaryconditions; - -import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.DATA_KEY; -import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.FILE_NAME_KEY; -import eu.engys.core.dictionary.Dictionary; -import eu.engys.core.dictionary.model.DictionaryModel; -import eu.engys.core.dictionary.parser.ListField2; - -public class NonUniformInterpolationTable extends AbstractInterpolationTable { - - public static final String DISTANCE_M_LABEL = "Distance [m]"; - - private DictionaryModel dictionaryModel; - - public NonUniformInterpolationTable(DictionaryModel dictionaryModel, String[] names) { - super(names); - this.dictionaryModel = dictionaryModel; - } - - @Override - protected void setupColumnNames() { - if (isVector()) { - this.columnNames = new String[] { DISTANCE_M_LABEL, names[0], names[1], names[2] }; - } else { - this.columnNames = new String[] { DISTANCE_M_LABEL, names[0] }; - } - } - - @Override - public void load() { - clear(); - Dictionary dict = dictionaryModel.getDictionary(); - if (dict.found(DATA_KEY)) { - if (dict.isList2(DATA_KEY)) { - // Fix for alpha1 which is read with DictionaryReader2 - loadTable(ListField2.convertToString(dict.getList2(DATA_KEY))); - } else { - loadTable(dict.lookup(DATA_KEY).trim()); - } - } - } - - @Override - public StringBuilder save() { - StringBuilder sb = super.save(); - dictionaryModel.getDictionary().add(DATA_KEY, sb.toString()); - dictionaryModel.getDictionary().remove(FILE_NAME_KEY); - return sb; - } - -} diff --git a/src/eu/engys/gui/casesetup/boundaryconditions/TimeVaryingComboBoxController.java b/src/eu/engys/gui/casesetup/boundaryconditions/TimeVaryingComboBoxController.java deleted file mode 100644 index cd454d9..0000000 --- a/src/eu/engys/gui/casesetup/boundaryconditions/TimeVaryingComboBoxController.java +++ /dev/null @@ -1,92 +0,0 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - -package eu.engys.gui.casesetup.boundaryconditions; - -import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.DATA_KEY; -import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.FILE_KEY; -import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.TABLE_FILE_KEY; -import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.TABLE_KEY; -import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.isTableFile; - -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; - -import eu.engys.core.dictionary.Dictionary; -import eu.engys.core.dictionary.model.DictionaryModel; -import eu.engys.core.dictionary.model.DictionaryModel.DictionaryError; -import eu.engys.core.dictionary.model.DictionaryModel.DictionaryListener; -import eu.engys.util.ui.builder.JComboBoxController; - -public class TimeVaryingComboBoxController extends JComboBoxController { - private DictionaryModel model; - - public TimeVaryingComboBoxController(DictionaryModel model, final String dictionaryKey) { - super(); - this.model = model; - model.addDictionaryListener(new DictionaryListener() { - @Override - public void dictionaryChanged() throws DictionaryError { - Dictionary dict = TimeVaryingComboBoxController.this.model.getDictionary(); - if (isTableFile(dict, dictionaryKey)) { - setSelectedKey(FILE_KEY); - } else { - setSelectedKey(DATA_KEY); - } - } - }); - addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - Dictionary dict = TimeVaryingComboBoxController.this.model.getDictionary(); - String key = getSelectedKey(); - if (key.equals(DATA_KEY)) { - fixData(dictionaryKey, dict); - } else if (key.equals(FILE_KEY)) { - fixFile(dictionaryKey, dict); - } - } - - private void fixData(final String dictionaryKey, Dictionary dict) { - if(dict.found(dictionaryKey)){ - dict.remove(dictionaryKey); - } - if(!dict.found(dictionaryKey + " " + TABLE_KEY)){ - dict.add(dictionaryKey + " " + TABLE_KEY, "()"); - } - } - - private void fixFile(final String dictionaryKey, Dictionary dict) { - if(dict.found(dictionaryKey + " " + TABLE_KEY)){ - dict.remove(dictionaryKey + " " + TABLE_KEY); - } - if(!dict.found(dictionaryKey)){ - dict.add(dictionaryKey, TABLE_FILE_KEY); - } - } - - }); - } -} diff --git a/src/eu/engys/gui/casesetup/boundaryconditions/TimeVaryingInterpolationTable.java b/src/eu/engys/gui/casesetup/boundaryconditions/TimeVaryingInterpolationTable.java deleted file mode 100644 index 36e7f2d..0000000 --- a/src/eu/engys/gui/casesetup/boundaryconditions/TimeVaryingInterpolationTable.java +++ /dev/null @@ -1,73 +0,0 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - -package eu.engys.gui.casesetup.boundaryconditions; - -import eu.engys.core.dictionary.Dictionary; -import eu.engys.core.dictionary.model.DictionaryModel; -import eu.engys.core.dictionary.parser.ListField2; - -public class TimeVaryingInterpolationTable extends AbstractInterpolationTable { - - private DictionaryModel dictionaryModel; - private String dictionaryKey; - - public TimeVaryingInterpolationTable(DictionaryModel dictionaryModel, String dictionaryKey, String[] names) { - super(names); - this.dictionaryModel = dictionaryModel; - this.dictionaryKey = dictionaryKey; - } - - @Override - protected void setupColumnNames() { - if (isVector()) { - this.columnNames = new String[] { "Time Step [s]", names[0], names[1], names[2] }; - } else { - this.columnNames = new String[] { "Time Step [s]", names[0] }; - } - } - - @Override - public void load() { - clear(); - Dictionary dict = dictionaryModel.getDictionary(); - if (dict.found(dictionaryKey)) { - if (dict.isList2(dictionaryKey)) { - // Fix for alpha1 which is read with DictionaryReader2 - loadTable(ListField2.convertToString(dict.getList2(dictionaryKey))); - } else { - loadTable(dict.lookup(dictionaryKey)); - } - } - } - - @Override - public StringBuilder save() { - StringBuilder sb = super.save(); - dictionaryModel.getDictionary().add(dictionaryKey, sb.toString()); - return sb; - } - -} diff --git a/src/eu/engys/gui/casesetup/boundaryconditions/charts/BeanSparkline.java b/src/eu/engys/gui/casesetup/boundaryconditions/charts/BeanSparkline.java new file mode 100644 index 0000000..0a79d33 --- /dev/null +++ b/src/eu/engys/gui/casesetup/boundaryconditions/charts/BeanSparkline.java @@ -0,0 +1,94 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.gui.casesetup.boundaryconditions.charts; + +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; + +import org.jfree.data.function.PolynomialFunction2D; +import org.jfree.data.general.DatasetUtilities; +import org.jfree.data.xy.XYDataItem; +import org.jfree.data.xy.XYSeries; + +import eu.engys.util.bean.AbstractBean; +import eu.engys.util.bean.BeanModel; + +public class BeanSparkline extends SparklineChart implements PropertyChangeListener { + + private BeanModel model; + private String propertyName; + + public BeanSparkline(BeanModel model, String propertyName) { + super(false); + setName(propertyName); + this.model = model; + this.propertyName = propertyName; + model.addBeanPropertyChangeListener(propertyName, this); + } + + @Override + public void propertyChange(PropertyChangeEvent evt) { + updateChart(); + } + + @Override + protected Double[][] parseData() { + Object value = model.getValue(propertyName); + + Double[][] data = new Double[0][0]; + if (value instanceof double[]) { + double[] d = (double[]) value; + data = toPolynomialObject(d); + } else if (value instanceof double[][]) { + double[][] d = (double[][]) value; + data = toObject(d); + } + return data; + } + + private Double[][] toObject(double[][] d) { + Double[][] data = new Double[d.length][d.length > 0 ? d[0].length : 0]; + for (int i = 0; i < data.length; i++) { + Double[] row = data[i]; + for (int j = 0; j < row.length; j++) { + data[i][j] = Double.valueOf(d[i][j]); + } + } + return data; + } + + private Double[][] toPolynomialObject(double[] d) { + PolynomialFunction2D function = new PolynomialFunction2D(d); + XYSeries series = DatasetUtilities.sampleFunction2DToSeries(function, 0, 1000, 100, ""); + Double[][] data = new Double[series.getItemCount()][2]; + for (int i = 0; i < series.getItemCount(); i++) { + XYDataItem item = series.getDataItem(i); + data[i][0] = item.getXValue(); + data[i][1] = item.getYValue(); + } + return data; + } + +} \ No newline at end of file diff --git a/src/eu/engys/gui/casesetup/boundaryconditions/charts/DictionarySparkline.java b/src/eu/engys/gui/casesetup/boundaryconditions/charts/DictionarySparkline.java new file mode 100644 index 0000000..eac1418 --- /dev/null +++ b/src/eu/engys/gui/casesetup/boundaryconditions/charts/DictionarySparkline.java @@ -0,0 +1,109 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.gui.casesetup.boundaryconditions.charts; + +import static eu.engys.util.RegexpUtils.DOUBLE; +import static eu.engys.util.RegexpUtils.SCALAR_PATTERN; +import static eu.engys.util.RegexpUtils.VECTOR_PATTERN; + +import java.util.ArrayList; +import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import java.util.regex.PatternSyntaxException; + +import eu.engys.core.dictionary.DefaultElement; +import eu.engys.core.dictionary.Dictionary; +import eu.engys.core.dictionary.FieldElement; +import eu.engys.core.dictionary.StartWithFinder; +import eu.engys.core.dictionary.model.DictionaryModel; +import eu.engys.core.dictionary.model.DictionaryModel.DictionaryError; +import eu.engys.core.dictionary.model.DictionaryModel.DictionaryListener; +import eu.engys.core.dictionary.parser.ListField2; + +public class DictionarySparkline extends SparklineChart implements DictionaryListener { + + private boolean vector; + private DictionaryModel dictionaryModel; + private StartWithFinder finder; + + public DictionarySparkline(DictionaryModel dictionaryModel, String dictionaryKey, boolean vector) { + super(vector); + this.dictionaryModel = dictionaryModel; + this.finder = new StartWithFinder(dictionaryKey); + this.vector = vector; + dictionaryModel.addDictionaryListener(this); + } + + @Override + public void dictionaryChanged() throws DictionaryError { + updateChart(); + } + + @Override + protected Double[][] parseData() { + Dictionary dict = dictionaryModel.getDictionary(); + Double[][] data = new Double[0][0]; + if (dict.found(finder)) { + DefaultElement element = dict.lookup(finder); + if (element instanceof ListField2) { + // Fix for alpha1 which is read with DictionaryReader2 + data = parseTable(ListField2.convertToString((ListField2)element)); + } else if(element instanceof FieldElement){ + data = parseTable(((FieldElement)element).getValue().trim()); + } + } + return data; + } + + private Double[][] parseTable(String tableData) { + List data = new ArrayList<>(); + if (tableData.startsWith("(") && tableData.endsWith(")")) { + tableData = tableData.substring(1, tableData.length() - 1).trim(); + try { + Pattern regex = Pattern.compile(vector ? VECTOR_PATTERN : SCALAR_PATTERN); + Matcher regexMatcher = regex.matcher(tableData); + while (regexMatcher.find()) { + Double[] row = parseRow(regexMatcher.group(0)); + data.add(row); + } + } catch (PatternSyntaxException ex) { + ex.printStackTrace(); + } + } + return data.toArray(new Double[0][0]); + } + + private Double[] parseRow(String row) { + Pattern innerRegex = Pattern.compile(DOUBLE); + Matcher innerRegexMatcher = innerRegex.matcher(row); + Double[] values = vector ? new Double[4] : new Double[2]; + int internalCount = 0; + while (innerRegexMatcher.find()) { + values[internalCount++] = Double.parseDouble(innerRegexMatcher.group(0)); + } + return values; + } +} \ No newline at end of file diff --git a/src/eu/engys/gui/casesetup/boundaryconditions/charts/SimpleHistoryChart.java b/src/eu/engys/gui/casesetup/boundaryconditions/charts/SimpleHistoryChart.java new file mode 100644 index 0000000..407df91 --- /dev/null +++ b/src/eu/engys/gui/casesetup/boundaryconditions/charts/SimpleHistoryChart.java @@ -0,0 +1,137 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.gui.casesetup.boundaryconditions.charts; + +import java.util.List; + +import org.jfree.chart.ChartFactory; +import org.jfree.chart.JFreeChart; +import org.jfree.chart.axis.NumberAxis; +import org.jfree.chart.plot.PlotOrientation; +import org.jfree.chart.plot.XYPlot; +import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer; +import org.jfree.data.xy.XYSeries; +import org.jfree.data.xy.XYSeriesCollection; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import eu.engys.core.project.system.monitoringfunctionobjects.TimeBlock; +import eu.engys.core.project.system.monitoringfunctionobjects.TimeBlockUnit; +import eu.engys.core.project.system.monitoringfunctionobjects.TimeBlocks; +import eu.engys.gui.solver.postprocessing.data.DoubleTimeBlockUnit; +import eu.engys.gui.solver.postprocessing.panels.SeriesChart; +import eu.engys.util.ui.textfields.DoubleField; + +public class SimpleHistoryChart extends SeriesChart { + + private static final Logger logger = LoggerFactory.getLogger(SimpleHistoryChart.class); + private String domainAxisLabel; + private String rangeAxisLabel; + private List seriesNames; + + public SimpleHistoryChart(List seriesNames, String domainAxisLabel, String rangeAxisLabel) { + super(); + this.seriesNames = seriesNames; + this.domainAxisLabel = domainAxisLabel; + this.rangeAxisLabel = rangeAxisLabel; + } + + @Override + protected void notifySeries(boolean notify) { + XYSeriesCollection dataset = (XYSeriesCollection) getXYDataset(DATASET_INDEX); + dataset.setNotify(notify); + for (int i = 0; i < dataset.getSeriesCount(); i++) { + dataset.getSeries(i).setNotify(notify); + } + } + + @Override + protected JFreeChart createChart() { + XYSeriesCollection dataset = new XYSeriesCollection(); + + JFreeChart chart = ChartFactory.createXYLineChart("", "", "", dataset, PlotOrientation.VERTICAL, true, true, false); + + NumberAxis domainAxis = new NumberAxis(domainAxisLabel); + domainAxis.setAutoRangeIncludesZero(false); + domainAxis.setAutoRange(true); + + NumberAxis rangeAxis = new NumberAxis(rangeAxisLabel); + rangeAxis.setNumberFormatOverride(DoubleField.getFormatForDISPLAY(10)); + rangeAxis.setAutoRangeIncludesZero(false); + rangeAxis.setAutoRange(true); + + XYPlot xyplot = chart.getXYPlot(); + xyplot.setDomainAxis(domainAxis); + xyplot.setRangeAxis(rangeAxis); + + XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) chart.getXYPlot().getRenderer(); + renderer.setDrawOutlines(true); + renderer.setUseFillPaint(true); + + return chart; + } + + @Override + public void _addToDataSet(TimeBlocks list) { + for (TimeBlock block : list) { + for (String serieName : seriesNames) { + XYSeriesCollection dataset = (XYSeriesCollection) getXYDataset(DATASET_INDEX); + if (dataset.getSeriesIndex(serieName) == -1) { + XYSeries serie = new XYSeries(serieName); + serie.setNotify(false); + dataset.addSeries(serie); + applyGraphicProperties(serieName); + populateSeriesPanel(serieName); + } + addTimeUnit(block.getTime(), block.getUnitsMap().get(serieName)); + } + } + } + + @Override + public void postAddToDataSet() { + } + + private void addTimeUnit(double time, TimeBlockUnit unit) { + if (unit instanceof DoubleTimeBlockUnit) { + DoubleTimeBlockUnit doubleUnit = (DoubleTimeBlockUnit) unit; + Double value = doubleUnit.getValue(); + ((XYSeriesCollection) getXYDataset(DATASET_INDEX)).getSeries(unit.getVarName()).add(time, value); + } else { + logger.error("Invalid unit type {} in time {}", (unit != null ? unit.getClass().getCanonicalName() : "null"), time); + } + } + + @Override + public void _clearData() { + super._clearData(); + ((XYSeriesCollection) getXYDataset(DATASET_INDEX)).removeAllSeries(); + } + + @Override + public void stop() { + } + +} \ No newline at end of file diff --git a/src/eu/engys/gui/casesetup/boundaryconditions/charts/SparklineChart.java b/src/eu/engys/gui/casesetup/boundaryconditions/charts/SparklineChart.java new file mode 100644 index 0000000..287da64 --- /dev/null +++ b/src/eu/engys/gui/casesetup/boundaryconditions/charts/SparklineChart.java @@ -0,0 +1,174 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.gui.casesetup.boundaryconditions.charts; + +import java.awt.Color; +import java.awt.Dimension; +import java.awt.Graphics; +import java.awt.image.BufferedImage; +import java.beans.Transient; + +import javax.swing.JButton; +import javax.swing.JComponent; + +import org.jfree.chart.JFreeChart; +import org.jfree.chart.axis.NumberAxis; +import org.jfree.chart.plot.XYPlot; +import org.jfree.chart.renderer.xy.StandardXYItemRenderer; +import org.jfree.data.xy.XYSeries; +import org.jfree.data.xy.XYSeriesCollection; +import org.jfree.ui.RectangleInsets; + +public abstract class SparklineChart extends JComponent { + + private static final int SPARK_H = new JButton("-").getPreferredSize().height; + private static final int SPARK_W = 60; + + private JFreeChart chart; + private BufferedImage image; + private boolean vector; + private XYSeriesCollection dataset; + + public SparklineChart(boolean vector) { + this.vector = vector; + dataset = createDataset(); + XYPlot plot = createPlot(); + chart = createChart(plot); + } + + private XYSeriesCollection createDataset() { + XYSeriesCollection dataset = new XYSeriesCollection(); + if (vector) { + XYSeries xseries = new XYSeries("SparklineX"); + XYSeries yseries = new XYSeries("SparklineY"); + XYSeries zseries = new XYSeries("SparklineZ"); + dataset.addSeries(xseries); + dataset.addSeries(yseries); + dataset.addSeries(zseries); + } else { + XYSeries series = new XYSeries("Sparkline"); + dataset.addSeries(series); + } + return dataset; + } + + private XYPlot createPlot() { + NumberAxis x = new NumberAxis(); + x.setTickLabelsVisible(false); + x.setTickMarksVisible(false); + x.setAxisLineVisible(false); + x.setNegativeArrowVisible(false); + x.setPositiveArrowVisible(false); + x.setVisible(false); + + NumberAxis y = new NumberAxis(); + y.setTickLabelsVisible(false); + y.setTickMarksVisible(false); + y.setAxisLineVisible(false); + y.setNegativeArrowVisible(false); + y.setPositiveArrowVisible(false); + y.setVisible(false); + + XYPlot plot = new XYPlot(); + plot.setInsets(new RectangleInsets()); + plot.setDataset(dataset); + plot.setDomainAxis(x); + plot.setDomainGridlinesVisible(false); + plot.setDomainCrosshairVisible(false); + plot.setRangeGridlinesVisible(false); + plot.setRangeCrosshairVisible(false); + plot.setRangeAxis(y); + plot.setOutlinePaint(null); + + StandardXYItemRenderer renderer = new StandardXYItemRenderer(StandardXYItemRenderer.LINES); + plot.setRenderer(renderer); + + if (vector) { + // This "get" method will force to generate the color for each series + // If you do not call it, the colors are generated randomly later + // (i.e. sometimes series 0 is red, sometimes is blue...) and you loose the match with the real chart + plot.getRenderer().getItemPaint(0, 0); + plot.getRenderer().getItemPaint(1, 0); + plot.getRenderer().getItemPaint(2, 0); + } + + return plot; + } + + private JFreeChart createChart(XYPlot plot) { + JFreeChart c = new JFreeChart(null, JFreeChart.DEFAULT_TITLE_FONT, plot, false); + c.setAntiAlias(true); + c.setBorderVisible(true); + c.setBorderPaint(Color.LIGHT_GRAY); + c.setPadding(RectangleInsets.ZERO_INSETS); + c.setBackgroundPaint(Color.WHITE); + return c; + } + + @Override + @Transient + public Dimension getPreferredSize() { + return new Dimension(SPARK_W, SPARK_H); + } + + @Override + protected void paintComponent(Graphics g) { + if (image != null) { + g.drawImage(image, 0, 0, null); + } + } + + public void updateChart() { + clearSeries(); + addToDataSet(parseData()); + refreshImage(); + } + + protected abstract Double[][] parseData(); + + private void addToDataSet(Double[][] d) { + for (int i = 0; i < d.length; i++) { + Double[] row = d[i]; + for (int j = 0; j < row.length - 1; j++) { + dataset.getSeries(j).add(row[0], row[j + 1]); + } + } + } + + private void clearSeries() { + for (int i = 0; i < dataset.getSeriesCount(); i++) { + dataset.getSeries(i).clear(); + } + } + + private void refreshImage() { + if (dataset.getSeries(0).isEmpty()) { + image = null; + } else { + image = chart.createBufferedImage(SPARK_W, SPARK_H); + } + } + +} \ No newline at end of file diff --git a/src/eu/engys/gui/casesetup/boundaryconditions/factories/CyclicFactory.java b/src/eu/engys/gui/casesetup/boundaryconditions/factories/CyclicFactory.java index 653bf10..59e534a 100644 --- a/src/eu/engys/gui/casesetup/boundaryconditions/factories/CyclicFactory.java +++ b/src/eu/engys/gui/casesetup/boundaryconditions/factories/CyclicFactory.java @@ -1,141 +1,150 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.casesetup.boundaryconditions.factories; -import static eu.engys.gui.casesetup.boundaryconditions.panels.AbstractCyclicAMISettingsPanel.BRIDGE_OVERLAP_KEY; -import static eu.engys.gui.casesetup.boundaryconditions.panels.AbstractCyclicAMISettingsPanel.COUPLING_KEY; -import static eu.engys.gui.casesetup.boundaryconditions.panels.AbstractCyclicAMISettingsPanel.COUPLING_LABEL; -import static eu.engys.gui.casesetup.boundaryconditions.panels.AbstractCyclicAMISettingsPanel.MATCH_TOLERANCE_KEY; -import static eu.engys.gui.casesetup.boundaryconditions.panels.AbstractCyclicAMISettingsPanel.NEIGHBOUR_PATCH_KEY; -import static eu.engys.gui.casesetup.boundaryconditions.panels.AbstractCyclicAMISettingsPanel.ROTATIONAL_KEY; -import static eu.engys.gui.casesetup.boundaryconditions.panels.AbstractCyclicAMISettingsPanel.ROTATIONAL_LABEL; -import static eu.engys.gui.casesetup.boundaryconditions.panels.AbstractCyclicAMISettingsPanel.ROTATION_ANGLE_KEY; -import static eu.engys.gui.casesetup.boundaryconditions.panels.AbstractCyclicAMISettingsPanel.ROTATION_AXIS_KEY; -import static eu.engys.gui.casesetup.boundaryconditions.panels.AbstractCyclicAMISettingsPanel.ROTATION_CENTRE_KEY; -import static eu.engys.gui.casesetup.boundaryconditions.panels.AbstractCyclicAMISettingsPanel.SEPARATION_VECTOR_KEY; -import static eu.engys.gui.casesetup.boundaryconditions.panels.AbstractCyclicAMISettingsPanel.TRANSFORM_KEY; -import static eu.engys.gui.casesetup.boundaryconditions.panels.AbstractCyclicAMISettingsPanel.TRANSLATIONAL_KEY; -import static eu.engys.gui.casesetup.boundaryconditions.panels.AbstractCyclicAMISettingsPanel.TRANSLATIONAL_LABEL; -import static eu.engys.gui.casesetup.boundaryconditions.panels.AbstractCyclicAMISettingsPanel.WEIGHT_CORRECTION_KEY; +import static eu.engys.gui.casesetup.boundaryconditions.parameterspanel.AbstractCyclicAMISettingsPanel.BRIDGE_OVERLAP_KEY; +import static eu.engys.gui.casesetup.boundaryconditions.parameterspanel.AbstractCyclicAMISettingsPanel.COUPLING_KEY; +import static eu.engys.gui.casesetup.boundaryconditions.parameterspanel.AbstractCyclicAMISettingsPanel.COUPLING_LABEL; +import static eu.engys.gui.casesetup.boundaryconditions.parameterspanel.AbstractCyclicAMISettingsPanel.MATCH_TOLERANCE_KEY; +import static eu.engys.gui.casesetup.boundaryconditions.parameterspanel.AbstractCyclicAMISettingsPanel.NEIGHBOUR_PATCH_KEY; +import static eu.engys.gui.casesetup.boundaryconditions.parameterspanel.AbstractCyclicAMISettingsPanel.ROTATIONAL_KEY; +import static eu.engys.gui.casesetup.boundaryconditions.parameterspanel.AbstractCyclicAMISettingsPanel.ROTATIONAL_LABEL; +import static eu.engys.gui.casesetup.boundaryconditions.parameterspanel.AbstractCyclicAMISettingsPanel.ROTATION_ANGLE_KEY; +import static eu.engys.gui.casesetup.boundaryconditions.parameterspanel.AbstractCyclicAMISettingsPanel.ROTATION_AXIS_KEY; +import static eu.engys.gui.casesetup.boundaryconditions.parameterspanel.AbstractCyclicAMISettingsPanel.ROTATION_CENTRE_KEY; +import static eu.engys.gui.casesetup.boundaryconditions.parameterspanel.AbstractCyclicAMISettingsPanel.SEPARATION_VECTOR_KEY; +import static eu.engys.gui.casesetup.boundaryconditions.parameterspanel.AbstractCyclicAMISettingsPanel.TRANSFORM_KEY; +import static eu.engys.gui.casesetup.boundaryconditions.parameterspanel.AbstractCyclicAMISettingsPanel.TRANSLATIONAL_KEY; +import static eu.engys.gui.casesetup.boundaryconditions.parameterspanel.AbstractCyclicAMISettingsPanel.TRANSLATIONAL_LABEL; +import static eu.engys.gui.casesetup.boundaryconditions.parameterspanel.AbstractCyclicAMISettingsPanel.WEIGHT_CORRECTION_KEY; + import eu.engys.core.dictionary.Dictionary; public class CyclicFactory { - public static final String CYCLIC_AMI_KEY = "cyclicAMI"; - public static final String CYCLIC_KEY = "cyclic"; + public static final String CYCLIC_KEY = "cyclic"; + public static final String CYCLIC_AMI_KEY = "cyclicAMI"; - public static final Dictionary BOUNDARY_CONDITION = new Dictionary("patch") { - { - add(TYPE, CYCLIC_KEY); - add(VALUE, "uniform 0"); - } - }; + public static final Dictionary BOUNDARY_CONDITION(final double value) { + return new Dictionary("patch") { + { + add(TYPE, CYCLIC_KEY); + addUniform(VALUE, value); + } + }; + } - public static final Dictionary BOUNDARY_CONDITION_VECTOR = new Dictionary("patch") { - { - add(TYPE, CYCLIC_KEY); - add(VALUE, "uniform (0 0 0)"); - } - }; + public static final Dictionary BOUNDARY_CONDITION_VECTOR(final double[] value) { + return new Dictionary("patch") { + { + add(TYPE, CYCLIC_KEY); + addUniform(VALUE, new double[] { 0, 0, 0 }); + } + }; + } - public static final Dictionary CYCLIC = new Dictionary("patch") { - { - add(TYPE, CYCLIC_KEY); - add(MATCH_TOLERANCE_KEY, "0.0001"); - add(NEIGHBOUR_PATCH_KEY, ""); - } - }; + public static final Dictionary CYCLIC = new Dictionary("patch") { + { + add(TYPE, CYCLIC_KEY); + add(MATCH_TOLERANCE_KEY, 0.0001); + add(NEIGHBOUR_PATCH_KEY, ""); + } + }; - public static final Dictionary AMI_BOUNDARY_CONDITION = new Dictionary("patch") { - { - add(TYPE, CYCLIC_AMI_KEY); - add(VALUE, "uniform 0"); - } - }; + public static final Dictionary AMI_BOUNDARY_CONDITION(final double value) { - public static final Dictionary AMI_BOUNDARY_CONDITION_VECTOR = new Dictionary("patch") { - { - add(TYPE, CYCLIC_AMI_KEY); - add(VALUE, "uniform (0 0 0)"); - } - }; + return new Dictionary("patch") { + { + add(TYPE, CYCLIC_AMI_KEY); + addUniform(VALUE, value); + } + }; + } - public static final Dictionary CYCLIC_AMI = new Dictionary("patch") { - { - add(TYPE, CYCLIC_AMI_KEY); - add(MATCH_TOLERANCE_KEY, "0.0001"); - add(NEIGHBOUR_PATCH_KEY, ""); - add(TRANSFORM_KEY, COUPLING_KEY); - add(BRIDGE_OVERLAP_KEY, "true"); - } - }; + public static final Dictionary AMI_BOUNDARY_CONDITION_VECTOR(final double[] value) { + return new Dictionary("patch") { + { + add(TYPE, CYCLIC_AMI_KEY); + addUniform(VALUE, value); + } + }; + } - public static final Dictionary CYCLIC_AMI_OS = new Dictionary("patch") { - { - add(TYPE, CYCLIC_AMI_KEY); - add(MATCH_TOLERANCE_KEY, "0.0001"); - add(WEIGHT_CORRECTION_KEY, "0.2"); - add(NEIGHBOUR_PATCH_KEY, ""); - add(TRANSFORM_KEY, COUPLING_KEY); - add(BRIDGE_OVERLAP_KEY, "true"); - } - }; + public static final Dictionary CYCLIC_AMI = new Dictionary("patch") { + { + add(TYPE, CYCLIC_AMI_KEY); + add(MATCH_TOLERANCE_KEY, 0.0001); + add(NEIGHBOUR_PATCH_KEY, ""); + add(TRANSFORM_KEY, COUPLING_KEY); + add(BRIDGE_OVERLAP_KEY, true); + } + }; - public static final Dictionary CYCLIC_AMI_COUPLING = new Dictionary("") { - { - add(TYPE, COUPLING_LABEL); - add(TRANSFORM_KEY, COUPLING_KEY); - } - }; + public static final Dictionary CYCLIC_AMI_OS = new Dictionary("patch") { + { + add(TYPE, CYCLIC_AMI_KEY); + add(MATCH_TOLERANCE_KEY, 0.0001); + add(WEIGHT_CORRECTION_KEY, 0.2); + add(NEIGHBOUR_PATCH_KEY, ""); + add(TRANSFORM_KEY, COUPLING_KEY); + add(BRIDGE_OVERLAP_KEY, true); + } + }; - public static final Dictionary CYCLIC_AMI_ROTATIONAL = new Dictionary("") { - { - add(TYPE, ROTATIONAL_LABEL); - add(TRANSFORM_KEY, ROTATIONAL_KEY); - add(ROTATION_AXIS_KEY, "(1 0 0)"); - add(ROTATION_CENTRE_KEY, "(0 0 0)"); - } - }; + public static final Dictionary CYCLIC_AMI_COUPLING = new Dictionary("") { + { + add(TYPE, COUPLING_LABEL); + add(TRANSFORM_KEY, COUPLING_KEY); + } + }; - public static final Dictionary CYCLIC_AMI_ROTATIONAL_OS = new Dictionary("") { - { - add(TYPE, ROTATIONAL_LABEL); - add(TRANSFORM_KEY, ROTATIONAL_KEY); - add(ROTATION_AXIS_KEY, "(1 0 0)"); - add(ROTATION_CENTRE_KEY, "(0 0 0)"); - add(ROTATION_ANGLE_KEY, "30"); - } - }; + public static final Dictionary CYCLIC_AMI_ROTATIONAL = new Dictionary("") { + { + add(TYPE, ROTATIONAL_LABEL); + add(TRANSFORM_KEY, ROTATIONAL_KEY); + add(ROTATION_AXIS_KEY, new double[] { 1, 0, 0 }); + add(ROTATION_CENTRE_KEY, new double[] { 0, 0, 0 }); + } + }; - public static final Dictionary CYCLIC_AMI_TRANSLATIONAL = new Dictionary("") { - { - add(TYPE, TRANSLATIONAL_LABEL); - add(TRANSFORM_KEY, TRANSLATIONAL_KEY); - add(SEPARATION_VECTOR_KEY, "(0 0 0)"); - } - }; + public static final Dictionary CYCLIC_AMI_ROTATIONAL_OS = new Dictionary("") { + { + add(TYPE, ROTATIONAL_LABEL); + add(TRANSFORM_KEY, ROTATIONAL_KEY); + add(ROTATION_AXIS_KEY, new double[] { 1, 0, 0 }); + add(ROTATION_CENTRE_KEY, new double[] { 0, 0, 0 }); + add(ROTATION_ANGLE_KEY, 30); + } + }; + + public static final Dictionary CYCLIC_AMI_TRANSLATIONAL = new Dictionary("") { + { + add(TYPE, TRANSLATIONAL_LABEL); + add(TRANSFORM_KEY, TRANSLATIONAL_KEY); + add(SEPARATION_VECTOR_KEY, new double[] { 0, 0, 0 }); + } + }; } diff --git a/src/eu/engys/gui/casesetup/boundaryconditions/factories/PressureFactory.java b/src/eu/engys/gui/casesetup/boundaryconditions/factories/PressureFactory.java index bc73fc9..2288306 100644 --- a/src/eu/engys/gui/casesetup/boundaryconditions/factories/PressureFactory.java +++ b/src/eu/engys/gui/casesetup/boundaryconditions/factories/PressureFactory.java @@ -1,29 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.casesetup.boundaryconditions.factories; import static eu.engys.core.project.zero.fields.Fields.P; @@ -32,15 +30,25 @@ import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditions import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.FIXED_FLUX_PRESSURE_KEY; import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.FIXED_VALUE_KEY; import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.FREESTREAM_PRESSURE_KEY; +import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.GAMMA_KEY; import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.OUT_OF_BOUNDS_KEY; +import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.P0_KEY; import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.PRESSURE_KEY; +import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.PRESSURE_OUTLET_KEY; +import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.PVALUE_KEY; +import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.RHOK_KEY; import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.RHO_KEY; +import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.START_DAMPING_ANGLE_KEY; import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.TABLE_FILE_COEFFS_KEY; import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.TABLE_FILE_KEY; import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.TABLE_KEY; import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.TOTAL_PRESSURE_KEY; import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.UNIFORM_TOTAL_PRESSURE_KEY; +import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.VALUE_KEY; +import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.WALL_PRESSURE_KEY; +import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.ZERO_GRADIENT_ANGLE_KEY; import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.ZERO_GRADIENT_KEY; + import eu.engys.core.dictionary.Dictionary; public class PressureFactory { @@ -48,19 +56,19 @@ public class PressureFactory { public static final Dictionary totalPressure = new Dictionary(P) { { add(TYPE, TOTAL_PRESSURE_KEY); - add(VALUE, "uniform 0"); - add("p0", "uniform 0"); - add("gamma", "1.4"); + addUniform(VALUE_KEY, 0.0); + addUniform(P0_KEY, 0.0); + add(GAMMA_KEY, 1.4); } }; public static final Dictionary uniformTotalPressure = new Dictionary(P) { { add(TYPE, UNIFORM_TOTAL_PRESSURE_KEY); - add(VALUE, "uniform 0"); + addUniform(VALUE_KEY, 0.0); add(RHO_KEY, RHO_KEY); - add("gamma", "1.4"); - add("p0", "0"); + add(GAMMA_KEY, 1.4); + add(P0_KEY, 0); add(PRESSURE_KEY, TABLE_KEY + " ()"); add(OUT_OF_BOUNDS_KEY, CLAMP_KEY); } @@ -69,28 +77,36 @@ public class PressureFactory { public static final Dictionary fixedValuePressure_COMP = new Dictionary(P) { { add(TYPE, FIXED_VALUE_KEY); - add(VALUE, "uniform 1e5"); + addUniform(VALUE_KEY, 1e5); } }; public static final Dictionary fixedValuePressure = new Dictionary(P) { { add(TYPE, FIXED_VALUE_KEY); - add(VALUE, "uniform 0"); + addUniform(VALUE_KEY, 0.0); + } + }; + + public static final Dictionary fixedValuePressureCOUPLED = new Dictionary(P) { + { + add(TYPE, PRESSURE_OUTLET_KEY); + addUniform(VALUE_KEY, 0); + addUniform(PVALUE_KEY, 0); } }; public static final Dictionary staticValuePressure_COMP = new Dictionary(P) { { add(TYPE, FIXED_VALUE_KEY); - add(VALUE, "uniform 1e5"); + addUniform(VALUE_KEY, 1e5); } }; public static final Dictionary staticValuePressure = new Dictionary(P) { { add(TYPE, FIXED_VALUE_KEY); - add(VALUE, "uniform 0"); + addUniform(VALUE_KEY, 0.0); } }; @@ -100,11 +116,19 @@ public class PressureFactory { } }; + public static final Dictionary wallPressure = new Dictionary(P) { + { + add(TYPE, WALL_PRESSURE_KEY); + add(START_DAMPING_ANGLE_KEY, 20.0); + add(ZERO_GRADIENT_ANGLE_KEY, 50.0); + } + }; + public static final Dictionary fixedFluxPressure = new Dictionary(P) { { add(TYPE, FIXED_FLUX_PRESSURE_KEY); - add(VALUE, "uniform 0"); - add(RHO_KEY, "rhok"); + addUniform(VALUE_KEY, 0.0); + add(RHO_KEY, RHOK_KEY); } }; @@ -118,10 +142,10 @@ public class PressureFactory { public static final Dictionary uniformTotalPressure_FILE = new Dictionary(P) { { add(TYPE, UNIFORM_TOTAL_PRESSURE_KEY); - add(VALUE, "uniform 0"); + addUniform(VALUE_KEY, 0.0); add(RHO_KEY, RHO_KEY); - add("gamma", "1.4"); - add("p0", "0"); + add(GAMMA_KEY, 1.4); + add(P0_KEY, 0); add(PRESSURE_KEY, TABLE_FILE_KEY); add(new Dictionary(TABLE_FILE_COEFFS_KEY) { { diff --git a/src/eu/engys/gui/casesetup/boundaryconditions/factories/StandardPhaseFactory.java b/src/eu/engys/gui/casesetup/boundaryconditions/factories/StandardPhaseFactory.java index a5cf7ab..73ac656 100644 --- a/src/eu/engys/gui/casesetup/boundaryconditions/factories/StandardPhaseFactory.java +++ b/src/eu/engys/gui/casesetup/boundaryconditions/factories/StandardPhaseFactory.java @@ -1,32 +1,32 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.casesetup.boundaryconditions.factories; import static eu.engys.core.project.zero.fields.Fields.ALPHA; + import eu.engys.core.dictionary.Dictionary; public class StandardPhaseFactory { diff --git a/src/eu/engys/gui/casesetup/boundaryconditions/factories/StandardPressureFactory.java b/src/eu/engys/gui/casesetup/boundaryconditions/factories/StandardPressureFactory.java deleted file mode 100644 index 5ad5f1b..0000000 --- a/src/eu/engys/gui/casesetup/boundaryconditions/factories/StandardPressureFactory.java +++ /dev/null @@ -1,43 +0,0 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - - -package eu.engys.gui.casesetup.boundaryconditions.factories; - -import eu.engys.core.dictionary.Dictionary; - -public class StandardPressureFactory extends PressureFactory { - - public static final Dictionary totalPressure = new Dictionary("p"){ - { - add("type", "totalPressure"); - add("value", "uniform 0"); - add("p0", "uniform 0"); - add("gamma", "0"); - add("rho", "rho"); - } - }; - -} diff --git a/src/eu/engys/gui/casesetup/boundaryconditions/factories/StandardTurbulenceFactory.java b/src/eu/engys/gui/casesetup/boundaryconditions/factories/StandardTurbulenceFactory.java new file mode 100644 index 0000000..b6e1236 --- /dev/null +++ b/src/eu/engys/gui/casesetup/boundaryconditions/factories/StandardTurbulenceFactory.java @@ -0,0 +1,55 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.gui.casesetup.boundaryconditions.factories; + +import static eu.engys.core.project.zero.fields.Fields.EPSILON; +import static eu.engys.core.project.zero.fields.Fields.OMEGA; +import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.MIXING_LENGTH_KEY; +import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.TURBULENT_MIXING_LENGTH_DISSIPATION_RATE_INLET_KEY; +import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.TURBULENT_MIXING_LENGTH_FREQUENCY_INLET_KEY; + +import eu.engys.core.dictionary.Dictionary; + +public class StandardTurbulenceFactory { + + public static final Dictionary omegaMixingLength_COMP = new Dictionary(OMEGA) { + { + add(TYPE, TURBULENT_MIXING_LENGTH_FREQUENCY_INLET_KEY); + addUniform(VALUE, 0.01); + add(MIXING_LENGTH_KEY, "0.01"); + } + }; + + public static final Dictionary epsilonMixingLength_COMP = new Dictionary(EPSILON) { + { + add(TYPE, TURBULENT_MIXING_LENGTH_DISSIPATION_RATE_INLET_KEY); + addUniform(VALUE, 0.01); + add(MIXING_LENGTH_KEY, "0.01"); + } + }; + + + +} diff --git a/src/eu/engys/gui/casesetup/boundaryconditions/factories/StandardVelocityFactory.java b/src/eu/engys/gui/casesetup/boundaryconditions/factories/StandardVelocityFactory.java deleted file mode 100644 index ac34345..0000000 --- a/src/eu/engys/gui/casesetup/boundaryconditions/factories/StandardVelocityFactory.java +++ /dev/null @@ -1,32 +0,0 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - - -package eu.engys.gui.casesetup.boundaryconditions.factories; - - -public class StandardVelocityFactory { - -} diff --git a/src/eu/engys/gui/casesetup/boundaryconditions/factories/TemperatureFactory.java b/src/eu/engys/gui/casesetup/boundaryconditions/factories/TemperatureFactory.java index 3e13d44..1109b9c 100644 --- a/src/eu/engys/gui/casesetup/boundaryconditions/factories/TemperatureFactory.java +++ b/src/eu/engys/gui/casesetup/boundaryconditions/factories/TemperatureFactory.java @@ -1,173 +1,194 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.casesetup.boundaryconditions.factories; +import static eu.engys.core.project.zero.fields.Fields.T; +import static eu.engys.core.project.zero.fields.Fields.U; +import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.ADVECTIVE_KEY; +import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.ALPHA_EFF_KEY; +import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.COMPRESSIBLE_TURBULENT_HEAT_FLUX_TEMPERATURE_KEY; +import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.CP_KEY; +import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.FIXED_VALUE_KEY; +import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.GAMMA_KEY; +import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.HEAT_SOURCE_KEY; +import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.INCOMPRESSIBLE_TURBULENT_HEAT_FLUX_TEMPERATURE_KEY; +import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.INLET_OUTLET_KEY; +import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.INLET_OUTLET_TOTAL_TEMPERATURE_KEY; +import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.INLET_VALUE_KEY; +import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.KAPPA_KEY; +import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.KAPPA_NAME_KEY; +import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.PHI_KEY; +import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.PSI_KEY; +import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.QR_KEY; +import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.Q_KEY; +import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.T0_KEY; +import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.TOTAL_TEMPERATURE_KEY; +import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.ZERO_GRADIENT_KEY; + import eu.engys.core.dictionary.Dictionary; public class TemperatureFactory { - public static final Dictionary fixedValue = new Dictionary("T") { + public static final Dictionary fixedValue = new Dictionary(T) { { - add(TYPE, "fixedValue"); - add("value", "uniform 300"); + add(TYPE, FIXED_VALUE_KEY); + add(VALUE, "uniform 300"); } }; - public static final Dictionary zeroGradient = new Dictionary("T") { + public static final Dictionary zeroGradient = new Dictionary(T) { { - add(TYPE, "zeroGradient"); + add(TYPE, ZERO_GRADIENT_KEY); } }; - public static final Dictionary advectiveTemperature = new Dictionary("T") { + public static final Dictionary advectiveTemperature = new Dictionary(T) { { - add(TYPE, "advective"); + add(TYPE, ADVECTIVE_KEY); } }; - public static final Dictionary totalTemperature = new Dictionary("T") { + public static final Dictionary totalTemperature = new Dictionary(T) { { - add(TYPE, "totalTemperature"); - add("value", "uniform 300"); - add("U", "U"); - add("phi", "phi"); - add("psi", "0"); - add("gamma", "1.4"); - add("T0", "uniform 300"); + add(TYPE, TOTAL_TEMPERATURE_KEY); + add(VALUE, "uniform 300"); + add(U, U); + add(PHI_KEY, PHI_KEY); + add(PSI_KEY, "0"); + add(GAMMA_KEY, "1.4"); + add(T0_KEY, "uniform 300"); } }; - public static final Dictionary inletOutletTotalTemperature = new Dictionary("T") { + public static final Dictionary inletOutletTotalTemperature = new Dictionary(T) { { - add(TYPE, "inletOutletTotalTemperature"); - add("value", "uniform 300"); - add("U", "U"); - add("phi", "phi"); - add("psi", "0"); - add("gamma", "1.4"); - add("T0", "uniform 300"); + add(TYPE, INLET_OUTLET_TOTAL_TEMPERATURE_KEY); + add(VALUE, "uniform 300"); + add(U, "U"); + add(PHI_KEY, PHI_KEY); + add(PSI_KEY, "0"); + add(GAMMA_KEY, "1.4"); + add(T0_KEY, "uniform 300"); } }; - public static final Dictionary inletOutlet = new Dictionary("T") { + public static final Dictionary inletOutlet = new Dictionary(T) { { - add(TYPE, "inletOutlet"); - add("value", "uniform 300"); - add("inletValue", "uniform 300"); + add(TYPE, INLET_OUTLET_KEY); + add(VALUE, "uniform 300"); + add(INLET_VALUE_KEY, "uniform 300"); } }; - public static final Dictionary turbulentHeatFluxTemperature_FLUX = new Dictionary("T") { + public static final Dictionary turbulentHeatFluxTemperature_FLUX = new Dictionary(T) { { - add(TYPE, "incompressible::turbulentHeatFluxTemperature"); - add("value", "uniform 300"); - add("q", "uniform 10.0"); - add("heatSource", "flux"); - add("alphaEff", "kappaEff"); - add("Cp", "Cp0"); + add(TYPE, INCOMPRESSIBLE_TURBULENT_HEAT_FLUX_TEMPERATURE_KEY); + add(VALUE, "uniform 300"); + add(Q_KEY, "uniform 10.0"); + add(HEAT_SOURCE_KEY, "flux"); + add(ALPHA_EFF_KEY, "kappaEff"); + add(CP_KEY, "Cp0"); } }; - public static final Dictionary turbulentHeatFluxTemperature_FLUX_COMP = new Dictionary("T") { + public static final Dictionary turbulentHeatFluxTemperature_FLUX_COMP = new Dictionary(T) { { - add(TYPE, "compressible::turbulentHeatFluxTemperature"); - add("value", "uniform 300"); - add("q", "uniform 10.0"); - add("heatSource", "flux"); - add("kappa", "fluidThermo"); - add("kappaName", "default"); + add(TYPE, COMPRESSIBLE_TURBULENT_HEAT_FLUX_TEMPERATURE_KEY); + add(VALUE, "uniform 300"); + add(Q_KEY, "uniform 10.0"); + add(HEAT_SOURCE_KEY, "flux"); + add(KAPPA_KEY, "fluidThermo"); + add(KAPPA_NAME_KEY, "default"); } }; - public static final Dictionary turbulentHeatFluxTemperatureOCFD_FLUX = new Dictionary("T") { +// public static final Dictionary turbulentHeatFluxTemperatureOCFD_FLUX = new Dictionary(T) { +// { +// add(TYPE, TURBULENT_HEAT_FLUX_TEMPERATURE_KEY); +// add(VALUE, "uniform 300"); +// add(Q_KEY, "uniform 10.0"); +// add(HEAT_SOURCE_KEY, "flux"); +// add(ALPHA_EFF_KEY, ALPHA_EFF_KEY); +// } +// }; + + public static final Dictionary turbulentHeatFluxTemperatureOCFD_FLUX_COMP = new Dictionary(T) { { - add(TYPE, "turbulentHeatFluxTemperature"); - add("value", "uniform 300"); - add("q", "uniform 10.0"); - add("heatSource", "flux"); - add("alphaEff", "alphaEff"); + add(TYPE, COMPRESSIBLE_TURBULENT_HEAT_FLUX_TEMPERATURE_KEY); + add(VALUE, "uniform 300"); + add(Q_KEY, "uniform 10.0"); + add(HEAT_SOURCE_KEY, "flux"); + add(KAPPA_KEY, "fluidThermo"); + add(KAPPA_NAME_KEY, "default"); + add(QR_KEY, "none"); } }; - public static final Dictionary turbulentHeatFluxTemperatureOCFD_FLUX_COMP = new Dictionary("T") { + public static final Dictionary turbulentHeatFluxTemperature_POWER = new Dictionary(T) { { - add(TYPE, "compressible::turbulentHeatFluxTemperature"); - add("value", "uniform 300"); - add("q", "uniform 10.0"); - add("heatSource", "flux"); - add("kappa", "fluidThermo"); - add("kappaName", "default"); - add("Qr", "none"); + add(TYPE, INCOMPRESSIBLE_TURBULENT_HEAT_FLUX_TEMPERATURE_KEY); + add(VALUE, "uniform 300"); + add(Q_KEY, "uniform 10.0"); + add(HEAT_SOURCE_KEY, "power"); + add(ALPHA_EFF_KEY, "kappaEff"); + add(CP_KEY, "Cp0"); } }; - public static final Dictionary turbulentHeatFluxTemperature_POWER = new Dictionary("T") { +// public static final Dictionary turbulentHeatFluxTemperatureOCFD_POWER = new Dictionary(T) { +// { +// add(TYPE, TURBULENT_HEAT_FLUX_TEMPERATURE_KEY); +// add(VALUE, "uniform 300"); +// add(Q_KEY, "uniform 10.0"); +// add(HEAT_SOURCE_KEY, "power"); +// add(ALPHA_EFF_KEY, ALPHA_EFF_KEY); +// } +// }; + + public static final Dictionary turbulentHeatFluxTemperature_POWER_COMP = new Dictionary(T) { { - add(TYPE, "incompressible::turbulentHeatFluxTemperature"); - add("value", "uniform 300"); - add("q", "uniform 10.0"); - add("heatSource", "power"); - add("alphaEff", "kappaEff"); - add("Cp", "Cp0"); + add(TYPE, COMPRESSIBLE_TURBULENT_HEAT_FLUX_TEMPERATURE_KEY); + add(VALUE, "uniform 300"); + add(Q_KEY, "uniform 10.0"); + add(HEAT_SOURCE_KEY, "power"); + add(KAPPA_KEY, "fluidThermo"); + add(KAPPA_NAME_KEY, "none"); } }; - public static final Dictionary turbulentHeatFluxTemperatureOCFD_POWER = new Dictionary("T") { + public static final Dictionary turbulentHeatFluxTemperatureOCFD_POWER_COMP = new Dictionary(T) { { - add(TYPE, "turbulentHeatFluxTemperature"); - add("value", "uniform 300"); - add("q", "uniform 10.0"); - add("heatSource", "power"); - add("alphaEff", "alphaEff"); - } - }; - - public static final Dictionary turbulentHeatFluxTemperature_POWER_COMP = new Dictionary("T") { - { - add(TYPE, "compressible::turbulentHeatFluxTemperature"); - add("value", "uniform 300"); - add("q", "uniform 10.0"); - add("heatSource", "power"); - add("kappa", "fluidThermo"); - add("kappaName", "none"); - } - }; - - public static final Dictionary turbulentHeatFluxTemperatureOCFD_POWER_COMP = new Dictionary("T") { - { - add(TYPE, "compressible::turbulentHeatFluxTemperature"); - add("value", "uniform 300"); - add("q", "uniform 10.0"); - add("heatSource", "power"); - add("kappa", "fluidThermo"); - add("kappaName", "default"); - add("Qr", "none"); + add(TYPE, COMPRESSIBLE_TURBULENT_HEAT_FLUX_TEMPERATURE_KEY); + add(VALUE, "uniform 300"); + add(Q_KEY, "uniform 10.0"); + add(HEAT_SOURCE_KEY, "power"); + add(KAPPA_KEY, "fluidThermo"); + add(KAPPA_NAME_KEY, "default"); + add(QR_KEY, "none"); } }; } diff --git a/src/eu/engys/gui/casesetup/boundaryconditions/factories/TurbulenceFactory.java b/src/eu/engys/gui/casesetup/boundaryconditions/factories/TurbulenceFactory.java index 123f71c..e0ffcbf 100644 --- a/src/eu/engys/gui/casesetup/boundaryconditions/factories/TurbulenceFactory.java +++ b/src/eu/engys/gui/casesetup/boundaryconditions/factories/TurbulenceFactory.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.casesetup.boundaryconditions.factories; @@ -35,8 +34,6 @@ import static eu.engys.core.project.zero.fields.Fields.NU_SGS; import static eu.engys.core.project.zero.fields.Fields.NU_TILDA; import static eu.engys.core.project.zero.fields.Fields.OMEGA; import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.CLAMP_KEY; -import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.COMPRESSIBLE_TURBULENT_MIXING_LENGTH_DISSIPATION_RATE_INLET_KEY; -import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.COMPRESSIBLE_TURBULENT_MIXING_LENGTH_FREQUENCY_INLET_KEY; import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.CS_KEY; import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.FIXED_VALUE_KEY; import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.INLET_OUTLET_KEY; @@ -63,6 +60,7 @@ import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditions import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.UNIFORM_VALUE_KEY; import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.Z0_KEY; import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.ZERO_GRADIENT_KEY; + import eu.engys.core.dictionary.Dictionary; public class TurbulenceFactory { @@ -74,25 +72,25 @@ public class TurbulenceFactory { public static final Dictionary kFixedValue = new Dictionary(K) { { add(TYPE, FIXED_VALUE_KEY); - add(VALUE, "uniform 0.01"); + addUniform(VALUE, 0.01); } }; public static final Dictionary omegaFixedValue = new Dictionary(OMEGA) { { add(TYPE, FIXED_VALUE_KEY); - add(VALUE, "uniform 0.01"); + addUniform(VALUE, 0.01); } }; public static final Dictionary epsilonFixedValue = new Dictionary(EPSILON) { { add(TYPE, FIXED_VALUE_KEY); - add(VALUE, "uniform 0.01"); + addUniform(VALUE, 0.01); } }; public static final Dictionary nutildaFixedValue = new Dictionary(NU_TILDA) { { add(TYPE, FIXED_VALUE_KEY); - add(VALUE, "uniform 0.01"); + addUniform(VALUE, 0.01); } }; @@ -102,42 +100,28 @@ public class TurbulenceFactory { public static final Dictionary kMixingLength = new Dictionary(K) { { add(TYPE, TURBULENT_INTENSITY_KINETIC_ENERGY_INLET_KEY); - add(VALUE, "uniform 0.01"); + addUniform(VALUE, 0.01); add(INTENSITY_KEY, "0.05"); } }; public static final Dictionary epsilonMixingLength = new Dictionary(EPSILON) { { add(TYPE, TURBULENT_MIXING_LENGTH_DISSIPATION_RATE_INLET_KEY); - add(VALUE, "uniform 0.01"); - add(MIXING_LENGTH_KEY, "0.01"); - } - }; - public static final Dictionary epsilonMixingLength_COMP = new Dictionary(EPSILON) { - { - add(TYPE, COMPRESSIBLE_TURBULENT_MIXING_LENGTH_DISSIPATION_RATE_INLET_KEY); - add(VALUE, "uniform 0.01"); + addUniform(VALUE, 0.01); add(MIXING_LENGTH_KEY, "0.01"); } }; public static final Dictionary omegaMixingLength = new Dictionary(OMEGA) { { add(TYPE, TURBULENT_MIXING_LENGTH_FREQUENCY_INLET_KEY); - add(VALUE, "uniform 0.01"); - add(MIXING_LENGTH_KEY, "0.01"); - } - }; - public static final Dictionary omegaMixingLength_COMP = new Dictionary(OMEGA) { - { - add(TYPE, COMPRESSIBLE_TURBULENT_MIXING_LENGTH_FREQUENCY_INLET_KEY); - add(VALUE, "uniform 0.01"); + addUniform(VALUE, 0.01); add(MIXING_LENGTH_KEY, "0.01"); } }; public static final Dictionary nuTildaMixingLength = new Dictionary(NU_TILDA) { { add(TYPE, NUT_TURBULENT_INTENSITY_LENGTH_SCALE_INLET_KEY); - add(VALUE, "uniform 0.01"); + addUniform(VALUE, 0.01); add(INTENSITY_KEY, "0.05"); add(LENGTH_KEY, "0.01"); } @@ -149,7 +133,7 @@ public class TurbulenceFactory { public static final Dictionary kTimeVarying = new Dictionary(K) { { add(TYPE, UNIFORM_FIXED_VALUE_KEY); - add(VALUE, "uniform 0.01"); + addUniform(VALUE, 0.01); add(UNIFORM_VALUE_KEY, TABLE_KEY + " ()"); add(OUT_OF_BOUNDS_KEY, CLAMP_KEY); } @@ -157,7 +141,7 @@ public class TurbulenceFactory { public static final Dictionary omegaTimeVarying = new Dictionary(OMEGA) { { add(TYPE, UNIFORM_FIXED_VALUE_KEY); - add(VALUE, "uniform 0.01"); + addUniform(VALUE, 0.01); add(UNIFORM_VALUE_KEY, TABLE_KEY + " ()"); add(OUT_OF_BOUNDS_KEY, CLAMP_KEY); } @@ -165,7 +149,7 @@ public class TurbulenceFactory { public static final Dictionary epsilonTimeVarying = new Dictionary(EPSILON) { { add(TYPE, UNIFORM_FIXED_VALUE_KEY); - add(VALUE, "uniform 0.01"); + addUniform(VALUE, 0.01); add(UNIFORM_VALUE_KEY, TABLE_KEY + " ()"); add(OUT_OF_BOUNDS_KEY, CLAMP_KEY); } @@ -173,7 +157,7 @@ public class TurbulenceFactory { public static final Dictionary nuTildaTimeVarying = new Dictionary(NU_TILDA) { { add(TYPE, UNIFORM_FIXED_VALUE_KEY); - add(VALUE, "uniform 0.01"); + addUniform(VALUE, 0.01); add(UNIFORM_VALUE_KEY, TABLE_KEY + " ()"); add(OUT_OF_BOUNDS_KEY, CLAMP_KEY); } @@ -186,29 +170,29 @@ public class TurbulenceFactory { public static final Dictionary kInletOutlet = new Dictionary(K) { { add(TYPE, INLET_OUTLET_KEY); - add(VALUE, "uniform 0.01"); - add(INLET_VALUE_KEY, "uniform 0.01"); + addUniform(VALUE, 0.01); + addUniform(INLET_VALUE_KEY, 0.01); } }; public static final Dictionary omegaInletOutlet = new Dictionary(OMEGA) { { add(TYPE, INLET_OUTLET_KEY); - add(VALUE, "uniform 0.01"); - add(INLET_VALUE_KEY, "uniform 0.01"); + addUniform(VALUE, 0.01); + addUniform(INLET_VALUE_KEY, 0.01); } }; public static final Dictionary epsilonInletOutlet = new Dictionary(EPSILON) { { add(TYPE, INLET_OUTLET_KEY); - add(VALUE, "uniform 0.01"); - add(INLET_VALUE_KEY, "uniform 0.01"); + addUniform(VALUE, 0.01); + addUniform(INLET_VALUE_KEY, 0.01); } }; public static final Dictionary nuTildaInletOutlet = new Dictionary(NU_TILDA) { { add(TYPE, INLET_OUTLET_KEY); - add(VALUE, "uniform 0.01"); - add(INLET_VALUE_KEY, "uniform 0.01"); + addUniform(VALUE, 0.01); + addUniform(INLET_VALUE_KEY, 0.01); } }; @@ -242,22 +226,22 @@ public class TurbulenceFactory { public static final Dictionary nutkRoughWallFunction = new Dictionary(NUT) { { add(TYPE, NUT_K_ROUGH_WALL_FUNCTION_KEY); - add(VALUE, "uniform 0"); - add(KS_KEY, "uniform 0"); - add(CS_KEY, "uniform 0.5"); + addUniform(VALUE, 0.0); + addUniform(KS_KEY, 0.0); + addUniform(CS_KEY, 0.5); } }; public static final Dictionary nutkAtmRoughWallFunction = new Dictionary(NUT) { { add(TYPE, NUT_K_ATM_ROUGH_WALL_FUNCTION_KEY); - add(VALUE, "uniform 0"); - add(Z0_KEY, "uniform 0"); + addUniform(VALUE, 0.0); + addUniform(Z0_KEY, 0.0); } }; public static final Dictionary nutURoughWallFunction = new Dictionary(NUT) { { add(TYPE, NUT_U_ROUGH_WALL_FUNCTION_KEY); - add(VALUE, "uniform 0"); + addUniform(VALUE, 0.0); add(ROUGHNESS_HEIGHT_KEY, "1e-5"); add(ROUGHNESS_CONSTANT_KEY, "0.5"); add(ROUGHNESS_FACTOR_KEY, "1"); @@ -266,7 +250,7 @@ public class TurbulenceFactory { public static final Dictionary nuSgsURoughWallFunction = new Dictionary(NU_SGS) { { add(TYPE, NUT_U_ROUGH_WALL_FUNCTION_KEY); - add(VALUE, "uniform 0"); + addUniform(VALUE, 0.0); add(ROUGHNESS_HEIGHT_KEY, "1e-5"); add(ROUGHNESS_CONSTANT_KEY, "0.5"); add(ROUGHNESS_FACTOR_KEY, "1"); @@ -276,15 +260,15 @@ public class TurbulenceFactory { public static final Dictionary mutKRoughWallFunction = new Dictionary(MUT) { { add(TYPE, MUT_K_ROUGH_WALL_FUNCTION_KEY); - add(VALUE, "uniform 0"); - add(KS_KEY, "uniform 0"); - add(CS_KEY, "uniform 0.5"); + addUniform(VALUE, 0.0); + addUniform(KS_KEY, 0.0); + addUniform(CS_KEY, 0.5); } }; public static final Dictionary mutURoughWallFunction = new Dictionary(MUT) { { add(TYPE, MUT_U_ROUGH_WALL_FUNCTION_KEY); - add(VALUE, "uniform 0"); + addUniform(VALUE, 0.0); add(ROUGHNESS_HEIGHT_KEY, "1e-5"); add(ROUGHNESS_CONSTANT_KEY, "0.5"); add(ROUGHNESS_FACTOR_KEY, "1"); @@ -293,7 +277,7 @@ public class TurbulenceFactory { public static final Dictionary muSgsURoughWallFunction = new Dictionary(MU_SGS) { { add(TYPE, MUT_U_ROUGH_WALL_FUNCTION_KEY); - add(VALUE, "uniform 0"); + addUniform(VALUE, 0.0); add(ROUGHNESS_HEIGHT_KEY, "1e-5"); add(ROUGHNESS_CONSTANT_KEY, "0.5"); add(ROUGHNESS_FACTOR_KEY, "1"); diff --git a/src/eu/engys/gui/casesetup/boundaryconditions/factories/VelocityFactory.java b/src/eu/engys/gui/casesetup/boundaryconditions/factories/VelocityFactory.java index 2f03cca..a6080a4 100644 --- a/src/eu/engys/gui/casesetup/boundaryconditions/factories/VelocityFactory.java +++ b/src/eu/engys/gui/casesetup/boundaryconditions/factories/VelocityFactory.java @@ -1,36 +1,37 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.casesetup.boundaryconditions.factories; import static eu.engys.core.project.zero.fields.Fields.U; import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.ACCOMMODATION_COEFFICIENT_KEY; import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.ADVECTIVE_KEY; import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.ALPHA_KEY; +import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.AXIAL_VELOCITY_KEY; import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.AXIS_KEY; +import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.CENTRE_KEY; +import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.CURVATURE_KEY; import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.CYLINDRICAL_INLET_VELOCITY_KEY; import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.FIXED_VALUE_KEY; import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.FLOW_RATE_INLET_VELOCITY_KEY; @@ -45,22 +46,28 @@ import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditions import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.MAXWELL_SLIP_U_KEY; import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.MOVING_WALL_VELOCITY_KEY; import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.NO_SLIP_WALL_KEY; +import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.OMEGA_KEY; +import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.ORIGIN_KEY; import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.PHI_KEY; +import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.PRESSURE_DIRECTED_INLET_VELOCITY_KEY; import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.PRESSURE_DIRECT_INLET_OUTLET_VELOCITY_KEY; -import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.PRESSURE_DIRECT_INLET_VELOCITY_KEY; import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.PRESSURE_INLET_OUTLET_VELOCITY_KEY; import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.PRESSURE_INLET_VELOCITY_KEY; +import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.RADIAL_VELOCITY_KEY; import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.REF_VALUE_KEY; import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.RHO_INLET_KEY; import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.RHO_KEY; import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.ROTATING_WALL_VELOCITY_KEY; +import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.RPM_KEY; import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.SLIP_KEY; import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.SLIP_WALL_KEY; import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.SURFACE_NORMAL_FIXED_VALUE_KEY; -import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.UWALL; +import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.THERMAL_CREEP_KEY; +import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.UWALL_KEY; import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.VARIABLE_HEIGHT_FLOW_RATE_INLET_VELOCITY_KEY; import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.VOLUMETRIC_FLOW_RATE_KEY; import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.ZERO_GRADIENT_KEY; + import eu.engys.core.dictionary.Dictionary; public class VelocityFactory { @@ -68,19 +75,19 @@ public class VelocityFactory { public static final Dictionary fixedValueVelocity = new Dictionary(U) { { add(TYPE, FIXED_VALUE_KEY); - add(VALUE, "uniform (0 0 0)"); + addUniform(VALUE, new double[] { 0, 0, 0 }); } }; public static final Dictionary movingWallVelocity = new Dictionary(U) { { add(TYPE, MOVING_WALL_VELOCITY_KEY); - add(VALUE, "uniform (0 0 0)"); + addUniform(VALUE, new double[] { 0, 0, 0 }); } }; public static final Dictionary zeroGradientVelocity = new Dictionary(U) { { add(TYPE, ZERO_GRADIENT_KEY); - add(VALUE, "uniform (0 0 0)"); + addUniform(VALUE, new double[] { 0, 0, 0 }); } }; public static final Dictionary advectiveVelocity = new Dictionary(U) { @@ -91,61 +98,61 @@ public class VelocityFactory { public static final Dictionary inletOutletVelocity = new Dictionary(U) { { add(TYPE, INLET_OUTLET_KEY); - add(VALUE, "uniform (0 0 0)"); - add(INLET_VALUE_KEY, "uniform (0 0 0)"); + addUniform(VALUE, new double[] { 0, 0, 0 }); + addUniform(INLET_VALUE_KEY, new double[] { 0, 0, 0 }); } }; public static final Dictionary cylindricalInletVelocity = new Dictionary(U) { { add(TYPE, CYLINDRICAL_INLET_VELOCITY_KEY); - add(VALUE, "uniform (0 0 0)"); - add(AXIS_KEY, "(0 0 1)"); - add("centre", "(0 0 0)"); - add("axialVelocity", "30"); - add("rpm", "100"); - add("radialVelocity", "-10"); + addUniform(VALUE, new double[] { 0, 0, 0 }); + add(AXIS_KEY, new double[] { 0, 0, 1 }); + add(CENTRE_KEY, new double[] { 0, 0, 0 }); + add(AXIAL_VELOCITY_KEY, 30); + add(RPM_KEY, 100); + add(RADIAL_VELOCITY_KEY, -10); } }; public static final Dictionary surfaceNormalFixedValue = new Dictionary(U) { { add(TYPE, SURFACE_NORMAL_FIXED_VALUE_KEY); - add(VALUE, "uniform (0 0 0)"); - add(REF_VALUE_KEY, "uniform -1.5"); + addUniform(VALUE, new double[] { 0, 0, 0 }); + addUniform(REF_VALUE_KEY, -1.5); } }; public static final Dictionary volumetricFlowRateInletVelocity = new Dictionary(U) { { add(TYPE, FLOW_RATE_INLET_VELOCITY_KEY); - add(VALUE, "uniform (0 0 0)"); - add(VOLUMETRIC_FLOW_RATE_KEY, "0.1"); + addUniform(VALUE, new double[] { 0, 0, 0 }); + add(VOLUMETRIC_FLOW_RATE_KEY, 0.1); } }; public static final Dictionary massFlowRateInletVelocity = new Dictionary(U) { { add(TYPE, FLOW_RATE_INLET_VELOCITY_KEY); - add(VALUE, "uniform (0 0 0)"); - add(MASS_FLOW_RATE_KEY, "0.1"); - add(RHO_KEY, "rho"); + addUniform(VALUE, new double[] { 0, 0, 0 }); + add(MASS_FLOW_RATE_KEY, 0.1); + add(RHO_KEY, RHO_KEY); } }; public static final Dictionary massFlowRateInletVelocity_INCOMPRESSIBLE = new Dictionary(U) { { add(TYPE, FLOW_RATE_INLET_VELOCITY_KEY); - add(VALUE, "uniform (0 0 0)"); - add(MASS_FLOW_RATE_KEY, "0.1"); - add(RHO_KEY, "rho"); - add(RHO_INLET_KEY, "1.0"); + addUniform(VALUE, new double[] { 0, 0, 0 }); + add(MASS_FLOW_RATE_KEY, 0.1); + add(RHO_KEY, RHO_KEY); + add(RHO_INLET_KEY, 1.0); } }; public static final Dictionary variableHeightFlowRateInletVelocity = new Dictionary(U) { { add(TYPE, VARIABLE_HEIGHT_FLOW_RATE_INLET_VELOCITY_KEY); - add(VALUE, "uniform (0 0 0)"); - add(FLOW_RATE_KEY, "0.2"); + addUniform(VALUE, new double[] { 0, 0, 0 }); + add(FLOW_RATE_KEY, 0.2); add(ALPHA_KEY, "alpha.water"); } }; @@ -153,7 +160,7 @@ public class VelocityFactory { public static final Dictionary pressureInletVelocity = new Dictionary(U) { { add(TYPE, PRESSURE_INLET_VELOCITY_KEY); - add(VALUE, "uniform (0 0 0)"); + addUniform(VALUE, new double[] { 0, 0, 0 }); } }; @@ -165,33 +172,33 @@ public class VelocityFactory { public static final Dictionary pressureDirectedInletVelocity = new Dictionary(U) { { - add(TYPE, PRESSURE_DIRECT_INLET_VELOCITY_KEY); - add(VALUE, "uniform (0 0 0)"); - add(INLET_DIRECTION_KEY, "(1 0 0)"); + add(TYPE, PRESSURE_DIRECTED_INLET_VELOCITY_KEY); + addUniform(VALUE, new double[] { 0, 0, 0 }); + add(INLET_DIRECTION_KEY, new double[] { 1, 0, 0 }); } }; public static final Dictionary pressureInletOutletVelocity = new Dictionary(U) { { add(TYPE, PRESSURE_INLET_OUTLET_VELOCITY_KEY); - add(VALUE, "uniform (0 0 0)"); + addUniform(VALUE, new double[] { 0, 0, 0 }); } }; public static final Dictionary pressureDirectedInletOutletVelocity = new Dictionary(U) { { add(TYPE, PRESSURE_DIRECT_INLET_OUTLET_VELOCITY_KEY); - add(VALUE, "uniform (0 0 0)"); - add(INLET_DIRECTION_KEY, "(1 0 0)"); + addUniform(VALUE, new double[] { 0, 0, 0 }); + add(INLET_DIRECTION_KEY, new double[] { 1, 0, 0 }); } }; public static final Dictionary freestreamVelocity = new Dictionary(U) { { add(TYPE, FREESTREAM_KEY); - add(VALUE, "uniform (0 0 0)"); + addUniform(VALUE, new double[] { 0, 0, 0 }); add(PHI_KEY, PHI_KEY); - add(FREESTREAM_VALUE_KEY, "uniform (0 0 0)"); + addUniform(FREESTREAM_VALUE_KEY, new double[] { 0, 0, 0 }); } }; @@ -210,35 +217,35 @@ public class VelocityFactory { public static final Dictionary maxwellSlipWall = new Dictionary(U) { { add(TYPE, MAXWELL_SLIP_U_KEY); - add(VALUE, "uniform (0 0 0)"); - add(ACCOMMODATION_COEFFICIENT_KEY, "0.85"); - add("thermalCreep", "on"); - add("curvature", "on"); - add(UWALL, "uniform (0 0 0)"); + addUniform(VALUE, new double[] { 0, 0, 0 }); + add(ACCOMMODATION_COEFFICIENT_KEY, 0.85); + add(THERMAL_CREEP_KEY, "on"); + add(CURVATURE_KEY, "on"); + addUniform(UWALL_KEY, new double[] { 0, 0, 0 }); } }; public static final Dictionary noSlipWall = new Dictionary(U) { { add(TYPE, FIXED_VALUE_KEY); - add(VALUE, "uniform (0 0 0)"); + addUniform(VALUE, new double[] { 0, 0, 0 }); } }; public static final Dictionary noSlipWallCoupled = new Dictionary(U) { { add(TYPE, NO_SLIP_WALL_KEY); - add(VALUE, "uniform (0 0 0)"); + addUniform(VALUE, new double[] { 0, 0, 0 }); } }; public static final Dictionary standardRotatingWallVelocity = new Dictionary(U) { { add(TYPE, ROTATING_WALL_VELOCITY_KEY); - add(VALUE, "uniform (0 0 0)"); - add("origin", "(0 0 0)"); - add("axis", "(1 0 0)"); - add("omega", "5"); + addUniform(VALUE, new double[] { 0, 0, 0 }); + add(ORIGIN_KEY, new double[] { 0, 0, 0 }); + add(AXIS_KEY, new double[] { 1, 0, 0 }); + add(OMEGA_KEY, 5); } }; diff --git a/src/eu/engys/gui/casesetup/boundaryconditions/panels/AbstractCyclicAMISettingsPanel.java b/src/eu/engys/gui/casesetup/boundaryconditions/panels/AbstractCyclicAMISettingsPanel.java deleted file mode 100644 index 33656ad..0000000 --- a/src/eu/engys/gui/casesetup/boundaryconditions/panels/AbstractCyclicAMISettingsPanel.java +++ /dev/null @@ -1,333 +0,0 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - - -package eu.engys.gui.casesetup.boundaryconditions.panels; - -import static eu.engys.core.dictionary.Dictionary.TYPE; -import static eu.engys.gui.casesetup.boundaryconditions.factories.CyclicFactory.AMI_BOUNDARY_CONDITION; -import static eu.engys.gui.casesetup.boundaryconditions.factories.CyclicFactory.AMI_BOUNDARY_CONDITION_VECTOR; -import static eu.engys.gui.casesetup.boundaryconditions.factories.CyclicFactory.CYCLIC_AMI_COUPLING; -import static eu.engys.gui.casesetup.boundaryconditions.factories.CyclicFactory.CYCLIC_AMI_KEY; -import static eu.engys.gui.casesetup.boundaryconditions.factories.CyclicFactory.CYCLIC_AMI_TRANSLATIONAL; - -import java.awt.BorderLayout; -import java.awt.Component; - -import javax.swing.JOptionPane; -import javax.swing.JPanel; - -import eu.engys.core.dictionary.Dictionary; -import eu.engys.core.dictionary.model.DictionaryModel; -import eu.engys.core.dictionary.model.DictionaryPanelBuilder; -import eu.engys.core.modules.boundaryconditions.BoundaryTypePanel; -import eu.engys.core.modules.boundaryconditions.ParametersPanel; -import eu.engys.core.project.Model; -import eu.engys.core.project.zero.fields.Field; -import eu.engys.core.project.zero.fields.Field.FieldType; -import eu.engys.core.project.zero.patches.BoundaryConditions; -import eu.engys.core.project.zero.patches.BoundaryConditionsDefaults; -import eu.engys.core.project.zero.patches.BoundaryType; -import eu.engys.core.project.zero.patches.Patch; -import eu.engys.util.ui.UiUtil; -import eu.engys.util.ui.builder.PanelBuilder; - -public abstract class AbstractCyclicAMISettingsPanel extends JPanel implements BoundaryTypePanel { - - public static final String MATCH_TOLERANCE_KEY = "matchTolerance"; - public static final String NEIGHBOUR_PATCH_KEY = "neighbourPatch"; - public static final String SEPARATION_VECTOR_LABEL = "Separation Vector"; - public static final String SEPARATION_VECTOR_KEY = "separationVector"; - public static final String ROTATION_CENTRE_KEY = "rotationCentre"; - public static final String ROTATION_AXIS_KEY = "rotationAxis"; - public static final String TRANSFORM_KEY = "transform"; - public static final String COUPLING_KEY = "noOrdering"; - public static final String TRANSLATIONAL_KEY = "translational"; - public static final String ROTATIONAL_KEY = "rotational"; - public static final String ROTATION_ANGLE_KEY = "rotationAngle"; - public static final String WEIGHT_CORRECTION_KEY = "lowWeightCorrection"; - public static final String BRIDGE_OVERLAP_KEY = "bridgeOverlap"; - - public static final String ROTATION_ANGLE_LABEL = "Rotation [deg]"; - public static final String WEIGHT_CORRECTION_LABEL = "Weight Correction"; - public static final String TRANSFORM_LABEL = "Transform"; - public static final String COUPLING_LABEL = "Coupling"; - public static final String TRANSLATIONAL_LABEL = "Translational"; - public static final String ROTATIONAL_LABEL = "Rotational"; - public static final String CENTRE_LABEL = "Centre"; - public static final String AXIS_LABEL = "Axis"; - public static final String NEIGHBOUR_PATCH_LABEL = "Neighbour Patch"; - public static final String MATCH_TOLERANCE_LABEL = "Match Tolerance"; - - protected DictionaryModel cyclicModel; - protected DictionaryModel rotationalModel; - protected DictionaryModel couplingModel; - private DictionaryModel translationalModel; - - protected Model model; - - protected DictionaryPanelBuilder transformBuilder; - - public AbstractCyclicAMISettingsPanel(Model model) { - super(new BorderLayout()); - this.model = model; - this.cyclicModel = new DictionaryModel(); - this.couplingModel = new DictionaryModel(); - this.rotationalModel = new DictionaryModel(); - this.translationalModel = new DictionaryModel(); - } - - @Override - public void resetToDefault() { - this.couplingModel.setDictionary(new Dictionary(CYCLIC_AMI_COUPLING)); - this.translationalModel.setDictionary(new Dictionary(CYCLIC_AMI_TRANSLATIONAL)); - } - - @Override - public void layoutPanel() { - resetToDefault(); - - PanelBuilder builder = new PanelBuilder(); - - bindAmiParameters(builder); - - transformBuilder = new DictionaryPanelBuilder(); - transformBuilder.startChoice(TRANSFORM_LABEL); - - bindCouplingParameters(); - - bindRotationalParameters(); - - bindTranslationalParameters(); - - transformBuilder.endChoice(); - transformBuilder.selectDictionary(couplingModel.getDictionary()); - - builder.addFill(transformBuilder.removeMargins().getPanel()); - - add(builder.getPanel()); - } - - protected abstract void bindAmiParameters(PanelBuilder builder); - - private void bindCouplingParameters() { - transformBuilder.startDictionary(COUPLING_LABEL, couplingModel); - transformBuilder.endDictionary(); - } - - protected abstract void bindRotationalParameters(); - - private void bindTranslationalParameters() { - transformBuilder.startDictionary(TRANSLATIONAL_LABEL, translationalModel); - transformBuilder.addComponent(SEPARATION_VECTOR_LABEL, translationalModel.bindPoint(SEPARATION_VECTOR_KEY)); - transformBuilder.endDictionary(); - } - - @Override - public BoundaryType getType() { - return BoundaryType.CYCLIC_AMI; - } - - @Override - public Component getPanel() { - return this; - } - - @Override - public void saveToPatch(Patch patch) { - Dictionary cyclicDict = new Dictionary(cyclicModel.getDictionary()); - Dictionary transformDict = new Dictionary(transformBuilder.getSelectedModel().getDictionary()); - transformDict.remove(TYPE); - cyclicDict.merge(transformDict); - - patch.setBoundaryConditions(getAMIBoundaryConditions()); - Dictionary oldPatchDict = new Dictionary(patch.getDictionary()); - Dictionary oldPatchCyclicDict = extractCyclicDict(oldPatchDict); - oldPatchCyclicDict.merge(cyclicDict); - patch.setDictionary(oldPatchCyclicDict); - - updateNeighbourPatchDictionary(patch.getName(), oldPatchDict, cyclicDict); - } - - protected Dictionary extractCyclicDict(Dictionary dictionary) { - Dictionary cyclicDict = new Dictionary(dictionary); - cyclicDict.remove(TRANSFORM_KEY); - cyclicDict.remove(SEPARATION_VECTOR_KEY); - cyclicDict.remove(ROTATION_AXIS_KEY); - cyclicDict.remove(ROTATION_CENTRE_KEY); - return cyclicDict; - } - - protected Dictionary extractTransformDict(Dictionary dictionary) { - Dictionary transformDict = new Dictionary(""); - if (dictionary.found(TRANSFORM_KEY)) { - transformDict.add(TRANSFORM_KEY, dictionary.lookup(TRANSFORM_KEY)); - } - if (dictionary.found(SEPARATION_VECTOR_KEY)) { - transformDict.add(SEPARATION_VECTOR_KEY, dictionary.lookup(SEPARATION_VECTOR_KEY)); - } - if (dictionary.found(ROTATION_AXIS_KEY)) { - transformDict.add(ROTATION_AXIS_KEY, dictionary.lookup(ROTATION_AXIS_KEY)); - } - if (dictionary.found(ROTATION_CENTRE_KEY)) { - transformDict.add(ROTATION_CENTRE_KEY, dictionary.lookup(ROTATION_CENTRE_KEY)); - } - switch (dictionary.lookup(TRANSFORM_KEY)) { - case COUPLING_KEY: - transformDict.add(TYPE, COUPLING_LABEL); - break; - case ROTATIONAL_KEY: - transformDict.add(TYPE, ROTATIONAL_LABEL); - break; - case TRANSLATIONAL_KEY: - transformDict.add(TYPE, TRANSLATIONAL_LABEL); - break; - default: - transformDict.add(TYPE, COUPLING_LABEL); - break; - } - return transformDict; - } - - private BoundaryConditions getAMIBoundaryConditions() { - BoundaryConditions boundaryConditions = new BoundaryConditions(); - for (Field field : model.getFields().values()) { - if (field.getFieldType() == FieldType.SCALAR) { - boundaryConditions.add(field.getName(), new Dictionary(AMI_BOUNDARY_CONDITION)); - } else { - boundaryConditions.add(field.getName(), new Dictionary(AMI_BOUNDARY_CONDITION_VECTOR)); - } - } - return boundaryConditions; - } - - private void updateNeighbourPatchDictionary(String patchName, Dictionary oldDict, Dictionary newDict) { - Patch neighbourPatch = model.getPatches().patchesToDisplay().toMap().get(newDict.lookup(NEIGHBOUR_PATCH_KEY)); - if (neighbourPatch != null) { - fixPreviousRelatedNeighbourPatches(patchName, neighbourPatch.getName()); - setNeighbourPatchToAMI(patchName, newDict, neighbourPatch); - } else if (isAlreadyCyclicAMIWithoutNeighbour(oldDict)) { - JOptionPane.showMessageDialog(UiUtil.getActiveWindow(), "No Neighbour Patch selected!\n", "Cyclic AMI Warning", JOptionPane.WARNING_MESSAGE); - } - } - - private void fixPreviousRelatedNeighbourPatches(String patchName, String neighbourPatchName) { - for (Patch p : model.getPatches().patchesToDisplay()) { - if (isRelatedPatch(p, patchName, neighbourPatchName)) { - setToDefaultType(p); - } - } - } - - private void setToDefaultType(Patch p) { - p.setPhisicalType(BoundaryType.getDefaultType()); - p.setBoundaryConditions(new BoundaryConditions(BoundaryConditionsDefaults.get(BoundaryType.getDefaultKey()))); - p.setDictionary(new Dictionary("")); - } - - private void setNeighbourPatchToAMI(String patchName, Dictionary newDict, Patch neighbourPatch) { - neighbourPatch.setBoundaryConditions(getAMIBoundaryConditions()); - neighbourPatch.setPhisicalType(BoundaryType.CYCLIC_AMI); - if (newDict.found(SEPARATION_VECTOR_KEY)) { - invertSeparationVector(newDict); - } - neighbourPatch.getDictionary().merge(newDict); - neighbourPatch.getDictionary().add(NEIGHBOUR_PATCH_KEY, patchName); - } - - private boolean isAlreadyCyclicAMIWithoutNeighbour(Dictionary dict) { - boolean notNull = dict != null; - boolean isCyclicAMI = dict.found(TYPE) && dict.lookup(TYPE).equals(CYCLIC_AMI_KEY); - boolean withoutNeighbour = dict.found(NEIGHBOUR_PATCH_KEY) && dict.lookup(NEIGHBOUR_PATCH_KEY).equals(""); - return notNull && isCyclicAMI && withoutNeighbour; - } - - private boolean isRelatedPatch(Patch p, String patchName, String neighbourPatchName) { - boolean isNotCurrentOrNeighbourPatch = !p.getName().equals(patchName) && !p.getName().equals(neighbourPatchName); - boolean isAMI = p.getPhisicalType().isCyclicAMI(); - boolean hasNeighbour = p.getDictionary() != null && p.getDictionary().found(NEIGHBOUR_PATCH_KEY); - if (hasNeighbour) { - boolean neighbourEqualsCurrentPatch = p.getDictionary().lookup(NEIGHBOUR_PATCH_KEY).equals(patchName); - boolean neighbourEqualsNeighbourPatch = p.getDictionary().lookup(NEIGHBOUR_PATCH_KEY).equals(neighbourPatchName); - return (isNotCurrentOrNeighbourPatch && isAMI && hasNeighbour && (neighbourEqualsCurrentPatch || neighbourEqualsNeighbourPatch)); - } - return false; - } - - private void invertSeparationVector(Dictionary d) { - String[] sepVector = d.lookupArray(SEPARATION_VECTOR_KEY); - StringBuilder sb = new StringBuilder("("); - for (String value : sepVector) { - double doubleValue = Double.parseDouble(value); - sb.append(-doubleValue + " "); - } - sb.append(")"); - d.add(SEPARATION_VECTOR_KEY, sb.toString()); - } - - @Override - public void stateChanged() { - } - - @Override - public void addMomentumPanel(ParametersPanel momentumPanel) { - } - - @Override - public void addTurbulencePanel(ParametersPanel momentumPanel) { - } - - @Override - public void addThermalPanel(ParametersPanel momentumPanel) { - } - - @Override - public void addPanel(String name, ParametersPanel pPanel) { - } - - @Override - public void addPanel(String name, ParametersPanel pPanel, int index) { - } - - @Override - public ParametersPanel getMomentumPanel() { - return null; - } - - @Override - public ParametersPanel getTurbulencePanel() { - return null; - } - - @Override - public ParametersPanel getThermalPanel() { - return null; - } - - @Override - public ParametersPanel getPanel(String name) { - return null; - } -} diff --git a/src/eu/engys/gui/casesetup/boundaryconditions/BoundaryConditionsPanel.java b/src/eu/engys/gui/casesetup/boundaryconditions/panels/BoundaryConditionsPanel.java similarity index 76% rename from src/eu/engys/gui/casesetup/boundaryconditions/BoundaryConditionsPanel.java rename to src/eu/engys/gui/casesetup/boundaryconditions/panels/BoundaryConditionsPanel.java index c5d7408..974eda0 100644 --- a/src/eu/engys/gui/casesetup/boundaryconditions/BoundaryConditionsPanel.java +++ b/src/eu/engys/gui/casesetup/boundaryconditions/panels/BoundaryConditionsPanel.java @@ -1,31 +1,31 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.gui.casesetup.boundaryconditions.panels; -package eu.engys.gui.casesetup.boundaryconditions; - +import static eu.engys.gui.casesetup.boundaryconditions.parameterspanel.AbstractCyclicAMISettingsPanel.NEIGHBOUR_PATCH_KEY; import static eu.engys.util.ui.ComponentsFactory.selectField; import static eu.engys.util.ui.ComponentsFactory.stringField; @@ -46,7 +46,6 @@ import javax.swing.JComponent; import javax.swing.JLabel; import javax.swing.JPanel; -import eu.engys.core.dictionary.Dictionary; import eu.engys.core.modules.ApplicationModule; import eu.engys.core.modules.ModulesUtil; import eu.engys.core.modules.boundaryconditions.BoundaryTypePanel; @@ -74,14 +73,14 @@ public class BoundaryConditionsPanel extends AbstractGUIPanel implements IBounda private JPanel centerPanel; private final Set panels; - private Map panelsByType = new HashMap(); + private Map panelsByType = new HashMap<>(); private StringField patchNameField; private SelectField patchTypeField; private BoundaryType activeBoundaryType; - private SelectBoundaryConditionAction selectBoundaryConditionListener; + private SelectBoundaryConditionTypeAction selectBoundaryConditionListener; private BoundaryConditionsTreeNodeManager treeNodeManager; private PropertyChangeListener listener; @@ -149,7 +148,7 @@ public class BoundaryConditionsPanel extends AbstractGUIPanel implements IBounda patchTypeField = selectField(); patchTypeField.setSelectedIndex(-1); patchTypeField.setEnabled(false); - selectBoundaryConditionListener = new SelectBoundaryConditionAction(patchTypeField); + selectBoundaryConditionListener = new SelectBoundaryConditionTypeAction(patchTypeField); patchTypeField.addActionListener(selectBoundaryConditionListener); } @@ -169,10 +168,10 @@ public class BoundaryConditionsPanel extends AbstractGUIPanel implements IBounda patchNameField.addPropertyChangeListener(listener); } - class SelectBoundaryConditionAction implements ActionListener { + class SelectBoundaryConditionTypeAction implements ActionListener { private JComboBox patchTypeField; - public SelectBoundaryConditionAction(JComboBox patchTypeField) { + public SelectBoundaryConditionTypeAction(JComboBox patchTypeField) { this.patchTypeField = patchTypeField; } @@ -185,22 +184,21 @@ public class BoundaryConditionsPanel extends AbstractGUIPanel implements IBounda if (patches.length > 0) { for (Patch patch : patches) { fixAMIPatch(patch); + patch.setPhysicalType(boundaryType); patch.setBoundaryConditions(new BoundaryConditions(defaults)); - patch.setPhisicalType(boundaryType); } } activateBoundaryMesh(patches); treeNodeManager.getSelectionHandler().handleSelection(false, (Object[]) patches); + model.boundaryTypeChanged(boundaryType); } private void fixAMIPatch(Patch patch) { - if (patch.getPhisicalType().isCyclicAMI() && patch.getDictionary().found("neighbourPatch")) { - String neighboutPatchName = patch.getDictionary().lookup("neighbourPatch"); + if (patch.getPhysicalType().isCyclicAMI() && patch.getDictionary().found(NEIGHBOUR_PATCH_KEY)) { + String neighbourPatchName = patch.getDictionary().lookup(NEIGHBOUR_PATCH_KEY); for (Patch p : model.getPatches().filterProcBoundary()) { - if (p.getName().equals(neighboutPatchName)) { - p.setPhisicalType(BoundaryType.getDefaultType()); - p.setBoundaryConditions(new BoundaryConditions(BoundaryConditionsDefaults.get(BoundaryType.getDefaultKey()))); - p.setDictionary(new Dictionary("")); + if (p.getName().equals(neighbourPatchName)) { + p.resetToDefault(); } } } @@ -232,8 +230,10 @@ public class BoundaryConditionsPanel extends AbstractGUIPanel implements IBounda if (patches.length > 0) { patchTypeField.setEnabled(true); if (patchesAreOfTheSameType(patches)) { - patchTypeField.setSelectedItem(patches[0].getPhisicalType().getKey()); + patchTypeField.setSelectedItem(patches[0].getPhysicalType().isEditable() ? patches[0].getPhysicalType().getKey() : null); + patchTypeField.setEnabled(patches[0].getPhysicalType().isEditable()); } else { + patchTypeField.setEnabled(areEditable(patches)); patchTypeField.setSelectedItem(null); } } else { @@ -243,12 +243,21 @@ public class BoundaryConditionsPanel extends AbstractGUIPanel implements IBounda patchTypeField.addActionListener(selectBoundaryConditionListener); } + private boolean areEditable(Patch[] patches) { + for (Patch patch : patches) { + if (!patch.getPhysicalType().isEditable()) { + return false; + } + } + return true; + } + private boolean patchesAreOfTheSameType(Patch[] patches) { BoundaryType type = null; for (Patch patch : patches) { if (type == null) - type = patch.getPhisicalType(); - else if (patch.getPhisicalType() != type) + type = patch.getPhysicalType(); + else if (patch.getPhysicalType() != type) return false; } @@ -257,13 +266,14 @@ public class BoundaryConditionsPanel extends AbstractGUIPanel implements IBounda private void activateBoundaryMesh(Patch[] patches) { if (patches.length > 0) { - BoundaryType boundaryType = patchesAreOfTheSameType(patches) ? patches[0].getPhisicalType() : null; + BoundaryType boundaryType = patchesAreOfTheSameType(patches) ? patches[0].getPhysicalType() : null; if (boundaryType != null) { if (boundaryType.hasBoundaryConditions()) { // System.out.println("BoundaryConditionsPanel.activateBoundaryMesh() " // + patches[0].getBoundaryConditions().toDictionary()); centerPanelLayout.show(centerPanel, boundaryType.getKey()); + panelsByType.get(boundaryType).resetToDefault(); panelsByType.get(boundaryType).loadFromPatches(patches); } else { centerPanelLayout.show(centerPanel, "other"); @@ -316,9 +326,10 @@ public class BoundaryConditionsPanel extends AbstractGUIPanel implements IBounda } public void savePatch(Patch patch) { - patch.setPhisicalType(activeBoundaryType); + patch.setPhysicalType(activeBoundaryType); if (panelsByType.containsKey(activeBoundaryType)) { panelsByType.get(activeBoundaryType).saveToPatch(patch); + ModulesUtil.saveToBoundaryConditions(modules, patch.getBoundaryConditions()); } else { patch.setBoundaryConditions(null); } diff --git a/src/eu/engys/gui/casesetup/boundaryconditions/BoundaryConditionsTreeNodeManager.java b/src/eu/engys/gui/casesetup/boundaryconditions/panels/BoundaryConditionsTreeNodeManager.java similarity index 83% rename from src/eu/engys/gui/casesetup/boundaryconditions/BoundaryConditionsTreeNodeManager.java rename to src/eu/engys/gui/casesetup/boundaryconditions/panels/BoundaryConditionsTreeNodeManager.java index 2195174..968ab7c 100644 --- a/src/eu/engys/gui/casesetup/boundaryconditions/BoundaryConditionsTreeNodeManager.java +++ b/src/eu/engys/gui/casesetup/boundaryconditions/panels/BoundaryConditionsTreeNodeManager.java @@ -1,29 +1,28 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - -package eu.engys.gui.casesetup.boundaryconditions; +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.gui.casesetup.boundaryconditions.panels; import static eu.engys.core.dictionary.Dictionary.TYPE; @@ -93,7 +92,7 @@ public class BoundaryConditionsTreeNodeManager extends DefaultTreeNodeManager getColumnClass(int columnIndex) { + return Double.class; + } + + @Override + public boolean isCellEditable(int row, int column) { + return true; + } + }; + return tableModel; + } + + @Override + protected TimeBlocks convertTableDataToTimeBlocks() { + TimeBlocks tbs = new TimeBlocks(); + for (int row = 0; row < table.getRowCount(); row++) { + TimeBlock timeBlock = new TimeBlock(((Double) table.getValueAt(row, 0))); + timeBlock.getUnitsMap().put(VALUE_VAR, new DoubleTimeBlockUnit(VALUE_VAR, ((Double) table.getValueAt(row, 1)))); + tbs.add(timeBlock); + } + return tbs; + } + + @Override + public void saveOnDialogClose() { + TableModel tableModel = table.getModel(); + Double[][] data = new Double[tableModel.getRowCount()][tableModel.getColumnCount()]; + for (int row = 0; row < tableModel.getRowCount(); row++) { + for (int col = 0; col < tableModel.getColumnCount(); col++) { + // use table here because it is ordered + data[row][col] = (Double) table.getValueAt(row, col); + } + } + this.data = data; + } + + // public void save(Dictionary dictionary) { + // String value = toPrimitive(); + // dictionary.add(key, value); + // } + + public void save(Dictionary dictionary) { + StartWithFinder finder = new StartWithFinder(key); + String value = toPrimitive(); + if (dictionary.found(finder)) { + String foundedKey = dictionary.findKey(finder); + dictionary.add(foundedKey, value); + } else { + dictionary.add(key + " table", value); + } + } + + @Override + protected String toPrimitive() { + StringBuilder sb = new StringBuilder(); + sb.append("( "); + if (data != null) { + for (int i = 0; i < data.length; i++) { + Double[] row = data[i]; + Double time = row[0].doubleValue(); + Double value = row[1].doubleValue(); + sb.append("( " + time + " " + value + " ) "); + } + sb.append(")"); + } + return sb.toString(); + } + + @Override + protected Double[][] toObject(String tableData) { + List rows = new ArrayList<>(); + if (tableData.startsWith("(") && tableData.endsWith(")")) { + tableData = tableData.substring(1, tableData.length() - 1).trim(); + try { + Pattern regex = Pattern.compile(SCALAR_PATTERN); + Matcher regexMatcher = regex.matcher(tableData); + while (regexMatcher.find()) { + rows.add(parseRows(regexMatcher.group(0))); + } + } catch (PatternSyntaxException ex) { + logger.error("Parsing error: {}", ex.getMessage()); + } + } + return rows.toArray(new Double[0][0]); + } + + private Double[] parseRows(String row) { + Pattern innerRegex = Pattern.compile(DOUBLE); + Matcher innerRegexMatcher = innerRegex.matcher(row); + Double[] values = new Double[2]; + int internalCount = 0; + while (innerRegexMatcher.find()) { + values[internalCount++] = Double.parseDouble(innerRegexMatcher.group(0)); + } + return values; + } + +} diff --git a/src/eu/engys/gui/casesetup/boundaryconditions/panels/GeneralTensorTable.java b/src/eu/engys/gui/casesetup/boundaryconditions/panels/GeneralTensorTable.java new file mode 100644 index 0000000..10dabf4 --- /dev/null +++ b/src/eu/engys/gui/casesetup/boundaryconditions/panels/GeneralTensorTable.java @@ -0,0 +1,181 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.gui.casesetup.boundaryconditions.panels; + +import static eu.engys.util.RegexpUtils.ATMOSPHERIC_PATTERN; +import static eu.engys.util.RegexpUtils.DOUBLE; + +import java.util.ArrayList; +import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import java.util.regex.PatternSyntaxException; + +import javax.swing.table.DefaultTableModel; +import javax.swing.table.TableModel; + +import org.apache.commons.lang.ArrayUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import eu.engys.core.dictionary.Dictionary; +import eu.engys.core.dictionary.parser.ListField2; +import eu.engys.core.modules.AbstractChart; +import eu.engys.core.project.system.monitoringfunctionobjects.TimeBlocks; +import eu.engys.gui.casesetup.DictionaryTableAndChartPanel; + +public class GeneralTensorTable extends DictionaryTableAndChartPanel { + + private static final Logger logger = LoggerFactory.getLogger(GeneralTensorTable.class); + + public static final String DISTANCE_M_LABEL = "Distance [m]"; + public static final String VALUE_VAR = "Value"; + + public static final String TITLE = "General Table"; + + private String[] columnNames; + private String key; + + public GeneralTensorTable(String key, String label, String[] columnNames) { + super(label, label, DISTANCE_M_LABEL, "", true, columnNames); + this.key = key; + this.columnNames = columnNames; + } + + @Override + protected AbstractChart createChart(String domainAxisLabel, String rangeAxisLabel) { + return null; + } + + public void load(Dictionary dictionary) { + if (dictionary.found(key)) { + if (dictionary.isList2(key)) { + // // Fix for alpha1 which is read with DictionaryReader2 + this.data = toObject(ListField2.convertToString(dictionary.getList2(key))); + } else { + this.data = toObject(dictionary.lookup(key).trim()); + } + } + loadTableAndChart(); + } + + @Override + protected Object[] getEmptyRowData() { + return new Object[] { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }; + } + + @Override + protected TableModel createTableModel() { + DefaultTableModel tableModel = new DefaultTableModel(data, ArrayUtils.add(columnNames, 0, DISTANCE_M_LABEL)) { + @Override + public Class getColumnClass(int columnIndex) { + return Double.class; + } + + @Override + public boolean isCellEditable(int row, int column) { + return true; + } + }; + return tableModel; + } + + @Override + protected TimeBlocks convertTableDataToTimeBlocks() { + TimeBlocks tbs = new TimeBlocks(); + return tbs; + } + + @Override + public void saveOnDialogClose() { + TableModel tableModel = table.getModel(); + Double[][] data = new Double[tableModel.getRowCount()][tableModel.getColumnCount()]; + for (int row = 0; row < tableModel.getRowCount(); row++) { + for (int col = 0; col < tableModel.getColumnCount(); col++) { + // use table here because it is ordered + data[row][col] = (Double) table.getValueAt(row, col); + } + } + this.data = data; + } + + public void save(Dictionary dictionary) { + String value = toPrimitive(); + dictionary.add(key, value); + } + + @Override + protected String toPrimitive() { + StringBuilder sb = new StringBuilder(); + sb.append("( "); + if(data != null){ + for (int i = 0; i < data.length; i++) { + Double[] row = data[i]; + Double time = row[0].doubleValue(); + + Double xx = row[1].doubleValue(); + Double xy = row[2].doubleValue(); + Double xz = row[3].doubleValue(); + Double yy = row[4].doubleValue(); + Double yz = row[5].doubleValue(); + Double zz = row[6].doubleValue(); + + sb.append("( " + time + " ( " + xx + " " + xy + " " + xz + " " + yy + " " + yz + " " + zz + " ) ) "); + } + } + sb.append(")"); + return sb.toString(); + } + + @Override + protected Double[][] toObject(String tableData) { + List rows = new ArrayList<>(); + if (tableData.startsWith("(") && tableData.endsWith(")")) { + tableData = tableData.substring(1, tableData.length() - 1).trim(); + try { + Pattern regex = Pattern.compile(ATMOSPHERIC_PATTERN); + Matcher regexMatcher = regex.matcher(tableData); + while (regexMatcher.find()) { + rows.add(parseRows(regexMatcher.group(0))); + } + } catch (PatternSyntaxException ex) { + logger.error("Parsing error: {}", ex.getMessage()); + } + } + return rows.toArray(new Double[0][0]); + } + + private Double[] parseRows(String row) { + Pattern innerRegex = Pattern.compile(DOUBLE); + Matcher innerRegexMatcher = innerRegex.matcher(row); + Double[] values = new Double[7]; + int internalCount = 0; + while (innerRegexMatcher.find()) { + values[internalCount++] = Double.parseDouble(innerRegexMatcher.group(0)); + } + return values; + } + +} diff --git a/src/eu/engys/gui/casesetup/boundaryconditions/panels/MomentumParametersPanel.java b/src/eu/engys/gui/casesetup/boundaryconditions/panels/MomentumParametersPanel.java deleted file mode 100644 index cb2a1d7..0000000 --- a/src/eu/engys/gui/casesetup/boundaryconditions/panels/MomentumParametersPanel.java +++ /dev/null @@ -1,60 +0,0 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - - -package eu.engys.gui.casesetup.boundaryconditions.panels; - -import eu.engys.core.dictionary.Dictionary; -import eu.engys.core.modules.boundaryconditions.BoundaryTypePanel; -import eu.engys.core.project.Model; -import eu.engys.core.project.zero.patches.BoundaryConditions; - -public abstract class MomentumParametersPanel extends AbstractParametersPanel { - - public MomentumParametersPanel(BoundaryTypePanel parent) { - super(parent); - } - - @Override - public String getTitle() { - return "Momentum"; - } - - public boolean isEnabled(Model model) { - return true; - } - - @Override - public void loadFromBoundaryConditions(String patchName, BoundaryConditions bc) { - Dictionary dictionary = bc.getMomentum(); - loadFromDictionary(dictionary); - } - - @Override - public void saveToBoundaryConditions(String patchName, BoundaryConditions bc) { - Dictionary dictionary = bc.getMomentum(); - saveToDictionary(dictionary); - } -} diff --git a/src/eu/engys/gui/casesetup/boundaryconditions/panels/NonUniformComboBoxController.java b/src/eu/engys/gui/casesetup/boundaryconditions/panels/NonUniformComboBoxController.java new file mode 100644 index 0000000..87afab4 --- /dev/null +++ b/src/eu/engys/gui/casesetup/boundaryconditions/panels/NonUniformComboBoxController.java @@ -0,0 +1,70 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.gui.casesetup.boundaryconditions.panels; + +import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.DATA_KEY; +import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.FILE_KEY; +import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.FILE_NAME_KEY; + +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +import eu.engys.core.dictionary.Dictionary; +import eu.engys.core.dictionary.model.DictionaryModel; +import eu.engys.core.dictionary.model.DictionaryModel.DictionaryError; +import eu.engys.core.dictionary.model.DictionaryModel.DictionaryListener; +import eu.engys.util.ui.builder.JComboBoxController; + +public class NonUniformComboBoxController extends JComboBoxController { + private DictionaryModel model; + + public NonUniformComboBoxController(DictionaryModel model) { + super(); + this.model = model; + model.addDictionaryListener(new DictionaryListener() { + @Override + public void dictionaryChanged() throws DictionaryError { + Dictionary dict = NonUniformComboBoxController.this.model.getDictionary(); + if (dict != null && dict.found(FILE_NAME_KEY) && dict.lookup(FILE_NAME_KEY).length() > 2) { + setSelectedKey(FILE_KEY); + } else { + setSelectedKey(DATA_KEY); + } + } + }); + addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + Dictionary dict = NonUniformComboBoxController.this.model.getDictionary(); + String key = getSelectedKey(); + if (key.equals(DATA_KEY) && dict.found(FILE_NAME_KEY)) { + dict.remove(FILE_NAME_KEY); + } else if (key.equals(FILE_KEY) && !dict.found(FILE_NAME_KEY)) { + dict.add(FILE_NAME_KEY, "\"\""); + } + } + }); + } +} \ No newline at end of file diff --git a/src/eu/engys/gui/casesetup/boundaryconditions/panels/PhaseParametersPanel.java b/src/eu/engys/gui/casesetup/boundaryconditions/panels/PhaseParametersPanel.java deleted file mode 100644 index 75a7320..0000000 --- a/src/eu/engys/gui/casesetup/boundaryconditions/panels/PhaseParametersPanel.java +++ /dev/null @@ -1,63 +0,0 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - - -package eu.engys.gui.casesetup.boundaryconditions.panels; - -import eu.engys.core.dictionary.Dictionary; -import eu.engys.core.modules.boundaryconditions.BoundaryTypePanel; -import eu.engys.core.project.Model; -import eu.engys.core.project.state.State; -import eu.engys.core.project.zero.patches.BoundaryConditions; - -public abstract class PhaseParametersPanel extends AbstractParametersPanel { - - public PhaseParametersPanel(BoundaryTypePanel parent) { - super(parent); - } - - @Override - public String getTitle() { - return AbstractBoundaryTypePanel.PHASE_FRACTION; - } - - public boolean isEnabled(Model model) { - State state = model.getState(); - return state.getMultiphaseModel().isMultiphase(); - } - - @Override - public void saveToBoundaryConditions(String patchName, BoundaryConditions bc) { - Dictionary dictionary = bc.getPhase(); - saveToDictionary(dictionary); - } - - @Override - public void loadFromBoundaryConditions(String patchName, BoundaryConditions bc) { - Dictionary dictionary = bc.getPhase(); - loadFromDictionary(dictionary); - } - -} diff --git a/src/eu/engys/gui/casesetup/boundaryconditions/panels/ScalarNonUniformInterpolationTable.java b/src/eu/engys/gui/casesetup/boundaryconditions/panels/ScalarNonUniformInterpolationTable.java new file mode 100644 index 0000000..db0f3a7 --- /dev/null +++ b/src/eu/engys/gui/casesetup/boundaryconditions/panels/ScalarNonUniformInterpolationTable.java @@ -0,0 +1,193 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.gui.casesetup.boundaryconditions.panels; + +import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.DATA_KEY; +import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.FILE_NAME_KEY; +import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.INTERPOLATION_TABLE_NAME; +import static eu.engys.util.RegexpUtils.DOUBLE; +import static eu.engys.util.RegexpUtils.SCALAR_PATTERN; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import java.util.regex.PatternSyntaxException; + +import javax.swing.table.DefaultTableModel; +import javax.swing.table.TableModel; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import eu.engys.core.dictionary.Dictionary; +import eu.engys.core.dictionary.parser.ListField2; +import eu.engys.core.modules.AbstractChart; +import eu.engys.core.project.system.monitoringfunctionobjects.TimeBlock; +import eu.engys.core.project.system.monitoringfunctionobjects.TimeBlocks; +import eu.engys.gui.casesetup.DictionaryTableAndChartPanel; +import eu.engys.gui.casesetup.boundaryconditions.charts.SimpleHistoryChart; +import eu.engys.gui.solver.postprocessing.data.DoubleTimeBlockUnit; + +public class ScalarNonUniformInterpolationTable extends DictionaryTableAndChartPanel { + + private static final Logger logger = LoggerFactory.getLogger(ScalarNonUniformInterpolationTable.class); + + public static final String DISTANCE_M_LABEL = "Distance [m]"; + public static final String VALUE_VAR = "Value"; + + public static final String TITLE = "Interpolation Table"; + + private String columnName; + + public ScalarNonUniformInterpolationTable(String[] columnNames) { + super(TITLE, INTERPOLATION_TABLE_NAME, DISTANCE_M_LABEL, "", true, columnNames); + this.columnName = columnNames[0]; + } + + @Override + protected AbstractChart createChart(String domainAxisLabel, String rangeAxisLabel) { + AbstractChart chart = new SimpleHistoryChart(Arrays.asList(new String[] { VALUE_VAR }), domainAxisLabel, rangeAxisLabel); + chart.layoutComponents(); + return chart; + } + + public void load(Dictionary dictionary) { + if (dictionary.found(DATA_KEY)) { + if (dictionary.isList2(DATA_KEY)) { + // // Fix for alpha1 which is read with DictionaryReader2 + this.data = toObject(ListField2.convertToString(dictionary.getList2(DATA_KEY))); + } else { + this.data = toObject(dictionary.lookup(DATA_KEY).trim()); + } + } + loadTableAndChart(); + } + + @Override + protected Object[] getEmptyRowData() { + return new Object[] { 0.0, 0.0 }; + } + + @Override + protected TableModel createTableModel() { + DefaultTableModel tableModel = new DefaultTableModel(data, new String[] { DISTANCE_M_LABEL, columnName }) { + @Override + public Class getColumnClass(int columnIndex) { + return Double.class; + } + + @Override + public boolean isCellEditable(int row, int column) { + return true; + } + }; + return tableModel; + } + + @Override + protected TimeBlocks convertTableDataToTimeBlocks() { + TimeBlocks tbs = new TimeBlocks(); + for (int row = 0; row < table.getRowCount(); row++) { + TimeBlock timeBlock = new TimeBlock(((Double) table.getValueAt(row, 0))); + timeBlock.getUnitsMap().put(VALUE_VAR, new DoubleTimeBlockUnit(VALUE_VAR, ((Double) table.getValueAt(row, 1)))); + tbs.add(timeBlock); + } + return tbs; + } + + @Override + public void saveOnDialogClose() { + TableModel tableModel = table.getModel(); + Double[][] data = new Double[tableModel.getRowCount()][tableModel.getColumnCount()]; + for (int row = 0; row < tableModel.getRowCount(); row++) { + for (int col = 0; col < tableModel.getColumnCount(); col++) { + // use table here because it is ordered + data[row][col] = (Double) table.getValueAt(row, col); + } + } + this.data = data; + } + + public void save(Dictionary dictionary) { + String value = toPrimitive(); + dictionary.add(DATA_KEY, value); + dictionary.remove(FILE_NAME_KEY); + } + + @Override + protected String toPrimitive() { + StringBuilder sb = new StringBuilder(); + sb.append("( "); + for (int i = 0; i < data.length; i++) { + Double[] row = data[i]; + Double time = row[0].doubleValue(); + Double value = row[1].doubleValue(); + sb.append("( " + time + " " + value + " ) "); + } + sb.append(")"); + return sb.toString(); + } + + @Override + protected Double[][] toObject(String tableData) { + List rows = new ArrayList<>(); + if (tableData.startsWith("(") && tableData.endsWith(")")) { + tableData = tableData.substring(1, tableData.length() - 1).trim(); + if (!tableData.isEmpty()) { + try { + Pattern regex = Pattern.compile(SCALAR_PATTERN); + Matcher regexMatcher = regex.matcher(tableData); + if (regexMatcher.find()) { + regexMatcher.reset(); + while (regexMatcher.find()) { + rows.add(parseRows(regexMatcher.group(0))); + } + } else { + logger.error("Parsing error: pattern not found for {}", tableData); + } + } catch (PatternSyntaxException ex) { + logger.error("Parsing error: {}", ex.getMessage()); + } + } + } else { + logger.error("Parsing error: {} does not start with '('", tableData); + } + return rows.toArray(new Double[0][0]); + } + + private Double[] parseRows(String row) { + Pattern innerRegex = Pattern.compile(DOUBLE); + Matcher innerRegexMatcher = innerRegex.matcher(row); + Double[] values = new Double[2]; + int internalCount = 0; + while (innerRegexMatcher.find()) { + values[internalCount++] = Double.parseDouble(innerRegexMatcher.group(0)); + } + return values; + } + +} diff --git a/src/eu/engys/gui/casesetup/boundaryconditions/panels/ScalarTimeVaryingInterpolationTable.java b/src/eu/engys/gui/casesetup/boundaryconditions/panels/ScalarTimeVaryingInterpolationTable.java new file mode 100644 index 0000000..3909537 --- /dev/null +++ b/src/eu/engys/gui/casesetup/boundaryconditions/panels/ScalarTimeVaryingInterpolationTable.java @@ -0,0 +1,203 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.gui.casesetup.boundaryconditions.panels; + +import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.INTERPOLATION_TABLE_NAME; +import static eu.engys.util.RegexpUtils.DOUBLE; +import static eu.engys.util.RegexpUtils.SCALAR_PATTERN; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import java.util.regex.PatternSyntaxException; + +import javax.swing.table.DefaultTableModel; +import javax.swing.table.TableModel; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import eu.engys.core.dictionary.DefaultElement; +import eu.engys.core.dictionary.Dictionary; +import eu.engys.core.dictionary.FieldElement; +import eu.engys.core.dictionary.StartWithFinder; +import eu.engys.core.dictionary.parser.ListField2; +import eu.engys.core.modules.AbstractChart; +import eu.engys.core.project.system.monitoringfunctionobjects.TimeBlock; +import eu.engys.core.project.system.monitoringfunctionobjects.TimeBlocks; +import eu.engys.gui.casesetup.DictionaryTableAndChartPanel; +import eu.engys.gui.casesetup.boundaryconditions.charts.SimpleHistoryChart; +import eu.engys.gui.solver.postprocessing.data.DoubleTimeBlockUnit; + +public class ScalarTimeVaryingInterpolationTable extends DictionaryTableAndChartPanel { + + private static final Logger logger = LoggerFactory.getLogger(ScalarTimeVaryingInterpolationTable.class); + + public static final String TIME_STEP_LABEL = "Time Step [s]"; + public static final String VALUE_VAR = "Value"; + + public static final String TITLE = "Interpolation Table"; + + private String columnName; + public ScalarTimeVaryingInterpolationTable(String[] columnNames) { + super(TITLE, INTERPOLATION_TABLE_NAME, TIME_STEP_LABEL, "", true, columnNames); + this.columnName = columnNames[0]; + } + + @Override + protected AbstractChart createChart(String domainAxisLabel, String rangeAxisLabel) { + AbstractChart chart = new SimpleHistoryChart(Arrays.asList(new String[] { VALUE_VAR }), domainAxisLabel, rangeAxisLabel); + chart.layoutComponents(); + return chart; + } + + public void load(Dictionary dictionary, String key) { + StartWithFinder finder = new StartWithFinder(key); + if (dictionary.found(finder)) { + DefaultElement element = dictionary.lookup(finder); + if (element instanceof FieldElement) { + FieldElement fieldElement = (FieldElement) element; + this.data = toObject(fieldElement.getValue()); + } else if (element instanceof ListField2) { + // // Fix for alpha1 which is read with DictionaryReader2 + ListField2 listElement = (ListField2) element; + this.data = toObject(ListField2.convertToString(listElement)); + } + } + loadTableAndChart(); + } + + @Override + protected Object[] getEmptyRowData() { + return new Object[] { 0.0, 0.0 }; + } + + @Override + protected TableModel createTableModel() { + DefaultTableModel tableModel = new DefaultTableModel(data, new String[] { TIME_STEP_LABEL, columnName }) { + @Override + public Class getColumnClass(int columnIndex) { + return Double.class; + } + + @Override + public boolean isCellEditable(int row, int column) { + return true; + } + }; + return tableModel; + } + + @Override + protected TimeBlocks convertTableDataToTimeBlocks() { + TimeBlocks tbs = new TimeBlocks(); + for (int row = 0; row < table.getRowCount(); row++) { + TimeBlock timeBlock = new TimeBlock(((Double) table.getValueAt(row, 0))); + timeBlock.getUnitsMap().put(VALUE_VAR, new DoubleTimeBlockUnit(VALUE_VAR, ((Double) table.getValueAt(row, 1)))); + tbs.add(timeBlock); + } + return tbs; + } + + @Override + public void saveOnDialogClose() { + TableModel tableModel = table.getModel(); + Double[][] data = new Double[tableModel.getRowCount()][tableModel.getColumnCount()]; + for (int row = 0; row < tableModel.getRowCount(); row++) { + for (int col = 0; col < tableModel.getColumnCount(); col++) { + // use table here because it is ordered + data[row][col] = (Double) table.getValueAt(row, col); + } + } + this.data = data; + } + + public void save(Dictionary dictionary, String key) { + StartWithFinder finder = new StartWithFinder(key); + String value = toPrimitive(); + if(dictionary.found(finder)){ + String foundedKey = dictionary.findKey(finder); + dictionary.add(foundedKey, value); + } else { + dictionary.add(key, value); + } + } + + @Override + protected String toPrimitive() { + StringBuilder sb = new StringBuilder(); + sb.append("( "); + for (int i = 0; i < data.length; i++) { + Double[] row = data[i]; + Double time = row[0].doubleValue(); + Double value = row[1].doubleValue(); + sb.append("( " + time + " " + value + " ) "); + } + sb.append(")"); + return sb.toString(); + } + + @Override + protected Double[][] toObject(String tableData) { + List rows = new ArrayList<>(); + if (tableData.startsWith("(") && tableData.endsWith(")")) { + tableData = tableData.substring(1, tableData.length() - 1).trim(); + if (!tableData.isEmpty()) { + try { + Pattern regex = Pattern.compile(SCALAR_PATTERN); + Matcher regexMatcher = regex.matcher(tableData); + if (regexMatcher.find()) { + regexMatcher.reset(); + while (regexMatcher.find()) { + rows.add(parseRows(regexMatcher.group(0))); + } + } else { + logger.error("Parsing error: pattern not found for {}", tableData); + } + + } catch (PatternSyntaxException ex) { + logger.error("Parsing error: {}", ex.getMessage()); + } + } + } else { + logger.error("Parsing error: {} does not start with '('", tableData); + } + return rows.toArray(new Double[0][0]); + } + + private Double[] parseRows(String row) { + Pattern innerRegex = Pattern.compile(DOUBLE); + Matcher innerRegexMatcher = innerRegex.matcher(row); + Double[] values = new Double[2]; + int internalCount = 0; + while (innerRegexMatcher.find()) { + values[internalCount++] = Double.parseDouble(innerRegexMatcher.group(0)); + } + return values; + } + +} diff --git a/src/eu/engys/gui/casesetup/boundaryconditions/panels/StandardCyclicAMISettingsPanel.java b/src/eu/engys/gui/casesetup/boundaryconditions/panels/StandardCyclicAMISettingsPanel.java index 139ee3f..efa27cf 100644 --- a/src/eu/engys/gui/casesetup/boundaryconditions/panels/StandardCyclicAMISettingsPanel.java +++ b/src/eu/engys/gui/casesetup/boundaryconditions/panels/StandardCyclicAMISettingsPanel.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.casesetup.boundaryconditions.panels; @@ -37,6 +36,7 @@ import eu.engys.core.dictionary.Dictionary; import eu.engys.core.project.Model; import eu.engys.core.project.zero.patches.Patch; import eu.engys.gui.ListBuilderFactory; +import eu.engys.gui.casesetup.boundaryconditions.parameterspanel.AbstractCyclicAMISettingsPanel; import eu.engys.util.ui.builder.PanelBuilder; public class StandardCyclicAMISettingsPanel extends AbstractCyclicAMISettingsPanel { @@ -80,7 +80,7 @@ public class StandardCyclicAMISettingsPanel extends AbstractCyclicAMISettingsPan transformBuilder.selectDictionary(transformDict); } else { cyclicModel.setDictionary(new Dictionary(CYCLIC_AMI_OS)); - transformBuilder.selectDictionary(couplingModel.getDictionary()); + transformBuilder.selectDictionary(new Dictionary(couplingModel.getDictionary())); } } } diff --git a/src/eu/engys/gui/casesetup/boundaryconditions/panels/ThermalParametersPanel.java b/src/eu/engys/gui/casesetup/boundaryconditions/panels/ThermalParametersPanel.java deleted file mode 100644 index 3df271f..0000000 --- a/src/eu/engys/gui/casesetup/boundaryconditions/panels/ThermalParametersPanel.java +++ /dev/null @@ -1,54 +0,0 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - - -package eu.engys.gui.casesetup.boundaryconditions.panels; - -import eu.engys.core.modules.boundaryconditions.BoundaryTypePanel; -import eu.engys.core.project.Model; -import eu.engys.core.project.state.State; -import eu.engys.core.project.zero.patches.BoundaryConditions; - -public abstract class ThermalParametersPanel extends AbstractParametersPanel { - - public ThermalParametersPanel(BoundaryTypePanel parent) { - super(parent); - } - - @Override - public String getTitle() { - return "Thermal"; - } - - public boolean isEnabled(Model model) { - State state = model.getState(); - return state.isEnergy(); - } - - @Override - public void saveToBoundaryConditions(String patchName, BoundaryConditions bc) { - saveToDictionary(bc.getThermal()); - } -} diff --git a/src/eu/engys/gui/casesetup/boundaryconditions/panels/TimeVaryingComboBoxController.java b/src/eu/engys/gui/casesetup/boundaryconditions/panels/TimeVaryingComboBoxController.java new file mode 100644 index 0000000..d6350fa --- /dev/null +++ b/src/eu/engys/gui/casesetup/boundaryconditions/panels/TimeVaryingComboBoxController.java @@ -0,0 +1,128 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.gui.casesetup.boundaryconditions.panels; + +import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.DATA_KEY; +import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.FILE_KEY; +import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.TABLE_FILE_KEY; +import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.TABLE_KEY; +import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.isTableFile; + +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +import eu.engys.core.dictionary.Dictionary; +import eu.engys.core.dictionary.StartWithFinder; +import eu.engys.core.dictionary.model.DictionaryModel; +import eu.engys.core.dictionary.model.DictionaryModel.DictionaryError; +import eu.engys.core.dictionary.model.DictionaryModel.DictionaryListener; +import eu.engys.util.ui.builder.JComboBoxController; + +public class TimeVaryingComboBoxController extends JComboBoxController { + + private DictionaryModel model; + + /* + * Note: + * - if I use from file dictionary the key is "uniformValue" + * - if I use from table dictionary the key can be: + * + "uniformValue table" + * + "uniformValue table " + */ + + public TimeVaryingComboBoxController(DictionaryModel model, String dictionaryKey) { + super(); + this.model = model; + model.addDictionaryListener(new TableOrFileListener(dictionaryKey)); + addActionListener(new FixListener(dictionaryKey)); + } + + static void fixData(String dictionaryKey, Dictionary dict) { + // remove from file entry if present + if (dict.found(dictionaryKey)) { + dict.remove(dictionaryKey); + } + + // add empty table if no table specified + if (dict.found(new StartWithFinder(dictionaryKey))) { + //do nothing, data already in place + } else { + dict.add(dictionaryKey + " " + TABLE_KEY, "()"); +// dict.add(dictionaryKey, TABLE_KEY + " ()"); + } + } + + static void fixFile(String dictionaryKey, Dictionary dict) { + if(dict.found(dictionaryKey)){ + //do nothing, data already in place + } else { + // remove from table entry if present + if(dict.found(new StartWithFinder(dictionaryKey))){ + dict.remove(new StartWithFinder(dictionaryKey)); + } + // add empty from file + dict.add(dictionaryKey, TABLE_FILE_KEY); + } + } + + private class TableOrFileListener implements DictionaryListener { + + private String dictionaryKey; + + public TableOrFileListener(String dictionaryKey) { + this.dictionaryKey = dictionaryKey; + } + + @Override + public void dictionaryChanged() throws DictionaryError { + Dictionary dict = TimeVaryingComboBoxController.this.model.getDictionary(); + if (isTableFile(dict, dictionaryKey)) { + setSelectedKey(FILE_KEY); + } else { + setSelectedKey(DATA_KEY); + } + } + } + + private class FixListener implements ActionListener { + + private String dictionaryKey; + + public FixListener(String dictionaryKey) { + this.dictionaryKey = dictionaryKey; + } + + @Override + public void actionPerformed(ActionEvent e) { + Dictionary dict = TimeVaryingComboBoxController.this.model.getDictionary(); + String key = getSelectedKey(); + if (key.equals(DATA_KEY)) { + fixData(dictionaryKey, dict); + } else if (key.equals(FILE_KEY)) { + fixFile(dictionaryKey, dict); + } + } + } +} \ No newline at end of file diff --git a/src/eu/engys/gui/casesetup/boundaryconditions/panels/TurbulenceParametersPanel.java b/src/eu/engys/gui/casesetup/boundaryconditions/panels/TurbulenceParametersPanel.java deleted file mode 100644 index 2b011e4..0000000 --- a/src/eu/engys/gui/casesetup/boundaryconditions/panels/TurbulenceParametersPanel.java +++ /dev/null @@ -1,81 +0,0 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - - -package eu.engys.gui.casesetup.boundaryconditions.panels; - -import static eu.engys.gui.casesetup.boundaryconditions.utils.TurbulenceUtils.setKEpsilon; -import static eu.engys.gui.casesetup.boundaryconditions.utils.TurbulenceUtils.setKEquationEddy; -import static eu.engys.gui.casesetup.boundaryconditions.utils.TurbulenceUtils.setKOmega; -import static eu.engys.gui.casesetup.boundaryconditions.utils.TurbulenceUtils.setSpalartAllmaras; -import eu.engys.core.dictionary.Dictionary; -import eu.engys.core.modules.boundaryconditions.BoundaryTypePanel; -import eu.engys.core.project.Model; -import eu.engys.core.project.TurbulenceModelType; -import eu.engys.core.project.state.State; -import eu.engys.core.project.zero.patches.BoundaryConditions; - -public abstract class TurbulenceParametersPanel extends AbstractParametersPanel { - - public static final String TURBULENCE = "Turbulence"; - private TurbulenceModelType type; - - public TurbulenceParametersPanel(BoundaryTypePanel parent) { - super(parent); - } - - @Override - public String getTitle() { - return TURBULENCE; - } - - public boolean isEnabled(Model model) { - State state = model.getState(); - return (state.getTurbulenceModel() != null && state.getTurbulenceModel().getType() != TurbulenceModelType.LAMINAR); - } - - @Override - public void stateChanged(Model model) { - TurbulenceModelType type = model.getState().getTurbulenceModel().getType(); - if (this.type == null || this.type != type) { - this.type = type; - if (type.isKepsilon()) { - setKEpsilon(builder); - } else if (type.isKomega()) { - setKOmega(builder); - } else if (type.isSpalartAllmaras()) { - setSpalartAllmaras(builder); - } else if (type.isKEquationeddy()) { - setKEquationEddy(builder); - } - } - } - - @Override - public void saveToBoundaryConditions(String patchName, BoundaryConditions bc) { - Dictionary dictionary = bc.getTurbulence(); - saveToDictionary(dictionary); - } -} diff --git a/src/eu/engys/gui/casesetup/boundaryconditions/panels/VectorNonUniformInterpolationTable.java b/src/eu/engys/gui/casesetup/boundaryconditions/panels/VectorNonUniformInterpolationTable.java new file mode 100644 index 0000000..adf5dc5 --- /dev/null +++ b/src/eu/engys/gui/casesetup/boundaryconditions/panels/VectorNonUniformInterpolationTable.java @@ -0,0 +1,197 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.gui.casesetup.boundaryconditions.panels; + +import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.DATA_KEY; +import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.FILE_NAME_KEY; +import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.INTERPOLATION_TABLE_NAME; +import static eu.engys.util.RegexpUtils.DOUBLE; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import java.util.regex.PatternSyntaxException; + +import javax.swing.table.DefaultTableModel; +import javax.swing.table.TableModel; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import eu.engys.core.dictionary.Dictionary; +import eu.engys.core.dictionary.parser.ListField2; +import eu.engys.core.modules.AbstractChart; +import eu.engys.core.project.system.monitoringfunctionobjects.TimeBlock; +import eu.engys.core.project.system.monitoringfunctionobjects.TimeBlocks; +import eu.engys.gui.casesetup.DictionaryTableAndChartPanel; +import eu.engys.gui.casesetup.boundaryconditions.charts.SimpleHistoryChart; +import eu.engys.gui.solver.postprocessing.data.DoubleTimeBlockUnit; +import eu.engys.util.RegexpUtils; + +public class VectorNonUniformInterpolationTable extends DictionaryTableAndChartPanel { + + private static final Logger logger = LoggerFactory.getLogger(VectorNonUniformInterpolationTable.class); + + public static final String DISTANCE_M_LABEL = "Distance [m]"; + public static final String X_VAR = "X"; + public static final String Y_VAR = "Y"; + public static final String Z_VAR = "Z"; + + public static final String TITLE = "Interpolation Table"; + + private String[] columnNames; + public VectorNonUniformInterpolationTable(String[] columnNames) { + super(TITLE, INTERPOLATION_TABLE_NAME, DISTANCE_M_LABEL, "", true, columnNames); + this.columnNames = columnNames; + } + + @Override + protected AbstractChart createChart(String domainAxisLabel, String rangeAxisLabel) { + AbstractChart chart = new SimpleHistoryChart(Arrays.asList(new String[] { X_VAR, Y_VAR, Z_VAR }), domainAxisLabel, rangeAxisLabel); + chart.layoutComponents(); + return chart; + } + + public void load(Dictionary dictionary) { + if (dictionary.found(DATA_KEY)) { + if (dictionary.isList2(DATA_KEY)) { + // Fix for alpha1 which is read with DictionaryReader2 + this.data = toObject(ListField2.convertToString(dictionary.getList2(DATA_KEY))); + } else { + this.data = toObject(dictionary.lookup(DATA_KEY).trim()); + } + } + loadTableAndChart(); + } + + @Override + protected Object[] getEmptyRowData() { + return new Object[] { 0.0, 0.0, 0.0, 0.0 }; + } + + @Override + protected TableModel createTableModel() { + DefaultTableModel tableModel = new DefaultTableModel(data, new String[] { DISTANCE_M_LABEL, columnNames[0], columnNames[1], columnNames[2] }) { + @Override + public Class getColumnClass(int columnIndex) { + return Double.class; + } + + @Override + public boolean isCellEditable(int row, int column) { + return true; + } + }; + return tableModel; + } + + @Override + protected TimeBlocks convertTableDataToTimeBlocks() { + TimeBlocks tbs = new TimeBlocks(); + for (int row = 0; row < table.getRowCount(); row++) { + TimeBlock timeBlock = new TimeBlock(((Double) table.getValueAt(row, 0))); + timeBlock.getUnitsMap().put(X_VAR, new DoubleTimeBlockUnit(X_VAR, ((Double) table.getValueAt(row, 1)))); + timeBlock.getUnitsMap().put(Y_VAR, new DoubleTimeBlockUnit(Y_VAR, ((Double) table.getValueAt(row, 2)))); + timeBlock.getUnitsMap().put(Z_VAR, new DoubleTimeBlockUnit(Z_VAR, ((Double) table.getValueAt(row, 3)))); + tbs.add(timeBlock); + } + return tbs; + } + + @Override + public void saveOnDialogClose() { + Double[][] data = new Double[table.getRowCount()][table.getColumnCount()]; + for (int row = 0; row < table.getRowCount(); row++) { + for (int col = 0; col < table.getColumnCount(); col++) { + // use table here because it is ordered + data[row][col] = (Double) table.getValueAt(row, col); + } + } + this.data = data; + } + + public void save(Dictionary dictionary) { + String value = toPrimitive(); + dictionary.add(DATA_KEY, value); + dictionary.remove(FILE_NAME_KEY); + } + + @Override + protected String toPrimitive() { + StringBuilder sb = new StringBuilder(); + sb.append("( "); + for (int i = 0; i < data.length; i++) { + Double[] row = data[i]; + Double distance = row[0].doubleValue(); + Double x = row[1].doubleValue(); + Double y = row[2].doubleValue(); + Double z = row[3].doubleValue(); + sb.append("( " + distance + " ( " + x + " " + y + " " + z + " ) ) "); + } + sb.append(")"); + return sb.toString(); + } + + @Override + protected Double[][] toObject(String tableData) { + List rows = new ArrayList<>(); + if (tableData.startsWith("(") && tableData.endsWith(")")) { + tableData = tableData.substring(1, tableData.length() - 1).trim(); + if (!tableData.isEmpty()) { + try { + Pattern regex = Pattern.compile(RegexpUtils.VECTOR_PATTERN); + Matcher regexMatcher = regex.matcher(tableData); + if (regexMatcher.find()) { + regexMatcher.reset(); + while (regexMatcher.find()) { + rows.add(parseRows(regexMatcher.group(0))); + } + } else { + logger.error("Parsing error: pattern not found for {}", tableData); + } + } catch (PatternSyntaxException ex) { + logger.error("Parsing error: {}", ex.getMessage()); + } + } + } else { + logger.error("Parsing error: {} does not start with '('", tableData); + } + return rows.toArray(new Double[0][0]); + } + + private Double[] parseRows(String row) { + Pattern innerRegex = Pattern.compile(DOUBLE); + Matcher innerRegexMatcher = innerRegex.matcher(row); + Double[] values = new Double[4]; + int internalCount = 0; + while (innerRegexMatcher.find()) { + values[internalCount++] = Double.parseDouble(innerRegexMatcher.group(0)); + } + return values; + } + +} diff --git a/src/eu/engys/gui/casesetup/boundaryconditions/panels/VectorTimeVaryingInterpolationTable.java b/src/eu/engys/gui/casesetup/boundaryconditions/panels/VectorTimeVaryingInterpolationTable.java new file mode 100644 index 0000000..bd87ea6 --- /dev/null +++ b/src/eu/engys/gui/casesetup/boundaryconditions/panels/VectorTimeVaryingInterpolationTable.java @@ -0,0 +1,208 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.gui.casesetup.boundaryconditions.panels; + +import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.INTERPOLATION_TABLE_NAME; +import static eu.engys.util.RegexpUtils.DOUBLE; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import java.util.regex.PatternSyntaxException; + +import javax.swing.table.DefaultTableModel; +import javax.swing.table.TableModel; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import eu.engys.core.dictionary.DefaultElement; +import eu.engys.core.dictionary.Dictionary; +import eu.engys.core.dictionary.FieldElement; +import eu.engys.core.dictionary.StartWithFinder; +import eu.engys.core.dictionary.parser.ListField2; +import eu.engys.core.modules.AbstractChart; +import eu.engys.core.project.system.monitoringfunctionobjects.TimeBlock; +import eu.engys.core.project.system.monitoringfunctionobjects.TimeBlocks; +import eu.engys.gui.casesetup.DictionaryTableAndChartPanel; +import eu.engys.gui.casesetup.boundaryconditions.charts.SimpleHistoryChart; +import eu.engys.gui.solver.postprocessing.data.DoubleTimeBlockUnit; +import eu.engys.util.RegexpUtils; + +public class VectorTimeVaryingInterpolationTable extends DictionaryTableAndChartPanel { + + private static final Logger logger = LoggerFactory.getLogger(VectorTimeVaryingInterpolationTable.class); + + public static final String TIME_STEP_LABEL = "Time Step [s]"; + private static final String X_VAR = "X"; + private static final String Y_VAR = "Y"; + private static final String Z_VAR = "Z"; + + public static final String TITLE = "Interpolation Table"; + + private String[] columnNames; + + public VectorTimeVaryingInterpolationTable(String[] columnNames) { + super(TITLE, INTERPOLATION_TABLE_NAME, TIME_STEP_LABEL, "", true, columnNames); + this.columnNames = columnNames; + } + + @Override + protected AbstractChart createChart(String domainAxisLabel, String rangeAxisLabel) { + AbstractChart chart = new SimpleHistoryChart(Arrays.asList(new String[] { X_VAR, Y_VAR, Z_VAR }), domainAxisLabel, rangeAxisLabel); + chart.layoutComponents(); + return chart; + } + + public void load(Dictionary dictionary, String key) { + StartWithFinder finder = new StartWithFinder(key); + if (dictionary.found(finder)) { + DefaultElement element = dictionary.lookup(finder); + if (element instanceof FieldElement) { + FieldElement fieldElement = (FieldElement) element; + this.data = toObject(fieldElement.getValue()); + } else if (element instanceof ListField2) { + // // Fix for alpha1 which is read with DictionaryReader2 + ListField2 listElement = (ListField2) element; + this.data = toObject(ListField2.convertToString(listElement)); + } + } + loadTableAndChart(); + } + + @Override + protected Object[] getEmptyRowData() { + return new Object[] { 0.0, 0.0, 0.0, 0.0 }; + } + + @Override + protected TableModel createTableModel() { + DefaultTableModel tableModel = new DefaultTableModel(data, new String[] { TIME_STEP_LABEL, columnNames[0], columnNames[1], columnNames[2] }) { + @Override + public Class getColumnClass(int columnIndex) { + return Double.class; + } + + @Override + public boolean isCellEditable(int row, int column) { + return true; + } + }; + return tableModel; + } + + @Override + protected TimeBlocks convertTableDataToTimeBlocks() { + TimeBlocks tbs = new TimeBlocks(); + for (int row = 0; row < table.getRowCount(); row++) { + TimeBlock timeBlock = new TimeBlock(((Double) table.getValueAt(row, 0))); + timeBlock.getUnitsMap().put(X_VAR, new DoubleTimeBlockUnit(X_VAR, ((Double) table.getValueAt(row, 1)))); + timeBlock.getUnitsMap().put(Y_VAR, new DoubleTimeBlockUnit(Y_VAR, ((Double) table.getValueAt(row, 2)))); + timeBlock.getUnitsMap().put(Z_VAR, new DoubleTimeBlockUnit(Z_VAR, ((Double) table.getValueAt(row, 3)))); + tbs.add(timeBlock); + } + return tbs; + } + + @Override + public void saveOnDialogClose() { + Double[][] data = new Double[table.getRowCount()][table.getColumnCount()]; + for (int row = 0; row < table.getRowCount(); row++) { + for (int col = 0; col < table.getColumnCount(); col++) { + // use table here because it is ordered + data[row][col] = (Double) table.getValueAt(row, col); + } + } + this.data = data; + } + + public void save(Dictionary dictionary, String key) { + StartWithFinder finder = new StartWithFinder(key); + String value = toPrimitive(); + if (dictionary.found(finder)) { + String foundedKey = dictionary.findKey(finder); + dictionary.add(foundedKey, value); + } else { + dictionary.add(key, value); + } + } + + @Override + protected String toPrimitive() { + StringBuilder sb = new StringBuilder(); + sb.append("( "); + for (int i = 0; i < data.length; i++) { + Double[] row = data[i]; + Double distance = row[0].doubleValue(); + Double x = row[1].doubleValue(); + Double y = row[2].doubleValue(); + Double z = row[3].doubleValue(); + sb.append("( " + distance + " ( " + x + " " + y + " " + z + " ) ) "); + } + sb.append(")"); + return sb.toString(); + } + + @Override + protected Double[][] toObject(String tableData) { + List rows = new ArrayList<>(); + if (tableData.startsWith("(") && tableData.endsWith(")")) { + tableData = tableData.substring(1, tableData.length() - 1).trim(); + if (!tableData.isEmpty()) { + try { + Pattern regex = Pattern.compile(RegexpUtils.VECTOR_PATTERN); + Matcher regexMatcher = regex.matcher(tableData); + if (regexMatcher.find()) { + regexMatcher.reset(); + while (regexMatcher.find()) { + rows.add(parseRows(regexMatcher.group(0))); + } + } else { + logger.error("Parsing error: pattern not found for {}", tableData); + } + } catch (PatternSyntaxException ex) { + logger.error("Parsing error: {}", ex.getMessage()); + } + } + } else { + logger.error("Parsing error: '{}' does not start/end with '(' or ')' ", tableData); + } + return rows.toArray(new Double[0][0]); + } + + private Double[] parseRows(String row) { + Pattern innerRegex = Pattern.compile(DOUBLE); + Matcher innerRegexMatcher = innerRegex.matcher(row); + Double[] values = new Double[4]; + int internalCount = 0; + while (innerRegexMatcher.find()) { + values[internalCount++] = Double.parseDouble(innerRegexMatcher.group(0)); + } + return values; + } + +} diff --git a/src/eu/engys/gui/casesetup/boundaryconditions/panels/patch/MomentumPatch.java b/src/eu/engys/gui/casesetup/boundaryconditions/panels/patch/MomentumPatch.java index 99c9a18..bbed6f8 100644 --- a/src/eu/engys/gui/casesetup/boundaryconditions/panels/patch/MomentumPatch.java +++ b/src/eu/engys/gui/casesetup/boundaryconditions/panels/patch/MomentumPatch.java @@ -1,39 +1,38 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.casesetup.boundaryconditions.panels.patch; +import static eu.engys.core.project.constant.ThermophysicalProperties.GAMMA_KEY; import static eu.engys.core.project.zero.fields.Fields.P; import static eu.engys.core.project.zero.fields.Fields.U; import static eu.engys.gui.casesetup.boundaryconditions.factories.PressureFactory.fixedFluxPressure; import static eu.engys.gui.casesetup.boundaryconditions.factories.PressureFactory.fixedValuePressure; import static eu.engys.gui.casesetup.boundaryconditions.factories.PressureFactory.fixedValuePressure_COMP; import static eu.engys.gui.casesetup.boundaryconditions.factories.PressureFactory.freestreamPressure; +import static eu.engys.gui.casesetup.boundaryconditions.factories.PressureFactory.totalPressure; import static eu.engys.gui.casesetup.boundaryconditions.factories.PressureFactory.zeroGradientPressure; -import static eu.engys.gui.casesetup.boundaryconditions.factories.StandardPressureFactory.totalPressure; import static eu.engys.gui.casesetup.boundaryconditions.factories.VelocityFactory.cylindricalInletVelocity; import static eu.engys.gui.casesetup.boundaryconditions.factories.VelocityFactory.fixedValueVelocity; import static eu.engys.gui.casesetup.boundaryconditions.factories.VelocityFactory.freestreamVelocity; @@ -47,11 +46,32 @@ import static eu.engys.gui.casesetup.boundaryconditions.factories.VelocityFactor import static eu.engys.gui.casesetup.boundaryconditions.factories.VelocityFactory.variableHeightFlowRateInletVelocity; import static eu.engys.gui.casesetup.boundaryconditions.factories.VelocityFactory.volumetricFlowRateInletVelocity; import static eu.engys.gui.casesetup.boundaryconditions.factories.VelocityFactory.zeroGradientVelocity; +import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.CYLINDRICAL_INLET_VELOCITY_LABEL; +import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.FIXED_FLUX_PRESSURE_LABEL; +import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.FIXED_VALUE_LABEL; +import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.FREESTREAM_LABEL; +import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.FREESTREAM_PRESSURE_LABEL; +import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.GAMMA_LABEL; +import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.INLET_OUTLET_VELOCITY_LABEL; +import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.INLET_VALUE_LABEL; +import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.MASS_FLOW_RATE_INLET_LABEL; import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.MASS_FLOW_RATE_KEY; +import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.PRESSURE_COMP_LABEL; +import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.PRESSURE_DIRECTED_INLET_OUTLET_VELOCITY_LABEL; +import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.PRESSURE_DIRECTED_INLET_VELOCITY_LABEL; +import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.PRESSURE_INCOMP_LABEL; +import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.PRESSURE_INLET_OUTLET_VELOCITY_LABEL; +import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.PRESSURE_INLET_VELOCITY_LABEL; +import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.PRESSURE_TYPE_LABEL; +import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.SURFACE_NORMAL_FIXED_VALUE_LABEL; +import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.TOTAL_PRESSURE_LABEL; +import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.VARIABLE_HEIGHT_FLOW_RATE_INLET_LABEL; +import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.VELOCITY_MAGNITUDE_LABEL; +import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.VELOCITY_TYPE_LABEL; +import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.VOLUMETRIC_FLOW_RATE_INLET_LABEL; import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.VOLUMETRIC_FLOW_RATE_KEY; +import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.ZERO_GRADIENT_LABEL; import static eu.engys.util.Symbols.CUBE; -import static eu.engys.util.Symbols.M2_S2; -import static eu.engys.util.Symbols.PASCAL; import javax.swing.BorderFactory; import javax.swing.JLabel; @@ -63,33 +83,13 @@ import eu.engys.core.dictionary.model.DictionaryPanelBuilder; import eu.engys.core.modules.boundaryconditions.BoundaryTypePanel; import eu.engys.core.project.Model; import eu.engys.core.project.zero.patches.BoundaryConditions; -import eu.engys.gui.casesetup.boundaryconditions.panels.MomentumParametersPanel; +import eu.engys.gui.casesetup.boundaryconditions.parameterspanel.MomentumParametersPanel; import eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils; -import eu.engys.util.Symbols; import eu.engys.util.ui.builder.JComboBoxController; import eu.engys.util.ui.textfields.DoubleField; public class MomentumPatch extends MomentumParametersPanel { - public static final String TOTAL_PRESSURE_LABEL = "Total Pressure"; - public static final String INLET_OUTLET_VELOCITY_LABEL = "Inlet Outlet Velocity"; - public static final String FREESTREAM_LABEL = "Freestream"; - public static final String PRESSURE_DIRECTED_INLET_OUTLET_VELOCITY_LABEL = "Pressure Directed Inlet Outlet Velocity"; - public static final String PRESSURE_INLET_OUTLET_VELOCITY_LABEL = "Pressure Inlet Outlet Velocity"; - public static final String PRESSURE_DIRECTED_INLET_VELOCITY_LABEL = "Pressure Directed Inlet Velocity"; - public static final String PRESSURE_INLET_VELOCITY_LABEL = "Pressure Inlet Velocity"; - public static final String VOLUMETRIC_FLOW_RATE_INLET_LABEL = "Volumetric Flow Rate Inlet"; - public static final String VARIABLE_HEIGHT_FLOW_RATE_INLET_LABEL = "Variable Height Flow Rate Inlet"; - public static final String MASS_FLOW_RATE_INLET_LABEL = "Mass Flow Rate Inlet"; - public static final String SURFACE_NORMAL_FIXED_VALUE_LABEL = "Surface Normal Fixed Value"; - public static final String CYLINDRICAL_INLET_VELOCITY_LABEL = "Cylindrical Inlet Velocity"; - public static final String FIXED_VALUE_LABEL = "Fixed Value"; - public static final String ZERO_GRADIENT_LABEL = "Zero Gradient"; - public static final String FREESTREAM_PRESSURE_LABEL = "Freestream Pressure"; - public static final String FIXED_FLUX_PRESSURE_LABEL = "Fixed Flux Pressure"; - public static final String PRESSURE_COMP = "Pressure " + PASCAL; - public static final String PRESSURE_INCOMP = "Pressure " + M2_S2; - private DictionaryPanelBuilder velocityBuilder; private JComboBoxController velocityTypeChoice; @@ -189,7 +189,7 @@ public class MomentumPatch extends MomentumParametersPanel { resetToDefault(null); /* VELOCITY */ velocityBuilder = new DictionaryPanelBuilder(); - velocityTypeChoice = (JComboBoxController) velocityBuilder.startChoice("Velocity Type"); + velocityTypeChoice = (JComboBoxController) velocityBuilder.startChoice(VELOCITY_TYPE_LABEL); buildFixedValueVelocity(); buildCylindricalInletVelocity(); @@ -208,7 +208,7 @@ public class MomentumPatch extends MomentumParametersPanel { /* PRESSURE */ pressureBuilder = new DictionaryPanelBuilder(); - pressureChoice = (JComboBoxController) pressureBuilder.startChoice("Pressure Type"); + pressureChoice = (JComboBoxController) pressureBuilder.startChoice(PRESSURE_TYPE_LABEL); buildFixedValuePressure(); buildTotalPressure(); buildFreestreamPressure(); @@ -242,7 +242,7 @@ public class MomentumPatch extends MomentumParametersPanel { private void buildSurfaceNormalFixedValue() { velocityBuilder.startDictionary(SURFACE_NORMAL_FIXED_VALUE_LABEL, surfaceNormalFixedValuemodel); - velocityBuilder.addComponent("Velocity Magnitude " + Symbols.M_S, surfaceNormalFixedValuemodel.bindUniformDouble("refValue", -Double.MAX_VALUE, 0, 0)); + velocityBuilder.addComponent(VELOCITY_MAGNITUDE_LABEL, surfaceNormalFixedValuemodel.bindUniformDouble("refValue", -Double.MAX_VALUE, 0, 0)); velocityBuilder.endDictionary(); } @@ -294,7 +294,7 @@ public class MomentumPatch extends MomentumParametersPanel { public void buildInletOutlet() { velocityBuilder.startDictionary(INLET_OUTLET_VELOCITY_LABEL, inletOutletVelocityModel); - velocityBuilder.addComponent("Inlet Value", inletOutletVelocityModel.bindUniformPoint("inletValue")); + velocityBuilder.addComponent(INLET_VALUE_LABEL, inletOutletVelocityModel.bindUniformPoint("inletValue")); velocityBuilder.endDictionary(); } @@ -307,7 +307,7 @@ public class MomentumPatch extends MomentumParametersPanel { * PRESSURE */ private void buildFixedValuePressure() { - fixedPressureLabel = new JLabel(PRESSURE_INCOMP); + fixedPressureLabel = new JLabel(PRESSURE_INCOMP_LABEL); fixedPressureField = fixedValuePressureModel.bindUniformDouble("value"); pressureBuilder.startDictionary(FIXED_VALUE_LABEL, fixedValuePressureModel); pressureBuilder.addComponent(fixedPressureLabel, fixedPressureField); @@ -315,10 +315,11 @@ public class MomentumPatch extends MomentumParametersPanel { } private void buildTotalPressure() { - totalPressureLabel = new JLabel(PRESSURE_INCOMP); + totalPressureLabel = new JLabel(PRESSURE_INCOMP_LABEL); pressureBuilder.startDictionary(TOTAL_PRESSURE_LABEL, totalPressureModel); totalPressureField = totalPressureModel.bindUniformDouble("p0"); pressureBuilder.addComponent(totalPressureLabel, totalPressureField); + pressureBuilder.addComponent(GAMMA_LABEL, totalPressureModel.bindDouble(GAMMA_KEY)); pressureBuilder.endDictionary(); } @@ -342,7 +343,7 @@ public class MomentumPatch extends MomentumParametersPanel { */ @Override - public void loadFromBoundaryConditions(String patchName, BoundaryConditions bc) { + public void loadFromBoundaryConditions(BoundaryConditions bc) { Dictionary dictionary = bc.getMomentum(); if (dictionary.subDict(U) != null) { @@ -367,7 +368,7 @@ public class MomentumPatch extends MomentumParametersPanel { } @Override - public void saveToBoundaryConditions(String patchName, BoundaryConditions bc) { + public void saveToBoundaryConditions(BoundaryConditions bc) { Dictionary momentum = bc.getMomentum(); DictionaryModel velocityModel = velocityBuilder.getSelectedModel(); DictionaryModel pressureModel = pressureBuilder.getSelectedModel(); @@ -387,21 +388,21 @@ public class MomentumPatch extends MomentumParametersPanel { velocityTypeChoice.clearDisabledIndexes(); if (model.getState() != null && model.getState().isCompressible()) { - fixedPressureLabel.setText(PRESSURE_COMP); - totalPressureLabel.setText(PRESSURE_COMP); + fixedPressureLabel.setText(PRESSURE_COMP_LABEL); + totalPressureLabel.setText(PRESSURE_COMP_LABEL); - fixedPressureField.setName(PRESSURE_COMP); - totalPressureField.setName(PRESSURE_COMP); + fixedPressureField.setName(PRESSURE_COMP_LABEL); + totalPressureField.setName(PRESSURE_COMP_LABEL); velocityTypeChoice.clearDisabledIndexes(); velocityTypeChoice.addDisabledItem(VOLUMETRIC_FLOW_RATE_INLET_LABEL); } else { - fixedPressureLabel.setText(PRESSURE_INCOMP); - totalPressureLabel.setText(PRESSURE_INCOMP); + fixedPressureLabel.setText(PRESSURE_INCOMP_LABEL); + totalPressureLabel.setText(PRESSURE_INCOMP_LABEL); - fixedPressureField.setName(PRESSURE_INCOMP); - totalPressureField.setName(PRESSURE_INCOMP); + fixedPressureField.setName(PRESSURE_INCOMP_LABEL); + totalPressureField.setName(PRESSURE_INCOMP_LABEL); velocityTypeChoice.addDisabledItem(MASS_FLOW_RATE_INLET_LABEL); } diff --git a/src/eu/engys/gui/casesetup/boundaryconditions/panels/patch/PatchSettingsPanel.java b/src/eu/engys/gui/casesetup/boundaryconditions/panels/patch/PatchSettingsPanel.java index 92699b0..34f4f12 100644 --- a/src/eu/engys/gui/casesetup/boundaryconditions/panels/patch/PatchSettingsPanel.java +++ b/src/eu/engys/gui/casesetup/boundaryconditions/panels/patch/PatchSettingsPanel.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.casesetup.boundaryconditions.panels.patch; @@ -30,14 +29,13 @@ import javax.inject.Inject; import eu.engys.core.project.Model; import eu.engys.core.project.zero.patches.BoundaryType; -import eu.engys.gui.casesetup.boundaryconditions.panels.AbstractBoundaryTypePanel; +import eu.engys.gui.casesetup.boundaryconditions.parameterspanel.AbstractBoundaryTypePanel; public class PatchSettingsPanel extends AbstractBoundaryTypePanel { @Inject public PatchSettingsPanel(Model model) { super(model); - setName("Turbulence"); } @Override diff --git a/src/eu/engys/gui/casesetup/boundaryconditions/panels/patch/PhasePatch.java b/src/eu/engys/gui/casesetup/boundaryconditions/panels/patch/PhasePatch.java index a7fc777..8e985c8 100644 --- a/src/eu/engys/gui/casesetup/boundaryconditions/panels/patch/PhasePatch.java +++ b/src/eu/engys/gui/casesetup/boundaryconditions/panels/patch/PhasePatch.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.casesetup.boundaryconditions.panels.patch; @@ -30,6 +29,7 @@ import static eu.engys.gui.casesetup.boundaryconditions.factories.StandardPhaseF import static eu.engys.gui.casesetup.boundaryconditions.factories.StandardPhaseFactory.fixedValueVelocity; import static eu.engys.gui.casesetup.boundaryconditions.factories.StandardPhaseFactory.inletOutlet; import static eu.engys.gui.casesetup.boundaryconditions.factories.StandardPhaseFactory.zeroGradient; + import eu.engys.core.dictionary.Dictionary; import eu.engys.core.dictionary.model.DictionaryModel; import eu.engys.core.modules.boundaryconditions.BoundaryTypePanel; @@ -37,7 +37,7 @@ import eu.engys.core.project.Model; import eu.engys.core.project.materials.Materials; import eu.engys.core.project.zero.fields.Fields; import eu.engys.core.project.zero.patches.BoundaryConditions; -import eu.engys.gui.casesetup.boundaryconditions.panels.PhaseParametersPanel; +import eu.engys.gui.casesetup.boundaryconditions.parameterspanel.PhaseParametersPanel; public class PhasePatch extends PhaseParametersPanel { @@ -126,7 +126,7 @@ public class PhasePatch extends PhaseParametersPanel { } @Override - public void loadFromBoundaryConditions(String patchName, BoundaryConditions bc) { + public void loadFromBoundaryConditions(BoundaryConditions bc) { Dictionary dictionary = bc.getPhase(); if (model.getState().getMultiphaseModel().isMultiphase()) { String alphaField = Fields.ALPHA + "." + model.getMaterials().getFirstMaterialName(); diff --git a/src/eu/engys/gui/casesetup/boundaryconditions/panels/patch/ThermalPatch.java b/src/eu/engys/gui/casesetup/boundaryconditions/panels/patch/ThermalPatch.java index 27d0ec3..9f1a370 100644 --- a/src/eu/engys/gui/casesetup/boundaryconditions/panels/patch/ThermalPatch.java +++ b/src/eu/engys/gui/casesetup/boundaryconditions/panels/patch/ThermalPatch.java @@ -1,46 +1,60 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.casesetup.boundaryconditions.panels.patch; +import static eu.engys.core.project.zero.fields.Fields.T; import static eu.engys.gui.casesetup.boundaryconditions.factories.TemperatureFactory.fixedValue; import static eu.engys.gui.casesetup.boundaryconditions.factories.TemperatureFactory.inletOutlet; import static eu.engys.gui.casesetup.boundaryconditions.factories.TemperatureFactory.inletOutletTotalTemperature; import static eu.engys.gui.casesetup.boundaryconditions.factories.TemperatureFactory.totalTemperature; import static eu.engys.gui.casesetup.boundaryconditions.factories.TemperatureFactory.zeroGradient; +import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.COMPRESSIBILITY_LABEL; +import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.FIXED_TEMPERATURE_LABEL; +import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.GAMMA_KEY; +import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.INLET_OUTLET_LABEL; +import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.INLET_OUTLET_TOTAL_TEMPERATURE_LABEL; +import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.INLET_VALUE_KEY; +import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.PSI_KEY; +import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.RATIO_OF_SPECIFIC_HEATS_LABEL; +import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.T0_KEY; +import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.TEMPERATURE_VALUE_K_LABEL; +import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.TOTAL_TEMPERATURE_LABEL; +import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.TYPE_LABEL; +import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.VALUE_KEY; +import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.ZERO_GRADIENT_LABEL; + import eu.engys.core.dictionary.Dictionary; import eu.engys.core.dictionary.model.DictionaryModel; import eu.engys.core.modules.boundaryconditions.BoundaryTypePanel; import eu.engys.core.project.Model; import eu.engys.core.project.zero.patches.BoundaryConditions; -import eu.engys.gui.casesetup.boundaryconditions.panels.ThermalParametersPanel; +import eu.engys.gui.casesetup.boundaryconditions.parameterspanel.ThermalParametersPanel; public class ThermalPatch extends ThermalParametersPanel { - private DictionaryModel fixedTemperatureModel; + private DictionaryModel fixedTemperatureModel; private DictionaryModel totalTemperatureModel; private DictionaryModel inletOutletModel; private DictionaryModel zeroGradientModel; @@ -72,7 +86,7 @@ public class ThermalPatch extends ThermalParametersPanel { public void populatePanel() { resetToDefault(null); - builder.startChoice("Type"); + builder.startChoice(TYPE_LABEL); buildFixedTemperaturePanel(); buildTotalTemperaturePanel(); buildInletOutlet(); @@ -82,43 +96,43 @@ public class ThermalPatch extends ThermalParametersPanel { } private void buildFixedTemperaturePanel() { - builder.startDictionary("Fixed Temperature", fixedTemperatureModel); - builder.addComponent("Temperature Value [K]", fixedTemperatureModel.bindUniformDouble("value")); + builder.startDictionary(FIXED_TEMPERATURE_LABEL, fixedTemperatureModel); + builder.addComponent(TEMPERATURE_VALUE_K_LABEL, fixedTemperatureModel.bindUniformDouble(VALUE_KEY)); builder.endDictionary(); } private void buildTotalTemperaturePanel() { - builder.startDictionary("Total Temperature", totalTemperatureModel); - builder.addComponent("Compressibility", totalTemperatureModel.bindDouble("psi")); - builder.addComponent("Ratio Of Specific Heats", totalTemperatureModel.bindDouble("gamma")); - builder.addComponent("Temperature Value [K]", totalTemperatureModel.bindUniformDouble("T0")); + builder.startDictionary(TOTAL_TEMPERATURE_LABEL, totalTemperatureModel); + builder.addComponent(COMPRESSIBILITY_LABEL, totalTemperatureModel.bindDouble(PSI_KEY)); + builder.addComponent(RATIO_OF_SPECIFIC_HEATS_LABEL, totalTemperatureModel.bindDouble(GAMMA_KEY)); + builder.addComponent(TEMPERATURE_VALUE_K_LABEL, totalTemperatureModel.bindUniformDouble(T0_KEY)); builder.endDictionary(); } private void buildInletOutlet() { - builder.startDictionary("Inlet Outlet", inletOutletModel); - builder.addComponent("Temperature Value [K]", inletOutletModel.bindUniformDouble("value", "inletValue")); + builder.startDictionary(INLET_OUTLET_LABEL, inletOutletModel); + builder.addComponent(TEMPERATURE_VALUE_K_LABEL, inletOutletModel.bindUniformDouble(VALUE_KEY, INLET_VALUE_KEY)); builder.endDictionary(); } private void buildZeroGradient() { - builder.startDictionary("Zero Gradient", zeroGradientModel); + builder.startDictionary(ZERO_GRADIENT_LABEL, zeroGradientModel); builder.endDictionary(); } private void buildInletOutletTotalTemperature() { - builder.startDictionary("Inlet Outlet Total Temperature", inletOutletTotalTemperatureModel); - builder.addComponent("Compressibility", inletOutletTotalTemperatureModel.bindDouble("psi")); - builder.addComponent("Ratio Of Specific Heats", inletOutletTotalTemperatureModel.bindDouble("gamma")); - builder.addComponent("Temperature Value [K]", inletOutletTotalTemperatureModel.bindUniformDouble("T0")); + builder.startDictionary(INLET_OUTLET_TOTAL_TEMPERATURE_LABEL, inletOutletTotalTemperatureModel); + builder.addComponent(COMPRESSIBILITY_LABEL, inletOutletTotalTemperatureModel.bindDouble(PSI_KEY)); + builder.addComponent(RATIO_OF_SPECIFIC_HEATS_LABEL, inletOutletTotalTemperatureModel.bindDouble(GAMMA_KEY)); + builder.addComponent(TEMPERATURE_VALUE_K_LABEL, inletOutletTotalTemperatureModel.bindUniformDouble(T0_KEY)); builder.endDictionary(); } @Override - public void loadFromBoundaryConditions(String patchName, BoundaryConditions bc) { + public void loadFromBoundaryConditions(BoundaryConditions bc) { Dictionary dictionary = bc.getThermal(); - Dictionary T = dictionary.subDict("T"); - builder.selectDictionary(T); + Dictionary tDict = dictionary.subDict(T); + builder.selectDictionary(tDict); } } diff --git a/src/eu/engys/gui/casesetup/boundaryconditions/panels/patch/TurbulencePatch.java b/src/eu/engys/gui/casesetup/boundaryconditions/panels/patch/TurbulencePatch.java index d1c2e8e..41d662e 100644 --- a/src/eu/engys/gui/casesetup/boundaryconditions/panels/patch/TurbulencePatch.java +++ b/src/eu/engys/gui/casesetup/boundaryconditions/panels/patch/TurbulencePatch.java @@ -1,35 +1,34 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.casesetup.boundaryconditions.panels.patch; +import static eu.engys.gui.casesetup.boundaryconditions.factories.StandardTurbulenceFactory.epsilonMixingLength_COMP; +import static eu.engys.gui.casesetup.boundaryconditions.factories.StandardTurbulenceFactory.omegaMixingLength_COMP; import static eu.engys.gui.casesetup.boundaryconditions.factories.TurbulenceFactory.epsilonFixedValue; import static eu.engys.gui.casesetup.boundaryconditions.factories.TurbulenceFactory.epsilonInletOutlet; import static eu.engys.gui.casesetup.boundaryconditions.factories.TurbulenceFactory.epsilonMixingLength; -import static eu.engys.gui.casesetup.boundaryconditions.factories.TurbulenceFactory.epsilonMixingLength_COMP; import static eu.engys.gui.casesetup.boundaryconditions.factories.TurbulenceFactory.epsilonZeroGradient; import static eu.engys.gui.casesetup.boundaryconditions.factories.TurbulenceFactory.kFixedValue; import static eu.engys.gui.casesetup.boundaryconditions.factories.TurbulenceFactory.kInletOutlet; @@ -41,16 +40,18 @@ import static eu.engys.gui.casesetup.boundaryconditions.factories.TurbulenceFact import static eu.engys.gui.casesetup.boundaryconditions.factories.TurbulenceFactory.omegaFixedValue; import static eu.engys.gui.casesetup.boundaryconditions.factories.TurbulenceFactory.omegaInletOutlet; import static eu.engys.gui.casesetup.boundaryconditions.factories.TurbulenceFactory.omegaMixingLength; -import static eu.engys.gui.casesetup.boundaryconditions.factories.TurbulenceFactory.omegaMixingLength_COMP; import static eu.engys.gui.casesetup.boundaryconditions.factories.TurbulenceFactory.omegaZeroGradient; +import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.BY_TURB_INTENSITY_AND_MIXING_LENGTH_LABEL; + import eu.engys.core.dictionary.Dictionary; import eu.engys.core.dictionary.model.DictionaryModel; import eu.engys.core.modules.boundaryconditions.BoundaryTypePanel; import eu.engys.core.project.Model; +import eu.engys.core.project.TurbulenceModelType; import eu.engys.core.project.state.State; import eu.engys.core.project.zero.fields.Fields; import eu.engys.core.project.zero.patches.BoundaryConditions; -import eu.engys.gui.casesetup.boundaryconditions.panels.TurbulenceParametersPanel; +import eu.engys.gui.casesetup.boundaryconditions.parameterspanel.TurbulenceParametersPanel; import eu.engys.gui.casesetup.boundaryconditions.utils.TurbulenceUtils; import eu.engys.util.ui.builder.JComboBoxController; @@ -139,7 +140,7 @@ public class TurbulencePatch extends TurbulenceParametersPanel { builder.endChoice(); } - public void loadFromBoundaryConditions(String patchName, BoundaryConditions bc) { + public void loadFromBoundaryConditions(BoundaryConditions bc) { Dictionary dictionary = bc.getTurbulence(); Dictionary k = dictionary.subDict(Fields.K); Dictionary omega = dictionary.subDict(Fields.OMEGA); @@ -159,13 +160,6 @@ public class TurbulencePatch extends TurbulenceParametersPanel { } } - @Override - public void tabChanged(Model model) { - super.tabChanged(model); - - fixIntensityAndMixingVisibility(model); - } - @Override public void stateChanged(Model model) { super.stateChanged(model); @@ -185,13 +179,43 @@ public class TurbulencePatch extends TurbulenceParametersPanel { private void fixIntensityAndMixingVisibility(Model model) { State state = model.getState(); typeChoice.clearDisabledIndexes(); - if (state.getTurbulenceModel().getType().isSpalartAllmaras()) { - typeChoice.addDisabledItem(TurbulenceUtils.BY_TURB_INTENSITY_AND_MIXING_LENGTH_LABEL); + TurbulenceModelType turbulenceType = state.getTurbulenceModel().getType(); + if (turbulenceType.isSpalartAllmaras()) { + typeChoice.addDisabledItem(BY_TURB_INTENSITY_AND_MIXING_LENGTH_LABEL); } - - if (state.getTurbulenceModel().getType().isKEquationeddy()) { - typeChoice.addDisabledItem(TurbulenceUtils.BY_TURB_INTENSITY_AND_MIXING_LENGTH_LABEL); + if (turbulenceType.isKEquationeddy()) { + typeChoice.addDisabledItem(BY_TURB_INTENSITY_AND_MIXING_LENGTH_LABEL); } } + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + } diff --git a/src/eu/engys/gui/casesetup/boundaryconditions/panels/wall/StandardMomentumWall.java b/src/eu/engys/gui/casesetup/boundaryconditions/panels/wall/StandardMomentumWall.java index f543a22..a7ed42a 100644 --- a/src/eu/engys/gui/casesetup/boundaryconditions/panels/wall/StandardMomentumWall.java +++ b/src/eu/engys/gui/casesetup/boundaryconditions/panels/wall/StandardMomentumWall.java @@ -1,35 +1,57 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.casesetup.boundaryconditions.panels.wall; +import static eu.engys.core.dictionary.Dictionary.TYPE; +import static eu.engys.core.project.zero.fields.Fields.U; import static eu.engys.gui.casesetup.boundaryconditions.factories.VelocityFactory.fixedValueVelocity; +import static eu.engys.gui.casesetup.boundaryconditions.factories.VelocityFactory.movingWallVelocity; import static eu.engys.gui.casesetup.boundaryconditions.factories.VelocityFactory.noSlipWall; import static eu.engys.gui.casesetup.boundaryconditions.factories.VelocityFactory.slipWall; import static eu.engys.gui.casesetup.boundaryconditions.factories.VelocityFactory.standardRotatingWallVelocity; +import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.AXIS_KEY; +import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.AXIS_LABEL; +import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.FIXED_VALUE_KEY; +import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.FIXED_VELOCITY_LABEL; +import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.MOVING_WALL_VELOCITY_KEY; +import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.MOVING_WALL_VELOCITY_LABEL; +import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.NO_SLIP_LABEL; +import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.OMEGA_KEY; +import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.OMEGA_VELOCITY_LABEL; +import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.ORIGIN_KEY; +import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.ORIGIN_LABEL; +import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.ROTATING_WALL_LABEL; +import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.ROTATING_WALL_VELOCITY_KEY; +import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.SLIP_KEY; +import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.SLIP_LABEL; +import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.TYPE_LABEL; +import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.VALUE_KEY; +import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.VELOCITY_TYPE_LABEL; +import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.WALL_TYPE_LABEL; +import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.buildSimpleFixedVelocityPanel; import java.util.Arrays; @@ -39,8 +61,7 @@ import eu.engys.core.dictionary.model.DictionaryPanelBuilder; import eu.engys.core.modules.boundaryconditions.BoundaryTypePanel; import eu.engys.core.project.Model; import eu.engys.core.project.zero.patches.BoundaryConditions; -import eu.engys.gui.casesetup.boundaryconditions.panels.MomentumParametersPanel; -import eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils; +import eu.engys.gui.casesetup.boundaryconditions.parameterspanel.MomentumParametersPanel; public class StandardMomentumWall extends MomentumParametersPanel { @@ -53,6 +74,7 @@ public class StandardMomentumWall extends MomentumParametersPanel { private DictionaryModel slipModel; private DictionaryModel fixedVelocityModel; private DictionaryModel rotatingWallModel; + private DictionaryModel movingWallVelocityModel; public StandardMomentumWall(BoundaryTypePanel parent) { super(parent); @@ -64,6 +86,7 @@ public class StandardMomentumWall extends MomentumParametersPanel { slipModel = new DictionaryModel(); fixedVelocityModel = new DictionaryModel(); rotatingWallModel = new DictionaryModel(); + movingWallVelocityModel = new DictionaryModel(); } @Override @@ -72,12 +95,13 @@ public class StandardMomentumWall extends MomentumParametersPanel { slipModel.setDictionary(new Dictionary(slipWall)); fixedVelocityModel.setDictionary(new Dictionary(fixedValueVelocity)); rotatingWallModel.setDictionary(new Dictionary(standardRotatingWallVelocity)); + movingWallVelocityModel.setDictionary(new Dictionary(movingWallVelocity)); } @Override public void populatePanel() { resetToDefault(null); - builder.startChoice("Type"); + builder.startChoice(TYPE_LABEL); fixedWallPanel(builder); movingWallPanel(builder); builder.endChoice(); @@ -85,12 +109,12 @@ public class StandardMomentumWall extends MomentumParametersPanel { public void fixedWallPanel(DictionaryPanelBuilder builder) { builder.startGroup(FIXED_WALL); - builder.startChoice("Wall Type"); + builder.startChoice(WALL_TYPE_LABEL); - builder.startDictionary("No-slip", noSlipModel); + builder.startDictionary(NO_SLIP_LABEL, noSlipModel); builder.endDictionary(); - builder.startDictionary("Slip", slipModel); + builder.startDictionary(SLIP_LABEL, slipModel); builder.endDictionary(); builder.endChoice(); @@ -99,51 +123,58 @@ public class StandardMomentumWall extends MomentumParametersPanel { public void movingWallPanel(DictionaryPanelBuilder builder) { builder.startGroup(MOVING_WALL); - builder.startChoice("Velocity Type"); + builder.startChoice(VELOCITY_TYPE_LABEL); buildFixedVelocityPanel(builder); buildRotatingWallPanel(builder); + buildMovingWallPanel(builder); builder.endChoice(); builder.endGroup(); } private void buildFixedVelocityPanel(DictionaryPanelBuilder builder) { - builder.startDictionary("Fixed Velocity", fixedVelocityModel); - BoundaryConditionsUtils.buildSimpleFixedVelocityPanel(builder, fixedVelocityModel); + builder.startDictionary(FIXED_VELOCITY_LABEL, fixedVelocityModel); + buildSimpleFixedVelocityPanel(builder, fixedVelocityModel); builder.endDictionary(); } private void buildRotatingWallPanel(DictionaryPanelBuilder builder) { - builder.startDictionary("Rotating Wall", rotatingWallModel); - builder.addComponent("Origin", rotatingWallModel.bindPoint("origin")); - builder.addComponent("Axis", rotatingWallModel.bindPoint("axis")); - builder.addComponent("Omega [rad/s]", rotatingWallModel.bindDouble("omega")); + builder.startDictionary(ROTATING_WALL_LABEL, rotatingWallModel); + builder.addComponent(ORIGIN_LABEL, rotatingWallModel.bindPoint(ORIGIN_KEY)); + builder.addComponent(AXIS_LABEL, rotatingWallModel.bindPoint(AXIS_KEY)); + builder.addComponent(OMEGA_VELOCITY_LABEL, rotatingWallModel.bindDouble(OMEGA_KEY)); builder.endDictionary(); } - public void loadFromBoundaryConditions(String patchName, BoundaryConditions bc) { + private void buildMovingWallPanel(DictionaryPanelBuilder builder) { + builder.startDictionary(MOVING_WALL_VELOCITY_LABEL, movingWallVelocityModel); + builder.endDictionary(); + } + + public void loadFromBoundaryConditions(BoundaryConditions bc) { Dictionary dictionary = bc.getMomentum(); - Dictionary U = dictionary.subDict("U"); - Dictionary p = dictionary.subDict("p"); - if (U != null) { - String U_type = U.lookup("type"); - if (U_type.contains("slip")) { - builder.selectDictionary(U); - } else if (U_type.equals("fixedValue")) { - if (U.found("value")) { - double[] value = U.lookupDoubleArray("value"); + Dictionary uDict = dictionary.subDict(U); +// Dictionary pDict = dictionary.subDict(P); + if (uDict != null) { + String U_type = uDict.lookup(TYPE); + if (U_type.contains(SLIP_KEY)) { + builder.selectDictionary(uDict); + } else if (U_type.equals(FIXED_VALUE_KEY)) { + if (uDict.found(VALUE_KEY)) { + double[] value = uDict.lookupDoubleArray(VALUE_KEY); double[] zeros = new double[] { 0, 0, 0 }; if (Arrays.equals(value, zeros)) { - builder.selectDictionaryByModel(noSlipModel, U); + builder.selectDictionaryByModel(noSlipModel, uDict); } else { - builder.selectDictionaryByModel(fixedVelocityModel, U); + builder.selectDictionaryByModel(fixedVelocityModel, uDict); } } else { } - } else if (U_type.equals("tangentialVelocity") || U_type.equals("timeVaryingUniformFixedValue") || U_type.equals("rotatingWallVelocity") || U_type.equals("wheelVelocity")) { - builder.selectDictionary(U); + } else if (U_type.equals(MOVING_WALL_VELOCITY_KEY) + || U_type.equals(ROTATING_WALL_VELOCITY_KEY)){ + builder.selectDictionary(uDict); } } } diff --git a/src/eu/engys/gui/casesetup/boundaryconditions/panels/wall/StandardThermalWall.java b/src/eu/engys/gui/casesetup/boundaryconditions/panels/wall/StandardThermalWall.java index 4a51b31..4def665 100644 --- a/src/eu/engys/gui/casesetup/boundaryconditions/panels/wall/StandardThermalWall.java +++ b/src/eu/engys/gui/casesetup/boundaryconditions/panels/wall/StandardThermalWall.java @@ -1,52 +1,57 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.casesetup.boundaryconditions.panels.wall; import static eu.engys.gui.casesetup.boundaryconditions.factories.TemperatureFactory.fixedValue; -import static eu.engys.gui.casesetup.boundaryconditions.factories.TemperatureFactory.turbulentHeatFluxTemperatureOCFD_FLUX; import static eu.engys.gui.casesetup.boundaryconditions.factories.TemperatureFactory.turbulentHeatFluxTemperatureOCFD_FLUX_COMP; -import static eu.engys.gui.casesetup.boundaryconditions.factories.TemperatureFactory.turbulentHeatFluxTemperatureOCFD_POWER; import static eu.engys.gui.casesetup.boundaryconditions.factories.TemperatureFactory.turbulentHeatFluxTemperatureOCFD_POWER_COMP; import static eu.engys.gui.casesetup.boundaryconditions.factories.TemperatureFactory.zeroGradient; -import static eu.engys.util.Symbols.SQUARE; +import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.TOTAL_HEAT_LOAD_AT_WALL_W_LABEL; +import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.WALL_HEAT_LABEL; + import eu.engys.core.dictionary.Dictionary; import eu.engys.core.dictionary.model.DictionaryModel; import eu.engys.core.modules.boundaryconditions.BoundaryTypePanel; import eu.engys.core.project.Model; import eu.engys.core.project.state.State; import eu.engys.core.project.zero.patches.BoundaryConditions; -import eu.engys.gui.casesetup.boundaryconditions.panels.ThermalParametersPanel; +import eu.engys.gui.casesetup.boundaryconditions.parameterspanel.ThermalParametersPanel; +import eu.engys.util.ui.builder.JComboBoxController; public class StandardThermalWall extends ThermalParametersPanel { - private DictionaryModel heatPowerModel; + public static final String TOTAL_HEAT_LOAD_LABEL = "Total Heat Load"; + public static final String HEAT_FLUX_LABEL = "Heat Flux"; + public static final String FIXED_TEMPERATURE_LABEL = "Fixed Temperature"; + + private DictionaryModel heatPowerModel; private DictionaryModel heatFluxModel; private DictionaryModel fixedTemperatureModel; private DictionaryModel zeroGradientModel; + private JComboBoxController typeCombo; public StandardThermalWall(BoundaryTypePanel parent) { super(parent); @@ -63,12 +68,12 @@ public class StandardThermalWall extends ThermalParametersPanel { @Override public void resetToDefault(Model model) { fixedTemperatureModel.setDictionary(new Dictionary(fixedValue)); - if (model != null && model.getState() != null && model.getState().isCompressible()) { - heatFluxModel.setDictionary(new Dictionary(turbulentHeatFluxTemperatureOCFD_FLUX_COMP)); - heatPowerModel.setDictionary(new Dictionary(turbulentHeatFluxTemperatureOCFD_POWER_COMP)); - } else { - heatFluxModel.setDictionary(new Dictionary(turbulentHeatFluxTemperatureOCFD_FLUX)); - heatPowerModel.setDictionary(new Dictionary(turbulentHeatFluxTemperatureOCFD_POWER)); + if (model != null && model.getState() != null) { + fixCombo(model.getState()); + if(model.getState().isCompressible()){ + heatFluxModel.setDictionary(new Dictionary(turbulentHeatFluxTemperatureOCFD_FLUX_COMP)); + heatPowerModel.setDictionary(new Dictionary(turbulentHeatFluxTemperatureOCFD_POWER_COMP)); + } } zeroGradientModel.setDictionary(new Dictionary(zeroGradient)); } @@ -76,7 +81,7 @@ public class StandardThermalWall extends ThermalParametersPanel { @Override public void populatePanel() { resetToDefault(null); - builder.startChoice("Type"); + typeCombo = (JComboBoxController) builder.startChoice("Type"); buildFixedTemperaturePanel(); buildHeatFluxPanel(); buildTotalHeatPanel(); @@ -85,20 +90,20 @@ public class StandardThermalWall extends ThermalParametersPanel { } private void buildFixedTemperaturePanel() { - builder.startDictionary("Fixed Temperature", fixedTemperatureModel); + builder.startDictionary(FIXED_TEMPERATURE_LABEL, fixedTemperatureModel); builder.addComponent("Temperature Value [K]", fixedTemperatureModel.bindUniformDouble("value")); builder.endDictionary(); } private void buildHeatFluxPanel() { - builder.startDictionary("Heat Flux", heatFluxModel); - builder.addComponent("Wall Heat Flux [W/m"+SQUARE+"]", heatFluxModel.bindUniformDouble("q")); + builder.startDictionary(HEAT_FLUX_LABEL, heatFluxModel); + builder.addComponent(WALL_HEAT_LABEL, heatFluxModel.bindUniformDouble("q")); builder.endDictionary(); } private void buildTotalHeatPanel() { - builder.startDictionary("Total Heat Load", heatPowerModel); - builder.addComponent("Total Heat Load At Wall [W]", heatPowerModel.bindUniformDouble("q")); + builder.startDictionary(TOTAL_HEAT_LOAD_LABEL, heatPowerModel); + builder.addComponent(TOTAL_HEAT_LOAD_AT_WALL_W_LABEL, heatPowerModel.bindUniformDouble("q")); builder.endDictionary(); } @@ -110,17 +115,26 @@ public class StandardThermalWall extends ThermalParametersPanel { @Override public void stateChanged(Model model) { State state = model.getState(); + + fixCombo(state); if (state.isCompressible()) { heatFluxModel.setDictionary(new Dictionary(turbulentHeatFluxTemperatureOCFD_FLUX_COMP)); heatPowerModel.setDictionary(new Dictionary(turbulentHeatFluxTemperatureOCFD_POWER_COMP)); - } else if (state.isIncompressible()) { - heatFluxModel.setDictionary(new Dictionary(turbulentHeatFluxTemperatureOCFD_FLUX)); - heatPowerModel.setDictionary(new Dictionary(turbulentHeatFluxTemperatureOCFD_POWER)); } } + + private void fixCombo(State state){ + if(state.isCompressible()){ + typeCombo.clearDisabledIndexes(); + } else { + typeCombo.addDisabledItem(HEAT_FLUX_LABEL); + typeCombo.addDisabledItem(TOTAL_HEAT_LOAD_LABEL); + } + + } @Override - public void loadFromBoundaryConditions(String patchName, BoundaryConditions bc) { + public void loadFromBoundaryConditions(BoundaryConditions bc) { Dictionary dictionary = bc.getThermal(); Dictionary T = dictionary.subDict("T"); if (T != null) { diff --git a/src/eu/engys/gui/casesetup/boundaryconditions/panels/wall/StandardWallSettingsPanel.java b/src/eu/engys/gui/casesetup/boundaryconditions/panels/wall/StandardWallSettingsPanel.java index 8ea8fd3..3367b6c 100644 --- a/src/eu/engys/gui/casesetup/boundaryconditions/panels/wall/StandardWallSettingsPanel.java +++ b/src/eu/engys/gui/casesetup/boundaryconditions/panels/wall/StandardWallSettingsPanel.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.casesetup.boundaryconditions.panels.wall; @@ -30,7 +29,7 @@ import javax.inject.Inject; import eu.engys.core.project.Model; import eu.engys.core.project.zero.patches.BoundaryType; -import eu.engys.gui.casesetup.boundaryconditions.panels.AbstractBoundaryTypePanel; +import eu.engys.gui.casesetup.boundaryconditions.parameterspanel.AbstractBoundaryTypePanel; public class StandardWallSettingsPanel extends AbstractBoundaryTypePanel { diff --git a/src/eu/engys/gui/casesetup/boundaryconditions/panels/AbstractBoundaryTypePanel.java b/src/eu/engys/gui/casesetup/boundaryconditions/parameterspanel/AbstractBoundaryTypePanel.java similarity index 62% rename from src/eu/engys/gui/casesetup/boundaryconditions/panels/AbstractBoundaryTypePanel.java rename to src/eu/engys/gui/casesetup/boundaryconditions/parameterspanel/AbstractBoundaryTypePanel.java index 781b6fb..e58fa27 100644 --- a/src/eu/engys/gui/casesetup/boundaryconditions/panels/AbstractBoundaryTypePanel.java +++ b/src/eu/engys/gui/casesetup/boundaryconditions/parameterspanel/AbstractBoundaryTypePanel.java @@ -1,30 +1,34 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.gui.casesetup.boundaryconditions.parameterspanel; -package eu.engys.gui.casesetup.boundaryconditions.panels; +import static eu.engys.gui.casesetup.boundaryconditions.parameterspanel.MomentumParametersPanel.MOMENTUM; +import static eu.engys.gui.casesetup.boundaryconditions.parameterspanel.PhaseParametersPanel.PHASE_FRACTION; +import static eu.engys.gui.casesetup.boundaryconditions.parameterspanel.ThermalParametersPanel.THERMAL; +import static eu.engys.gui.casesetup.boundaryconditions.parameterspanel.TurbulenceParametersPanel.TURBULENCE; import java.awt.BorderLayout; import java.awt.Component; @@ -33,8 +37,6 @@ import java.util.Map; import javax.swing.JPanel; import javax.swing.JTabbedPane; -import javax.swing.event.ChangeEvent; -import javax.swing.event.ChangeListener; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -48,12 +50,13 @@ import eu.engys.core.project.zero.patches.Patch; public abstract class AbstractBoundaryTypePanel extends JPanel implements BoundaryTypePanel { - private static final Logger logger = LoggerFactory.getLogger(BoundaryTypePanel.class); + public static final String BOUNDARY_CONDITIONS_TAB = "boundary.conditions.tab"; + + private static final Logger logger = LoggerFactory.getLogger(BoundaryTypePanel.class); private ParametersPanel momentumPanel; private ParametersPanel turbulencePanel; private ParametersPanel thermalPanel; - private ParametersPanel pScalarsPanel; private ParametersPanel phasePanel; private Map indexes = new HashMap<>(); @@ -72,14 +75,8 @@ public abstract class AbstractBoundaryTypePanel extends JPanel implements Bounda @Override public void layoutPanel() { tabPanel = new JTabbedPane(); - tabPanel.setName("boundary.conditions.tab"); + tabPanel.setName(BOUNDARY_CONDITIONS_TAB); tabPanel.putClientProperty("Synthetica.tabbedPane.tabIndex", 0); - tabPanel.addChangeListener(new ChangeListener() { - @Override - public void stateChanged(ChangeEvent e) { - tabChanged(); - } - }); add(tabPanel, BorderLayout.CENTER); setName(getClass().getSimpleName()); } @@ -88,6 +85,7 @@ public abstract class AbstractBoundaryTypePanel extends JPanel implements Bounda public void addMomentumPanel(ParametersPanel momentumPanel) { if (tabPanel.indexOfTab(MOMENTUM) < 0) { this.momentumPanel = momentumPanel; + indexes.put(MOMENTUM, 0); components.put(MOMENTUM, momentumPanel.getComponent()); } } @@ -108,13 +106,6 @@ public abstract class AbstractBoundaryTypePanel extends JPanel implements Bounda } } - protected void addPScalarsPanel(ParametersPanel pScalarsPanel) { - if (tabPanel.indexOfTab(PASSIVE_SCALARS) < 0) { - this.pScalarsPanel = pScalarsPanel; - components.put(PASSIVE_SCALARS, pScalarsPanel.getComponent()); - } - } - protected void addPhasePanel(ParametersPanel phasePanel) { if (tabPanel.indexOfTab(PHASE_FRACTION) < 0) { this.phasePanel = phasePanel; @@ -137,38 +128,11 @@ public abstract class AbstractBoundaryTypePanel extends JPanel implements Bounda addPanel(name, pPanel, -1); } - - private void tabChanged() { - int selectedIndex = tabPanel.getSelectedIndex(); - if (selectedIndex < 0) { - return; - } - String title = tabPanel.getTitleAt(selectedIndex); - if (model == null || model.getState() == null) { - return; - } - if (title.equals(MOMENTUM)) { - momentumPanel.tabChanged(model); - } else if (title.equals(THERMAL)) { - thermalPanel.tabChanged(model); - } else if (title.equals(TURBULENCE)) { - turbulencePanel.tabChanged(model); - } else if (title.equals(PASSIVE_SCALARS)) { - pScalarsPanel.tabChanged(model); - } else if (title.equals(PHASE_FRACTION)) { - phasePanel.tabChanged(model); - } else { - if (parametersPanels.containsKey(title)) { - parametersPanels.get(title).tabChanged(model); - } - } - } - @Override public void stateChanged() { State state = model.getState(); setEnabledAt(MOMENTUM, !state.getMultiphaseModel().isMultiphase()); - setEnabledAt(TURBULENCE, (state.getTurbulenceModel() != null && !state.getTurbulenceModel().getType().isLaminar())); + setEnabledAt(TURBULENCE, (state.getTurbulenceModel() != null && state.getTurbulenceModel().getType().hasFields())); setEnabledAt(THERMAL, state.isEnergy()); setEnabledAt(PHASE_FRACTION, state.getMultiphaseModel().isMultiphase()); @@ -182,8 +146,6 @@ public abstract class AbstractBoundaryTypePanel extends JPanel implements Bounda thermalPanel.stateChanged(model); if (isEnabledAt(TURBULENCE)) turbulencePanel.stateChanged(model); - if (isEnabledAt(PASSIVE_SCALARS)) - pScalarsPanel.stateChanged(model); if (isEnabledAt(PHASE_FRACTION)) phasePanel.stateChanged(model); @@ -201,8 +163,6 @@ public abstract class AbstractBoundaryTypePanel extends JPanel implements Bounda thermalPanel.resetToDefault(model); if (isEnabledAt(TURBULENCE)) turbulencePanel.resetToDefault(model); - if (isEnabledAt(PASSIVE_SCALARS)) - pScalarsPanel.resetToDefault(model); if (isEnabledAt(PHASE_FRACTION)) phasePanel.resetToDefault(model); @@ -254,30 +214,31 @@ public abstract class AbstractBoundaryTypePanel extends JPanel implements Bounda boolean multipleSelection = patches.length > 1; // System.out.println("AbstractBoundaryTypePanel.loadFromPatches() multipleSelection: "+multipleSelection); if (momentumPanel != null && isEnabledAt(MOMENTUM)) { + momentumPanel.setPatchName(patchName); momentumPanel.setMultipleEditing(multipleSelection); - momentumPanel.loadFromBoundaryConditions(patchName, bc); + momentumPanel.loadFromBoundaryConditions(bc); } if (turbulencePanel != null && isEnabledAt(TURBULENCE)) { + turbulencePanel.setPatchName(patchName); turbulencePanel.setMultipleEditing(multipleSelection); - turbulencePanel.loadFromBoundaryConditions(patchName, bc); + turbulencePanel.loadFromBoundaryConditions(bc); } if (thermalPanel != null && isEnabledAt(THERMAL)) { + thermalPanel.setPatchName(patchName); thermalPanel.setMultipleEditing(multipleSelection); - thermalPanel.loadFromBoundaryConditions(patchName, bc); - } - if (pScalarsPanel != null && isEnabledAt(PASSIVE_SCALARS)) { - pScalarsPanel.setMultipleEditing(multipleSelection); - pScalarsPanel.loadFromBoundaryConditions(patchName, bc); + thermalPanel.loadFromBoundaryConditions(bc); } if (phasePanel != null && isEnabledAt(PHASE_FRACTION)) { + phasePanel.setPatchName(patchName); phasePanel.setMultipleEditing(multipleSelection); - phasePanel.loadFromBoundaryConditions(patchName, bc); + phasePanel.loadFromBoundaryConditions(bc); } for (String title : parametersPanels.keySet()) { if (isEnabledAt(title)) { ParametersPanel parametersPanel = parametersPanels.get(title); + parametersPanel.setPatchName(patchName); parametersPanel.setMultipleEditing(multipleSelection); - parametersPanel.loadFromBoundaryConditions(patchName, bc); + parametersPanel.loadFromBoundaryConditions(bc); } } } else { @@ -291,20 +252,17 @@ public abstract class AbstractBoundaryTypePanel extends JPanel implements Bounda patch.setBoundaryConditions(new BoundaryConditions()); } BoundaryConditions bc = patch.getBoundaryConditions(); - String patchName = patch.getName(); - if (momentumPanel != null && isEnabledAt(MOMENTUM) && momentumPanel.canEdit()) - momentumPanel.saveToBoundaryConditions(patchName, bc); + if (momentumPanel != null && isEnabledAt(MomentumParametersPanel.MOMENTUM) && momentumPanel.canEdit()) + momentumPanel.saveToBoundaryConditions(bc); if (turbulencePanel != null && isEnabledAt(TURBULENCE) && turbulencePanel.canEdit()) - turbulencePanel.saveToBoundaryConditions(patchName, bc); + turbulencePanel.saveToBoundaryConditions(bc); if (thermalPanel != null && isEnabledAt(THERMAL) && thermalPanel.canEdit()) - thermalPanel.saveToBoundaryConditions(patchName, bc); - if (pScalarsPanel != null && isEnabledAt(PASSIVE_SCALARS) && pScalarsPanel.canEdit()) - pScalarsPanel.saveToBoundaryConditions(patchName, bc); + thermalPanel.saveToBoundaryConditions(bc); if (phasePanel != null && isEnabledAt(PHASE_FRACTION) && phasePanel.canEdit()) - phasePanel.saveToBoundaryConditions(patchName, bc); + phasePanel.saveToBoundaryConditions(bc); for (String title : parametersPanels.keySet()) { if (isEnabledAt(title)) { - parametersPanels.get(title).saveToBoundaryConditions(patchName, bc); + parametersPanels.get(title).saveToBoundaryConditions(bc); } } } diff --git a/src/eu/engys/gui/casesetup/boundaryconditions/parameterspanel/AbstractCyclicAMISettingsPanel.java b/src/eu/engys/gui/casesetup/boundaryconditions/parameterspanel/AbstractCyclicAMISettingsPanel.java new file mode 100644 index 0000000..a9dccd2 --- /dev/null +++ b/src/eu/engys/gui/casesetup/boundaryconditions/parameterspanel/AbstractCyclicAMISettingsPanel.java @@ -0,0 +1,349 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.gui.casesetup.boundaryconditions.parameterspanel; + +import static eu.engys.core.dictionary.Dictionary.TYPE; +import static eu.engys.gui.casesetup.boundaryconditions.factories.CyclicFactory.AMI_BOUNDARY_CONDITION; +import static eu.engys.gui.casesetup.boundaryconditions.factories.CyclicFactory.AMI_BOUNDARY_CONDITION_VECTOR; +import static eu.engys.gui.casesetup.boundaryconditions.factories.CyclicFactory.CYCLIC_AMI_COUPLING; +import static eu.engys.gui.casesetup.boundaryconditions.factories.CyclicFactory.CYCLIC_AMI_TRANSLATIONAL; + +import java.awt.BorderLayout; +import java.awt.Component; + +import javax.swing.JPanel; + +import eu.engys.core.dictionary.Dictionary; +import eu.engys.core.dictionary.model.DictionaryModel; +import eu.engys.core.dictionary.model.DictionaryPanelBuilder; +import eu.engys.core.modules.boundaryconditions.BoundaryTypePanel; +import eu.engys.core.modules.boundaryconditions.ParametersPanel; +import eu.engys.core.project.Model; +import eu.engys.core.project.zero.fields.Field; +import eu.engys.core.project.zero.fields.FieldType; +import eu.engys.core.project.zero.fields.Fields; +import eu.engys.core.project.zero.patches.BoundaryConditions; +import eu.engys.core.project.zero.patches.BoundaryType; +import eu.engys.core.project.zero.patches.Patch; +import eu.engys.util.ui.builder.PanelBuilder; + +public abstract class AbstractCyclicAMISettingsPanel extends JPanel implements BoundaryTypePanel { + + public static final String MATCH_TOLERANCE_KEY = "matchTolerance"; + public static final String NEIGHBOUR_PATCH_KEY = "neighbourPatch"; + public static final String SEPARATION_VECTOR_LABEL = "Separation Vector"; + public static final String SEPARATION_VECTOR_KEY = "separationVector"; + public static final String ROTATION_CENTRE_KEY = "rotationCentre"; + public static final String ROTATION_AXIS_KEY = "rotationAxis"; + public static final String TRANSFORM_KEY = "transform"; + public static final String COUPLING_KEY = "noOrdering"; + public static final String TRANSLATIONAL_KEY = "translational"; + public static final String ROTATIONAL_KEY = "rotational"; + public static final String ROTATION_ANGLE_KEY = "rotationAngle"; + public static final String WEIGHT_CORRECTION_KEY = "lowWeightCorrection"; + public static final String BRIDGE_OVERLAP_KEY = "bridgeOverlap"; + + public static final String ROTATION_ANGLE_LABEL = "Rotation [deg]"; + public static final String WEIGHT_CORRECTION_LABEL = "Weight Correction"; + public static final String TRANSFORM_LABEL = "Transform"; + public static final String COUPLING_LABEL = "Coupling"; + public static final String TRANSLATIONAL_LABEL = "Translational"; + public static final String ROTATIONAL_LABEL = "Rotational"; + public static final String CENTRE_LABEL = "Centre"; + public static final String AXIS_LABEL = "Axis"; + public static final String NEIGHBOUR_PATCH_LABEL = "Neighbour Patch"; + public static final String MATCH_TOLERANCE_LABEL = "Match Tolerance"; + + protected DictionaryModel cyclicModel; + protected DictionaryModel rotationalModel; + protected DictionaryModel couplingModel; + protected Model model; + protected DictionaryPanelBuilder transformBuilder; + private DictionaryModel translationalModel; + + public AbstractCyclicAMISettingsPanel(Model model) { + super(new BorderLayout()); + this.model = model; + this.cyclicModel = new DictionaryModel(); + this.couplingModel = new DictionaryModel(); + this.rotationalModel = new DictionaryModel(); + this.translationalModel = new DictionaryModel(); + } + + @Override + public void resetToDefault() { + this.couplingModel.setDictionary(new Dictionary(CYCLIC_AMI_COUPLING)); + this.translationalModel.setDictionary(new Dictionary(CYCLIC_AMI_TRANSLATIONAL)); + } + + @Override + public void layoutPanel() { + resetToDefault(); + + PanelBuilder builder = new PanelBuilder(); + + bindAmiParameters(builder); + + transformBuilder = new DictionaryPanelBuilder(); + transformBuilder.startChoice(TRANSFORM_LABEL); + bindCouplingParameters(); + bindRotationalParameters(); + bindTranslationalParameters(); + + transformBuilder.endChoice(); + transformBuilder.selectDictionary(couplingModel.getDictionary()); + + builder.addFill(transformBuilder.removeMargins().getPanel()); + + add(builder.getPanel()); + } + + protected abstract void bindAmiParameters(PanelBuilder builder); + + private void bindCouplingParameters() { + transformBuilder.startDictionary(COUPLING_LABEL, couplingModel); + transformBuilder.endDictionary(); + } + + protected abstract void bindRotationalParameters(); + + private void bindTranslationalParameters() { + transformBuilder.startDictionary(TRANSLATIONAL_LABEL, translationalModel); + transformBuilder.addComponent(SEPARATION_VECTOR_LABEL, translationalModel.bindPoint(SEPARATION_VECTOR_KEY)); + transformBuilder.endDictionary(); + } + + @Override + public BoundaryType getType() { + return BoundaryType.CYCLIC_AMI; + } + + @Override + public Component getPanel() { + return this; + } + + @Override + public void saveToPatch(Patch patch) { + Dictionary oldDict = patch.getDictionary(); + Dictionary newDict = getNewDict(); + + resetOldNeighbourPatch(oldDict, newDict); + + patch.setDictionary(newDict); + patch.setBoundaryConditions(getAMIBoundaryConditions()); + + setNeighbourPatchToAMI(newDict, patch.getName()); + } + + /* + * Scenario: + * 1) you set patch A to AMI and you set patch B as its neighbour + * 2) patch A may already be an AMI patch with another neighbour (let say patch C) + * 3) patch C should be reset to default type + */ + private void resetOldNeighbourPatch(Dictionary oldDict, Dictionary newDict) { + if (oldDict.found(NEIGHBOUR_PATCH_KEY)) { + String oldNeighbourPatchName = oldDict.lookup(NEIGHBOUR_PATCH_KEY); + if (newDict.found(NEIGHBOUR_PATCH_KEY)) { + String newNeighbourPatchName = newDict.lookup(NEIGHBOUR_PATCH_KEY); + if (oldNeighbourPatchName.equals(newNeighbourPatchName)) { + // Same neighbour = nothing to do + return; + } else { + Patch neighbourPatch = model.getPatches().toMap().get(oldNeighbourPatchName); + if (neighbourPatch != null && neighbourPatch.getPhysicalType().isCyclicAMI()) { + neighbourPatch.resetToDefault(); + } + } + } else { + Patch neighbourPatch = model.getPatches().toMap().get(oldNeighbourPatchName); + if (neighbourPatch != null && neighbourPatch.getPhysicalType().isCyclicAMI()) { + neighbourPatch.resetToDefault(); + } + } + } + } + + private void setNeighbourPatchToAMI(Dictionary newDict, String patchName) { + if (newDict.found(NEIGHBOUR_PATCH_KEY)) { + String neighbourPatchName = newDict.lookup(NEIGHBOUR_PATCH_KEY); + Patch neighbourPatch = model.getPatches().toMap().get(neighbourPatchName); + if (neighbourPatch != null) { + resetNeighbourOfNeighbourIfAny(neighbourPatch, patchName); + neighbourPatch.setPhysicalType(BoundaryType.CYCLIC_AMI); + neighbourPatch.setDictionary(createDictionaryForNeighbourPatch(newDict, patchName)); + neighbourPatch.setBoundaryConditions(getAMIBoundaryConditions()); + } + } + } + + /* + * Scenario: + * 1) you set patch A to AMI and you set patch B as its neighbour + * 2) patch B may already be an AMI patch with its own neighbour (let say patch C) + * 3) patch C should be reset to default type because you cannot have 2 patches with the same neighbour (patch B) + * 4) of course only if patch C != patch A + */ + private void resetNeighbourOfNeighbourIfAny(Patch neighbourPatch, String patchName) { + if (neighbourPatch.getPhysicalType().isCyclicAMI() && neighbourPatch.getDictionary().found(NEIGHBOUR_PATCH_KEY)) { + String neighbour2PatchName = neighbourPatch.getDictionary().lookup(NEIGHBOUR_PATCH_KEY); + if (neighbour2PatchName.equals(patchName)) { + // nothing do do + return; + } else { + Patch neighbour2Patch = model.getPatches().toMap().get(neighbour2PatchName); + if (neighbour2Patch != null) { + neighbour2Patch.resetToDefault(); + } + } + + } + } + + private Dictionary createDictionaryForNeighbourPatch(Dictionary newDict, String patchName) { + Dictionary neighbourPatchDict = new Dictionary(newDict); + neighbourPatchDict.add(NEIGHBOUR_PATCH_KEY, patchName); + if (neighbourPatchDict.found(SEPARATION_VECTOR_KEY)) { + invertSeparationVector(neighbourPatchDict); + } + return neighbourPatchDict; + } + + private void invertSeparationVector(Dictionary d) { + String[] sepVector = d.lookupArray(SEPARATION_VECTOR_KEY); + StringBuilder sb = new StringBuilder("( "); + for (String value : sepVector) { + double doubleValue = Double.parseDouble(value); + sb.append(-doubleValue + " "); + } + sb.append(")"); + d.add(SEPARATION_VECTOR_KEY, sb.toString()); + } + + private Dictionary getNewDict() { + Dictionary cyclicDict = new Dictionary(cyclicModel.getDictionary()); + Dictionary transformDict = new Dictionary(transformBuilder.getSelectedModel().getDictionary()); + transformDict.remove(TYPE); + cyclicDict.merge(transformDict); + return cyclicDict; + } + + protected Dictionary extractCyclicDict(Dictionary dictionary) { + Dictionary cyclicDict = new Dictionary(dictionary); + cyclicDict.remove(TRANSFORM_KEY); + cyclicDict.remove(SEPARATION_VECTOR_KEY); + cyclicDict.remove(ROTATION_AXIS_KEY); + cyclicDict.remove(ROTATION_CENTRE_KEY); + return cyclicDict; + } + + protected Dictionary extractTransformDict(Dictionary dictionary) { + Dictionary transformDict = new Dictionary(""); + if (dictionary.found(TRANSFORM_KEY)) { + transformDict.add(TRANSFORM_KEY, dictionary.lookup(TRANSFORM_KEY)); + } + if (dictionary.found(SEPARATION_VECTOR_KEY)) { + transformDict.add(SEPARATION_VECTOR_KEY, dictionary.lookup(SEPARATION_VECTOR_KEY)); + } + if (dictionary.found(ROTATION_AXIS_KEY)) { + transformDict.add(ROTATION_AXIS_KEY, dictionary.lookup(ROTATION_AXIS_KEY)); + } + if (dictionary.found(ROTATION_CENTRE_KEY)) { + transformDict.add(ROTATION_CENTRE_KEY, dictionary.lookup(ROTATION_CENTRE_KEY)); + } + switch (dictionary.lookup(TRANSFORM_KEY)) { + case COUPLING_KEY: + transformDict.add(TYPE, COUPLING_LABEL); + break; + case ROTATIONAL_KEY: + transformDict.add(TYPE, ROTATIONAL_LABEL); + break; + case TRANSLATIONAL_KEY: + transformDict.add(TYPE, TRANSLATIONAL_LABEL); + break; + default: + transformDict.add(TYPE, COUPLING_LABEL); + break; + } + return transformDict; + } + + private BoundaryConditions getAMIBoundaryConditions() { + BoundaryConditions boundaryConditions = new BoundaryConditions(); + for (Field field : model.getFields().values()) { + if (Fields.getFieldTypeByName(field.getName()) == FieldType.SCALAR) { + boundaryConditions.add(field.getName(), new Dictionary(AMI_BOUNDARY_CONDITION(field.getInternalFieldScalarValue(model.getState())))); + } else { + boundaryConditions.add(field.getName(), new Dictionary(AMI_BOUNDARY_CONDITION_VECTOR(field.getInternalFieldArrayValue(model.getState())))); + } + } + return boundaryConditions; + } + + @Override + public void stateChanged() { + } + + @Override + public void addMomentumPanel(ParametersPanel momentumPanel) { + } + + @Override + public void addTurbulencePanel(ParametersPanel momentumPanel) { + } + + @Override + public void addThermalPanel(ParametersPanel momentumPanel) { + } + + @Override + public void addPanel(String name, ParametersPanel pPanel) { + } + + @Override + public void addPanel(String name, ParametersPanel pPanel, int index) { + } + + @Override + public ParametersPanel getMomentumPanel() { + return null; + } + + @Override + public ParametersPanel getTurbulencePanel() { + return null; + } + + @Override + public ParametersPanel getThermalPanel() { + return null; + } + + @Override + public ParametersPanel getPanel(String name) { + return null; + } +} diff --git a/src/eu/engys/gui/casesetup/boundaryconditions/panels/AbstractParametersPanel.java b/src/eu/engys/gui/casesetup/boundaryconditions/parameterspanel/AbstractParametersPanel.java similarity index 54% rename from src/eu/engys/gui/casesetup/boundaryconditions/panels/AbstractParametersPanel.java rename to src/eu/engys/gui/casesetup/boundaryconditions/parameterspanel/AbstractParametersPanel.java index 69e87ac..45429b6 100644 --- a/src/eu/engys/gui/casesetup/boundaryconditions/panels/AbstractParametersPanel.java +++ b/src/eu/engys/gui/casesetup/boundaryconditions/parameterspanel/AbstractParametersPanel.java @@ -1,30 +1,29 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ - -package eu.engys.gui.casesetup.boundaryconditions.panels; +package eu.engys.gui.casesetup.boundaryconditions.parameterspanel; import java.awt.BorderLayout; import java.awt.event.ActionEvent; @@ -38,17 +37,20 @@ import eu.engys.core.dictionary.model.DictionaryModel; import eu.engys.core.dictionary.model.DictionaryPanelBuilder; import eu.engys.core.modules.boundaryconditions.BoundaryTypePanel; import eu.engys.core.modules.boundaryconditions.ParametersPanel; +import eu.engys.core.parameters.Parameter.ParameterKeyArgument; import eu.engys.core.project.Model; import eu.engys.core.project.zero.patches.BoundaryConditions; -public abstract class AbstractParametersPanel extends JPanel implements ParametersPanel { - +public abstract class AbstractParametersPanel extends JPanel implements ParametersPanel, ParameterKeyArgument { + private final JCheckBox allowEditing; protected final DictionaryPanelBuilder builder; private BoundaryTypePanel parentPanel; + private String patchName; + public AbstractParametersPanel(BoundaryTypePanel parent) { super(new BorderLayout()); this.parentPanel = parent; @@ -94,10 +96,6 @@ public abstract class AbstractParametersPanel extends JPanel implements Paramete @Override public void materialsChanged(Model model) { } - - @Override - public void tabChanged(Model model) { - } public void loadFromDictionary(Dictionary dictionary) { } @@ -119,10 +117,24 @@ public abstract class AbstractParametersPanel extends JPanel implements Paramete } } } - - public abstract void saveToBoundaryConditions(String patchName, BoundaryConditions bc); - public abstract void loadFromBoundaryConditions(String patchName, BoundaryConditions bc); + @Override + public String getArgument() { + return patchName; + } + + public String getPatchName() { + return patchName; + } + + @Override + public void setPatchName(String patchName) { + this.patchName = patchName; + } + + public abstract void saveToBoundaryConditions(BoundaryConditions bc); + + public abstract void loadFromBoundaryConditions(BoundaryConditions bc); private boolean canEdit = false; @@ -144,19 +156,4 @@ public abstract class AbstractParametersPanel extends JPanel implements Paramete return builder.getSelectedModel(); } -// @Override -// public void selectDictionary(Dictionary dictionary) { -// builder.selectDictionary(dictionary); -// } -// -// @Override -// public void selectDictionaryByModel(DictionaryModel model, Dictionary dict) { -// builder.selectDictionaryByKey(model.getKey(), dict); -// } -// -// @Override -// public void selectDictionaries(Dictionary dictionary, Dictionary companion) { -// builder.selectDictionaries(dictionary, companion); -// } - } diff --git a/src/eu/engys/gui/casesetup/boundaryconditions/panels/CyclicSettingsPanel.java b/src/eu/engys/gui/casesetup/boundaryconditions/parameterspanel/CyclicSettingsPanel.java similarity index 50% rename from src/eu/engys/gui/casesetup/boundaryconditions/panels/CyclicSettingsPanel.java rename to src/eu/engys/gui/casesetup/boundaryconditions/parameterspanel/CyclicSettingsPanel.java index a816212..83298fd 100644 --- a/src/eu/engys/gui/casesetup/boundaryconditions/panels/CyclicSettingsPanel.java +++ b/src/eu/engys/gui/casesetup/boundaryconditions/parameterspanel/CyclicSettingsPanel.java @@ -1,34 +1,35 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.gui.casesetup.boundaryconditions.parameterspanel; -package eu.engys.gui.casesetup.boundaryconditions.panels; - +import static eu.engys.core.dictionary.Dictionary.TYPE; import static eu.engys.gui.casesetup.boundaryconditions.factories.CyclicFactory.BOUNDARY_CONDITION; import static eu.engys.gui.casesetup.boundaryconditions.factories.CyclicFactory.BOUNDARY_CONDITION_VECTOR; import static eu.engys.gui.casesetup.boundaryconditions.factories.CyclicFactory.CYCLIC; +import static eu.engys.gui.casesetup.boundaryconditions.factories.CyclicFactory.CYCLIC_KEY; import java.awt.BorderLayout; import java.awt.Component; @@ -42,7 +43,8 @@ import eu.engys.core.modules.boundaryconditions.BoundaryTypePanel; import eu.engys.core.modules.boundaryconditions.ParametersPanel; import eu.engys.core.project.Model; import eu.engys.core.project.zero.fields.Field; -import eu.engys.core.project.zero.fields.Field.FieldType; +import eu.engys.core.project.zero.fields.FieldType; +import eu.engys.core.project.zero.fields.Fields; import eu.engys.core.project.zero.patches.BoundaryConditions; import eu.engys.core.project.zero.patches.BoundaryType; import eu.engys.core.project.zero.patches.Patch; @@ -51,6 +53,11 @@ import eu.engys.util.ui.builder.PanelBuilder; public class CyclicSettingsPanel extends JPanel implements BoundaryTypePanel { + public static final String MATCH_TOLERANCE_KEY = "matchTolerance"; + public static final String NEIGHBOUR_PATCH_KEY = "neighbourPatch"; + + public static final String MATCH_TOLERANCE_LABEL = "Match Tolerance"; + public static final String NEIGHBOUR_PATCH_LABEL = "Neighbour Patch"; private DictionaryModel cyclicModel; private Model model; @@ -71,8 +78,8 @@ public class CyclicSettingsPanel extends JPanel implements BoundaryTypePanel { public void layoutPanel() { PanelBuilder builder = new PanelBuilder(); cyclicModel.setDictionary(new Dictionary(CYCLIC)); - builder.addComponent("Match Tolerance", cyclicModel.bindDouble("matchTolerance")); - builder.addComponent("Neighbour Patch", cyclicModel.bindSelection("neighbourPatch", ListBuilderFactory.getPatchesListBuilder(model))); + builder.addComponent(MATCH_TOLERANCE_LABEL, cyclicModel.bindDouble(MATCH_TOLERANCE_KEY)); + builder.addComponent(NEIGHBOUR_PATCH_LABEL, cyclicModel.bindSelection(NEIGHBOUR_PATCH_KEY, ListBuilderFactory.getPatchesListBuilder(model))); add(builder.getPanel()); } @@ -90,8 +97,8 @@ public class CyclicSettingsPanel extends JPanel implements BoundaryTypePanel { public void loadFromPatches(Patch... patches) { if (patches.length == 1) { Dictionary dictionary = patches[0].getDictionary(); - if (dictionary.found(Dictionary.TYPE) && dictionary.lookup(Dictionary.TYPE).equals("cyclic")) { - cyclicModel.setDictionary(dictionary); + if (dictionary.found(TYPE) && dictionary.lookup(TYPE).equals(CYCLIC_KEY)) { + cyclicModel.setDictionary(new Dictionary(dictionary)); } else { cyclicModel.setDictionary(new Dictionary(CYCLIC)); } @@ -101,18 +108,17 @@ public class CyclicSettingsPanel extends JPanel implements BoundaryTypePanel { @Override public void saveToPatch(Patch patch) { Dictionary newDict = cyclicModel.getDictionary(); - + patch.setDictionary(new Dictionary(newDict)); patch.setBoundaryConditions(getBoundaryConditions()); - patch.getDictionary().merge(newDict); } private BoundaryConditions getBoundaryConditions() { BoundaryConditions boundaryConditions = new BoundaryConditions(); for (Field field : model.getFields().values()) { - if (field.getFieldType() == FieldType.SCALAR) { - boundaryConditions.add(field.getName(), new Dictionary(BOUNDARY_CONDITION)); + if (Fields.getFieldTypeByName(field.getName()) == FieldType.SCALAR) { + boundaryConditions.add(field.getName(), new Dictionary(BOUNDARY_CONDITION(field.getInternalFieldScalarValue(model.getState())))); } else { - boundaryConditions.add(field.getName(), new Dictionary(BOUNDARY_CONDITION_VECTOR)); + boundaryConditions.add(field.getName(), new Dictionary(BOUNDARY_CONDITION_VECTOR(field.getInternalFieldArrayValue(model.getState())))); } } return boundaryConditions; @@ -162,7 +168,7 @@ public class CyclicSettingsPanel extends JPanel implements BoundaryTypePanel { public void addPanel(String name, ParametersPanel pPanel) { } - @Override - public void addPanel(String name, ParametersPanel pPanel, int index) { - } + @Override + public void addPanel(String name, ParametersPanel pPanel, int index) { + } } diff --git a/src/eu/engys/gui/casesetup/boundaryconditions/parameterspanel/MomentumParametersPanel.java b/src/eu/engys/gui/casesetup/boundaryconditions/parameterspanel/MomentumParametersPanel.java new file mode 100644 index 0000000..6d9c9a6 --- /dev/null +++ b/src/eu/engys/gui/casesetup/boundaryconditions/parameterspanel/MomentumParametersPanel.java @@ -0,0 +1,60 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.gui.casesetup.boundaryconditions.parameterspanel; + +import eu.engys.core.dictionary.Dictionary; +import eu.engys.core.modules.boundaryconditions.BoundaryTypePanel; +import eu.engys.core.project.Model; +import eu.engys.core.project.zero.patches.BoundaryConditions; + +public abstract class MomentumParametersPanel extends AbstractParametersPanel { + + public static final String MOMENTUM = "Momentum"; + + public MomentumParametersPanel(BoundaryTypePanel parent) { + super(parent); + } + + @Override + public String getTitle() { + return MOMENTUM; + } + + public boolean isEnabled(Model model) { + return true; + } + + @Override + public void loadFromBoundaryConditions(BoundaryConditions bc) { + Dictionary dictionary = bc.getMomentum(); + loadFromDictionary(dictionary); + } + + @Override + public void saveToBoundaryConditions(BoundaryConditions bc) { + Dictionary dictionary = bc.getMomentum(); + saveToDictionary(dictionary); + } +} diff --git a/src/eu/engys/gui/casesetup/boundaryconditions/parameterspanel/PhaseParametersPanel.java b/src/eu/engys/gui/casesetup/boundaryconditions/parameterspanel/PhaseParametersPanel.java new file mode 100644 index 0000000..f73a1ef --- /dev/null +++ b/src/eu/engys/gui/casesetup/boundaryconditions/parameterspanel/PhaseParametersPanel.java @@ -0,0 +1,63 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.gui.casesetup.boundaryconditions.parameterspanel; + +import eu.engys.core.dictionary.Dictionary; +import eu.engys.core.modules.boundaryconditions.BoundaryTypePanel; +import eu.engys.core.project.Model; +import eu.engys.core.project.state.State; +import eu.engys.core.project.zero.patches.BoundaryConditions; + +public abstract class PhaseParametersPanel extends AbstractParametersPanel { + + public static final String PHASE_FRACTION = "Phase Fraction"; + + public PhaseParametersPanel(BoundaryTypePanel parent) { + super(parent); + } + + @Override + public String getTitle() { + return PHASE_FRACTION; + } + + public boolean isEnabled(Model model) { + State state = model.getState(); + return state.getMultiphaseModel().isMultiphase(); + } + + @Override + public void saveToBoundaryConditions(BoundaryConditions bc) { + Dictionary dictionary = bc.getPhase(); + saveToDictionary(dictionary); + } + + @Override + public void loadFromBoundaryConditions(BoundaryConditions bc) { + Dictionary dictionary = bc.getPhase(); + loadFromDictionary(dictionary); + } + +} diff --git a/src/eu/engys/gui/casesetup/boundaryconditions/parameterspanel/ThermalParametersPanel.java b/src/eu/engys/gui/casesetup/boundaryconditions/parameterspanel/ThermalParametersPanel.java new file mode 100644 index 0000000..ef1b612 --- /dev/null +++ b/src/eu/engys/gui/casesetup/boundaryconditions/parameterspanel/ThermalParametersPanel.java @@ -0,0 +1,54 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.gui.casesetup.boundaryconditions.parameterspanel; + +import eu.engys.core.modules.boundaryconditions.BoundaryTypePanel; +import eu.engys.core.project.Model; +import eu.engys.core.project.state.State; +import eu.engys.core.project.zero.patches.BoundaryConditions; + +public abstract class ThermalParametersPanel extends AbstractParametersPanel { + + public static final String THERMAL = "Thermal"; + + public ThermalParametersPanel(BoundaryTypePanel parent) { + super(parent); + } + + @Override + public String getTitle() { + return THERMAL; + } + + public boolean isEnabled(Model model) { + State state = model.getState(); + return state.isEnergy(); + } + + @Override + public void saveToBoundaryConditions(BoundaryConditions bc) { + saveToDictionary(bc.getThermal()); + } +} diff --git a/src/eu/engys/gui/casesetup/boundaryconditions/parameterspanel/TurbulenceParametersPanel.java b/src/eu/engys/gui/casesetup/boundaryconditions/parameterspanel/TurbulenceParametersPanel.java new file mode 100644 index 0000000..81cb96f --- /dev/null +++ b/src/eu/engys/gui/casesetup/boundaryconditions/parameterspanel/TurbulenceParametersPanel.java @@ -0,0 +1,81 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.gui.casesetup.boundaryconditions.parameterspanel; + +import static eu.engys.gui.casesetup.boundaryconditions.utils.TurbulenceUtils.setKEpsilon; +import static eu.engys.gui.casesetup.boundaryconditions.utils.TurbulenceUtils.setKEquationEddy; +import static eu.engys.gui.casesetup.boundaryconditions.utils.TurbulenceUtils.setKOmega; +import static eu.engys.gui.casesetup.boundaryconditions.utils.TurbulenceUtils.setSpalartAllmaras; + +import eu.engys.core.dictionary.Dictionary; +import eu.engys.core.modules.boundaryconditions.BoundaryTypePanel; +import eu.engys.core.project.Model; +import eu.engys.core.project.TurbulenceModelType; +import eu.engys.core.project.state.State; +import eu.engys.core.project.zero.patches.BoundaryConditions; + +public abstract class TurbulenceParametersPanel extends AbstractParametersPanel { + + public static final String TURBULENCE = "Turbulence"; + + private TurbulenceModelType type; + + public TurbulenceParametersPanel(BoundaryTypePanel parent) { + super(parent); + } + + @Override + public String getTitle() { + return TURBULENCE; + } + + public boolean isEnabled(Model model) { + State state = model.getState(); + return (state.getTurbulenceModel() != null && state.getTurbulenceModel().getType().hasFields()); + } + + @Override + public void stateChanged(Model model) { + TurbulenceModelType type = model.getState().getTurbulenceModel().getType(); + if (this.type == null || this.type != type) { + this.type = type; + if (type.isKepsilon()) { + setKEpsilon(builder); + } else if (type.isKomega()) { + setKOmega(builder); + } else if (type.isSpalartAllmaras()) { + setSpalartAllmaras(builder); + } else if (type.isKEquationeddy()) { + setKEquationEddy(builder); + } + } + } + + @Override + public void saveToBoundaryConditions(BoundaryConditions bc) { + Dictionary dictionary = bc.getTurbulence(); + saveToDictionary(dictionary); + } +} diff --git a/src/eu/engys/gui/casesetup/boundaryconditions/utils/BoundaryConditionsUtils.java b/src/eu/engys/gui/casesetup/boundaryconditions/utils/BoundaryConditionsUtils.java index 5a83ec0..4ac50c6 100644 --- a/src/eu/engys/gui/casesetup/boundaryconditions/utils/BoundaryConditionsUtils.java +++ b/src/eu/engys/gui/casesetup/boundaryconditions/utils/BoundaryConditionsUtils.java @@ -1,327 +1,694 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.casesetup.boundaryconditions.utils; import static eu.engys.core.dictionary.Dictionary.TYPE; +import static eu.engys.util.Symbols.CUBE; +import static eu.engys.util.Symbols.DENSITY; +import static eu.engys.util.Symbols.DOT; +import static eu.engys.util.Symbols.EPSILON_SYMBOL; +import static eu.engys.util.Symbols.KELVIN; +import static eu.engys.util.Symbols.K_SYMBOL; +import static eu.engys.util.Symbols.M; +import static eu.engys.util.Symbols.M2_S; +import static eu.engys.util.Symbols.M2_S2; +import static eu.engys.util.Symbols.M_S; +import static eu.engys.util.Symbols.OMEGA_SYMBOL_RAD; +import static eu.engys.util.Symbols.OMEGA_SYMBOL_S; +import static eu.engys.util.Symbols.PASCAL; +import static eu.engys.util.Symbols.SQUARE; +import static eu.engys.util.ui.UiUtil.EDIT_BUTTON_LABEL; import java.awt.event.ActionEvent; import javax.swing.AbstractAction; import javax.swing.JButton; -import net.java.dev.designgridlayout.Componentizer; import eu.engys.core.dictionary.Dictionary; +import eu.engys.core.dictionary.StartWithFinder; import eu.engys.core.dictionary.model.DictionaryModel; import eu.engys.core.dictionary.model.DictionaryPanelBuilder; -import eu.engys.gui.casesetup.boundaryconditions.TimeVaryingComboBoxController; -import eu.engys.gui.casesetup.boundaryconditions.TimeVaryingInterpolationTable; +import eu.engys.gui.casesetup.boundaryconditions.charts.DictionarySparkline; +import eu.engys.gui.casesetup.boundaryconditions.charts.SparklineChart; +import eu.engys.gui.casesetup.boundaryconditions.panels.ScalarTimeVaryingInterpolationTable; +import eu.engys.gui.casesetup.boundaryconditions.panels.TimeVaryingComboBoxController; +import eu.engys.gui.casesetup.boundaryconditions.panels.VectorTimeVaryingInterpolationTable; import eu.engys.util.Symbols; +import net.java.dev.designgridlayout.Componentizer; public class BoundaryConditionsUtils { /* - * TYPES - */ - public static final String ADVECTIVE_KEY = "advective"; - public static final String ALPHA_CONTACT_ANGLE_KEY = "alphaContactAngle"; - public static final String CYLINDRICAL_INLET_VELOCITY_KEY = "cylindricalInletVelocity"; - public static final String COMPRESSIBLE_TURBULENT_MIXING_LENGTH_DISSIPATION_RATE_INLET_KEY = "compressible::turbulentMixingLengthDissipationRateInlet"; - public static final String COMPRESSIBLE_TURBULENT_MIXING_LENGTH_FREQUENCY_INLET_KEY = "compressible::turbulentMixingLengthFrequencyInlet"; - public static final String CONSTANT_ALPHA_CONTACT_ANGLE_KEY = "constantAlphaContactAngle"; + * TYPES + */ + public static final String ADVECTIVE_KEY = "advective"; + public static final String ALPHA_CONTACT_ANGLE_KEY = "alphaContactAngle"; + public static final String CALCULATED_KEY = "calculated"; + public static final String CYLINDRICAL_INLET_VELOCITY_KEY = "cylindricalInletVelocity"; + public static final String COMPRESSIBLE_TURBULENT_CONVECTIVE_TEMPERATURE_KEY = "compressible::turbulentConvectiveTemperature"; + public static final String COMPRESSIBLE_TURBULENT_HEAT_FLUX_TEMPERATURE_KEY = "compressible::turbulentHeatFluxTemperature"; + public static final String COMPRESSIBLE_TURBULENT_MIXING_LENGTH_DISSIPATION_RATE_INLET_KEY = "compressible::turbulentMixingLengthDissipationRateInlet"; + public static final String COMPRESSIBLE_TURBULENT_MIXING_LENGTH_FREQUENCY_INLET_KEY = "compressible::turbulentMixingLengthFrequencyInlet"; + public static final String CONSTANT_ALPHA_CONTACT_ANGLE_KEY = "constantAlphaContactAngle"; + public static final String COUPLED_TOTAL_VELOCITY_KEY = "coupledTotalVelocity"; + public static final String COUPLED_TOTAL_PRESSURE_KEY = "coupledTotalPressure"; + public static final String CURVATURE_KEY = "curvature"; + public static final String DYNAMIC_ALPHA_CONTACT_ANGLE_KEY = "dynamicAlphaContactAngle"; + public static final String FIXED_FLUX_PRESSURE_KEY = "fixedFluxPressure"; + public static final String FIXED_MEAN_VALUE_KEY = "fixedMeanValue"; + public static final String FIXED_VALUE_KEY = "fixedValue"; + public static final String FLOW_RATE_INLET_VELOCITY_KEY = "flowRateInletVelocity"; + public static final String FLOW_RATE_OUTLET_VELOCITY_KEY = "flowRateOutletVelocity"; + public static final String FLUX_CORRECTED_VELOCITY_KEY = "fluxCorrectedVelocity"; + public static final String FREESTREAM_PRESSURE_KEY = "freestreamPressure"; + public static final String FREESTREAM_KEY = "freestream"; + public static final String GREY_DIFFUSIVE_RADIATION_KEY = "greyDiffusiveRadiation"; + public static final String GROUP_OF_HUMANS_CO2_KEY = "groupOfHumansCO2"; + public static final String GROUP_OF_HUMANS_HEAT_FLUX_KEY = "groupOfHumansHeatFlux"; + public static final String GROUP_OF_HUMANS_HUMIDITY_FLUX_KEY = "groupOfHumansHumidityFlux"; + public static final String INCOMPRESSIBLE_TURBULENT_CONVECTIVE_TEMPERATURE_KEY = "incompressible::turbulentConvectiveTemperature"; + public static final String INCOMPRESSIBLE_TURBULENT_HEAT_FLUX_TEMPERATURE_KEY = "incompressible::turbulentHeatFluxTemperature"; + public static final String INLET_OUTLET_KEY = "inletOutlet"; + public static final String INLET_OUTLET_TOTAL_TEMPERATURE_KEY = "inletOutletTotalTemperature"; + public static final String INTERPOLATED_CYLINDRICAL_VELOCITY_KEY = "interpolatedCylindricalVelocity"; + public static final String INTERPOLATED_FIXED_VALUE_KEY = "interpolatedFixedValue"; + public static final String INTERPOLATED_INLET_OUTLET_KEY = "interpolatedInletOutlet"; + public static final String MAXWELL_SLIP_U_KEY = "maxwellSlipU"; + public static final String MOVING_WALL_VELOCITY_KEY = "movingWallVelocity"; + public static final String MOVING_WALL_VELOCITY_KEY_COUPLED = "movingNoSlipWall"; + public static final String MUT_K_ROUGH_WALL_FUNCTION_KEY = "mutKRoughWallFunction"; + public static final String MUT_U_ROUGH_WALL_FUNCTION_KEY = "mutURoughWallFunction"; + public static final String NUT_K_ROUGH_WALL_FUNCTION_KEY = "nutkRoughWallFunction"; + public static final String NUT_K_ATM_ROUGH_WALL_FUNCTION_KEY = "nutkAtmRoughWallFunction"; + public static final String NUT_U_ROUGH_WALL_FUNCTION_KEY = "nutURoughWallFunction"; + public static final String NUT_TURBULENT_INTENSITY_LENGTH_SCALE_INLET_KEY = "nutTurbulentIntensityLengthScaleInlet"; + public static final String PHASE_CHANGE_HUMIDITY_KEY = "phaseChangeHumidity"; + public static final String PRESSURE_DIRECTED_INLET_VELOCITY_KEY = "pressureDirectedInletVelocity"; + public static final String PRESSURE_DIRECT_INLET_OUTLET_VELOCITY_KEY = "pressureDirectedInletOutletVelocity"; + public static final String PRESSURE_INLET_OUTLET_VELOCITY_KEY = "pressureInletOutletVelocity"; + public static final String PRESSURE_INLET_VELOCITY_KEY = "pressureInletVelocity"; + public static final String PRESSURE_OUTLET_KEY = "pressureOutlet"; + public static final String RELATIVE_HUMIDITY_INLET_OUTLET_KEY = "relativeHumidityInletOutlet"; + public static final String RESISTIVE_PRESSURE_KEY = "resistivePressure"; + public static final String RESISTIVE_VELOCITY_KEY = "resistiveVelocity"; + public static final String ROTATING_WALL_VELOCITY_KEY = "rotatingWallVelocity"; + public static final String ROTATING_NO_SLIP_WALL_KEY = "rotatingNoSlipWall"; + public static final String SLIP_KEY = "slip"; + public static final String SLIP_WALL_KEY = "slipWall"; + public static final String NO_SLIP_WALL_KEY = "noSlipWall"; + public static final String SUPERSONIC_FREESTREAM_KEY = "supersonicFreestream"; + public static final String SURFACE_NORMAL_FIXED_VALUE_KEY = "surfaceNormalFixedValue"; + public static final String SMOLUCHOWSKI_JUMP_T_KEY = "smoluchowskiJumpT"; + public static final String START_DAMPING_ANGLE_KEY = "startDampingAngle"; + public static final String TURBULENT_ABL_INLET_VELOCITY_KEY = "turbulentAtmBLInletVelocity"; + public static final String TANGENTIAL_VELOCITY_KEY = "tangentialVelocity"; + public static final String THERMAL_CREEP_KEY = "thermalCreep"; + public static final String TOTAL_PRESSURE_KEY = "totalPressure"; + public static final String TOTAL_TEMPERATURE_KEY = "totalTemperature"; + public static final String TRANSLATING_NO_SLIP_WALL_VELOCITY = "translatingNoSlipWallVelocity"; + public static final String TURBULENT_HEAT_FLUX_TEMPERATURE_KEY = "turbulentHeatFluxTemperature"; + public static final String TURBULENT_INTENSITY_KINETIC_ENERGY_INLET_KEY = "turbulentIntensityKineticEnergyInlet"; + public static final String TURBULENT_MIXING_LENGTH_DISSIPATION_RATE_INLET_KEY = "turbulentMixingLengthDissipationRateInlet"; + public static final String TURBULENT_MIXING_LENGTH_FREQUENCY_INLET_KEY = "turbulentMixingLengthFrequencyInlet"; + public static final String UNIFORM_FIXED_VALUE_KEY = "uniformFixedValue"; + public static final String UNIFORM_TOTAL_PRESSURE_KEY = "uniformTotalPressure"; + public static final String VARIABLE_HEIGHT_FLOW_RATE_INLET_VELOCITY_KEY = "variableHeightFlowRateInletVelocity"; + public static final String VELOCITY_GRADIENT_DISSIPATION_INLET_OUTLET_KEY = "velocityGradientDissipationInletOutlet"; + public static final String WALL_PRESSURE_KEY = "wallPressure"; + public static final String WAVE_TRANSMISSIVE_KEY = "waveTransmissive"; + public static final String WHEEL_VELOCITY_KEY = "wheelVelocity"; + public static final String WIND_PROFILE_DIRECTION_VELOCITY_KEY = "windProfileDirectionVelocity"; + public static final String ZERO_GRADIENT_ANGLE_KEY = "zeroGradientAngle"; + public static final String ZERO_GRADIENT_KEY = "zeroGradient"; - public static final String COUPLED_TOTAL_VELOCITY_KEY = "coupledTotalVelocity"; - public static final String COUPLED_TOTAL_PRESSURE_KEY = "coupledTotalPressure"; - - public static final String DYNAMIC_ALPHA_CONTACT_ANGLE_KEY = "dynamicAlphaContactAngle"; - public static final String FIXED_FLUX_PRESSURE_KEY = "fixedFluxPressure"; - public static final String FIXED_MEAN_VALUE_KEY = "fixedMeanValue"; - public static final String FIXED_VALUE_KEY = "fixedValue"; - public static final String FLOW_RATE_INLET_VELOCITY_KEY = "flowRateInletVelocity"; - public static final String FLOW_RATE_OUTLET_VELOCITY_KEY = "flowRateOutletVelocity"; - public static final String FLUX_CORRECTED_VELOCITY_KEY = "fluxCorrectedVelocity"; - public static final String FREESTREAM_PRESSURE_KEY = "freestreamPressure"; - public static final String FREESTREAM_KEY = "freestream"; - public static final String INLET_OUTLET_KEY = "inletOutlet"; - public static final String INTERPOLATED_CYLINDRICAL_VELOCITY_KEY = "interpolatedCylindricalVelocity"; - public static final String INTERPOLATED_FIXED_VALUE_KEY = "interpolatedFixedValue"; - public static final String INTERPOLATED_INLET_OUTLET_KEY = "interpolatedInletOutlet"; - public static final String MAXWELL_SLIP_U_KEY = "maxwellSlipU"; - public static final String MOVING_WALL_VELOCITY_KEY = "movingWallVelocity"; - public static final String MOVING_WALL_COUPLED_VELOCITY_KEY = "movingNoSlipWall"; - public static final String MUT_K_ROUGH_WALL_FUNCTION_KEY = "mutKRoughWallFunction"; - public static final String MUT_U_ROUGH_WALL_FUNCTION_KEY = "mutURoughWallFunction"; - public static final String NUT_K_ROUGH_WALL_FUNCTION_KEY = "nutkRoughWallFunction"; - public static final String NUT_K_ATM_ROUGH_WALL_FUNCTION_KEY = "nutkAtmRoughWallFunction"; - public static final String NUT_U_ROUGH_WALL_FUNCTION_KEY = "nutURoughWallFunction"; - public static final String NUT_TURBULENT_INTENSITY_LENGTH_SCALE_INLET_KEY = "nutTurbulentIntensityLengthScaleInlet"; - public static final String PRESSURE_DIRECT_INLET_VELOCITY_KEY = "pressureDirectedInletVelocity"; - public static final String PRESSURE_DIRECT_INLET_OUTLET_VELOCITY_KEY = "pressureDirectedInletOutletVelocity"; - public static final String PRESSURE_INLET_OUTLET_VELOCITY_KEY = "pressureInletOutletVelocity"; - public static final String PRESSURE_INLET_VELOCITY_KEY = "pressureInletVelocity"; - public static final String RESISTIVE_PRESSURE_KEY = "resistivePressure"; - public static final String RESISTIVE_VELOCITY_KEY = "resistiveVelocity"; - public static final String ROTATING_WALL_VELOCITY_KEY = "rotatingWallVelocity"; - public static final String ROTATING_WALL_COUPLED_VELOCITY_KEY = "rotatingNoSlipWall"; - public static final String SLIP_KEY = "slip"; - public static final String SLIP_WALL_KEY = "slipWall"; - public static final String NO_SLIP_WALL_KEY = "noSlipWall"; - public static final String SUPERSONIC_FREESTREAM_KEY = "supersonicFreestream"; - public static final String SURFACE_NORMAL_FIXED_VALUE_KEY = "surfaceNormalFixedValue"; - public static final String TANGENTIAL_VELOCITY_KEY = "tangentialVelocity"; - public static final String TOTAL_PRESSURE_KEY = "totalPressure"; - public static final String TURBULENT_INTENSITY_KINETIC_ENERGY_INLET_KEY = "turbulentIntensityKineticEnergyInlet"; - public static final String TURBULENT_MIXING_LENGTH_DISSIPATION_RATE_INLET_KEY = "turbulentMixingLengthDissipationRateInlet"; - public static final String TURBULENT_MIXING_LENGTH_FREQUENCY_INLET_KEY = "turbulentMixingLengthFrequencyInlet"; - public static final String UNIFORM_FIXED_VALUE_KEY = "uniformFixedValue"; - public static final String UNIFORM_TOTAL_PRESSURE_KEY = "uniformTotalPressure"; - public static final String VARIABLE_HEIGHT_FLOW_RATE_INLET_VELOCITY_KEY = "variableHeightFlowRateInletVelocity"; - public static final String VELOCITY_GRADIENT_DISSIPATION_INLET_OUTLET_KEY = "velocityGradientDissipationInletOutlet"; - public static final String WAVE_TRANSMISSIVE_KEY = "waveTransmissive"; - public static final String WHEEL_VELOCITY_KEY = "wheelVelocity"; - public static final String WIND_PROFILE_DIRECTION_VELOCITY_KEY = "windProfileDirectionVelocity"; - public static final String ZERO_GRADIENT_KEY = "zeroGradient"; + /* + * OTHER KEYS + */ - /* - * OTHER KEYS - */ - public static final String ACCOMMODATION_COEFFICIENT_KEY = "accommodationCoeff"; - public static final String ALPHA_KEY = "alpha"; - public static final String AXIS_KEY = "axis"; - public static final String CENTRE_KEY = "centre"; - public static final String CLAMP_KEY = "clamp"; - public static final String CS_KEY = "Cs"; - public static final String DATA_KEY = "data"; - public static final String DIRECTION_KEY = "direction"; - public static final String DISTANCE_ALONG_VECTOR_KEY = "distanceAlongVector"; - public static final String DISTANCE_TYPE_KEY = "distanceType"; - public static final String FIELD_KEY = "field"; - public static final String FILE_KEY = "file"; - public static final String FILE_NAME_KEY = "fileName"; - public static final String FLOW_RATE_KEY = "flowRate"; - public static final String FREESTREAM_VALUE_KEY = "freestreamValue"; - public static final String GAMMA_KEY = "gamma"; - public static final String GRADIENT_KEY = "gradient"; - public static final String INLET_VALUE_KEY = "inletValue"; - public static final String INLET_DIRECTION_KEY = "inletDirection"; - public static final String INTENSITY_KEY = "intensity"; - public static final String KS_KEY = "Ks"; - public static final String LENGTH_KEY = "length"; - public static final String LIMIT_KEY = "limit"; - public static final String MASS_FLOW_RATE_KEY = "massFlowRate"; - public static final String MEAN_VALUE_KEY = "meanValue"; - public static final String MIXING_LENGTH_KEY = "mixingLength"; - public static final String NONE_KEY = "none"; - public static final String NORMAL_KEY = "normal"; - public static final String OMEGA_KEY = "omega"; - public static final String ORIGIN_KEY = "origin"; - public static final String OUT_OF_BOUNDS_KEY = "outOfBounds"; - public static final String P0_KEY = "p0"; - public static final String PHASE_KEY = "phase"; - public static final String PHI_KEY = "phi"; - public static final String POINT_KEY = "point"; - public static final String POINT_DISTANCE_KEY = "pointDistance"; - public static final String PRESSURE_KEY = "pressure"; - public static final String RHO_KEY = "rho"; - public static final String RHO_INLET_KEY = "rhoInlet"; - public static final String REF_VALUE_KEY = "refValue"; - public static final String ROUGHNESS_CONSTANT_KEY = "roughnessConstant"; - public static final String ROUGHNESS_HEIGHT_KEY = "roughnessHeight"; - public static final String ROUGHNESS_FACTOR_KEY = "roughnessFactor"; - public static final String TABLE_KEY = "table"; - public static final String TABLE_FILE_KEY = "tableFile"; - public static final String THETA_0_KEY = "theta0"; - public static final String THETA_A_KEY = "thetaA"; - public static final String THETA_PROPERTIES_KEY = "thetaProperties"; - public static final String THETA_R_KEY = "thetaR"; - public static final String U_THETA_KEY = "uTheta"; - public static final String UNIFORM_VALUE_KEY = "uniformValue"; - public static final String UNIFORM_KEY = "uniform"; - public static final String USE_WALL_DISTANCE_KEY = "useWallDistance"; - public static final String UWALL = "Uwall"; - public static final String VOLUMETRIC_FLOW_RATE_KEY = "volumetricFlowRate"; - public static final String VALUE_KEY = "value"; - public static final String WALL_DISTANCE_KEY = "wallDistance"; - public static final String WIND_DIRECTION_KEY = "windDirection"; - public static final String X_KEY = "x"; - public static final String XOFFSET_KEY = "xoffset"; - public static final String XSCALE_KEY = "xscale"; - public static final String YOFFSET_KEY = "yoffset"; - public static final String Y_KEY = "y"; - public static final String YSCALE_KEY = "yscale"; - public static final String Z_KEY = "z"; - public static final String Z0_KEY = "z0"; + public static final String ACCOMMODATION_COEFFICIENT_KEY = "accommodationCoeff"; + public static final String AGE_KEY = "age"; + public static final String AIJ_KEY = "AIJ"; + public static final String ALPHA_KEY = "alpha"; + public static final String ALPHA_EFF_KEY = "alphaEff"; + public static final String ALPHA_WALL_KEY = "alphaWall"; + public static final String AXIAL_VELOCITY_KEY = "axialVelocity"; + public static final String AXIS_KEY = "axis"; + public static final String AVERAGING_DISTANCE_KEY = "averagingDistance"; + public static final String C1_KEY = "C1"; + public static final String C2_KEY = "C2"; + public static final String CENTRE_KEY = "centre"; + public static final String CLAMP_KEY = "clamp"; + public static final String CO2_MASS_FRACTION_LABEL = "CO" + Symbols.SUBSCRIPT_2 + " Mass Fraction"; + public static final String COFG_KEY = "CofG"; + public static final String CONTACT_ANGLE_KEY = "contactAngle"; + public static final String CONTACT_RADIUS_KEY = "contactRadius"; + public static final String CP_KEY = "Cp"; + public static final String CP0_KEY = "Cp0"; + public static final String CN_KEY = "Cn"; + public static final String CS_KEY = "Cs"; + public static final String CT_KEY = "Ct"; + public static final String DATA_KEY = "data"; + public static final String DIRECTION_KEY = "direction"; + public static final String DEFAULT_KEY = "default"; + public static final String DEMOGRAPHICS_KEY = "demographics"; + public static final String DISTANCE_ALONG_VECTOR_KEY = "distanceAlongVector"; + public static final String DISTANCE_TYPE_KEY = "distanceType"; + public static final String DROPLETS_KEY = "droplets"; + public static final String EMISSIVITY_KEY = "emissivity"; + public static final String EMISSIVITY_MODE_KEY = "emissivityMode"; + public static final String ERROR_KEY = "error"; + public static final String FEMALE_ADULT_KEY = "femaleAdult"; + public static final String FEMALE_CHILD_KEY = "femaleChild"; + public static final String FIELD_KEY = "field"; + public static final String FIELD_INF_KEY = "fieldInf"; + public static final String FILE_KEY = "file"; + public static final String FILE_NAME_KEY = "fileName"; + public static final String FILM_MASS_KEY = "filmMass"; + public static final String FIXED_KEY = "fixed"; + public static final String FLOW_RATE_KEY = "flowRate"; + public static final String FLUID_THERMO_KEY = "fluidThermo"; + public static final String FLUX_KEY = "flux"; + public static final String FREESTREAM_VALUE_KEY = "freestreamValue"; + public static final String GAMMA_KEY = "gamma"; + public static final String GRADIENT_KEY = "gradient"; + public static final String HEAT_SOURCE_KEY = "heatSource"; + public static final String HREF_KEY = "Href"; + public static final String HEIGHT_KEY = "height"; + public static final String HUB_SPEED_KEY = "hubSpeed"; + public static final String I_USER_DEFINED_KEY = "iUserDefined"; + public static final String INLET_VALUE_KEY = "inletValue"; + public static final String INLET_DIRECTION_KEY = "inletDirection"; + public static final String INOUT_KEY = "inout"; + public static final String INTENSITY_KEY = "intensity"; + public static final String KAPPA_KEY = "kappa"; + public static final String KAPPA_EFF_KEY = "kappaEff"; + public static final String KAPPA_NAME_KEY = "kappaName"; + public static final String KS_KEY = "Ks"; + public static final String L_USER_DEFINED_KEY = "LUserDefined"; + public static final String LAMBDA_KEY = "lambda"; + public static final String LAYERS_KEY = "layers"; + public static final String LENGTH_KEY = "length"; + public static final String LIMIT_KEY = "limit"; + public static final String LINF_KEY = "lInf"; + public static final String LOOKUP_KEY = "lookup"; + public static final String MAGNITUDE_KEY = "magnitude"; + public static final String MALE_ADULT_KEY = "maleAdult"; + public static final String MALE_CHILD_KEY = "maleChild"; + public static final String MASS_FLOW_RATE_KEY = "massFlowRate"; + public static final String MEAN_VALUE_KEY = "meanValue"; + public static final String MIXING_KEY = "mixing"; + public static final String MIXING_LENGTH_KEY = "mixingLength"; + public static final String N_KEY = "n"; + public static final String NONE_KEY = "none"; + public static final String NONUNIFROM_KEY = "nonunifrom"; + public static final String NORMAL_KEY = "normal"; + public static final String NUMBER_KEY = "number"; + public static final String OMEGA_KEY = "omega"; + public static final String ORIGIN_KEY = "origin"; + public static final String OUT_OF_BOUNDS_KEY = "outOfBounds"; + public static final String P0_KEY = "p0"; + public static final String PHASE_KEY = "phase"; + public static final String PHI_KEY = "phi"; + public static final String PINF_KEY = "pInf"; + public static final String POINT_KEY = "point"; + public static final String POINT_DISTANCE_KEY = "pointDistance"; + public static final String POWER_KEY = "power"; + public static final String PRESSURE_KEY = "pressure"; + public static final String PROFILE_TYPE_KEY = "profileType"; + public static final String PSI_KEY = "psi"; + public static final String PVALUE_KEY = "pValue"; + public static final String Q_KEY = "q"; + public static final String QADD_KEY = "qadd"; + public static final String QR_KEY = "Qr"; + public static final String R_USER_DEFINED_KEY = "RUserDefined"; + public static final String RADIAL_VELOCITY_KEY = "radialVelocity"; + public static final String RAU_KEY = "rAU"; + public static final String REGION0_KEY = "region0"; + public static final String REPEAT_KEY = "repeat"; + public static final String RHO_KEY = "rho"; + public static final String RHOK_KEY = "rhok"; + public static final String RHO_INLET_KEY = "rhoInlet"; + public static final String REF_VALUE_KEY = "refValue"; + public static final String RELATIVE_HUMIDITY_KEY = "relativeHumidity"; + public static final String RICHARDS_HOXEY_KEY = "RichardsHoxey"; + public static final String ROUGHNESS_CONSTANT_KEY = "roughnessConstant"; + public static final String ROUGHNESS_HEIGHT_KEY = "roughnessHeight"; + public static final String ROUGHNESS_FACTOR_KEY = "roughnessFactor"; + public static final String RPM_KEY = "rpm"; + public static final String SOLAR_TRANSMISSIVITY_KEY = "solarTransmissivity"; + public static final String STEADY_EVAPORATION_KEY = "steadyEvaporation"; + public static final String T0_KEY = "T0"; + public static final String TABLE_KEY = "table"; + public static final String TABLE_FILE_KEY = "tableFile"; + public static final String THERMAL_COUPLING_KEY = "thermalCoupling"; + public static final String THERMO_PSI_KEY = "thermo:psi"; + public static final String THETA_0_KEY = "theta0"; + public static final String THETA_A_KEY = "thetaA"; + public static final String THETA_PROPERTIES_KEY = "thetaProperties"; + public static final String THETA_R_KEY = "thetaR"; + public static final String THICKNESS_KEY = "thickness"; + public static final String TIMEVARYING_KEY = "timevarying"; + public static final String TINF_KEY = "Tinf"; + public static final String TRANSMISSIVITY_KEY = "transmissivity"; + public static final String TWALL = "Twall"; + public static final String U_THETA_KEY = "uTheta"; + public static final String U_USER_DEFINED_KEY = "UUserDefined"; + public static final String UINF_KEY = "Uinf"; + public static final String UREF_KEY = "Uref"; + public static final String UNIFORM_VALUE_KEY = "uniformValue"; + public static final String UNIFORM_KEY = "uniform"; + public static final String USE_WALL_DISTANCE_KEY = "useWallDistance"; + public static final String USER_DEFINED_KEY = "userDefined"; + public static final String UWALL_KEY = "Uwall"; + public static final String VELOCITY_KEY = "velocity"; + public static final String VOLUMETRIC_FLOW_RATE_KEY = "volumetricFlowRate"; + public static final String VALUE_KEY = "value"; + public static final String WALL_DISTANCE_KEY = "wallDistance"; + public static final String WARN_KEY = "warn"; + public static final String WATER_VAPOUR_MASS_FRACTION_LABEL = "Water Vapour Mass Fraction"; + public static final String WEIGHT_KEY = "weight"; + public static final String WIND_DIRECTION_KEY = "windDirection"; + public static final String X_KEY = "x"; + public static final String X_OFFSET_KEY = "xoffset"; + public static final String X_SCALE_KEY = "xscale"; + public static final String Y_OFFSET_KEY = "yoffset"; + public static final String Y_KEY = "y"; + public static final String Y_SCALE_KEY = "yscale"; + public static final String Z_KEY = "z"; + public static final String ZERO_KEY = "zero"; + public static final String Z0_KEY = "z0"; + public static final String ZG_KEY = "zG"; - /* - * LISTS - */ - public static final String[] LIMIT_KEYS = { NONE_KEY, GRADIENT_KEY, "zeroGradient", ALPHA_KEY }; + /* + * LIST OF KEYS + */ + public static final String[] LIMIT_KEYS = { NONE_KEY, GRADIENT_KEY, ZERO_GRADIENT_KEY, ALPHA_KEY }; + public static final String[] INTERP_ALGO_TYPE_KEYS = { REPEAT_KEY, CLAMP_KEY, WARN_KEY, ERROR_KEY }; - // TO ORDER + /* + * LABELS + */ + + public static final String ACCOMMODATION_COEFFICIENT_LABEL = "Accommodation Coefficient"; + public static final String ADIABATIC_LABEL = "Adiabatic"; + public static final String ADVECTIVE_TEMPERATURE_LABEL = "Advective"; + public static final String AGE_LABEL = "Age"; + public static final String AIJ_LABEL = "AIJ"; + public static final String AMBIENT_TEMPERATURE_LABEL = "Ambient Temperature
Outside The Wall [K]"; + public static final String ATMOSPHERIC_BOUNDARY_LAYER_LABEL = "Atmospheric Boundary Layer"; + public static final String AVERAGE_DISTANCE_LABEL = "Average Distance"; + public static final String AXIAL_VELOCITY_LABEL = "Axial Velocity"; + public static final String BOUNDARY_LAYER_HEIGHT_LABEL = "Boundary Layer Height " + M; + public static final String BY_INTENSITY_FROM_WIND_LABEL = "By Intensity from Wind"; + public static final String BY_TURB_INTENSITY_AND_MIXING_LENGTH_LABEL = "By Turb. Intensity And Mixing Length"; + public static final String AXIS_LABEL = "Axis"; + public static final String CENTRE_LABEL = "Centre"; + public static final String CYLINDRICAL_INLET_VELOCITY_LABEL = "Cylindrical Inlet Velocity"; + public static final String CLAMP_LABEL = "Clamp"; + public static final String COFG_LABEL = "CofG"; + public static final String COMPRESSIBILITY_LABEL = "Compressibility"; + public static final String COMPRESSIBLE_LABEL = "Compressible"; + public static final String CONDUCTIVITY_LABEL = "Conductivity [W/K" + DOT + "m]"; + public static final String CONTACT_RADIUS_LABEL = "Contact Radius [m]"; + public static final String CONVECTIVE_HEAT_LABEL = "Convective Heat Transfer
Coefficient [W/K" + DOT + "m" + SQUARE + "]"; + public static final String CONVECTIVE_HEAT_TRANSFER_LABEL = "Convective Heat Transfer"; + public static final String COORDINATE_SYSTEM_LABEL = "Coordinate System"; + public static final String COUPLED_LABEL = "Coupled"; + public static final String CURVATURE_LABEL = "Curvature"; + public static final String DEMOGRAPHICS_LABEL = "Demographics"; + public static final String DIRECTION_LABEL = "Direction"; + public static final String DISTANCE_ALONG_VECTOR_LABEL = "Distance Along Vector"; + public static final String DISTANCE_TYPE_LABEL = "Distance Type"; + public static final String DISTRIBUTION_BASED_ON_WIND_PROFILE_LABEL = "Distribution Based On Wind Profile"; + public static final String DOWNSTREAM_PRESSURE_COMP = "Downstream Pressure " + PASCAL; + public static final String DOWNSTREAM_PRESSURE_INCOMP = "Downstream Pressure " + M2_S2; + public static final String DROPLETS_CONTACT_ANGLE_LABEL = "Droplets Contact Angle"; + public static final String DROPLETS_LABEL = "Droplets"; + public static final String EDIT_I_LABEL = "Turbulent Intensity"; + public static final String EDIT_L_LABEL = "Turbulent Length Scale"; + public static final String EDIT_VELOCITY_LABEL = "Velocity"; + public static final String EPSILON_LABEL = "Epsilon " + EPSILON_SYMBOL; + public static final String ERROR_LABEL = "Error"; + public static final String FEMALE_ADULT_LABEL = "Female Adult"; + public static final String FEMALE_CHILD_LABEL = "Female Child"; + public static final String FIXED_FLUX_PRESSURE_LABEL = "Fixed Flux Pressure"; + public static final String FIXED_FLOW_RATE_LABEL = "Fixed Flow Rate"; + public static final String FIXED_PRESSURE_COUPLED_LABEL = "Fixed Pressure (Coupled)"; + public static final String FIXED_PRESSURE_LABEL = "Fixed Pressure"; + public static final String FIXED_PRESSURE_COMP_LABEL = FIXED_PRESSURE_LABEL + " " + PASCAL; + public static final String FIXED_PRESSURE_INCOMP_LABEL = FIXED_PRESSURE_LABEL + " " + M2_S2; + public static final String FIXED_TANGENTIAL_VELOCITY_LABEL = "Fixed Tangential Velocity"; + public static final String FIXED_TEMPERATURE_LABEL = "Fixed Temperature"; + public static final String FIXED_VALUE_COUPLED_LABEL = "Fixed Value (Coupled)"; + public static final String FIXED_VALUE_LABEL = "Fixed Value"; + public static final String FIXED_VALUES_LABEL = "Fixed Values"; + public static final String FIXED_VELOCITY_LABEL = "Fixed Velocity"; + public static final String FIXED_VELOCITY_AND_PRESSURE_LABEL = "Fixed Velocity and Pressure"; + public static final String FIXED_WALL_LABEL = "Fixed Wall"; + public static final String FLOW_DIRECTION_LABEL = "Flow Direction"; + public static final String FLOW_RATE_LABEL = "Flow Rate"; + public static final String FLOW_RATE_OUTLET_LABEL = "Flow Rate Outlet"; + public static final String FLOW_VELOCITY_LABEL = "Flow Velocity"; + public static final String FLUX_CORRECTED_LABEL = "Flux Corrected"; + public static final String FREESTREAM_LABEL = "Freestream"; + public static final String FREESTREAM_PRESSURE_LABEL = "Freestream Pressure " + PASCAL; + public static final String FREESTREAM_VELOCITY_LABEL = "Freestream Velocity " + M_S; + public static final String FROM_FILE_LABEL = "From File"; + public static final String GAMMA_LABEL = "Gamma"; + public static final String GLOBAL_CARTESIAN_LABEL = "Global Cartesian"; + public static final String GROUP_OF_HUMANS_LABEL = "Group of Humans"; + public static final String HEAT_FLUX_LABEL = "Heat Flux"; + public static final String HEAT_FLUX_LABEL_WM = "Heat Flux [W/m" + SQUARE + "]"; + public static final String HEIGHT_LABEL = "Height"; + public static final String HUB_SPEED_LABEL = "Hub Speed " + M_S; + public static final String I_LABEL = "I"; + public static final String INCOMPRESSIBLE_LABEL = "Incompressible"; + public static final String INFLOW_FIXED_TEMPERATURE_LABEL = "Inflow Fixed Temperature"; + public static final String INFLOW_FIXED_VALUES_LABEL = "Inflow Fixed Values"; + public static final String INFLOW_PHASE_FRACTION_LABEL = "Inflow Phase Fraction"; + public static final String INFLOW_TOTAL_PRESSURE_LABEL = "Inflow Total Pressure"; + public static final String INFLOW_VELOCITY_LABEL = "Inflow Velocity " + M_S; + public static final String INITIAL_PHASE_FRACTION_LABEL = "Initial Phase Fraction"; + public static final String INITIAL_PRESSURE_PA_LABEL = "Initial Pressure " + PASCAL; + public static final String INITIAL_TEMPERATURE_K_LABEL = "Initial Temperature " + KELVIN; + public static final String INLET_DIRECTION_LABEL = "Inlet Direction"; + public static final String INLET_OUTLET_LABEL = "Inlet Outlet"; + public static final String INLET_OUTLET_TOTAL_TEMPERATURE_LABEL = "Inlet Outlet Total Temperature"; + public static final String INLET_OUTLET_VELOCITY_LABEL = "Inlet Outlet Velocity"; + public static final String INLET_VALUE_LABEL = "Inlet Value"; + public static final String INTERPOLATION_ALGORITHM_LABEL = "Interpolation Algorithm"; + public static final String INTERPOLATION_PROFILE_LABEL = "Interpolation Profile"; + public static final String INITIAL_VELOCITY_LABEL = "Initial Velocity " + M_S; + public static final String K_LABEL = "K " + K_SYMBOL;// "Turbulent Kinetik Energy"; + public static final String KEQUATION_LABEL = K_LABEL; + public static final String L_LABEL = "L"; + public static final String LENGTH_INF_M_LABEL = "Length Inf " + M; + public static final String LOCAL_CYLINDRICAL_LABEL = "Local Cylindrical"; + public static final String MAGNITUDE_LABEL = "Magnitude " + M_S; + public static final String MALE_ADULT_LABEL = "Male Adult"; + public static final String MALE_CHILD_LABEL = "Male Child"; + public static final String MASS_FLOW_RATE_INLET_LABEL = "Mass Flow Rate Inlet"; + public static final String MASS_FLOW_RATE_LABEL = "Mass Flow Rate [kg/s]"; + public static final String MAXWELL_SLIP_LABEL = "Maxwell Slip"; + public static final String MEAN_PRESSURE_LABEL = "Mean Pressure"; + public static final String MEAN_PRESSURE_INCOMP = MEAN_PRESSURE_LABEL + " " + M2_S2; + public static final String MEAN_PRESSURE_COMP = MEAN_PRESSURE_LABEL + " " + PASCAL; + public static final String MIXING_LENGTH_LABEL = "Mixing Length " + M; + public static final String MOVING_WALL_LABEL = "Moving Wall"; + public static final String MOVING_WALL_VELOCITY_LABEL = "Moving Wall Velocity"; + public static final String MOVING_WALL_COUPLED_VELOCITY_LABEL = "Moving Wall Velocity (Coupled)"; + public static final String NAME_LABEL = "Name"; + public static final String NO_PHASES_LABEL = "No Phases"; + public static final String NO_SLIP_COUPLED_LABEL = "No-slip (Coupled)"; + public static final String NO_SLIP_LABEL = "No-slip"; + public static final String NON_UNIFORM_PHASE_FRACTION_LABEL = "Non-uniform Phase Fraction"; + public static final String NON_UNIFORM_TEMPERATURE_LABEL = "Non-uniform Temperature"; + public static final String NON_UNIFORM_TURBULENCE_LABEL = "Non-uniform Turbulence"; + public static final String NON_UNIFORM_VELOCITY_LABEL = "Non-uniform Velocity"; + public static final String NORMAL_GRADIENT_COEFFICIENT = "Normal Gradient Coefficient"; + public static final String NORMAL_TO_BOUNDARY_LABEL = "Normal to Boundary"; + public static final String NORMAL_TO_BOUNDARY_PATCH_LABEL = "Normal To Boundary Patch"; + public static final String NUTILDA_LABEL = "NuTilda " + M2_S; + public static final String NUMBER_LABEL = "Number"; + public static final String OMEGA_TURBULENCE_LABEL = "Omega " + OMEGA_SYMBOL_S; + public static final String OMEGA_VELOCITY_LABEL = "Omega " + OMEGA_SYMBOL_RAD; + public static final String ORIGIN_LABEL = "Origin"; + public static final String OUTSIDE_ENVIRONMENTAL_TEMPERATURE_K_LABEL = "Outside Environmental Temperature [K]"; + public static final String PHASE_CHANGE_LABEL = "Phase Change"; + public static final String PHASE_LABEL = "Phase"; + public static final String PHASE_CHANGE_EFFECT_LABEL = "Phase Change Effect"; + public static final String POINT_DISTANCE_LABEL = "Point Distance"; + public static final String POINT_LABEL = "Point"; + public static final String POWER_LAW_COEFFICIENT_LABEL = "Power Law Coefficient"; + public static final String PRESSURE_COMP_LABEL = "Pressure " + PASCAL; + public static final String PRESSURE_DIRECTED_INLET_OUTLET_VELOCITY_LABEL = "Pressure Directed Inlet Outlet Velocity"; + public static final String PRESSURE_DIRECTED_INLET_VELOCITY_LABEL = "Pressure Directed Inlet Velocity"; + public static final String PRESSURE_INCOMP_LABEL = "Pressure " + M2_S2; + public static final String PRESSURE_INF_LABEL = "Pressure Inf " + PASCAL; + public static final String PRESSURE_INLET_OUTLET_VELOCITY_LABEL = "Pressure Inlet Outlet Velocity"; + public static final String PRESSURE_INLET_VELOCITY_LABEL = "Pressure Inlet Velocity"; + public static final String PRESSURE_LABEL = "Pressure"; + public static final String PRESSURE_TYPE_LABEL = "Pressure Type"; + public static final String PROFILE_TYPE_LABEL = "Profile Type"; + public static final String RADIAL_VELOCITY_LABEL = "Radial Velocity"; + public static final String RATIO_OF_SPECIFIC_HEATS_LABEL = "Ratio of Specific Heats"; + public static final String REFERENCE_HEIGHT_LABEL = "Reference Height " + M; + public static final String REFERENCE_VELOCITY_LABEL = "Reference Velocity " + M_S; + public static final String REPEAT_LABEL = "Repeat"; + public static final String RESISTIVE_LABEL = "Resistive"; + public static final String REYNOLDS_STRESS_LABEL = "Mean Reynolds Stress"; + public static final String RHO_INLET_LABEL = "Initial Density "+DENSITY; + public static final String RICHARDS_HOXEY_LABEL = "Richards-Hoxey"; + public static final String ROTATING_WALL_LABEL = "Rotating Wall"; + public static final String ROTATING_WALL_COUPLED_LABEL = "Rotating Wall (Coupled)"; + public static final String ROTATING_WHEEL_LABEL = "Rotating Wheel"; + public static final String ROUGHNESS_HEIGHT_LABEL = "Roughness Height " + M; + public static final String RPM_LABEL = "RPM"; + public static final String SLIP_COUPLED_LABEL = "Slip (Coupled)"; + public static final String SLIP_LABEL = "Slip"; + public static final String SMOLUCHOWSKI_JUMP_LABEL = "Smoluchowski Jump"; + public static final String SOLAR_RADIATION_LABEL = "Solar Radiation"; + public static final String SPECIFICATION_METHOD_LABEL = "Specification Method"; + public static final String SPECIFY_DIRECTION_LABEL = "Specify Direction"; + public static final String STEADY_EVAPORATION_LABEL = "Steady Evaporation"; + public static final String SUPERSONIC_FREESTREAM_LABEL = "Supersonic Freestream"; + public static final String SURFACE_EMISSIVITY_LABEL = "Surface Emissivity"; + public static final String SURFACE_LIQUID_MASS_LABEL = "Surface Liquid Mass [Kg/m" + Symbols.SQUARE + "]"; + public static final String SURFACE_NORMAL_FIXED_VALUE_LABEL = "Surface Normal Fixed Value"; + public static final String SURFACE_TRANSMISSIVITY_LABEL = "Surface Transmissivity"; + public static final String TABLE_DATA_LABEL = "Table Data"; + public static final String TABLE_FILE_COEFFS_KEY = "tableFileCoeffs"; + public static final String TANGENTIAL_GRADIENT_COEFFICIENT = "Tangential Gradient Coefficient"; + public static final String TEMPERATURE_INF_K_LABEL = "Temperature Inf " + KELVIN; + public static final String TEMPERATURE_INFLOW_VALUE_LABEL = "Inflow Value " + KELVIN; + public static final String TEMPERATURE_INITIAL_VALUE_LABEL = "Initial Value " + KELVIN; + public static final String TEMPERATURE_VALUE_LABEL = "Temperature Value " + KELVIN; + public static final String TEMPERATURE_VALUE_K_LABEL = "Temperature Value " + KELVIN; + public static final String THERMAL_CONDUCTION_LABEL = "Thermal Conduction"; + public static final String THERMAL_CREEP_LABEL = "Thermal Creep"; + public static final String THERMAL_RADIATION_LABEL = "Thermal Radiation"; + public static final String THICKNESS_M_LABEL = "Thickness " + M; + public static final String TIME_VARYING_FLOW_RATE_LABEL = "Time-varying Flow Rate"; + public static final String TIME_VARYING_LABEL = "Time-varying"; + public static final String TIME_VARYING_PHASE_FRACTION_LABEL = "Time-varying Phase Fraction"; + public static final String TIME_VARYING_VELOCITY_LABEL = "Time-varying Velocity"; + public static final String TIME_VARYING_TEMPERATURE_LABEL = "Time-varying Temperature"; + public static final String TIME_VARYING_TURBULENCE_LABEL = "Time-varying Turbulence"; + public static final String TOTAL_HEAT_LOAD_LABEL = "Total Heat Load"; + public static final String TOTAL_HEAT_LOAD_AT_WALL_W_LABEL = "Total Heat Load At Wall [W]"; + public static final String TOTAL_PRESSURE_LABEL = "Total Pressure"; + public static final String TOTAL_PRESSURE_COMP_LABEL = TOTAL_PRESSURE_LABEL + " " + PASCAL; + public static final String TOTAL_PRESSURE_INCOMP_LABEL = TOTAL_PRESSURE_LABEL + " " + M2_S2; + public static final String TOTAL_TEMPERATURE_LABEL = "Total Temperature"; + public static final String TRANSLATING_WALL_COUPLED_LABEL = "Tangential Wall (Coupled)"; + public static final String TURBULENCE_INTENSITY_LABEL = "Turbulence Intensity"; + public static final String TYPE_LABEL = "Type"; + public static final String U_LABEL = "U"; + public static final String USE_WALL_DISTANCE_LABEL = "Use Wall Distance"; + public static final String UINF_LABEL = "UInf " + M_S; + public static final String UNIFORM_VELOCITY_LABEL = "Uniform Velocity"; + public static final String USER_DEFINED_HEAT_LABEL = "User Defined Heat Flux
[W/m" + SQUARE + "]"; + public static final String USER_DEFINED_LABEL = "User Defined"; + public static final String VALUE_LABEL = "Value"; + public static final String VARIABLE_HEIGHT_FLOW_RATE_INLET_LABEL = "Variable Height Flow Rate Inlet"; + public static final String VARIABLE_HEIGHT_FLOW_RATE_LABEL = "Variable Height Flow Rate"; + public static final String VELOCITY_COMPONENTS_LABEL = "Velocity Components"; + public static final String VELOCITY_LABEL = "Velocity"; + public static final String VELOCITY_LABEL_MS = "Velocity " + M_S; + public static final String VELOCITY_MAGNITUDE_LABEL = "Velocity Magnitude " + M_S; + public static final String VELOCITY_TYPE_LABEL = "Velocity Type"; + public static final String VOLUMETRIC_FLOW_RATE_LABEL = "Volumetric Flow Rate [m" + CUBE + "/s]"; + public static final String VOLUMETRIC_FLOW_RATE_INLET_LABEL = "Volumetric Flow Rate Inlet"; + public static final String WALL_HEAT_LABEL = "Wall Heat Flux [W/m" + SQUARE + "]"; + public static final String WALL_DISTANCE_LABEL = "Wall Distance"; + public static final String WALL_TEMPERATURE_K_LABEL = "Wall Temperature " + KELVIN; + public static final String WALL_TYPE_LABEL = "Wall Type"; + public static final String WARN_LABEL = "Warn"; + public static final String WAVE_TRANSMISSIVE_LABEL = "Wave Transmissive"; + public static final String WEIGHT_LABEL = "Weight"; + public static final String WIND_DIRECTION_DEG_LABEL = "Wind Direction [deg]"; + public static final String WIND_UPWARD_DIRECTION_LABEL = "Wind Upward Direction"; + public static final String X_LABEL = "X"; + public static final String X_OFFSET_LABEL = "X Offset"; + public static final String X_SCALE_LABEL = "X Scale"; + public static final String Y_LABEL = "Y"; + public static final String Y_OFFSET_LABEL = "Y Offset"; + public static final String Y_SCALE_LABEL = "Y Scale"; + public static final String Z_LABEL = "Z"; + public static final String ZERO_GRADIENT_LABEL = "Zero Gradient"; + + /* + * LIST OF LABELS + */ + public static final String[] INTERP_ALGO_TYPE_LABELS = { REPEAT_LABEL, CLAMP_LABEL, WARN_LABEL, ERROR_LABEL }; - public static final String[] INTERP_ALGO_TYPE_KEYS = { "repeat", "clamp", "warn", "error" }; - public static final String TABLE_FILE_COEFFS_KEY = "tableFileCoeffs"; + /* + * Names + */ + public static final String INTERPOLATION_TABLE_NAME = "interpolation.table"; + public static final String MEAN_PRESSURE_NAME = "pressure.mean"; + public static final String PRESSURE_FIXED_NAME = "pressure.fixed"; + public static final String RESISTIVE_PRESSURE_NAME = "resistive.pressure"; + public static final String TOTAL_PRESSURE_NAME = "total.pressure"; - public static final String[] INTERP_ALGO_TYPE_LABELS = { "Repeat", "Clamp", "Warn", "Error" }; + public static void buildSimpleFixedVelocityPanel(DictionaryPanelBuilder builder, DictionaryModel model) { + builder.addComponent(VELOCITY_LABEL_MS, model.bindUniformPoint(VALUE_KEY)); + } - public static final String ZERO_GRADIENT_LABEL = "Zero Gradient"; - public static final String FIXED_VALUE_LABEL = "Fixed Value"; + public static void buildFreestreamVelocityPanel(DictionaryPanelBuilder builder, DictionaryModel model) { + builder.addComponent(VELOCITY_LABEL_MS, model.bindUniformPoint(VALUE_KEY, FREESTREAM_VALUE_KEY)); + } - public static final String NON_UNIFORM_TEMPERATURE_LABEL = "Non-uniform Temperature"; - public static final String NON_UNIFORM_TURBULENCE_LABEL = "Non-uniform Turbulence"; - public static final String NON_UNIFORM_PHASE_FRACTION_LABEL = "Non-uniform Phase Fraction"; + public static void buildFixedCylindricalVelocityPanel(DictionaryPanelBuilder builder, DictionaryModel model) { + builder.addComponent(AXIS_LABEL, model.bindPoint(AXIS_KEY)); + builder.addComponent(CENTRE_LABEL, model.bindPoint(CENTRE_KEY)); + builder.addComponent(AXIAL_VELOCITY_LABEL, model.bindDouble(AXIAL_VELOCITY_KEY)); + builder.addComponent(RPM_LABEL, model.bindDouble(RPM_KEY)); + builder.addComponent(RADIAL_VELOCITY_LABEL, model.bindDouble(RADIAL_VELOCITY_KEY)); + } - public static final String TIME_VARYING_LABEL = "Time-varying"; - public static final String TIME_VARYING_VELOCITY_LABEL = "Time-varying Velocity"; - public static final String TIME_VARYING_FLOW_RATE_LABEL = "Time-varying Flow Rate"; - public static final String TIME_VARYING_TEMPERATURE_LABEL = "Time-varying Temperature"; - public static final String TIME_VARYING_TURBULENCE_LABEL = "Time-varying Turbulence"; - public static final String TIME_VARYING_PHASE_FRACTION_LABEL = "Time-varying Phase Fraction"; + public static void buildTimeVaryingScalarPanel(DictionaryPanelBuilder builder, DictionaryModel model, String dictionaryKey, String name) { + buildTimeVaryingInterpolationTablePanel(builder, model, dictionaryKey, new String[] { name }); + } - public static final String TABLE_DATA_LABEL = "Table Data"; - public static final String INTERPOLATION_PROFILE_LABEL = "Interpolation Profile"; - public static final String FROM_FILE_LABEL = "From File"; + public static void buildTimeVaryingVectorPanel(DictionaryPanelBuilder builder, DictionaryModel model, String dictionaryKey, String X, String Y, String Z) { + buildTimeVaryingInterpolationTablePanel(builder, model, dictionaryKey, new String[] { X, Y, Z }); + } - public static final String INTERPOLATION_ALGORITHM_LABEL = "Interpolation Algorithm"; - - public static final String VELOCITY_LABEL = "Velocity " + Symbols.M_S; + /* + * Utils + */ - public static void buildSimpleFixedVelocityPanel(DictionaryPanelBuilder builder, DictionaryModel model) { - builder.addComponent(VELOCITY_LABEL, model.bindUniformPoint("value")); - } + private static void buildTimeVaryingInterpolationTablePanel(DictionaryPanelBuilder builder, final DictionaryModel model, final String dictionaryKey, final String[] names) { + builder.startChoice(INTERPOLATION_PROFILE_LABEL, new TimeVaryingComboBoxController(model, dictionaryKey)); - public static void buildFreestreamVelocityPanel(DictionaryPanelBuilder builder, DictionaryModel model) { - builder.addComponent(VELOCITY_LABEL, model.bindUniformPoint("value", "freestreamValue")); - } + builder.startGroup(DATA_KEY, TABLE_DATA_LABEL); + final boolean isVector = names.length == 3; + SparklineChart sparkline = new DictionarySparkline(model, dictionaryKey, isVector); + JButton editButton = new JButton(new AbstractAction(EDIT_BUTTON_LABEL) { + @Override + public void actionPerformed(ActionEvent e) { + if (isVector) { + VectorTimeVaryingInterpolationTable table = new VectorTimeVaryingInterpolationTable(names); + table.load(model.getDictionary(), dictionaryKey); + table.showDialog(); + table.save(model.getDictionary(), dictionaryKey); + } else { + ScalarTimeVaryingInterpolationTable table = new ScalarTimeVaryingInterpolationTable(names); + table.load(model.getDictionary(), dictionaryKey); + table.showDialog(); + table.save(model.getDictionary(), dictionaryKey); + } + model.refresh(); + } + }); + editButton.setName(EDIT_BUTTON_LABEL); + builder.addComponent("", Componentizer.create().minToPref(editButton).minToPref(sparkline).component()); + builder.endGroup(); - public static void buildFixedCylindricalVelocityPanel(DictionaryPanelBuilder builder, DictionaryModel model) { - builder.addComponent("Axis", model.bindPoint("axis")); - builder.addComponent("Centre", model.bindPoint("centre")); - builder.addComponent("Axial Velocity", model.bindDouble("axialVelocity")); - builder.addComponent("RPM", model.bindDouble("rpm")); - builder.addComponent("Radial Velocity", model.bindDouble("radialVelocity")); - } + builder.startGroup(FILE_KEY, FROM_FILE_LABEL); + builder.addComponent("", model.bindFile(FILE_NAME_KEY)); + builder.endGroup(); - public static void buildTimeVaryingScalarPanel(DictionaryPanelBuilder builder, DictionaryModel model, String dictionaryKey, String name) { - buildTimeVaryingInterpolationTablePanel(builder, model, dictionaryKey, new String[]{name}); - } + builder.endChoice(); - public static void buildTimeVaryingVectorPanel(DictionaryPanelBuilder builder, DictionaryModel model, String dictionaryKey, String X, String Y, String Z) { - buildTimeVaryingInterpolationTablePanel(builder, model, dictionaryKey, new String[]{X,Y,Z}); - } + builder.addComponent(INTERPOLATION_ALGORITHM_LABEL, model.bindSelection(OUT_OF_BOUNDS_KEY, INTERP_ALGO_TYPE_KEYS, INTERP_ALGO_TYPE_LABELS)); + } - /* - * Utils - */ + /* + * Time varying fix + */ - private static void buildTimeVaryingInterpolationTablePanel(DictionaryPanelBuilder builder, final DictionaryModel model, final String dictionaryKey, final String[] names) { - builder.startChoice(INTERPOLATION_PROFILE_LABEL, new TimeVaryingComboBoxController(model, dictionaryKey)); + public static void fixTimeVaryingLoad(Dictionary dict, String dictionaryKey) { + String type = dict.lookup(TYPE); + if (type.equals(UNIFORM_FIXED_VALUE_KEY) || type.equals(ROTATING_WALL_VELOCITY_KEY) || type.equals(FLOW_RATE_INLET_VELOCITY_KEY) || type.equals(FLOW_RATE_OUTLET_VELOCITY_KEY) || type.equals(UNIFORM_TOTAL_PRESSURE_KEY)) { + if (isTableFile(dict, dictionaryKey)) { + if (dict.found(TABLE_FILE_COEFFS_KEY)) { + Dictionary tableFileCoeffs = dict.subDict(TABLE_FILE_COEFFS_KEY); + dict.add(OUT_OF_BOUNDS_KEY, tableFileCoeffs.lookup(OUT_OF_BOUNDS_KEY)); + dict.add(FILE_NAME_KEY, tableFileCoeffs.lookup(FILE_NAME_KEY)); + dict.remove(TABLE_FILE_COEFFS_KEY); + } + } + } + } - builder.startGroup(DATA_KEY, TABLE_DATA_LABEL); - JButton editButton = new JButton(new AbstractAction("Edit") { - @Override - public void actionPerformed(ActionEvent e) { - new TimeVaryingInterpolationTable(model, dictionaryKey + " " + TABLE_KEY, names).showDialog(); - } - }); - editButton.setName("Edit"); - builder.addComponent("", Componentizer.create().minToPref(editButton).component()); - builder.endGroup(); + public static void fixTimeVaryingSave(Dictionary dict, String dictionaryKey) { + String type = dict.lookup(TYPE); + if (type.equals(UNIFORM_FIXED_VALUE_KEY) || type.equals(ROTATING_WALL_VELOCITY_KEY) || type.equals(FLOW_RATE_INLET_VELOCITY_KEY) || type.equals(FLOW_RATE_OUTLET_VELOCITY_KEY) || type.equals(UNIFORM_TOTAL_PRESSURE_KEY)) { + if (isTableFile(dict, dictionaryKey)) { + Dictionary tableFileCoeffs = new Dictionary(TABLE_FILE_COEFFS_KEY); + tableFileCoeffs.add(OUT_OF_BOUNDS_KEY, dict.lookup(OUT_OF_BOUNDS_KEY)); + tableFileCoeffs.add(FILE_NAME_KEY, dict.lookup(FILE_NAME_KEY)); + dict.remove(OUT_OF_BOUNDS_KEY); + dict.remove(FILE_NAME_KEY); + dict.add(tableFileCoeffs); + } else { + dict.remove(FILE_NAME_KEY); + } + } + } - builder.startGroup(FILE_KEY, FROM_FILE_LABEL); - builder.addComponent("", model.bindFile(FILE_NAME_KEY)); - builder.endGroup(); + public static boolean isTableFile(Dictionary dict, String dictionaryKey) { + if (dict == null) { + return false; + } + if (dict.found(TABLE_FILE_COEFFS_KEY)) { + return true; + } + if (!dict.found(dictionaryKey)) { + return false; + } + if (!dict.isField(dictionaryKey)) { + return false; + } + return dict.lookup(dictionaryKey).equals(TABLE_FILE_KEY); + } - builder.endChoice(); - - builder.addComponent(INTERPOLATION_ALGORITHM_LABEL, model.bindSelection(OUT_OF_BOUNDS_KEY, INTERP_ALGO_TYPE_KEYS, INTERP_ALGO_TYPE_LABELS)); - } - - /* - * Time varying fix - */ - - public static void fixTimeVaryingLoad(Dictionary dict, String dictionaryKey) { - String type = dict.lookup(TYPE); - if (type.equals(UNIFORM_FIXED_VALUE_KEY) || type.equals(ROTATING_WALL_VELOCITY_KEY) || type.equals(FLOW_RATE_INLET_VELOCITY_KEY) || type.equals(UNIFORM_TOTAL_PRESSURE_KEY)) { - if (isTableFile(dict, dictionaryKey)) { - if (dict.found(TABLE_FILE_COEFFS_KEY)) { - Dictionary tableFileCoeffs = dict.subDict(TABLE_FILE_COEFFS_KEY); - dict.add(OUT_OF_BOUNDS_KEY, tableFileCoeffs.lookup(OUT_OF_BOUNDS_KEY)); - dict.add(FILE_NAME_KEY, tableFileCoeffs.lookup(FILE_NAME_KEY)); - dict.remove(TABLE_FILE_COEFFS_KEY); - } - } - } - } - - public static void fixTimeVaryingSave(Dictionary dict, String dictionaryKey) { - String type = dict.lookup(TYPE); - if (type.equals(UNIFORM_FIXED_VALUE_KEY) || type.equals(ROTATING_WALL_VELOCITY_KEY) || type.equals(FLOW_RATE_INLET_VELOCITY_KEY) || type.equals(UNIFORM_TOTAL_PRESSURE_KEY)) { - if (isTableFile(dict, dictionaryKey)) { - Dictionary tableFileCoeffs = new Dictionary(TABLE_FILE_COEFFS_KEY); - tableFileCoeffs.add(OUT_OF_BOUNDS_KEY, dict.lookup(OUT_OF_BOUNDS_KEY)); - tableFileCoeffs.add(FILE_NAME_KEY, dict.lookup(FILE_NAME_KEY)); - dict.remove(OUT_OF_BOUNDS_KEY); - dict.remove(FILE_NAME_KEY); - dict.add(tableFileCoeffs); - } else { - dict.remove(FILE_NAME_KEY); - } - } - } - - public static boolean isTableFile(Dictionary dict, String dictionaryKey) { - if (dict == null) { - return false; - } - if (!dict.found(dictionaryKey)) { - return false; - } - if (!dict.isField(dictionaryKey)) { - return false; - } - return dict.lookup(dictionaryKey).equals(TABLE_FILE_KEY); - } - - public static void loadFlowRate(Dictionary U, DictionaryPanelBuilder builder) { + public static void loadFlowRate(Dictionary U, DictionaryPanelBuilder builder) { if (U.found(MASS_FLOW_RATE_KEY)) { - if (U.lookup(MASS_FLOW_RATE_KEY).startsWith(TABLE_KEY)) { + String value = U.lookupString(MASS_FLOW_RATE_KEY); + if (value.equals(TABLE_FILE_KEY) || value.startsWith(TABLE_KEY)) { fixTimeVaryingLoad(U, MASS_FLOW_RATE_KEY); builder.selectDictionaryByKey(BoundaryConditionsUtils.getTimeVaryingMassFlowRate(), U); } else { builder.selectDictionaryByKey(BoundaryConditionsUtils.getMassFlowRate(), U); } + } else if (U.found(new StartWithFinder(MASS_FLOW_RATE_KEY))) { + builder.selectDictionaryByKey(BoundaryConditionsUtils.getTimeVaryingMassFlowRate(), U); } else if (U.found(VOLUMETRIC_FLOW_RATE_KEY)) { - if (U.lookup(VOLUMETRIC_FLOW_RATE_KEY).startsWith(TABLE_KEY)) { + String value = U.lookupString(VOLUMETRIC_FLOW_RATE_KEY); + if (value.equals(TABLE_FILE_KEY) || value.startsWith(TABLE_KEY)) { fixTimeVaryingLoad(U, VOLUMETRIC_FLOW_RATE_KEY); builder.selectDictionaryByKey(BoundaryConditionsUtils.getTimeVaryingVolumetricFlowRate(), U); } else { builder.selectDictionaryByKey(BoundaryConditionsUtils.getVolumetricFlowRate(), U); } + } else if (U.found(new StartWithFinder(VOLUMETRIC_FLOW_RATE_KEY))) { + builder.selectDictionaryByKey(BoundaryConditionsUtils.getTimeVaryingVolumetricFlowRate(), U); + } else if (U.found(FLOW_RATE_KEY)) { builder.selectDictionaryByKey(BoundaryConditionsUtils.getVariableHeightFlowRate(), U); } diff --git a/src/eu/engys/gui/casesetup/boundaryconditions/utils/ThermalUtils.java b/src/eu/engys/gui/casesetup/boundaryconditions/utils/ThermalUtils.java index 1f33b4d..e53f982 100644 --- a/src/eu/engys/gui/casesetup/boundaryconditions/utils/ThermalUtils.java +++ b/src/eu/engys/gui/casesetup/boundaryconditions/utils/ThermalUtils.java @@ -1,63 +1,59 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.casesetup.boundaryconditions.utils; import static eu.engys.core.dictionary.Dictionary.VALUE; + import eu.engys.core.dictionary.model.DictionaryModel; import eu.engys.core.dictionary.model.DictionaryPanelBuilder; public class ThermalUtils extends BoundaryConditionsUtils { - public static final String INLET_VALUE_KEY = "inletValue"; - public static final String GAMMA_KEY = "gamma"; - public static final String T0_KEY = "T0"; - - public static final String RATIO_OF_SPECIFIC_HEATS_LABEL = "Ratio Of Specific Heats"; - public static final String TOTAL_TEMPERATURE_LABEL = "Total Temperature"; - public static final String TEMPERATURE_VALUE_K_LABEL = "Temperature Value [K]"; - public static final String FIXED_TEMPERATURE_LABEL = "Fixed Temperature"; - public static void buildFixedTemperaturePanel(DictionaryPanelBuilder builder, DictionaryModel model) { builder.startDictionary(FIXED_TEMPERATURE_LABEL, model); - builder.addComponent(TEMPERATURE_VALUE_K_LABEL, model.bindUniformDouble(VALUE)); + builder.addComponent(TEMPERATURE_VALUE_LABEL, model.bindUniformDouble(VALUE)); builder.endDictionary(); model.setDictionary(model.getDictionary()); } public static void buildInletOutletTemperaturePanel(DictionaryPanelBuilder builder, DictionaryModel model) { - builder.startDictionary(FIXED_TEMPERATURE_LABEL, model); - builder.addComponent(TEMPERATURE_VALUE_K_LABEL, model.bindUniformDouble(INLET_VALUE_KEY)); + builder.startDictionary(INFLOW_FIXED_TEMPERATURE_LABEL, model); + builder.addComponent(TEMPERATURE_INITIAL_VALUE_LABEL, model.bindUniformDouble(VALUE)); + builder.addComponent(TEMPERATURE_INFLOW_VALUE_LABEL, model.bindUniformDouble(INLET_VALUE_KEY)); + builder.endDictionary(); + } + + public static void buildAdvectiveTemperaturePanel(DictionaryPanelBuilder builder, DictionaryModel model) { + builder.startDictionary(ADVECTIVE_TEMPERATURE_LABEL, model); builder.endDictionary(); } public static void buildTotalTemperaturePanel(DictionaryPanelBuilder builder, DictionaryModel dict) { builder.startDictionary(TOTAL_TEMPERATURE_LABEL, dict); builder.addComponent(RATIO_OF_SPECIFIC_HEATS_LABEL, dict.bindDouble(GAMMA_KEY)); - builder.addComponent(TEMPERATURE_VALUE_K_LABEL, dict.bindUniformDouble(T0_KEY)); + builder.addComponent(TEMPERATURE_VALUE_LABEL, dict.bindUniformDouble(T0_KEY)); builder.endDictionary(); } diff --git a/src/eu/engys/gui/casesetup/boundaryconditions/utils/TurbulenceUtils.java b/src/eu/engys/gui/casesetup/boundaryconditions/utils/TurbulenceUtils.java index 600dacd..e57b901 100644 --- a/src/eu/engys/gui/casesetup/boundaryconditions/utils/TurbulenceUtils.java +++ b/src/eu/engys/gui/casesetup/boundaryconditions/utils/TurbulenceUtils.java @@ -1,83 +1,56 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.casesetup.boundaryconditions.utils; -import static eu.engys.util.Symbols.EPSILON_SYMBOL; -import static eu.engys.util.Symbols.K_SYMBOL; -import static eu.engys.util.Symbols.M2_S; -import static eu.engys.util.Symbols.OMEGA_SYMBOL; import eu.engys.core.dictionary.model.DictionaryModel; import eu.engys.core.dictionary.model.DictionaryPanelBuilder; public class TurbulenceUtils extends BoundaryConditionsUtils { - public static final String FIXED_VALUES_LABEL = "Fixed Values"; - public static final String INFLOW_FIXED_VALUES_LABEL = "Inflow Fixed Values"; - public static final String INLET_OUTLET_LABEL = "Inlet Outlet"; - public static final String ZERO_GRADIENT_LABEL = "Zero Gradient"; - public static final String BY_TURB_INTENSITY_AND_MIXING_LENGTH_LABEL = "By Turb. Intensity And Mixing Length"; - - public static final String K_LABEL = "k " + K_SYMBOL;// "Turbulent Kinetik Energy"; - public static final String NU_TILDA_LABEL = "NuTilda " + M2_S; - public static final String EPSILON_LABEL = "Epsilon " + EPSILON_SYMBOL; - public static final String OMEGA_LABEL = "Omega " + OMEGA_SYMBOL; - public static final String KEQUATION_LABEL = K_LABEL; - - private static final String TIMEVARYING_KEY = "timevarying"; - private static final String NONUNIFROM_KEY = "nonunifrom"; - private static final String FIXED_KEY = "fixed"; - private static final String ZERO_KEY = "zero"; - private static final String INOUT_KEY = "inout"; - private static final String MIXING_KEY = "mixing"; - - public static final String TURBULENCE_INTENSITY = "Turbulence Intensity"; - public static void buildFixedKnownValuesPanel(DictionaryPanelBuilder builder, DictionaryModel dictK, DictionaryModel dictOmega, DictionaryModel dictEpsilon, DictionaryModel dictNutilda) { builder.startGroup(FIXED_VALUES_LABEL); builder.startHidable(FIXED_KEY); dictOmega.setCompanion(dictK); - builder.startDictionary(OMEGA_LABEL, dictOmega); - builder.addComponent(K_LABEL, dictK.bindUniformDouble("value")); - builder.addComponent(OMEGA_LABEL, dictOmega.bindUniformDouble("value")); + builder.startDictionary(OMEGA_TURBULENCE_LABEL, dictOmega); + builder.addComponent(K_LABEL, dictK.bindUniformDouble(VALUE_KEY)); + builder.addComponent(OMEGA_TURBULENCE_LABEL, dictOmega.bindUniformDouble(VALUE_KEY)); builder.endDictionary(); dictEpsilon.setCompanion(dictK); builder.startDictionary(EPSILON_LABEL, dictEpsilon); - builder.addComponent(K_LABEL, dictK.bindUniformDouble("value")); - builder.addComponent(EPSILON_LABEL, dictEpsilon.bindUniformDouble("value")); + builder.addComponent(K_LABEL, dictK.bindUniformDouble(VALUE_KEY)); + builder.addComponent(EPSILON_LABEL, dictEpsilon.bindUniformDouble(VALUE_KEY)); builder.endDictionary(); - builder.startDictionary(NU_TILDA_LABEL, dictNutilda); - builder.addComponent(NU_TILDA_LABEL, dictNutilda.bindUniformDouble("value")); + builder.startDictionary(NUTILDA_LABEL, dictNutilda); + builder.addComponent(NUTILDA_LABEL, dictNutilda.bindUniformDouble(VALUE_KEY)); builder.endDictionary(); builder.startDictionary(KEQUATION_LABEL, dictK); - builder.addComponent(K_LABEL, dictK.bindUniformDouble("value")); + builder.addComponent(K_LABEL, dictK.bindUniformDouble(VALUE_KEY)); builder.endDictionary(); builder.endHidable(); @@ -89,23 +62,23 @@ public class TurbulenceUtils extends BoundaryConditionsUtils { builder.startHidable(INOUT_KEY); dictOmega.setCompanion(dictK); - builder.startDictionary(OMEGA_LABEL, dictOmega); - builder.addComponent(K_LABEL, dictK.bindUniformDouble("inletValue")); - builder.addComponent(OMEGA_LABEL, dictOmega.bindUniformDouble("inletValue")); + builder.startDictionary(OMEGA_TURBULENCE_LABEL, dictOmega); + builder.addComponent(K_LABEL, dictK.bindUniformDouble(INLET_VALUE_KEY)); + builder.addComponent(OMEGA_TURBULENCE_LABEL, dictOmega.bindUniformDouble(INLET_VALUE_KEY)); builder.endDictionary(); dictEpsilon.setCompanion(dictK); builder.startDictionary(EPSILON_LABEL, dictEpsilon); - builder.addComponent(K_LABEL, dictK.bindUniformDouble("inletValue")); - builder.addComponent(EPSILON_LABEL, dictEpsilon.bindUniformDouble("inletValue")); + builder.addComponent(K_LABEL, dictK.bindUniformDouble(INLET_VALUE_KEY)); + builder.addComponent(EPSILON_LABEL, dictEpsilon.bindUniformDouble(INLET_VALUE_KEY)); builder.endDictionary(); - builder.startDictionary(NU_TILDA_LABEL, dictNutilda); - builder.addComponent(NU_TILDA_LABEL, dictNutilda.bindUniformDouble("inletValue")); + builder.startDictionary(NUTILDA_LABEL, dictNutilda); + builder.addComponent(NUTILDA_LABEL, dictNutilda.bindUniformDouble(INLET_VALUE_KEY)); builder.endDictionary(); builder.startDictionary(KEQUATION_LABEL, dictK); - builder.addComponent(K_LABEL, dictK.bindUniformDouble("inletValue")); + builder.addComponent(K_LABEL, dictK.bindUniformDouble(INLET_VALUE_KEY)); builder.endDictionary(); builder.endHidable(); @@ -117,14 +90,14 @@ public class TurbulenceUtils extends BoundaryConditionsUtils { builder.startHidable(ZERO_KEY); dictOmega.setCompanion(dictK); - builder.startDictionary(OMEGA_LABEL, dictOmega); + builder.startDictionary(OMEGA_TURBULENCE_LABEL, dictOmega); builder.endDictionary(); dictEpsilon.setCompanion(dictK); builder.startDictionary(EPSILON_LABEL, dictEpsilon); builder.endDictionary(); - builder.startDictionary(NU_TILDA_LABEL, dictNutilda); + builder.startDictionary(NUTILDA_LABEL, dictNutilda); builder.endDictionary(); builder.startDictionary(KEQUATION_LABEL, dictK); @@ -139,24 +112,24 @@ public class TurbulenceUtils extends BoundaryConditionsUtils { builder.startHidable(MIXING_KEY); dictOmega.setCompanion(dictK); - builder.startDictionary(OMEGA_LABEL, dictOmega); + builder.startDictionary(OMEGA_TURBULENCE_LABEL, dictOmega); // builder.addComponent(new JLabel(OMEGA_LABEL), new JLabel("")); - builder.addComponent(TURBULENCE_INTENSITY, dictK.bindDouble("intensity")); - builder.addComponent("Mixing Length [m]", dictOmega.bindDouble("mixingLength")); + builder.addComponent(TURBULENCE_INTENSITY_LABEL, dictK.bindDouble(INTENSITY_KEY)); + builder.addComponent(MIXING_LENGTH_LABEL, dictOmega.bindDouble(MIXING_LENGTH_KEY)); builder.endDictionary(); dictEpsilon.setCompanion(dictK); builder.startDictionary(EPSILON_LABEL, dictEpsilon); // builder.addComponent(new JLabel(EPSILON_LABEL), new JLabel("")); - builder.addComponent(TURBULENCE_INTENSITY, dictK.bindDouble("intensity")); - builder.addComponent("Mixing Length [m]", dictEpsilon.bindDouble("mixingLength")); + builder.addComponent(TURBULENCE_INTENSITY_LABEL, dictK.bindDouble(INTENSITY_KEY)); + builder.addComponent(MIXING_LENGTH_LABEL, dictEpsilon.bindDouble(MIXING_LENGTH_KEY)); builder.endDictionary(); if (dictNuTilda != null) { - builder.startDictionary(NU_TILDA_LABEL, dictNuTilda); + builder.startDictionary(NUTILDA_LABEL, dictNuTilda); // builder.addComponent(new JLabel(NU_TILDA_LABEL), new JLabel("")); - builder.addComponent(TURBULENCE_INTENSITY, dictNuTilda.bindDouble("intensity")); - builder.addComponent("Mixing Length [m]", dictNuTilda.bindDouble("length")); + builder.addComponent(TURBULENCE_INTENSITY_LABEL, dictNuTilda.bindDouble(INTENSITY_KEY)); + builder.addComponent(MIXING_LENGTH_LABEL, dictNuTilda.bindDouble(LENGTH_KEY)); builder.endDictionary(); } @@ -168,12 +141,12 @@ public class TurbulenceUtils extends BoundaryConditionsUtils { public static void setSpalartAllmaras(DictionaryPanelBuilder builder) { // Dictionary selectedDict = builder.getSelectedModel().getDictionary(); - builder.setShowing(FIXED_KEY, NU_TILDA_LABEL); + builder.setShowing(FIXED_KEY, NUTILDA_LABEL); // builder.setShowing(MIXING_KEY, NU_TILDA_LABEL); - builder.setShowing(NONUNIFROM_KEY, NU_TILDA_LABEL); - builder.setShowing(TIMEVARYING_KEY, NU_TILDA_LABEL); - builder.setShowing(INOUT_KEY, NU_TILDA_LABEL); - builder.setShowing(ZERO_KEY, NU_TILDA_LABEL); + builder.setShowing(NONUNIFROM_KEY, NUTILDA_LABEL); + builder.setShowing(TIMEVARYING_KEY, NUTILDA_LABEL); + builder.setShowing(INOUT_KEY, NUTILDA_LABEL); + builder.setShowing(ZERO_KEY, NUTILDA_LABEL); // builder.selectDictionary(selectedDict); } @@ -195,12 +168,12 @@ public class TurbulenceUtils extends BoundaryConditionsUtils { // Dictionary selectedCompanion = // builder.getSelectedModel().getCompanion().getDictionary(); - builder.setShowing(FIXED_KEY, OMEGA_LABEL); - builder.setShowing(MIXING_KEY, OMEGA_LABEL); - builder.setShowing(NONUNIFROM_KEY, OMEGA_LABEL); - builder.setShowing(TIMEVARYING_KEY, OMEGA_LABEL); - builder.setShowing(INOUT_KEY, OMEGA_LABEL); - builder.setShowing(ZERO_KEY, OMEGA_LABEL); + builder.setShowing(FIXED_KEY, OMEGA_TURBULENCE_LABEL); + builder.setShowing(MIXING_KEY, OMEGA_TURBULENCE_LABEL); + builder.setShowing(NONUNIFROM_KEY, OMEGA_TURBULENCE_LABEL); + builder.setShowing(TIMEVARYING_KEY, OMEGA_TURBULENCE_LABEL); + builder.setShowing(INOUT_KEY, OMEGA_TURBULENCE_LABEL); + builder.setShowing(ZERO_KEY, OMEGA_TURBULENCE_LABEL); // builder.selectDictionaries(selectedDict, selectedCompanion); } diff --git a/src/eu/engys/gui/casesetup/cellzones/CellZoneComparator.java b/src/eu/engys/gui/casesetup/cellzones/CellZoneComparator.java index 9a2d7a1..81f431b 100644 --- a/src/eu/engys/gui/casesetup/cellzones/CellZoneComparator.java +++ b/src/eu/engys/gui/casesetup/cellzones/CellZoneComparator.java @@ -1,34 +1,34 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.casesetup.cellzones; +import static eu.engys.core.project.zero.cellzones.CellZoneType.DYNAMIC_MESH_KEY; +import static eu.engys.core.project.zero.cellzones.CellZoneType.HEAT_EXCHANGER_KEY; import static eu.engys.core.project.zero.cellzones.CellZoneType.HUMIDITY_KEY; import static eu.engys.core.project.zero.cellzones.CellZoneType.MRF_KEY; import static eu.engys.core.project.zero.cellzones.CellZoneType.POROUS_KEY; -import static eu.engys.core.project.zero.cellzones.CellZoneType.SLIDING_MESH_KEY; import static eu.engys.core.project.zero.cellzones.CellZoneType.THERMAL_KEY; import java.util.Arrays; @@ -38,7 +38,12 @@ import eu.engys.core.project.zero.cellzones.CellZoneType; public class CellZoneComparator implements Comparator { - public static final String[] ORDERED_KEYS = new String[] { POROUS_KEY, MRF_KEY, SLIDING_MESH_KEY, THERMAL_KEY, HUMIDITY_KEY }; + public static final String[] ORDERED_KEYS = new String[] { + POROUS_KEY, MRF_KEY, + DYNAMIC_MESH_KEY, + THERMAL_KEY, + HEAT_EXCHANGER_KEY, + HUMIDITY_KEY }; @Override public int compare(CellZoneType type1, CellZoneType type2) { diff --git a/src/eu/engys/gui/casesetup/cellzones/CellZonesFactory.java b/src/eu/engys/gui/casesetup/cellzones/CellZonesFactory.java index e5e3fb6..f202689 100644 --- a/src/eu/engys/gui/casesetup/cellzones/CellZonesFactory.java +++ b/src/eu/engys/gui/casesetup/cellzones/CellZonesFactory.java @@ -1,34 +1,33 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.casesetup.cellzones; +import static eu.engys.core.project.zero.cellzones.CellZoneType.HEAT_EXCHANGER_KEY; import static eu.engys.core.project.zero.cellzones.CellZoneType.HUMIDITY_KEY; import static eu.engys.core.project.zero.cellzones.CellZoneType.MRF_KEY; import static eu.engys.core.project.zero.cellzones.CellZoneType.POROUS_KEY; -import static eu.engys.core.project.zero.cellzones.CellZoneType.SLIDING_MESH_KEY; import static eu.engys.core.project.zero.cellzones.CellZoneType.THERMAL_KEY; import static eu.engys.core.project.zero.cellzones.CellZonesUtils.ABSOLUTE_KEY; import static eu.engys.core.project.zero.cellzones.CellZonesUtils.ATTACHED_PATCHES_KEY; @@ -40,30 +39,45 @@ import static eu.engys.core.project.zero.cellzones.CellZonesUtils.CM_KEY; import static eu.engys.core.project.zero.cellzones.CellZonesUtils.D_KEY; import static eu.engys.core.project.zero.cellzones.CellZonesUtils.E1_KEY; import static eu.engys.core.project.zero.cellzones.CellZonesUtils.E2_KEY; +import static eu.engys.core.project.zero.cellzones.CellZonesUtils.FACE_ZONE_KEY; import static eu.engys.core.project.zero.cellzones.CellZonesUtils.F_KEY; import static eu.engys.core.project.zero.cellzones.CellZonesUtils.NON_ROTATING_PATCHES_KEY; import static eu.engys.core.project.zero.cellzones.CellZonesUtils.OMEGA_KEY; import static eu.engys.core.project.zero.cellzones.CellZonesUtils.ORIGIN_KEY; -import static eu.engys.core.project.zero.cellzones.CellZonesUtils.PERIOD_KEY; import static eu.engys.core.project.zero.cellzones.CellZonesUtils.PLACE_HOLDER_KEY; import static eu.engys.core.project.zero.cellzones.CellZonesUtils.POROUS_DARCY_KEY; import static eu.engys.core.project.zero.cellzones.CellZonesUtils.POROUS_POWER_LAW_KEY; +import static eu.engys.core.project.zero.cellzones.CellZonesUtils.PRIMARY_INLET_T_KEY; +import static eu.engys.core.project.zero.cellzones.CellZonesUtils.SECONDARY_INLET_T_KEY; +import static eu.engys.core.project.zero.cellzones.CellZonesUtils.SECONDARY_MASS_FLOW_RATE_KEY; import static eu.engys.core.project.zero.cellzones.CellZonesUtils.SPECIFIC_KEY; import static eu.engys.core.project.zero.cellzones.CellZonesUtils.T0_KEY; import static eu.engys.core.project.zero.cellzones.CellZonesUtils.TEMPERATURE_KEY; import static eu.engys.core.project.zero.cellzones.CellZonesUtils.THERMAL_EXPONENTIAL_KEY; import static eu.engys.core.project.zero.cellzones.CellZonesUtils.THERMAL_FIXED_KEY; import static eu.engys.core.project.zero.cellzones.CellZonesUtils.THERMAL_SCALAR_KEY; -import static eu.engys.core.project.zero.cellzones.CellZonesUtils.THETA_KEY; import static eu.engys.core.project.zero.cellzones.CellZonesUtils.T_KEY; import static eu.engys.core.project.zero.cellzones.CellZonesUtils.VOLUME_MODE_KEY; import static eu.engys.core.project.zero.cellzones.CellZonesUtils.W_KEY; -import static eu.engys.core.project.zero.cellzones.CellZonesUtils.t0_KEY; + import eu.engys.core.dictionary.Dictionary; import eu.engys.core.dictionary.DimensionedScalar; import eu.engys.util.DimensionalUnits; public class CellZonesFactory { + + /* + * HEAT EXCHANGER + */ + public static Dictionary heatExchanger = new Dictionary(HEAT_EXCHANGER_KEY) { + { + add(TYPE, HEAT_EXCHANGER_KEY); + add(PRIMARY_INLET_T_KEY, 313); + add(SECONDARY_INLET_T_KEY, 375.6); + add(SECONDARY_MASS_FLOW_RATE_KEY, 1.01); + add(FACE_ZONE_KEY, ""); + } + }; /* * MRF @@ -71,9 +85,9 @@ public class CellZonesFactory { public static Dictionary mrf = new Dictionary(MRF_KEY) { { add(TYPE, MRF_KEY); - add(ORIGIN_KEY, "(0 0 0)"); - add(AXIS_KEY, "(0 0 1)"); - add(OMEGA_KEY, "constant 104.72"); + add(ORIGIN_KEY, new double[]{0, 0, 0}); + add(AXIS_KEY, new double[]{0, 0, 1}); + addConstant(OMEGA_KEY, 104.72); add(NON_ROTATING_PATCHES_KEY, "()"); add(ATTACHED_PATCHES_KEY, "()"); } @@ -95,8 +109,8 @@ public class CellZonesFactory { public static Dictionary porousPowerLaw = new Dictionary(POROUS_KEY) { { add(TYPE, POROUS_POWER_LAW_KEY); - add(C0_KEY, "1e-14"); - add(C1_KEY, "1"); + add(C0_KEY, 1e-14); + add(C1_KEY, 1); } }; @@ -106,23 +120,23 @@ public class CellZonesFactory { public static Dictionary thermalFixedTemperature = new Dictionary(THERMAL_KEY) { { add(TYPE, THERMAL_FIXED_KEY); - add(TEMPERATURE_KEY, "constant 350"); + addConstant(TEMPERATURE_KEY, 350); } }; public static Dictionary thermalFixedTemperature_OS = new Dictionary(THERMAL_KEY) { { add(TYPE, THERMAL_FIXED_KEY); - add(T_KEY, "350"); + add(T_KEY, 350); } }; public static Dictionary thermalExponential = new Dictionary(THERMAL_KEY) { { add(TYPE, THERMAL_EXPONENTIAL_KEY); - add(CM_KEY, "0.291"); - add(CE_KEY, "1.369"); - add(T0_KEY, "350"); + add(CM_KEY, 0.291); + add(CE_KEY, 1.369); + add(T0_KEY, 350); } }; @@ -146,36 +160,6 @@ public class CellZonesFactory { } }; - /* - * Rotating - */ - public static Dictionary slidingMesh = new Dictionary(SLIDING_MESH_KEY) { - { - add(ORIGIN_KEY, "(0 0 0)"); - add(AXIS_KEY, "(0 0 1)"); - add(OMEGA_KEY, "1"); - - } - }; - - public static Dictionary coupledSlidingMesh_steady = new Dictionary(SLIDING_MESH_KEY) { - { - add(ORIGIN_KEY, "(0 0 0)"); - add(AXIS_KEY, "(0 0 1)"); - add(THETA_KEY, "60"); - add(PERIOD_KEY, "150"); - } - }; - - public static Dictionary coupledSlidingMesh_transient = new Dictionary(SLIDING_MESH_KEY) { - { - add(ORIGIN_KEY, "(0 0 0)"); - add(AXIS_KEY, "(0 0 1)"); - add(OMEGA_KEY, "-308.92"); - add(t0_KEY, "2"); - } - }; - // For tests purposes only public static Dictionary thermalScalarSemiImplicit_Specific = new Dictionary(THERMAL_KEY) { { diff --git a/src/eu/engys/gui/casesetup/cellzones/CellZonesPanel.java b/src/eu/engys/gui/casesetup/cellzones/CellZonesPanel.java index d182ca2..f007763 100644 --- a/src/eu/engys/gui/casesetup/cellzones/CellZonesPanel.java +++ b/src/eu/engys/gui/casesetup/cellzones/CellZonesPanel.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.casesetup.cellzones; import static eu.engys.gui.casesetup.cellzones.SourceTypeSelectionPanel.UPDATE_SELECTION; @@ -54,8 +53,8 @@ import eu.engys.util.ui.textfields.StringField; public class CellZonesPanel extends AbstractGUIPanel { public static final String CELL_ZONES = "Cell Zones"; - public static final String CELL_ZONE_NAME_LABEL = "CellZone Name"; - public static final String CELL_ZONE_TYPE_LABEL = "CellZone Type"; + public static final String CELL_ZONE_NAME_LABEL = "Cell Zone Name"; + public static final String CELL_ZONE_TYPE_LABEL = "Cell Zone Type"; private CellZonesTreeNodeManager treeNodeManager; private List types; @@ -64,8 +63,6 @@ public class CellZonesPanel extends AbstractGUIPanel { private SourcePanelContainer centerPanel; private SourceTypeSelectionPanel zoneTypePanel; -// private PropertyChangeListener zoneNameListener; - @Inject public CellZonesPanel(Model model, Set cellZoneTypes, Set modules) { super(CELL_ZONES, model); @@ -95,17 +92,6 @@ public class CellZonesPanel extends AbstractGUIPanel { private StringField initNameField() { final StringField zoneNameField = stringField(); -// zoneNameListener = new PropertyChangeListener() { -// @Override -// public void propertyChange(PropertyChangeEvent evt) { -// CellZone[] cellzones = treeNodeManager.getSelectedValues(); -// if (cellzones.length == 1 && cellzones[0] != null) { -// cellzones[0].setName(zoneNameField.getText()); -// treeNodeManager.refreshNode(cellzones[0]); -// } -// } -// }; -// zoneNameField.addPropertyChangeListener(zoneNameListener); zoneNameField.setEnabled(false); return zoneNameField; } @@ -138,7 +124,7 @@ public class CellZonesPanel extends AbstractGUIPanel { if (!cellZone.hasDictionary(typeKey)) { cellZone.setDictionary(typeKey, type.getDefaultDictionary()); } - centerPanel.showPanel(type, cellZone.getDictionary(typeKey)); + centerPanel.showPanel(cellZone.getName(), type, cellZone.getDictionary(typeKey)); } private void hidePanel(CellZoneType type, CellZone cellZone) { @@ -151,7 +137,6 @@ public class CellZonesPanel extends AbstractGUIPanel { } public void updateSelection(CellZone[] selection) { -// zoneNameField.removePropertyChangeListener(zoneNameListener); if (Util.isVarArgsNotNullAndOfSize(1, selection)) { zoneNameField.setValue(selection[0].getName()); zoneNameField.setEnabled(false); @@ -167,7 +152,6 @@ public class CellZonesPanel extends AbstractGUIPanel { zoneTypePanel.handleSelectionOnTree(null); centerPanel.handleSelectionOnTree(null); } -// zoneNameField.addPropertyChangeListener(zoneNameListener); } @Override diff --git a/src/eu/engys/gui/casesetup/cellzones/CellZonesTreeNodeManager.java b/src/eu/engys/gui/casesetup/cellzones/CellZonesTreeNodeManager.java index 195a9b4..f543971 100644 --- a/src/eu/engys/gui/casesetup/cellzones/CellZonesTreeNodeManager.java +++ b/src/eu/engys/gui/casesetup/cellzones/CellZonesTreeNodeManager.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.casesetup.cellzones; import java.awt.Component; @@ -48,6 +47,7 @@ import eu.engys.gui.view3D.Actor; import eu.engys.gui.view3D.Picker; import eu.engys.util.ui.ExecUtil; import eu.engys.util.ui.TreeUtil; +import eu.engys.util.ui.checkboxtree.RootVisibleLoadableTreeNode; import eu.engys.util.ui.checkboxtree.VisibleItem; public class CellZonesTreeNodeManager extends DefaultTreeNodeManager { @@ -57,6 +57,7 @@ public class CellZonesTreeNodeManager extends DefaultTreeNodeManager { public CellZonesTreeNodeManager(Model model, CellZonesPanel cellZonesPanel) { super(model, cellZonesPanel); + this.root = new RootVisibleLoadableTreeNode(cellZonesPanel.getTitle()); this.selectionHandler = new CellZonesSelectionHandler(cellZonesPanel); this.zonesMap = new HashMap<>(); } @@ -227,44 +228,4 @@ public class CellZonesTreeNodeManager extends DefaultTreeNodeManager { currentSelection = null; } } - - // private final class PopUpMenuListener extends MouseAdapter { - // private JPopupMenu popUp; - // private RemoveSurfaceAction removeAction; - // - // public PopUpMenuListener() { - // // removeAction = new RemoveSurfaceAction(); - // - // popUp = new JPopupMenu(); - // // popUp.add(removeAction); - // } - // - // @Override - // public void mouseReleased(MouseEvent e) { - // // Surface[] selectedValues = treeNodeManager.getSelectedValues(); - // // if (SwingUtilities.isRightMouseButton(e) && selectedValues.length - // // > 0) { - // // removeAction.setEnabled(selectedValues[0].getType() != - // // Type.REGION); - // // popUp.show(treeNodeManager, e.getX(), e.getY()); - // // } - // } - // } - - // private final class VisibilityListener implements TableModelListener { - // @Override - // public void tableChanged(TableModelEvent e) { - // if (e.getType() == TableModelEvent.UPDATE && e.getColumn() == 0) { - // if (e.getSource() instanceof AbstractTableModel) { - // AbstractTableModel tm = (AbstractTableModel) e.getSource(); - // int row = e.getFirstRow(); - // boolean b = Boolean.parseBoolean(tm.getValueAt(row, - // GeometryTreePanel.VISIBLE_INDEX).toString()); - // Surface surface = (Surface) tm.getValueAt(row, - // GeometryTreePanel.SURFACE_INDEX); - // EventManager.triggerEvent(this, new VisibleSurfaceEvent(surface, b)); - // } - // } - // } - // } } diff --git a/src/eu/engys/gui/casesetup/cellzones/SourcePanelContainer.java b/src/eu/engys/gui/casesetup/cellzones/SourcePanelContainer.java index 8cbb55c..ef690f0 100644 --- a/src/eu/engys/gui/casesetup/cellzones/SourcePanelContainer.java +++ b/src/eu/engys/gui/casesetup/cellzones/SourcePanelContainer.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.casesetup.cellzones; import java.awt.BorderLayout; @@ -71,7 +70,7 @@ public class SourcePanelContainer extends JPanel { if (cellZone != null) { for (CellZoneType type : types) { if (cellZone.hasType(type.getKey()) && type.isEnabled()) { - showPanel(type, cellZone.getDictionary(type.getKey())); + showPanel(cellZone.getName(), type, cellZone.getDictionary(type.getKey())); } else { hidePanel(type); } @@ -81,8 +80,8 @@ public class SourcePanelContainer extends JPanel { } } - public void showPanel(CellZoneType type, Dictionary cellZoneDictionary) { - type.getPanel().loadFromDictionary(cellZoneDictionary); + public void showPanel(String cellZoneName, CellZoneType type, Dictionary cellZoneDictionary) { + type.getPanel().loadFromDictionary(cellZoneName, cellZoneDictionary); builder.setShowing(type.getKey(), type.getLabel()); } @@ -101,8 +100,10 @@ public class SourcePanelContainer extends JPanel { String typeKey = type.getKey(); if (type.isEnabled()) { if (zone.getTypes().contains(typeKey)) { - Dictionary dict = type.getPanel().saveToDictionary(); - zone.setDictionary(typeKey, dict); + Dictionary dict = type.getPanel().saveToDictionary(zone.getName()); + if(dict != null){ + zone.setDictionary(typeKey, dict); + } } else { zone.removeDictionary(typeKey); } diff --git a/src/eu/engys/gui/casesetup/cellzones/SourceTypeSelectionPanel.java b/src/eu/engys/gui/casesetup/cellzones/SourceTypeSelectionPanel.java index dc01682..aee7a6d 100644 --- a/src/eu/engys/gui/casesetup/cellzones/SourceTypeSelectionPanel.java +++ b/src/eu/engys/gui/casesetup/cellzones/SourceTypeSelectionPanel.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.casesetup.cellzones; import java.awt.BorderLayout; diff --git a/src/eu/engys/gui/casesetup/cellzones/StandardCellZonesBuilder.java b/src/eu/engys/gui/casesetup/cellzones/StandardCellZonesBuilder.java index dfb7017..b6ceb04 100644 --- a/src/eu/engys/gui/casesetup/cellzones/StandardCellZonesBuilder.java +++ b/src/eu/engys/gui/casesetup/cellzones/StandardCellZonesBuilder.java @@ -1,33 +1,32 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.casesetup.cellzones; import static eu.engys.core.dictionary.Dictionary.TYPE; import static eu.engys.core.project.system.SnappyHexMeshDict.CELL_ZONE_KEY; -import static eu.engys.core.project.zero.cellzones.CellZonesUtils.ABSOLUTE_KEY; +import static eu.engys.core.project.zero.cellzones.CellZoneType.THERMAL_KEY; import static eu.engys.core.project.zero.cellzones.CellZonesUtils.ACTIVE_KEY; import static eu.engys.core.project.zero.cellzones.CellZonesUtils.AXES_ROTATION_KEY; import static eu.engys.core.project.zero.cellzones.CellZonesUtils.AXIS_KEY; @@ -42,19 +41,20 @@ import static eu.engys.core.project.zero.cellzones.CellZonesUtils.D_KEY; import static eu.engys.core.project.zero.cellzones.CellZonesUtils.E1_KEY; import static eu.engys.core.project.zero.cellzones.CellZonesUtils.E2_KEY; import static eu.engys.core.project.zero.cellzones.CellZonesUtils.EXPLICIT_POROSITY_SOURCE_KEY; +import static eu.engys.core.project.zero.cellzones.CellZonesUtils.FIELD_VALUES_KEY; import static eu.engys.core.project.zero.cellzones.CellZonesUtils.F_KEY; import static eu.engys.core.project.zero.cellzones.CellZonesUtils.INJECTION_RATE_KEY; -import static eu.engys.core.project.zero.cellzones.CellZonesUtils.MRF_SOURCE_KEY; +import static eu.engys.core.project.zero.cellzones.CellZonesUtils.NON_ROTATING_PATCHES_KEY; import static eu.engys.core.project.zero.cellzones.CellZonesUtils.OMEGA_KEY; import static eu.engys.core.project.zero.cellzones.CellZonesUtils.ORIGIN_KEY; import static eu.engys.core.project.zero.cellzones.CellZonesUtils.POROUS_DARCY_KEY; import static eu.engys.core.project.zero.cellzones.CellZonesUtils.POROUS_POWER_LAW_KEY; import static eu.engys.core.project.zero.cellzones.CellZonesUtils.POWER_LAW_KEY; import static eu.engys.core.project.zero.cellzones.CellZonesUtils.SCALAR_EXPLICIT_SET_VALUE_KEY; +import static eu.engys.core.project.zero.cellzones.CellZonesUtils.SCALAR_FIXED_VALUE_CONSTRAINT_KEY; import static eu.engys.core.project.zero.cellzones.CellZonesUtils.SELECTION_MODE_KEY; import static eu.engys.core.project.zero.cellzones.CellZonesUtils.THERMAL_FIXED_KEY; import static eu.engys.core.project.zero.cellzones.CellZonesUtils.T_KEY; -import static eu.engys.core.project.zero.cellzones.CellZonesUtils.VOLUME_MODE_KEY; import java.util.List; @@ -63,12 +63,14 @@ import org.slf4j.LoggerFactory; import eu.engys.core.dictionary.Dictionary; import eu.engys.core.project.Model; +import eu.engys.core.project.constant.MRFProperties; import eu.engys.core.project.state.State; import eu.engys.core.project.system.FvOptions; import eu.engys.core.project.zero.cellzones.CellZone; import eu.engys.core.project.zero.cellzones.CellZoneType; import eu.engys.core.project.zero.cellzones.CellZones; import eu.engys.core.project.zero.cellzones.CellZonesBuilder; +import eu.engys.util.PrefUtil; public class StandardCellZonesBuilder implements CellZonesBuilder { @@ -76,30 +78,26 @@ public class StandardCellZonesBuilder implements CellZonesBuilder { @Override public void loadMRFDictionary(Model model) { - loadMRFDictionary(model.getCellZones(), model.getProject().getSystemFolder().getFvOptions()); + loadMRFDictionary(model.getCellZones(), model.getProject().getSystemFolder().getFvOptions(), model.getProject().getConstantFolder().getMrfProperties()); } @Override - public void loadMRFDictionary(CellZones cellZones, FvOptions fvOptions) { - if (fvOptions != null) { + public void loadMRFDictionary(CellZones cellZones, FvOptions fvOptions, MRFProperties mrfProperties) { + if (mrfProperties != null) { for (CellZone cellZone : cellZones) { String zoneName = cellZone.getName(); - List zonesDict = fvOptions.getDictionaries(); + List zonesDict = mrfProperties.getDictionaries(); for (Dictionary zoneDict : zonesDict) { if (zoneDict.found(CELL_ZONE_KEY) && zoneDict.lookup(CELL_ZONE_KEY).equals(zoneName)) { - if (zoneDict.found(TYPE) && zoneDict.lookup(TYPE).equals(MRF_SOURCE_KEY)) { - Dictionary encodedDictionary = new Dictionary(""); - encodedDictionary.add(TYPE, CellZoneType.MRF_KEY); - if (zoneDict.isDictionary(MRF_SOURCE_KEY + COEFFS_KEY)) { - Dictionary coeffs = zoneDict.subDict(MRF_SOURCE_KEY + COEFFS_KEY); - encodedDictionary.add(ORIGIN_KEY, coeffs.lookup(ORIGIN_KEY)); - encodedDictionary.add(AXIS_KEY, coeffs.lookup(AXIS_KEY)); - encodedDictionary.add(OMEGA_KEY, coeffs.lookup(OMEGA_KEY)); - } + Dictionary encodedDictionary = new Dictionary(""); + encodedDictionary.add(TYPE, CellZoneType.MRF_KEY); + encodedDictionary.add(ORIGIN_KEY, zoneDict.lookup(ORIGIN_KEY)); + encodedDictionary.add(AXIS_KEY, zoneDict.lookup(AXIS_KEY)); + encodedDictionary.add(OMEGA_KEY, zoneDict.lookup(OMEGA_KEY)); + encodedDictionary.add(NON_ROTATING_PATCHES_KEY, zoneDict.isField(NON_ROTATING_PATCHES_KEY) ? zoneDict.lookup(NON_ROTATING_PATCHES_KEY) : "()"); - cellZone.setDictionary(CellZoneType.MRF_KEY, encodedDictionary); - cellZone.getTypes().add(CellZoneType.MRF_KEY); - } + cellZone.setDictionary(CellZoneType.MRF_KEY, encodedDictionary); + cellZone.getTypes().add(CellZoneType.MRF_KEY); } } } @@ -108,12 +106,12 @@ public class StandardCellZonesBuilder implements CellZonesBuilder { @Override public void saveMRFDictionary(Model model) { - saveMRFDictionary(model.getCellZones(), model.getProject().getSystemFolder().getFvOptions()); + saveMRFDictionary(model.getCellZones(), model.getProject().getSystemFolder().getFvOptions(), model.getProject().getConstantFolder().getMrfProperties()); } @Override - public void saveMRFDictionary(CellZones cellZones, FvOptions fvOptions) { - if (fvOptions != null) { + public void saveMRFDictionary(CellZones cellZones, FvOptions fvOptions, MRFProperties mrfProperties) { + if (mrfProperties != null) { for (CellZone cellZone : cellZones) { String zoneName = cellZone.getName(); @@ -121,19 +119,14 @@ public class StandardCellZonesBuilder implements CellZonesBuilder { Dictionary encodedDictionary = cellZone.getDictionary(CellZoneType.MRF_KEY); Dictionary toBeDecoded = new Dictionary(zoneName + "_" + CellZoneType.MRF_KEY); - toBeDecoded.add(TYPE, MRF_SOURCE_KEY); - toBeDecoded.add(ACTIVE_KEY, "true"); - toBeDecoded.add(SELECTION_MODE_KEY, CELL_ZONE_KEY); toBeDecoded.add(CELL_ZONE_KEY, zoneName); + toBeDecoded.add(ACTIVE_KEY, true); + toBeDecoded.add(NON_ROTATING_PATCHES_KEY, encodedDictionary.lookup(NON_ROTATING_PATCHES_KEY)); + toBeDecoded.add(ORIGIN_KEY, encodedDictionary.lookup(ORIGIN_KEY)); + toBeDecoded.add(AXIS_KEY, encodedDictionary.lookup(AXIS_KEY)); + toBeDecoded.add(OMEGA_KEY, encodedDictionary.lookup(OMEGA_KEY)); - Dictionary MRFSourceCoeffs = new Dictionary(MRF_SOURCE_KEY + COEFFS_KEY); - MRFSourceCoeffs.add(ORIGIN_KEY, encodedDictionary.lookup(ORIGIN_KEY)); - MRFSourceCoeffs.add(AXIS_KEY, encodedDictionary.lookup(AXIS_KEY)); - MRFSourceCoeffs.add(OMEGA_KEY, encodedDictionary.lookup(OMEGA_KEY)); - - toBeDecoded.add(MRFSourceCoeffs); - - fvOptions.add(toBeDecoded); + mrfProperties.add(toBeDecoded); } else { logger.debug(zoneName + " NOT A MRF Zone " + cellZone.getTypes()); } @@ -153,13 +146,13 @@ public class StandardCellZonesBuilder implements CellZonesBuilder { String zoneName = cellZone.getName(); List zonesDict = fvOptions.getDictionaries(); for (Dictionary zoneDict : zonesDict) { - if (zoneDict.found(CELL_ZONE_KEY) && zoneDict.lookup(CELL_ZONE_KEY).equals(zoneName)) { - if (zoneDict.lookup(TYPE).equals(EXPLICIT_POROSITY_SOURCE_KEY)) { - Dictionary encodedDictionary = new Dictionary(""); - if (zoneDict.isDictionary(EXPLICIT_POROSITY_SOURCE_KEY + COEFFS_KEY)) { - Dictionary coeffDict = zoneDict.subDict(EXPLICIT_POROSITY_SOURCE_KEY + COEFFS_KEY); + if (zoneDict.lookup(TYPE).equals(EXPLICIT_POROSITY_SOURCE_KEY)) { + if (zoneDict.isDictionary(EXPLICIT_POROSITY_SOURCE_KEY + COEFFS_KEY)) { + Dictionary coeffDict = zoneDict.subDict(EXPLICIT_POROSITY_SOURCE_KEY + COEFFS_KEY); + if (coeffDict.found(CELL_ZONE_KEY) && coeffDict.lookup(CELL_ZONE_KEY).equals(zoneName)) { String type = coeffDict.lookup(TYPE); + Dictionary encodedDictionary = new Dictionary(""); if (type.equals(DARCY_FORCHHEIMER_KEY)) { encodedDictionary.add(TYPE, POROUS_DARCY_KEY); @@ -182,10 +175,9 @@ public class StandardCellZonesBuilder implements CellZonesBuilder { } else { System.err.println("Unknown type"); } + cellZone.getTypes().add(CellZoneType.POROUS_KEY); + cellZone.setDictionary(CellZoneType.POROUS_KEY, encodedDictionary); } - - cellZone.getTypes().add(CellZoneType.POROUS_KEY); - cellZone.setDictionary(CellZoneType.POROUS_KEY, encodedDictionary); } } } @@ -209,13 +201,14 @@ public class StandardCellZonesBuilder implements CellZonesBuilder { Dictionary toBeDecoded = new Dictionary(zoneName + "_" + CellZoneType.POROUS_KEY); toBeDecoded.add(TYPE, EXPLICIT_POROSITY_SOURCE_KEY); - toBeDecoded.add(ACTIVE_KEY, "true"); - toBeDecoded.add(SELECTION_MODE_KEY, CELL_ZONE_KEY); - toBeDecoded.add(CELL_ZONE_KEY, zoneName); + toBeDecoded.add(ACTIVE_KEY, true); Dictionary porousCoeffs = new Dictionary(EXPLICIT_POROSITY_SOURCE_KEY + COEFFS_KEY); toBeDecoded.add(porousCoeffs); + porousCoeffs.add(SELECTION_MODE_KEY, CELL_ZONE_KEY); + porousCoeffs.add(CELL_ZONE_KEY, zoneName); + if (typeString != null && typeString.equals(POROUS_DARCY_KEY)) { porousCoeffs.add(TYPE, DARCY_FORCHHEIMER_KEY); @@ -264,31 +257,45 @@ public class StandardCellZonesBuilder implements CellZonesBuilder { public void loadThermalDictionary(CellZones cellZones, FvOptions fvOptions, State state) { if (fvOptions != null) { for (CellZone cellZone : cellZones) { - String zoneName = cellZone.getName(); List zonesDict = fvOptions.getDictionaries(); for (Dictionary zoneDict : zonesDict) { - if (zoneDict.found(CELL_ZONE_KEY) && zoneDict.lookup(CELL_ZONE_KEY).equals(zoneName)) { - String type = zoneDict.lookup(TYPE); - if (type != null && (type.equals(SCALAR_EXPLICIT_SET_VALUE_KEY))) { - Dictionary encodedDictionary = new Dictionary(""); - if (type.equals(SCALAR_EXPLICIT_SET_VALUE_KEY)) { - if (zoneDict.isDictionary(SCALAR_EXPLICIT_SET_VALUE_KEY + COEFFS_KEY)) { - Dictionary coeffDict = zoneDict.subDict(SCALAR_EXPLICIT_SET_VALUE_KEY + COEFFS_KEY); - Dictionary injectionDict = coeffDict.subDict(INJECTION_RATE_KEY); - - encodedDictionary.add(TYPE, THERMAL_FIXED_KEY); - encodedDictionary.add(T_KEY, injectionDict.lookup(T_KEY)); - } - } - cellZone.getTypes().add(CellZoneType.THERMAL_KEY); - cellZone.setDictionary(CellZoneType.THERMAL_KEY, encodedDictionary); - } + String type = zoneDict.lookup(TYPE); + if (type != null && (type.equals(SCALAR_FIXED_VALUE_CONSTRAINT_KEY))) { + loadThermal_OF4_STYLE(type, cellZone, zoneDict); + } else if (type != null && (type.equals(SCALAR_EXPLICIT_SET_VALUE_KEY))) { + loadThermal_OF3_STYLE(type, cellZone, zoneDict); } } } } } + private void loadThermal_OF4_STYLE(String type, CellZone cellZone, Dictionary zoneDict) { + if (zoneDict.isDictionary(SCALAR_FIXED_VALUE_CONSTRAINT_KEY + COEFFS_KEY) && zoneDict.subDict(SCALAR_FIXED_VALUE_CONSTRAINT_KEY + COEFFS_KEY).lookup(CELL_ZONE_KEY).equals(cellZone.getName())) { + Dictionary coeffDict = zoneDict.subDict(SCALAR_FIXED_VALUE_CONSTRAINT_KEY + COEFFS_KEY); + Dictionary valuesDict = coeffDict.subDict(FIELD_VALUES_KEY); + + Dictionary encodedDictionary = new Dictionary(""); + encodedDictionary.add(TYPE, THERMAL_FIXED_KEY); + encodedDictionary.add(T_KEY, valuesDict.lookupDouble(T_KEY)); + cellZone.getTypes().add(THERMAL_KEY); + cellZone.setDictionary(THERMAL_KEY, encodedDictionary); + } + } + + private void loadThermal_OF3_STYLE(String type, CellZone cellZone, Dictionary zoneDict) { + if (zoneDict.isDictionary(SCALAR_EXPLICIT_SET_VALUE_KEY + COEFFS_KEY) && zoneDict.subDict(SCALAR_EXPLICIT_SET_VALUE_KEY + COEFFS_KEY).lookup(CELL_ZONE_KEY).equals(cellZone.getName())) { + Dictionary encodedDictionary = new Dictionary(""); + Dictionary coeffDict = zoneDict.subDict(SCALAR_EXPLICIT_SET_VALUE_KEY + COEFFS_KEY); + Dictionary injectionDict = coeffDict.subDict(INJECTION_RATE_KEY); + + encodedDictionary.add(TYPE, THERMAL_FIXED_KEY); + encodedDictionary.add(T_KEY, injectionDict.lookup(T_KEY)); + cellZone.getTypes().add(CellZoneType.THERMAL_KEY); + cellZone.setDictionary(CellZoneType.THERMAL_KEY, encodedDictionary); + } + } + @Override public void saveThermalDictionary(Model model) { saveThermalDictionary(model.getCellZones(), model.getProject().getSystemFolder().getFvOptions(), model.getState()); @@ -299,25 +306,9 @@ public class StandardCellZonesBuilder implements CellZonesBuilder { if (fvOptions != null) { for (CellZone cellZone : cellZones) { String zoneName = cellZone.getName(); - if (cellZone.hasType(CellZoneType.THERMAL_KEY)) { - Dictionary encodedDictionary = cellZone.getDictionary(CellZoneType.THERMAL_KEY); - - Dictionary toBeDecoded = new Dictionary(zoneName + "_" + CellZoneType.THERMAL_KEY); - toBeDecoded.add(TYPE, SCALAR_EXPLICIT_SET_VALUE_KEY); - toBeDecoded.add(ACTIVE_KEY, "true"); - toBeDecoded.add(SELECTION_MODE_KEY, CELL_ZONE_KEY); - toBeDecoded.add(CELL_ZONE_KEY, zoneName); - - Dictionary coeffsDict = new Dictionary(SCALAR_EXPLICIT_SET_VALUE_KEY + COEFFS_KEY); - coeffsDict.add(VOLUME_MODE_KEY, ABSOLUTE_KEY); - - Dictionary injectionDict = new Dictionary(INJECTION_RATE_KEY); - injectionDict.add(T_KEY, encodedDictionary.lookup(T_KEY)); - coeffsDict.add(injectionDict); - - toBeDecoded.add(coeffsDict); - - fvOptions.add(toBeDecoded); + if (cellZone.hasType(THERMAL_KEY)) { + Dictionary dict = PrefUtil.isUsingDocker() ? saveThermal_OF3_STYLE(cellZone) : saveThermal_OF4_STYLE(cellZone); + fvOptions.add(dict); } else { logger.debug(zoneName + " NOT A Thermal Zone " + cellZone.getTypes()); } @@ -325,4 +316,60 @@ public class StandardCellZonesBuilder implements CellZonesBuilder { } } + private Dictionary saveThermal_OF4_STYLE(CellZone cellZone) { + Dictionary encodedDictionary = cellZone.getDictionary(CellZoneType.THERMAL_KEY); + + Dictionary toBeDecoded = new Dictionary(cellZone.getName() + "_" + CellZoneType.THERMAL_KEY); + toBeDecoded.add(TYPE, SCALAR_FIXED_VALUE_CONSTRAINT_KEY); + toBeDecoded.add(ACTIVE_KEY, true); + + Dictionary coeffsDict = new Dictionary(SCALAR_FIXED_VALUE_CONSTRAINT_KEY + COEFFS_KEY); + coeffsDict.add(SELECTION_MODE_KEY, CELL_ZONE_KEY); + coeffsDict.add(CELL_ZONE_KEY, cellZone.getName()); + + Dictionary fieldValuesDict = new Dictionary(FIELD_VALUES_KEY); + fieldValuesDict.add(T_KEY, encodedDictionary.lookup(T_KEY)); + coeffsDict.add(fieldValuesDict); + + toBeDecoded.add(coeffsDict); + + return toBeDecoded; + } + + private Dictionary saveThermal_OF3_STYLE(CellZone cellZone) { + Dictionary encodedDictionary = cellZone.getDictionary(CellZoneType.THERMAL_KEY); + + Dictionary toBeDecoded = new Dictionary(cellZone.getName() + "_" + CellZoneType.THERMAL_KEY); + toBeDecoded.add(TYPE, SCALAR_EXPLICIT_SET_VALUE_KEY); + toBeDecoded.add(ACTIVE_KEY, true); + + Dictionary coeffsDict = new Dictionary(SCALAR_EXPLICIT_SET_VALUE_KEY + COEFFS_KEY); + coeffsDict.add(SELECTION_MODE_KEY, CELL_ZONE_KEY); + coeffsDict.add(CELL_ZONE_KEY, cellZone.getName()); + + Dictionary injectionDict = new Dictionary(INJECTION_RATE_KEY); + injectionDict.add(T_KEY, encodedDictionary.lookup(T_KEY)); + coeffsDict.add(injectionDict); + + toBeDecoded.add(coeffsDict); + + return toBeDecoded; + } + + @Override + public void loadHeatExchangerDictionary(Model model) { + } + + @Override + public void loadHeatExchangerDictionary(CellZones cellZones, FvOptions fvOptions) { + } + + @Override + public void saveHeatExchangerDictionary(Model model) { + } + + @Override + public void saveHeatExchangerDictionary(CellZones cellZones, FvOptions fvOptions) { + } + } diff --git a/src/eu/engys/gui/casesetup/cellzones/mrf/StandardCellZoneMRFPanel.java b/src/eu/engys/gui/casesetup/cellzones/mrf/StandardCellZoneMRFPanel.java index 45b2e77..b7806b0 100644 --- a/src/eu/engys/gui/casesetup/cellzones/mrf/StandardCellZoneMRFPanel.java +++ b/src/eu/engys/gui/casesetup/cellzones/mrf/StandardCellZoneMRFPanel.java @@ -1,32 +1,32 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.casesetup.cellzones.mrf; import static eu.engys.core.project.zero.cellzones.CellZonesUtils.AXIS_KEY; +import static eu.engys.core.project.zero.cellzones.CellZonesUtils.NON_ROTATING_PATCHES_KEY; import static eu.engys.core.project.zero.cellzones.CellZonesUtils.OMEGA_KEY; import static eu.engys.core.project.zero.cellzones.CellZonesUtils.ORIGIN_KEY; import static eu.engys.gui.casesetup.cellzones.CellZonesFactory.mrf; @@ -40,16 +40,19 @@ import javax.swing.JPanel; import eu.engys.core.dictionary.Dictionary; import eu.engys.core.dictionary.model.DictionaryModel; import eu.engys.core.modules.cellzones.CellZonePanel; +import eu.engys.core.project.Model; import eu.engys.core.project.zero.cellzones.CellZoneType; +import eu.engys.gui.ListBuilderFactory; import eu.engys.util.ui.builder.PanelBuilder; public class StandardCellZoneMRFPanel implements CellZonePanel { private PanelBuilder builder = new PanelBuilder(); private DictionaryModel mrfModel; + private Model model; - @Inject - public StandardCellZoneMRFPanel() { + public StandardCellZoneMRFPanel(Model model) { + this.model = model; } @Override @@ -58,8 +61,7 @@ public class StandardCellZoneMRFPanel implements CellZonePanel { builder.addComponent(ORIGIN_LABEL, mrfModel.bindPoint(ORIGIN_KEY)); builder.addComponent(AXIS_LABEL, mrfModel.bindPoint(AXIS_KEY)); builder.addComponent(OMEGA_RAD_S_LABEL, mrfModel.bindConstantDouble(OMEGA_KEY)); - mrfModel.refresh(); - + builder.addComponent(NON_ROTATING_PATCHES_INSIDE_MRF_ZONE_LABEL, mrfModel.bindList(NON_ROTATING_PATCHES_KEY, ListBuilderFactory.getPatchesListBuilder(model))); } @Override @@ -75,7 +77,7 @@ public class StandardCellZoneMRFPanel implements CellZonePanel { } @Override - public void loadFromDictionary(Dictionary cellZoneDictionary) { + public void loadFromDictionary(String cellZoneName, Dictionary cellZoneDictionary) { Dictionary d = new Dictionary(CellZoneType.MRF_KEY); d.merge(cellZoneDictionary); mrfModel.setDictionary(cellZoneDictionary); @@ -83,7 +85,7 @@ public class StandardCellZoneMRFPanel implements CellZonePanel { } @Override - public Dictionary saveToDictionary() { + public Dictionary saveToDictionary(String czName) { return mrfModel.getDictionary(); } diff --git a/src/eu/engys/gui/casesetup/cellzones/mrf/StandardMRF.java b/src/eu/engys/gui/casesetup/cellzones/mrf/StandardMRF.java index 8d30d67..909d79c 100644 --- a/src/eu/engys/gui/casesetup/cellzones/mrf/StandardMRF.java +++ b/src/eu/engys/gui/casesetup/cellzones/mrf/StandardMRF.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.casesetup.cellzones.mrf; import static eu.engys.gui.casesetup.cellzones.CellZonesFactory.mrf; @@ -42,7 +41,7 @@ public class StandardMRF implements CellZoneType { @Inject public StandardMRF(Model model) { - this.panel = new StandardCellZoneMRFPanel(); + this.panel = new StandardCellZoneMRFPanel(model); } @Override diff --git a/src/eu/engys/gui/casesetup/cellzones/porous/StandardCellZonePorousPanel.java b/src/eu/engys/gui/casesetup/cellzones/porous/StandardCellZonePorousPanel.java index be500d9..433264d 100644 --- a/src/eu/engys/gui/casesetup/cellzones/porous/StandardCellZonePorousPanel.java +++ b/src/eu/engys/gui/casesetup/cellzones/porous/StandardCellZonePorousPanel.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.casesetup.cellzones.porous; import static eu.engys.core.project.zero.cellzones.CellZonesUtils.C0_KEY; @@ -39,8 +38,6 @@ import javax.swing.BorderFactory; import javax.swing.JComponent; import javax.swing.JPanel; -import com.google.inject.Inject; - import eu.engys.core.dictionary.Dictionary; import eu.engys.core.dictionary.model.DictionaryModel; import eu.engys.core.dictionary.model.DictionaryPanelBuilder; @@ -52,10 +49,6 @@ public class StandardCellZonePorousPanel implements CellZonePanel { private DictionaryPanelBuilder builder; - @Inject - public StandardCellZonePorousPanel() { - } - @Override public void layoutPanel() { DictionaryModel porousDarcyModel = new DictionaryModel(new Dictionary(porousDarcyForchheimer)); @@ -92,14 +85,14 @@ public class StandardCellZonePorousPanel implements CellZonePanel { } @Override - public void loadFromDictionary(Dictionary cellZoneDictionary) { + public void loadFromDictionary(String cellZoneName, Dictionary cellZoneDictionary) { Dictionary d = new Dictionary(CellZoneType.POROUS_KEY); d.merge(cellZoneDictionary); builder.selectDictionary(d); } @Override - public Dictionary saveToDictionary() { + public Dictionary saveToDictionary(String czName) { return builder.getSelectedModel().getDictionary(); } } diff --git a/src/eu/engys/gui/casesetup/cellzones/porous/StandardPorous.java b/src/eu/engys/gui/casesetup/cellzones/porous/StandardPorous.java index 2b72676..58e86d9 100644 --- a/src/eu/engys/gui/casesetup/cellzones/porous/StandardPorous.java +++ b/src/eu/engys/gui/casesetup/cellzones/porous/StandardPorous.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.casesetup.cellzones.porous; import static eu.engys.gui.casesetup.cellzones.CellZonesFactory.porousDarcyForchheimer; diff --git a/src/eu/engys/gui/casesetup/cellzones/thermal/StandardCellZoneThermalPanel.java b/src/eu/engys/gui/casesetup/cellzones/thermal/StandardCellZoneThermalPanel.java index 3e490c9..63179a5 100644 --- a/src/eu/engys/gui/casesetup/cellzones/thermal/StandardCellZoneThermalPanel.java +++ b/src/eu/engys/gui/casesetup/cellzones/thermal/StandardCellZoneThermalPanel.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.casesetup.cellzones.thermal; import static eu.engys.core.project.zero.cellzones.CellZonesUtils.T_KEY; @@ -33,23 +32,16 @@ import javax.swing.BorderFactory; import javax.swing.JComponent; import javax.swing.JPanel; -import com.google.inject.Inject; - import eu.engys.core.dictionary.Dictionary; import eu.engys.core.dictionary.model.DictionaryModel; import eu.engys.core.dictionary.model.DictionaryPanelBuilder; import eu.engys.core.modules.cellzones.CellZonePanel; -import eu.engys.core.project.Model; import eu.engys.core.project.zero.cellzones.CellZoneType; public class StandardCellZoneThermalPanel implements CellZonePanel { private DictionaryPanelBuilder builder; - @Inject - public StandardCellZoneThermalPanel(Model model) { - } - @Override public void layoutPanel() { DictionaryModel fixedModel = new DictionaryModel(new Dictionary(thermalFixedTemperature_OS)); @@ -78,14 +70,14 @@ public class StandardCellZoneThermalPanel implements CellZonePanel { } @Override - public void loadFromDictionary(Dictionary cellZoneDictionary) { + public void loadFromDictionary(String cellZoneName, Dictionary cellZoneDictionary) { Dictionary d = new Dictionary(CellZoneType.THERMAL_KEY); d.merge(cellZoneDictionary); builder.selectDictionary(d); } @Override - public Dictionary saveToDictionary() { + public Dictionary saveToDictionary(String czName) { return builder.getSelectedModel().getDictionary(); } diff --git a/src/eu/engys/gui/casesetup/cellzones/thermal/StandardThermal.java b/src/eu/engys/gui/casesetup/cellzones/thermal/StandardThermal.java index 8e67353..bbf050a 100644 --- a/src/eu/engys/gui/casesetup/cellzones/thermal/StandardThermal.java +++ b/src/eu/engys/gui/casesetup/cellzones/thermal/StandardThermal.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.casesetup.cellzones.thermal; import static eu.engys.gui.casesetup.cellzones.CellZonesFactory.thermalFixedTemperature_OS; @@ -46,7 +45,7 @@ public class StandardThermal implements CellZoneType { @Inject public StandardThermal(Model model) { this.model = model; - this.panel = new StandardCellZoneThermalPanel(model); + this.panel = new StandardCellZoneThermalPanel(); this.enabled = false; } diff --git a/src/eu/engys/gui/casesetup/facezones/FaceZonesPanel.java b/src/eu/engys/gui/casesetup/facezones/FaceZonesPanel.java new file mode 100644 index 0000000..9372b48 --- /dev/null +++ b/src/eu/engys/gui/casesetup/facezones/FaceZonesPanel.java @@ -0,0 +1,98 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.gui.casesetup.facezones; + +import static eu.engys.util.ui.ComponentsFactory.stringField; + +import javax.inject.Inject; +import javax.swing.JComponent; + +import eu.engys.core.project.Model; +import eu.engys.core.project.zero.facezones.FaceZone; +import eu.engys.gui.AbstractGUIPanel; +import eu.engys.gui.tree.TreeNodeManager; +import eu.engys.util.Util; +import eu.engys.util.ui.builder.PanelBuilder; +import eu.engys.util.ui.textfields.StringField; + +public class FaceZonesPanel extends AbstractGUIPanel { + + public static final String FACE_ZONES = "Face Zones"; + public static final String FACE_ZONE_NAME_LABEL = "Face Zone Name"; + public static final String FACE_ZONE_TYPE_LABEL = "Face Zone Type"; + + private FaceZonesTreeNodeManager treeNodeManager; + + private StringField zoneNameField; + + @Inject + public FaceZonesPanel(Model model) { + super(FACE_ZONES, model); + this.treeNodeManager = new FaceZonesTreeNodeManager(model, this); + model.addObserver(treeNodeManager); + } + + protected JComponent layoutComponents() { + PanelBuilder panelBuilder = new PanelBuilder(); + panelBuilder.addComponent(FACE_ZONE_NAME_LABEL, zoneNameField = initNameField()); + return panelBuilder.removeMargins().getPanel(); + } + + private StringField initNameField() { + final StringField zoneNameField = stringField(); + zoneNameField.setEnabled(false); + return zoneNameField; + } + + public void updateSelection(FaceZone[] selection) { + if (Util.isVarArgsNotNullAndOfSize(1, selection)) { + zoneNameField.setValue(selection[0].getName()); + zoneNameField.setEnabled(false); + } else { + StringBuilder sb = new StringBuilder(); + for (FaceZone cellZone : selection) { + sb.append(cellZone.getName() + " "); + } + zoneNameField.setValue(sb.toString()); + zoneNameField.setEnabled(false); + } + } + + @Override + public void clear() { + treeNodeManager.getSelectionHandler().handleSelection(false, (Object[]) new FaceZone[0]); + } + + @Override + public void save() { + treeNodeManager.getSelectionHandler().handleSelection(false, (Object[]) treeNodeManager.getSelectedValues()); + } + + @Override + public TreeNodeManager getTreeNodeManager() { + return treeNodeManager; + } + +} diff --git a/src/eu/engys/gui/casesetup/facezones/FaceZonesTreeNodeManager.java b/src/eu/engys/gui/casesetup/facezones/FaceZonesTreeNodeManager.java new file mode 100644 index 0000000..5e75c07 --- /dev/null +++ b/src/eu/engys/gui/casesetup/facezones/FaceZonesTreeNodeManager.java @@ -0,0 +1,212 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.gui.casesetup.facezones; + +import java.awt.Component; +import java.util.Arrays; +import java.util.HashMap; +import java.util.Map; +import java.util.Observable; + +import javax.swing.JTree; +import javax.swing.tree.DefaultMutableTreeNode; +import javax.swing.tree.DefaultTreeCellRenderer; +import javax.swing.tree.TreePath; + +import eu.engys.core.project.Model; +import eu.engys.core.project.zero.facezones.FaceZone; +import eu.engys.core.project.zero.facezones.FaceZones; +import eu.engys.gui.events.EventManager; +import eu.engys.gui.events.view3D.SelectFaceZonesEvent; +import eu.engys.gui.tree.AbstractSelectionHandler; +import eu.engys.gui.tree.DefaultTreeNodeManager; +import eu.engys.gui.tree.SelectionHandler; +import eu.engys.gui.view3D.Actor; +import eu.engys.gui.view3D.Picker; +import eu.engys.util.ui.ExecUtil; +import eu.engys.util.ui.TreeUtil; +import eu.engys.util.ui.checkboxtree.VisibleItem; + +public class FaceZonesTreeNodeManager extends DefaultTreeNodeManager { + + private Map zonesMap; + private SelectionHandler selectionHandler; + + public FaceZonesTreeNodeManager(Model model, FaceZonesPanel cellZonesPanel) { + super(model, cellZonesPanel); + this.selectionHandler = new FaceZonesSelectionHandler(cellZonesPanel); + this.zonesMap = new HashMap<>(); + } + + @Override + public void update(Observable o, final Object arg) { + if (arg instanceof FaceZones) { + ExecUtil.invokeLater(new Runnable() { + @Override + public void run() { + selectionHandler.disable(); + loadTree(); + selectVisibleItems(); + expandTree(); + selectionHandler.enable(); + } + }); + } + } + + private void loadTree() { + clear(); + for (FaceZone zone : model.getFaceZones()) { + addFaceZone(root, zone); + } + treeChanged(root); + } + + private void selectVisibleItems() { + // for(DefaultMutableTreeNode node : nodeMap.values()) + // getTree().getCheckManager().selectNode(node); + } + + private void expandTree() { + getTree().expandNode(getRoot()); + } + + private void addFaceZone(DefaultMutableTreeNode parent, FaceZone cellZone) { + DefaultMutableTreeNode node = new DefaultMutableTreeNode(cellZone); + parent.add(node); + nodeMap.put(cellZone, node); + zonesMap.put(node, cellZone); + } + + public FaceZone[] getSelectedValues() { + if (getTree() != null) { + TreePath[] selectionPaths = getTree().getSelectedDescendantOf(getRoot()); + FaceZone[] cellzones = new FaceZone[selectionPaths.length]; + for (int i = 0; i < selectionPaths.length; i++) { + DefaultMutableTreeNode node = (DefaultMutableTreeNode) selectionPaths[i].getLastPathComponent(); + FaceZone zone = zonesMap.get(node); + cellzones[i] = zone; + } + return cellzones; + } + return new FaceZone[0]; + } + + public void clear() { + // clear node before selection handler! + clearNode(root); + selectionHandler.clear(); + nodeMap.clear(); + zonesMap.clear(); + } + + public DefaultMutableTreeNode getRoot() { + return root; + } + + @Override + public Class getRendererClass() { + return FaceZone.class; + } + + public DefaultTreeCellRenderer getRenderer() { + return new DefaultTreeCellRenderer() { + @Override + public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) { + super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus); + DefaultMutableTreeNode node = (DefaultMutableTreeNode) value; + Object userObject = node.getUserObject(); + + if (userObject instanceof FaceZone) { + FaceZone patch = (FaceZone) userObject; + setText(patch.getName()); + } + setIcon(null); + return this; + } + }; + } + + @Override + public SelectionHandler getSelectionHandler() { + return selectionHandler; + } + + private final class FaceZonesSelectionHandler extends AbstractSelectionHandler { + + private FaceZonesPanel panel; + private FaceZone[] currentSelection; + + public FaceZonesSelectionHandler(FaceZonesPanel panel) { + this.panel = panel; + } + + @Override + public void handleSelection(boolean fire3DEvent, Object... selection) { + if (TreeUtil.isConsistent(selection, FaceZone.class)) { + this.currentSelection = Arrays.copyOf(selection, selection.length, FaceZone[].class); + } else { + this.currentSelection = new FaceZone[0]; + } + panel.updateSelection(currentSelection); + if (fire3DEvent) { + EventManager.triggerEvent(this, new SelectFaceZonesEvent(currentSelection)); + } + } + + @Override + public void handleVisibility(VisibleItem item) { + } + + @Override + public void process3DSelectionEvent(Picker picker, Actor actor, boolean keep) { + if (getTree() != null && actor.getVisibleItem() instanceof VisibleItem) { + DefaultMutableTreeNode selectedNode = nodeMap.get(actor.getVisibleItem()); + if (selectedNode != null) { + getTree().setSelectedNode(selectedNode); + } + } + } + + @Override + public void process3DVisibilityEvent(boolean selected) { + if (getTree() != null) { + for (DefaultMutableTreeNode node : nodeMap.values()) { + // if (selected) { + // getTree().getCheckManager().selectNode(node); + // } else { + getTree().getCheckManager().deselectNode(node); + // } + } + } + } + + @Override + public void clear() { + currentSelection = null; + } + } + +} diff --git a/src/eu/engys/gui/casesetup/fields/AbstractFieldsInitialisationPanel.java b/src/eu/engys/gui/casesetup/fields/AbstractFieldsInitialisationPanel.java index 26e8a66..52eaebf 100644 --- a/src/eu/engys/gui/casesetup/fields/AbstractFieldsInitialisationPanel.java +++ b/src/eu/engys/gui/casesetup/fields/AbstractFieldsInitialisationPanel.java @@ -1,32 +1,30 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.casesetup.fields; -import static eu.engys.core.dictionary.Dictionary.TYPE; -import static eu.engys.core.dictionary.Dictionary.VALUE; +import static eu.engys.core.controller.AbstractController.INITIALISE_SCRIPT; import static eu.engys.core.project.zero.fields.Fields.ALPHA_1; import static eu.engys.core.project.zero.fields.Fields.AOA; import static eu.engys.core.project.zero.fields.Fields.CO2; @@ -44,20 +42,23 @@ import static eu.engys.core.project.zero.fields.Fields.W; import static eu.engys.core.project.zero.fields.Initialisations.CELL_SET_KEY; import static eu.engys.core.project.zero.fields.Initialisations.DEFAULT_KEY; import static eu.engys.core.project.zero.fields.Initialisations.FIXED_VALUE_KEY; +import static eu.engys.core.project.zero.fields.Initialisations.POTENTIAL_FLOW_KEY; import static eu.engys.util.Symbols.EPSILON_SYMBOL; import static eu.engys.util.Symbols.K_SYMBOL; import static eu.engys.util.Symbols.M2_S; import static eu.engys.util.Symbols.M2_S2; import static eu.engys.util.Symbols.MU_MEASURE; import static eu.engys.util.Symbols.M_S; -import static eu.engys.util.Symbols.OMEGA_SYMBOL; +import static eu.engys.util.Symbols.OMEGA_SYMBOL_S; import static eu.engys.util.Symbols.PASCAL; import java.awt.event.ActionEvent; -import java.awt.event.ComponentAdapter; -import java.awt.event.ComponentEvent; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; +import java.util.Arrays; import java.util.HashMap; import java.util.Map; +import java.util.Set; import javax.swing.AbstractAction; import javax.swing.Action; @@ -68,156 +69,212 @@ import javax.swing.JComponent; import javax.swing.JPanel; import javax.swing.JScrollPane; -import eu.engys.core.dictionary.Dictionary; -import eu.engys.core.dictionary.DictionaryBuilder; -import eu.engys.core.dictionary.model.DictionaryModel; -import eu.engys.core.dictionary.model.DictionaryPanelBuilder; +import eu.engys.core.modules.ApplicationModule; +import eu.engys.core.modules.ModulesUtil; import eu.engys.core.presentation.ActionManager; import eu.engys.core.project.Model; +import eu.engys.core.project.geometry.surface.Box; +import eu.engys.core.project.zero.fields.CellSetInitialisation; +import eu.engys.core.project.zero.fields.CellSetInitialisation.ScalarSurface; +import eu.engys.core.project.zero.fields.CellSetInitialisation.VectorSurface; +import eu.engys.core.project.zero.fields.DefaultInitialisation; import eu.engys.core.project.zero.fields.Field; import eu.engys.core.project.zero.fields.Fields; +import eu.engys.core.project.zero.fields.FixedScalarInitialisation; +import eu.engys.core.project.zero.fields.FixedVectorInitialisation; +import eu.engys.core.project.zero.fields.Initialisation; +import eu.engys.core.project.zero.fields.ScalarCellSetInitialisation; +import eu.engys.core.project.zero.fields.VectorCellSetInitialisation; +import eu.engys.core.project.zero.patches.BoundaryConditions; import eu.engys.gui.DefaultGUIPanel; +import eu.engys.util.bean.BeanModel; +import eu.engys.util.bean.BeanPanelBuilder; +import eu.engys.util.progress.ProgressMonitor; import eu.engys.util.ui.ExecUtil; import eu.engys.util.ui.ResourcesUtil; import eu.engys.util.ui.builder.JComboBoxController; import eu.engys.util.ui.builder.PanelBuilder; public abstract class AbstractFieldsInitialisationPanel extends DefaultGUIPanel { + + protected static final Icon EDIT_ICON = ResourcesUtil.getIcon("edit.icon"); + + public static final String TYPE_LABEL = "Type"; public static final String FIELDS_INITIALISATION = "Fields Initialisation"; + public static final String FIELDS_INITIALISE_BUTTON = "fields.initialise.button"; public static final String DEFAULT_LABEL = "Default"; public static final String FIXED_VALUE_LABEL = "Fixed Value"; + public static final String POTENTIAL_FLOW_LABEL = "Potential Flow"; public static final String CELL_SET_LABEL = "CellSet"; + public static final String INITIALISE_BOUNDARIES_LABEL = "Initialise Boundaries"; public static final String EDIT_LABEL = "Edit"; private Map unityMeasures = new HashMap<>(); - protected Map fieldBuilderMap = new HashMap<>(); + protected Map fieldBuilderMap = new HashMap<>(); protected Map builders = new HashMap<>(); private PanelBuilder mainBuilder; + private InitialisationComboGroup group; - public AbstractFieldsInitialisationPanel(Model model) { + private Set modules; + protected ProgressMonitor monitor; + + + public AbstractFieldsInitialisationPanel(Model model, Set modules, ProgressMonitor monitor) { super(FIELDS_INITIALISATION, model); + this.monitor = monitor; + this.modules = modules; } @Override protected JComponent layoutComponents() { mainBuilder = new PanelBuilder(); - + JScrollPane mainScrollPane = new JScrollPane(mainBuilder.removeMargins().getPanel()); mainScrollPane.setBorder(BorderFactory.createEmptyBorder()); builders.put(DEFAULT_KEY, defaultBuilder); builders.put(FIXED_VALUE_KEY, fixedValueBuilder); + builders.put(POTENTIAL_FLOW_KEY, createPotentialFlowBuilder()); builders.put(CELL_SET_KEY, cellSetBuilder); + + group = new InitialisationComboGroup(); return mainScrollPane; } + public interface Builder { - void build(DictionaryPanelBuilder builder, Field field); + void build(BeanPanelBuilder builder, Field field); } private final Builder defaultBuilder = new Builder() { @Override - public void build(DictionaryPanelBuilder builder, Field field) { - DictionaryModel dictModel = new DictionaryModel(DictionaryBuilder.newDictionary("initialisation").field(TYPE, DEFAULT_KEY).done()) { - public String getKey() { - return DEFAULT_KEY; - } - }; - builder.startDictionary(DEFAULT_LABEL, dictModel); - builder.endGroup(); + public void build(BeanPanelBuilder builder, Field field) { + BeanModel defaultModel = new BeanModel<>(new DefaultInitialisation()); + builder.startBean(DEFAULT_LABEL, defaultModel); + builder.endBean(); } }; private final Builder fixedValueBuilder = new Builder() { + + private BeanModel fixedScalarModel; + private BeanModel fixedVectorModel; + @Override - public void build(DictionaryPanelBuilder builder, Field field) { - if (field.getFieldType().isScalar()) { - DictionaryModel dictScalarModel = new DictionaryModel(DictionaryBuilder.newDictionary("initialisation").field(TYPE, FIXED_VALUE_KEY).field(VALUE, "uniform 0").done()) { - public String getKey() { - return FIXED_VALUE_KEY; - } - }; - builder.startDictionary(FIXED_VALUE_LABEL, dictScalarModel); - builder.addComponent("Value", dictScalarModel.bindUniformDouble(VALUE)); - builder.endDictionary(); + public void build(BeanPanelBuilder builder, Field field) { + if (fixedScalarModel != null) { + fixedScalarModel.release(); + } + if (fixedVectorModel != null) { + fixedVectorModel.release(); + } + if (Fields.getFieldTypeByName(field.getName()).isScalar()) { + fixedScalarModel = new BeanModel<>(new FixedScalarInitialisation()); + builder.startBean(FIXED_VALUE_LABEL, fixedScalarModel); + builder.addComponent("Value", fixedScalarModel.bindDouble(FixedScalarInitialisation.VALUE_KEY)); + builder.endBean(); } else { - DictionaryModel dictVectorModel = new DictionaryModel(DictionaryBuilder.newDictionary("initialisation").field(TYPE, FIXED_VALUE_KEY).field(VALUE, "uniform (0 0 0)").done()) { - public String getKey() { - return FIXED_VALUE_KEY; - } - }; - builder.startDictionary(FIXED_VALUE_LABEL, dictVectorModel); - builder.addComponent("Value", dictVectorModel.bindUniformPoint(VALUE)); - builder.endDictionary(); + fixedVectorModel = new BeanModel<>(new FixedVectorInitialisation()); + builder.startBean(FIXED_VALUE_LABEL, fixedVectorModel); + builder.addComponent("Value", fixedVectorModel.bindPoint(FixedVectorInitialisation.VALUE_KEY)); + builder.endBean(); } } }; + + protected abstract Builder createPotentialFlowBuilder(); + @SuppressWarnings("deprecation") private final Builder cellSetBuilder = new Builder() { + + private BeanModel cellSetScalarModel; + private BeanModel cellSetVectorModel; + @Override - public void build(DictionaryPanelBuilder builder, final Field field) { - final DictionaryModel dictModel = new DictionaryModel(getCellSetDefaultDict()) { - public String getKey() { - return CELL_SET_KEY; - } - }; - - builder.startDictionary(CELL_SET_LABEL, dictModel); - builder.addComponent("Default Value", dictModel.bindUniformDouble("defaultValue")); - - JButton editButton = getEditButton(field, dictModel); - builder.addRight(editButton); - builder.endDictionary(); + public void build(BeanPanelBuilder builder, final Field field) { + if (cellSetScalarModel != null) { + cellSetScalarModel.release(); + } + if (cellSetVectorModel != null) { + cellSetVectorModel.release(); + } + if (Fields.getFieldTypeByName(field.getName()).isVector()) { + VectorCellSetInitialisation initialisation = new VectorCellSetInitialisation(new double[3], Arrays.asList(new VectorSurface(new Box("box1"), new double[3]))); + cellSetVectorModel = new BeanModel<>(initialisation); + builder.startBean(CELL_SET_LABEL, cellSetVectorModel); + builder.addComponent("Default Value", cellSetVectorModel.bindPoint(CellSetInitialisation.DEFAULT_VALUE_KEY)); + JButton editButton = getEditVectorButton(field, cellSetVectorModel); + builder.addRight(editButton); + builder.endBean(); + } else { + ScalarCellSetInitialisation initialisation = new ScalarCellSetInitialisation(0, Arrays.asList(new ScalarSurface(new Box("box1"), 0))); + cellSetScalarModel = new BeanModel<>(initialisation); + builder.startBean(CELL_SET_LABEL, cellSetScalarModel); + builder.addComponent("Default Value", cellSetScalarModel.bindDouble(CellSetInitialisation.DEFAULT_VALUE_KEY)); + JButton editButton = getEditScalarButton(field, cellSetScalarModel); + builder.addRight(editButton); + builder.endBean(); + } } - private JButton getEditButton(final Field field, final DictionaryModel dictModel) { - final CellSetDialog cellSetDialog = new CellSetDialog(model, dictModel, field.getName(), "setSources", AbstractFieldsInitialisationPanel.this); + private JButton getEditVectorButton(final Field field, final BeanModel beanModel) { + final InitialisationVectorCellSetDialog cellSetDialog = new InitialisationVectorCellSetDialog(model, field.getName(), monitor); final Action action = new AbstractAction(EDIT_LABEL, EDIT_ICON) { @Override public void actionPerformed(ActionEvent e) { - cellSetDialog.showDialog(); + cellSetDialog.setInitialisation(beanModel.getBean()); + cellSetDialog.showDialog(new WindowAdapter() { + @Override + public void windowOpened(WindowEvent e) { + setEnabled(false); + } + + @Override + public void windowClosed(WindowEvent e) { + setEnabled(true); + } + }); } }; - cellSetDialog.getDialog().addComponentListener(new ComponentAdapter() { - - @Override - public void componentShown(ComponentEvent e) { - super.componentShown(e); - action.setEnabled(false); - } - - @Override - public void componentHidden(ComponentEvent e) { - super.componentHidden(e); - action.setEnabled(true); - } - }); - - JButton editButton = new JButton(action); - editButton.setName(EDIT_LABEL); - return editButton; + return new EnableDisableActionButton(action, cellSetDialog); } - private Dictionary getCellSetDefaultDict() { - DictionaryBuilder boxBuilder = DictionaryBuilder.newDictionary("boxToCell"); - boxBuilder.field("box", "(0 0 0) (2.0 2.0 1.0 )"); - boxBuilder.field("value", "0.0"); + private JButton getEditScalarButton(final Field field, final BeanModel beanModel) { + final InitialisationScalarCellSetDialog cellSetDialog = new InitialisationScalarCellSetDialog(model, field.getName(), monitor); + final Action action = new AbstractAction(EDIT_LABEL, EDIT_ICON) { + @Override + public void actionPerformed(ActionEvent e) { + cellSetDialog.setInitialisation(beanModel.getBean()); + cellSetDialog.showDialog(new WindowAdapter() { + @Override + public void windowOpened(WindowEvent e) { + setEnabled(false); + } - DictionaryBuilder builder = DictionaryBuilder.newDictionary("initialisation"); - builder.field(TYPE, CELL_SET_KEY); - builder.field("defaultValue", "uniform 0.0"); - builder.list("setSources", boxBuilder.done()); + @Override + public void windowClosed(WindowEvent e) { + setEnabled(true); + } + }); + } + }; - return builder.done(); + return new EnableDisableActionButton(action, cellSetDialog); } - }; + private class EnableDisableActionButton extends JButton { + public EnableDisableActionButton(final Action action, final CellSetDialog cellSetDialog) { + super(action); + setName(EDIT_LABEL); + } + } + @Override public void load() { rebuildPanel(); @@ -226,9 +283,10 @@ public abstract class AbstractFieldsInitialisationPanel extends DefaultGUIPanel @Override public void save() { for (Field f : fieldBuilderMap.keySet()) { - DictionaryPanelBuilder b = fieldBuilderMap.get(f); - Dictionary dictionary = b.getSelectedModel().getDictionary(); - f.setInitialisation(dictionary); + BeanPanelBuilder b = fieldBuilderMap.get(f); + Initialisation init = (Initialisation) b.getSelectedModel().getBean(); + // System.out.println("AbstractFieldsInitialisationPanel.save() " + f.getName() + " -> " + init); + f.setInitialisation(init); } } @@ -257,11 +315,13 @@ public abstract class AbstractFieldsInitialisationPanel extends DefaultGUIPanel } protected void rebuildPanel() { + group.clear(); + fieldBuilderMap.clear(); mainBuilder.clear(); - JButton initialiseButton = new JButton(ActionManager.getInstance().get("initialise.fields")); - initialiseButton.setName("fields.initialise.button"); + JButton initialiseButton = new JButton(ActionManager.getInstance().get(INITIALISE_SCRIPT)); + initialiseButton.setName(FIELDS_INITIALISE_BUTTON); mainBuilder.addRight(initialiseButton); Fields fields = model.getFields(); @@ -271,19 +331,25 @@ public abstract class AbstractFieldsInitialisationPanel extends DefaultGUIPanel buildFieldPanel(field); } initialiseButton.setEnabled(fields.size() > 0); - + revalidate(); repaint(); } - protected JComboBoxController buildFieldPanel(Field field) { + protected void buildFieldPanel(Field field) { + if (ModulesUtil.isFieldInitialisationVetoed(field, modules)) { + return; + } String name = field.getName(); String labelText = unityMeasure(name); - DictionaryPanelBuilder builder = new DictionaryPanelBuilder(); + BeanPanelBuilder builder = new BeanPanelBuilder(); builder.addSeparator(labelText); builder.indent(); builder.prefix(name + "."); - JComboBoxController combo = (JComboBoxController) builder.startChoice("Type"); + + // builder.startChoice(TYPE_LABEL, fieldyModel.bindComboController(TYPE_KEY, noneModifierModel, levelSetModifierModel), TYPE_TOOLTIP); + + JComboBoxController combo = (JComboBoxController) builder.startChoice(TYPE_LABEL); String[] initialisationMethods = field.getInitialisationMethods(); for (String method : initialisationMethods) { @@ -297,7 +363,8 @@ public abstract class AbstractFieldsInitialisationPanel extends DefaultGUIPanel builder.outdent(); builder.prefix(""); - builder.selectDictionary(field.getInitialisation()); + // System.out.println("AbstractFieldsInitialisationPanel.buildFieldPanel() " + field.getInitialisation()); + builder.selectBean(field.getInitialisation()); JPanel builderPanel = builder.getPanel(); builderPanel.setName(name); @@ -306,8 +373,10 @@ public abstract class AbstractFieldsInitialisationPanel extends DefaultGUIPanel mainBuilder.addComponent(builderPanel); fieldBuilderMap.put(field, builder); - - return combo; + + if (BoundaryConditions.isMomentum(name) || BoundaryConditions.isTurbulence(name)) { + group.add(combo); + } } private String unityMeasure(String name) { @@ -325,7 +394,7 @@ public abstract class AbstractFieldsInitialisationPanel extends DefaultGUIPanel if (fields.containsKey(K)) unityMeasures.put(K, K_SYMBOL); if (fields.containsKey(OMEGA)) - unityMeasures.put(OMEGA, OMEGA_SYMBOL); + unityMeasures.put(OMEGA, OMEGA_SYMBOL_S); if (fields.containsKey(EPSILON)) unityMeasures.put(EPSILON, EPSILON_SYMBOL); if (fields.containsKey(NU_TILDA)) @@ -356,10 +425,4 @@ public abstract class AbstractFieldsInitialisationPanel extends DefaultGUIPanel unityMeasures.put("Intensity", ""); } - /** - * Resources - */ - - protected static final Icon EDIT_ICON = ResourcesUtil.getIcon("script.edit.icon"); - } diff --git a/src/eu/engys/gui/casesetup/fields/CellSetDialog.java b/src/eu/engys/gui/casesetup/fields/CellSetDialog.java index ff9b862..59bd1f1 100644 --- a/src/eu/engys/gui/casesetup/fields/CellSetDialog.java +++ b/src/eu/engys/gui/casesetup/fields/CellSetDialog.java @@ -1,41 +1,39 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.casesetup.fields; import java.awt.BorderLayout; -import java.awt.Component; import java.awt.Dialog.ModalityType; import java.awt.FlowLayout; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.Insets; -import java.awt.Window; import java.awt.event.ActionEvent; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; +import java.awt.event.WindowListener; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -43,69 +41,77 @@ import java.util.Map; import javax.swing.AbstractAction; import javax.swing.BorderFactory; +import javax.swing.Icon; import javax.swing.JButton; import javax.swing.JDialog; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JScrollPane; -import javax.swing.SwingUtilities; -import eu.engys.core.dictionary.Dictionary; -import eu.engys.core.dictionary.ListField; -import eu.engys.core.dictionary.model.DictionaryModel; import eu.engys.core.project.Model; +import eu.engys.core.project.geometry.Geometry; import eu.engys.core.project.geometry.Surface; -import eu.engys.core.project.zero.fields.Fields; +import eu.engys.core.project.geometry.Type; +import eu.engys.core.project.geometry.surface.Box; +import eu.engys.core.project.geometry.surface.Cylinder; +import eu.engys.core.project.geometry.surface.Ring; +import eu.engys.core.project.geometry.surface.Sphere; +import eu.engys.core.project.geometry.surface.StlArea; import eu.engys.gui.events.EventManager; import eu.engys.gui.events.view3D.AddSurfaceEvent; import eu.engys.gui.events.view3D.RemoveSurfaceEvent; +import eu.engys.gui.mesh.actions.AddSTLArea; +import eu.engys.util.Util; +import eu.engys.util.progress.ProgressMonitor; +import eu.engys.util.ui.ResourcesUtil; +import eu.engys.util.ui.TitledBorderWithAction; import eu.engys.util.ui.UiUtil; +import eu.engys.util.ui.ViewAction; -public class CellSetDialog extends JPanel { +public abstract class CellSetDialog extends JPanel { + public static final String DIALOG_NAME = "cellset.dialog"; public static final String CELLSET_PANEL_NAME = "cellset.panel"; public static final String CELLSET_REM_NAME = "cellset.rem"; public static final String CELLSET_ADD_NAME = "cellset.add"; - - private Map rowsMap = new HashMap<>(); + + protected final Model model; + protected final ProgressMonitor monitor; + private final String title; + protected Map rowsMap = new HashMap<>(); + private JDialog dialog; private JPanel rowsPanel; private JScrollPane scrollPane; - private DictionaryModel dictionaryModel; - private final String fieldName; - private final Model model; - private final String listName; - private Component parentComponent; private JButton okButton; - public CellSetDialog(Model model, DictionaryModel dictionaryModel, String fieldName, String listName, Component parentComponent) { + public CellSetDialog(Model model, String title, ProgressMonitor monitor) { super(new BorderLayout()); - this.dictionaryModel = dictionaryModel; - this.fieldName = fieldName; this.model = model; - this.parentComponent = parentComponent; - this.listName = listName; + this.monitor = monitor; + this.title = title; setName(CELLSET_PANEL_NAME); layoutComponents(); } private void layoutComponents() { - JPanel addRemovePanel = new JPanel(new FlowLayout()); - addRemovePanel.setOpaque(false); - JButton addButton = new JButton(new AddRowAction()); - addButton.setName(CELLSET_ADD_NAME); - JButton remButton = new JButton(new RemRowAction()); - remButton.setName(CELLSET_REM_NAME); - addRemovePanel.add(addButton); - addRemovePanel.add(remButton); - + JPanel buttonsPanel = new JPanel(new FlowLayout()); + buttonsPanel.setOpaque(false); + + buttonsPanel.add(new JButton(new AddRowAction(Type.STL_AREA)){{ setName(CELLSET_ADD_NAME + ".stl");}}); +// buttonsPanel.add(new JButton(new AddRowAction(Type.IGES)){{ setName(CELLSET_ADD_NAME + ".iges");}}); + buttonsPanel.add(new JButton(new AddRowAction(Type.BOX)){{ setName(CELLSET_ADD_NAME + ".box");}}); + buttonsPanel.add(new JButton(new AddRowAction(Type.SPHERE)){{ setName(CELLSET_ADD_NAME + ".sphere");}}); + buttonsPanel.add(new JButton(new AddRowAction(Type.CYLINDER)){{ setName(CELLSET_ADD_NAME + ".cylinder");}}); +// buttonsPanel.add(new JButton(new AddRowAction(Type.PLANE)){{ setName(CELLSET_ADD_NAME + ".plane");}}); + buttonsPanel.add(new JButton(new AddRowAction(Type.RING)){{ setName(CELLSET_ADD_NAME + ".ring");}}); + JPanel okPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); okButton = new JButton(new AbstractAction("OK") { @Override public void actionPerformed(ActionEvent e) { handleDialogClose(); } - }); okButton.setName("OK"); okPanel.add(okButton); @@ -115,25 +121,18 @@ public class CellSetDialog extends JPanel { centerPanel.add(rowsPanel, BorderLayout.NORTH); centerPanel.add(new JLabel(), BorderLayout.CENTER); - add(addRemovePanel, BorderLayout.NORTH); + add(buttonsPanel, BorderLayout.NORTH); scrollPane = new JScrollPane(centerPanel); scrollPane.setBorder(BorderFactory.createEmptyBorder()); add(scrollPane, BorderLayout.CENTER); add(okPanel, BorderLayout.SOUTH); - layoutDialog(); } - public JDialog getDialog() { - return dialog; - } - - private void layoutDialog() { - Window parent = parentComponent == null ? UiUtil.getActiveWindow() : SwingUtilities.getWindowAncestor(parentComponent); - String title = fieldName.equals(Fields.ALPHA_1) ? fieldName + " [phase 1]" : fieldName; - dialog = new JDialog(parent, title, ModalityType.MODELESS); - dialog.setName("cellset.dialog"); + public void showDialog(WindowListener adapter) { + load(); + dialog = new JDialog(UiUtil.getActiveWindow(), title, ModalityType.MODELESS); + dialog.setName(DIALOG_NAME); dialog.addWindowListener(new WindowAdapter() { - @Override public void windowClosing(WindowEvent e) { handleDialogClose(); @@ -144,47 +143,43 @@ public class CellSetDialog extends JPanel { dialog.setSize(600, 400); dialog.setLocationRelativeTo(null); dialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE); - dialog.getRootPane().setDefaultButton(okButton); - } - - public void showDialog() { - load(); +// dialog.getRootPane().setDefaultButton(okButton); +// dialog.addComponentListener(adapter); + dialog.addWindowListener(adapter); dialog.setVisible(true); } - public void load() { - Dictionary initialisation = dictionaryModel.getDictionary(); - if (initialisation != null && initialisation.isList(listName)) { - ListField sources = initialisation.getList(listName); - for (int i = 0; i < sources.getListElements().size(); i++) { - Dictionary source = (Dictionary) sources.getListElements().get(i); - addRow(new CellSetRow(model, fieldName, source, i)); - } - } - } + protected abstract CellSetRow newRow(Surface surface); - private void addRow(CellSetRow row) { - Integer index = rowsMap.size(); - rowsMap.put(index, row); - rowsPanel.add(row, new GridBagConstraints(0, index, 1, 1, 1.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(5, 10, 5, 10), 0, 0)); - rowsPanel.revalidate(); + protected abstract void load(); + + protected abstract void save(); + + protected void addRow(CellSetRow row) { + _addRow(row); EventManager.triggerEvent(this, new AddSurfaceEvent(row.getSurface())); } + + private void _addRow(CellSetRow row) { + final Surface surface = row.getSurface(); + rowsMap.put(surface.getName(), row); + //remButton.setName(CELLSET_REM_NAME); + row.setBorder(new TitledBorderWithAction(row.getSelectedKey(), row, new Runnable() { + @Override + public void run() { + removeRow(surface.getName()); + } + })); + rowsPanel.add(row, new GridBagConstraints(0, rowsPanel.getComponentCount(), 1, 1, 1.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(5, 10, 5, 10), 0, 0)); + rowsPanel.revalidate(); + } private void handleDialogClose() { save(); clear(); dialog.setVisible(false); - } - - public void save() { - ListField regions = new ListField(listName); - for (Dictionary dict : getDictionaries()) { - regions.add(dict); - } - Dictionary initialisation = dictionaryModel.getDictionary(); - initialisation.remove(listName); - initialisation.add(new ListField(regions)); + dialog.dispose(); + dialog = null; } public void clear() { @@ -196,7 +191,7 @@ public class CellSetDialog extends JPanel { rowsMap.clear(); } - private List getSurfaces() { + protected List getSurfaces() { List surfaces = new ArrayList<>(); for (CellSetRow row : rowsMap.values()) { surfaces.add(row.getSurface()); @@ -204,56 +199,73 @@ public class CellSetDialog extends JPanel { return surfaces; } - private List getDictionaries() { - List dicts = new ArrayList<>(); - for (CellSetRow row : rowsMap.values()) { - dicts.add(row.getDictionary()); - } - return dicts; - } - - private void removeRow() { - CellSetRow row = rowsMap.get(rowsMap.size() - 1); - rowsPanel.remove(row); - rowsPanel.revalidate(); - rowsMap.remove(rowsMap.size() - 1); + private void removeRow(String surfaceName) { + CellSetRow row = rowsMap.remove(surfaceName); EventManager.triggerEvent(this, new RemoveSurfaceEvent(row.getSurface())); + + List rows = new ArrayList<>(rowsMap.values()); + rowsMap.clear(); + rowsPanel.removeAll(); + for (int i = 0; i < rows.size(); i++) { + _addRow(rows.get(i)); + } + rowsPanel.revalidate(); } - private class AddRowAction extends AbstractAction { - - public AddRowAction() { - super("+"); - } - - @Override - public void actionPerformed(ActionEvent e) { - addRow(new CellSetRow(model, fieldName, new Dictionary("boxToCell"), rowsMap.size())); - } - - } - - private class RemRowAction extends AbstractAction { - - public RemRowAction() { - super("-"); - } - - @Override - public void actionPerformed(ActionEvent e) { - if (rowsMap.size() > 1) { - removeRow(); - } - } - } - - // Test purpose only - public void setInitialisation(Dictionary initialisation) { - this.dictionaryModel = new DictionaryModel(initialisation); - } - - // Test purpose only - public Dictionary getInitialisation() { - return dictionaryModel.getDictionary(); + private static String getTooltip(Type type) { + switch (type) { + case BOX: return ResourcesUtil.getString("mesh.box.tooltip"); + case SPHERE: return ResourcesUtil.getString("mesh.sphere.tooltip"); + case CYLINDER: return ResourcesUtil.getString("mesh.cylinder.tooltip"); + case RING: return ResourcesUtil.getString("mesh.ring.tooltip"); + case STL_AREA: return ResourcesUtil.getString("mesh.stl.tooltip"); + default: return ""; } +} + + private static Icon getIcon(Type type) { + switch (type) { + case BOX: return ResourcesUtil.getIcon("mesh.box.icon"); + case SPHERE: return ResourcesUtil.getIcon("mesh.sphere.icon"); + case CYLINDER: return ResourcesUtil.getIcon("mesh.cylinder.icon"); + case RING: return ResourcesUtil.getIcon("mesh.ring.icon"); + case STL_AREA: return ResourcesUtil.getIcon("mesh.stl.icon"); + default: return null; + } + } + + private class AddRowAction extends ViewAction { + private Type type; + + public AddRowAction(Type type) { + super(null, CellSetDialog.getIcon(type), CellSetDialog.getTooltip(type)); + this.type = type; + } + + @Override + public void actionPerformed(ActionEvent e) { + Geometry geometry = model.getGeometry(); + switch (type) { + case BOX: addRow(newRow(geometry.getFactory().newSurface(Box.class, getAName()))); break; + case SPHERE: addRow(newRow(geometry.getFactory().newSurface(Sphere.class, getAName()))); break; + case CYLINDER: addRow(newRow(geometry.getFactory().newSurface(Cylinder.class, getAName()))); break; + case RING: addRow(newRow(geometry.getFactory().newSurface(Ring.class, getAName()))); break; + case STL_AREA: + new AddSTLArea(model, monitor) { + @Override + public void postLoad(StlArea stlArea) { + addRow(newRow(stlArea)); + } + }.execute(); + break; + default: break; + } + + } + + private String getAName() { + return type + Util.generateID(); + } + } + } diff --git a/src/eu/engys/gui/casesetup/fields/CellSetRow.java b/src/eu/engys/gui/casesetup/fields/CellSetRow.java index c96448e..05e798e 100644 --- a/src/eu/engys/gui/casesetup/fields/CellSetRow.java +++ b/src/eu/engys/gui/casesetup/fields/CellSetRow.java @@ -1,515 +1,475 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.casesetup.fields; -import static eu.engys.core.project.geometry.Surface.CENTRE_KEY; -import static eu.engys.core.project.geometry.Surface.INNER_RADIUS_KEY; -import static eu.engys.core.project.geometry.Surface.MAX_KEY; -import static eu.engys.core.project.geometry.Surface.MIN_KEY; -import static eu.engys.core.project.geometry.Surface.OUTER_RADIUS_KEY; -import static eu.engys.core.project.geometry.Surface.POINT1_KEY; -import static eu.engys.core.project.geometry.Surface.POINT2_KEY; -import static eu.engys.core.project.geometry.Surface.RADIUS_KEY; -import static eu.engys.core.project.system.SetFieldsDict.BOX_TO_CELL_KEY; -import static eu.engys.core.project.system.SetFieldsDict.CYLINDER_TO_CELL_KEY; -import static eu.engys.core.project.system.SetFieldsDict.RING_TO_CELL_KEY; -import static eu.engys.core.project.system.SetFieldsDict.SPHERE_TO_CELL_KEY; -import static eu.engys.gui.casesetup.boundaryconditions.utils.BoundaryConditionsUtils.VALUE_KEY; -import static eu.engys.gui.mesh.panels.GeometriesPanelBuilder.CENTRE_LABEL; -import static eu.engys.gui.mesh.panels.GeometriesPanelBuilder.INNER_RADIUS_LABEL; -import static eu.engys.gui.mesh.panels.GeometriesPanelBuilder.MAX_LABEL; -import static eu.engys.gui.mesh.panels.GeometriesPanelBuilder.MIN_LABEL; -import static eu.engys.gui.mesh.panels.GeometriesPanelBuilder.OUTER_RADIUS_LABEL; -import static eu.engys.gui.mesh.panels.GeometriesPanelBuilder.POINT_1_LABEL; -import static eu.engys.gui.mesh.panels.GeometriesPanelBuilder.POINT_2_LABEL; -import static eu.engys.gui.mesh.panels.GeometriesPanelBuilder.RADIUS_LABEL; +import static eu.engys.gui.mesh.panels.ShapesPanel.CENTRE_LABEL; +import static eu.engys.gui.mesh.panels.ShapesPanel.DELTA_LABEL; +import static eu.engys.gui.mesh.panels.ShapesPanel.FILE_LABEL; +import static eu.engys.gui.mesh.panels.ShapesPanel.INCLUDE_CUT_LABEL; +import static eu.engys.gui.mesh.panels.ShapesPanel.INCLUDE_INSIDE_LABEL; +import static eu.engys.gui.mesh.panels.ShapesPanel.INCLUDE_OUTSIDE_LABEL; +import static eu.engys.gui.mesh.panels.ShapesPanel.INNER_RADIUS_LABEL; +import static eu.engys.gui.mesh.panels.ShapesPanel.I_LABEL; +import static eu.engys.gui.mesh.panels.ShapesPanel.J_LABEL; +import static eu.engys.gui.mesh.panels.ShapesPanel.K_LABEL; +import static eu.engys.gui.mesh.panels.ShapesPanel.MAX_LABEL; +import static eu.engys.gui.mesh.panels.ShapesPanel.MIN_LABEL; +import static eu.engys.gui.mesh.panels.ShapesPanel.ORIGIN_LABEL; +import static eu.engys.gui.mesh.panels.ShapesPanel.OUTER_RADIUS_LABEL; +import static eu.engys.gui.mesh.panels.ShapesPanel.OUTSIDE_POINT_LABEL; +import static eu.engys.gui.mesh.panels.ShapesPanel.POINT_1_LABEL; +import static eu.engys.gui.mesh.panels.ShapesPanel.POINT_2_LABEL; +import static eu.engys.gui.mesh.panels.ShapesPanel.RADIUS_LABEL; +import static eu.engys.gui.mesh.panels.ShapesPanel.ROTATION_LABEL; import java.awt.BorderLayout; import java.awt.CardLayout; -import java.awt.GridBagConstraints; -import java.awt.GridBagLayout; -import java.awt.Insets; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; -import java.beans.PropertyChangeEvent; -import java.beans.PropertyChangeListener; -import javax.swing.BorderFactory; -import javax.swing.JComboBox; -import javax.swing.JLabel; +import javax.swing.AbstractAction; +import javax.swing.JButton; +import javax.swing.JCheckBox; +import javax.swing.JComponent; import javax.swing.JPanel; -import javax.swing.JSlider; -import javax.swing.event.ChangeEvent; -import javax.swing.event.ChangeListener; +import javax.swing.JTextField; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import eu.engys.core.dictionary.Dictionary; -import eu.engys.core.dictionary.FieldChangeListener; -import eu.engys.core.dictionary.model.DictionaryModel; import eu.engys.core.project.Model; import eu.engys.core.project.geometry.Surface; import eu.engys.core.project.geometry.surface.Box; import eu.engys.core.project.geometry.surface.Cylinder; import eu.engys.core.project.geometry.surface.Ring; +import eu.engys.core.project.geometry.surface.RotatedBox; import eu.engys.core.project.geometry.surface.Sphere; -import eu.engys.core.project.zero.fields.Fields; +import eu.engys.core.project.geometry.surface.StlArea; import eu.engys.gui.events.EventManager; -import eu.engys.gui.events.view3D.AddSurfaceEvent; import eu.engys.gui.events.view3D.ChangeSurfaceEvent; -import eu.engys.gui.events.view3D.RemoveSurfaceEvent; +import eu.engys.gui.mesh.actions.AddSTLArea; +import eu.engys.gui.mesh.panels.ShapesPanel; import eu.engys.gui.view3D.BoxEventButton; -import eu.engys.util.ui.ComponentsFactory; +import eu.engys.gui.view3D.RotatedBoxEventButton; +import eu.engys.util.bean.BeanModel; +import eu.engys.util.progress.ProgressMonitor; +import eu.engys.util.ui.FieldChangeListener; +import eu.engys.util.ui.TitledBorderWithAction; +import eu.engys.util.ui.builder.JComboBoxController; import eu.engys.util.ui.builder.PanelBuilder; import eu.engys.util.ui.textfields.DoubleField; +import eu.engys.util.ui.textfields.StringField; +import net.java.dev.designgridlayout.Componentizer; -public class CellSetRow extends JPanel { +public abstract class CellSetRow extends JPanel { private static final Logger logger = LoggerFactory.getLogger(CellSetRow.class); public static final String BOX = "Box"; + public static final String RBOX = "Rotated Box"; public static final String SPHERE = "Sphere"; public static final String CYLINDER = "Cylinder"; public static final String RING = "Ring"; + public static final String SURFACE = "Surface"; public static final String CELLSET_NAME = "cellset"; public static final String CELLSET_ROW_NAME = "cellset.row"; public static final String CELLSET_VALUE_NAME = "cellset.value"; public static final String CELLSET_SLIDER_NAME = "cellset.slider"; - private DictionaryModel boxModel = new DictionaryModel(getDefaultBoxModelDictionary()); - private DictionaryModel sphereModel = new DictionaryModel(getDefaultSphereModelDictionary()); - private DictionaryModel cylinderModel = new DictionaryModel(getDefaultCylinderModelDictionary()); - private DictionaryModel ringModel = new DictionaryModel(getDefaultRingModelDictionary()); + private BeanModel boxModel = new BeanModel<>(); + private BeanModel rBoxModel = new BeanModel<>(); + private BeanModel sphereModel = new BeanModel<>(); + private BeanModel cylinderModel = new BeanModel<>(); + private BeanModel ringModel = new BeanModel<>(); + private BeanModel surfaceModel = new BeanModel<>(); + private FieldChangeListener listener; private JPanel coordinatesPanel; - private Dictionary loadedDictionary; - private Surface surface; - private Integer index; - private JComboBox choice; - private DoubleField valueField; - private SliderChangeListener valueSliderListener; - private TextFieldChangeListener valueFieldListener; + // private JComboBox choice; private BoxEventButton showBoxButton; + private RotatedBoxEventButton showRotatedBoxButton; - private Model model; - private String fieldName; + protected Model model; + protected Surface surface; - public CellSetRow(Model model, String fieldName, Dictionary dictionary, Integer index) { + // private SurfaceTypeListener surfaceTypeListener; + private ProgressMonitor monitor; + private JComboBoxController boxType; + + private ActionListener boxTypeListener; + + private String selectedKey; + + public CellSetRow(Model model, Surface surface, ProgressMonitor monitor) { super(new BorderLayout()); this.model = model; - this.fieldName = fieldName; - this.loadedDictionary = dictionary; - this.index = index; + this.surface = surface; + this.monitor = monitor; this.listener = new ValueFieldChangeListener(); - setName(CELLSET_ROW_NAME + "." + index); - layoutComponents(); - load(); + setName(CELLSET_ROW_NAME + "." + surface.getName()); } - private void layoutComponents() { - setBorder(BorderFactory.createTitledBorder(BOX)); + protected void layoutComponents() { + // setBorder(BorderFactory.createTitledBorder(BOX)); setOpaque(false); coordinatesPanel = createCoordinatersPanel(); - choice = create3DCombo(); + // choice = create3DCombo(); JPanel valuePanel = createValuePanel(); - add(choice, BorderLayout.NORTH); + // add(choice, BorderLayout.NORTH); add(coordinatesPanel, BorderLayout.CENTER); add(valuePanel, BorderLayout.SOUTH); } - private JPanel createValuePanel() { - valueField = ComponentsFactory.doubleField(0.0, 0.0, 1.0); - valueField.setName(CELLSET_VALUE_NAME + "." + index); - JSlider valueSlider = createSlider(); - valueSlider.addChangeListener(valueSliderListener = new SliderChangeListener(valueField)); - valueField.addPropertyChangeListener(valueFieldListener = new TextFieldChangeListener(valueSlider)); + protected abstract JPanel createValuePanel(); - JPanel valuePanel = new JPanel(new GridBagLayout()); - valuePanel.setOpaque(false); - valuePanel.add(valueSlider, new GridBagConstraints(0, 0, 2, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); - valuePanel.add(valueField, new GridBagConstraints(2, 0, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(12, 5, 0, 0), 0, 0)); - - valuePanel.add(label(getLeftLabel()), new GridBagConstraints(0, 1, 1, 1, 1.0, 1.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); - valuePanel.add(label(getRightLabel()), new GridBagConstraints(1, 1, 1, 1, 1.0, 1.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); - valuePanel.add(label(""), new GridBagConstraints(2, 1, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); - return valuePanel; - } - - private void load() { - if (!loadedDictionary.isEmpty()) { - Dictionary newDict = new Dictionary(""); - if (loadedDictionary.found("box")) { - String boxValue = loadedDictionary.lookup("box"); - String min = boxValue.substring(0, boxValue.indexOf(")") + 1).trim(); - String max = boxValue.replace(min, "").trim(); - newDict.add(MIN_KEY, min); - newDict.add(MAX_KEY, max); - choice.setSelectedItem(BOX); - boxModel.setDictionary(newDict); - surface.setGeometryDictionary(boxModel.getDictionary()); - } else if (loadedDictionary.found(CENTRE_KEY) && loadedDictionary.found(RADIUS_KEY)) {// sphere - newDict.add(CENTRE_KEY, loadedDictionary.lookup(CENTRE_KEY)); - newDict.add(RADIUS_KEY, loadedDictionary.lookup(RADIUS_KEY)); - choice.setSelectedItem(SPHERE); - sphereModel.setDictionary(newDict); - surface.setGeometryDictionary(sphereModel.getDictionary()); - } else if (loadedDictionary.found(POINT1_KEY) && loadedDictionary.found(RADIUS_KEY)) {// cylinder - newDict.add(RADIUS_KEY, loadedDictionary.lookup(RADIUS_KEY)); - newDict.add(POINT1_KEY, loadedDictionary.lookup(POINT1_KEY)); - newDict.add(POINT2_KEY, loadedDictionary.lookup(POINT2_KEY)); - choice.setSelectedItem(CYLINDER); - cylinderModel.setDictionary(newDict); - surface.setGeometryDictionary(cylinderModel.getDictionary()); - } else if (loadedDictionary.found(INNER_RADIUS_KEY) && loadedDictionary.found(OUTER_RADIUS_KEY)) {// ring - newDict.add(POINT1_KEY, loadedDictionary.lookup(POINT1_KEY)); - newDict.add(POINT2_KEY, loadedDictionary.lookup(POINT2_KEY)); - newDict.add(INNER_RADIUS_KEY, loadedDictionary.lookup(INNER_RADIUS_KEY)); - newDict.add(OUTER_RADIUS_KEY, loadedDictionary.lookup(OUTER_RADIUS_KEY)); - choice.setSelectedItem(RING); - ringModel.setDictionary(newDict); - surface.setGeometryDictionary(ringModel.getDictionary()); - } - - if (loadedDictionary.found(VALUE_KEY)) { - String value = loadedDictionary.lookup(VALUE_KEY); - valueField.setDoubleValue(Double.parseDouble(value)); + protected void _load() { + // choice.removeActionListener(surfaceTypeListener); + listener.setAdjusting(true); + if (surface != null) { + if (surface instanceof Box) { + // choice.setSelectedItem(BOX); + showPanel(BOX); + Box box = (Box) surface; + boxModel.setBean(box); + if (box.getRotation()[0] != 0 || box.getRotation()[1] != 0 || box.getRotation()[2] != 0) { + boxType.setSelectedKey(ShapesPanel.CENTRE_DELTA_BOX); + } else { + boxType.setSelectedKey(ShapesPanel.MIN_MAX_BOX); + } + } else if (surface instanceof RotatedBox) { + // choice.setSelectedItem(RBOX); + showPanel(RBOX); + rBoxModel.setBean((RotatedBox) surface); + } else if (surface instanceof Sphere) { + // choice.setSelectedItem(SPHERE); + showPanel(SPHERE); + sphereModel.setBean((Sphere) surface); + } else if (surface instanceof Cylinder) { + // choice.setSelectedItem(CYLINDER); + showPanel(CYLINDER); + cylinderModel.setBean((Cylinder) surface); + } else if (surface instanceof Ring) { + // choice.setSelectedItem(RING); + showPanel(RING); + ringModel.setBean((Ring) surface); + } else if (surface instanceof StlArea) { + // choice.setSelectedItem(SURFACE); + showPanel(SURFACE); + surfaceModel.setBean((StlArea) surface); } + load(); } else { addNewBox(); } + listener.setAdjusting(false); + // choice.addActionListener(surfaceTypeListener); } + protected abstract void load(); + + protected abstract void newBox(); + private void addNewBox() { - surface = model.getGeometry().getFactory().newSurface(Box.class, "Box_" + index); - boxModel.setDictionary(surface.getGeometryDictionary()); + surface = model.getGeometry().getFactory().newSurface(Box.class, model.getGeometry().getAName(BOX)); + boxModel.setBean((Box) surface); + newBox(); } - private JSlider createSlider() { - JSlider valueSlider = new JSlider(JSlider.HORIZONTAL, 0, fieldName.equals(Fields.ALPHA_1) ? 1 : 100, 0); - valueSlider.setName(CELLSET_SLIDER_NAME + "." + index); - valueSlider.setMajorTickSpacing(10); - valueSlider.setPaintTicks(true); - valueSlider.setPaintTrack(true); - valueSlider.setPaintLabels(false); - return valueSlider; - } - - private JComboBox create3DCombo() { - choice = new JComboBox(new String[] { BOX, SPHERE, CYLINDER, RING }); - choice.setName(CELLSET_NAME + "." + index); - choice.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - CardLayout layout = (CardLayout) coordinatesPanel.getLayout(); - Surface existingSurface = surface; - if (existingSurface != null) { - EventManager.triggerEvent(this, new RemoveSurfaceEvent(surface)); - } - if (choice.getSelectedIndex() == 0) { - layout.show(coordinatesPanel, BOX); - setBorder(BorderFactory.createTitledBorder(BOX)); - surface = model.getGeometry().getFactory().newSurface(Box.class, BOX + "_" + index); - boxModel.setDictionary(surface.getGeometryDictionary()); - } else if (choice.getSelectedIndex() == 1) { - layout.show(coordinatesPanel, SPHERE); - setBorder(BorderFactory.createTitledBorder(SPHERE)); - surface = model.getGeometry().getFactory().newSurface(Sphere.class, SPHERE + "_" + index); - sphereModel.setDictionary(surface.getGeometryDictionary()); - } else if (choice.getSelectedIndex() == 2) { - layout.show(coordinatesPanel, CYLINDER); - setBorder(BorderFactory.createTitledBorder(CYLINDER)); - surface = model.getGeometry().getFactory().newSurface(Cylinder.class, CYLINDER + "_" + index); - cylinderModel.setDictionary(surface.getGeometryDictionary()); - } else if (choice.getSelectedIndex() == 3) { - layout.show(coordinatesPanel, RING); - setBorder(BorderFactory.createTitledBorder(RING)); - surface = model.getGeometry().getFactory().newSurface(Ring.class, RING + "_" + index); - ringModel.setDictionary(surface.getGeometryDictionary()); - } - if (existingSurface != null) { - EventManager.triggerEvent(this, new AddSurfaceEvent(surface)); - } - } - }); - return choice; - } + // private JComboBox create3DCombo() { + // surfaceTypeListener = new SurfaceTypeListener(); + // choice = new JComboBox(new String[] { BOX, RBOX, SPHERE, CYLINDER, RING, SURFACE }); + // choice.setName(CELLSET_NAME + "." + index); + // choice.addActionListener(surfaceTypeListener); + // return choice; + // } private JPanel createCoordinatersPanel() { CardLayout c = new CardLayout(); JPanel p = new JPanel(c); p.setOpaque(false); p.add(getBoxPanel(), BOX); + p.add(getRBoxPanel(), RBOX); p.add(getSpherePanel(), SPHERE); p.add(getCylinderPanel(), CYLINDER); p.add(getRingPanel(), RING); + p.add(getSurfacePanel(), SURFACE); c.show(p, BOX); return p; } private JPanel getBoxPanel() { PanelBuilder boxBuilder = new PanelBuilder(); - DoubleField[] boxMin = boxModel.bindPoint(MIN_KEY, listener); - DoubleField[] boxMax = boxModel.bindPoint(MAX_KEY, listener); + DoubleField[] boxMin = boxModel.bindPoint(Box.MIN_KEY); + DoubleField[] boxMax = boxModel.bindPoint(Box.MAX_KEY); + + DoubleField[] center = boxModel.bindPoint(Box.CENTER_KEY); + DoubleField[] delta = boxModel.bindPoint(Box.DELTA_KEY); + DoubleField[] rotation = boxModel.bindPoint(Box.ROTATION_KEY); + + addChangeSurfaceAction(boxMin); + addChangeSurfaceAction(boxMax); + addChangeSurfaceAction(center); + addChangeSurfaceAction(delta); + addChangeSurfaceAction(rotation); showBoxButton = new BoxEventButton(boxMin, boxMax); + showRotatedBoxButton = new RotatedBoxEventButton(center, delta, rotation); + boxType = (JComboBoxController) boxBuilder.startChoice("Type"); + boxBuilder.startGroup(ShapesPanel.MIN_MAX_BOX); boxBuilder.addComponent(MIN_LABEL, boxMin[0], boxMin[1], boxMin[2], showBoxButton); boxBuilder.addComponentAndSpan(MAX_LABEL, boxMax); + boxBuilder.endGroup(); + boxBuilder.startGroup(ShapesPanel.CENTRE_DELTA_BOX); + boxBuilder.addComponent(CENTRE_LABEL, center[0], center[1], center[2], showRotatedBoxButton); + boxBuilder.addComponentAndSpan(DELTA_LABEL, delta); + boxBuilder.addComponentAndSpan(ROTATION_LABEL, rotation); + boxBuilder.endGroup(); + boxBuilder.endChoice(); + boxTypeListener = new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + if (boxType.getSelectedKey().equals(ShapesPanel.MIN_MAX_BOX)) { + boxModel.getBean().setRotation(Box.DEFAULT_ROTATION); + if (showRotatedBoxButton.isSelected()) { + showRotatedBoxButton.doClick(); + showBoxButton.doClick(); + } + } else if (boxType.getSelectedKey().equals(ShapesPanel.CENTRE_DELTA_BOX)) { + if (showBoxButton.isSelected()) { + showBoxButton.doClick(); + showRotatedBoxButton.doClick(); + } + } + } + }; + boxType.addActionListener(boxTypeListener); return boxBuilder.getPanel(); } - private JPanel getSpherePanel() { - PanelBuilder sphereBuilder = new PanelBuilder(); - sphereBuilder.addComponent(CENTRE_LABEL, sphereModel.bindPoint(CENTRE_KEY, listener)); - sphereBuilder.addComponent(RADIUS_LABEL, sphereModel.bindDouble(RADIUS_KEY, listener)); - return sphereBuilder.getPanel(); + private JPanel getRBoxPanel() { + PanelBuilder rboxBuilder = new PanelBuilder(); + DoubleField[] boxOrigin = rBoxModel.bindPoint(RotatedBox.ORIGIN_KEY); + DoubleField[] boxI = rBoxModel.bindPoint(RotatedBox.I_KEY); + DoubleField[] boxJ = rBoxModel.bindPoint(RotatedBox.J_KEY); + DoubleField[] boxK = rBoxModel.bindPoint(RotatedBox.K_KEY); + addChangeSurfaceAction(boxOrigin); + addChangeSurfaceAction(boxI); + addChangeSurfaceAction(boxJ); + addChangeSurfaceAction(boxK); + + rboxBuilder.addComponent(ORIGIN_LABEL, boxOrigin); + rboxBuilder.addComponent(I_LABEL, boxI); + rboxBuilder.addComponent(J_LABEL, boxJ); + rboxBuilder.addComponent(K_LABEL, boxK); + + return rboxBuilder.getPanel(); + } + + private JPanel getSpherePanel() { + DoubleField[] centre = sphereModel.bindPoint(Sphere.CENTRE_KEY); + DoubleField radius = sphereModel.bindDouble(Sphere.RADIUS_KEY); + + PanelBuilder sphereBuilder = new PanelBuilder(); + sphereBuilder.addComponent(CENTRE_LABEL, centre); + sphereBuilder.addComponent(RADIUS_LABEL, radius); + + addChangeSurfaceAction(centre); + addChangeSurfaceAction(radius); + + return sphereBuilder.getPanel(); } private JPanel getCylinderPanel() { + DoubleField[] point1 = cylinderModel.bindPoint(Cylinder.POINT1_KEY); + DoubleField[] point2 = cylinderModel.bindPoint(Cylinder.POINT2_KEY); + DoubleField radius = cylinderModel.bindDouble(Cylinder.RADIUS_KEY); + PanelBuilder cylinderBuilder = new PanelBuilder(); - cylinderBuilder.addComponent(POINT_1_LABEL, cylinderModel.bindPoint(POINT1_KEY, listener)); - cylinderBuilder.addComponent(POINT_2_LABEL, cylinderModel.bindPoint(POINT2_KEY, listener)); - cylinderBuilder.addComponent(RADIUS_LABEL, cylinderModel.bindDouble(RADIUS_KEY, listener)); + cylinderBuilder.addComponent(POINT_1_LABEL, point1); + cylinderBuilder.addComponent(POINT_2_LABEL, point2); + cylinderBuilder.addComponent(RADIUS_LABEL, radius); + + addChangeSurfaceAction(point1); + addChangeSurfaceAction(point2); + addChangeSurfaceAction(radius); + return cylinderBuilder.getPanel(); } private JPanel getRingPanel() { + DoubleField[] point1 = ringModel.bindPoint(Ring.POINT1_KEY); + DoubleField[] point2 = ringModel.bindPoint(Ring.POINT2_KEY); + DoubleField radius1 = ringModel.bindDouble(Ring.INNER_RADIUS_KEY); + DoubleField radius2 = ringModel.bindDouble(Ring.OUTER_RADIUS_KEY); + PanelBuilder ringBuilder = new PanelBuilder(); - ringBuilder.addComponent(POINT_1_LABEL, ringModel.bindPoint(POINT1_KEY, listener)); - ringBuilder.addComponent(POINT_2_LABEL, ringModel.bindPoint(POINT2_KEY, listener)); - ringBuilder.addComponent(INNER_RADIUS_LABEL, ringModel.bindDouble(INNER_RADIUS_KEY, listener)); - ringBuilder.addComponent(OUTER_RADIUS_LABEL, ringModel.bindDouble(OUTER_RADIUS_KEY, listener)); + ringBuilder.addComponent(POINT_1_LABEL, point1); + ringBuilder.addComponent(POINT_2_LABEL, point2); + ringBuilder.addComponent(INNER_RADIUS_LABEL, radius1); + ringBuilder.addComponent(OUTER_RADIUS_LABEL, radius2); + + addChangeSurfaceAction(point1); + addChangeSurfaceAction(point2); + addChangeSurfaceAction(radius1, radius2); + return ringBuilder.getPanel(); } + private JPanel getSurfacePanel() { + StringField file = surfaceModel.bindLabel(StlArea.FILE); + DoubleField[] point = surfaceModel.bindPoint(StlArea.OUTSIDE_POINT); + JCheckBox cut = surfaceModel.bindBoolean(StlArea.INCLUDE_CUT); + JCheckBox inside = surfaceModel.bindBoolean(StlArea.INCLUDE_INSIDE); + JCheckBox outside = surfaceModel.bindBoolean(StlArea.INCLUDE_OUTSIDE); + + file.setEnabled(false); + JButton button = new JButton(new AbstractAction("Open") { + @Override + public void actionPerformed(ActionEvent e) { + new AddSTLArea(model, monitor) { + @Override + public void postLoad(StlArea stlArea) { + StlArea bean = surfaceModel.getBean(); + bean.setDataSet(stlArea.getDataSet()); + bean.setFile(stlArea.getFile()); + } + }.execute(); + } + }); + JComponent c = Componentizer.create().minAndMore(file).minToPref(button).component(); + PanelBuilder surfaceBuilder = new PanelBuilder(); + surfaceBuilder.addComponent(FILE_LABEL, c); + surfaceBuilder.addComponent(OUTSIDE_POINT_LABEL, point); + surfaceBuilder.addComponent(INCLUDE_CUT_LABEL, cut); + surfaceBuilder.addComponent(INCLUDE_INSIDE_LABEL, inside); + surfaceBuilder.addComponent(INCLUDE_OUTSIDE_LABEL, outside); + + file.setName(CELLSET_NAME + "." + FILE_LABEL); + button.setName(CELLSET_NAME + "." + "button"); + + addChangeSurfaceAction(file); + + return surfaceBuilder.getPanel(); + } + + void addChangeSurfaceAction(JTextField... components) { + for (JTextField c : components) { + c.addPropertyChangeListener("value", listener); + } + } + public Surface getSurface() { return surface; } - public Dictionary getDictionary() { - switch (choice.getItemAt(choice.getSelectedIndex())) { - case BOX: { - Dictionary boxToCell = new Dictionary(BOX_TO_CELL_KEY); - String min = boxModel.getDictionary().lookup(MIN_KEY); - String max = boxModel.getDictionary().lookup(MAX_KEY); - boxToCell.add("box", min + " " + max); - boxToCell.add(VALUE_KEY, String.valueOf(valueField.getDoubleValue())); - return boxToCell; + // private final class SurfaceTypeListener implements ActionListener { + // @Override + // public void actionPerformed(ActionEvent e) { + // Surface existingSurface = surface; + // if (existingSurface != null) { + // EventManager.triggerEvent(this, new RemoveSurfaceEvent(surface)); + // } + // + // listener.setAdjusting(true); + // if (BOX.equals(choice.getSelectedItem())) { + // boxType.removeActionListener(boxTypeListener); + // showPanel(BOX); + // surface = model.getGeometry().getFactory().newSurface(Box.class, model.getGeometry().getAName(BOX)); + // boxModel.setBean((Box) surface); + // boxType.addActionListener(boxTypeListener); + // } else if (RBOX.equals(choice.getSelectedItem())) { + // showPanel(RBOX); + // surface = model.getGeometry().getFactory().newSurface(RotatedBox.class, model.getGeometry().getAName(RBOX)); + // rBoxModel.setBean((RotatedBox) surface); + // } else if (SPHERE.equals(choice.getSelectedItem())) { + // showPanel(SPHERE); + // surface = model.getGeometry().getFactory().newSurface(Sphere.class, model.getGeometry().getAName(SPHERE)); + // sphereModel.setBean((Sphere) surface); + // } else if (CYLINDER.equals(choice.getSelectedItem())) { + // showPanel(CYLINDER); + // surface = model.getGeometry().getFactory().newSurface(Cylinder.class, model.getGeometry().getAName(CYLINDER)); + // cylinderModel.setBean((Cylinder) surface); + // } else if (RING.equals(choice.getSelectedItem())) { + // showPanel(RING); + // surface = model.getGeometry().getFactory().newSurface(Ring.class, model.getGeometry().getAName(RING)); + // ringModel.setBean((Ring) surface); + // } else if (SURFACE.equals(choice.getSelectedItem())) { + // showPanel(SURFACE); + // surface = model.getGeometry().getFactory().newSurface(StlArea.class, model.getGeometry().getAName(SURFACE)); + // surfaceModel.setBean((StlArea) surface); + // } + // listener.setAdjusting(false); + // // newBox(); + // if (existingSurface != null) { + // EventManager.triggerEvent(this, new AddSurfaceEvent(surface)); + // } + // } + // + // } + + private void showPanel(String key) { + this.selectedKey = key; + CardLayout layout = (CardLayout) coordinatesPanel.getLayout(); + layout.show(coordinatesPanel, key); + // setBorder(BorderFactory.createTitledBorder(key)); + if (getBorder() instanceof TitledBorderWithAction) { + ((TitledBorderWithAction) getBorder()).setTitle(key); } - case SPHERE: { - Dictionary sphereToCell = new Dictionary(SPHERE_TO_CELL_KEY); - String centre = sphereModel.getDictionary().lookup(CENTRE_KEY); - String radius = sphereModel.getDictionary().lookup(RADIUS_KEY); - sphereToCell.add(CENTRE_KEY, centre); - sphereToCell.add(RADIUS_KEY, radius); - sphereToCell.add(VALUE_KEY, String.valueOf(valueField.getDoubleValue())); - return sphereToCell; - } - case CYLINDER: { - Dictionary cylinderToCell = new Dictionary(CYLINDER_TO_CELL_KEY); - String p1 = cylinderModel.getDictionary().lookup(POINT1_KEY); - String p2 = cylinderModel.getDictionary().lookup(POINT2_KEY); - String radius = cylinderModel.getDictionary().lookup(RADIUS_KEY); - cylinderToCell.add(POINT1_KEY, p1); - cylinderToCell.add(POINT2_KEY, p2); - cylinderToCell.add(RADIUS_KEY, radius); - cylinderToCell.add(VALUE_KEY, String.valueOf(valueField.getDoubleValue())); - return cylinderToCell; - } - case RING: { - Dictionary ringToCell = new Dictionary(RING_TO_CELL_KEY); - String p1 = ringModel.getDictionary().lookup(POINT1_KEY); - String p2 = ringModel.getDictionary().lookup(POINT2_KEY); - String iRadius = ringModel.getDictionary().lookup(INNER_RADIUS_KEY); - String oRadius = ringModel.getDictionary().lookup(OUTER_RADIUS_KEY); - ringToCell.add(POINT1_KEY, p1); - ringToCell.add(POINT2_KEY, p2); - ringToCell.add(INNER_RADIUS_KEY, iRadius); - ringToCell.add(OUTER_RADIUS_KEY, oRadius); - ringToCell.add(VALUE_KEY, String.valueOf(valueField.getDoubleValue())); - return ringToCell; - } - default: - return null; - } - } - - private class TextFieldChangeListener implements PropertyChangeListener { - - private JSlider slider; - - public TextFieldChangeListener(JSlider slider) { - this.slider = slider; - } - - @Override - public void propertyChange(PropertyChangeEvent evt) { - if (evt.getPropertyName().equals("value")) { - slider.removeChangeListener(valueSliderListener); - DoubleField field = (DoubleField) evt.getSource(); - slider.setValue((int) (field.getDoubleValue() * 100)); - slider.addChangeListener(valueSliderListener); - } - } - }; - - private class SliderChangeListener implements ChangeListener { - - private DoubleField field; - - public SliderChangeListener(DoubleField field) { - this.field = field; - } - - @Override - public void stateChanged(ChangeEvent e) { - field.removePropertyChangeListener(valueFieldListener); - JSlider slider = (JSlider) e.getSource(); - double value = slider.getValue(); - field.setDoubleValue(value / slider.getMaximum()); - field.addPropertyChangeListener(valueFieldListener); - } - }; - - private class ValueFieldChangeListener implements FieldChangeListener { - - boolean adjusting = false; - - @Override - public void actionPerformed(ActionEvent e) { - } - - @Override - public void setAdjusting(boolean b) { - this.adjusting = b; - } - - @Override - public boolean isAdjusting() { - return adjusting; - } - - @Override - public void fieldChanged() { - if (!isAdjusting()) { - if (surface.getType().isBox()) - surface.setGeometryDictionary(boxModel.getDictionary()); - else if (surface.getType().isSphere()) - surface.setGeometryDictionary(sphereModel.getDictionary()); - else if (surface.getType().isCylinder()) - surface.setGeometryDictionary(cylinderModel.getDictionary()); - else if (surface.getType().isRing()) - surface.setGeometryDictionary(ringModel.getDictionary()); - else - logger.error("Unknow surface type"); - - EventManager.triggerEvent(this, new ChangeSurfaceEvent(surface, false)); - } - } - }; - - private Dictionary getDefaultBoxModelDictionary() { - Dictionary dictionary = new Dictionary(BOX_TO_CELL_KEY); - dictionary.add(MIN_KEY, "(0.0 0.0 0.0)"); - dictionary.add(MAX_KEY, "(2.0 2.0 1.0)"); - return dictionary; - } - - private Dictionary getDefaultSphereModelDictionary() { - Dictionary dictionary = new Dictionary(SPHERE_TO_CELL_KEY); - dictionary.add(CENTRE_KEY, "(0.0 0.0 0.0 )"); - dictionary.add(RADIUS_KEY, "2.0"); - return dictionary; - } - - private Dictionary getDefaultCylinderModelDictionary() { - Dictionary dictionary = new Dictionary(CYLINDER_TO_CELL_KEY); - dictionary.add(POINT1_KEY, "(0.0 0.0 -1.5 )"); - dictionary.add(POINT2_KEY, "(0.0 0.0 1.5 )"); - dictionary.add(RADIUS_KEY, "2.0"); - return dictionary; - } - - private Dictionary getDefaultRingModelDictionary() { - Dictionary dictionary = new Dictionary(RING_TO_CELL_KEY); - dictionary.add(POINT1_KEY, "(0.0 0.0 0 )"); - dictionary.add(POINT2_KEY, "(0.05 0.0 0 )"); - dictionary.add(INNER_RADIUS_KEY, "0.2"); - dictionary.add(OUTER_RADIUS_KEY, "0.5"); - return dictionary; - } - - private String getLeftLabel() { - String label; - if (model.getState().getMultiphaseModel().isMultiphase()) { - if (fieldName.equals(Fields.ALPHA_1)) { - label = model.getMaterials().get(1).getName(); - } else if (fieldName.startsWith(Fields.ALPHA + ".")) { - label = "No " + Fields.PHASE_OS(fieldName); - } else if (fieldName.startsWith(Fields.ALPHA)) { - label = "No " + Fields.PHASE(fieldName); - } else { - label = "No " + fieldName; - } - } else { - label = "No " + fieldName; - } - return label; - } - - private String getRightLabel() { - String label; - if (model.getState().getMultiphaseModel().isMultiphase()) { - if (fieldName.equals(Fields.ALPHA_1)) { - label = model.getMaterials().get(0).getName(); - } else if (fieldName.startsWith(Fields.ALPHA)) { - label = Fields.PHASE(fieldName); - } else { - label = fieldName; - } - } else { - label = fieldName; - } - return label; - } - - private JLabel label(String name) { - return new JLabel(name); } public void clear() { + boxModel.release(); + rBoxModel.release(); + sphereModel.release(); + cylinderModel.release(); + ringModel.release(); + surfaceModel.release(); + if (showBoxButton.isSelected()) { showBoxButton.doClick(); } + if (showRotatedBoxButton.isSelected()) { + showRotatedBoxButton.doClick(); + } } + private class ValueFieldChangeListener extends FieldChangeListener { + @Override + public void fieldChanged(Object source) { + EventManager.triggerEvent(this, new ChangeSurfaceEvent(surface, false)); + } + } + + public String getSelectedKey() { + return selectedKey; + }; + } diff --git a/src/eu/engys/gui/casesetup/fields/InitialisationAlphaCellSetRow.java b/src/eu/engys/gui/casesetup/fields/InitialisationAlphaCellSetRow.java new file mode 100644 index 0000000..9dd48c2 --- /dev/null +++ b/src/eu/engys/gui/casesetup/fields/InitialisationAlphaCellSetRow.java @@ -0,0 +1,179 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.gui.casesetup.fields; + +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; +import java.awt.Insets; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; + +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JSlider; +import javax.swing.event.ChangeEvent; +import javax.swing.event.ChangeListener; + +import eu.engys.core.project.Model; +import eu.engys.core.project.geometry.Surface; +import eu.engys.core.project.zero.fields.Fields; +import eu.engys.util.progress.ProgressMonitor; +import eu.engys.util.ui.ComponentsFactory; +import eu.engys.util.ui.textfields.DoubleField; + +public class InitialisationAlphaCellSetRow extends CellSetRow { + + private DoubleField valueField; + private double value; + private String fieldName; + private SliderChangeListener valueSliderListener; + private TextFieldChangeListener valueFieldListener; + + public InitialisationAlphaCellSetRow(Model model, String fieldName, Surface surface, double value, ProgressMonitor monitor) { + super(model, surface, monitor); + this.fieldName = fieldName; + this.value = value; + layoutComponents(); + _load(); + } + + @Override + protected JPanel createValuePanel() { + valueField = ComponentsFactory.doubleField(0.0, 0.0, 1.0); + valueField.setName(CELLSET_VALUE_NAME + "." + surface.getName()); + JSlider valueSlider = createSlider(); + valueSlider.addChangeListener(valueSliderListener = new SliderChangeListener(valueField)); + valueField.addPropertyChangeListener(valueFieldListener = new TextFieldChangeListener(valueSlider)); + + JPanel valuePanel = new JPanel(new GridBagLayout()); + valuePanel.setOpaque(false); + valuePanel.add(valueSlider, new GridBagConstraints(0, 0, 2, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); + valuePanel.add(valueField, new GridBagConstraints(2, 0, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(12, 5, 0, 0), 0, 0)); + + valuePanel.add(label(getLeftLabel()), new GridBagConstraints(0, 1, 1, 1, 1.0, 1.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); + valuePanel.add(label(getRightLabel()), new GridBagConstraints(1, 1, 1, 1, 1.0, 1.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); + valuePanel.add(label(""), new GridBagConstraints(2, 1, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); + return valuePanel; + } + + private JSlider createSlider() { + JSlider valueSlider = new JSlider(JSlider.HORIZONTAL, 0, fieldName.equals(Fields.ALPHA_1) ? 1 : 100, 0); + valueSlider.setName(CELLSET_SLIDER_NAME + "." + surface.getName()); + valueSlider.setMajorTickSpacing(10); + valueSlider.setPaintTicks(true); + valueSlider.setPaintTrack(true); + valueSlider.setPaintLabels(false); + return valueSlider; + } + + private class TextFieldChangeListener implements PropertyChangeListener { + + private JSlider slider; + + public TextFieldChangeListener(JSlider slider) { + this.slider = slider; + } + + @Override + public void propertyChange(PropertyChangeEvent evt) { + if (evt.getPropertyName().equals("value")) { + slider.removeChangeListener(valueSliderListener); + DoubleField field = (DoubleField) evt.getSource(); + slider.setValue((int) (field.getDoubleValue() * 100)); + slider.addChangeListener(valueSliderListener); + } + } + }; + + private class SliderChangeListener implements ChangeListener { + + private DoubleField field; + + public SliderChangeListener(DoubleField field) { + this.field = field; + } + + @Override + public void stateChanged(ChangeEvent e) { + field.removePropertyChangeListener(valueFieldListener); + JSlider slider = (JSlider) e.getSource(); + double value = slider.getValue(); + field.setDoubleValue(value / slider.getMaximum()); + field.addPropertyChangeListener(valueFieldListener); + } + }; + + private String getLeftLabel() { + String label; + if (model.getState().getMultiphaseModel().isMultiphase()) { + if (fieldName.equals(Fields.ALPHA_1)) { + label = model.getMaterials().get(1).getName(); + } else if (fieldName.startsWith(Fields.ALPHA + ".")) { + label = "No " + Fields.PHASE_OS(fieldName); + } else if (fieldName.startsWith(Fields.ALPHA)) { + label = "No " + Fields.PHASE(fieldName); + } else { + label = "No " + fieldName; + } + } else { + label = "No " + fieldName; + } + return label; + } + + private String getRightLabel() { + String label; + if (model.getState().getMultiphaseModel().isMultiphase()) { + if (fieldName.equals(Fields.ALPHA_1)) { + label = model.getMaterials().get(0).getName(); + } else if (fieldName.startsWith(Fields.ALPHA)) { + label = Fields.PHASE(fieldName); + } else { + label = fieldName; + } + } else { + label = fieldName; + } + return label; + } + + private JLabel label(String name) { + return new JLabel(name); + } + + @Override + protected void load() { + valueField.setDoubleValue(value); + } + + @Override + protected void newBox() { + valueField.setDoubleValue(0); + } + + public Double getValue() { + return value = valueField.getDoubleValue(); + } +} diff --git a/src/eu/engys/gui/casesetup/fields/InitialisationComboGroup.java b/src/eu/engys/gui/casesetup/fields/InitialisationComboGroup.java new file mode 100644 index 0000000..8b47ccb --- /dev/null +++ b/src/eu/engys/gui/casesetup/fields/InitialisationComboGroup.java @@ -0,0 +1,122 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.gui.casesetup.fields; + +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Vector; + +import eu.engys.core.project.zero.fields.BoundaryValueInitialisation; +import eu.engys.core.project.zero.fields.DefaultInitialisation; +import eu.engys.core.project.zero.fields.FixedScalarInitialisation; +import eu.engys.core.project.zero.fields.FixedVectorInitialisation; +import eu.engys.core.project.zero.fields.PotentialFlowInitialisation; +import eu.engys.core.project.zero.fields.PrandtlInitialisation; +import eu.engys.core.project.zero.fields.TurbulentILInitialisation; +import eu.engys.util.ui.builder.JComboBoxController; + +public class InitialisationComboGroup implements ActionListener { + + private static final String DEFAULT_CLASS = DefaultInitialisation.class.getCanonicalName(); + private static final String FIXED_SCALAR_VALUE_CLASS = FixedScalarInitialisation.class.getCanonicalName(); + private static final String FIXED_VECTOR_VALUE_CLASS = FixedVectorInitialisation.class.getCanonicalName(); + private static final String POTENTIAL_FLOW_CLASS = PotentialFlowInitialisation.class.getCanonicalName(); + private static final String TURBULENT_IL_CLASS = TurbulentILInitialisation.class.getCanonicalName(); + private static final String PRANDTL_CLASS = PrandtlInitialisation.class.getCanonicalName(); + private static final String BOUNDARY_VALUE_CLASS = BoundaryValueInitialisation.class.getCanonicalName(); + + private static final List TURBULENCE_TYPES = new ArrayList(Arrays.asList(new String[] { "k.Type", "omega.Type", "epsilon.Type", "nuTilda.Type" })); + private static final List MOMENTUM_TYPES = new ArrayList(Arrays.asList(new String[] { "U.Type", "p.Type", "p_rgh.Type" })); + + + private Vector combos = new Vector(); + + public void clear() { + for (JComboBoxController combo : combos) { + combo.removeActionListener(this); + } + combos.clear(); + } + + public void add(JComboBoxController b) { + if (b == null) { + return; + } + combos.addElement(b); + b.addActionListener(this); + } + + /* + * When 'potentialFlow' is selected by the user for 'U' or 'p', the + * other should be automatically put to potentialFlow Same behavior for + * turbulent quantities + */ + @Override + public void actionPerformed(ActionEvent e) { + JComboBoxController source = (JComboBoxController) e.getSource(); + if (hasBeenSelected(source, POTENTIAL_FLOW_CLASS)) { + changeTo(null, POTENTIAL_FLOW_CLASS, MOMENTUM_TYPES); + } else if (hasBeenSelected(source, TURBULENT_IL_CLASS)) { + changeTo(null, TURBULENT_IL_CLASS, TURBULENCE_TYPES); + } else if (hasBeenSelected(source, PRANDTL_CLASS)) { + changeTo(null, PRANDTL_CLASS, TURBULENCE_TYPES); + changeTo(null, POTENTIAL_FLOW_CLASS, MOMENTUM_TYPES); + } else if (hasBeenSelected(source, DEFAULT_CLASS) || hasBeenSelected(source, FIXED_SCALAR_VALUE_CLASS) || hasBeenSelected(source, FIXED_VECTOR_VALUE_CLASS)) { + if (fieldChangedIsA(source, TURBULENCE_TYPES)) { + changeTo(TURBULENT_IL_CLASS, DEFAULT_CLASS, TURBULENCE_TYPES); + changeTo(PRANDTL_CLASS, DEFAULT_CLASS, TURBULENCE_TYPES); + } else if (fieldChangedIsA(source, MOMENTUM_TYPES)) { + changeTo(PRANDTL_CLASS, DEFAULT_CLASS, TURBULENCE_TYPES); + changeTo(POTENTIAL_FLOW_CLASS, DEFAULT_CLASS, MOMENTUM_TYPES); + } + } + } + + private boolean hasBeenSelected(JComboBoxController source, String type) { + return type.equals(source.getSelectedKey()); + } + + private boolean fieldChangedIsA(JComboBoxController source, List type) { + return type.contains(source.getName()); + } + + private void changeTo(String oldKey, String newKey, List fieldsToChangeList) { + for (JComboBoxController combo : combos) { + boolean condition1 = combo.getSelectedKey().equals(oldKey) || oldKey == null; + boolean condition2 = combo.containsKey(newKey); + boolean condition3 = !combo.getSelectedKey().equals(newKey); + boolean condition4 = fieldsToChangeList.contains(combo.getName()); + + if (condition1 && condition2 && condition3 && condition4) { + combo.removeActionListener(this); + combo.setSelectedKey(newKey); + combo.addActionListener(this); + } + } + } +} diff --git a/src/eu/engys/gui/casesetup/fields/InitialisationScalarCellSetDialog.java b/src/eu/engys/gui/casesetup/fields/InitialisationScalarCellSetDialog.java new file mode 100644 index 0000000..3cbbcb7 --- /dev/null +++ b/src/eu/engys/gui/casesetup/fields/InitialisationScalarCellSetDialog.java @@ -0,0 +1,110 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.gui.casesetup.fields; + +import java.util.ArrayList; +import java.util.List; + +import eu.engys.core.project.Model; +import eu.engys.core.project.geometry.Surface; +import eu.engys.core.project.zero.fields.CellSetInitialisation.ScalarSurface; +import eu.engys.core.project.zero.fields.Fields; +import eu.engys.core.project.zero.fields.ScalarCellSetInitialisation; +import eu.engys.util.progress.ProgressMonitor; + +public class InitialisationScalarCellSetDialog extends CellSetDialog { + + private final String fieldName; + private ScalarCellSetInitialisation initialisation; + + public InitialisationScalarCellSetDialog(Model model, String fieldName, ProgressMonitor monitor) { + super(model, getTitle(fieldName), monitor); + this.fieldName = fieldName; + } + + private static String getTitle(String fieldName) { + return fieldName.equals(Fields.ALPHA_1) ? fieldName + " [phase 1]" : fieldName; + } + + @Override + protected CellSetRow newRow(Surface surface) { + if (fieldName.startsWith(Fields.ALPHA)) { + return new InitialisationAlphaCellSetRow(model, fieldName, surface, 0.0, monitor); + } else { + return new InitialisationScalarCellSetRow(model, fieldName, surface, 0.0, monitor); + } + } + + private CellSetRow createRow(Surface surface, double value, Integer i) { + if (fieldName.startsWith(Fields.ALPHA)) { + return new InitialisationAlphaCellSetRow(model, fieldName, surface, value, monitor); + } else { + return new InitialisationScalarCellSetRow(model, fieldName, surface, value, monitor); + } + } + + @Override + public void load() { + List sources = initialisation.getSurfaces(); + for (int i = 0; i < sources.size(); i++) { + ScalarSurface scalarSurface = sources.get(i); + addRow(createRow(scalarSurface.getSurface(), scalarSurface.getValue(), i)); + } + } + + @Override + public void save() { + List surfaces = getSurfaces(); + List values = getValues(); + List ss = new ArrayList<>(); + for (int i = 0; i < surfaces.size(); i++) { + Surface surface = surfaces.get(i); + Double value = values.get(i); + ss.add(new ScalarSurface(surface, value)); + } + initialisation.setSurfaces(ss); + + } + + private List getValues() { + List values = new ArrayList<>(); + for (CellSetRow row : rowsMap.values()) { + if (row instanceof InitialisationScalarCellSetRow) { + values.add(((InitialisationScalarCellSetRow)row).getValue()); + } else if (row instanceof InitialisationAlphaCellSetRow) { + values.add(((InitialisationAlphaCellSetRow)row).getValue()); + } + } + return values; + } + + public void setInitialisation(ScalarCellSetInitialisation initialisation) { + this.initialisation = initialisation; + } + + public ScalarCellSetInitialisation getInitialisation() { + return initialisation; + } +} diff --git a/src/eu/engys/gui/casesetup/fields/InitialisationScalarCellSetRow.java b/src/eu/engys/gui/casesetup/fields/InitialisationScalarCellSetRow.java new file mode 100644 index 0000000..48e0a30 --- /dev/null +++ b/src/eu/engys/gui/casesetup/fields/InitialisationScalarCellSetRow.java @@ -0,0 +1,72 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.gui.casesetup.fields; + +import javax.swing.JPanel; + +import eu.engys.core.project.Model; +import eu.engys.core.project.geometry.Surface; +import eu.engys.util.progress.ProgressMonitor; +import eu.engys.util.ui.ComponentsFactory; +import eu.engys.util.ui.builder.PanelBuilder; +import eu.engys.util.ui.textfields.DoubleField; + +public class InitialisationScalarCellSetRow extends CellSetRow { + + private DoubleField valueField; + private double value; + + public InitialisationScalarCellSetRow(Model model, String fieldName, Surface surface, double value, ProgressMonitor monitor) { + super(model, surface, monitor); + this.value = value; + layoutComponents(); + _load(); + } + + @Override + protected JPanel createValuePanel() { + valueField = ComponentsFactory.doubleField(); + + PanelBuilder pb = new PanelBuilder(); + pb.addComponent("Value", valueField); + + valueField.setName(CELLSET_VALUE_NAME + "." + surface.getName()); + return pb.getPanel(); + } + + @Override + protected void load() { + valueField.setDoubleValue(value); + } + + @Override + protected void newBox() { + valueField.setDoubleValue(0); + } + + public Double getValue() { + return value = valueField.getDoubleValue(); + } +} diff --git a/src/eu/engys/gui/casesetup/fields/InitialisationVectorCellSetDialog.java b/src/eu/engys/gui/casesetup/fields/InitialisationVectorCellSetDialog.java new file mode 100644 index 0000000..aba1b16 --- /dev/null +++ b/src/eu/engys/gui/casesetup/fields/InitialisationVectorCellSetDialog.java @@ -0,0 +1,97 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.gui.casesetup.fields; + +import java.util.ArrayList; +import java.util.List; + +import eu.engys.core.project.Model; +import eu.engys.core.project.geometry.Surface; +import eu.engys.core.project.zero.fields.CellSetInitialisation.VectorSurface; +import eu.engys.core.project.zero.fields.Fields; +import eu.engys.core.project.zero.fields.VectorCellSetInitialisation; +import eu.engys.util.progress.ProgressMonitor; + +public class InitialisationVectorCellSetDialog extends CellSetDialog { + + private final String fieldName; + private VectorCellSetInitialisation initialisation; + + public InitialisationVectorCellSetDialog(Model model, String fieldName, ProgressMonitor monitor) { + super(model, getTitle(fieldName), monitor); + this.fieldName = fieldName; + } + + private static String getTitle(String fieldName) { + return fieldName.equals(Fields.ALPHA_1) ? fieldName + " [phase 1]" : fieldName; + } + + @Override + protected CellSetRow newRow(Surface surface) { + return new InitialisationVectorCellSetRow(model, fieldName, surface, new double[]{0.0, 0.0, 0.0}, monitor); + } + + private CellSetRow createRow(Surface surface, double[] value) { + return new InitialisationVectorCellSetRow(model, fieldName, surface, value, monitor); + } + + @Override + public void load() { + List sources = initialisation.getSurfaces(); + for (int i = 0; i < sources.size(); i++) { + VectorSurface vectorSurface = sources.get(i); + addRow(createRow(vectorSurface.getSurface(), vectorSurface.getValue())); + } + } + + @Override + public void save() { + List surfaces = getSurfaces(); + List values = getValues(); + List vs = new ArrayList<>(); + for (int i = 0; i < surfaces.size(); i++) { + Surface surface = surfaces.get(i); + double[] value = values.get(i); + vs.add(new VectorSurface(surface, value)); + } + initialisation.setSurfaces(vs); + } + + private List getValues() { + List values = new ArrayList<>(); + for (CellSetRow row : rowsMap.values()) { + values.add(((InitialisationVectorCellSetRow)row).getValue()); + } + return values; + } + + public void setInitialisation(VectorCellSetInitialisation initialisation) { + this.initialisation = initialisation; + } + + public VectorCellSetInitialisation getInitialisation() { + return initialisation; + } +} diff --git a/src/eu/engys/gui/casesetup/fields/InitialisationVectorCellSetRow.java b/src/eu/engys/gui/casesetup/fields/InitialisationVectorCellSetRow.java new file mode 100644 index 0000000..ed4b2b4 --- /dev/null +++ b/src/eu/engys/gui/casesetup/fields/InitialisationVectorCellSetRow.java @@ -0,0 +1,83 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.gui.casesetup.fields; + +import javax.swing.JPanel; + +import eu.engys.core.project.Model; +import eu.engys.core.project.geometry.Surface; +import eu.engys.util.progress.ProgressMonitor; +import eu.engys.util.ui.ComponentsFactory; +import eu.engys.util.ui.builder.PanelBuilder; +import eu.engys.util.ui.textfields.DoubleField; + +public class InitialisationVectorCellSetRow extends CellSetRow { + + private DoubleField[] valueField; + private double[] value; + + public InitialisationVectorCellSetRow(Model model, String fieldName, Surface surface, double[] value, ProgressMonitor monitor) { + super(model, surface, monitor); + this.value = value; + layoutComponents(); + _load(); + } + + @Override + protected JPanel createValuePanel() { + valueField = ComponentsFactory.doublePointField(); + + PanelBuilder pb = new PanelBuilder(); + pb.addComponent("Value", valueField); + + valueField[0].setName(CELLSET_VALUE_NAME + "." + surface.getName() + ".0"); + valueField[1].setName(CELLSET_VALUE_NAME + "." + surface.getName() + ".1"); + valueField[2].setName(CELLSET_VALUE_NAME + "." + surface.getName() + ".2"); + + return pb.getPanel(); + } + + @Override + protected void load() { + for (int i = 0; i < valueField.length; i++) { + valueField[i].setDoubleValue(value[i]); + } + } + + @Override + protected void newBox() { + for (int i = 0; i < valueField.length; i++) { + valueField[i].setDoubleValue(0.0); + } + } + + public double[] getValue() { + value = new double[3]; + for (int i = 0; i < valueField.length; i++) { + value[i] = valueField[i].getDoubleValue(); + } + return value; + } +} diff --git a/src/eu/engys/gui/casesetup/fields/SetFieldsDictConverter.java b/src/eu/engys/gui/casesetup/fields/SetFieldsDictConverter.java index 306b6b1..e54347a 100644 --- a/src/eu/engys/gui/casesetup/fields/SetFieldsDictConverter.java +++ b/src/eu/engys/gui/casesetup/fields/SetFieldsDictConverter.java @@ -1,32 +1,31 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.casesetup.fields; import static eu.engys.core.dictionary.Dictionary.TYPE; +import static eu.engys.core.dictionary.Dictionary.UNIFORM; import static eu.engys.core.dictionary.Dictionary.VALUE; import static eu.engys.core.project.system.SetFieldsDict.CELL_SET_KEY; import static eu.engys.core.project.system.SetFieldsDict.DEFAULT_FIELD_VALUES_KEY; @@ -35,89 +34,150 @@ import static eu.engys.core.project.system.SetFieldsDict.FIELD_VALUES_KEY; import static eu.engys.core.project.system.SetFieldsDict.REGIONS_KEY; import static eu.engys.core.project.system.SetFieldsDict.SET_SOURCES_KEY; import static eu.engys.core.project.system.SetFieldsDict.VOL_SCALAR_FIELD_VALUE_KEY; -import eu.engys.core.dictionary.DefaultElement; +import static eu.engys.core.project.system.SetFieldsDict.VOL_VECTOR_FIELD_VALUE_KEY; +import static eu.engys.core.project.zero.fields.Field.INITIALISATION_KEY; +import static eu.engys.core.project.zero.fields.Fields.U; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; + import eu.engys.core.dictionary.Dictionary; import eu.engys.core.project.system.SetFieldsDict; import eu.engys.core.project.zero.fields.Field; +import eu.engys.core.project.zero.fields.Fields; public class SetFieldsDictConverter { + private final String SCALAR_REGEXP(String fieldName) { + return VOL_SCALAR_FIELD_VALUE_KEY + "\\s*" + fieldName + "\\s*(\\-?\\d+\\.?\\d*(?:[eE][+-]?\\d+)?)"; + } + + private final String VECTOR_REGEXP(String fieldName) { + return VOL_VECTOR_FIELD_VALUE_KEY + "\\s*" + fieldName + "\\s+(\\(.*\\))"; + } + + private SetFieldsDict setFieldsDict; private Field field; - public SetFieldsDictConverter(Field field) { + public SetFieldsDictConverter(SetFieldsDict setFieldsDict, Field field) { + this.setFieldsDict = setFieldsDict; this.field = field; } - public Dictionary convertForRead(SetFieldsDict dictToFix) { - Dictionary fixedDict = new Dictionary(dictToFix); - fixHeaderForRead(fixedDict); - fixRegionsForRead(fixedDict); - fixedDict.setName("initialisation"); - return fixedDict; - } - - public SetFieldsDict convertForWrite(Dictionary dictToFix) { - SetFieldsDict fixedDict = new SetFieldsDict(dictToFix); - fixHeaderForWrite(fixedDict); - fixRegionsForWrite(fixedDict); - fixedDict.setName(SetFieldsDict.SET_FIELDS_DICT); - return fixedDict; - } - - private void fixHeaderForRead(Dictionary dictionary) { - if (!dictionary.found(TYPE)) { - dictionary.add(TYPE, CELL_SET_KEY); + public boolean isFieldCellSetInitialized() { + if (setFieldsDict.found(DEFAULT_FIELD_VALUES_KEY)) { + String defaultFieldValues = setFieldsDict.lookupString(DEFAULT_FIELD_VALUES_KEY); + Pattern pattern; + if (field.getName().equals(U)) { + pattern = Pattern.compile(VECTOR_REGEXP(field.getName())); + } else { + pattern = Pattern.compile(SCALAR_REGEXP(field.getName())); + } + Matcher matcher = pattern.matcher(defaultFieldValues); + if (matcher.find() && matcher.groupCount() == 1) { + return true; + } } - if (!dictionary.found(DEFAULT_VALUE_KEY) && dictionary.found(DEFAULT_FIELD_VALUES_KEY)) { - String fixedValue = dictionary.lookup(DEFAULT_FIELD_VALUES_KEY).replace("(", "").replace(")", "").replace(VOL_SCALAR_FIELD_VALUE_KEY, "").replace(field.getName(), "").trim(); - dictionary.add(DEFAULT_VALUE_KEY, "uniform " + fixedValue); - dictionary.remove(DEFAULT_FIELD_VALUES_KEY); + return false; + } + + public Dictionary readFromSetFieldsDict() { + Dictionary convertedDict = new Dictionary(INITIALISATION_KEY); + readHeaderFromSetFieldsDict(convertedDict); + readRegionsFromSetFieldsDict(convertedDict); + return convertedDict; + } + + private void readHeaderFromSetFieldsDict(Dictionary d) { + d.add(TYPE, CELL_SET_KEY); + if (setFieldsDict.found(DEFAULT_FIELD_VALUES_KEY)) { + String defaultFieldValues = setFieldsDict.lookupString(DEFAULT_FIELD_VALUES_KEY); + Pattern pattern; + if (field.getName().equals(U)) { + pattern = Pattern.compile(VECTOR_REGEXP(field.getName())); + } else { + pattern = Pattern.compile(SCALAR_REGEXP(field.getName())); + } + Matcher matcher = pattern.matcher(defaultFieldValues); + if (matcher.find() && matcher.groupCount() == 1) { + String value = matcher.group(1); + d.add(DEFAULT_VALUE_KEY, UNIFORM + " " + value); + } } } - private void fixRegionsForRead(Dictionary dictionary) { - if (!dictionary.found(SET_SOURCES_KEY) && dictionary.found(REGIONS_KEY)) { - for (DefaultElement element : dictionary.getList(REGIONS_KEY).getListElements()) { - if (element instanceof Dictionary) { - Dictionary dict = (Dictionary) element; - if (!dict.found(VALUE) && dict.found(FIELD_VALUES_KEY)) { - String fixedValue = dict.lookup(FIELD_VALUES_KEY).replace("(", "").replace(")", "").replace(VOL_SCALAR_FIELD_VALUE_KEY, "").replace(field.getName(), "").trim(); - dict.add(VALUE, fixedValue); - dict.remove(FIELD_VALUES_KEY); + private void readRegionsFromSetFieldsDict(Dictionary d) { + if (setFieldsDict.found(REGIONS_KEY)) { + for (Dictionary dict : setFieldsDict.getList(REGIONS_KEY).getDictionaries()) { + Dictionary cloneDict = new Dictionary(dict); + if (cloneDict.found(FIELD_VALUES_KEY)) { + String fieldValues = cloneDict.lookup(FIELD_VALUES_KEY); + Pattern pattern; + if (field.getName().equals(U)) { + pattern = Pattern.compile(VECTOR_REGEXP(field.getName())); + } else { + pattern = Pattern.compile(SCALAR_REGEXP(field.getName())); + } + Matcher matcher = pattern.matcher(fieldValues); + if (matcher.find() && matcher.groupCount() == 1) { + String value = matcher.group(1); + cloneDict.add(VALUE, value); + cloneDict.remove(FIELD_VALUES_KEY); + d.addToList(SET_SOURCES_KEY, cloneDict); } - dictionary.addToList(SET_SOURCES_KEY, dict); } } - dictionary.remove(REGIONS_KEY); } } - private void fixHeaderForWrite(Dictionary dictionary) { - if (dictionary.found(TYPE)) { - dictionary.remove(TYPE); + public void writeToSetFieldsDict(Dictionary toConvertDict) { + if (!setFieldsDict.found(DEFAULT_FIELD_VALUES_KEY)) { + setFieldsDict.add(DEFAULT_FIELD_VALUES_KEY, ""); } - if (dictionary.found(DEFAULT_VALUE_KEY)) { - String fixedValue = "( " + VOL_SCALAR_FIELD_VALUE_KEY + " " + field.getName() + " " + dictionary.lookup(DEFAULT_VALUE_KEY).replace("uniform", "").trim() + " )"; - dictionary.add(DEFAULT_FIELD_VALUES_KEY, fixedValue); - dictionary.remove(DEFAULT_VALUE_KEY); - } - } + + String trimmed = setFieldsDict.lookupString(DEFAULT_FIELD_VALUES_KEY).trim(); + String defaultFieldValuesString = trimmed.isEmpty() ? trimmed : trimmed.substring(1, trimmed.length() - 1); + defaultFieldValuesString += (" " + getDefaultFieldValue(toConvertDict)); + setFieldsDict.add(DEFAULT_FIELD_VALUES_KEY, "(" + defaultFieldValuesString.trim() + ")"); - private void fixRegionsForWrite(Dictionary dictionary) { - if (dictionary.found(SET_SOURCES_KEY)) { - for (DefaultElement element : dictionary.getList(SET_SOURCES_KEY).getListElements()) { - if (element instanceof Dictionary) { - Dictionary dict = (Dictionary) element; - if (dict.found(VALUE)) { - String value = dict.lookup(VALUE); - dict.add(FIELD_VALUES_KEY, "( " + VOL_SCALAR_FIELD_VALUE_KEY + " " + field.getName() + " " + value + " )"); - dict.remove(VALUE); - } - dictionary.addToList(REGIONS_KEY, dict); + if (toConvertDict.found(SET_SOURCES_KEY)) { + for (Dictionary dict : toConvertDict.getList(SET_SOURCES_KEY).getDictionaries()) { + Dictionary regionDict = getRegionDict(dict); + if (regionDict != null) { + setFieldsDict.addToList(REGIONS_KEY, regionDict); } } - dictionary.remove(SET_SOURCES_KEY); } } + private String getDefaultFieldValue(Dictionary d) { + if (d.found(DEFAULT_VALUE_KEY)) { + if (field.getName().equals(Fields.U)) { + return VOL_VECTOR_FIELD_VALUE_KEY + " " + field.getName() + " " + doubleArrayToString(d.lookupDoubleArray(DEFAULT_VALUE_KEY)); + } else { + return VOL_SCALAR_FIELD_VALUE_KEY + " " + field.getName() + " " + d.lookupDoubleUniform(DEFAULT_VALUE_KEY); + } + } + return ""; + } + + private Dictionary getRegionDict(Dictionary dict) { + if (dict.found(VALUE)) { + Dictionary copy = new Dictionary(dict); + if (field.getName().equals(Fields.U)) { + copy.add(FIELD_VALUES_KEY, "( " + VOL_VECTOR_FIELD_VALUE_KEY + " " + field.getName() + " " + doubleArrayToString(copy.lookupDoubleArray(VALUE)) + " )"); + copy.remove(VALUE); + } else { + copy.add(FIELD_VALUES_KEY, "( " + VOL_SCALAR_FIELD_VALUE_KEY + " " + field.getName() + " " + copy.lookupDouble(VALUE) + " )"); + copy.remove(VALUE); + } + return copy; + } + return null; + } + + private String doubleArrayToString(double[] array) { + return "(" + array[0] + " " + array[1] + " " + array[2] + ")"; + } + } diff --git a/src/eu/engys/gui/casesetup/fields/StandardFieldsInitialisationPanel.java b/src/eu/engys/gui/casesetup/fields/StandardFieldsInitialisationPanel.java index 68f0bff..2ac0fc6 100644 --- a/src/eu/engys/gui/casesetup/fields/StandardFieldsInitialisationPanel.java +++ b/src/eu/engys/gui/casesetup/fields/StandardFieldsInitialisationPanel.java @@ -1,75 +1,128 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.casesetup.fields; import static eu.engys.core.dictionary.Dictionary.TYPE; +import static eu.engys.core.project.system.FvSolution.INITIALISE_UBCS_KEY; +import static eu.engys.core.project.system.FvSolution.N_NON_ORTHOGONAL_CORRECTORS_KEY; +import static eu.engys.core.project.zero.fields.Fields.ALPHA; +import static eu.engys.core.project.zero.fields.Fields.U; import static eu.engys.core.project.zero.fields.Initialisations.CELL_SET_KEY; +import static eu.engys.core.project.zero.fields.PotentialFlowInitialisation.INIT_UBCS; +import static eu.engys.core.project.zero.fields.PotentialFlowInitialisation.N_NON_ORTHOGONAL_CORRECTORS; + +import java.util.Set; import javax.inject.Inject; -import eu.engys.core.controller.Controller; import eu.engys.core.dictionary.Dictionary; -import eu.engys.core.dictionary.DictionaryUtils; -import eu.engys.core.dictionary.model.DictionaryPanelBuilder; +import eu.engys.core.modules.ApplicationModule; import eu.engys.core.project.Model; +import eu.engys.core.project.system.FvSolution; import eu.engys.core.project.system.SetFieldsDict; -import eu.engys.core.project.system.SystemFolder; import eu.engys.core.project.zero.fields.Field; import eu.engys.core.project.zero.fields.Fields; +import eu.engys.core.project.zero.fields.LoadSaveInitialisation; +import eu.engys.core.project.zero.fields.PotentialFlowInitialisation; +import eu.engys.util.bean.BeanModel; +import eu.engys.util.bean.BeanPanelBuilder; +import eu.engys.util.progress.ProgressMonitor; public class StandardFieldsInitialisationPanel extends AbstractFieldsInitialisationPanel { - @Inject - public StandardFieldsInitialisationPanel(Model model, Controller controller) { - super(model); - } + private static final String POTENTIAL_FLOW_KEY = "potentialFlow"; - @Override - public void save() { - for (Field f : fieldBuilderMap.keySet()) { - DictionaryPanelBuilder builder = fieldBuilderMap.get(f); - Dictionary dictionary = builder.getSelectedModel().getDictionary(); + public static final String NON_ORTHOGONAL_CORRECTORS_LABEL = "Non-orthogonal Correctors"; - if (model.getState().getMultiphaseModel().isMultiphase() && f.getName().equals(Fields.ALPHA + "." + model.getMaterials().getFirstMaterialName())) { - if (dictionary.found(TYPE) && dictionary.lookup(TYPE).equals(CELL_SET_KEY)) { - writeSetFieldsDict(dictionary, f); - } else { - writeSetFieldsDict(new SetFieldsDict(), f); - } - } - f.setInitialisation(dictionary); - } - } + @Inject + public StandardFieldsInitialisationPanel(Model model, Set modules, ProgressMonitor monitor) { + super(model, modules, monitor); + } - private void writeSetFieldsDict(Dictionary dictionary, Field field) { - SetFieldsDict fixedSetFieldsDict = new SetFieldsDictConverter(field).convertForWrite(dictionary); - SystemFolder systemFolder = model.getProject().getSystemFolder(); - systemFolder.setSetFieldsDict(fixedSetFieldsDict); - DictionaryUtils.writeDictionary(systemFolder.getFileManager().getFile(), fixedSetFieldsDict, monitor); - } + @Override + protected Builder createPotentialFlowBuilder() { + return new Builder() { + private BeanModel beanModel; + + @Override + public void build(BeanPanelBuilder builder, Field field) { + if (beanModel != null) { + beanModel.release(); + } + beanModel = createPotentialFlowDictionaryModel(field); + + boolean isPRGH = model.getState().isBuoyant() || model.getState().getMultiphaseModel().isOn(); + if(model.getState().isIncompressible() && !isPRGH){ + builder.startBean(POTENTIAL_FLOW_LABEL, beanModel); + if (U.equals(field.getName())) { + builder.addComponent(INITIALISE_BOUNDARIES_LABEL, beanModel.bindBoolean(INIT_UBCS)); + builder.addComponent(NON_ORTHOGONAL_CORRECTORS_LABEL, beanModel.bindIntegerPositive(N_NON_ORTHOGONAL_CORRECTORS)); + } + builder.endBean(); + } + } + + private BeanModel createPotentialFlowDictionaryModel(Field field) { + return new BeanModel<>(new PotentialFlowInitialisation()); + } + }; + } + + @Override + public void save() { + super.save(); + SetFieldsDict setFieldsDict = new SetFieldsDict(); + for (Field f : fieldBuilderMap.keySet()) { + LoadSaveInitialisation loadSaveInitialisation = new LoadSaveInitialisation(model.getProject().getBaseDir(), model.getState(), monitor); + Dictionary dictionary = loadSaveInitialisation.save(f.getInitialisation(), Fields.getFieldTypeByName(f.getName())); + saveCellSetInitialisation(setFieldsDict, f, dictionary); + savePotentialFlowInitialisation(f, dictionary); + } + model.getProject().getSystemFolder().setSetFieldsDict(setFieldsDict); + } + + private void savePotentialFlowInitialisation(Field f, Dictionary dictionary) { + if (f.getName().equals(U)) { + FvSolution fvSolution = model.getProject().getSystemFolder().getFvSolution(); + if (dictionary.found(TYPE) && dictionary.lookup(TYPE).equals(POTENTIAL_FLOW_KEY)) { + Dictionary potentialFlowDict = new Dictionary(POTENTIAL_FLOW_KEY); + potentialFlowDict.add(N_NON_ORTHOGONAL_CORRECTORS_KEY, ((PotentialFlowInitialisation) f.getInitialisation()).getnNonOrthogonalCorrectors()); + potentialFlowDict.add(INITIALISE_UBCS_KEY, ((PotentialFlowInitialisation) f.getInitialisation()).isInitUBCS()); + fvSolution.add(potentialFlowDict); + } else { + fvSolution.remove(POTENTIAL_FLOW_KEY); + } + } + } + + private void saveCellSetInitialisation(SetFieldsDict setFieldsDict, Field f, Dictionary dictionary) { + if (f.getName().equals(ALPHA + "." + model.getMaterials().getFirstMaterialName())) { + if (dictionary.found(TYPE) && dictionary.lookup(TYPE).equals(CELL_SET_KEY)) { + new SetFieldsDictConverter(setFieldsDict, f).writeToSetFieldsDict(dictionary); + } + } + } } diff --git a/src/eu/engys/gui/casesetup/fields/StandardInitialisations.java b/src/eu/engys/gui/casesetup/fields/StandardInitialisations.java index fe37c98..73f3d02 100644 --- a/src/eu/engys/gui/casesetup/fields/StandardInitialisations.java +++ b/src/eu/engys/gui/casesetup/fields/StandardInitialisations.java @@ -1,35 +1,32 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.casesetup.fields; -import static eu.engys.core.dictionary.Dictionary.TYPE; -import static eu.engys.core.dictionary.Dictionary.VALUE; +import static eu.engys.core.project.system.FvSolution.N_NON_ORTHOGONAL_CORRECTORS_KEY; import java.io.File; -import java.util.Set; import javax.inject.Inject; @@ -37,31 +34,34 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import eu.engys.core.dictionary.Dictionary; -import eu.engys.core.dictionary.DictionaryBuilder; -import eu.engys.core.modules.ApplicationModule; import eu.engys.core.project.Model; +import eu.engys.core.project.system.FvSolution; import eu.engys.core.project.system.SetFieldsDict; -import eu.engys.core.project.zero.cellzones.CellZonesBuilder; import eu.engys.core.project.zero.fields.AbstractInitialisations; import eu.engys.core.project.zero.fields.ArrayInternalField; +import eu.engys.core.project.zero.fields.DefaultInitialisation; import eu.engys.core.project.zero.fields.Field; import eu.engys.core.project.zero.fields.Fields; +import eu.engys.core.project.zero.fields.FixedScalarInitialisation; +import eu.engys.core.project.zero.fields.FixedVectorInitialisation; +import eu.engys.core.project.zero.fields.Initialisation; +import eu.engys.core.project.zero.fields.InternalField; +import eu.engys.core.project.zero.fields.LoadSaveInitialisation; +import eu.engys.core.project.zero.fields.PotentialFlowInitialisation; import eu.engys.core.project.zero.fields.ScalarInternalField; +import eu.engys.core.project.zero.patches.BoundaryConditions; import eu.engys.core.project.zero.patches.Patch; import eu.engys.util.progress.ProgressMonitor; -import eu.engys.util.progress.SilentMonitor; public class StandardInitialisations extends AbstractInitialisations { private static final Logger logger = LoggerFactory.getLogger(StandardInitialisations.class); - private Set modules; - private CellZonesBuilder cellZonesBuilder; + private ProgressMonitor monitor; @Inject - public StandardInitialisations(Model model, CellZonesBuilder cellZonesBuilder, Set modules) { + public StandardInitialisations(Model model, ProgressMonitor monitor) { super(model); - this.cellZonesBuilder = cellZonesBuilder; - this.modules = modules; + this.monitor = monitor; } @Override @@ -70,7 +70,7 @@ public class StandardInitialisations extends AbstractInitialisations { loadInitialisations(field); } - // Public for test purpouse only + // Public for test purpose only public void loadInitialisations(Field field) { if (map.containsKey(field.getName())) { field.setInitialisation(map.get(field.getName())); @@ -80,81 +80,109 @@ public class StandardInitialisations extends AbstractInitialisations { if (isScalar) { ScalarInternalField internalField = (ScalarInternalField) field.getInternalField(); double value = internalField.getValue()[0][0]; - field.setInitialisation(DictionaryBuilder.newDictionary("initialisation").field(TYPE, "fixedValue").field(VALUE, String.valueOf(value)).done()); + FixedScalarInitialisation i = new FixedScalarInitialisation(); + i.setValue(value); + field.setInitialisation(i); } else if (isArray) { ArrayInternalField internalField = (ArrayInternalField) field.getInternalField(); - double valueX = internalField.getValue()[0][0]; - double valueY = internalField.getValue()[0][1]; - double valueZ = internalField.getValue()[0][2]; - String value = "(" + valueX + " " + valueY + " " + valueZ + ")"; - field.setInitialisation(DictionaryBuilder.newDictionary("initialisation").field(TYPE, "fixedValue").field(VALUE, value).done()); + FixedVectorInitialisation i = new FixedVectorInitialisation(); + i.setValue(internalField.getValue()[0]); + field.setInitialisation(i); } else { - field.setInitialisation(DictionaryBuilder.newDictionary("initialisation").field(TYPE, "default").done()); + field.setInitialisation(new DefaultInitialisation()); } } - logger.info("{} initialised to {}", field.getName(), field.getInitialisationType()); + logger.info("{} initialised to {}", field.getName(), field.getInitialisation()); } @Override public void readInitialisationFromFile(Field field) { + if (BoundaryConditions.isMomentum(field.getName())) { + readPotentialFlowInitialisation(field); + } if (field.getName().startsWith(Fields.ALPHA)) { - SetFieldsDict setFieldsDict = model.getProject().getSystemFolder().getSetFieldsDict(); - if (setFieldsDict != null && !setFieldsDict.isEmpty()) { - readInitialisationFromSetFieldsDict(setFieldsDict, field); - map.put(field.getName(), field.getInitialisation()); - } + readCellSetInitialisation(field); } } - private void readInitialisationFromSetFieldsDict(SetFieldsDict setFieldsDict, Field field) { - Dictionary convertedInitialisation = new SetFieldsDictConverter(field).convertForRead(setFieldsDict); - field.setInitialisation(convertedInitialisation); + private void readPotentialFlowInitialisation(Field field) { + FvSolution fvSolution = model.getProject().getSystemFolder().getFvSolution(); + if (fvSolution.found(POTENTIAL_FLOW_KEY)) { + PotentialFlowInitialisation pfInitialisation = new PotentialFlowInitialisation(); + Dictionary potentialFlowDict = fvSolution.subDict(POTENTIAL_FLOW_KEY); + if (potentialFlowDict.found(INITIALISE_UBCS_KEY)) { + pfInitialisation.setInitUBCS(potentialFlowDict.lookupBoolean(INITIALISE_UBCS_KEY)); + } + if (potentialFlowDict.found(N_NON_ORTHOGONAL_CORRECTORS_KEY)) { + pfInitialisation.setnNonOrthogonalCorrectors(potentialFlowDict.lookupInt(N_NON_ORTHOGONAL_CORRECTORS_KEY)); + } + field.setInitialisation(pfInitialisation); + map.put(field.getName(), pfInitialisation); + } + } + + private void readCellSetInitialisation(Field field) { + SetFieldsDict setFieldsDict = model.getProject().getSystemFolder().getSetFieldsDict(); + SetFieldsDictConverter converter = new SetFieldsDictConverter(setFieldsDict, field); + if (converter.isFieldCellSetInitialized()) { + Dictionary convertedDict = converter.readFromSetFieldsDict(); + + LoadSaveInitialisation loadSaveInitialisation = new LoadSaveInitialisation(model.getProject().getBaseDir(), model.getState(), monitor); + Initialisation i = loadSaveInitialisation.load(convertedDict, Fields.getFieldTypeByName(field.getName())); + field.setInitialisation(i); + map.put(field.getName(), i); + } } public void initializeFields() { for (Field field : model.getFields().values()) { initializeField(field); } - model.getProject().getZeroFolder().write(model, cellZonesBuilder, modules, this, new SilentMonitor()); } private void initializeField(Field field) { String fieldName = field.getName(); - String initMethod = field.getInitialisationType(); - logger.info("Inititalising field: {} as {}", fieldName, initMethod); + logger.info("Inititalising field: {} as {}", fieldName, field.getInitialisation()); - if (initMethod.equals("fixedValue")) { - initializeFixedValue(field); - } else if (initMethod.equals("default")) { - } else { - logger.warn("'{}': Invalid initialisation: set to 'default'", initMethod); - } + initializeFixedValue(field); } private void initializeFixedValue(Field field) { - String value = field.getInitialisation().lookup("value"); - if (value != null && value.startsWith("uniform")) { - field.setInternalField("internalField " + value); + Initialisation init = field.getInitialisation(); + InternalField internalField = null; + if (init instanceof FixedScalarInitialisation) { + double value = ((FixedScalarInitialisation) init).getValue(); + internalField = new ScalarInternalField(value); + } else if (init instanceof FixedVectorInitialisation) { + double[] value = ((FixedVectorInitialisation) init).getValue(); + internalField = new ArrayInternalField(value); + } + if (internalField != null) { + field.setInternalField(internalField); Fields[] parallelFields = model.getFields().getParallelFields(); if (parallelFields != null) { for (int i = 0; i < parallelFields.length; i++) { Field subField = parallelFields[i].get(field.getName()); - subField.setInternalField("internalField " + value); + subField.setInternalField(internalField); } } - } - if (field.getName().equals(Fields.P) || field.getName().equals(Fields.P_RGH)) { - writeValueOnProcBoundary(field); + if (field.getName().equals(Fields.P) || field.getName().equals(Fields.P_RGH)) { + writeValueOnProcBoundary(field); + } } } private void writeValueOnProcBoundary(Field field) { - for (Patch patch : model.getPatches()) { - if (patch.getPhisicalType().isProcessor()) { - Dictionary momentum = patch.getBoundaryConditions().getMomentum(); - if (momentum.found(Fields.P)) { - Dictionary p = momentum.subDict(Fields.P); - p.add(Dictionary.VALUE, field.getInitialisation().lookup("value")); + Initialisation init = field.getInitialisation(); + if (init instanceof FixedScalarInitialisation) { + double value = ((FixedScalarInitialisation) init).getValue(); + for (Patch patch : model.getPatches()) { + if (patch.getPhysicalType().isProcessor()) { + Dictionary momentum = patch.getBoundaryConditions().getMomentum(); + if (momentum.found(Fields.P)) { + Dictionary p = momentum.subDict(Fields.P); + p.addUniform(Dictionary.VALUE, value); + } } } } diff --git a/src/eu/engys/gui/casesetup/materials/AbstractIncompressibleMaterialsPanel.java b/src/eu/engys/gui/casesetup/materials/AbstractIncompressibleMaterialsPanel.java index 4d44303..ad68d8a 100644 --- a/src/eu/engys/gui/casesetup/materials/AbstractIncompressibleMaterialsPanel.java +++ b/src/eu/engys/gui/casesetup/materials/AbstractIncompressibleMaterialsPanel.java @@ -1,40 +1,33 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.casesetup.materials; -import static eu.engys.core.project.constant.TransportProperties.CP_KEY; -import static eu.engys.core.project.constant.TransportProperties.LAMBDA_KEY; -import static eu.engys.core.project.constant.TransportProperties.MATERIAL_NAME_KEY; import static eu.engys.core.project.constant.TransportProperties.MU_KEY; import static eu.engys.core.project.constant.TransportProperties.NU_KEY; -import static eu.engys.core.project.constant.TransportProperties.PRT_KEY; -import static eu.engys.core.project.constant.TransportProperties.P_REF_KEY; import static eu.engys.core.project.constant.TransportProperties.RHO_KEY; import static eu.engys.core.project.constant.TransportProperties.SIGMA_KEY; -import static eu.engys.core.project.constant.TransportProperties.T_REF_KEY; import static eu.engys.util.Symbols.CP; import static eu.engys.util.Symbols.DENSITY; import static eu.engys.util.Symbols.DOT; @@ -47,11 +40,12 @@ import java.beans.PropertyChangeListener; import eu.engys.core.dictionary.Dictionary; import eu.engys.core.dictionary.DimensionedScalar; -import eu.engys.core.dictionary.model.DictionaryModel; import eu.engys.core.modules.materials.MaterialsBuilder; import eu.engys.core.project.Model; +import eu.engys.core.project.materials.incompressible.IncompressibleMaterial; import eu.engys.core.project.state.State; import eu.engys.util.DimensionalUnits; +import eu.engys.util.bean.BeanModel; import eu.engys.util.ui.builder.PanelBuilder; import eu.engys.util.ui.textfields.DoubleField; import eu.engys.util.ui.textfields.StringField; @@ -68,8 +62,10 @@ public abstract class AbstractIncompressibleMaterialsPanel implements Incompress public static final String DENSITY_LABEL = "Density " + DENSITY; public static final String THERMAL_EXPANTION_COEFF_LABEL = "Thermal Expansion Coefficient [K" + MINUS_ONE + "]"; - protected DictionaryModel incompressibleModel = new DictionaryModel("newMaterial", getEmptyMaterial()); +// protected DictionaryModel incompressibleModel = new DictionaryModel("newMaterial", getEmptyMaterial()); + protected BeanModel materialModel = new BeanModel<>(new IncompressibleMaterial()); + private StringField nameField; private DoubleField rho; private DoubleField mu; @@ -82,9 +78,9 @@ public abstract class AbstractIncompressibleMaterialsPanel implements Incompress this.builder = new PanelBuilder(); } - public abstract Dictionary getMaterial(Model model); + public abstract IncompressibleMaterial getMaterial(Model model); - public abstract void setMaterial(Dictionary material); + public abstract void setMaterial(IncompressibleMaterial material); @Override public void setEnabled(boolean enabled) { @@ -101,24 +97,33 @@ public abstract class AbstractIncompressibleMaterialsPanel implements Incompress } protected void buildIncompressibleMaterialPanel() { - builder.addComponent("Name", nameField = incompressibleModel.bindLabel(MATERIAL_NAME_KEY)); - builder.addComponent(DENSITY_LABEL, rho = incompressibleModel.bindDimensionedDouble(RHO_KEY, DimensionalUnits.KG_M3, 0D, Double.MAX_VALUE)); - builder.addComponent(DYNAMIC_VISCOSITY_LABEL, mu = incompressibleModel.bindDimensionedDouble(MU_KEY, DimensionalUnits.KG_MS, 0D, Double.MAX_VALUE)); - builder.addComponent(KINEMATIC_VISCOSITY_LABEL, nu = incompressibleModel.bindDimensionedDouble(NU_KEY, DimensionalUnits.M2_S, 0D, Double.MAX_VALUE)); + builder.addComponent("Name", nameField = materialModel.bindLabel(IncompressibleMaterial.NAME_KEY)); + builder.addComponent(DENSITY_LABEL, rho = materialModel.bindDoublePositive(IncompressibleMaterial.RHO_KEY)); + builder.addComponent(DYNAMIC_VISCOSITY_LABEL, mu = materialModel.bindDoublePositive(IncompressibleMaterial.MU_KEY)); + builder.addComponent(KINEMATIC_VISCOSITY_LABEL, nu = materialModel.bindDoublePositive(IncompressibleMaterial.NU_KEY)); nameField.setEnabled(false); + addListeners(); + + builder.addComponent(SPECIFIC_HEAT_CAPACITY_LABEL, materialModel.bindDoublePositive(IncompressibleMaterial.CP_KEY)); + builder.addComponent(TURBULENT_PRANDTL_NUMBER_LABEL, materialModel.bindDoublePositive(IncompressibleMaterial.PRT_KEY)); + builder.addComponent(THERMAL_CONDUCTIVITY_LABEL, materialModel.bindDoublePositive(IncompressibleMaterial.LAMBDA_KEY)); + builder.addComponent(REFERENCE_ABSOLUTE_PRESSURE_PA_LABEL, materialModel.bindDoublePositive(IncompressibleMaterial.P_REF_KEY)); + builder.addComponent(REFERENCE_TEMPERATURE_K_LABEL, materialModel.bindDoublePositive(IncompressibleMaterial.T_REF_KEY)); + } + + protected void removeListeners() { + rho.removePropertyChangeListener("value", this); + mu.removePropertyChangeListener("value", this); + nu.removePropertyChangeListener("value", this); + } + protected void addListeners() { rho.addPropertyChangeListener("value", this); mu.addPropertyChangeListener("value", this); nu.addPropertyChangeListener("value", this); - - builder.addComponent(SPECIFIC_HEAT_CAPACITY_LABEL, incompressibleModel.bindDimensionedDouble(CP_KEY, DimensionalUnits.M2_S2K, 0D, Double.MAX_VALUE)); - builder.addComponent(TURBULENT_PRANDTL_NUMBER_LABEL, incompressibleModel.bindDimensionedDouble(PRT_KEY, DimensionalUnits.NONE, 0D, Double.MAX_VALUE)); - builder.addComponent(THERMAL_CONDUCTIVITY_LABEL, incompressibleModel.bindDimensionedDouble(LAMBDA_KEY, DimensionalUnits.KGM_S3K, 0D, Double.MAX_VALUE)); - builder.addComponent(REFERENCE_ABSOLUTE_PRESSURE_PA_LABEL, incompressibleModel.bindDimensionedDouble(P_REF_KEY, DimensionalUnits.KG_MS2, 0D, Double.MAX_VALUE)); - builder.addComponent(REFERENCE_TEMPERATURE_K_LABEL, incompressibleModel.bindDimensionedDouble(T_REF_KEY, DimensionalUnits.K, 0D, Double.MAX_VALUE)); } - + @Override public void propertyChange(PropertyChangeEvent evt) { if (evt.getSource() == nu) { diff --git a/src/eu/engys/gui/casesetup/materials/AbstractMaterialsBuilder.java b/src/eu/engys/gui/casesetup/materials/AbstractMaterialsBuilder.java index b6189e8..9011a5d 100644 --- a/src/eu/engys/gui/casesetup/materials/AbstractMaterialsBuilder.java +++ b/src/eu/engys/gui/casesetup/materials/AbstractMaterialsBuilder.java @@ -1,113 +1,96 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.casesetup.materials; -import static eu.engys.core.project.constant.ThermophysicalProperties.CP_KEY; -import static eu.engys.core.project.constant.ThermophysicalProperties.LAMBDA_KEY; -import static eu.engys.core.project.constant.ThermophysicalProperties.MATERIAL_NAME_KEY; -import static eu.engys.core.project.constant.ThermophysicalProperties.MU_KEY; -import static eu.engys.core.project.constant.ThermophysicalProperties.NU_KEY; -import static eu.engys.core.project.constant.ThermophysicalProperties.PRT_KEY; -import static eu.engys.core.project.constant.ThermophysicalProperties.PR_KEY; -import static eu.engys.core.project.constant.ThermophysicalProperties.P_REF_KEY; -import static eu.engys.core.project.constant.ThermophysicalProperties.RHO_KEY; -import static eu.engys.core.project.constant.ThermophysicalProperties.TRANSPORT_MODEL_KEY; -import static eu.engys.core.project.constant.ThermophysicalProperties.T_REF_KEY; -import eu.engys.core.dictionary.Dictionary; -import eu.engys.core.dictionary.DimensionedScalar; -import eu.engys.core.dictionary.DimensionedScalar.Dimensions; import eu.engys.core.modules.materials.MaterialsBuilder; -import eu.engys.core.project.Model; public abstract class AbstractMaterialsBuilder implements MaterialsBuilder { - @Override - public Dictionary saveIncompressible(Model model, Dictionary materialDict) { - String materialName = materialDict.lookup(MATERIAL_NAME_KEY); +// @Override +// public Dictionary saveIncompressible(Model model, Dictionary materialDict) { +// String materialName = materialDict.lookup(MATERIAL_NAME_KEY); +// +// Dictionary transportProperties = new Dictionary(materialName); +// transportProperties.add(MATERIAL_NAME_KEY, materialName); +// +// String transportModel = materialDict.lookup(TRANSPORT_MODEL_KEY); +// transportProperties.add(TRANSPORT_MODEL_KEY, transportModel); +// +// if (materialDict.found(transportModel + "Coeffs")) { +// transportProperties.add(materialDict.subDict(transportModel + "Coeffs")); +// } +// +// if (materialDict.found(RHO_KEY)) { +// transportProperties.add(materialDict.lookupScalar(RHO_KEY)); +// } +// +// if (materialDict.found(MU_KEY)) { +// transportProperties.add(materialDict.lookupScalar(MU_KEY)); +// } +// +// if (materialDict.found(NU_KEY)) { +// transportProperties.add(materialDict.lookupScalar(NU_KEY)); +// } else if (materialDict.found(RHO_KEY) && materialDict.found(MU_KEY)) { +// DimensionedScalar rho = materialDict.lookupScalar(RHO_KEY); +// DimensionedScalar mu = materialDict.lookupScalar(MU_KEY); +// +// double nuValue = mu.doubleValue() / rho.doubleValue(); +// Dimensions nuDimensions = mu.getDimensions().divide(rho.getDimensions()); +// +// DimensionedScalar nu = new DimensionedScalar(NU_KEY, Double.toString(nuValue), nuDimensions); +// +// transportProperties.add(nu); +// } +// +// if (materialDict.found(CP_KEY)) { +// transportProperties.add(materialDict.lookupScalar(CP_KEY)); +// } +// if (materialDict.found(PRT_KEY)) { +// transportProperties.add(materialDict.lookupScalar(PRT_KEY)); +// } +// if (materialDict.found(PR_KEY)) { +// transportProperties.add(materialDict.lookupScalar(PR_KEY)); +// } +// if (materialDict.found(LAMBDA_KEY)) { +// transportProperties.add(materialDict.lookupScalar(LAMBDA_KEY)); +// } +// +// if (materialDict.found(P_REF_KEY)) { +// transportProperties.add(materialDict.lookupScalar(P_REF_KEY)); +// } +// if (materialDict.found(getBetaKey())) { +// transportProperties.add(materialDict.lookupScalar(getBetaKey())); +// } +// if (materialDict.found(T_REF_KEY)) { +// transportProperties.add(materialDict.lookupScalar(T_REF_KEY)); +// } +// +// // System.out.println("MaterialsBuilder.saveIncompressible() "+transportProperties); +// +// return transportProperties; +// } - Dictionary transportProperties = new Dictionary(materialName); - transportProperties.add(MATERIAL_NAME_KEY, materialName); - - String transportModel = materialDict.lookup(TRANSPORT_MODEL_KEY); - transportProperties.add(TRANSPORT_MODEL_KEY, transportModel); - - if (materialDict.found(transportModel + "Coeffs")) { - transportProperties.add(materialDict.subDict(transportModel + "Coeffs")); - } - - if (materialDict.found(RHO_KEY)) { - transportProperties.add(materialDict.lookupScalar(RHO_KEY)); - } - - if (materialDict.found(MU_KEY)) { - transportProperties.add(materialDict.lookupScalar(MU_KEY)); - } - - if (materialDict.found(NU_KEY)) { - transportProperties.add(materialDict.lookupScalar(NU_KEY)); - } else if (materialDict.found(RHO_KEY) && materialDict.found(MU_KEY)) { - DimensionedScalar rho = materialDict.lookupScalar(RHO_KEY); - DimensionedScalar mu = materialDict.lookupScalar(MU_KEY); - - double nuValue = mu.doubleValue() / rho.doubleValue(); - Dimensions nuDimensions = mu.getDimensions().divide(rho.getDimensions()); - - DimensionedScalar nu = new DimensionedScalar(NU_KEY, Double.toString(nuValue), nuDimensions); - - transportProperties.add(nu); - } - - if (materialDict.found(CP_KEY)) { - transportProperties.add(materialDict.lookupScalar(CP_KEY)); - } - if (materialDict.found(PRT_KEY)) { - transportProperties.add(materialDict.lookupScalar(PRT_KEY)); - } - if (materialDict.found(PR_KEY)) { - transportProperties.add(materialDict.lookupScalar(PR_KEY)); - } - if (materialDict.found(LAMBDA_KEY)) { - transportProperties.add(materialDict.lookupScalar(LAMBDA_KEY)); - } - - if (materialDict.found(P_REF_KEY)) { - transportProperties.add(materialDict.lookupScalar(P_REF_KEY)); - } - if (materialDict.found(getBetaKey())) { - transportProperties.add(materialDict.lookupScalar(getBetaKey())); - } - if (materialDict.found(T_REF_KEY)) { - transportProperties.add(materialDict.lookupScalar(T_REF_KEY)); - } - - // System.out.println("MaterialsBuilder.saveIncompressible() "+transportProperties); - - return transportProperties; - } - - protected abstract String getBetaKey(); } diff --git a/src/eu/engys/gui/casesetup/materials/AbstractMaterialsReader.java b/src/eu/engys/gui/casesetup/materials/AbstractMaterialsReader.java index 5177e63..e6f6894 100644 --- a/src/eu/engys/gui/casesetup/materials/AbstractMaterialsReader.java +++ b/src/eu/engys/gui/casesetup/materials/AbstractMaterialsReader.java @@ -1,66 +1,396 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.casesetup.materials; -import static eu.engys.core.project.constant.TransportProperties.MATERIAL_NAME_KEY; +import static eu.engys.core.project.constant.ThermophysicalProperties.ADIABATIC_PERFECT_FLUID_KEY; +import static eu.engys.core.project.constant.ThermophysicalProperties.AS_KEY; +import static eu.engys.core.project.constant.ThermophysicalProperties.B_KEY; +import static eu.engys.core.project.constant.ThermophysicalProperties.CP_COEFFS_KEY; +import static eu.engys.core.project.constant.ThermophysicalProperties.EQUATION_CONSTANT_KEY; +import static eu.engys.core.project.constant.ThermophysicalProperties.EQUATION_OF_STATE_KEY; +import static eu.engys.core.project.constant.ThermophysicalProperties.EQUATION_POLYNOMIAL_KEY; +import static eu.engys.core.project.constant.ThermophysicalProperties.GAMMA_KEY; +import static eu.engys.core.project.constant.ThermophysicalProperties.HF_KEY; +import static eu.engys.core.project.constant.ThermophysicalProperties.HIGH_CP_COEFFS_KEY; +import static eu.engys.core.project.constant.ThermophysicalProperties.INCOMPRESSIBLE_KEY; +import static eu.engys.core.project.constant.ThermophysicalProperties.KAPPA_COEFFS_KEY; +import static eu.engys.core.project.constant.ThermophysicalProperties.LOW_CP_COEFFS_KEY; +import static eu.engys.core.project.constant.ThermophysicalProperties.MIXTURE_KEY; +import static eu.engys.core.project.constant.ThermophysicalProperties.MOL_WEIGHT_KEY; +import static eu.engys.core.project.constant.ThermophysicalProperties.MU_COEFFS_KEY; +import static eu.engys.core.project.constant.ThermophysicalProperties.N_MOLES_KEY; +import static eu.engys.core.project.constant.ThermophysicalProperties.PERFECT_FLUID_KEY; +import static eu.engys.core.project.constant.ThermophysicalProperties.PERFECT_GAS_KEY; +import static eu.engys.core.project.constant.ThermophysicalProperties.RHO0_KEY; +import static eu.engys.core.project.constant.ThermophysicalProperties.RHO_COEFFS_KEY; +import static eu.engys.core.project.constant.ThermophysicalProperties.R_KEY; +import static eu.engys.core.project.constant.ThermophysicalProperties.SF_KEY; +import static eu.engys.core.project.constant.ThermophysicalProperties.SPECIE_KEY; +import static eu.engys.core.project.constant.ThermophysicalProperties.TCOMMON_KEY; +import static eu.engys.core.project.constant.ThermophysicalProperties.THERMODYNAMICS_KEY; +import static eu.engys.core.project.constant.ThermophysicalProperties.THERMO_CONST_KEY; +import static eu.engys.core.project.constant.ThermophysicalProperties.THERMO_JANAF_KEY; +import static eu.engys.core.project.constant.ThermophysicalProperties.THERMO_KEY; +import static eu.engys.core.project.constant.ThermophysicalProperties.THERMO_POLYNOMIAL_KEY; +import static eu.engys.core.project.constant.ThermophysicalProperties.THERMO_TYPE_KEY; +import static eu.engys.core.project.constant.ThermophysicalProperties.THIGH_KEY; +import static eu.engys.core.project.constant.ThermophysicalProperties.TLOW_KEY; +import static eu.engys.core.project.constant.ThermophysicalProperties.TRANSPORT_CONST_KEY; +import static eu.engys.core.project.constant.ThermophysicalProperties.TRANSPORT_KEY; +import static eu.engys.core.project.constant.ThermophysicalProperties.TRANSPORT_POLYNOMIAL_KEY; +import static eu.engys.core.project.constant.ThermophysicalProperties.TRANSPORT_SUTHERLAND_KEY; +import static eu.engys.core.project.constant.ThermophysicalProperties.TS_KEY; +import static eu.engys.core.project.constant.TransportProperties.BIRD_CARREAU_KEY; +import static eu.engys.core.project.constant.TransportProperties.CROSS_POWER_LAW_KEY; +import static eu.engys.core.project.constant.TransportProperties.HERSCHEL_BULKLEY_KEY; +import static eu.engys.core.project.constant.TransportProperties.K_KEY; +import static eu.engys.core.project.constant.TransportProperties.M_KEY; +import static eu.engys.core.project.constant.TransportProperties.NEWTONIAN_KEY; +import static eu.engys.core.project.constant.TransportProperties.NU_0_KEY; +import static eu.engys.core.project.constant.TransportProperties.NU_INF_KEY; +import static eu.engys.core.project.constant.TransportProperties.NU_MAX_KEY; +import static eu.engys.core.project.constant.TransportProperties.NU_MIN_KEY; +import static eu.engys.core.project.constant.TransportProperties.N_KEY; +import static eu.engys.core.project.constant.TransportProperties.POWER_LAW_KEY; +import static eu.engys.core.project.constant.TransportProperties.TAU_0_KEY; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import eu.engys.core.dictionary.Dictionary; +import eu.engys.core.dictionary.StartWithFinder; import eu.engys.core.project.constant.ThermophysicalProperties; import eu.engys.core.project.constant.TransportProperties; -import eu.engys.core.project.materials.Material; -import eu.engys.core.project.materials.Materials; import eu.engys.core.project.materials.MaterialsReader; -import eu.engys.util.progress.ProgressMonitor; +import eu.engys.core.project.materials.compressible.AdiabaticPerfectFluid; +import eu.engys.core.project.materials.compressible.CompressibleMaterial; +import eu.engys.core.project.materials.compressible.ConstantDensity; +import eu.engys.core.project.materials.compressible.ConstantThermodynamicModel; +import eu.engys.core.project.materials.compressible.ConstantTransport; +import eu.engys.core.project.materials.compressible.EquationOfState; +import eu.engys.core.project.materials.compressible.IncompressiblePerfectGas; +import eu.engys.core.project.materials.compressible.JANAFThermodynamicModel; +import eu.engys.core.project.materials.compressible.PerfectFluid; +import eu.engys.core.project.materials.compressible.PerfectGas; +import eu.engys.core.project.materials.compressible.PolynomialEquation; +import eu.engys.core.project.materials.compressible.PolynomialThermodynamicModel; +import eu.engys.core.project.materials.compressible.PolynomialTransport; +import eu.engys.core.project.materials.compressible.SutherlandTransport; +import eu.engys.core.project.materials.compressible.ThermodynamicModel; +import eu.engys.core.project.materials.compressible.Transport; +import eu.engys.core.project.materials.incompressible.BirdCarreauTransportModel; +import eu.engys.core.project.materials.incompressible.CrossPowerLawTransportModel; +import eu.engys.core.project.materials.incompressible.HerschelBulkleyTransportModel; +import eu.engys.core.project.materials.incompressible.IncompressibleMaterial; +import eu.engys.core.project.materials.incompressible.NewtonianTransportModel; +import eu.engys.core.project.materials.incompressible.PowerLawTransportModel; +import eu.engys.core.project.materials.incompressible.TransportModel; public abstract class AbstractMaterialsReader implements MaterialsReader { - - @Override - public void readSingle_Material(Materials materials, TransportProperties tpp, ProgressMonitor monitor) { - readMaterial(materials, tpp, monitor); - } - @Override - public void readSingle_Material(Materials materials, ThermophysicalProperties tfp, ProgressMonitor monitor) { - readMaterial(materials, tfp, monitor); - } + public static final String COEFFS = "Coeffs"; - private void readMaterial(Materials materials, Dictionary tfp, ProgressMonitor monitor) { - Dictionary dict = new Dictionary(tfp); - dict.setFoamFile(null); - if (dict.isEmpty()) { - monitor.warning("No material found", 1); - return; - } else { - if (!dict.found(MATERIAL_NAME_KEY)) { - dict.add(MATERIAL_NAME_KEY, "material"); - } - String name = dict.lookup(MATERIAL_NAME_KEY); - dict.setName(name); - materials.add(new Material(name, dict)); - monitor.info(name, 1); - } - } + private static final Logger logger = LoggerFactory.getLogger(AbstractMaterialsReader.class); + + public static final String DEFAULT_MATERIAL_NAME = "material"; + + @Override + public IncompressibleMaterial readIncompressibleMaterial(Dictionary dictionary) { + Dictionary materialDict = readMaterialDict(dictionary); + IncompressibleMaterial im = new IncompressibleMaterial(materialDict.getName()); + + im.setRho(getAValue(materialDict, TransportProperties.RHO_KEY)); + im.setMu(getAValue(materialDict, TransportProperties.MU_KEY)); + im.setNu(getAValue(materialDict, TransportProperties.NU_KEY)); + if (im.getNu() == 0 && im.getRho() != 0) { + im.setNu(im.getMu() / im.getRho()); + } + im.setCp(getAValue(materialDict, TransportProperties.CP_KEY)); + im.setPrt(getAValue(materialDict, TransportProperties.PRT_KEY)); + im.setLambda(getAValue(materialDict, TransportProperties.LAMBDA_KEY)); + im.setpRef(getAValue(materialDict, TransportProperties.P_REF_KEY)); + im.settRef(getAValue(materialDict, TransportProperties.T_REF_KEY)); + im.setBeta(getAValue(materialDict, getBetaKey())); + im.setPr(getAValue(materialDict, TransportProperties.PR_KEY)); + + if (materialDict.found(TransportProperties.TRANSPORT_MODEL_KEY)) { + readTransportModel(im, materialDict); + } + + return im; + } + + void readTransportModel(IncompressibleMaterial im, Dictionary materialDict) { + String transport = materialDict.lookup(TransportProperties.TRANSPORT_MODEL_KEY); + TransportModel transportModel = getTransportModel(transport); + im.setTransportModel(transportModel); + + if (materialDict.isDictionary(transport + COEFFS)) { + Dictionary transportDict = materialDict.subDict(transport + COEFFS); + loadTransportModel(im, transportDict); + } + } + + private double getAValue(Dictionary materialDict, String key) { + if (materialDict.isScalar(key)) { + return materialDict.lookupScalar(key).doubleValue(); + } else if (materialDict.isField(key)) { + return materialDict.lookupDouble(key); + } else { + return 0; + } + } + + private TransportModel getTransportModel(String transport) { + switch (transport) { + case NEWTONIAN_KEY: + return new NewtonianTransportModel(); + case CROSS_POWER_LAW_KEY: + return new CrossPowerLawTransportModel(); + case BIRD_CARREAU_KEY: + return new BirdCarreauTransportModel(); + case HERSCHEL_BULKLEY_KEY: + return new HerschelBulkleyTransportModel(); + case POWER_LAW_KEY: + return new PowerLawTransportModel(); + default: + return new NewtonianTransportModel(); + } + } + + void loadTransportModel(IncompressibleMaterial im, Dictionary coeffsDict) { + TransportModel transportModel = im.getTransportModel(); + if (transportModel instanceof CrossPowerLawTransportModel) { + CrossPowerLawTransportModel cpl = (CrossPowerLawTransportModel) transportModel; + cpl.setNu0(coeffsDict.lookupScalar(NU_0_KEY).doubleValue()); + cpl.setNuInf(coeffsDict.lookupScalar(NU_INF_KEY).doubleValue()); + cpl.setM(coeffsDict.lookupScalar(M_KEY).doubleValue()); + cpl.setN(coeffsDict.lookupScalar(N_KEY).doubleValue()); + } else if (transportModel instanceof BirdCarreauTransportModel) { + BirdCarreauTransportModel bc = (BirdCarreauTransportModel) transportModel; + bc.setNu0(coeffsDict.lookupScalar(NU_0_KEY).doubleValue()); + bc.setNuInf(coeffsDict.lookupScalar(NU_INF_KEY).doubleValue()); + bc.setK(coeffsDict.lookupScalar(K_KEY).doubleValue()); + bc.setN(coeffsDict.lookupScalar(N_KEY).doubleValue()); + } else if (transportModel instanceof HerschelBulkleyTransportModel) { + HerschelBulkleyTransportModel hb = (HerschelBulkleyTransportModel) transportModel; + hb.setNu0(coeffsDict.lookupScalar(NU_0_KEY).doubleValue()); + hb.setTau0(coeffsDict.lookupScalar(TAU_0_KEY).doubleValue()); + hb.setK(coeffsDict.lookupScalar(K_KEY).doubleValue()); + hb.setN(coeffsDict.lookupScalar(N_KEY).doubleValue()); + } else if (transportModel instanceof PowerLawTransportModel) { + PowerLawTransportModel pl = (PowerLawTransportModel) transportModel; + pl.setNuMin(coeffsDict.lookupScalar(NU_MIN_KEY).doubleValue()); + pl.setNuMax(coeffsDict.lookupScalar(NU_MAX_KEY).doubleValue()); + pl.setK(coeffsDict.lookupScalar(K_KEY).doubleValue()); + pl.setN(coeffsDict.lookupScalar(N_KEY).doubleValue()); + } + } + + public abstract String getBetaKey(); + + Dictionary readMaterialDict(Dictionary d) { + Dictionary dict = new Dictionary(d); + dict.setFoamFile(null); + String name = DEFAULT_MATERIAL_NAME; + + if (dict.isEmpty()) { + logger.warn("No material found"); + } else { + if (!dict.found(TransportProperties.MATERIAL_NAME_KEY)) { + dict.add(TransportProperties.MATERIAL_NAME_KEY, DEFAULT_MATERIAL_NAME); + } + name = dict.lookup(TransportProperties.MATERIAL_NAME_KEY); + } + dict.setName(name); + return dict; + } + + @Override + public CompressibleMaterial readCompressibleMaterial(Dictionary dictionary) { + Dictionary materialDict = readMaterialDict(dictionary); + CompressibleMaterial cm = new CompressibleMaterial(materialDict.getName()); + + if (dictionary.found(THERMO_TYPE_KEY)) { + Dictionary thermoType = dictionary.subDict(THERMO_TYPE_KEY); + readThermoDict(cm, thermoType); + } + + if (dictionary.found(MIXTURE_KEY)) { + Dictionary mixture = dictionary.subDict(MIXTURE_KEY); + readMixtureDict(cm, mixture); + } + return cm; + } + + void readThermoDict(CompressibleMaterial cm, Dictionary thermoType) { + if (thermoType.found(TRANSPORT_KEY)) { + String transport = thermoType.lookup(TRANSPORT_KEY); + cm.setTransport(getTransport(transport)); + } + if (thermoType.found(THERMO_KEY)) { + String thermo = thermoType.lookup(THERMO_KEY); + cm.setThermodynamicModel(getThermo(thermo)); + } + if (thermoType.found(EQUATION_OF_STATE_KEY)) { + String equation = thermoType.lookup(EQUATION_OF_STATE_KEY); + cm.setEqOfState(getEquation(equation)); + } + } + + private Transport getTransport(String transport) { + switch (transport) { + case TRANSPORT_CONST_KEY: + return new ConstantTransport(); + case TRANSPORT_SUTHERLAND_KEY: + return new SutherlandTransport(); + case TRANSPORT_POLYNOMIAL_KEY: + return new PolynomialTransport(); + default: + return new ConstantTransport(); + } + } + + private ThermodynamicModel getThermo(String thermo) { + switch (thermo) { + case THERMO_CONST_KEY: + return new ConstantThermodynamicModel(); + case THERMO_JANAF_KEY: + return new JANAFThermodynamicModel(); + case THERMO_POLYNOMIAL_KEY: + return new PolynomialThermodynamicModel(); + default: + return new ConstantThermodynamicModel(); + } + } + + private EquationOfState getEquation(String equation) { + switch (equation) { + case ADIABATIC_PERFECT_FLUID_KEY: + return new AdiabaticPerfectFluid(); + case EQUATION_CONSTANT_KEY: + return new ConstantDensity(); + case PERFECT_GAS_KEY: + return new PerfectGas(); + case PERFECT_FLUID_KEY: + return new PerfectFluid(); + case INCOMPRESSIBLE_KEY: + return new IncompressiblePerfectGas(); + case EQUATION_POLYNOMIAL_KEY: + return new PolynomialEquation(); + default: + return new PerfectGas(); + } + } + + void readMixtureDict(CompressibleMaterial cm, Dictionary mixture) { + if(mixture.found(SPECIE_KEY)){ + Dictionary specieDict = mixture.subDict(SPECIE_KEY); + loadSpecie(cm, specieDict); + } + if(mixture.found(THERMODYNAMICS_KEY)){ + Dictionary thermoDict = mixture.subDict(THERMODYNAMICS_KEY); + loadThermo(cm, thermoDict); + } + if(mixture.found(TRANSPORT_KEY)){ + Dictionary transportDict = mixture.subDict(TRANSPORT_KEY); + loadTransport(cm, transportDict); + } + if(mixture.found(EQUATION_OF_STATE_KEY)){ + Dictionary equationDict = mixture.subDict(EQUATION_OF_STATE_KEY); + loadEquationOfState(cm, equationDict); + } + } + + private void loadSpecie(CompressibleMaterial cm, Dictionary specieDict) { + cm.setnMoles(specieDict.lookupInt(N_MOLES_KEY)); + cm.setMolWeight(specieDict.lookupDouble(MOL_WEIGHT_KEY)); + } + + private void loadThermo(CompressibleMaterial cm, Dictionary thermoDict) { + ThermodynamicModel thermo = cm.getThermodynamicModel(); + if (thermo instanceof ConstantThermodynamicModel) { + ConstantThermodynamicModel ctm = (ConstantThermodynamicModel) thermo; + ctm.setCp(thermoDict.lookupDouble(ThermophysicalProperties.CP_KEY)); + ctm.setHf(thermoDict.lookupDouble(HF_KEY)); + } else if (thermo instanceof JANAFThermodynamicModel) { + JANAFThermodynamicModel jtm = (JANAFThermodynamicModel) thermo; + jtm.settLow(thermoDict.lookupDouble(TLOW_KEY)); + jtm.settHigh(thermoDict.lookupDouble(THIGH_KEY)); + jtm.settCommon(thermoDict.lookupDouble(TCOMMON_KEY)); + jtm.setLowCpCoefficients(thermoDict.lookupDoubleArray(new StartWithFinder(LOW_CP_COEFFS_KEY))); + jtm.setHighCpCoefficients(thermoDict.lookupDoubleArray(new StartWithFinder(HIGH_CP_COEFFS_KEY))); + } else if (thermo instanceof PolynomialThermodynamicModel) { + PolynomialThermodynamicModel ptm = (PolynomialThermodynamicModel) thermo; + ptm.setHf(thermoDict.lookupDouble(HF_KEY)); + ptm.setSf(thermoDict.lookupDouble(SF_KEY)); + ptm.setCpCoefficients(thermoDict.lookupDoubleArray(new StartWithFinder(CP_COEFFS_KEY))); + } + } + + private void loadTransport(CompressibleMaterial cm, Dictionary transportDict) { + Transport transport = cm.getTransport(); + if (transport instanceof ConstantTransport) { + ConstantTransport ct = (ConstantTransport) transport; + ct.setMu(transportDict.lookupDouble(ThermophysicalProperties.MU_KEY)); + ct.setPr(transportDict.lookupDouble(ThermophysicalProperties.PR_KEY)); + } else if (transport instanceof SutherlandTransport) { + SutherlandTransport st = (SutherlandTransport) transport; + st.setAs(transportDict.lookupDouble(AS_KEY)); + st.setTs(transportDict.lookupDouble(TS_KEY)); + } else if (transport instanceof PolynomialTransport) { + PolynomialTransport pt = (PolynomialTransport) transport; + pt.setMuCoefficients(transportDict.lookupDoubleArray(new StartWithFinder(MU_COEFFS_KEY))); + pt.setKappaCoefficients(transportDict.lookupDoubleArray(new StartWithFinder(KAPPA_COEFFS_KEY))); + } + } + + private void loadEquationOfState(CompressibleMaterial cm, Dictionary equationDict) { + EquationOfState equation = cm.getEqOfState(); + if (equation instanceof AdiabaticPerfectFluid) { + AdiabaticPerfectFluid apf = (AdiabaticPerfectFluid) equation; + apf.setRho0(equationDict.lookupDouble(RHO0_KEY)); + apf.setB(equationDict.lookupDouble(B_KEY)); + apf.setP0(equationDict.lookupDouble(ThermophysicalProperties.P0_KEY)); + apf.setGamma(equationDict.lookupDouble(GAMMA_KEY)); + } else if (equation instanceof ConstantDensity) { + ConstantDensity cd = (ConstantDensity) equation; + cd.setRho(equationDict.lookupDouble(ThermophysicalProperties.RHO_KEY)); + } else if (equation instanceof PerfectGas) { +// PerfectGas pg = (PerfectGas) equation; + } else if (equation instanceof PerfectFluid) { + PerfectFluid pf = (PerfectFluid) equation; + pf.setRho0(equationDict.lookupDouble(RHO0_KEY)); + pf.setR(equationDict.lookupDouble(R_KEY)); + } else if (equation instanceof IncompressiblePerfectGas) { + IncompressiblePerfectGas ipg = (IncompressiblePerfectGas) equation; + ipg.setpRef(equationDict.lookupDouble(ThermophysicalProperties.P_REF_KEY)); + } else if (equation instanceof PolynomialEquation) { + PolynomialEquation pe = (PolynomialEquation) equation; + pe.setRhoCoefficients(equationDict.lookupDoubleArray(new StartWithFinder(RHO_COEFFS_KEY))); + } + } } diff --git a/src/eu/engys/gui/casesetup/materials/AbstractMaterialsWriter.java b/src/eu/engys/gui/casesetup/materials/AbstractMaterialsWriter.java index e816c10..f6c32e9 100644 --- a/src/eu/engys/gui/casesetup/materials/AbstractMaterialsWriter.java +++ b/src/eu/engys/gui/casesetup/materials/AbstractMaterialsWriter.java @@ -1,58 +1,365 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.casesetup.materials; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import static eu.engys.core.project.constant.ThermophysicalProperties.ADIABATIC_PERFECT_FLUID_KEY; +import static eu.engys.core.project.constant.ThermophysicalProperties.AS_KEY; +import static eu.engys.core.project.constant.ThermophysicalProperties.B_KEY; +import static eu.engys.core.project.constant.ThermophysicalProperties.COEFFICIENTS_NUMBER; +import static eu.engys.core.project.constant.ThermophysicalProperties.CP_COEFFS_KEY; +import static eu.engys.core.project.constant.ThermophysicalProperties.ENERGY_KEY; +import static eu.engys.core.project.constant.ThermophysicalProperties.EQUATION_CONSTANT_KEY; +import static eu.engys.core.project.constant.ThermophysicalProperties.EQUATION_OF_STATE_KEY; +import static eu.engys.core.project.constant.ThermophysicalProperties.EQUATION_POLYNOMIAL_KEY; +import static eu.engys.core.project.constant.ThermophysicalProperties.GAMMA_KEY; +import static eu.engys.core.project.constant.ThermophysicalProperties.HE_PSI_THERMO_KEY; +import static eu.engys.core.project.constant.ThermophysicalProperties.HE_RHO_THERMO_KEY; +import static eu.engys.core.project.constant.ThermophysicalProperties.HF_KEY; +import static eu.engys.core.project.constant.ThermophysicalProperties.HIGH_CP_COEFFS_KEY; +import static eu.engys.core.project.constant.ThermophysicalProperties.INCOMPRESSIBLE_KEY; +import static eu.engys.core.project.constant.ThermophysicalProperties.KAPPA_COEFFS_KEY; +import static eu.engys.core.project.constant.ThermophysicalProperties.LOW_CP_COEFFS_KEY; +import static eu.engys.core.project.constant.ThermophysicalProperties.MIXTURE_KEY; +import static eu.engys.core.project.constant.ThermophysicalProperties.MOL_WEIGHT_KEY; +import static eu.engys.core.project.constant.ThermophysicalProperties.MU_COEFFS_KEY; +import static eu.engys.core.project.constant.ThermophysicalProperties.N_MOLES_KEY; +import static eu.engys.core.project.constant.ThermophysicalProperties.PERFECT_FLUID_KEY; +import static eu.engys.core.project.constant.ThermophysicalProperties.PERFECT_GAS_KEY; +import static eu.engys.core.project.constant.ThermophysicalProperties.PURE_MIXTURE_KEY; +import static eu.engys.core.project.constant.ThermophysicalProperties.RHO0_KEY; +import static eu.engys.core.project.constant.ThermophysicalProperties.RHO_COEFFS_KEY; +import static eu.engys.core.project.constant.ThermophysicalProperties.R_KEY; +import static eu.engys.core.project.constant.ThermophysicalProperties.SENSIBLE_ENTHALPY_KEY; +import static eu.engys.core.project.constant.ThermophysicalProperties.SENSIBLE_INTERNAL_ENERGY_KEY; +import static eu.engys.core.project.constant.ThermophysicalProperties.SF_KEY; +import static eu.engys.core.project.constant.ThermophysicalProperties.SPECIE_KEY; +import static eu.engys.core.project.constant.ThermophysicalProperties.TCOMMON_KEY; +import static eu.engys.core.project.constant.ThermophysicalProperties.THERMODYNAMICS_KEY; +import static eu.engys.core.project.constant.ThermophysicalProperties.THERMO_CONST_KEY; +import static eu.engys.core.project.constant.ThermophysicalProperties.THERMO_JANAF_KEY; +import static eu.engys.core.project.constant.ThermophysicalProperties.THERMO_KEY; +import static eu.engys.core.project.constant.ThermophysicalProperties.THERMO_POLYNOMIAL_KEY; +import static eu.engys.core.project.constant.ThermophysicalProperties.THERMO_TYPE_KEY; +import static eu.engys.core.project.constant.ThermophysicalProperties.THIGH_KEY; +import static eu.engys.core.project.constant.ThermophysicalProperties.TLOW_KEY; +import static eu.engys.core.project.constant.ThermophysicalProperties.TRANSPORT_CONST_KEY; +import static eu.engys.core.project.constant.ThermophysicalProperties.TRANSPORT_KEY; +import static eu.engys.core.project.constant.ThermophysicalProperties.TRANSPORT_POLYNOMIAL_KEY; +import static eu.engys.core.project.constant.ThermophysicalProperties.TRANSPORT_SUTHERLAND_KEY; +import static eu.engys.core.project.constant.ThermophysicalProperties.TS_KEY; +import static eu.engys.core.project.constant.TransportProperties.BIRD_CARREAU_KEY; +import static eu.engys.core.project.constant.TransportProperties.CROSS_POWER_LAW_KEY; +import static eu.engys.core.project.constant.TransportProperties.HERSCHEL_BULKLEY_KEY; +import static eu.engys.core.project.constant.TransportProperties.K_KEY; +import static eu.engys.core.project.constant.TransportProperties.M_KEY; +import static eu.engys.core.project.constant.TransportProperties.NEWTONIAN_KEY; +import static eu.engys.core.project.constant.TransportProperties.NU_0_KEY; +import static eu.engys.core.project.constant.TransportProperties.NU_INF_KEY; +import static eu.engys.core.project.constant.TransportProperties.NU_MAX_KEY; +import static eu.engys.core.project.constant.TransportProperties.NU_MIN_KEY; +import static eu.engys.core.project.constant.TransportProperties.N_KEY; +import static eu.engys.core.project.constant.TransportProperties.POWER_LAW_KEY; +import static eu.engys.core.project.constant.TransportProperties.TAU_0_KEY; +import static java.lang.String.valueOf; +import eu.engys.core.dictionary.Dictionary; +import eu.engys.core.dictionary.DimensionedScalar; +import eu.engys.core.project.Model; import eu.engys.core.project.constant.ThermophysicalProperties; import eu.engys.core.project.constant.TransportProperties; -import eu.engys.core.project.materials.Materials; +import eu.engys.core.project.materials.Material; import eu.engys.core.project.materials.MaterialsWriter; +import eu.engys.core.project.materials.compressible.AdiabaticPerfectFluid; +import eu.engys.core.project.materials.compressible.CompressibleMaterial; +import eu.engys.core.project.materials.compressible.ConstantDensity; +import eu.engys.core.project.materials.compressible.ConstantThermodynamicModel; +import eu.engys.core.project.materials.compressible.ConstantTransport; +import eu.engys.core.project.materials.compressible.EquationOfState; +import eu.engys.core.project.materials.compressible.IncompressiblePerfectGas; +import eu.engys.core.project.materials.compressible.JANAFThermodynamicModel; +import eu.engys.core.project.materials.compressible.PerfectFluid; +import eu.engys.core.project.materials.compressible.PerfectGas; +import eu.engys.core.project.materials.compressible.PolynomialEquation; +import eu.engys.core.project.materials.compressible.PolynomialThermodynamicModel; +import eu.engys.core.project.materials.compressible.PolynomialTransport; +import eu.engys.core.project.materials.compressible.SutherlandTransport; +import eu.engys.core.project.materials.compressible.ThermodynamicModel; +import eu.engys.core.project.materials.compressible.Transport; +import eu.engys.core.project.materials.incompressible.BirdCarreauTransportModel; +import eu.engys.core.project.materials.incompressible.CrossPowerLawTransportModel; +import eu.engys.core.project.materials.incompressible.HerschelBulkleyTransportModel; +import eu.engys.core.project.materials.incompressible.IncompressibleMaterial; +import eu.engys.core.project.materials.incompressible.NewtonianTransportModel; +import eu.engys.core.project.materials.incompressible.PowerLawTransportModel; +import eu.engys.core.project.materials.incompressible.TransportModel; +import eu.engys.util.DimensionalUnits; public abstract class AbstractMaterialsWriter implements MaterialsWriter { + + private Model model; - private static final Logger logger = LoggerFactory.getLogger(AbstractMaterialsWriter.class); + public AbstractMaterialsWriter(Model model) { + this.model = model; + } - @Override - public void writeSingle_IncompressibleMaterial(Materials materials, TransportProperties tpp) { - if (materials.size() == 1) { - tpp.merge(materials.get(0).getDictionary()); - } else { - logger.warn("Multiphase solution choosen but '{}' materials found", materials.size()); - } + @Override + public Dictionary writeSingle_IncompressibleMaterial(Material m) { + Dictionary d = new Dictionary(m.getName()); + d.add(TransportProperties.MATERIAL_NAME_KEY, m.getName()); + + if (m instanceof IncompressibleMaterial) { + IncompressibleMaterial im = (IncompressibleMaterial) m; + + TransportModel transport = im.getTransportModel(); + String transportKey = getTransportModelKey(transport); + d.add(TransportProperties.TRANSPORT_MODEL_KEY, transportKey); + + Dictionary coeffs = new Dictionary(transportKey + "Coeffs"); + d.add(coeffs); + + switch (transportKey) { + case NEWTONIAN_KEY: + break; + case CROSS_POWER_LAW_KEY: + CrossPowerLawTransportModel cpl = (CrossPowerLawTransportModel) transport; + coeffs.add(new DimensionedScalar(NU_0_KEY, valueOf(cpl.getNu0()), DimensionalUnits.M2_S)); + coeffs.add(new DimensionedScalar(NU_INF_KEY, valueOf(cpl.getNuInf()), DimensionalUnits.M2_S)); + coeffs.add(new DimensionedScalar(M_KEY, valueOf(cpl.getM()), DimensionalUnits.S)); + coeffs.add(new DimensionedScalar(N_KEY, valueOf(cpl.getN()), DimensionalUnits.NONE)); + break; + case BIRD_CARREAU_KEY: + BirdCarreauTransportModel bc = (BirdCarreauTransportModel) transport; + coeffs.add(new DimensionedScalar(NU_0_KEY, valueOf(bc.getNu0()), DimensionalUnits.M2_S)); + coeffs.add(new DimensionedScalar(NU_INF_KEY, valueOf(bc.getNuInf()), DimensionalUnits.M2_S)); + coeffs.add(new DimensionedScalar(K_KEY, valueOf(bc.getK()), DimensionalUnits.S)); + coeffs.add(new DimensionedScalar(N_KEY, valueOf(bc.getN()), DimensionalUnits.NONE)); + break; + case HERSCHEL_BULKLEY_KEY: + HerschelBulkleyTransportModel hb = (HerschelBulkleyTransportModel) transport; + coeffs.add(new DimensionedScalar(NU_0_KEY, valueOf(hb.getNu0()), DimensionalUnits.M2_S)); + coeffs.add(new DimensionedScalar(TAU_0_KEY, valueOf(hb.getTau0()), DimensionalUnits.M2_S2)); + coeffs.add(new DimensionedScalar(K_KEY, valueOf(hb.getK()), DimensionalUnits.M2_S)); + coeffs.add(new DimensionedScalar(N_KEY, valueOf(hb.getN()), DimensionalUnits.NONE)); + break; + case POWER_LAW_KEY: + PowerLawTransportModel pl = (PowerLawTransportModel) transport; + coeffs.add(new DimensionedScalar(NU_MIN_KEY, valueOf(pl.getNuMin()), DimensionalUnits.M2_S)); + coeffs.add(new DimensionedScalar(NU_MAX_KEY, valueOf(pl.getNuMax()), DimensionalUnits.M2_S)); + coeffs.add(new DimensionedScalar(K_KEY, valueOf(pl.getK()), DimensionalUnits.M2_S)); + coeffs.add(new DimensionedScalar(N_KEY, valueOf(pl.getN()), DimensionalUnits.NONE)); + break; + default: + break; + } + + d.add(new DimensionedScalar(TransportProperties.RHO_KEY, valueOf(im.getRho()), DimensionalUnits.KG_M3)); + d.add(new DimensionedScalar(TransportProperties.MU_KEY, valueOf(im.getMu()), DimensionalUnits.KG_MS)); + + if (im.getNu() != 0 && !Double.isNaN(im.getNu())) { + double nuValue = im.getMu() / im.getRho(); + d.add(new DimensionedScalar(TransportProperties.NU_KEY, valueOf(nuValue), DimensionalUnits.M2_S)); + } else { + d.add(new DimensionedScalar(TransportProperties.NU_KEY, valueOf(im.getNu()), DimensionalUnits.M2_S)); + } + + + d.add(new DimensionedScalar(TransportProperties.CP_KEY, valueOf(im.getCp()), DimensionalUnits.M2_S2K)); + d.add(new DimensionedScalar(TransportProperties.PRT_KEY, valueOf(im.getPrt()), DimensionalUnits.NONE)); + d.add(new DimensionedScalar(TransportProperties.LAMBDA_KEY, valueOf(im.getLambda()), DimensionalUnits.KGM_S3K)); + d.add(new DimensionedScalar(TransportProperties.P_REF_KEY, valueOf(im.getpRef()), DimensionalUnits.KG_MS2)); + d.add(new DimensionedScalar(TransportProperties.T_REF_KEY, valueOf(im.gettRef()), DimensionalUnits.K)); + d.add(new DimensionedScalar(getBetaKey(), valueOf(im.getBeta()), DimensionalUnits._K)); + d.add(new DimensionedScalar(TransportProperties.PR_KEY, valueOf(im.getPr()), DimensionalUnits.NONE)); + } + return d; } - @Override - public void writeSingle_CompressibleMaterial(Materials materials, ThermophysicalProperties tfp) { - if (materials.size() == 1) { - tfp.merge(materials.get(0).getDictionary()); - } else { - logger.warn("Multiphase solution choosen but '{}' materials found", materials.size()); - } + protected abstract String getBetaKey(); + + private String getTransportModelKey(TransportModel transport) { + if (transport instanceof NewtonianTransportModel) { + return NEWTONIAN_KEY; + } else if (transport instanceof CrossPowerLawTransportModel) { + return CROSS_POWER_LAW_KEY; + } else if (transport instanceof BirdCarreauTransportModel) { + return BIRD_CARREAU_KEY; + } else if (transport instanceof HerschelBulkleyTransportModel) { + return HERSCHEL_BULKLEY_KEY; + } else if (transport instanceof PowerLawTransportModel) { + return POWER_LAW_KEY; + } + return ""; + } + + @Override + public Dictionary writeSingle_CompressibleMaterial(Material m) { + Dictionary d = new Dictionary(m.getName()); + if (m instanceof CompressibleMaterial) { + CompressibleMaterial cm = (CompressibleMaterial) m; + d.add(ThermophysicalProperties.MATERIAL_NAME_KEY, cm.getName()); + d.add(saveThermoDict(cm)); + d.add(saveMixtureDict(cm)); + } + return d; } + private Dictionary saveThermoDict(CompressibleMaterial cm) { + String type = model != null ? (model.getState().isBuoyant() ? HE_RHO_THERMO_KEY : HE_PSI_THERMO_KEY) : HE_PSI_THERMO_KEY; + String energy = model != null && model.getState().isHighMach() && model.getState().getSolverFamily().isPimple() ? SENSIBLE_INTERNAL_ENERGY_KEY : SENSIBLE_ENTHALPY_KEY; + + Dictionary thermoDict = new Dictionary(THERMO_TYPE_KEY); + thermoDict.add(Dictionary.TYPE, type); + thermoDict.add(MIXTURE_KEY, PURE_MIXTURE_KEY); + thermoDict.add(TRANSPORT_KEY, getTransportKey(cm.getTransport())); + thermoDict.add(THERMO_KEY, getThermoKey(cm.getThermodynamicModel())); + thermoDict.add(EQUATION_OF_STATE_KEY, getEquationKey(cm.getEqOfState())); + thermoDict.add(SPECIE_KEY, SPECIE_KEY); + thermoDict.add(ENERGY_KEY, energy); + return thermoDict; + } + + private String getEquationKey(EquationOfState equation) { + if (equation instanceof AdiabaticPerfectFluid) { + return ADIABATIC_PERFECT_FLUID_KEY; + } else if (equation instanceof ConstantDensity) { + return EQUATION_CONSTANT_KEY; + } else if (equation instanceof PerfectGas) { + return PERFECT_GAS_KEY; + } else if (equation instanceof PerfectFluid) { + return PERFECT_FLUID_KEY; + } else if (equation instanceof IncompressiblePerfectGas) { + return INCOMPRESSIBLE_KEY; + } else if (equation instanceof PolynomialEquation) { + return EQUATION_POLYNOMIAL_KEY; + } + return ""; + } + + private String getThermoKey(ThermodynamicModel thermo) { + if (thermo instanceof ConstantThermodynamicModel) { + return THERMO_CONST_KEY; + } else if (thermo instanceof JANAFThermodynamicModel) { + return THERMO_JANAF_KEY; + } else if (thermo instanceof PolynomialThermodynamicModel) { + return THERMO_POLYNOMIAL_KEY; + } + return ""; + } + + private String getTransportKey(Transport transport) { + if (transport instanceof ConstantTransport) { + return TRANSPORT_CONST_KEY; + } else if (transport instanceof SutherlandTransport) { + return TRANSPORT_SUTHERLAND_KEY; + } else if (transport instanceof PolynomialTransport) { + return TRANSPORT_POLYNOMIAL_KEY; + } + return ""; + } + + private Dictionary saveMixtureDict(CompressibleMaterial cm) { + Dictionary mixtureDict = new Dictionary(MIXTURE_KEY); + mixtureDict.add(saveSpecieDict(cm)); + mixtureDict.add(saveThermodynamicsDict(cm.getThermodynamicModel())); + mixtureDict.add(saveTransportPropertiesDict(cm.getTransport())); + mixtureDict.add(saveEquationOfStateDict(cm.getEqOfState())); + + return mixtureDict; + } + + private Dictionary saveSpecieDict(CompressibleMaterial material) { + Dictionary specieDict = new Dictionary(SPECIE_KEY); + specieDict.add(N_MOLES_KEY, material.getnMoles()); + specieDict.add(MOL_WEIGHT_KEY, material.getMolWeight()); + return specieDict; + } + + private Dictionary saveThermodynamicsDict(ThermodynamicModel thermo) { + Dictionary thermodynamicsDict = new Dictionary(THERMODYNAMICS_KEY); + if (thermo instanceof ConstantThermodynamicModel) { + ConstantThermodynamicModel ctm = (ConstantThermodynamicModel) thermo; + thermodynamicsDict.add(ThermophysicalProperties.CP_KEY, ctm.getCp()); + thermodynamicsDict.add(HF_KEY, ctm.getHf()); + } else if (thermo instanceof JANAFThermodynamicModel) { + JANAFThermodynamicModel jtm = (JANAFThermodynamicModel) thermo; + thermodynamicsDict.add(TLOW_KEY, jtm.gettLow()); + thermodynamicsDict.add(THIGH_KEY, jtm.gettHigh()); + thermodynamicsDict.add(TCOMMON_KEY, jtm.gettCommon()); + thermodynamicsDict.add(HIGH_CP_COEFFS_KEY, jtm.getHighCpCoefficients()); + thermodynamicsDict.add(LOW_CP_COEFFS_KEY, jtm.getLowCpCoefficients()); + } else if (thermo instanceof PolynomialThermodynamicModel) { + PolynomialThermodynamicModel ptm = (PolynomialThermodynamicModel) thermo; + thermodynamicsDict.add(HF_KEY, ptm.getHf()); + thermodynamicsDict.add(SF_KEY, ptm.getSf()); + thermodynamicsDict.add(CP_COEFFS_KEY + "<" + COEFFICIENTS_NUMBER + ">", ptm.getCpCoefficients()); + } + return thermodynamicsDict; + } + + private Dictionary saveTransportPropertiesDict(Transport transport) { + Dictionary transportDict = new Dictionary(TRANSPORT_KEY); + if (transport instanceof ConstantTransport) { + ConstantTransport ct = (ConstantTransport) transport; + transportDict.add(ThermophysicalProperties.MU_KEY, ct.getMu()); + transportDict.add(ThermophysicalProperties.PR_KEY, ct.getPr()); + } else if (transport instanceof SutherlandTransport) { + SutherlandTransport st = (SutherlandTransport) transport; + transportDict.add(AS_KEY, st.getAs()); + transportDict.add(TS_KEY, st.getTs()); + } else if (transport instanceof PolynomialTransport) { + PolynomialTransport pt = (PolynomialTransport) transport; + transportDict.add(MU_COEFFS_KEY + "<" + COEFFICIENTS_NUMBER + ">", pt.getMuCoefficients()); + transportDict.add(KAPPA_COEFFS_KEY + "<" + COEFFICIENTS_NUMBER + ">", pt.getKappaCoefficients()); + } + return transportDict; + } + + private Dictionary saveEquationOfStateDict(EquationOfState equation) { + Dictionary equationOfStateDict = new Dictionary(EQUATION_OF_STATE_KEY); + if (equation instanceof AdiabaticPerfectFluid) { + AdiabaticPerfectFluid apf = (AdiabaticPerfectFluid) equation; + equationOfStateDict.add(RHO0_KEY, apf.getRho0()); + equationOfStateDict.add(B_KEY, apf.getB()); + equationOfStateDict.add(ThermophysicalProperties.P0_KEY, apf.getP0()); + equationOfStateDict.add(GAMMA_KEY, apf.getGamma()); + } else if (equation instanceof ConstantDensity) { + ConstantDensity cd = (ConstantDensity) equation; + equationOfStateDict.add(ThermophysicalProperties.RHO_KEY, cd.getRho()); + } else if (equation instanceof PerfectGas) { +// PerfectGas pg = (PerfectGas) equation; + } else if (equation instanceof PerfectFluid) { + PerfectFluid pf = (PerfectFluid) equation; + equationOfStateDict.add(RHO0_KEY, pf.getRho0()); + equationOfStateDict.add(R_KEY, pf.getR()); + } else if (equation instanceof IncompressiblePerfectGas) { + IncompressiblePerfectGas ipg = (IncompressiblePerfectGas) equation; + equationOfStateDict.add(ThermophysicalProperties.P_REF_KEY, ipg.getpRef()); + } else if (equation instanceof PolynomialEquation) { + PolynomialEquation pe = (PolynomialEquation) equation; + equationOfStateDict.add(RHO_COEFFS_KEY + "<" + COEFFICIENTS_NUMBER + ">", pe.getRhoCoefficients()); + } + return equationOfStateDict; + } } diff --git a/src/eu/engys/gui/casesetup/materials/CompressibleMaterialsPanel.java b/src/eu/engys/gui/casesetup/materials/CompressibleMaterialsPanel.java index 479fd2e..1cd7112 100644 --- a/src/eu/engys/gui/casesetup/materials/CompressibleMaterialsPanel.java +++ b/src/eu/engys/gui/casesetup/materials/CompressibleMaterialsPanel.java @@ -1,37 +1,35 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.casesetup.materials; -import static eu.engys.core.project.constant.ThermophysicalProperties.CONSTANT_CP_KEY; -import static eu.engys.core.project.constant.ThermophysicalProperties.CONST_KEY; import static eu.engys.core.project.constant.ThermophysicalProperties.CP_KEY; import static eu.engys.core.project.constant.ThermophysicalProperties.ENERGY_KEY; import static eu.engys.core.project.constant.ThermophysicalProperties.EQUATION_OF_STATE_KEY; import static eu.engys.core.project.constant.ThermophysicalProperties.HE_PSI_THERMO_KEY; import static eu.engys.core.project.constant.ThermophysicalProperties.HF_KEY; +import static eu.engys.core.project.constant.ThermophysicalProperties.MATERIAL_NAME_KEY; import static eu.engys.core.project.constant.ThermophysicalProperties.MIXTURE_KEY; import static eu.engys.core.project.constant.ThermophysicalProperties.MOL_WEIGHT_KEY; import static eu.engys.core.project.constant.ThermophysicalProperties.MU_KEY; @@ -42,10 +40,11 @@ import static eu.engys.core.project.constant.ThermophysicalProperties.PURE_MIXTU import static eu.engys.core.project.constant.ThermophysicalProperties.SENSIBLE_ENTHALPY_KEY; import static eu.engys.core.project.constant.ThermophysicalProperties.SPECIE_KEY; import static eu.engys.core.project.constant.ThermophysicalProperties.THERMODYNAMICS_KEY; +import static eu.engys.core.project.constant.ThermophysicalProperties.THERMO_CONST_KEY; import static eu.engys.core.project.constant.ThermophysicalProperties.THERMO_KEY; import static eu.engys.core.project.constant.ThermophysicalProperties.THERMO_TYPE_KEY; +import static eu.engys.core.project.constant.ThermophysicalProperties.TRANSPORT_CONST_KEY; import static eu.engys.core.project.constant.ThermophysicalProperties.TRANSPORT_KEY; -import static eu.engys.core.project.constant.TransportProperties.MATERIAL_NAME_KEY; import static eu.engys.util.Symbols.CP; import static eu.engys.util.Symbols.HF; import static eu.engys.util.Symbols.MU_MEASURE; @@ -54,6 +53,7 @@ import javax.swing.JPanel; import eu.engys.core.dictionary.Dictionary; import eu.engys.core.project.Model; +import eu.engys.core.project.materials.compressible.CompressibleMaterial; import eu.engys.core.project.state.State; import eu.engys.util.ui.textfields.StringField; @@ -64,6 +64,7 @@ public interface CompressibleMaterialsPanel { static final String NAME_LABEL = "Name"; static final String EQUATION_OF_STATE_LABEL = "Equation Of State"; static final String PERFECT_GAS_LABEL = "Perfect Gas"; + static final String PERFECT_FLUID_LABEL = "Perfect Fluid"; static final String SUTHERLAND_TEMPERATURE_TS_LABEL = "Sutherland Temperature (Ts)"; static final String SUTHERLAND_COEFFICIENT_AS_LABEL = "Sutherland Coefficient (As)"; static final String PRANDTL_NUMBER_LABEL = "Prandtl Number"; @@ -86,8 +87,8 @@ public interface CompressibleMaterialsPanel { { add(TYPE, HE_PSI_THERMO_KEY); add(MIXTURE_KEY, PURE_MIXTURE_KEY); - add(TRANSPORT_KEY, CONST_KEY); - add(THERMO_KEY, CONSTANT_CP_KEY); + add(TRANSPORT_KEY, TRANSPORT_CONST_KEY); + add(THERMO_KEY, THERMO_CONST_KEY); add(EQUATION_OF_STATE_KEY, PERFECT_GAS_KEY); add(SPECIE_KEY, SPECIE_KEY); add(ENERGY_KEY, SENSIBLE_ENTHALPY_KEY); @@ -119,11 +120,9 @@ public interface CompressibleMaterialsPanel { } }; - Dictionary getEmptyMaterial(); + CompressibleMaterial getMaterial(Model model); - Dictionary getMaterial(Model model); - - void setMaterial(Dictionary material); + void setMaterial(CompressibleMaterial material); JPanel getPanel(); diff --git a/src/eu/engys/gui/casesetup/materials/IncompressibleMaterialsPanel.java b/src/eu/engys/gui/casesetup/materials/IncompressibleMaterialsPanel.java index eec96ea..c24fbcb 100644 --- a/src/eu/engys/gui/casesetup/materials/IncompressibleMaterialsPanel.java +++ b/src/eu/engys/gui/casesetup/materials/IncompressibleMaterialsPanel.java @@ -1,44 +1,44 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.casesetup.materials; import javax.swing.JPanel; import eu.engys.core.dictionary.Dictionary; import eu.engys.core.project.Model; +import eu.engys.core.project.materials.incompressible.IncompressibleMaterial; import eu.engys.core.project.state.State; import eu.engys.util.ui.textfields.StringField; public interface IncompressibleMaterialsPanel { - Dictionary getEmptyMaterial(); + IncompressibleMaterial getEmptyMaterial(); - Dictionary getMaterial(Model model); + IncompressibleMaterial getMaterial(Model model); - void setMaterial(Dictionary material); + void setMaterial(IncompressibleMaterial material); JPanel getPanel(); diff --git a/src/eu/engys/gui/casesetup/materials/MaterialsTreeNodeManager.java b/src/eu/engys/gui/casesetup/materials/MaterialsTreeNodeManager.java index a4c65a6..ec689d6 100644 --- a/src/eu/engys/gui/casesetup/materials/MaterialsTreeNodeManager.java +++ b/src/eu/engys/gui/casesetup/materials/MaterialsTreeNodeManager.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.casesetup.materials; import java.awt.Component; diff --git a/src/eu/engys/gui/casesetup/materials/StandardCompressibleMaterialsPanel.java b/src/eu/engys/gui/casesetup/materials/StandardCompressibleMaterialsPanel.java index 95ca98d..b4b6243 100644 --- a/src/eu/engys/gui/casesetup/materials/StandardCompressibleMaterialsPanel.java +++ b/src/eu/engys/gui/casesetup/materials/StandardCompressibleMaterialsPanel.java @@ -1,54 +1,35 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.casesetup.materials; -import static eu.engys.core.project.constant.ThermophysicalProperties.AS_KEY; import static eu.engys.core.project.constant.ThermophysicalProperties.A_KEYS; -import static eu.engys.core.project.constant.ThermophysicalProperties.CONSTANT_CP_KEY; -import static eu.engys.core.project.constant.ThermophysicalProperties.CONST_KEY; -import static eu.engys.core.project.constant.ThermophysicalProperties.CP_KEY; -import static eu.engys.core.project.constant.ThermophysicalProperties.EQUATION_OF_STATE_KEY; -import static eu.engys.core.project.constant.ThermophysicalProperties.HF_KEY; -import static eu.engys.core.project.constant.ThermophysicalProperties.HIGH_CP_COEFFS_KEY; -import static eu.engys.core.project.constant.ThermophysicalProperties.JANAF_KEY; -import static eu.engys.core.project.constant.ThermophysicalProperties.LOW_CP_COEFFS_KEY; -import static eu.engys.core.project.constant.ThermophysicalProperties.MATERIAL_NAME_KEY; -import static eu.engys.core.project.constant.ThermophysicalProperties.MOL_WEIGHT_KEY; -import static eu.engys.core.project.constant.ThermophysicalProperties.MU_KEY; -import static eu.engys.core.project.constant.ThermophysicalProperties.N_MOLES_KEY; import static eu.engys.core.project.constant.ThermophysicalProperties.PERFECT_GAS_KEY; -import static eu.engys.core.project.constant.ThermophysicalProperties.PR_KEY; -import static eu.engys.core.project.constant.ThermophysicalProperties.SUTHERLAND_KEY; import static eu.engys.core.project.constant.ThermophysicalProperties.TCOMMON_KEY; -import static eu.engys.core.project.constant.ThermophysicalProperties.THERMO_KEY; import static eu.engys.core.project.constant.ThermophysicalProperties.THIGH_KEY; import static eu.engys.core.project.constant.ThermophysicalProperties.TLOW_KEY; -import static eu.engys.core.project.constant.ThermophysicalProperties.TRANSPORT_KEY; -import static eu.engys.core.project.constant.ThermophysicalProperties.TS_KEY; import static eu.engys.util.ui.ComponentsFactory.labelArrayField; import java.awt.event.ActionEvent; @@ -57,38 +38,44 @@ import java.awt.event.ActionListener; import javax.inject.Inject; import javax.swing.JPanel; -import eu.engys.core.dictionary.Dictionary; -import eu.engys.core.dictionary.model.DictionaryModel; -import eu.engys.core.modules.materials.MaterialsBuilder; import eu.engys.core.project.Model; +import eu.engys.core.project.materials.compressible.CompressibleMaterial; +import eu.engys.core.project.materials.compressible.ConstantThermodynamicModel; +import eu.engys.core.project.materials.compressible.ConstantTransport; +import eu.engys.core.project.materials.compressible.JANAFThermodynamicModel; +import eu.engys.core.project.materials.compressible.SutherlandTransport; +import eu.engys.core.project.materials.compressible.ThermodynamicModel; +import eu.engys.core.project.materials.compressible.Transport; import eu.engys.core.project.state.State; -import eu.engys.util.ui.builder.JComboBoxController; +import eu.engys.util.bean.BeanModel; +import eu.engys.util.bean.BeanPanelBuilder; +import eu.engys.util.ui.JComboBoxWithItemsSupport; import eu.engys.util.ui.builder.PanelBuilder; +import eu.engys.util.ui.textfields.DoubleField; import eu.engys.util.ui.textfields.StringField; public class StandardCompressibleMaterialsPanel implements CompressibleMaterialsPanel { - private DictionaryModel compressibleModel = new DictionaryModel(new Dictionary("")); +// private DictionaryModel compressibleModel = new DictionaryModel(new Dictionary("")); + private BeanModel materialModel = new BeanModel<>(new CompressibleMaterial()); - private JComboBoxController transport; - private JComboBoxController thermo; - private MaterialsBuilder materialsBuilder; + private JComboBoxWithItemsSupport> transport; + private JComboBoxWithItemsSupport> thermo; private PanelBuilder builder; private StringField nameField; + private BeanModel constantThermoModel; + private BeanModel janafThermoModel; + private BeanModel constantTransportModel; + private BeanModel sutherlandTransportModel; + @Inject public StandardCompressibleMaterialsPanel() { this.builder = new PanelBuilder(); - this.materialsBuilder = new StandardMaterialsBuilder(); buildCompressibleMaterialPanel(); } - @Override - public Dictionary getEmptyMaterial() { - return new Dictionary(defaultDictionary); - } - @Override public StringField getNameField() { return nameField; @@ -108,6 +95,10 @@ public class StandardCompressibleMaterialsPanel implements CompressibleMaterials public void stateChanged(State state) { } + /* + * Panels + */ + private void buildCompressibleMaterialPanel() { buildThermophysicalModelPanel(); buildTransportPropertiesPanel(); @@ -119,78 +110,117 @@ public class StandardCompressibleMaterialsPanel implements CompressibleMaterials @Override public void actionPerformed(ActionEvent e) { if (transport.getSelectedIndex() == 0) { - thermo.addDisabledItem(JANAF_LABEL); - thermo.setSelectedItem(CONSTANT_CP_LABEL); + thermo.addDisabledItem(janafThermoModel); + thermo.setSelectedItem(constantThermoModel); } else { thermo.clearDisabledIndexes(); } } }); - transport.setSelectedItem(CONSTANT_LABEL); + transport.setSelectedItem(constantTransportModel); } @Override public void buildThermophysicalModelPanel() { - builder.addComponent(NAME_LABEL, nameField = compressibleModel.bindLabel(MATERIAL_NAME_KEY)); - builder.addComponent(NUMBER_OF_MOLES_LABEL, compressibleModel.bindIntegerPositive(N_MOLES_KEY)); - builder.addComponent(MOLECULAR_WEIGHT_KG_KMOL_LABEL, compressibleModel.bindDoublePositive(MOL_WEIGHT_KEY)); + PanelBuilder pb = new PanelBuilder(); + pb.addComponent(NAME_LABEL, nameField = materialModel.bindLabel(CompressibleMaterial.NAME_KEY)); + pb.addComponent(NUMBER_OF_MOLES_LABEL, materialModel.bindIntegerPositive(CompressibleMaterial.N_MOLES)); + pb.addComponent(MOLECULAR_WEIGHT_KG_KMOL_LABEL, materialModel.bindDoublePositive(CompressibleMaterial.MOL_WEIGHT)); nameField.setEnabled(false); + + JPanel panel = pb.getPanel(); + builder.addComponent(panel); } @Override + @SuppressWarnings("unchecked") public void buildTransportPropertiesPanel() { - transport = (JComboBoxController) builder.startChoice(TRANSPORT_PROPERTIES_LABEL, compressibleModel.bindComboBoxController(TRANSPORT_KEY)); + BeanPanelBuilder pb = new BeanPanelBuilder(); + + constantTransportModel = new BeanModel<>(new ConstantTransport()); + sutherlandTransportModel = new BeanModel<>(new SutherlandTransport()); + + transport = (JComboBoxWithItemsSupport>) pb.startChoice(TRANSPORT_PROPERTIES_LABEL, + materialModel.bindComboController(CompressibleMaterial.TRANSPORT, constantTransportModel, sutherlandTransportModel)); - builder.startGroup(CONST_KEY, CONSTANT_LABEL); - builder.addComponent(DYNAMIC_VISCOSITY_LABEL, compressibleModel.bindDoublePositive(MU_KEY)); - builder.addComponent(PRANDTL_NUMBER_LABEL, compressibleModel.bindDoublePositive(PR_KEY)); - builder.endGroup(); + pb.startBean(CONSTANT_LABEL, constantTransportModel); + pb.addComponent(DYNAMIC_VISCOSITY_LABEL, constantTransportModel.bindDoublePositive(ConstantTransport.MU_KEY)); + pb.addComponent(PRANDTL_NUMBER_LABEL, constantTransportModel.bindDoublePositive(ConstantTransport.PR_KEY)); + pb.endBean(); - builder.startGroup(SUTHERLAND_KEY, SUTHERLAND_S_LABEL); - builder.addComponent(SUTHERLAND_COEFFICIENT_AS_LABEL, compressibleModel.bindDoublePositive(AS_KEY)); - builder.addComponent(SUTHERLAND_TEMPERATURE_TS_LABEL, compressibleModel.bindDoublePositive(TS_KEY)); - builder.endGroup(); + pb.startBean(SUTHERLAND_S_LABEL, sutherlandTransportModel); + pb.addComponent(SUTHERLAND_COEFFICIENT_AS_LABEL, sutherlandTransportModel.bindDoublePositive(SutherlandTransport.AS_KEY)); + pb.addComponent(SUTHERLAND_TEMPERATURE_TS_LABEL, sutherlandTransportModel.bindDoublePositive(SutherlandTransport.TS_KEY)); + pb.endBean(); - builder.endChoice(); + pb.endChoice(); + + JPanel panel = pb.getPanel(); + builder.addComponent(panel); } @Override + @SuppressWarnings("unchecked") public void buildThermodynamicModelPanel() { - thermo = (JComboBoxController) builder.startChoice(THERMODYNAMIC_MODEL_LABEL, compressibleModel.bindComboBoxController(THERMO_KEY)); + BeanPanelBuilder pb = new BeanPanelBuilder(); + + constantThermoModel = new BeanModel<>(new ConstantThermodynamicModel()); + janafThermoModel = new BeanModel<>(new JANAFThermodynamicModel()); + + thermo = (JComboBoxWithItemsSupport>) pb.startChoice(THERMODYNAMIC_MODEL_LABEL, + materialModel.bindComboController(CompressibleMaterial.THERMODYNAMIC_MODEL, constantThermoModel, janafThermoModel)); + pb.startBean(CONSTANT_CP_LABEL, constantThermoModel); + pb.addComponent(HEAT_CAPACITY_LABEL, constantThermoModel.bindDoublePositive(ConstantThermodynamicModel.CP_KEY)); + pb.addComponent(HEAT_OF_FUSION_LABEL, constantThermoModel.bindDoublePositive(ConstantThermodynamicModel.HF_KEY)); + pb.endBean(); - builder.startGroup(CONSTANT_CP_KEY, CONSTANT_CP_LABEL); - builder.addComponent(HEAT_CAPACITY_LABEL, compressibleModel.bindDoublePositive(CP_KEY)); - builder.addComponent(HEAT_OF_FUSION_LABEL, compressibleModel.bindDoublePositive(HF_KEY)); - builder.endGroup(); + pb.startBean(JANAF_LABEL, janafThermoModel); + pb.addComponent(TLOW_KEY, janafThermoModel.bindDoublePositive(JANAFThermodynamicModel.TLOW_KEY)); + pb.addComponent(THIGH_KEY, janafThermoModel.bindDoublePositive(JANAFThermodynamicModel.THIGH_KEY)); + pb.addComponent(TCOMMON_KEY, janafThermoModel.bindDoublePositive(JANAFThermodynamicModel.TCOMMON_KEY)); - builder.startGroup(JANAF_KEY, JANAF_LABEL); - builder.addComponent(TLOW_KEY, compressibleModel.bindDoublePositive(TLOW_KEY)); - builder.addComponent(THIGH_KEY, compressibleModel.bindDoublePositive(THIGH_KEY)); - builder.addComponent(TCOMMON_KEY, compressibleModel.bindDoublePositive(TCOMMON_KEY)); - builder.addComponent(labelArrayField(A_KEYS)); - builder.addComponent(HIGH_CP_LABEL, compressibleModel.bindArray(HIGH_CP_COEFFS_KEY, 7)); - builder.addComponent(labelArrayField(A_KEYS)); - builder.addComponent(LOW_CP_LABEL, compressibleModel.bindArray(LOW_CP_COEFFS_KEY, 7)); - builder.endGroup(); + DoubleField[] lowFields = janafThermoModel.bindDoubleArray(JANAFThermodynamicModel.LOW_CP_COEFFS_KEY, 7); + DoubleField[] highFields = janafThermoModel.bindDoubleArray(JANAFThermodynamicModel.HIGH_CP_COEFFS_KEY, 7); + pb.addComponent(labelArrayField(LOW_CP_LABEL, HIGH_CP_LABEL)); + for (int i = 0; i < 7; i++) { + pb.addComponent(A_KEYS[i], lowFields[i], highFields[i]); + + } + pb.endBean(); - builder.endChoice(); + pb.endChoice(); + + JPanel panel = pb.getPanel(); + builder.addComponent(panel); + } @Override public void buildEquationOfStatePanel() { String[] EOS_KEYS = { PERFECT_GAS_KEY };// , "ICOPolynomial" }; String[] EOS_LABELS = { PERFECT_GAS_LABEL };// , "Polymomial f(T)" }; - builder.addComponent(EQUATION_OF_STATE_LABEL, compressibleModel.bindChoice(EQUATION_OF_STATE_KEY, EOS_KEYS, EOS_LABELS)).setEnabled(false); + //builder.addComponent(EQUATION_OF_STATE_LABEL, materialModel.bindChoice(EQUATION_OF_STATE_KEY, EOS_KEYS, EOS_LABELS)).setEnabled(false); } @Override - public Dictionary getMaterial(Model model) { - return materialsBuilder.saveCompressible(model, compressibleModel.getDictionary()); + public CompressibleMaterial getMaterial(Model model) { +// return materialsBuilder.saveCompressible(model, compressibleModel.getDictionary()); + return materialModel.getBean(); } @Override - public void setMaterial(Dictionary material) { - compressibleModel.setDictionary(materialsBuilder.toGUIFormat(material)); + public void setMaterial(CompressibleMaterial material) { +// compressibleModel.setDictionary(materialsBuilder.toGUIFormat(material.getDictionary())); + materialModel.setBean(material); } + + + + + + + + + } diff --git a/src/eu/engys/gui/casesetup/materials/StandardIncompressibleMaterialsPanel.java b/src/eu/engys/gui/casesetup/materials/StandardIncompressibleMaterialsPanel.java index b0b467f..9b4a067 100644 --- a/src/eu/engys/gui/casesetup/materials/StandardIncompressibleMaterialsPanel.java +++ b/src/eu/engys/gui/casesetup/materials/StandardIncompressibleMaterialsPanel.java @@ -1,53 +1,35 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.casesetup.materials; -import static eu.engys.core.project.constant.TransportProperties.BETA_OS_KEY; -import static eu.engys.core.project.constant.TransportProperties.CP_KEY; -import static eu.engys.core.project.constant.TransportProperties.LAMBDA_KEY; -import static eu.engys.core.project.constant.TransportProperties.MATERIAL_NAME_KEY; -import static eu.engys.core.project.constant.TransportProperties.MU_KEY; -import static eu.engys.core.project.constant.TransportProperties.NEWTONIAN_COEFFS_KEY; -import static eu.engys.core.project.constant.TransportProperties.NEWTONIAN_KEY; -import static eu.engys.core.project.constant.TransportProperties.NU_KEY; -import static eu.engys.core.project.constant.TransportProperties.PRT_KEY; -import static eu.engys.core.project.constant.TransportProperties.PR_KEY; -import static eu.engys.core.project.constant.TransportProperties.P_REF_KEY; -import static eu.engys.core.project.constant.TransportProperties.RHO_KEY; -import static eu.engys.core.project.constant.TransportProperties.TRANSPORT_MODEL_KEY; -import static eu.engys.core.project.constant.TransportProperties.T_REF_KEY; - import javax.swing.JPanel; import com.google.inject.Inject; -import eu.engys.core.dictionary.Dictionary; -import eu.engys.core.dictionary.DimensionedScalar; import eu.engys.core.project.Model; -import eu.engys.util.DimensionalUnits; +import eu.engys.core.project.materials.incompressible.IncompressibleMaterial; public class StandardIncompressibleMaterialsPanel extends AbstractIncompressibleMaterialsPanel { @@ -61,21 +43,26 @@ public class StandardIncompressibleMaterialsPanel extends AbstractIncompressible } @Override - public Dictionary getMaterial(Model model) { - return materialsBuilder.saveIncompressible(model, incompressibleModel.getDictionary()); + public IncompressibleMaterial getMaterial(Model model) { +// return materialsBuilder.saveIncompressible(model, incompressibleModel.getDictionary()); + return materialModel.getBean(); } @Override - public void setMaterial(Dictionary material) { - adjustNuIfNeeded(material); - incompressibleModel.setDictionary(new Dictionary(material.getName(), material)); + public void setMaterial(IncompressibleMaterial material) { +// Dictionary materialDict = material.getDictionary(); +// adjustNuIfNeeded(materialDict); +// incompressibleModel.setDictionary(new Dictionary(materialDict.getName(), materialDict)); + removeListeners(); + materialModel.setBean(material); + addListeners(); } @Override protected void buildIncompressibleMaterialPanel() { super.buildIncompressibleMaterialPanel(); - builder.addComponent(THERMAL_EXPANTION_COEFF_LABEL, incompressibleModel.bindDimensionedDouble(BETA_OS_KEY, DimensionalUnits._K, 0D, Double.MAX_VALUE)); - builder.addComponent(LAMINAR_PRANDTL_NUMBER_LABEL, incompressibleModel.bindDimensionedDouble(PR_KEY, DimensionalUnits.NONE, 0D, Double.MAX_VALUE)); + builder.addComponent(THERMAL_EXPANTION_COEFF_LABEL, materialModel.bindDoublePositive(IncompressibleMaterial.BETA_KEY)); + builder.addComponent(LAMINAR_PRANDTL_NUMBER_LABEL, materialModel.bindDoublePositive(IncompressibleMaterial.PR_KEY)); } @Override @@ -84,27 +71,8 @@ public class StandardIncompressibleMaterialsPanel extends AbstractIncompressible } @Override - public Dictionary getEmptyMaterial() { - return new Dictionary(defaultDictionary); + public IncompressibleMaterial getEmptyMaterial() { + return new IncompressibleMaterial(); } - public static Dictionary defaultDictionary = new Dictionary("newMaterial") { - { - add(MATERIAL_NAME_KEY, "newMaterial"); - add(TRANSPORT_MODEL_KEY, NEWTONIAN_KEY); - add(new Dictionary(NEWTONIAN_COEFFS_KEY)); - add(new DimensionedScalar(RHO_KEY, "0.0", DimensionalUnits.KG_M3)); - add(new DimensionedScalar(RHO_KEY, "0.0", DimensionalUnits.KG_M3)); - add(new DimensionedScalar(MU_KEY, "0.0", DimensionalUnits.KG_MS)); - add(new DimensionedScalar(NU_KEY, "0.0", DimensionalUnits.M2_S)); - add(new DimensionedScalar(CP_KEY, "0.0", DimensionalUnits.M2_S2K)); - add(new DimensionedScalar(PRT_KEY, "0.0", DimensionalUnits.NONE)); - add(new DimensionedScalar(LAMBDA_KEY, "0.0", DimensionalUnits.KGM_S3K)); - add(new DimensionedScalar(P_REF_KEY, "0.0", DimensionalUnits.KG_MS2)); - add(new DimensionedScalar(T_REF_KEY, "0.0", DimensionalUnits.K)); - add(new DimensionedScalar(BETA_OS_KEY, "0.0", DimensionalUnits._K)); - add(new DimensionedScalar(PR_KEY, "0.0", DimensionalUnits.NONE)); - } - }; - } diff --git a/src/eu/engys/gui/casesetup/materials/StandardMaterialsBuilder.java b/src/eu/engys/gui/casesetup/materials/StandardMaterialsBuilder.java index ed57f5c..8ecd873 100644 --- a/src/eu/engys/gui/casesetup/materials/StandardMaterialsBuilder.java +++ b/src/eu/engys/gui/casesetup/materials/StandardMaterialsBuilder.java @@ -1,148 +1,45 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.casesetup.materials; -import static eu.engys.core.project.constant.ThermophysicalProperties.AS_KEY; -import static eu.engys.core.project.constant.ThermophysicalProperties.BETA_OS_KEY; -import static eu.engys.core.project.constant.ThermophysicalProperties.CONSTANT_CP_KEY; -import static eu.engys.core.project.constant.ThermophysicalProperties.CONST_KEY; import static eu.engys.core.project.constant.ThermophysicalProperties.DEFAULT_MATERIAL_KEY; -import static eu.engys.core.project.constant.ThermophysicalProperties.ENERGY_KEY; import static eu.engys.core.project.constant.ThermophysicalProperties.EQUATION_OF_STATE_KEY; -import static eu.engys.core.project.constant.ThermophysicalProperties.HE_PSI_THERMO_KEY; -import static eu.engys.core.project.constant.ThermophysicalProperties.HE_RHO_THERMO_KEY; -import static eu.engys.core.project.constant.ThermophysicalProperties.HF_KEY; -import static eu.engys.core.project.constant.ThermophysicalProperties.HIGH_CP_COEFFS_KEY; -import static eu.engys.core.project.constant.ThermophysicalProperties.JANAF_KEY; -import static eu.engys.core.project.constant.ThermophysicalProperties.LOW_CP_COEFFS_KEY; import static eu.engys.core.project.constant.ThermophysicalProperties.MATERIAL_NAME_KEY; import static eu.engys.core.project.constant.ThermophysicalProperties.MIXTURE_KEY; -import static eu.engys.core.project.constant.ThermophysicalProperties.MOL_WEIGHT_KEY; -import static eu.engys.core.project.constant.ThermophysicalProperties.MU_KEY; -import static eu.engys.core.project.constant.ThermophysicalProperties.N_MOLES_KEY; -import static eu.engys.core.project.constant.ThermophysicalProperties.PR_KEY; -import static eu.engys.core.project.constant.ThermophysicalProperties.PURE_MIXTURE_KEY; -import static eu.engys.core.project.constant.ThermophysicalProperties.SENSIBLE_ENTHALPY_KEY; -import static eu.engys.core.project.constant.ThermophysicalProperties.SENSIBLE_INTERNAL_ENERGY_KEY; import static eu.engys.core.project.constant.ThermophysicalProperties.SPECIE_KEY; -import static eu.engys.core.project.constant.ThermophysicalProperties.SUTHERLAND_KEY; -import static eu.engys.core.project.constant.ThermophysicalProperties.TCOMMON_KEY; import static eu.engys.core.project.constant.ThermophysicalProperties.THERMODYNAMICS_KEY; import static eu.engys.core.project.constant.ThermophysicalProperties.THERMO_KEY; import static eu.engys.core.project.constant.ThermophysicalProperties.THERMO_MODEL_KEY; import static eu.engys.core.project.constant.ThermophysicalProperties.THERMO_TYPE_KEY; -import static eu.engys.core.project.constant.ThermophysicalProperties.THIGH_KEY; -import static eu.engys.core.project.constant.ThermophysicalProperties.TLOW_KEY; import static eu.engys.core.project.constant.ThermophysicalProperties.TRANSPORT_KEY; -import static eu.engys.core.project.constant.ThermophysicalProperties.TS_KEY; -import static eu.engys.core.project.constant.TransportProperties.CP0_KEY; -import static eu.engys.core.project.constant.TransportProperties.CP_KEY; -import static eu.engys.core.project.constant.TransportProperties.RHO_CP0_KEY; -import static eu.engys.core.project.constant.TransportProperties.RHO_KEY; + import eu.engys.core.dictionary.Dictionary; import eu.engys.core.project.Model; public class StandardMaterialsBuilder extends AbstractMaterialsBuilder { - @Override - protected String getBetaKey() { - return BETA_OS_KEY; - } - - @Override - public Dictionary saveIncompressible(Model model, Dictionary materialDict) { - Dictionary transportProperties = super.saveIncompressible(model, materialDict); - if (materialDict.found(CP_KEY)) { - transportProperties.add(CP0_KEY, materialDict.lookupScalar(CP_KEY).getValue()); - } - if (materialDict.found(RHO_KEY)) { - transportProperties.add(RHO_CP0_KEY, materialDict.lookupScalar(RHO_KEY).getValue()); - } - return transportProperties; - } - - @Override - public Dictionary saveCompressible(Model model, Dictionary materialGUIDict) { - String type = model != null ? (model.getState().isBuoyant() ? HE_RHO_THERMO_KEY : HE_PSI_THERMO_KEY) : materialGUIDict.lookup(THERMO_MODEL_KEY); - String energy = model != null && model.getState().isHighMach() && model.getState().getSolverFamily().isPimple() ? SENSIBLE_INTERNAL_ENERGY_KEY : SENSIBLE_ENTHALPY_KEY; - String thermo = materialGUIDict.found(THERMO_KEY) ? materialGUIDict.lookup(THERMO_KEY) : ""; - String transport = materialGUIDict.found(TRANSPORT_KEY) ? materialGUIDict.lookup(TRANSPORT_KEY) : ""; - - Dictionary thermoDict = new Dictionary(THERMO_TYPE_KEY); - thermoDict.add(Dictionary.TYPE, type); - thermoDict.add(MIXTURE_KEY, PURE_MIXTURE_KEY); - thermoDict.add(TRANSPORT_KEY, transport.equals(CONST_KEY) ? CONST_KEY : SUTHERLAND_KEY); - thermoDict.add(THERMO_KEY, materialGUIDict.lookup(THERMO_KEY)); - thermoDict.add(EQUATION_OF_STATE_KEY, materialGUIDict.lookup(EQUATION_OF_STATE_KEY)); - thermoDict.add(SPECIE_KEY, SPECIE_KEY); - thermoDict.add(ENERGY_KEY, energy); - - /* SPECIES */ - Dictionary specieDict = new Dictionary(SPECIE_KEY); - specieDict.add(N_MOLES_KEY, materialGUIDict.lookup(N_MOLES_KEY)); - specieDict.add(MOL_WEIGHT_KEY, materialGUIDict.lookup(MOL_WEIGHT_KEY)); - - /* THERMODYNAMICS */ - Dictionary thermodynamicsDict = new Dictionary(THERMODYNAMICS_KEY); - if (thermo.equals(CONSTANT_CP_KEY)) { - thermodynamicsDict.add(CP_KEY, materialGUIDict.lookup(CP_KEY)); - thermodynamicsDict.add(HF_KEY, materialGUIDict.lookup(HF_KEY)); - } else if (thermo.equals(JANAF_KEY)) { - thermodynamicsDict.add(TLOW_KEY, materialGUIDict.lookup(TLOW_KEY)); - thermodynamicsDict.add(THIGH_KEY, materialGUIDict.lookup(THIGH_KEY)); - thermodynamicsDict.add(TCOMMON_KEY, materialGUIDict.lookup(TCOMMON_KEY)); - thermodynamicsDict.add(HIGH_CP_COEFFS_KEY, materialGUIDict.lookup(HIGH_CP_COEFFS_KEY)); - thermodynamicsDict.add(LOW_CP_COEFFS_KEY, materialGUIDict.lookup(LOW_CP_COEFFS_KEY)); - } - - /* TRANSPORT */ - Dictionary transportDict = new Dictionary(TRANSPORT_KEY); - if (transport.equals(CONST_KEY)) { - transportDict.add(MU_KEY, materialGUIDict.lookup(MU_KEY)); - transportDict.add(PR_KEY, materialGUIDict.lookup(PR_KEY)); - } else if (transport.equals(SUTHERLAND_KEY)) { - transportDict.add(AS_KEY, materialGUIDict.lookup(AS_KEY)); - transportDict.add(TS_KEY, materialGUIDict.lookup(TS_KEY)); - } - - Dictionary mixtureDict = new Dictionary(MIXTURE_KEY); - mixtureDict.add(specieDict); - mixtureDict.add(thermodynamicsDict); - mixtureDict.add(transportDict); - - String materialName = materialGUIDict.lookup(MATERIAL_NAME_KEY); - Dictionary thermophysicalProperties = new Dictionary(materialName); - thermophysicalProperties.add(MATERIAL_NAME_KEY, materialName); - thermophysicalProperties.add(thermoDict); - thermophysicalProperties.add(mixtureDict); - - // System.out.println("MaterialsBuilder.saveCompressible() "+thermophysicalProperties); - return thermophysicalProperties; - } - @Override public Dictionary loadCompressible(Model model) { Dictionary thermophysicalProperties = model.getProject().getConstantFolder().getThermophysicalProperties(); diff --git a/src/eu/engys/gui/casesetup/materials/StandardMaterialsReader.java b/src/eu/engys/gui/casesetup/materials/StandardMaterialsReader.java index 693dc0c..278eb59 100644 --- a/src/eu/engys/gui/casesetup/materials/StandardMaterialsReader.java +++ b/src/eu/engys/gui/casesetup/materials/StandardMaterialsReader.java @@ -1,87 +1,41 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.casesetup.materials; +import static eu.engys.core.project.constant.TransportProperties.BETA_OS_KEY; + import javax.inject.Inject; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - public class StandardMaterialsReader extends AbstractMaterialsReader { - private static final Logger logger = LoggerFactory.getLogger(StandardMaterialsReader.class); - @Inject public StandardMaterialsReader() { } -// @Override -// public void readMultiphase_IncompressibleMaterials(Materials materials, Dictionary transportProperties) { -// if (transportProperties.found("phases")) { -// String[] phases = transportProperties.lookupArray("phases"); -// if (phases.length == 2) { -// -// Dictionary dict1 = new Dictionary(transportProperties.subDict(phases[0])); -// if (!dict1.isEmpty()) { -// if (!dict1.found("materialName")) { -// dict1.add("materialName", "material1"); -// } -// String name1 = dict1.lookup("materialName"); -// dict1.setName(name1); -// materials.add(new Material(name1, dict1)); -// } -// -// Dictionary dict2 = new Dictionary(transportProperties.subDict(phases[1])); -// if (!dict2.isEmpty()) { -// if (!dict2.found("materialName")) { -// dict2.add("materialName", "material2"); -// } -// String name2 = dict2.lookup("materialName"); -// dict2.setName(name2); -// materials.add(new Material(name2, dict2)); -// } -// -// if (transportProperties.found("sigma")) { -// String sigmaValue = transportProperties.lookup("sigma"); -// materials.get(0).getDictionary().add("sigma", sigmaValue); -// materials.get(1).getDictionary().add("sigma", sigmaValue); -// } else if (dict1.found("sigma")) { -// String sigmaValue = dict1.lookup("sigma"); -// materials.get(1).getDictionary().add("sigma", sigmaValue); -// } else if (dict2.found("sigma")) { -// String sigmaValue = dict2.lookup("sigma"); -// materials.get(0).getDictionary().add("sigma", sigmaValue); -// } -// } else { -// logger.warn("Multiphase case but wrong phases number found in transportProperties: " + phases.length); -// } -// -// } else { -// logger.warn("Multiphase case but no phases found in transportProperties"); -// } -// } - + @Override + public String getBetaKey() { + return BETA_OS_KEY; + } } diff --git a/src/eu/engys/gui/casesetup/materials/StandardMaterialsWriter.java b/src/eu/engys/gui/casesetup/materials/StandardMaterialsWriter.java index 673d1c2..d633e8b 100644 --- a/src/eu/engys/gui/casesetup/materials/StandardMaterialsWriter.java +++ b/src/eu/engys/gui/casesetup/materials/StandardMaterialsWriter.java @@ -1,69 +1,65 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.casesetup.materials; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import static eu.engys.core.project.constant.TransportProperties.BETA_OS_KEY; +import static eu.engys.core.project.constant.TransportProperties.CP0_KEY; +import static eu.engys.core.project.constant.TransportProperties.RHO_CP_KEY; +import static java.lang.String.valueOf; + +import javax.inject.Inject; + +import eu.engys.core.dictionary.Dictionary; +import eu.engys.core.dictionary.DimensionedScalar; +import eu.engys.core.project.Model; +import eu.engys.core.project.materials.Material; +import eu.engys.core.project.materials.incompressible.IncompressibleMaterial; +import eu.engys.util.DimensionalUnits; public class StandardMaterialsWriter extends AbstractMaterialsWriter { - private static final Logger logger = LoggerFactory.getLogger(AbstractMaterialsWriter.class); + @Inject + public StandardMaterialsWriter(Model model) { + super(model); + } -// @Override -// public void writeMultiphase_IncompressibleMaterials(Materials materials, Dictionary tpp) { -// if (materials.size() == 2) { -// Material mat1 = materials.get(0); -// Material mat2 = materials.get(1); -// -// String mat1Name = mat1.getName(); -// String mat2Name = mat2.getName(); -// -// tpp.add(PHASES_KEY, "(" + mat1Name + " " + mat2Name + ")"); -// -// Dictionary dict1 = new Dictionary(mat1.getDictionary()); -// dict1.remove(SIGMA_KEY); -// dict1.setName(mat1Name); -// tpp.add(dict1); -// -// Dictionary dict2 = new Dictionary(mat2.getDictionary()); -// dict2.remove(SIGMA_KEY); -// dict2.setName(mat2Name); -// tpp.add(dict2); -// -// String sigmaValue = "0.0"; -// if (mat1.getDictionary().found(SIGMA_KEY)) { -// sigmaValue = mat1.getDictionary().lookup(SIGMA_KEY); -// } else if (mat2.getDictionary().found(SIGMA_KEY)) { -// sigmaValue = mat2.getDictionary().lookup(SIGMA_KEY); -// } -// tpp.add(new DimensionedScalar(SIGMA_KEY, sigmaValue, "[1 0 -2 0 0 0 0 ]")); -// -// } else { -// logger.warn("Multiphase solution choosen but '{}' materials found", materials.size()); -// } -// } + @Override + public Dictionary writeSingle_IncompressibleMaterial(Material m) { + Dictionary d = super.writeSingle_IncompressibleMaterial(m); + if (m instanceof IncompressibleMaterial) { + IncompressibleMaterial im = (IncompressibleMaterial) m; + d.add(new DimensionedScalar(CP0_KEY, valueOf(im.getCp()), DimensionalUnits.K)); + d.add(RHO_CP_KEY, valueOf(im.getRho())); /* NOT A DIMENSIONED SCALAR! */ + } + + return d; + } + + @Override + protected String getBetaKey() { + return BETA_OS_KEY; + } } diff --git a/src/eu/engys/gui/casesetup/materials/panels/MaterialParametersPanel.java b/src/eu/engys/gui/casesetup/materials/panels/MaterialParametersPanel.java index dce648b..c6fb4cc 100644 --- a/src/eu/engys/gui/casesetup/materials/panels/MaterialParametersPanel.java +++ b/src/eu/engys/gui/casesetup/materials/panels/MaterialParametersPanel.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.casesetup.materials.panels; @@ -31,8 +30,10 @@ import java.awt.CardLayout; import javax.swing.BorderFactory; import javax.swing.JPanel; -import eu.engys.core.dictionary.Dictionary; import eu.engys.core.project.Model; +import eu.engys.core.project.materials.Material; +import eu.engys.core.project.materials.compressible.CompressibleMaterial; +import eu.engys.core.project.materials.incompressible.IncompressibleMaterial; import eu.engys.core.project.state.State; import eu.engys.gui.casesetup.materials.CompressibleMaterialsPanel; import eu.engys.gui.casesetup.materials.IncompressibleMaterialsPanel; @@ -96,15 +97,7 @@ public class MaterialParametersPanel extends JPanel { } } - public Dictionary getEmptyMaterial(Model model) { - if (model.getState().isCompressible()) { - return compressiblePanel.getEmptyMaterial(); - } else { - return incompressiblePanel.getEmptyMaterial(); - } - } - - public Dictionary getMaterial(Model model) { + public Material getMaterial(Model model) { if (model.getState().isCompressible()) { return compressiblePanel.getMaterial(model); } else { @@ -120,11 +113,11 @@ public class MaterialParametersPanel extends JPanel { } } - public void setMaterial(Dictionary material) { - if (selected.equals(COMPRESSIBLE)) { - compressiblePanel.setMaterial(material); - } else { - incompressiblePanel.setMaterial(material); + public void setMaterial(Material material) { + if (selected.equals(COMPRESSIBLE) && material instanceof CompressibleMaterial) { + compressiblePanel.setMaterial((CompressibleMaterial) material); + } else if(selected.equals(INCOMPRESSIBLE) && material instanceof IncompressibleMaterial){ + incompressiblePanel.setMaterial((IncompressibleMaterial)material); } } diff --git a/src/eu/engys/gui/casesetup/materials/panels/MaterialsDatabasePanel.java b/src/eu/engys/gui/casesetup/materials/panels/MaterialsDatabasePanel.java index 063ab1d..99637b0 100644 --- a/src/eu/engys/gui/casesetup/materials/panels/MaterialsDatabasePanel.java +++ b/src/eu/engys/gui/casesetup/materials/panels/MaterialsDatabasePanel.java @@ -1,33 +1,29 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.casesetup.materials.panels; -import static eu.engys.core.project.constant.ThermophysicalProperties.MATERIAL_NAME_KEY; - import java.awt.BorderLayout; import java.awt.Color; import java.awt.event.ActionEvent; @@ -58,6 +54,9 @@ import com.google.inject.Inject; import eu.engys.core.dictionary.Dictionary; import eu.engys.core.dictionary.DictionaryUtils; import eu.engys.core.project.Model; +import eu.engys.core.project.materials.Material; +import eu.engys.core.project.materials.MaterialsReader; +import eu.engys.core.project.materials.MaterialsWriter; import eu.engys.gui.casesetup.materials.CompressibleMaterialsPanel; import eu.engys.gui.casesetup.materials.IncompressibleMaterialsPanel; import eu.engys.util.PrefUtil; @@ -75,6 +74,8 @@ public class MaterialsDatabasePanel extends JPanel { public static final String REMOVE_TOOLTIP = "Remove Currently Selected Material"; public static final String COPY_OF_SUFFIX = "_copy"; + public static final String USER_LIBRARY_LIST_NAME = "user.library.list"; + public static final String MATERIALS_LIBRARY_LIST_NAME = "materials.library.list"; private final Action newMaterial = new NewMaterialAction(); private final Action copyMaterial = new CopyMaterialAction(); @@ -92,12 +93,16 @@ public class MaterialsDatabasePanel extends JPanel { private JList userMaterialsList; private Model model; - private Map userMaterials = new HashMap(); + private Map userMaterials = new HashMap<>(); + private MaterialsReader reader; + private MaterialsWriter writer; @Inject - public MaterialsDatabasePanel(final Model model, CompressibleMaterialsPanel compressiblePanel, IncompressibleMaterialsPanel incompressiblePanel) { + public MaterialsDatabasePanel(final Model model, CompressibleMaterialsPanel compressiblePanel, IncompressibleMaterialsPanel incompressiblePanel, MaterialsReader reader, MaterialsWriter writer) { super(new BorderLayout()); this.model = model; + this.reader = reader; + this.writer = writer; materialListener = new DefaultMaterialsListListener(); userListener = new UserMaterialsListListener(); @@ -106,11 +111,11 @@ public class MaterialsDatabasePanel extends JPanel { userListModel = new DefaultListModel(); defaultMaterialsList = new JList(materialsListModel); - defaultMaterialsList.setName("materials.library.list"); + defaultMaterialsList.setName(MATERIALS_LIBRARY_LIST_NAME); defaultMaterialsList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); userMaterialsList = new JList(userListModel); - userMaterialsList.setName("user.library.list"); + userMaterialsList.setName(USER_LIBRARY_LIST_NAME); userMaterialsList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); defaultMaterialsList.addListSelectionListener(materialListener); @@ -178,6 +183,21 @@ public class MaterialsDatabasePanel extends JPanel { parametersPanel.show(model.getState()); } + private void updateDefaultMaterialsList() { + defaultMaterialsList.removeListSelectionListener(materialListener); + materialsListModel.clear(); + Collection materials = null; + if (model.getState().isCompressible()) { + materials = model.getMaterialsDatabase().getCompressibleMaterials(); + } else { + materials = model.getMaterialsDatabase().getIncompressibleMaterials(); + } + for (Material m : materials) { + materialsListModel.addElement(m.getName()); + } + defaultMaterialsList.addListSelectionListener(materialListener); + } + private void loadUserMaterials() { userMaterials.clear(); @@ -190,14 +210,15 @@ public class MaterialsDatabasePanel extends JPanel { try { if (model.getState().isCompressible()) { if (matDict.found("thermoType")) { - userMaterials.put(matDict.getName(), matDict); + userMaterials.put(matDict.getName(), reader.readCompressibleMaterial(matDict)); } } else { - userMaterials.put(matDict.getName(), matDict); + userMaterials.put(matDict.getName(), reader.readIncompressibleMaterial(matDict)); } } catch (Exception e) { System.out.println("INVALID MATERIAL DICTIONARY: " + matDict.getName()); + e.printStackTrace(); } } } @@ -207,13 +228,17 @@ public class MaterialsDatabasePanel extends JPanel { public void saveUserMaterials() { saveCurrentSelectedUserDefinedMaterial(); Dictionary userMaterialsProperties = new Dictionary("materials"); - for (Dictionary mat : userMaterials.values()) { - userMaterialsProperties.add(mat); + for (Material m : userMaterials.values()) { + if(model.getState().getFlow().isIncompressible()){ + userMaterialsProperties.add(writer.writeSingle_IncompressibleMaterial(m)); + } else { + userMaterialsProperties.add(writer.writeSingle_CompressibleMaterial(m)); + } } PrefUtil.putString(PrefUtil.MATERIALS_USER_LIB + model.getState().getFlow(), userMaterialsProperties.toString()); } - public Dictionary getMaterial() { + public Material getMaterial() { return parametersPanel.getMaterial(model); } @@ -228,25 +253,10 @@ public class MaterialsDatabasePanel extends JPanel { userMaterialsList.addListSelectionListener(userListener); } - private void updateDefaultMaterialsList() { - defaultMaterialsList.removeListSelectionListener(materialListener); - materialsListModel.clear(); - Collection materials = null; - if (model.getState().isCompressible()) { - materials = model.getMaterialsDatabase().getCompressibleMaterials(); - } else { - materials = model.getMaterialsDatabase().getIncompressibleMaterials(); - } - for (Dictionary mat : materials) { - materialsListModel.addElement(mat.lookup(MATERIAL_NAME_KEY)); - } - defaultMaterialsList.addListSelectionListener(materialListener); - } - private final class DefaultMaterialsListListener implements ListSelectionListener { @Override public void valueChanged(ListSelectionEvent e) { - if (!e.getValueIsAdjusting() && e.getSource() == defaultMaterialsList) { + if (!defaultMaterialsList.getValueIsAdjusting() && e.getSource() == defaultMaterialsList) { String key = (String) defaultMaterialsList.getSelectedValue(); if (key == null) return; @@ -255,12 +265,8 @@ public class MaterialsDatabasePanel extends JPanel { saveCurrentSelectedUserDefinedMaterial(); - if (model.getState().isCompressible()) { - setMaterialToParametersPanel(new Dictionary(model.getMaterialsDatabase().getCompressibleMaterialsMap().get(key))); - } else { - setMaterialToParametersPanel(new Dictionary(model.getMaterialsDatabase().getIncompressibleMaterialsMap().get(key))); - } - + setMaterialToParametersPanel(Material.newDefaultMaterial(model, key)); + parametersPanel.getNameField(model).setEnabled(false); copyMaterial.setEnabled(true); @@ -273,7 +279,7 @@ public class MaterialsDatabasePanel extends JPanel { private final class UserMaterialsListListener implements ListSelectionListener { @Override public void valueChanged(ListSelectionEvent e) { - if (!e.getValueIsAdjusting() && e.getSource() == userMaterialsList) { + if (!userMaterialsList.getValueIsAdjusting() && e.getSource() == userMaterialsList) { String key = (String) userMaterialsList.getSelectedValue(); if (key == null) return; @@ -282,8 +288,7 @@ public class MaterialsDatabasePanel extends JPanel { saveCurrentSelectedUserDefinedMaterial(); - Dictionary dict = new Dictionary(userMaterials.get(key)); - setMaterialToParametersPanel(dict); + setMaterialToParametersPanel(userMaterials.get(key));//Material.newMaterial(key, userMaterials.get(key))); parametersPanel.getNameField(model).setEnabled(true); @@ -295,22 +300,24 @@ public class MaterialsDatabasePanel extends JPanel { } private void saveCurrentSelectedUserDefinedMaterial() { - Dictionary currentMaterial = parametersPanel.getMaterial(model); - if (userMaterials.keySet().contains(currentMaterial.getName())) { - // If name is changed - String oldMaterialName = currentMaterial.getName(); - String newMaterialName = currentMaterial.lookup(MATERIAL_NAME_KEY); - - userMaterials.remove(oldMaterialName); - Dictionary newMaterialDict = new Dictionary(newMaterialName, currentMaterial); - userMaterials.put(newMaterialName, newMaterialDict); - - updateUserMaterialsList(); - } +// Material currentMaterial = parametersPanel.getMaterial(model); +// if (userMaterials.keySet().contains(currentMaterial.getName())) { +// // If name is changed +// String oldMaterialName = currentMaterial.getName(); +// String newMaterialName = currentMaterial.lookup(MATERIAL_NAME_KEY); +// +// userMaterials.remove(oldMaterialName); +// +// Material newMaterial = Material.newMaterial(newMaterialName, currentMaterial); +// userMaterials.put(newMaterialName, newMaterial); +// +// updateUserMaterialsList(); +// } + /* NON SERVE PIU' ???*/ } - private void setMaterialToParametersPanel(Dictionary material) { + private void setMaterialToParametersPanel(Material material) { parametersPanel.getNameField(model).removePropertyChangeListener(nameChangeListener); parametersPanel.setMaterial(material); parametersPanel.getNameField(model).addPropertyChangeListener(nameChangeListener); @@ -329,13 +336,10 @@ public class MaterialsDatabasePanel extends JPanel { public void actionPerformed(ActionEvent e) { clearSelectionOnAllLists(); - Dictionary emptyDict = parametersPanel.getEmptyMaterial(model); + String validMaterialName = getValidMaterialName("newMaterial"); + Material newMaterial = Material.newMaterial(model, validMaterialName); - String validMaterialName = getValidMaterialName(emptyDict.getName()); - Dictionary newMaterialDict = new Dictionary(validMaterialName, emptyDict); - newMaterialDict.add(MATERIAL_NAME_KEY, validMaterialName); - - userMaterials.put(validMaterialName, newMaterialDict); + userMaterials.put(validMaterialName, newMaterial); updateUserMaterialsList(); userMaterialsList.setSelectedValue(validMaterialName, true); } @@ -351,11 +355,10 @@ public class MaterialsDatabasePanel extends JPanel { public void actionPerformed(ActionEvent e) { clearSelectionOnAllLists(); - Dictionary currentlySelectedMaterial = parametersPanel.getMaterial(model); + Material currentlySelectedMaterial = parametersPanel.getMaterial(model); String validMaterialName = getValidMaterialName(currentlySelectedMaterial.getName()); - Dictionary copyMaterial = new Dictionary(validMaterialName, currentlySelectedMaterial); - copyMaterial.add(MATERIAL_NAME_KEY, validMaterialName); + Material copyMaterial = Material.newMaterial(validMaterialName, currentlySelectedMaterial); userMaterials.put(validMaterialName, copyMaterial); updateUserMaterialsList(); @@ -398,7 +401,7 @@ public class MaterialsDatabasePanel extends JPanel { } private String getValidMaterialName(String materialname) { - Map materials = null; + Map materials = null; if (model.getState().isCompressible()) { materials = model.getMaterialsDatabase().getCompressibleMaterialsMap(); @@ -429,11 +432,11 @@ public class MaterialsDatabasePanel extends JPanel { if (oldname != null) { String newName = (String) evt.getNewValue(); - Dictionary currentMaterial = parametersPanel.getMaterial(model); + Material currentMaterial = parametersPanel.getMaterial(model); userMaterials.remove(oldname); - Dictionary newMaterialDict = new Dictionary(newName, currentMaterial); - userMaterials.put(newName, newMaterialDict); +// Material newMaterial = Material.newMaterial(newName, currentMaterial); + userMaterials.put(newName, currentMaterial); updateUserMaterialsList(); userMaterialsList.setSelectedValue(newName, true); diff --git a/src/eu/engys/gui/casesetup/materials/panels/MaterialsPanel.java b/src/eu/engys/gui/casesetup/materials/panels/MaterialsPanel.java index 3d91ea4..97a702a 100644 --- a/src/eu/engys/gui/casesetup/materials/panels/MaterialsPanel.java +++ b/src/eu/engys/gui/casesetup/materials/panels/MaterialsPanel.java @@ -1,33 +1,32 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.casesetup.materials.panels; -import static eu.engys.core.project.constant.TransportProperties.MATERIAL_NAME_KEY; import static eu.engys.gui.casesetup.materials.panels.MaterialsDatabasePanel.COPY_OF_SUFFIX; +import static eu.engys.util.ui.UiUtil.DIALOG_CANCEL_LABEL; +import static eu.engys.util.ui.UiUtil.DIALOG_OK_LABEL; import java.awt.BorderLayout; import java.awt.CardLayout; @@ -49,7 +48,6 @@ import javax.swing.SwingUtilities; import com.google.inject.Inject; -import eu.engys.core.dictionary.Dictionary; import eu.engys.core.modules.ApplicationModule; import eu.engys.core.modules.ModulesUtil; import eu.engys.core.project.Model; @@ -69,7 +67,9 @@ import eu.engys.util.ui.builder.PanelBuilder; public class MaterialsPanel extends AbstractGUIPanel { public static final String MATERIALS = "Materials"; + public static final String CHANGE_MATERIAL = "Change Material"; private static final String MATERIAL_CHANGED_WARNING = "A material has been changed.\nAll fields default settings are going to be reset now.\nContinue?"; + public static final String MATERIALS_DATABASE_DIALOG_NAME = "materials.database.dialog"; private JDialog dialog; @@ -111,9 +111,8 @@ public class MaterialsPanel extends AbstractGUIPanel { parametersPanel = new MaterialParametersPanel(compressiblePanel, incompressiblePanel); parametersBuilder = new PanelBuilder(); - parametersBuilder.addComponent(parametersPanel); - ModulesUtil.configureMaterialsView(modules, parametersBuilder); + parametersBuilder.addComponent(parametersPanel); centerPanel.add(parametersBuilder.removeMargins().getPanel(), "material"); @@ -127,7 +126,7 @@ public class MaterialsPanel extends AbstractGUIPanel { private JComponent createButtonsPanel() { List actionsList = new ArrayList(); changeMaterialButton = new JButton(new ChangeMaterialAction()); - changeMaterialButton.setName("Change Material"); + changeMaterialButton.setName(CHANGE_MATERIAL); changeMaterialButton.setEnabled(false); actionsList.add(changeMaterialButton); @@ -138,23 +137,22 @@ public class MaterialsPanel extends AbstractGUIPanel { private void buildDialog() { JButton okButton = new JButton(new OkDialogAction()); - okButton.setName("OK"); + okButton.setName(DIALOG_OK_LABEL); JButton cancelButton = new JButton(new CancelDialogAction()); - cancelButton.setName("Cancel"); - + cancelButton.setName(DIALOG_CANCEL_LABEL); + JPanel buttonsPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); buttonsPanel.add(okButton); buttonsPanel.add(cancelButton); - + dialog = new JDialog(UiUtil.getActiveWindow(), "Materials Database", JDialog.DEFAULT_MODALITY_TYPE); - dialog.setName("materials.database.dialog"); + dialog.setName(MATERIALS_DATABASE_DIALOG_NAME); dialog.setSize(700, 500); dialog.setLocationRelativeTo(null); dialog.getContentPane().setLayout(new BorderLayout()); dialog.getContentPane().add(materialsDatabasePanel, BorderLayout.CENTER); dialog.getContentPane().add(buttonsPanel, BorderLayout.SOUTH); - dialog.getRootPane().setDefaultButton(okButton); } @Override @@ -187,16 +185,11 @@ public class MaterialsPanel extends AbstractGUIPanel { Materials materials = model.getMaterials(); if (!materials.isEmpty()) { for (Material material : materials) { - for (ApplicationModule module : modules) { - if (module.getMaterialsView() != null) { - module.getMaterialsView().updateDefaultMaterial(material); - } - } + ModulesUtil.updateMaterialFromDefaults(modules, material); updateSelection(material); saveMaterials(material); } } - } }); } @@ -205,11 +198,8 @@ public class MaterialsPanel extends AbstractGUIPanel { if (ms.length == 1) { Material material = ms[0]; centerPanelLayout.show(centerPanel, "material"); - parametersPanel.setMaterial(material.getDictionary()); - for (ApplicationModule module : modules) { - if (module.getMaterialsView() != null) - module.getMaterialsView().updateGUIFromModel(material); - } + parametersPanel.setMaterial(material); + ModulesUtil.updateGUIFromMaterial(modules, material); } else { centerPanelLayout.show(centerPanel, "none"); } @@ -219,14 +209,9 @@ public class MaterialsPanel extends AbstractGUIPanel { public void saveMaterials(Material... selection) { if (selection != null && selection.length == 1) { Material material = selection[0]; - Dictionary d = new Dictionary(parametersPanel.getMaterial(model)); - material.setDictionary(d); - - for (ApplicationModule module : modules) { - if (module.getMaterialsView() != null) { - module.getMaterialsView().updateModelFromGUI(material); - } - } +// Dictionary d = new Dictionary(parametersPanel.getMaterial(model).getDictionary()); +// material.setDictionary(d); +// ModulesUtil.updateMaterialFromGUI(modules, material); } } @@ -237,7 +222,7 @@ public class MaterialsPanel extends AbstractGUIPanel { private final class ChangeMaterialAction extends AbstractAction { public ChangeMaterialAction() { - super("Change Material"); + super(CHANGE_MATERIAL); } @Override @@ -300,27 +285,23 @@ public class MaterialsPanel extends AbstractGUIPanel { materialToChange = null; } - Dictionary dictionary = materialsDatabasePanel.getMaterial(); - - Material material = null; + Material material = materialsDatabasePanel.getMaterial(); - if (modelAlreadyContainsMaterial(dictionary.getName())) { - Dictionary newDict = new Dictionary(dictionary); - String newName = dictionary.getName() + COPY_OF_SUFFIX; - newDict.setName(newName); - newDict.add(MATERIAL_NAME_KEY, newName); - material = new Material(newName, newDict); - dictionary = newDict; + if (modelAlreadyContainsMaterial(material.getName())) { + String newName = material.getName() + COPY_OF_SUFFIX; + material = Material.newMaterial(newName, material); } else { - material = new Material(dictionary.getName(), dictionary); + material = Material.newMaterial(material); } + ModulesUtil.updateMaterialFromGUI(modules, material); + if (index != -1) { model.getMaterials().add(index, material); } else { model.getMaterials().add(material); } - parametersPanel.setMaterial(dictionary); + parametersPanel.setMaterial(material); return material; } diff --git a/src/eu/engys/gui/casesetup/phases/PhasesPanel.java b/src/eu/engys/gui/casesetup/phases/PhasesPanel.java index cb4da28..06be139 100644 --- a/src/eu/engys/gui/casesetup/phases/PhasesPanel.java +++ b/src/eu/engys/gui/casesetup/phases/PhasesPanel.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.casesetup.phases; import javax.swing.JComponent; diff --git a/src/eu/engys/gui/casesetup/phases/PhasesView.java b/src/eu/engys/gui/casesetup/phases/PhasesView.java index 7d87080..ce914bd 100644 --- a/src/eu/engys/gui/casesetup/phases/PhasesView.java +++ b/src/eu/engys/gui/casesetup/phases/PhasesView.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.casesetup.phases; import eu.engys.core.project.Model; diff --git a/src/eu/engys/gui/casesetup/run/StandardTable15.java b/src/eu/engys/gui/casesetup/run/StandardTable15.java index c56a3b8..2fed130 100644 --- a/src/eu/engys/gui/casesetup/run/StandardTable15.java +++ b/src/eu/engys/gui/casesetup/run/StandardTable15.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.casesetup.run; import java.util.Set; diff --git a/src/eu/engys/gui/casesetup/schemes/AdvectionSchemes.java b/src/eu/engys/gui/casesetup/schemes/AdvectionSchemes.java index ba13e0d..255919d 100644 --- a/src/eu/engys/gui/casesetup/schemes/AdvectionSchemes.java +++ b/src/eu/engys/gui/casesetup/schemes/AdvectionSchemes.java @@ -1,251 +1,119 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.casesetup.schemes; +import static eu.engys.core.project.system.ControlDict.FUNCTIONS_KEY; +import static eu.engys.core.project.system.FvSolution.CONSTANT_LIMITER_KEY; +import static eu.engys.core.project.system.FvSolution.COUPLED; +import static eu.engys.core.project.system.FvSolution.EQUATIONS_KEY; +import static eu.engys.core.project.system.FvSolution.HIGH_ORDER_KEY; +import static eu.engys.core.project.system.FvSolution.RELAXATION_FACTORS_KEY; +import static eu.engys.core.project.zero.fields.Fields.U; +import static eu.engys.gui.casesetup.schemes.CoupledSchemeTemplates.COUPLED_LES_SCHEMES; +import static eu.engys.gui.casesetup.schemes.SchemeUtils.searchTemplate; + import java.util.ArrayList; import java.util.List; -import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang.ArrayUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import eu.engys.core.dictionary.DefaultElement; import eu.engys.core.dictionary.Dictionary; import eu.engys.core.dictionary.ListField; import eu.engys.core.project.Model; import eu.engys.core.project.system.ControlDict; import eu.engys.core.project.system.FvSchemes; +import eu.engys.core.project.system.FvSolution; public class AdvectionSchemes { private static final Logger logger = LoggerFactory.getLogger(AdvectionSchemes.class); - static class SchemeTemplate { - private final String key; - private final String label; - private final Dictionary functions; + private static final String KEY = "key"; + private static final String LABEL = "label"; + private static final String FUNCTIONS = "functions"; + private static final String SCALAR = "scalar"; + private static final String VECTOR = "vector"; - public SchemeTemplate(String key, String label, Dictionary functions) { - this.key = key; - this.label = label; - this.functions = functions; - } + private List scalar = new ArrayList(); + private List vector = new ArrayList(); + private List coupledRANSVector = new ArrayList(); + private List coupledLESVector = new ArrayList(); - @Override - public String toString() { - return label; - } - - public boolean hasValue1() { - return key.contains("%f"); - } - - public boolean hasValue2() { - return key.contains("%f %f"); - } - - public boolean hasValue3() { - return StringUtils.countMatches(key, "%f") == 3; - } - - public boolean equalsIgnoringValues(String field, String schemeKey) { - String keyWithFieldName = key.replace("%s", gradName(field)); - - String[] schemeKeyTokens = schemeKey.split("\\s+"); - String[] keyWithFieldNameTokens = keyWithFieldName.split("\\s+"); - - if (schemeKeyTokens.length != keyWithFieldNameTokens.length) - return false; - - for (int i = 0; i < schemeKeyTokens.length; i++) { - if (schemeKeyTokens[i].equals(keyWithFieldNameTokens[i])) { - continue; - } else if (keyWithFieldNameTokens[i].equals("%f")) { - continue; - } else { - return false; - } - } - return true; - } - - public List extractValues(String field, String schemeKey) { - String keyWithFieldName = key.replace("%s", gradName(field)); - - String[] schemeKeyTokens = schemeKey.split("\\s+"); - String[] keyWithFieldNameTokens = keyWithFieldName.split("\\s+"); - - List values = new ArrayList(); - for (int i = 0; i < schemeKeyTokens.length; i++) { - if (keyWithFieldNameTokens[i].equals("%f")) { - values.add(Double.parseDouble(schemeKeyTokens[i])); - } - } - return values; - } - - public Dictionary getFunctions() { - return functions; - } - } - - static class Scheme { - private SchemeTemplate template; - private String field; - private double value1; - private double value2; - private double value3; - - public void setField(String field) { - this.field = field; - } - - public String getField() { - return field; - } - - public void setValue1(double value1) { - this.value1 = value1; - } - - public double getValue1() { - return value1; - } - - public void setValue2(double value2) { - this.value2 = value2; - } - - public double getValue2() { - return value2; - } - - public void setValue3(double value3) { - this.value3 = value3; - } - - public double getValue3() { - return value3; - } - - public void setTemplate(SchemeTemplate template) { - this.template = template; - } - - public SchemeTemplate getTemplate() { - return template; - } - } - - private ArrayList scalar = new ArrayList(); - private ArrayList vector = new ArrayList(); private Model model; + private CoupledSchemeTemplates coupledRansTemplates; + public AdvectionSchemes(Model model) { this.model = model; + this.coupledRansTemplates = new CoupledSchemeTemplates(); Dictionary defaultSchemes = model.getDefaults().getDefaultSchemes(); if (defaultSchemes != null) { - ListField scalarSchemes = defaultSchemes.getList("scalar"); - ListField vectorSchemes = defaultSchemes.getList("vector"); - for (DefaultElement el : scalarSchemes.getListElements()) { - if (el instanceof Dictionary) { - Dictionary d = (Dictionary) el; - addScalarScheme(new SchemeTemplate(d.lookup("key"), d.lookup("label"), d.subDict("functions"))); + ListField scalarSchemes = defaultSchemes.getList(SCALAR); + for (Dictionary d : scalarSchemes.getDictionaries()) { + scalar.add(new SchemeTemplate(d.lookup(KEY), d.lookup(LABEL), d.subDict(FUNCTIONS))); + } + + ListField vectorSchemes = defaultSchemes.getList(VECTOR); + for (Dictionary d : vectorSchemes.getDictionaries()) { + vector.add(new SchemeTemplate(d.lookup(KEY), d.lookup(LABEL), d.subDict(FUNCTIONS))); + } + + coupledRANSVector.addAll(coupledRansTemplates.getAll()); + + for (SchemeTemplate s : vector) { + if (ArrayUtils.contains(COUPLED_LES_SCHEMES, s.getKey())) { + coupledLESVector.add(s.copy()); } } - for (DefaultElement el : vectorSchemes.getListElements()) { - if (el instanceof Dictionary) { - Dictionary d = (Dictionary) el; - addVectorScheme(new SchemeTemplate(d.lookup("key"), d.lookup("label"), d.subDict("functions"))); - } - } } else { logger.warn("Advection schemes defaults not found!"); } } - public void addScalarScheme(SchemeTemplate scheme) { - scalar.add(scheme); - } + public Scheme load(String field) { + boolean coupled_U_RAS = model.getState().isCoupled() && model.getState().isRANS() && field.equals(U); + boolean coupled_LES = model.getState().isCoupled() && model.getState().isLES(); - public void addVectorScheme(SchemeTemplate scheme) { - vector.add(scheme); - } - - public List getScalarSchemes() { - return scalar; - } - - public List getVectorSchemes() { - return vector; - } - - public void writeScheme(Scheme scheme) { - FvSchemes fvSchemes = model.getProject().getSystemFolder().getFvSchemes(); - Dictionary divSchemes = fvSchemes.getDivSchemes(); - String gradName = gradName(scheme.field); - String divName = div(gradName); - String value = ""; - if (divSchemes != null && scheme.getTemplate() != null) { - String keyWithFieldName = scheme.template.key.replace("%s", gradName); - if (scheme.template.hasValue1()) { - if (scheme.template.hasValue3()) { - value = String.format(keyWithFieldName, scheme.value1, scheme.value2, scheme.value3); - } else if (scheme.template.hasValue2()) { - value = String.format(keyWithFieldName, scheme.value1, scheme.value2); - } else { - value = String.format(keyWithFieldName, scheme.value1); - } - } else { - value = keyWithFieldName; - } - divSchemes.add(divName, value); - - if (scheme.getTemplate().functions != null) { - ControlDict controlDict = model.getProject().getSystemFolder().getControlDict(); - controlDict.functionObjectsToDict(); - Dictionary functions = controlDict.subDict("functions"); - if (functions == null) { - functions = new Dictionary("functions"); - controlDict.add(functions); - } - functions.merge(scheme.getTemplate().functions); - controlDict.functionObjectsToList(); - } + if(coupled_U_RAS){ + return loadCoupledRAS(field); + } else if(coupled_LES){ + return loadCoupledLES(field); + } else { + return loadSegregated(field); } } - public Scheme readScheme(String field) { - String schemeKey = readSchemeKeyFor(div(gradName(field))); - SchemeTemplate template = searchTemplate(field, schemeKey); + private Scheme loadSegregated(String field) { Scheme scheme = new Scheme(); + String schemeKey = SchemeUtils.readSchemeKeyFor(field, model.getProject().getSystemFolder().getFvSchemes()); + SchemeTemplate template = searchTemplate(field, schemeKey, field.startsWith(U) ? vector : scalar); if (template != null) { List values = template.extractValues(field, schemeKey); scheme.setTemplate(template); @@ -256,45 +124,109 @@ public class AdvectionSchemes { } else { logger.error("Template Scheme {} not found for field {}", schemeKey, field); } - return scheme; } - private String readSchemeKeyFor(String divName) { - FvSchemes fvSchemes = model.getProject().getSystemFolder().getFvSchemes(); - Dictionary divSchemes = fvSchemes.getDivSchemes(); - if(divSchemes != null){ - if(divSchemes.found(divName)){ - return divSchemes.lookup(divName); - } else { - logger.error(String.format("Scheme Key not found for div '%s'", divName)); - return ""; - } + private Scheme loadCoupledRAS(String field) { + Scheme scheme = new Scheme(); + coupledRansTemplates.load(model.getProject().getSystemFolder().getFvSolution(), field, scheme); + return scheme; + } + + private Scheme loadCoupledLES(String field) { + Scheme scheme = new Scheme(); + String schemeKey = SchemeUtils.readSchemeKeyFor(field, model.getProject().getSystemFolder().getFvSchemes()); + SchemeTemplate template = searchTemplate(field, schemeKey, field.startsWith(U) ? coupledLESVector : scalar); + if (template != null) { + List values = template.extractValues(field, schemeKey); + scheme.setTemplate(template); + scheme.setField(field); + scheme.setValue1(values.size() > 0 ? values.get(0) : 0); + scheme.setValue2(values.size() > 1 ? values.get(1) : 0); + scheme.setValue3(values.size() > 2 ? values.get(2) : 0); } else { - logger.error("DivSchemes is NULL"); - return ""; + logger.error("Template Scheme {} not found for field {}", schemeKey, field); } + return scheme; } - private SchemeTemplate searchTemplate(String field, String scheme) { - List templates = field.startsWith("U") ? vector : scalar; - for (SchemeTemplate t : templates) { - if (t.equalsIgnoringValues(field, scheme)) { - return t; + public void save(Scheme scheme) { + boolean coupled_U_RAS = model.getState().isCoupled() && model.getState().isRANS() && scheme.getField().equals(U); + boolean coupled_U_LES = model.getState().isCoupled() && model.getState().isLES() && scheme.getField().equals(U); + + if (coupled_U_RAS) { + saveCoupledRAS(scheme); + } else { + saveSegregated(scheme); + if (coupled_U_LES) { + saveCoupledLES(scheme); } } - return null; } - private static String div(String gradName) { - return String.format("div(phi,%s)", gradName); + private void saveSegregated(Scheme scheme) { + FvSchemes fvSchemes = model.getProject().getSystemFolder().getFvSchemes(); + + Dictionary divSchemes = fvSchemes.getDivSchemes(); + String gradName = SchemeUtils.gradName(scheme.getField()); + String divName = SchemeUtils.divPhi(gradName); + String value = ""; + if (divSchemes != null && scheme.getTemplate() != null) { + String keyWithFieldName = scheme.getTemplate().getKey().replace("%s", gradName); + if (scheme.getTemplate().hasValue1()) { + if (scheme.getTemplate().hasValue3()) { + value = String.format(keyWithFieldName, scheme.getValue1(), scheme.getValue2(), scheme.getValue3()); + } else if (scheme.getTemplate().hasValue2()) { + value = String.format(keyWithFieldName, scheme.getValue1(), scheme.getValue2()); + } else { + value = String.format(keyWithFieldName, scheme.getValue1()); + } + } else { + value = keyWithFieldName; + } + divSchemes.add(divName, value); + + if (scheme.getTemplate().getFunctions() != null) { + ControlDict controlDict = model.getProject().getSystemFolder().getControlDict(); + Dictionary functions = controlDict.subDict(FUNCTIONS_KEY); + if (functions == null) { + functions = new Dictionary(FUNCTIONS_KEY); + controlDict.add(functions); + } + functions.merge(scheme.getTemplate().getFunctions()); + } + } } - private static String gradName(String field) { - if (field.equals("ILambda")) - return "Ii_h"; - else - return field; + private void saveCoupledRAS(Scheme scheme) { + FvSolution fvSolution = model.getProject().getSystemFolder().getFvSolution(); + coupledRansTemplates.save(fvSolution, scheme); + } + + private void saveCoupledLES(Scheme scheme) { + FvSolution fvSolution = model.getProject().getSystemFolder().getFvSolution(); + if (fvSolution.found(COUPLED)) { + fvSolution.subDict(COUPLED).add(CONSTANT_LIMITER_KEY, true); + } + if (fvSolution.found(RELAXATION_FACTORS_KEY) && fvSolution.subDict(RELAXATION_FACTORS_KEY).found(EQUATIONS_KEY)) { + fvSolution.subDict(RELAXATION_FACTORS_KEY).subDict(EQUATIONS_KEY).add(HIGH_ORDER_KEY, 0); + } + } + + public List getScalarSchemes() { + return scalar; + } + + public List getVectorSchemes() { + return vector; + } + + public List getCoupledVectorSchemesRANS() { + return coupledRANSVector; + } + + public List getCoupledVectorSchemesLES() { + return coupledLESVector; } } diff --git a/src/eu/engys/gui/casesetup/schemes/CoupledSchemeTemplates.java b/src/eu/engys/gui/casesetup/schemes/CoupledSchemeTemplates.java new file mode 100644 index 0000000..4c283f8 --- /dev/null +++ b/src/eu/engys/gui/casesetup/schemes/CoupledSchemeTemplates.java @@ -0,0 +1,133 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.gui.casesetup.schemes; + +import static eu.engys.core.project.system.FvSolution.CONSTANT_LIMITER_KEY; +import static eu.engys.core.project.system.FvSolution.COUPLED; +import static eu.engys.core.project.system.FvSolution.EQUATIONS_KEY; +import static eu.engys.core.project.system.FvSolution.HIGH_ORDER_KEY; +import static eu.engys.core.project.system.FvSolution.RELAXATION_FACTORS_KEY; + +import java.util.LinkedList; +import java.util.List; + +import eu.engys.core.dictionary.Dictionary; +import eu.engys.core.project.system.FvSolution; + +public class CoupledSchemeTemplates { + + public static final String DYNAMIC_LABEL = "Dynamic - 2nd Order"; + public static final String UPWIND_1ST_ORDER_LABEL = "Upwind - 1st Order"; + public static final String UPWIND_2ND_ORDER_LABEL = "Upwind - 2nd Order"; + public static final String BLENDED_LABEL = "Blended"; + + public static final String[] COUPLED_LES_SCHEMES = new String[]{ + "Gauss filteredLinear2V %f %f", + "Gauss LUSTV unlimitedGrad(U)", + "bounded Gauss localBlended filteredLinear2V %f %f LUSTV grad(U)" + }; + + public static final double DEFAULT_BLENDED_HIGH_ORDER = 0.75; + + private SchemeTemplate dynamicTemplate; + private SchemeTemplate upwind1stOrderTemplate; + private SchemeTemplate upwind2ndOrderTemplate; + private SchemeTemplate blendedTemplate; + + public CoupledSchemeTemplates() { + this.dynamicTemplate = new SchemeTemplate("", DYNAMIC_LABEL, null); + this.upwind1stOrderTemplate = new SchemeTemplate("", UPWIND_1ST_ORDER_LABEL, null); + this.upwind2ndOrderTemplate = new SchemeTemplate("", UPWIND_2ND_ORDER_LABEL, null); + this.blendedTemplate = new SchemeTemplate("", BLENDED_LABEL, null) { + @Override + public boolean hasValue1() { + return true; + } + }; + } + + public void load(FvSolution fvSolution, String field, Scheme scheme) { + if (fvSolution.found(COUPLED)) { + Dictionary coupledDict = fvSolution.subDict(COUPLED); + boolean constantLimiter = coupledDict.lookupBoolean(CONSTANT_LIMITER_KEY); + if (constantLimiter && fvSolution.found(RELAXATION_FACTORS_KEY) && fvSolution.subDict(RELAXATION_FACTORS_KEY).found(EQUATIONS_KEY)) { + Dictionary eqDict = fvSolution.subDict(RELAXATION_FACTORS_KEY).subDict(EQUATIONS_KEY); + if (eqDict.found(HIGH_ORDER_KEY)) { + double highOrder = eqDict.lookupDouble(HIGH_ORDER_KEY); + if (highOrder == 0) { + scheme.setTemplate(upwind1stOrderTemplate); + scheme.setValue1(DEFAULT_BLENDED_HIGH_ORDER); + } else if (highOrder == 1) { + scheme.setTemplate(upwind2ndOrderTemplate); + scheme.setValue1(DEFAULT_BLENDED_HIGH_ORDER); + } else { + scheme.setTemplate(blendedTemplate); + scheme.setValue1(highOrder); + } + } else { + scheme.setTemplate(dynamicTemplate); + scheme.setValue1(DEFAULT_BLENDED_HIGH_ORDER); + } + } else { + scheme.setTemplate(dynamicTemplate); + scheme.setValue1(DEFAULT_BLENDED_HIGH_ORDER); + } + } + scheme.setField(field); + } + + public void save(FvSolution fvSolution, Scheme scheme) { + if (fvSolution.found(COUPLED)) { + Dictionary coupledDict = fvSolution.subDict(COUPLED); + if (scheme.getTemplate().getLabel().equals(DYNAMIC_LABEL)) { + coupledDict.add(CONSTANT_LIMITER_KEY, false); + } else { + coupledDict.add(CONSTANT_LIMITER_KEY, true); + } + } + if (fvSolution.found(RELAXATION_FACTORS_KEY) && fvSolution.subDict(RELAXATION_FACTORS_KEY).found(EQUATIONS_KEY)) { + Dictionary equationsDict = fvSolution.subDict(RELAXATION_FACTORS_KEY).subDict(EQUATIONS_KEY); + if (scheme.getTemplate().getLabel().equals(UPWIND_1ST_ORDER_LABEL)) { + equationsDict.add(HIGH_ORDER_KEY, 0); + } else if (scheme.getTemplate().getLabel().equals(UPWIND_2ND_ORDER_LABEL)) { + equationsDict.add(HIGH_ORDER_KEY, 1); + } else if (scheme.getTemplate().getLabel().equals(BLENDED_LABEL)) { + equationsDict.add(HIGH_ORDER_KEY, scheme.getValue1()); + } else { + equationsDict.add(HIGH_ORDER_KEY, 1); + } + } + } + + public List getAll() { + List list = new LinkedList<>(); + list.add(dynamicTemplate); + list.add(upwind1stOrderTemplate); + list.add(upwind2ndOrderTemplate); + list.add(blendedTemplate); + return list; + } + +} diff --git a/src/eu/engys/gui/casesetup/schemes/NumericalSchemesPanel.java b/src/eu/engys/gui/casesetup/schemes/NumericalSchemesPanel.java index d44bb38..43d62ea 100644 --- a/src/eu/engys/gui/casesetup/schemes/NumericalSchemesPanel.java +++ b/src/eu/engys/gui/casesetup/schemes/NumericalSchemesPanel.java @@ -1,31 +1,36 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.casesetup.schemes; +import static eu.engys.core.project.system.FvSchemes.CORRECTED; +import static eu.engys.core.project.system.FvSchemes.DEFAULT; +import static eu.engys.core.project.system.FvSchemes.LAPLACIAN_SCHEMES; +import static eu.engys.core.project.system.FvSchemes.LIMITED; +import static eu.engys.core.project.system.FvSchemes.SN_GRAD_SCHEMES; +import static eu.engys.core.project.system.FvSchemes.UNCORRECTED; import static eu.engys.core.project.zero.fields.Fields.AOA; import static eu.engys.core.project.zero.fields.Fields.CO2; import static eu.engys.core.project.zero.fields.Fields.EPSILON; @@ -41,13 +46,10 @@ import static eu.engys.util.ui.ComponentsFactory.doubleField; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; -import java.text.ParseException; import java.util.LinkedHashMap; import java.util.Map; -import javax.swing.BorderFactory; import javax.swing.JComponent; -import javax.swing.JPanel; import com.google.inject.Inject; @@ -83,91 +85,33 @@ public class NumericalSchemesPanel extends DefaultGUIPanel { private PanelBuilder advectionBuilder; private AdvectionSchemes schemes; - + private Map schemePanelsMap = new LinkedHashMap(); @Inject public NumericalSchemesPanel(Model model) { super(NUMERICAL_SCHEMES, model); + this.schemes = new AdvectionSchemes(model); } @Override protected JComponent layoutComponents() { - laplaceModel = new DictionaryModel(new Dictionary("laplacianSchemes")); - snGradModel = new DictionaryModel(new Dictionary("snGradSchemes")); + this.laplaceModel = new DictionaryModel(new Dictionary(LAPLACIAN_SCHEMES)); + this.snGradModel = new DictionaryModel(new Dictionary(SN_GRAD_SCHEMES)); DoubleField field = doubleField(0.0, 1.0); - laplacianBuilder = new PanelBuilder(); - laplacianBuilder.addComponent(NON_ORTHOGONAL_CORRECTION_LABEL, field).addPropertyChangeListener(new LaplacianFieldHandler("default", field)); - try { - field.commitEdit(); - } catch (ParseException e) { - e.printStackTrace(); - } + this.laplacianBuilder = new PanelBuilder(); + this.laplacianBuilder.addComponent(NON_ORTHOGONAL_CORRECTION_LABEL, field).addPropertyChangeListener(new LaplacianFieldHandler(DEFAULT, field)); - schemes = new AdvectionSchemes(model); - - advectionBuilder = new PanelBuilder(); - JPanel advectionPanel = advectionBuilder.removeMargins().getPanel(); - advectionPanel.setBorder(BorderFactory.createTitledBorder(ADVECTION_LABEL)); - advectionPanel.setName(ADVECTION_LABEL); - - JPanel laplacianPanel = laplacianBuilder.removeMargins().getPanel(); - laplacianPanel.setBorder(BorderFactory.createTitledBorder(LAPLACIAN_LABEL)); - laplacianPanel.setName(LAPLACIAN_LABEL); + this.advectionBuilder = new PanelBuilder(); PanelBuilder builder = new PanelBuilder(); - builder.addComponent(advectionPanel); - builder.addComponent(laplacianPanel); + builder.addComponent(advectionBuilder.removeMargins().withTitle(ADVECTION_LABEL).withName(ADVECTION_LABEL).getPanel()); + builder.addComponent(laplacianBuilder.removeMargins().withTitle(LAPLACIAN_LABEL).withName(LAPLACIAN_LABEL).getPanel()); return builder.removeMargins().getPanel(); } - private void rebuildPanel() { - if (model.getProject() != null) { - FvSchemes fvSchemes = model.getProject().getSystemFolder().getFvSchemes(); - if (fvSchemes != null) { - Dictionary divSchemes = fvSchemes.getDivSchemes(); - Dictionary laplacianSchemes = fvSchemes.getLaplacianSchemes(); - - if (divSchemes != null && laplacianSchemes != null) { - - laplaceModel.setDictionary(laplacianSchemes); - - advectionBuilder.clear(); - schemePanelsMap.clear(); - - buildFieldPanel(advectionBuilder, U); - for (Field field : model.getFields().getMultiphaseUFields()) { - buildFieldPanel(advectionBuilder, field.getName()); - } - - buildFieldPanel(advectionBuilder, K); - buildFieldPanel(advectionBuilder, EPSILON); - buildFieldPanel(advectionBuilder, OMEGA); - buildFieldPanel(advectionBuilder, NU_TILDA); - buildFieldPanel(advectionBuilder, T); - buildFieldPanel(advectionBuilder, W); - buildFieldPanel(advectionBuilder, ILAMBDA); - buildFieldPanel(advectionBuilder, CO2); - buildFieldPanel(advectionBuilder, AOA); - buildFieldPanel(advectionBuilder, SMOKE); - } - } - } - } - - private void buildFieldPanel(PanelBuilder advectionBuilder, String fieldName) { - - Fields fields = getModel().getFields(); - if (fields.containsKey(fieldName)) { - SchemePanel schemePanel = new SchemePanel(schemes, fieldName); - schemePanel.load(); - schemePanelsMap.put(fieldName, schemePanel); - advectionBuilder.addComponent(fieldName, schemePanel.getPanel()); - } - } - @Override public void load() { rebuildPanel(); @@ -204,7 +148,44 @@ public class NumericalSchemesPanel extends DefaultGUIPanel { }); } - class LaplacianFieldHandler implements PropertyChangeListener, DictionaryListener { + private void rebuildPanel() { + if (model.getProject() != null) { + FvSchemes fvSchemes = model.getProject().getSystemFolder().getFvSchemes(); + if (fvSchemes != null && fvSchemes.getLaplacianSchemes() != null) { + laplaceModel.setDictionary(fvSchemes.getLaplacianSchemes()); + + advectionBuilder.clear(); + schemePanelsMap.clear(); + + buildFieldPanel(U); + for (Field field : model.getFields().getMultiphaseUFields()) { + buildFieldPanel(field.getName()); + } + buildFieldPanel(K); + buildFieldPanel(EPSILON); + buildFieldPanel(OMEGA); + buildFieldPanel(NU_TILDA); + buildFieldPanel(T); + buildFieldPanel(W); + buildFieldPanel(ILAMBDA); + buildFieldPanel(CO2); + buildFieldPanel(AOA); + buildFieldPanel(SMOKE); + } + } + } + + private void buildFieldPanel(String fieldName) { + Fields fields = getModel().getFields(); + if (fields.containsKey(fieldName)) { + SchemePanel schemePanel = new SchemePanel(model, schemes, fieldName); + schemePanel.load(); + schemePanelsMap.put(fieldName, schemePanel); + advectionBuilder.addComponent(fieldName, schemePanel.getPanel()); + } + } + + private class LaplacianFieldHandler implements PropertyChangeListener, DictionaryListener { private String key; private DoubleField field; @@ -222,16 +203,16 @@ public class NumericalSchemesPanel extends DefaultGUIPanel { double value = field.getDoubleValue(); if (value == 0) { laplacianValue = GAUSS_LINEAR_UNCORRECTED; - snGradValue = "uncorrected"; + snGradValue = UNCORRECTED; } else if (value == 1) { laplacianValue = GAUSS_LINEAR_CORRECTED; - snGradValue = "corrected"; + snGradValue = CORRECTED; } else { laplacianValue = GAUSS_LINEAR_LIMITED + " " + Double.toString(value); - snGradValue = "limited" + " " + Double.toString(value); + snGradValue = LIMITED + " " + Double.toString(value); } - laplaceModel.getDictionary().add("default", laplacianValue); - snGradModel.getDictionary().add("default", snGradValue); + laplaceModel.getDictionary().add(DEFAULT, laplacianValue); + snGradModel.getDictionary().add(DEFAULT, snGradValue); } } diff --git a/src/eu/engys/gui/casesetup/schemes/Scheme.java b/src/eu/engys/gui/casesetup/schemes/Scheme.java new file mode 100644 index 0000000..655f89c --- /dev/null +++ b/src/eu/engys/gui/casesetup/schemes/Scheme.java @@ -0,0 +1,74 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.gui.casesetup.schemes; + +public class Scheme { + + private SchemeTemplate template; + private String field; + private double value1; + private double value2; + private double value3; + + public void setField(String field) { + this.field = field; + } + + public String getField() { + return field; + } + + public void setValue1(double value1) { + this.value1 = value1; + } + + public double getValue1() { + return value1; + } + + public void setValue2(double value2) { + this.value2 = value2; + } + + public double getValue2() { + return value2; + } + + public void setValue3(double value3) { + this.value3 = value3; + } + + public double getValue3() { + return value3; + } + + public void setTemplate(SchemeTemplate template) { + this.template = template; + } + + public SchemeTemplate getTemplate() { + return template; + } +} diff --git a/src/eu/engys/gui/casesetup/schemes/SchemePanel.java b/src/eu/engys/gui/casesetup/schemes/SchemePanel.java index 7b993e1..1b92863 100644 --- a/src/eu/engys/gui/casesetup/schemes/SchemePanel.java +++ b/src/eu/engys/gui/casesetup/schemes/SchemePanel.java @@ -1,43 +1,42 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.casesetup.schemes; +import static eu.engys.core.project.zero.fields.Fields.U; import static eu.engys.util.ui.ComponentsFactory.doubleField; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.util.List; import javax.swing.JComboBox; import javax.swing.JComponent; -import net.java.dev.designgridlayout.Componentizer; -import eu.engys.gui.casesetup.schemes.AdvectionSchemes.Scheme; -import eu.engys.gui.casesetup.schemes.AdvectionSchemes.SchemeTemplate; +import eu.engys.core.project.Model; import eu.engys.util.ui.textfields.DoubleField; +import net.java.dev.designgridlayout.Componentizer; public class SchemePanel { @@ -47,16 +46,60 @@ public class SchemePanel { private DoubleField value3; private JComboBox choice; private AdvectionSchemes schemes; + private Model model; - public SchemePanel(AdvectionSchemes schemes, String fieldName) { + public SchemePanel(Model model, AdvectionSchemes schemes, String fieldName) { + this.model = model; this.schemes = schemes; this.fieldName = fieldName; - layoutComponents(); } + private void layoutComponents() { + this.value1 = doubleField(0.0, 1.0); + this.value1.setVisible(false); + this.value1.setName(fieldName + ".0"); + + this.value2 = doubleField(0.0, 1.0); + this.value2.setVisible(false); + this.value2.setName(fieldName + ".1"); + + this.value3 = doubleField(0.0, 1.0); + this.value3.setVisible(false); + this.value3.setName(fieldName + ".2"); + + this.choice = new JComboBox(); + this.choice.setName(fieldName); + + if (fieldName.equals(U)) { + if (model.getState().isCoupled()) { + if (model.getState().isRANS()) { + addAllChoices(schemes.getCoupledVectorSchemesRANS()); + } else if (model.getState().isLES()) { + addAllChoices(schemes.getCoupledVectorSchemesLES()); + } + } else { + addAllChoices(schemes.getVectorSchemes()); + } + } else { + addAllChoices(schemes.getScalarSchemes()); + } + + this.choice.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + SchemeTemplate template = choice.getItemAt(choice.getSelectedIndex()); + if (template != null) { + value1.setVisible(template.hasValue1()); + value2.setVisible(template.hasValue2()); + value3.setVisible(template.hasValue3()); + } + } + }); + } + void load() { - Scheme scheme = schemes.readScheme(fieldName); + Scheme scheme = schemes.load(fieldName); choice.setSelectedItem(scheme.getTemplate()); value1.setDoubleValue(scheme.getValue1()); value2.setDoubleValue(scheme.getValue2()); @@ -70,64 +113,13 @@ public class SchemePanel { scheme.setValue1(value1.getDoubleValue()); scheme.setValue2(value2.getDoubleValue()); scheme.setValue3(value3.getDoubleValue()); - schemes.writeScheme(scheme); + schemes.save(scheme); } - private void layoutComponents() { - value1 = doubleField(); - value2 = doubleField(); - value3 = doubleField(); - - value1.setVisible(false); - value2.setVisible(false); - value3.setVisible(false); - - value1.setName(fieldName + ".0"); - value2.setName(fieldName + ".1"); - value3.setName(fieldName + ".2"); - - choice = new JComboBox(); - choice.setName(fieldName); - - if (fieldName.equals("U")) { - for (SchemeTemplate scheme : schemes.getVectorSchemes()) { - choice.addItem(scheme); - } - } else { - for (SchemeTemplate scheme : schemes.getScalarSchemes()) { - choice.addItem(scheme); - } + private void addAllChoices(List templates) { + for (SchemeTemplate template : templates) { + choice.addItem(template); } - - choice.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - SchemeTemplate scheme = choice.getItemAt(choice.getSelectedIndex()); - if (scheme != null) { - value1.setVisible(scheme.hasValue1()); - value2.setVisible(scheme.hasValue2()); - value3.setVisible(scheme.hasValue3()); - } - } - }); - - // PropertyChangeListener listener = new PropertyChangeListener() { - // @Override - // public void propertyChange(PropertyChangeEvent evt) { - // if (evt.getPropertyName().equals("value")) { - // choice.setSelectedIndex(choice.getSelectedIndex()); - // if (choice.getSelectedIndex() == 5) { - // choice.setEnabled(false); - // } else { - // choice.setEnabled(true); - // } - // } - // } - // }; - - // value1.addPropertyChangeListener(listener); - // value2.addPropertyChangeListener(listener); - // advectionBuilder.addComponent(name, row); } JComponent getPanel() { diff --git a/src/eu/engys/gui/casesetup/schemes/SchemeTemplate.java b/src/eu/engys/gui/casesetup/schemes/SchemeTemplate.java new file mode 100644 index 0000000..b064621 --- /dev/null +++ b/src/eu/engys/gui/casesetup/schemes/SchemeTemplate.java @@ -0,0 +1,114 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.gui.casesetup.schemes; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.commons.lang.StringUtils; + +import eu.engys.core.dictionary.Dictionary; + +public class SchemeTemplate { + + private final String key; + private final String label; + private final Dictionary functions; + + public SchemeTemplate(String key, String label, Dictionary functions) { + this.key = key; + this.label = label; + this.functions = functions; + } + + public SchemeTemplate copy(){ + return new SchemeTemplate(key, label, functions == null ? null : new Dictionary(functions)); + } + + @Override + public String toString() { + return label; + } + + public boolean hasValue1() { + return key.contains("%f"); + } + + public boolean hasValue2() { + return key.contains("%f %f"); + } + + public boolean hasValue3() { + return StringUtils.countMatches(key, "%f") == 3; + } + + public boolean equalsIgnoringValues(String field, String schemeKey) { + String keyWithFieldName = key.replace("%s", SchemeUtils.gradName(field)); + + String[] schemeKeyTokens = schemeKey.split("\\s+"); + String[] keyWithFieldNameTokens = keyWithFieldName.split("\\s+"); + + if (schemeKeyTokens.length != keyWithFieldNameTokens.length) + return false; + + for (int i = 0; i < schemeKeyTokens.length; i++) { + if (schemeKeyTokens[i].equals(keyWithFieldNameTokens[i])) { + continue; + } else if (keyWithFieldNameTokens[i].equals("%f")) { + continue; + } else { + return false; + } + } + return true; + } + + public List extractValues(String field, String schemeKey) { + String keyWithFieldName = key.replace("%s", SchemeUtils.gradName(field)); + + String[] schemeKeyTokens = schemeKey.split("\\s+"); + String[] keyWithFieldNameTokens = keyWithFieldName.split("\\s+"); + + List values = new ArrayList(); + for (int i = 0; i < schemeKeyTokens.length; i++) { + if (keyWithFieldNameTokens[i].equals("%f")) { + values.add(Double.parseDouble(schemeKeyTokens[i])); + } + } + return values; + } + + public String getKey() { + return key; + } + + public String getLabel() { + return label; + } + + public Dictionary getFunctions() { + return functions; + } +} diff --git a/src/eu/engys/gui/casesetup/schemes/SchemeUtils.java b/src/eu/engys/gui/casesetup/schemes/SchemeUtils.java new file mode 100644 index 0000000..29c28df --- /dev/null +++ b/src/eu/engys/gui/casesetup/schemes/SchemeUtils.java @@ -0,0 +1,76 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.gui.casesetup.schemes; + +import java.util.List; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import eu.engys.core.dictionary.Dictionary; +import eu.engys.core.project.system.FvSchemes; + +public class SchemeUtils { + + private static final Logger logger = LoggerFactory.getLogger(SchemeUtils.class); + + public static String divPhi(String gradName) { + return String.format("div(phi,%s)", gradName); + } + + public static String gradName(String field) { + if (field.equals("ILambda")) + return "Ii_h"; + else + return field; + } + + public static String readSchemeKeyFor(String field, FvSchemes fvSchemes) { + String divName = divPhi(gradName(field)); + + Dictionary divSchemes = fvSchemes.getDivSchemes(); + if (divSchemes != null) { + if (divSchemes.found(divName)) { + return divSchemes.lookup(divName); + } else { + logger.error(String.format("Scheme Key not found for div '%s'", divName)); + return ""; + } + } else { + logger.error("DivSchemes is NULL"); + return ""; + } + } + + public static SchemeTemplate searchTemplate(String field, String scheme, List templates) { + for (SchemeTemplate t : templates) { + if (t.equalsIgnoringValues(field, scheme)) { + return t; + } + } + return null; + } + +} diff --git a/src/eu/engys/gui/casesetup/solution/AbstractSolutionModellingPanel.java b/src/eu/engys/gui/casesetup/solution/AbstractSolutionModellingPanel.java index e8d0fcf..0958402 100644 --- a/src/eu/engys/gui/casesetup/solution/AbstractSolutionModellingPanel.java +++ b/src/eu/engys/gui/casesetup/solution/AbstractSolutionModellingPanel.java @@ -1,30 +1,31 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.casesetup.solution; +import static eu.engys.util.ui.ChooserPanel.SELECTION_PROPERTY; + import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.Insets; @@ -48,6 +49,7 @@ import eu.engys.core.modules.ModulesUtil; import eu.engys.core.modules.solutionmodelling.SolutionModellingPanel; import eu.engys.core.project.Model; import eu.engys.core.project.TurbulenceModel; +import eu.engys.core.project.state.AdjointState; import eu.engys.core.project.state.BuoyancyBuilder; import eu.engys.core.project.state.Flow; import eu.engys.core.project.state.Mach; @@ -67,16 +69,25 @@ import eu.engys.gui.casesetup.solution.panels.GPanel; import eu.engys.gui.casesetup.solution.panels.MultiphasePanel; import eu.engys.gui.casesetup.solution.panels.SolutionStatePanel; import eu.engys.gui.casesetup.solution.panels.TurbulencePanel; +import eu.engys.gui.events.EventManager; +import eu.engys.gui.events.EventManager.Event; +import eu.engys.gui.events.EventManager.GenericEventListener; +import eu.engys.gui.events.application.ApplicationEvent; +import eu.engys.gui.events.application.LicenseChangedEvent; import eu.engys.util.ui.ChooserPanel; +import eu.engys.util.ui.ExecUtil; import eu.engys.util.ui.UiUtil; +import eu.engys.util.ui.builder.PanelBuilder; -public abstract class AbstractSolutionModellingPanel extends DefaultGUIPanel implements SolutionModellingPanel { +public abstract class AbstractSolutionModellingPanel extends DefaultGUIPanel implements SolutionModellingPanel, GenericEventListener { private static final Logger logger = LoggerFactory.getLogger(AbstractSolutionModellingPanel.class); private static final String STATE_CHANGED_WARNING = "Solution state has been changed.\nAll fields default settings are going to be reset now.\nContinue?"; public static final String SOLUTION_MODELLING = "Solution Modelling"; + + private static final String DYNAMIC = "Dynamic Mesh"; protected Set modules; private Table15 solversTable; @@ -91,6 +102,21 @@ public abstract class AbstractSolutionModellingPanel extends DefaultGUIPanel imp super(SOLUTION_MODELLING, model); this.solversTable = solversTable; this.modules = modules; + EventManager.registerEventListener(this, ApplicationEvent.class); + } + + @Override + public void eventTriggered(Object obj, final Event event) { + if (event instanceof LicenseChangedEvent) { + ExecUtil.invokeLater(new Runnable() { + @Override + public void run() { + for (ApplicationModule m : modules) { + m.getSolutionView().handleLicenseChanged(solutionStatePanel.getSolutionState()); + } + } + }); + } } @Override @@ -102,68 +128,43 @@ public abstract class AbstractSolutionModellingPanel extends DefaultGUIPanel imp turbulencePanel = new TurbulencePanel(); multiphasePanel = createMultiphasePanel(); - final PropertyChangeListener multiphaseListener = new PropertyChangeListener() { - @Override - public void propertyChange(PropertyChangeEvent evt) { - if (evt.getPropertyName().equals("selection")) { - fix(); - } - } - }; - multiphasePanel.setListener(multiphaseListener); + multiphasePanel.setListener(new MultiphaseListener()); thermalPanel = createThermalPanel(); - ActionListener thermalListener = new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - fix(); - } - }; - thermalPanel.setThermalListener(thermalListener); + thermalPanel.setListener(new ThermalListener()); gPanel = new GPanel(); - PropertyChangeListener solutionStateListener = new PropertyChangeListener() { - @Override - public void propertyChange(PropertyChangeEvent evt) { - if (evt.getPropertyName().equals("selection")) { - multiphasePanel.removeListener(); - thermalPanel.removeListeners(); - - fix(); - - thermalPanel.addListeners(); - multiphasePanel.addListener(); - } - } - }; - solutionStatePanel.setListener(solutionStateListener); + solutionStatePanel.setListener(new SolutionStateListener()); + + PanelBuilder dynamicBuilder = new PanelBuilder(); for (ApplicationModule m : modules) { - m.getSolutionView().buildDynamic(getDynamicBuilder()); + m.getSolutionView().buildDynamic(dynamicBuilder); + } + for (ApplicationModule m : modules) { + m.getSolutionView().buildAdjoint(getAdjointBuilder()); + m.getSolutionView().setAdjointListener(new AdjointListener()); } - for (ApplicationModule m : modules) { m.getSolutionView().buildScalar(this); } - - topPanel.add(solutionStatePanel, new GridBagConstraints(0, 0, 2, 1, 1.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); - topPanel.add(turbulencePanel, new GridBagConstraints(0, 1, 2, 1, 1.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); - - topPanel.add(multiphasePanel, new GridBagConstraints(0, 2, 2, 1, 1.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); - topPanel.add(thermalPanel, new GridBagConstraints(0, 3, 2, 1, 1.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); - topPanel.add(gPanel, new GridBagConstraints(0, 4, 2, 1, 1.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); - topPanel.add(getDynamicPanel(), new GridBagConstraints(0, 5, 2, 1, 1.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); - topPanel.add(getScalarsPanel(), new GridBagConstraints(0, 6, 2, 1, 1.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); - - topPanel.add(new JLabel(), new GridBagConstraints(0, 7, 2, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); + JPanel dynamicPanel = dynamicBuilder.withTitle(DYNAMIC).getPanel(); + + topPanel.add(solutionStatePanel, new GridBagConstraints(0, 0, 2, 1, 1.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); + topPanel.add(turbulencePanel, new GridBagConstraints(0, 1, 2, 1, 1.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); + topPanel.add(multiphasePanel, new GridBagConstraints(0, 2, 2, 1, 1.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); + topPanel.add(thermalPanel, new GridBagConstraints(0, 3, 2, 1, 1.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); + topPanel.add(gPanel, new GridBagConstraints(0, 4, 2, 1, 1.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); + topPanel.add(dynamicPanel, new GridBagConstraints(0, 5, 1, 1, 1.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); + topPanel.add(getAdjointPanel(), new GridBagConstraints(0, 6, 1, 1, 1.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); + topPanel.add(getScalarsPanel(), new GridBagConstraints(0, 7, 2, 1, 1.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); + topPanel.add(new JLabel(), new GridBagConstraints(0, 8, 2, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); fix(); return topPanel; } - - protected abstract boolean isSolutionStatePanelVisible(); @Override public void load() { @@ -261,7 +262,7 @@ public abstract class AbstractSolutionModellingPanel extends DefaultGUIPanel imp } for (ApplicationModule m : modules) { - if (m.getSolutionView().hasChanged()) { + if (m.getSolutionView().hasChanged(state)) { return true; } } @@ -317,13 +318,13 @@ public abstract class AbstractSolutionModellingPanel extends DefaultGUIPanel imp state.setPhases(phases); } - ModulesUtil.updateStateFromGUI(modules); + ModulesUtil.updateStateFromGUI(modules, state); // Solver Families Set solverFamilies = new LinkedHashSet(); solversTable.updateSolverFamilies(state, solverFamilies); ModulesUtil.updateSolverFamilies(modules, state, solverFamilies); - + if (solverFamilies.isEmpty()) { state.setSolverFamily(SolverFamily.NONE); } else { @@ -345,8 +346,8 @@ public abstract class AbstractSolutionModellingPanel extends DefaultGUIPanel imp multiphasePanel.updateFromState(state); - thermalPanel.updateEnergyFromState(state); - thermalPanel.updateBuoyancyFromState(state); + thermalPanel.updateFromState(state); + gPanel.updateFromState(model, state); turbulencePanel.updateFromState(model, state); @@ -359,6 +360,7 @@ public abstract class AbstractSolutionModellingPanel extends DefaultGUIPanel imp private void fix() { SolutionState ss = solutionStatePanel.getSolutionState(); solutionStatePanel.fix(ss); + ss = solutionStatePanel.getSolutionState(); multiphasePanel.fixSolutionState(ss); for (ApplicationModule m : modules) { m.getSolutionView().fixSolutionState(ss); @@ -379,19 +381,33 @@ public abstract class AbstractSolutionModellingPanel extends DefaultGUIPanel imp m.getSolutionView().fixThermal(ss, ts); } + AdjointState as = new AdjointState(); + for (ApplicationModule m : modules) { + m.getSolutionView().updateAdjointState(as); + } + for (ApplicationModule m : modules) { + m.getSolutionView().fixAdjoint(as); + } + turbulencePanel.fixSolutionState(model, ss); } - private void removeListeners() { - multiphasePanel.removeListener(); - thermalPanel.removeListeners(); - solutionStatePanel.removeListeners(); + private void addListeners() { + solutionStatePanel.addListeners(); + thermalPanel.addListeners(); + multiphasePanel.addListener(); + for (ApplicationModule m : modules) { + m.getSolutionView().addAdjointListener(); + } } - private void addListeners() { - multiphasePanel.addListener(); - thermalPanel.addListeners(); - solutionStatePanel.addListeners(); + private void removeListeners() { + solutionStatePanel.removeListeners(); + thermalPanel.removeListeners(); + multiphasePanel.removeListener(); + for (ApplicationModule m : modules) { + m.getSolutionView().removeAdjointListener(); + } } @Override @@ -404,11 +420,13 @@ public abstract class AbstractSolutionModellingPanel extends DefaultGUIPanel imp return multiphasePanel; } + protected abstract boolean isSolutionStatePanelVisible(); + protected abstract AbstractThermalPanel createThermalPanel(); protected abstract MultiphasePanel createMultiphasePanel(); - protected abstract JComponent getDynamicPanel(); + protected abstract JComponent getAdjointPanel(); protected abstract JComponent getScalarsPanel(); @@ -416,4 +434,50 @@ public abstract class AbstractSolutionModellingPanel extends DefaultGUIPanel imp public void setModules(Set modules) { this.modules = modules; } + + private class SolutionStateListener implements PropertyChangeListener { + @Override + public void propertyChange(PropertyChangeEvent evt) { + if (evt.getPropertyName().equals(SELECTION_PROPERTY)) { + multiphasePanel.removeListener(); + thermalPanel.removeListeners(); + for (ApplicationModule m : modules) { + m.getSolutionView().removeAdjointListener(); + } + + fix(); + + for (ApplicationModule m : modules) { + m.getSolutionView().addAdjointListener(); + } + thermalPanel.addListeners(); + multiphasePanel.addListener(); + } + } + } + + private class MultiphaseListener implements PropertyChangeListener { + @Override + public void propertyChange(PropertyChangeEvent evt) { + if (evt.getPropertyName().equals(SELECTION_PROPERTY)) { + fix(); + } + } + } + + private class ThermalListener implements ActionListener { + @Override + public void actionPerformed(ActionEvent e) { + fix(); + } + + } + + private class AdjointListener implements ActionListener { + @Override + public void actionPerformed(ActionEvent e) { + fix(); + } + } + } diff --git a/src/eu/engys/gui/casesetup/solution/StandardSolutionModellingPanel.java b/src/eu/engys/gui/casesetup/solution/StandardSolutionModellingPanel.java index 09ec993..6370282 100644 --- a/src/eu/engys/gui/casesetup/solution/StandardSolutionModellingPanel.java +++ b/src/eu/engys/gui/casesetup/solution/StandardSolutionModellingPanel.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.casesetup.solution; import java.util.Set; @@ -68,6 +67,7 @@ public class StandardSolutionModellingPanel extends AbstractSolutionModellingPan phasesNumber.setEnabled(false); } } + }; } @@ -82,7 +82,7 @@ public class StandardSolutionModellingPanel extends AbstractSolutionModellingPan } @Override - public PanelBuilder getDynamicBuilder() { + public PanelBuilder getAdjointBuilder() { return new PanelBuilder(); } @@ -95,9 +95,9 @@ public class StandardSolutionModellingPanel extends AbstractSolutionModellingPan public PanelBuilder getScalarsBuilderRight() { return new PanelBuilder(); } - + @Override - protected JComponent getDynamicPanel() { + protected JComponent getAdjointPanel() { return new JLabel(); } diff --git a/src/eu/engys/gui/casesetup/solution/StandardThermalPanel.java b/src/eu/engys/gui/casesetup/solution/StandardThermalPanel.java index e105a9f..8b9ef77 100644 --- a/src/eu/engys/gui/casesetup/solution/StandardThermalPanel.java +++ b/src/eu/engys/gui/casesetup/solution/StandardThermalPanel.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.casesetup.solution; import java.util.Set; @@ -58,7 +57,7 @@ public class StandardThermalPanel extends AbstractThermalPanel { } else { energy.setEnabled(false); } - + if (ss.areSolverTypeAndTimeAndFlowAndTurbulenceChoosen()) { if (ss.isTransient() && ss.isLES()) { if (energy.isSelected()) { diff --git a/src/eu/engys/gui/casesetup/solution/panels/AbstractThermalPanel.java b/src/eu/engys/gui/casesetup/solution/panels/AbstractThermalPanel.java index e115e7a..e24977d 100644 --- a/src/eu/engys/gui/casesetup/solution/panels/AbstractThermalPanel.java +++ b/src/eu/engys/gui/casesetup/solution/panels/AbstractThermalPanel.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.casesetup.solution.panels; import java.awt.BorderLayout; @@ -42,10 +41,6 @@ import eu.engys.util.ui.builder.PanelBuilder; public abstract class AbstractThermalPanel extends JPanel { - public static final String BUOYANCY = "Buoyancy"; - public static final String ENERGY = "Energy"; - public static final String THERMAL = "Thermal"; - private Set modules; private ActionListener listener; protected JCheckBox energy; @@ -57,23 +52,22 @@ public abstract class AbstractThermalPanel extends JPanel { layoutComponents(); } - private void layoutComponents() { PanelBuilder builder = new PanelBuilder(); - this.energy = (JCheckBox) builder.startCheck(ENERGY); + this.energy = (JCheckBox) builder.startCheck(ThermalState.ENERGY); - this.buoyancy = (JCheckBox) builder.startCheck(BUOYANCY); - buoyancy.setName(BUOYANCY); + this.buoyancy = (JCheckBox) builder.startCheck(ThermalState.BUOYANCY); + buoyancy.setName(ThermalState.BUOYANCY); builder.endCheck(); for (ApplicationModule m : modules) { m.getSolutionView().buildThermal(builder); } - + builder.endCheck(false); - + JPanel panel = builder.getPanel(); - panel.setBorder(BorderFactory.createTitledBorder(AbstractThermalPanel.THERMAL)); + panel.setBorder(BorderFactory.createTitledBorder(ThermalState.THERMAL)); add(panel, BorderLayout.CENTER); } @@ -100,7 +94,12 @@ public abstract class AbstractThermalPanel extends JPanel { } } - public void updateEnergyFromState(State state) { + public void updateFromState(State state) { + updateEnergyFromState(state); + updateBuoyancyFromState(state); + } + + private void updateEnergyFromState(State state) { boolean energyEnabled = energy.isEnabled(); energy.setEnabled(true); if (state.isEnergy()) { @@ -116,7 +115,7 @@ public abstract class AbstractThermalPanel extends JPanel { fixEnergy(new SolutionState(state), state.getMultiphaseModel()); } - public void updateBuoyancyFromState(State state) { + private void updateBuoyancyFromState(State state) { boolean buoyancyEnabled = buoyancy.isEnabled(); buoyancy.setEnabled(true); if (state.isBuoyant()) { @@ -131,34 +130,46 @@ public abstract class AbstractThermalPanel extends JPanel { buoyancy.setEnabled(buoyancyEnabled); fixBuoyancy(new SolutionState(state), state.getMultiphaseModel()); } - + public ThermalState getThermalState() { ThermalState ts = new ThermalState(); ts.setEnergy(energy.isSelected()); ts.setBuoyancy(buoyancy.isSelected()); + for (ApplicationModule m : modules) { + m.getSolutionView().updateThermalState(ts); + } return ts; } - + public void removeListeners() { energy.removeActionListener(listener); buoyancy.removeActionListener(listener); + for (ApplicationModule m : modules) { + m.getSolutionView().removeThermalListener(); + } } public void addListeners() { energy.addActionListener(listener); buoyancy.addActionListener(listener); + for (ApplicationModule m : modules) { + m.getSolutionView().addThermalListener(); + } } - - public void setThermalListener(ActionListener listener) { + + public void setListener(ActionListener listener) { this.listener = listener; + for (ApplicationModule m : modules) { + m.getSolutionView().setThermalListener(listener); + } } - - public boolean isEnergySelected(){ + + public boolean isEnergySelected() { return energy.isSelected(); } - public boolean isBuoyancySelected(){ + public boolean isBuoyancySelected() { return buoyancy.isSelected(); } - + } diff --git a/src/eu/engys/gui/casesetup/solution/panels/FlowPanel.java b/src/eu/engys/gui/casesetup/solution/panels/FlowPanel.java index 810d495..4323efb 100644 --- a/src/eu/engys/gui/casesetup/solution/panels/FlowPanel.java +++ b/src/eu/engys/gui/casesetup/solution/panels/FlowPanel.java @@ -1,32 +1,29 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.casesetup.solution.panels; -import static eu.engys.core.project.state.SolutionState.COMPRESSIBLE; -import static eu.engys.core.project.state.SolutionState.INCOMPRESSIBLE; import eu.engys.core.project.state.Flow; import eu.engys.core.project.state.State; import eu.engys.util.ui.ChooserPanel; @@ -37,15 +34,15 @@ public class FlowPanel extends ChooserPanel { public FlowPanel() { super(FLOW); - addChoice(COMPRESSIBLE); - addChoice(INCOMPRESSIBLE); + addChoice(Flow.COMPRESSIBLE.label()); + addChoice(Flow.INCOMPRESSIBLE.label()); } public void updateFromState(State state) { if (state.isCompressible()) - select(COMPRESSIBLE); + select(Flow.COMPRESSIBLE.label()); else if (state.isIncompressible()) - select(INCOMPRESSIBLE); + select(Flow.INCOMPRESSIBLE.label()); else selectNone(); @@ -53,19 +50,19 @@ public class FlowPanel extends ChooserPanel { public Flow getFlow() { String selectedState = getSelectedState(); - if (selectedState.equals(COMPRESSIBLE)) + if (selectedState.equals(Flow.COMPRESSIBLE.label())) return Flow.COMPRESSIBLE; - else if (selectedState.equals(INCOMPRESSIBLE)) + else if (selectedState.equals(Flow.INCOMPRESSIBLE.label())) return Flow.INCOMPRESSIBLE; return Flow.NONE; } public boolean isCompressible() { - return getSelectedState().equals(COMPRESSIBLE); + return getSelectedState().equals(Flow.COMPRESSIBLE.label()); } public boolean isIncompressible() { - return getSelectedState().equals(INCOMPRESSIBLE); + return getSelectedState().equals(Flow.INCOMPRESSIBLE.label()); } } diff --git a/src/eu/engys/gui/casesetup/solution/panels/GPanel.java b/src/eu/engys/gui/casesetup/solution/panels/GPanel.java index 7d4d032..7eb453a 100644 --- a/src/eu/engys/gui/casesetup/solution/panels/GPanel.java +++ b/src/eu/engys/gui/casesetup/solution/panels/GPanel.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.casesetup.solution.panels; import static eu.engys.util.ui.ComponentsFactory.doublePointField; diff --git a/src/eu/engys/gui/casesetup/solution/panels/MachPanel.java b/src/eu/engys/gui/casesetup/solution/panels/MachPanel.java index 797abd0..f6dc764 100644 --- a/src/eu/engys/gui/casesetup/solution/panels/MachPanel.java +++ b/src/eu/engys/gui/casesetup/solution/panels/MachPanel.java @@ -1,32 +1,33 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.casesetup.solution.panels; +import static eu.engys.core.project.state.Mach.HIGH; +import static eu.engys.core.project.state.Mach.LOW; + import eu.engys.core.project.state.Mach; -import eu.engys.core.project.state.SolutionState; import eu.engys.core.project.state.State; import eu.engys.util.ui.ChooserPanel; @@ -36,15 +37,15 @@ public class MachPanel extends ChooserPanel { public MachPanel() { super(MACH); - addChoice(SolutionState.LO_MACH); - addChoice(SolutionState.HI_MACH); + addChoice(LOW.label()); + addChoice(HIGH.label()); } public void updateFromState(State state) { if (state.isLowMach()) - select(SolutionState.LO_MACH); + select(LOW.label()); else if (state.isHighMach()) - select(SolutionState.HI_MACH); + select(HIGH.label()); else selectNone(); @@ -52,19 +53,19 @@ public class MachPanel extends ChooserPanel { public Mach getMach() { String selectedState = getSelectedState(); - if (selectedState.equals(SolutionState.HI_MACH)) + if (selectedState.equals(HIGH.label())) return Mach.HIGH; - else if (selectedState.equals(SolutionState.LO_MACH)) + else if (selectedState.equals(LOW.label())) return Mach.LOW; return Mach.NONE; } public boolean isHighMach() { - return getSelectedState().equals(SolutionState.HI_MACH); + return getSelectedState().equals(HIGH.label()); } public boolean isLowMach() { - return getSelectedState().equals(SolutionState.LO_MACH); + return getSelectedState().equals(LOW.label()); } } diff --git a/src/eu/engys/gui/casesetup/solution/panels/MethodPanel.java b/src/eu/engys/gui/casesetup/solution/panels/MethodPanel.java index 116980e..6af13f3 100644 --- a/src/eu/engys/gui/casesetup/solution/panels/MethodPanel.java +++ b/src/eu/engys/gui/casesetup/solution/panels/MethodPanel.java @@ -1,32 +1,33 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.casesetup.solution.panels; +import static eu.engys.core.project.state.Method.LES; +import static eu.engys.core.project.state.Method.RANS; + import eu.engys.core.project.state.Method; -import eu.engys.core.project.state.SolutionState; import eu.engys.core.project.state.State; import eu.engys.util.ui.ChooserPanel; @@ -36,15 +37,15 @@ public class MethodPanel extends ChooserPanel { public MethodPanel() { super(TURBULENCE); - addChoice(SolutionState.RANS); - addChoice(SolutionState.LES_DES); + addChoice(RANS.label()); + addChoice(LES.label()); } public void updateFromState(State state) { if (state.isLES()) - select(SolutionState.LES_DES); + select(LES.label()); else if (state.isRANS()) - select(SolutionState.RANS); + select(RANS.label()); else selectNone(); @@ -52,19 +53,19 @@ public class MethodPanel extends ChooserPanel { public Method getMethod() { String selectedState = getSelectedState(); - if (selectedState.equals(SolutionState.LES_DES)) + if (selectedState.equals(LES.label())) return Method.LES; - else if (selectedState.equals(SolutionState.RANS)) + else if (selectedState.equals(RANS.label())) return Method.RANS; return Method.NONE; } public boolean isLES() { - return getSelectedState().equals(SolutionState.LES_DES); + return getSelectedState().equals(LES.label()); } public boolean isRAS() { - return getSelectedState().equals(SolutionState.RANS); + return getSelectedState().equals(RANS.label()); } } diff --git a/src/eu/engys/gui/casesetup/solution/panels/MultiphaseChooserPanel.java b/src/eu/engys/gui/casesetup/solution/panels/MultiphaseChooserPanel.java index 62cde4a..ef226bc 100644 --- a/src/eu/engys/gui/casesetup/solution/panels/MultiphaseChooserPanel.java +++ b/src/eu/engys/gui/casesetup/solution/panels/MultiphaseChooserPanel.java @@ -1,30 +1,31 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.casesetup.solution.panels; +import static eu.engys.util.ui.UiUtil.NONE_LABEL; + import java.beans.PropertyChangeListener; import java.util.HashMap; import java.util.Map; @@ -51,7 +52,7 @@ public class MultiphaseChooserPanel { public MultiphaseModel getSelectedMultiphase() { String selectedState = chooserPanel.getSelectedState(); - return selectedState == ChooserPanel.NONE ? MultiphaseModel.OFF : solvers.get(selectedState); + return selectedState == NONE_LABEL ? MultiphaseModel.OFF : solvers.get(selectedState); } public void select(MultiphaseModel model) { diff --git a/src/eu/engys/gui/casesetup/solution/panels/MultiphasePanel.java b/src/eu/engys/gui/casesetup/solution/panels/MultiphasePanel.java index c81c66c..5c6523a 100644 --- a/src/eu/engys/gui/casesetup/solution/panels/MultiphasePanel.java +++ b/src/eu/engys/gui/casesetup/solution/panels/MultiphasePanel.java @@ -1,35 +1,33 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.casesetup.solution.panels; import java.awt.BorderLayout; import java.beans.PropertyChangeListener; import java.util.Set; -import javax.swing.BorderFactory; import javax.swing.JPanel; import eu.engys.core.modules.ApplicationModule; @@ -41,7 +39,7 @@ import eu.engys.util.ui.ComponentsFactory; import eu.engys.util.ui.builder.PanelBuilder; import eu.engys.util.ui.textfields.SpinnerField; -public class MultiphasePanel extends JPanel implements MultiphaseBuilder { +public abstract class MultiphasePanel extends JPanel implements MultiphaseBuilder { public static final String PHASES_LABEL = "Phases"; private static final String MULTIPHASE = "Multiphase"; @@ -67,9 +65,8 @@ public class MultiphasePanel extends JPanel implements MultiphaseBuilder { multiphaseBuilder = new PanelBuilder(); multiphaseBuilder.addComponent(phaseBuilderLeft.removeMargins().getPanel(), phaseBuilderRight.removeMargins().getPanel()); - multiphaseBuilder.getPanel().setBorder(BorderFactory.createTitledBorder(MULTIPHASE)); - add(multiphaseBuilder.getPanel()); + add(multiphaseBuilder.withTitle(MULTIPHASE).getPanel()); for (ApplicationModule m : modules) { m.getSolutionView().buildMultiphase(this); @@ -80,12 +77,13 @@ public class MultiphasePanel extends JPanel implements MultiphaseBuilder { MultiphaseModel multiphaseModel = state.getMultiphaseModel(); if (multiphaseModel != null) { multiphaseChooser.select(multiphaseModel); + if (multiphaseModel.isMultiphase()) { + phasesNumber.setIntValue(Math.max(2, state.getPhases())); + } else { + phasesNumber.setIntValue(1); + } } else { multiphaseChooser.selectNone(); - } - if (multiphaseModel.isMultiphase()) { - phasesNumber.setIntValue(Math.max(2, state.getPhases())); - } else { phasesNumber.setIntValue(1); } @@ -93,8 +91,7 @@ public class MultiphasePanel extends JPanel implements MultiphaseBuilder { fixMultiphase(getSelectedModel()); } - public void fixSolutionState(SolutionState solutionState) { - } + public abstract void fixSolutionState(SolutionState solutionState); public void fixMultiphase(MultiphaseModel mm) { if (mm.isOff()) { @@ -145,10 +142,12 @@ public class MultiphasePanel extends JPanel implements MultiphaseBuilder { multiphaseChooser.setMultiphaseOff(); } + @Override public void enableChoice(MultiphaseModel mm) { multiphaseChooser.enableChoice(mm); } + @Override public void disableChoice(MultiphaseModel mm) { multiphaseChooser.disableChoice(mm); } diff --git a/src/eu/engys/gui/casesetup/solution/panels/SolutionStatePanel.java b/src/eu/engys/gui/casesetup/solution/panels/SolutionStatePanel.java index c870451..c2e5123 100644 --- a/src/eu/engys/gui/casesetup/solution/panels/SolutionStatePanel.java +++ b/src/eu/engys/gui/casesetup/solution/panels/SolutionStatePanel.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.casesetup.solution.panels; import java.awt.GridBagConstraints; @@ -59,10 +58,6 @@ public class SolutionStatePanel extends JPanel { layoutComponents(visibleSolverType); } - public void setListener(PropertyChangeListener listener) { - this.listener = listener; - } - private void layoutComponents(boolean visibleSolverType) { solverTypePanel = new SolverTypePanel(); timePanel = new TimePanel(); @@ -70,7 +65,6 @@ public class SolutionStatePanel extends JPanel { methodPanel = new MethodPanel(); machPanel = new MachPanel(); - if (visibleSolverType) { add(solverTypePanel, new GridBagConstraints(0, 0, 2, 1, 1.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); add(timePanel, new GridBagConstraints(0, 1, 1, 1, 1.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); @@ -78,10 +72,10 @@ public class SolutionStatePanel extends JPanel { add(methodPanel, new GridBagConstraints(0, 2, 1, 1, 1.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); add(machPanel, new GridBagConstraints(1, 2, 1, 1, 1.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); } else { - add(timePanel, new GridBagConstraints(0, 0, 1, 1, 1.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); - add(flowPanel, new GridBagConstraints(1, 0, 1, 1, 1.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); - add(methodPanel, new GridBagConstraints(0, 1, 1, 1, 1.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); - add(machPanel, new GridBagConstraints(1, 1, 1, 1, 1.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); + add(timePanel, new GridBagConstraints(0, 0, 1, 1, 1.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); + add(flowPanel, new GridBagConstraints(1, 0, 1, 1, 1.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); + add(methodPanel, new GridBagConstraints(0, 1, 1, 1, 1.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); + add(machPanel, new GridBagConstraints(1, 1, 1, 1, 1.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); } for (ApplicationModule m : modules) { @@ -116,9 +110,9 @@ public class SolutionStatePanel extends JPanel { machPanel.setEnabled(true); if (ss.isSteady()) { methodPanel.setEnabled(false); - methodPanel.select(SolutionState.RANS); + methodPanel.select(Method.RANS.label()); machPanel.setEnabled(false); - machPanel.select(SolutionState.LO_MACH); + machPanel.select(Mach.LOW.label()); } else if (ss.isTransient()) { if (ss.isFlowNone()) { methodPanel.setEnabled(false); @@ -128,21 +122,25 @@ public class SolutionStatePanel extends JPanel { if (ss.isCompressible()) { machPanel.setEnabled(true); if (ss.isMachNone()) { - machPanel.select(SolutionState.LO_MACH); + machPanel.select(Mach.LOW.label()); } } else if (ss.isIncompressible()) { machPanel.setEnabled(false); - machPanel.select(SolutionState.LO_MACH); + machPanel.select(Mach.LOW.label()); } } } } } else if (ss.isCoupled()) { - flowPanel.select(SolutionState.INCOMPRESSIBLE); + flowPanel.select(Flow.INCOMPRESSIBLE.label()); flowPanel.setEnabled(false); - methodPanel.select(SolutionState.RANS); - methodPanel.setEnabled(false); - machPanel.select(SolutionState.LO_MACH); + if (ss.isSteady()) { + methodPanel.select(Method.RANS.label()); + methodPanel.setEnabled(false); + } else if(ss.isTransient()){ + methodPanel.setEnabled(true); + } + machPanel.select(Mach.LOW.label()); machPanel.setEnabled(false); } } @@ -152,12 +150,16 @@ public class SolutionStatePanel extends JPanel { SolutionState ss = new SolutionState(); ss.time = timePanel.getSelectedState(); ss.flow = flowPanel.getSelectedState(); - ss.turbulence = methodPanel.getSelectedState(); - ss.solver = solverTypePanel.getSelectedState(); + ss.method = methodPanel.getSelectedState(); + ss.solverType = solverTypePanel.getSelectedState(); ss.mach = machPanel.getSelectedState(); return ss; } + public void setListener(PropertyChangeListener listener) { + this.listener = listener; + } + public void removeListeners() { solverTypePanel.removePropertyChangeListener(listener); timePanel.removePropertyChangeListener(listener); diff --git a/src/eu/engys/gui/casesetup/solution/panels/SolverTypePanel.java b/src/eu/engys/gui/casesetup/solution/panels/SolverTypePanel.java index 9ffff3d..bb4b833 100644 --- a/src/eu/engys/gui/casesetup/solution/panels/SolverTypePanel.java +++ b/src/eu/engys/gui/casesetup/solution/panels/SolverTypePanel.java @@ -1,31 +1,32 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.casesetup.solution.panels; -import eu.engys.core.project.state.SolutionState; +import static eu.engys.core.project.state.SolverType.COUPLED; +import static eu.engys.core.project.state.SolverType.SEGREGATED; + import eu.engys.core.project.state.SolverType; import eu.engys.core.project.state.State; import eu.engys.util.ui.ChooserPanel; @@ -36,16 +37,16 @@ public class SolverTypePanel extends ChooserPanel { public SolverTypePanel() { super(SOLVER_TYPE, false); - addChoice(SolutionState.SEGREGATED); - addChoice(SolutionState.COUPLED); - getButton(SolutionState.COUPLED).setEnabled(false); + addChoice(SEGREGATED.label()); + addChoice(COUPLED.label()); + getButton(COUPLED.label()).setEnabled(false); } public void updateFromState(State state) { if (state.getSolverType().isSegregated()) { - select(SolutionState.SEGREGATED); + select(SEGREGATED.label()); } else if (state.getSolverType().isCoupled()) { - select(SolutionState.COUPLED); + select(COUPLED.label()); } else { selectNone(); } @@ -53,19 +54,19 @@ public class SolverTypePanel extends ChooserPanel { public SolverType getSolverType() { String selectedState = getSelectedState(); - if (selectedState.equals(SolutionState.SEGREGATED)) + if (selectedState.equals(SEGREGATED.label())) return SolverType.SEGREGATED; - if (selectedState.equals(SolutionState.COUPLED)) + if (selectedState.equals(COUPLED.label())) return SolverType.COUPLED; return SolverType.NONE; } public boolean isCoupled() { - return getSelectedState().equals(SolutionState.COUPLED); + return getSelectedState().equals(COUPLED.label()); } public boolean isSegregated() { - return getSelectedState().equals(SolutionState.SEGREGATED); + return getSelectedState().equals(SEGREGATED.label()); } } diff --git a/src/eu/engys/gui/casesetup/solution/panels/TimePanel.java b/src/eu/engys/gui/casesetup/solution/panels/TimePanel.java index 61bc0c7..08f4066 100644 --- a/src/eu/engys/gui/casesetup/solution/panels/TimePanel.java +++ b/src/eu/engys/gui/casesetup/solution/panels/TimePanel.java @@ -1,32 +1,29 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.casesetup.solution.panels; -import static eu.engys.core.project.state.SolutionState.STEADY; -import static eu.engys.core.project.state.SolutionState.TRANSIENT; import eu.engys.core.project.state.State; import eu.engys.core.project.state.Time; import eu.engys.util.ui.ChooserPanel; @@ -37,34 +34,34 @@ public class TimePanel extends ChooserPanel { public TimePanel() { super(TimePanel.TIME); - addChoice(STEADY); - addChoice(TRANSIENT); + addChoice(Time.STEADY.label()); + addChoice(Time.TRANSIENT.label()); } public void updateFromState(State state) { if (state.isSteady()) - select(STEADY); + select(Time.STEADY.label()); else if (state.isTransient()) - select(TRANSIENT); + select(Time.TRANSIENT.label()); else selectNone(); } public Time getTime() { String selectedState = getSelectedState(); - if (selectedState.equals(STEADY)) + if (selectedState.equals(Time.STEADY.label())) return Time.STEADY; - else if (selectedState.equals(TRANSIENT)) + else if (selectedState.equals(Time.TRANSIENT.label())) return Time.TRANSIENT; return Time.NONE; } public boolean isSteady() { - return getSelectedState().equals(STEADY); + return getSelectedState().equals(Time.STEADY.label()); } public boolean isTransient() { - return getSelectedState().equals(TRANSIENT); + return getSelectedState().equals(Time.TRANSIENT.label()); } } diff --git a/src/eu/engys/gui/casesetup/solution/panels/TurbulencePanel.java b/src/eu/engys/gui/casesetup/solution/panels/TurbulencePanel.java index e3cc9c6..3fe71db 100644 --- a/src/eu/engys/gui/casesetup/solution/panels/TurbulencePanel.java +++ b/src/eu/engys/gui/casesetup/solution/panels/TurbulencePanel.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.casesetup.solution.panels; import java.awt.BorderLayout; @@ -57,7 +56,7 @@ public class TurbulencePanel extends JPanel { private void layoutComponents() { modelsCombo = new JComboBox(); - modelsCombo.setPrototypeDisplayValue(new TurbulenceModel("", "MMMMMMM")); + modelsCombo.setPrototypeDisplayValue(TurbulenceModel.getPrototypeForDisplay()); final ListCellRenderer renderer = modelsCombo.getRenderer(); modelsCombo.setRenderer(new ListCellRenderer() { @Override @@ -71,7 +70,7 @@ public class TurbulencePanel extends JPanel { } }); PanelBuilder builder = new PanelBuilder(); - builder.addComponent(TurbulencePanel.TURBULENCE_MODEL, modelsCombo); + builder.addComponent(TURBULENCE_MODEL, modelsCombo); add(builder.margins(.5, 0, .5, 0).getPanel(), BorderLayout.CENTER); } @@ -79,8 +78,8 @@ public class TurbulencePanel extends JPanel { return (TurbulenceModel) modelsCombo.getSelectedItem(); } - public void updateTurbulenceModels(Model model, SolverType solvertype, Method method, Flow flow) { - Object selectedItem = modelsCombo.getSelectedItem(); + private void updateTurbulenceModels(Model model, SolverType solvertype, Method method, Flow flow) { + TurbulenceModel selectedItem = modelsCombo.getItemAt(modelsCombo.getSelectedIndex()); List models = model.getTurbulenceModels().getModelsForState(solvertype, method, flow); modelsCombo.removeAllItems(); diff --git a/src/eu/engys/gui/casesetup/solver/SolverSettingsPanel.java b/src/eu/engys/gui/casesetup/solver/AbstractSolverSettingsPanel.java similarity index 79% rename from src/eu/engys/gui/casesetup/solver/SolverSettingsPanel.java rename to src/eu/engys/gui/casesetup/solver/AbstractSolverSettingsPanel.java index a1c51b1..d7ded51 100644 --- a/src/eu/engys/gui/casesetup/solver/SolverSettingsPanel.java +++ b/src/eu/engys/gui/casesetup/solver/AbstractSolverSettingsPanel.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.casesetup.solver; import static eu.engys.core.project.state.SolverFamily.CENTRAL; @@ -44,7 +43,6 @@ import java.util.LinkedHashSet; import java.util.Map; import java.util.Set; -import javax.inject.Inject; import javax.swing.DefaultComboBoxModel; import javax.swing.JComboBox; import javax.swing.JComponent; @@ -73,7 +71,7 @@ import eu.engys.util.ui.ExecUtil; import eu.engys.util.ui.UiUtil; import eu.engys.util.ui.builder.PanelBuilder; -public class SolverSettingsPanel extends DefaultGUIPanel { +public abstract class AbstractSolverSettingsPanel extends DefaultGUIPanel { private static final String EMPTY = "EMPTY"; private static final String STATE_CHANGED_WARNING = "Solution state has been changed.\nAll fields default settings are going to be reset now.\nContinue?"; @@ -81,15 +79,14 @@ public class SolverSettingsPanel extends DefaultGUIPanel { public static final String SOLVER_SETTINGS = "Solver Settings"; public static final String SOLUTION_ALGORITHM_LABEL = "Solution Algorithm"; - private JComboBox algorithmCombo; + protected JComboBox algorithmCombo; private ActionListener algorithmActionListener; private Map solverPanelMap = new LinkedHashMap<>(); private Table15 solversTable; private Set modules; - @Inject - public SolverSettingsPanel(Model model, Table15 solversTable, Set modules) { + public AbstractSolverSettingsPanel(Model model, Table15 solversTable, Set modules) { super(SOLVER_SETTINGS, model); this.solversTable = solversTable; this.modules = modules; @@ -114,10 +111,11 @@ public class SolverSettingsPanel extends DefaultGUIPanel { public void actionPerformed(ActionEvent actionevent) { SolverFamily selectedType = (SolverFamily) algorithmCombo.getSelectedItem(); if (selectedType != null) { - cardLayout.show(cardLayoutPanel, selectedType.getKey()); + cardLayout.show(cardLayoutPanel, selectedType.key()); fixPIMPLE_PISOSolver(model); fixPIMPLE_CENTRALSolver(model); solverPanelMap.get(selectedType).load(model); + solverPanelMap.get(selectedType).getPanel().add(getLimiterPanel(), BorderLayout.CENTER); } else { cardLayout.show(cardLayoutPanel, EMPTY); } @@ -125,18 +123,14 @@ public class SolverSettingsPanel extends DefaultGUIPanel { }; algorithmCombo.addActionListener(algorithmActionListener); - PanelBuilder comboBuilder = new PanelBuilder(); - comboBuilder.addComponent(SOLUTION_ALGORITHM_LABEL, algorithmCombo); - - PanelBuilder cardBuilder = new PanelBuilder(); - cardBuilder.addComponent(cardLayoutPanel); - - JPanel panel = new JPanel(new BorderLayout()); - panel.add(comboBuilder.margins(0, 0, 1, 0).getPanel(), BorderLayout.NORTH); - panel.add(cardBuilder.removeMargins().getPanel(), BorderLayout.CENTER); - return panel; + PanelBuilder builder = new PanelBuilder(); + builder.addComponent(SOLUTION_ALGORITHM_LABEL, algorithmCombo); + builder.addFill(cardLayoutPanel); + return builder.removeMargins().getPanel(); } + protected abstract JPanel getLimiterPanel(); + private JComboBox createAlgorithmsCombo(final CardLayout cardLayout, final JPanel cardLayoutPanel) { JComboBox combo = new JComboBox(); combo.setPrototypeDisplayValue(SolverFamily.CENTRAL); @@ -147,7 +141,7 @@ public class SolverSettingsPanel extends DefaultGUIPanel { Component c = renderer.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); if (c instanceof JLabel && value instanceof SolverFamily) { SolverFamily model = (SolverFamily) value; - ((JLabel) c).setText(model.getKey()); + ((JLabel) c).setText(model.label()); } return c; } @@ -155,7 +149,7 @@ public class SolverSettingsPanel extends DefaultGUIPanel { combo.setEnabled(false); for (SolverFamily solver : solverPanelMap.keySet()) { - cardLayoutPanel.add(solverPanelMap.get(solver).getPanel(), solver.getKey()); + cardLayoutPanel.add(solverPanelMap.get(solver).getPanel(), solver.key()); } combo.setSelectedIndex(-1); return combo; @@ -192,13 +186,13 @@ public class SolverSettingsPanel extends DefaultGUIPanel { solversTable.updateSolverFamilies(model.getState(), solverFamilies); ModulesUtil.updateSolverFamilies(modules, model.getState(), solverFamilies); - loadSolverPanels(model, solverFamilies); + loadSolverPanels(solverFamilies); populateCombo(solverFamilies); fixComboSelection(); } } - private void loadSolverPanels(Model model, Set solverFamiliesForState) { + private void loadSolverPanels(Set solverFamiliesForState) { Dictionary fvSolution = model.getProject().getSystemFolder().getFvSolution(); if (fvSolution != null) { leaveOneSolverDictionaryOnFvSolution(fvSolution); @@ -206,12 +200,13 @@ public class SolverSettingsPanel extends DefaultGUIPanel { solverPanelMap.get(family).load(model); } } + } private void leaveOneSolverDictionaryOnFvSolution(Dictionary fvSolution) { - if (fvSolution.found(SolverFamily.SIMPLE.getKey())) { - if (fvSolution.found(SolverFamily.PIMPLE.getKey()) || fvSolution.found(SolverFamily.PISO.getKey()) || fvSolution.found(SolverFamily.CENTRAL.getKey())) { - fvSolution.remove(SolverFamily.SIMPLE.getKey()); + if (fvSolution.found(SolverFamily.SIMPLE.key())) { + if (fvSolution.found(SolverFamily.PIMPLE.key()) || fvSolution.found(SolverFamily.PISO.key()) || fvSolution.found(SolverFamily.CENTRAL.key())) { + fvSolution.remove(SolverFamily.SIMPLE.key()); } } } @@ -304,13 +299,13 @@ public class SolverSettingsPanel extends DefaultGUIPanel { Dictionary pisoSolution = stateData.subDict("pisoFoamRAS").subDict(SYSTEM).subDict(FV_SOLUTION); Dictionary pimpleSolution = stateData.subDict("pimpleFoamRAS").subDict(SYSTEM).subDict(FV_SOLUTION); - if (isPISO() && fvSolution.found(SolverFamily.PIMPLE.getKey())) { + if (isPISO() && fvSolution.found(SolverFamily.PIMPLE.key())) { systemFolder.setFvSolution(pisoSolution); state.setSolverFamily(SolverFamily.PISO); solversTable.updateSolver(state); ModulesUtil.updateSolver(modules, state); model.solverChanged(); - } else if (isPIMPLE() && fvSolution.found(SolverFamily.PISO.getKey())) { + } else if (isPIMPLE() && fvSolution.found(SolverFamily.PISO.key())) { systemFolder.setFvSolution(pimpleSolution); state.setSolverFamily(SolverFamily.PIMPLE); solversTable.updateSolver(state); diff --git a/src/eu/engys/gui/casesetup/solver/SolverSettingsBuilder.java b/src/eu/engys/gui/casesetup/solver/SolverSettingsBuilder.java index 84ea771..17f677c 100644 --- a/src/eu/engys/gui/casesetup/solver/SolverSettingsBuilder.java +++ b/src/eu/engys/gui/casesetup/solver/SolverSettingsBuilder.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.casesetup.solver; import static eu.engys.core.project.system.ControlDict.MAX_ALPHA_CO_KEY; @@ -41,6 +40,7 @@ import static eu.engys.core.project.zero.fields.Fields.FINAL; import static eu.engys.core.project.zero.fields.Fields.P; import static eu.engys.core.project.zero.fields.Fields.P_RGH; import static eu.engys.core.project.zero.fields.Fields.RHO; + import eu.engys.core.dictionary.DefaultElement; import eu.engys.core.dictionary.Dictionary; import eu.engys.core.dictionary.FieldElement; diff --git a/src/eu/engys/gui/casesetup/solver/panels/CentralSettingsPanel.java b/src/eu/engys/gui/casesetup/solver/panels/CentralSettingsPanel.java index 629907c..474a407 100644 --- a/src/eu/engys/gui/casesetup/solver/panels/CentralSettingsPanel.java +++ b/src/eu/engys/gui/casesetup/solver/panels/CentralSettingsPanel.java @@ -1,34 +1,35 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.casesetup.solver.panels; import static eu.engys.core.project.system.FvSolution.RELAXATION_FACTORS_KEY; import static eu.engys.core.project.system.FvSolution.RESIDUAL_CONTROL_KEY; +import java.awt.BorderLayout; + import javax.swing.JPanel; import eu.engys.core.dictionary.Dictionary; @@ -39,19 +40,21 @@ import eu.engys.core.project.state.SolverFamily; public class CentralSettingsPanel implements SolverPanel { private DictionaryModel centralDictModel; + private JPanel mainPanel; public CentralSettingsPanel() { centralDictModel = new DictionaryModel(new Dictionary(getKey())); + mainPanel = new JPanel(new BorderLayout()); } @Override public String getKey() { - return SolverFamily.CENTRAL.getKey(); + return SolverFamily.CENTRAL.key(); } @Override public JPanel getPanel() { - return new JPanel(); + return mainPanel; } @Override diff --git a/src/eu/engys/gui/casesetup/solver/panels/CoupledSettingsPanel.java b/src/eu/engys/gui/casesetup/solver/panels/CoupledSettingsPanel.java index 05464de..8a9a430 100644 --- a/src/eu/engys/gui/casesetup/solver/panels/CoupledSettingsPanel.java +++ b/src/eu/engys/gui/casesetup/solver/panels/CoupledSettingsPanel.java @@ -1,32 +1,33 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.casesetup.solver.panels; import static eu.engys.core.project.system.FvSolution.RELAXATION_FACTORS_KEY; +import java.awt.BorderLayout; + import javax.swing.JPanel; import eu.engys.core.dictionary.Dictionary; @@ -37,19 +38,22 @@ import eu.engys.core.project.state.SolverFamily; public class CoupledSettingsPanel implements SolverPanel { private DictionaryModel coupledDictModel; + private JPanel mainPanel; public CoupledSettingsPanel() { coupledDictModel = new DictionaryModel(new Dictionary(getKey())); + + mainPanel = new JPanel(new BorderLayout()); } @Override public String getKey() { - return SolverFamily.COUPLED.getKey(); + return SolverFamily.COUPLED.key(); } @Override public JPanel getPanel() { - return new JPanel(); + return mainPanel; } @Override diff --git a/src/eu/engys/gui/casesetup/solver/panels/PimpleSettingsPanel.java b/src/eu/engys/gui/casesetup/solver/panels/PimpleSettingsPanel.java index b051f8b..9217c31 100644 --- a/src/eu/engys/gui/casesetup/solver/panels/PimpleSettingsPanel.java +++ b/src/eu/engys/gui/casesetup/solver/panels/PimpleSettingsPanel.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.casesetup.solver.panels; import static eu.engys.core.project.system.ControlDict.MAX_ALPHA_CO_KEY; @@ -85,6 +84,7 @@ public class PimpleSettingsPanel implements SolverPanel { private JComponent maxCourantNumber; private JComponent maxAlphaCourant; + private JPanel mainPanel; public PimpleSettingsPanel() { relaxationFactorsDictModel = new DictionaryModel(new Dictionary(RELAXATION_FACTORS_KEY)); @@ -121,11 +121,14 @@ public class PimpleSettingsPanel implements SolverPanel { relaxationFactorsPanel.setBorder(BorderFactory.createTitledBorder(RELAXATION_FACTORS_LABEL)); relaxationFactorsPanel.setName(RELAXATION_FACTORS_LABEL); builder.addFill(relaxationFactorsPanel); + + mainPanel = new JPanel(new BorderLayout()); + mainPanel.add(builder.removeMargins().getPanel(), BorderLayout.NORTH); } @Override public String getKey() { - return SolverFamily.PIMPLE.getKey(); + return SolverFamily.PIMPLE.key(); } @Override @@ -145,7 +148,7 @@ public class PimpleSettingsPanel implements SolverPanel { @Override public JPanel getPanel() { - return builder.removeMargins().getPanel(); + return mainPanel; } @Override @@ -192,7 +195,7 @@ public class PimpleSettingsPanel implements SolverPanel { finalField = relaxationFactorsDictModel.bindDouble(fieldName + FINAL, 0.0, 1.0); } finalField.setName(fieldName + FINAL); - relaxationBuilder.addComponent(new JLabel(fieldName), normalField, finalLabel, finalField); + relaxationBuilder.addComponent(fieldName, normalField, finalLabel, finalField); } if (PIMPLEDict != null && PIMPLEDict.found(RESIDUAL_CONTROL_KEY)) { diff --git a/src/eu/engys/gui/casesetup/solver/panels/PisoSettingsPanel.java b/src/eu/engys/gui/casesetup/solver/panels/PisoSettingsPanel.java index 17c265a..8f1e3d2 100644 --- a/src/eu/engys/gui/casesetup/solver/panels/PisoSettingsPanel.java +++ b/src/eu/engys/gui/casesetup/solver/panels/PisoSettingsPanel.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.casesetup.solver.panels; @@ -65,6 +64,8 @@ public class PisoSettingsPanel implements SolverPanel { private JComponent pisoRhoMin; private JComponent pisoRhoMax; + private JPanel mainPanel; + public PisoSettingsPanel() { relaxationFactorsDictModel = new DictionaryModel(new Dictionary(RELAXATION_FACTORS_KEY)); @@ -81,16 +82,19 @@ public class PisoSettingsPanel implements SolverPanel { relaxationFactorsPanel.setBorder(BorderFactory.createTitledBorder(RELAXATION_FACTORS_LABEL)); relaxationFactorsPanel.setName(RELAXATION_FACTORS_LABEL); builder.addFill(relaxationFactorsPanel); + + mainPanel = new JPanel(new BorderLayout()); + mainPanel.add(builder.removeMargins().getPanel(), BorderLayout.NORTH); } @Override public String getKey() { - return SolverFamily.PISO.getKey(); + return SolverFamily.PISO.key(); } @Override public JPanel getPanel() { - return builder.removeMargins().getPanel(); + return mainPanel; } @Override diff --git a/src/eu/engys/gui/casesetup/solver/panels/SimpleSettingsPanel.java b/src/eu/engys/gui/casesetup/solver/panels/SimpleSettingsPanel.java index b60cb61..ab09356 100644 --- a/src/eu/engys/gui/casesetup/solver/panels/SimpleSettingsPanel.java +++ b/src/eu/engys/gui/casesetup/solver/panels/SimpleSettingsPanel.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.casesetup.solver.panels; @@ -55,6 +54,8 @@ public class SimpleSettingsPanel implements SolverPanel { private JPanel relaxationFactorsPanel; private JPanel residualControlPanel; + private JPanel mainPanel; + public SimpleSettingsPanel() { relaxationFactorsDictModel = new DictionaryModel(new Dictionary(RELAXATION_FACTORS_KEY)); residualControlDict = new DictionaryModel(new Dictionary(RESIDUAL_CONTROL_KEY)); @@ -75,16 +76,19 @@ public class SimpleSettingsPanel implements SolverPanel { relaxationFactorsPanel.setBorder(BorderFactory.createTitledBorder(RELAXATION_FACTORS_LABEL)); relaxationFactorsPanel.setName(RELAXATION_FACTORS_LABEL); builder.addFill(relaxationFactorsPanel); + + mainPanel = new JPanel(new BorderLayout()); + mainPanel.add(builder.removeMargins().getPanel(), BorderLayout.NORTH); } @Override public String getKey() { - return SolverFamily.SIMPLE.getKey(); + return SolverFamily.SIMPLE.key(); } @Override public JPanel getPanel() { - return builder.removeMargins().getPanel(); + return mainPanel; } @Override diff --git a/src/eu/engys/gui/casesetup/solver/panels/SolverPanel.java b/src/eu/engys/gui/casesetup/solver/panels/SolverPanel.java index 950563e..b5f13cf 100644 --- a/src/eu/engys/gui/casesetup/solver/panels/SolverPanel.java +++ b/src/eu/engys/gui/casesetup/solver/panels/SolverPanel.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.casesetup.solver.panels; import javax.swing.JPanel; diff --git a/src/eu/engys/gui/custom/CustomFileDialog.java b/src/eu/engys/gui/custom/CustomFileDialog.java index fa7dbf1..5c3a278 100644 --- a/src/eu/engys/gui/custom/CustomFileDialog.java +++ b/src/eu/engys/gui/custom/CustomFileDialog.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.custom; import static eu.engys.core.project.constant.ConstantFolder.CONSTANT; @@ -30,9 +29,13 @@ import static eu.engys.core.project.custom.CustomFileType.DICTIONARY; import static eu.engys.core.project.custom.CustomFileType.DIRECTORY; import static eu.engys.core.project.custom.CustomFileType.FIELD; import static eu.engys.core.project.system.SystemFolder.SYSTEM; +import static eu.engys.core.project.zero.fields.Fields.POINT_DISPLACEMENT; +import static eu.engys.core.project.zero.fields.Fields.POINT_MOTION_U; import static eu.engys.util.ui.ComponentsFactory.selectField; import static eu.engys.util.ui.ComponentsFactory.selectFieldWithItemSupport; import static eu.engys.util.ui.ComponentsFactory.stringField; +import static eu.engys.util.ui.UiUtil.DIALOG_CANCEL_LABEL; +import static eu.engys.util.ui.UiUtil.DIALOG_OK_LABEL; import java.awt.BorderLayout; import java.awt.Dialog.ModalityType; @@ -52,6 +55,7 @@ import javax.swing.JDialog; import javax.swing.JOptionPane; import javax.swing.JPanel; +import eu.engys.core.dictionary.Dictionary; import eu.engys.core.project.Model; import eu.engys.core.project.custom.CustomFile; import eu.engys.core.project.custom.CustomFileType; @@ -84,7 +88,7 @@ public class CustomFileDialog { private static final String[] VETOED_DICT_LIST = new String[] { RunDict.RUN_DICT, CaseSetupDict.CASE_SETUP_DICT, CustomNodeDict.CUSTOM_NODE_DICT }; - private JComboBoxWithItemsSupport typeCombo; + private JComboBoxWithItemsSupport typeCombo; private JComboBox parentCombo; private JComboBox namesCombo; private StringField nameField; @@ -154,8 +158,8 @@ public class CustomFileDialog { return namesCombo; } - private JComboBoxWithItemsSupport createTypeCombo() { - JComboBoxWithItemsSupport typeCombo = selectFieldWithItemSupport(CustomFileType.keys(), CustomFileType.labels()); + private JComboBoxWithItemsSupport createTypeCombo() { + JComboBoxWithItemsSupport typeCombo = selectFieldWithItemSupport(CustomFileType.keys(), CustomFileType.labels()); typeCombo.setSelectedIndex(-1); typeCombo.addPropertyChangeListener(enableOKButtonListener); typeCombo.addPropertyChangeListener(updateNamesCombo); @@ -174,10 +178,10 @@ public class CustomFileDialog { JPanel panel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); okButton = new JButton(new AddCustomFile()); okButton.setEnabled(false); - okButton.setName("ok"); + okButton.setName(DIALOG_OK_LABEL); panel.add(okButton); - JButton cancelButton = new JButton(new AbstractAction("Cancel") { + JButton cancelButton = new JButton(new AbstractAction(DIALOG_CANCEL_LABEL) { @Override public void actionPerformed(ActionEvent e) { @@ -185,7 +189,7 @@ public class CustomFileDialog { } }); - cancelButton.setName("cancel"); + cancelButton.setName(DIALOG_CANCEL_LABEL); panel.add(cancelButton); return panel; } @@ -290,7 +294,7 @@ public class CustomFileDialog { private class AddCustomFile extends AbstractAction { public AddCustomFile() { - super("OK"); + super(DIALOG_OK_LABEL); } @Override @@ -302,6 +306,11 @@ public class CustomFileDialog { String type = typeCombo.getItemAt(typeCombo.getSelectedIndex()); CustomFile parent = parentCombo.getItemAt(parentCombo.getSelectedIndex()); + if (type == null) { + JOptionPane.showMessageDialog(dialog, "Please, specify a type for the file", "Warning", JOptionPane.WARNING_MESSAGE); + return; + } + if (parent == null) { JOptionPane.showMessageDialog(dialog, "Please, specify a parent for the file", "Warning", JOptionPane.WARNING_MESSAGE); return; @@ -314,29 +323,43 @@ public class CustomFileDialog { File file = CustomUtils.getFiles(model, customFile).get(0); boolean exists = file.exists(); - if (exists && !customFile.getType().isDirectory()) { - if (isNewFile()) { - boolean parallel = model.getProject().isParallel(); - String suffix = (customFile.getType().isField() && parallel) ? "Template" : "from File"; - Object[] options = { "Load " + suffix, CREATE_NEW_LABEL, CANCEL_LABEL }; - String message = customFile.getName() + " already exists, please select an action."; - int retVal = JOptionPane.showOptionDialog(dialog, message, "Warning", JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE, null, options, options[0]); - switch (retVal) { - case CANCEL: - return; - case NEW: - break; - case LOAD: - CustomUtils.loadFromDisk(fileName, customFile, file); - break; - default: - break; - } + if (exists) { + if(customFile.getType().isDirectory()){ + //do nothing } else { - CustomUtils.loadFromDisk(fileName, customFile, file); + if (isNewFile()) { + boolean parallel = model.getProject().isParallel(); + String suffix = (customFile.getType().isField() && parallel) ? "Template" : "from File"; + Object[] options = { "Load " + suffix, CREATE_NEW_LABEL, CANCEL_LABEL }; + String message = customFile.getName() + " already exists, please select an action."; + int retVal = JOptionPane.showOptionDialog(dialog, message, "Warning", JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE, null, options, options[0]); + switch (retVal) { + case CANCEL: + return; + case NEW: + break; + case LOAD: + CustomUtils.loadFromDisk(fileName, customFile, file); + break; + default: + break; + } + } else { + CustomUtils.loadFromDisk(fileName, customFile, file); + } + } + } else { + /* + * If a field does not exist I load the empty BCs from an existing one + */ + if(customFile.getType().isField() && !model.getFields().isEmpty()){ + Dictionary dict = new Dictionary(fileName); + dict.add(CustomUtils.getCleanBoundaryField(model.getFields().orderedFields().get(0))); + customFile.getDictionary().merge(dict); } - } + + model.getCustom().add(customFile); model.customFileChanged(customFile); resetAndClose(); @@ -415,7 +438,7 @@ public class CustomFileDialog { switch (selectedItem.toString()) { case "0": typeCombo.clearDisabledIndexes(); - if (typeCombo.getSelectedItem() == DICTIONARY.getKey()) { + if (DICTIONARY.getKey().equals(typeCombo.getItemAt(typeCombo.getSelectedIndex()))) { typeCombo.setSelectedItem(FIELD.getKey()); } // typeCombo.addDisabledIndex(directoryIndex); @@ -425,7 +448,8 @@ public class CustomFileDialog { case CONSTANT: default: typeCombo.clearDisabledIndexes(); - if (typeCombo.getSelectedItem() == FIELD.getKey()) { + + if (FIELD.getKey().equals(typeCombo.getItemAt(typeCombo.getSelectedIndex()))) { typeCombo.setSelectedItem(DICTIONARY.getKey()); } typeCombo.addDisabledItem(FIELD.getKey()); @@ -477,7 +501,7 @@ public class CustomFileDialog { } private boolean isDynamic(String name) { - return name.equals("pointMotionU") || name.equals("pointDisplacement"); + return name.equals(POINT_MOTION_U) || name.equals(POINT_DISPLACEMENT); } } @@ -494,7 +518,7 @@ public class CustomFileDialog { boolean isDir = pathname.isDirectory(); boolean isVisible = !pathname.isHidden(); boolean isNotAlreadyUsed = !children.contains(pathname.getName()); - return isDir && isVisible && isNotAlreadyUsed && isNotAlreadyUsed; + return isDir && isVisible && isNotAlreadyUsed; } } diff --git a/src/eu/engys/gui/custom/CustomNodePanel.java b/src/eu/engys/gui/custom/CustomNodePanel.java index 393b474..6e7d74a 100644 --- a/src/eu/engys/gui/custom/CustomNodePanel.java +++ b/src/eu/engys/gui/custom/CustomNodePanel.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.custom; import static eu.engys.util.ui.ComponentsFactory.stringField; @@ -39,21 +38,21 @@ import javax.swing.JComponent; import javax.swing.JLabel; import javax.swing.SwingUtilities; -import net.java.dev.designgridlayout.Componentizer; import eu.engys.core.dictionary.Dictionary; -import eu.engys.core.dictionary.DictionaryEditor; -import eu.engys.core.dictionary.FileEditor; import eu.engys.core.project.Model; import eu.engys.core.project.custom.Custom.ConstantDirectory; import eu.engys.core.project.custom.Custom.SystemDirectory; import eu.engys.core.project.custom.Custom.ZeroDirectory; import eu.engys.core.project.custom.CustomFile; import eu.engys.gui.AbstractGUIPanel; +import eu.engys.gui.DictionaryEditor; +import eu.engys.gui.FileEditor; import eu.engys.gui.tree.TreeNodeManager; import eu.engys.util.ui.ExecUtil; import eu.engys.util.ui.UiUtil; import eu.engys.util.ui.builder.PanelBuilder; import eu.engys.util.ui.textfields.StringField; +import net.java.dev.designgridlayout.Componentizer; public class CustomNodePanel extends AbstractGUIPanel { @@ -342,6 +341,7 @@ public class CustomNodePanel extends AbstractGUIPanel { @Override public void run() { editButton.setEnabled(true); + model.customFileChanged(customFile); } }; Runnable onOKRunnable = new Runnable() { diff --git a/src/eu/engys/gui/custom/CustomTreeNodeManager.java b/src/eu/engys/gui/custom/CustomTreeNodeManager.java index 6cb2e58..8ceebd3 100644 --- a/src/eu/engys/gui/custom/CustomTreeNodeManager.java +++ b/src/eu/engys/gui/custom/CustomTreeNodeManager.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.custom; import java.awt.Component; @@ -34,6 +33,7 @@ import java.util.Observable; import javax.swing.AbstractAction; import javax.swing.Action; +import javax.swing.Icon; import javax.swing.JPopupMenu; import javax.swing.JTree; import javax.swing.tree.DefaultMutableTreeNode; @@ -47,15 +47,16 @@ import eu.engys.core.project.custom.CustomUtils; import eu.engys.gui.tree.AbstractSelectionHandler; import eu.engys.gui.tree.DefaultTreeNodeManager; import eu.engys.gui.tree.SelectionHandler; -import eu.engys.gui.view3D.Actor; -import eu.engys.gui.view3D.Picker; import eu.engys.util.Symbols; import eu.engys.util.ui.ExecUtil; +import eu.engys.util.ui.ResourcesUtil; import eu.engys.util.ui.TreeUtil; -import eu.engys.util.ui.checkboxtree.VisibleItem; public class CustomTreeNodeManager extends DefaultTreeNodeManager { + private static final Icon FILE_ICON = ResourcesUtil.getIcon("file.icon"); + private static final Icon FOLDER_ICON = ResourcesUtil.getIcon("folder.icon"); + private SelectionHandler selectionHandler; private Map filesMap = new HashMap<>(); private CustomNodePanel panel; @@ -231,9 +232,9 @@ public class CustomTreeNodeManager extends DefaultTreeNodeManager { private void icon(CustomFile item) { if (item.getType().isDirectory()) { - setIcon(getDefaultOpenIcon()); + setIcon(FOLDER_ICON); } else { - setIcon(getDefaultLeafIcon()); + setIcon(FILE_ICON); } } }; @@ -274,18 +275,6 @@ public class CustomTreeNodeManager extends DefaultTreeNodeManager { editFileAction.setEnabled(panel.canEditSelectedCustomFile(getSelectedValues())); } - @Override - public void handleVisibility(VisibleItem item) { - } - - @Override - public void process3DSelectionEvent(Picker picker, Actor actor, boolean keep) { - } - - @Override - public void process3DVisibilityEvent(boolean selected) { - } - public void clear() { currentSelection = null; } diff --git a/src/eu/engys/gui/events/EventManager.java b/src/eu/engys/gui/events/EventManager.java index 7d7fe54..b5f4562 100644 --- a/src/eu/engys/gui/events/EventManager.java +++ b/src/eu/engys/gui/events/EventManager.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.events; import java.io.Serializable; @@ -189,6 +188,7 @@ public class EventManager { return eventSubscription.getEventClass().isAssignableFrom(event.getClass()); } + @SuppressWarnings("unchecked") private Map eventSubscriptionListsForClass(Class klass) { String className = klass.getName(); // System.out.println("className: "+className); diff --git a/src/eu/engys/gui/events/EventObject.java b/src/eu/engys/gui/events/EventObject.java index fa552e2..a3d8e00 100644 --- a/src/eu/engys/gui/events/EventObject.java +++ b/src/eu/engys/gui/events/EventObject.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.events; diff --git a/src/eu/engys/gui/events/EventSubscription.java b/src/eu/engys/gui/events/EventSubscription.java index a07e3fa..3fff5e9 100644 --- a/src/eu/engys/gui/events/EventSubscription.java +++ b/src/eu/engys/gui/events/EventSubscription.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.events; diff --git a/src/eu/engys/gui/events/EventWatcher.java b/src/eu/engys/gui/events/EventWatcher.java index 6913bb1..6a34765 100644 --- a/src/eu/engys/gui/events/EventWatcher.java +++ b/src/eu/engys/gui/events/EventWatcher.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.events; diff --git a/src/eu/engys/gui/events/application/ApplicationEvent.java b/src/eu/engys/gui/events/application/ApplicationEvent.java index 4fb2654..755d747 100644 --- a/src/eu/engys/gui/events/application/ApplicationEvent.java +++ b/src/eu/engys/gui/events/application/ApplicationEvent.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.events.application; diff --git a/src/eu/engys/gui/events/application/BaseMeshTypeChangedEvent.java b/src/eu/engys/gui/events/application/BaseMeshTypeChangedEvent.java index 6368c06..97be305 100644 --- a/src/eu/engys/gui/events/application/BaseMeshTypeChangedEvent.java +++ b/src/eu/engys/gui/events/application/BaseMeshTypeChangedEvent.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.events.application; diff --git a/src/eu/engys/gui/events/application/LicenseChangedEvent.java b/src/eu/engys/gui/events/application/LicenseChangedEvent.java new file mode 100644 index 0000000..b218533 --- /dev/null +++ b/src/eu/engys/gui/events/application/LicenseChangedEvent.java @@ -0,0 +1,36 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ + +package eu.engys.gui.events.application; + +import eu.engys.gui.events.EventObject; + +public class LicenseChangedEvent extends EventObject implements ApplicationEvent { + + public LicenseChangedEvent() { + super(); + } + +} diff --git a/src/eu/engys/gui/events/application/OpenMonitorEvent.java b/src/eu/engys/gui/events/application/OpenMonitorEvent.java index 947cffe..602ce33 100644 --- a/src/eu/engys/gui/events/application/OpenMonitorEvent.java +++ b/src/eu/engys/gui/events/application/OpenMonitorEvent.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.events.application; diff --git a/src/eu/engys/gui/events/view3D/ActorExtractEvent.java b/src/eu/engys/gui/events/view3D/ActorExtractEvent.java index 0b21f47..7ac9cd8 100644 --- a/src/eu/engys/gui/events/view3D/ActorExtractEvent.java +++ b/src/eu/engys/gui/events/view3D/ActorExtractEvent.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.events.view3D; diff --git a/src/eu/engys/gui/events/view3D/ActorPopUpEvent.java b/src/eu/engys/gui/events/view3D/ActorPopUpEvent.java index 121292d..3406054 100644 --- a/src/eu/engys/gui/events/view3D/ActorPopUpEvent.java +++ b/src/eu/engys/gui/events/view3D/ActorPopUpEvent.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.events.view3D; diff --git a/src/eu/engys/gui/events/view3D/ActorSelectionEvent.java b/src/eu/engys/gui/events/view3D/ActorSelectionEvent.java index 41556ee..56e059e 100644 --- a/src/eu/engys/gui/events/view3D/ActorSelectionEvent.java +++ b/src/eu/engys/gui/events/view3D/ActorSelectionEvent.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.events.view3D; diff --git a/src/eu/engys/gui/events/view3D/ActorVisibilityEvent.java b/src/eu/engys/gui/events/view3D/ActorVisibilityEvent.java index f14f6eb..e51377e 100644 --- a/src/eu/engys/gui/events/view3D/ActorVisibilityEvent.java +++ b/src/eu/engys/gui/events/view3D/ActorVisibilityEvent.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.events.view3D; diff --git a/src/eu/engys/gui/events/view3D/AddSTLEvent.java b/src/eu/engys/gui/events/view3D/AddSTLEvent.java index dc838e1..52c5ee6 100644 --- a/src/eu/engys/gui/events/view3D/AddSTLEvent.java +++ b/src/eu/engys/gui/events/view3D/AddSTLEvent.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.events.view3D; diff --git a/src/eu/engys/gui/events/view3D/AddSurfaceEvent.java b/src/eu/engys/gui/events/view3D/AddSurfaceEvent.java index 6a9c009..bcf77eb 100644 --- a/src/eu/engys/gui/events/view3D/AddSurfaceEvent.java +++ b/src/eu/engys/gui/events/view3D/AddSurfaceEvent.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.events.view3D; diff --git a/src/eu/engys/gui/events/view3D/AxisEvent.java b/src/eu/engys/gui/events/view3D/AxisEvent.java index 3a4fa77..b2f820b 100644 --- a/src/eu/engys/gui/events/view3D/AxisEvent.java +++ b/src/eu/engys/gui/events/view3D/AxisEvent.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.events.view3D; diff --git a/src/eu/engys/gui/events/view3D/BoxEvent.java b/src/eu/engys/gui/events/view3D/BoxEvent.java index 1b9b32e..939752f 100644 --- a/src/eu/engys/gui/events/view3D/BoxEvent.java +++ b/src/eu/engys/gui/events/view3D/BoxEvent.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.events.view3D; diff --git a/src/eu/engys/gui/events/view3D/ChangeSurfaceEvent.java b/src/eu/engys/gui/events/view3D/ChangeSurfaceEvent.java index 35d54c1..e911df9 100644 --- a/src/eu/engys/gui/events/view3D/ChangeSurfaceEvent.java +++ b/src/eu/engys/gui/events/view3D/ChangeSurfaceEvent.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.events.view3D; diff --git a/src/eu/engys/gui/events/view3D/ColorSurfaceEvent.java b/src/eu/engys/gui/events/view3D/ColorSurfaceEvent.java index e7e438b..eb6fff1 100644 --- a/src/eu/engys/gui/events/view3D/ColorSurfaceEvent.java +++ b/src/eu/engys/gui/events/view3D/ColorSurfaceEvent.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.events.view3D; diff --git a/src/eu/engys/gui/events/view3D/FilterSurfaceEvent.java b/src/eu/engys/gui/events/view3D/FilterSurfaceEvent.java new file mode 100644 index 0000000..ed3666e --- /dev/null +++ b/src/eu/engys/gui/events/view3D/FilterSurfaceEvent.java @@ -0,0 +1,43 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ + +package eu.engys.gui.events.view3D; + +import eu.engys.core.project.geometry.Surface; +import eu.engys.gui.events.EventObject; + +public class FilterSurfaceEvent extends EventObject implements View3DEvent { + + private Surface[] selection; + + public FilterSurfaceEvent(Surface[] selection) { + super(); + this.selection = selection; + } + + public Surface[] getSelection() { + return selection; + } +} diff --git a/src/eu/engys/gui/events/view3D/GlassPaneEvent.java b/src/eu/engys/gui/events/view3D/GlassPaneEvent.java new file mode 100644 index 0000000..6094814 --- /dev/null +++ b/src/eu/engys/gui/events/view3D/GlassPaneEvent.java @@ -0,0 +1,42 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ + +package eu.engys.gui.events.view3D; + +import eu.engys.gui.events.EventObject; +import eu.engys.gui.events.application.ApplicationEvent; + +public class GlassPaneEvent extends EventObject implements ApplicationEvent { + + private boolean active; + + public GlassPaneEvent(boolean active) { + this.active = active; + } + + public boolean isActive() { + return active; + } +} diff --git a/src/eu/engys/gui/events/view3D/LayersCoverageEvent.java b/src/eu/engys/gui/events/view3D/LayersCoverageEvent.java index 4742222..135f7be 100644 --- a/src/eu/engys/gui/events/view3D/LayersCoverageEvent.java +++ b/src/eu/engys/gui/events/view3D/LayersCoverageEvent.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.events.view3D; diff --git a/src/eu/engys/gui/events/view3D/MeshQualityEvent.java b/src/eu/engys/gui/events/view3D/MeshQualityEvent.java index 60f38a9..1276f53 100644 --- a/src/eu/engys/gui/events/view3D/MeshQualityEvent.java +++ b/src/eu/engys/gui/events/view3D/MeshQualityEvent.java @@ -1,34 +1,33 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.events.view3D; import eu.engys.core.dictionary.model.EventActionType; import eu.engys.gui.events.EventObject; -import eu.engys.gui.view3D.QualityInfo; +import eu.engys.gui.view3D.quality.QualityInfo; public class MeshQualityEvent extends EventObject implements View3DEvent { diff --git a/src/eu/engys/gui/events/view3D/PlaneEvent.java b/src/eu/engys/gui/events/view3D/PlaneEvent.java index 2e53ed2..0f79aab 100644 --- a/src/eu/engys/gui/events/view3D/PlaneEvent.java +++ b/src/eu/engys/gui/events/view3D/PlaneEvent.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.events.view3D; @@ -32,55 +31,48 @@ import eu.engys.util.ui.textfields.DoubleField; public class PlaneEvent extends EventObject implements View3DEvent { + private String key; private DoubleField[] normal; private DoubleField[] origin; private EventActionType action; private boolean interactive; - public PlaneEvent(DoubleField[] origin, DoubleField[] normal, EventActionType action) { + public PlaneEvent(String key, DoubleField[] origin, DoubleField[] normal, EventActionType action) { super(); + this.key = key; this.origin = origin; this.normal = normal; this.action = action; this.interactive = true; } - public PlaneEvent(DoubleField[] origin, DoubleField[] normal, EventActionType action, boolean interactive) { + public PlaneEvent(String key, DoubleField[] origin, DoubleField[] normal, EventActionType action, boolean interactive) { super(); + this.key = key; this.origin = origin; this.normal = normal; this.action = action; this.interactive = interactive; } + + public String getKey() { + return key; + } public DoubleField[] getOrigin() { return origin; } - public void setOrigin(DoubleField[] origin) { - this.origin = origin; - } - public DoubleField[] getNormal() { return normal; } - public void setNormal(DoubleField[] normal) { - this.normal = normal; - } - public EventActionType getAction() { return action; } - public void setAction(EventActionType action) { - this.action = action; - } - - public void setInteractive(boolean interactive) { - this.interactive = interactive; - } public boolean isInteractive() { return interactive; } + } diff --git a/src/eu/engys/gui/events/view3D/PointEvent.java b/src/eu/engys/gui/events/view3D/PointEvent.java index 4efdc27..e85ab42 100644 --- a/src/eu/engys/gui/events/view3D/PointEvent.java +++ b/src/eu/engys/gui/events/view3D/PointEvent.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.events.view3D; diff --git a/src/eu/engys/gui/events/view3D/RemoveSurfaceEvent.java b/src/eu/engys/gui/events/view3D/RemoveSurfaceEvent.java index 468ee77..8dd0c0c 100644 --- a/src/eu/engys/gui/events/view3D/RemoveSurfaceEvent.java +++ b/src/eu/engys/gui/events/view3D/RemoveSurfaceEvent.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.events.view3D; diff --git a/src/eu/engys/gui/events/view3D/RenameSurfaceEvent.java b/src/eu/engys/gui/events/view3D/RenameSurfaceEvent.java index 0eb8c1a..943c54c 100644 --- a/src/eu/engys/gui/events/view3D/RenameSurfaceEvent.java +++ b/src/eu/engys/gui/events/view3D/RenameSurfaceEvent.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.events.view3D; diff --git a/src/eu/engys/gui/events/view3D/RotatedBoxEvent.java b/src/eu/engys/gui/events/view3D/RotatedBoxEvent.java new file mode 100644 index 0000000..2bfd4f0 --- /dev/null +++ b/src/eu/engys/gui/events/view3D/RotatedBoxEvent.java @@ -0,0 +1,77 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ + +package eu.engys.gui.events.view3D; + +import eu.engys.core.dictionary.model.EventActionType; +import eu.engys.gui.events.EventObject; +import eu.engys.util.ui.textfields.DoubleField; + +public class RotatedBoxEvent extends EventObject implements View3DEvent { + + private EventActionType action; + private DoubleField[] center; + private DoubleField[] delta; + private DoubleField[] rotation; + + public RotatedBoxEvent(DoubleField[] center, DoubleField[] delta, DoubleField[] rotation, EventActionType action) { + super(); + this.center = center; + this.delta = delta; + this.rotation = rotation; + this.action = action; + } + + public EventActionType getAction() { + return action; + } + public void setAction(EventActionType action) { + this.action = action; + } + + public DoubleField[] getCenter() { + return center; + } + public void setCenter(DoubleField[] center) { + this.center = center; + } + + public DoubleField[] getDelta() { + return delta; + } + public void setDelta(DoubleField[] delta) { + this.delta = delta; + } + + public DoubleField[] getRotation() { + return rotation; + } + public void setRotation(DoubleField[] rotation) { + this.rotation = rotation; + } + + + +} diff --git a/src/eu/engys/gui/events/view3D/ScalarBarWidgetEvent.java b/src/eu/engys/gui/events/view3D/ScalarBarWidgetEvent.java index 9c98a80..5c7174e 100644 --- a/src/eu/engys/gui/events/view3D/ScalarBarWidgetEvent.java +++ b/src/eu/engys/gui/events/view3D/ScalarBarWidgetEvent.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.events.view3D; diff --git a/src/eu/engys/gui/events/view3D/SelectCellZonesEvent.java b/src/eu/engys/gui/events/view3D/SelectCellZonesEvent.java index dd26ab8..62ed367 100644 --- a/src/eu/engys/gui/events/view3D/SelectCellZonesEvent.java +++ b/src/eu/engys/gui/events/view3D/SelectCellZonesEvent.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.events.view3D; diff --git a/src/eu/engys/gui/events/view3D/SelectFaceZonesEvent.java b/src/eu/engys/gui/events/view3D/SelectFaceZonesEvent.java new file mode 100644 index 0000000..1c68de3 --- /dev/null +++ b/src/eu/engys/gui/events/view3D/SelectFaceZonesEvent.java @@ -0,0 +1,43 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ + +package eu.engys.gui.events.view3D; + +import eu.engys.core.project.zero.facezones.FaceZone; +import eu.engys.gui.events.EventObject; + +public class SelectFaceZonesEvent extends EventObject implements View3DEvent { + + private FaceZone[] selection; + + public SelectFaceZonesEvent(FaceZone[] selection) { + super(); + this.selection = selection; + } + + public FaceZone[] getSelection() { + return selection; + } +} diff --git a/src/eu/engys/gui/events/view3D/SelectPatchesEvent.java b/src/eu/engys/gui/events/view3D/SelectPatchesEvent.java index f05cba8..8f8d3aa 100644 --- a/src/eu/engys/gui/events/view3D/SelectPatchesEvent.java +++ b/src/eu/engys/gui/events/view3D/SelectPatchesEvent.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.events.view3D; diff --git a/src/eu/engys/gui/events/view3D/SelectSurfaceEvent.java b/src/eu/engys/gui/events/view3D/SelectSurfaceEvent.java index 00bd45a..32b3357 100644 --- a/src/eu/engys/gui/events/view3D/SelectSurfaceEvent.java +++ b/src/eu/engys/gui/events/view3D/SelectSurfaceEvent.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.events.view3D; diff --git a/src/eu/engys/gui/events/view3D/SelectionEvent.java b/src/eu/engys/gui/events/view3D/SelectionEvent.java index 6a0102a..08d2bd4 100644 --- a/src/eu/engys/gui/events/view3D/SelectionEvent.java +++ b/src/eu/engys/gui/events/view3D/SelectionEvent.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.events.view3D; diff --git a/src/eu/engys/gui/events/view3D/TransformSurfaceEvent.java b/src/eu/engys/gui/events/view3D/TransformSurfaceEvent.java index c9714fb..e436580 100644 --- a/src/eu/engys/gui/events/view3D/TransformSurfaceEvent.java +++ b/src/eu/engys/gui/events/view3D/TransformSurfaceEvent.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.events.view3D; diff --git a/src/eu/engys/gui/events/view3D/View3DEvent.java b/src/eu/engys/gui/events/view3D/View3DEvent.java index 53cbb22..4be05e5 100644 --- a/src/eu/engys/gui/events/view3D/View3DEvent.java +++ b/src/eu/engys/gui/events/view3D/View3DEvent.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.events.view3D; diff --git a/src/eu/engys/gui/events/view3D/VisibleItemEvent.java b/src/eu/engys/gui/events/view3D/VisibleItemEvent.java index c652022..03b318d 100644 --- a/src/eu/engys/gui/events/view3D/VisibleItemEvent.java +++ b/src/eu/engys/gui/events/view3D/VisibleItemEvent.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.events.view3D; diff --git a/src/eu/engys/gui/events/view3D/VolumeReportEvent.java b/src/eu/engys/gui/events/view3D/VolumeReportEvent.java index 6376a6c..09dded6 100644 --- a/src/eu/engys/gui/events/view3D/VolumeReportEvent.java +++ b/src/eu/engys/gui/events/view3D/VolumeReportEvent.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.events.view3D; diff --git a/src/eu/engys/gui/events/view3D/VolumeReportVisibilityEvent.java b/src/eu/engys/gui/events/view3D/VolumeReportVisibilityEvent.java index a8b8e91..5086a06 100644 --- a/src/eu/engys/gui/events/view3D/VolumeReportVisibilityEvent.java +++ b/src/eu/engys/gui/events/view3D/VolumeReportVisibilityEvent.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.events.view3D; diff --git a/src/eu/engys/gui/mesh/GeometryPanel.java b/src/eu/engys/gui/mesh/GeometryPanel.java index 3fd8fe1..f9cd8e2 100644 --- a/src/eu/engys/gui/mesh/GeometryPanel.java +++ b/src/eu/engys/gui/mesh/GeometryPanel.java @@ -1,55 +1,53 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.mesh; +import javax.swing.JButton; + import eu.engys.core.project.Model; -import eu.engys.core.project.geometry.Surface; -import eu.engys.util.progress.ProgressMonitor; public interface GeometryPanel { - void addSTL(); + void addSTL(); - void addBox(); + void addBox(); - void addCylinder(); + void addCylinder(); - void addSphere(); + void addSphere(); - void addRing(); + void addRing(); - void addPlane(); + void addPlane(); - void renameSurface(String text); + void renameSurface(String text); - void changeSurface(Surface surface); + void changeSurface(); - Model getModel(); + Model getModel(); - ProgressMonitor getMonitor(); + JButton[] getShapeButtons(); } diff --git a/src/eu/engys/gui/mesh/Mesh.java b/src/eu/engys/gui/mesh/Mesh.java index 36e3e7f..600181b 100644 --- a/src/eu/engys/gui/mesh/Mesh.java +++ b/src/eu/engys/gui/mesh/Mesh.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.mesh; diff --git a/src/eu/engys/gui/mesh/Mesh3DElement.java b/src/eu/engys/gui/mesh/Mesh3DElement.java index 72547fe..6a57c33 100644 --- a/src/eu/engys/gui/mesh/Mesh3DElement.java +++ b/src/eu/engys/gui/mesh/Mesh3DElement.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.mesh; diff --git a/src/eu/engys/gui/mesh/MeshElement.java b/src/eu/engys/gui/mesh/MeshElement.java index 988ba0f..53794c2 100644 --- a/src/eu/engys/gui/mesh/MeshElement.java +++ b/src/eu/engys/gui/mesh/MeshElement.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.mesh; diff --git a/src/eu/engys/gui/mesh/StandardBoundaryMeshPanel.java b/src/eu/engys/gui/mesh/StandardBoundaryMeshPanel.java new file mode 100644 index 0000000..e46f174 --- /dev/null +++ b/src/eu/engys/gui/mesh/StandardBoundaryMeshPanel.java @@ -0,0 +1,46 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.gui.mesh; + +import javax.inject.Inject; +import javax.swing.JLabel; + +import eu.engys.core.project.Model; +import eu.engys.gui.mesh.panels.AbstractBoundaryMeshPanel; +import eu.engys.util.ui.builder.PanelBuilder; + +public class StandardBoundaryMeshPanel extends AbstractBoundaryMeshPanel { + + @Inject + public StandardBoundaryMeshPanel(Model model) { + super(model); + } + + @Override + protected void addExtraComponents(PanelBuilder builder) { + builder.addComponent(new JLabel("Press Check button to update statistics")); + } + +} diff --git a/src/eu/engys/gui/mesh/actions/AddIGES.java b/src/eu/engys/gui/mesh/actions/AddIGES.java deleted file mode 100644 index fb8ef5c..0000000 --- a/src/eu/engys/gui/mesh/actions/AddIGES.java +++ /dev/null @@ -1,153 +0,0 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - -package eu.engys.gui.mesh.actions; - -import java.io.File; -import java.io.FilenameFilter; -import java.io.IOException; -import java.util.ArrayList; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; - -import javax.swing.JOptionPane; - -import org.apache.commons.io.FileUtils; -import org.apache.commons.io.FilenameUtils; - -import eu.engys.core.controller.actions.RunCommand; -import eu.engys.core.project.Model; -import eu.engys.core.project.geometry.stl.AffineTransform; -import eu.engys.core.project.geometry.stl.ImportIGES; -import eu.engys.core.project.geometry.surface.Stl; -import eu.engys.util.TempFolder; -import eu.engys.util.filechooser.AbstractFileChooser.ReturnValue; -import eu.engys.util.progress.ProgressMonitor; -import eu.engys.util.ui.UiUtil; - -public abstract class AddIGES { - - private ProgressMonitor monitor; - private Model model; - - public AddIGES(Model model, ProgressMonitor monitor) { - this.model = model; - this.monitor = monitor; - } - - public void execute() { - IGESFileChooserWrapper fc = new IGESFileChooserWrapper(); - ReturnValue returnedValue = fc.showOpenDialog(); - - if (returnedValue.isApprove()) { - final File[] files = fc.getSelectedFiles(); - final AffineTransform[] transformations = fc.getSelectedTransform(); - final boolean split = fc.getIGESAccessory().getSplit(); - final double precision = fc.getIGESAccessory().getPrecision(); - - boolean filesOK = files != null && files.length > 0; - boolean transformationsOK = transformations != null && transformations.length > 0; - boolean sameLength = transformations.length == files.length; - if (filesOK && transformationsOK && sameLength) { - try { - convertIGES(files, transformations, split, precision); - } catch (IOException e) { - JOptionPane.showMessageDialog(UiUtil.getActiveWindow(), "Unable to load selected IGES: " + e.getMessage(), "File Type Error", JOptionPane.ERROR_MESSAGE); - } - } else { - JOptionPane.showMessageDialog(UiUtil.getActiveWindow(), "Unable to load selected IGES", "File Type Error", JOptionPane.ERROR_MESSAGE); - } - } - } - - public void convertIGES(File[] igesToCopy, final AffineTransform[] transformations, final boolean split, double precision) throws IOException { - final File[] copiedIgesList = new File[igesToCopy.length]; - final File[] createdStlList = new File[igesToCopy.length]; - final File tmpFolder = TempFolder.get(AddIGES.class.getSimpleName()); - - for (int i = 0; i < igesToCopy.length; i++) { - File iges = igesToCopy[i]; - FileUtils.copyFileToDirectory(iges, tmpFolder); - - copiedIgesList[i] = new File(tmpFolder, iges.getName()); - createdStlList[i] = new File(tmpFolder, FilenameUtils.removeExtension(iges.getName()) + ".stl"); - } - - Runnable loadSTLRunnable = new Runnable() { - @Override - public void run() { - monitor.setIndeterminate(false); - monitor.start("Loading IGES Files", false, new Runnable() { - @Override - public void run() { - Map fileMap = getSTLFilesToImport(createdStlList, split); - List keySet = new ArrayList(fileMap.keySet()); - List stls = new ArrayList<>(); - for (int i = 0; i < keySet.size(); i++) { - String key = keySet.get(i); - for (File stlFile : fileMap.get(key)) { - monitor.info(String.format("Loading %s ", stlFile.getAbsolutePath())); - - Stl stl = model.getGeometry().getFactory().readSTL(stlFile, monitor); - stl.setTransformation(transformations[i]); - stls.add(stl); - - } - } - postLoad(stls); - FileUtils.deleteQuietly(tmpFolder); - monitor.end(); - } - }); - } - }; - - RunCommand command = new ImportIGES(model, loadSTLRunnable, copiedIgesList, createdStlList, split, precision); - command.beforeExecute(); - command.executeClient(); - } - - private Map getSTLFilesToImport(File[] createdStlList, boolean split) { - final Map map = new LinkedHashMap(); - for (final File stl : createdStlList) { - if (split) { - File[] stlComponents = stl.getParentFile().listFiles(new FilenameFilter() { - @Override - public boolean accept(File dir, String name) { - return name.startsWith(FilenameUtils.removeExtension(stl.getName())) && name.contains("Component"); - } - }); - map.put(stl.getName(), stlComponents); - } else { - map.put(stl.getName(), new File[] { stl }); - } - } - return map; - } - - public abstract void postLoad(List stls); - -} diff --git a/src/eu/engys/gui/mesh/actions/AddSTL.java b/src/eu/engys/gui/mesh/actions/AddSTL.java index 3b7be8a..7c43482 100644 --- a/src/eu/engys/gui/mesh/actions/AddSTL.java +++ b/src/eu/engys/gui/mesh/actions/AddSTL.java @@ -1,29 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.mesh.actions; import java.io.File; @@ -54,7 +52,7 @@ public abstract class AddSTL { } public void execute() { - STLFileChooserWrapper fc = new STLFileChooserWrapper(); + STLFileChooserWrapper fc = new STLFileChooserWrapper(true); ReturnValue returnedValue = fc.showOpenDialog(); if (returnedValue.isApprove()) { @@ -63,20 +61,20 @@ public abstract class AddSTL { boolean filesOK = files != null && files.length > 0; boolean transformationsOK = transformations != null && transformations.length > 0; - boolean sameLength = transformations.length == files.length; - if (filesOK && transformationsOK && sameLength) { - monitor.setIndeterminate(false); - monitor.start("Loading STL Files", false, new Runnable() { + boolean sameLength = filesOK && transformationsOK && transformations.length == files.length; + + if (sameLength) { + monitor.setIndeterminate(false); + monitor.start("Loading STL Files", false, new Runnable() { @Override public void run() { List stls = new ArrayList<>(); for (int i = 0; i < files.length; i++) { File file = files[i]; AffineTransform transform = transformations[i]; - + if (ArchiveUtils.isArchive(file)) { File tmpFolder = TempFolder.get(AddSTL.class.getSimpleName()); - List extractedFiles = ArchiveUtils.unarchive(file, tmpFolder); for (File target : extractedFiles) { monitor.info(String.format("Loading %s-%s ", file.getAbsolutePath(), target.getName())); diff --git a/src/eu/engys/gui/mesh/actions/AddSTLArea.java b/src/eu/engys/gui/mesh/actions/AddSTLArea.java new file mode 100644 index 0000000..eea7a66 --- /dev/null +++ b/src/eu/engys/gui/mesh/actions/AddSTLArea.java @@ -0,0 +1,82 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.gui.mesh.actions; + +import java.io.File; + +import javax.swing.JOptionPane; + +import eu.engys.core.project.Model; +import eu.engys.core.project.geometry.stl.AffineTransform; +import eu.engys.core.project.geometry.surface.StlArea; +import eu.engys.util.filechooser.AbstractFileChooser.ReturnValue; +import eu.engys.util.progress.ProgressMonitor; +import eu.engys.util.ui.UiUtil; + +public abstract class AddSTLArea { + + private ProgressMonitor monitor; + private Model model; + + public AddSTLArea(Model model, ProgressMonitor monitor) { + this.model = model; + this.monitor = monitor; + } + + public void execute() { + STLFileChooserWrapper fc = new STLFileChooserWrapper(false); + ReturnValue returnedValue = fc.showOpenDialog(); + + if (returnedValue.isApprove()) { + final File file = fc.getSelectedFile(); + final AffineTransform[] transformations = fc.getSelectedTransform(); + + boolean filesOK = file != null; + boolean transformationsOK = transformations != null && transformations.length > 0; + boolean isOK = filesOK && transformationsOK; + + if (isOK) { + monitor.setIndeterminate(false); + monitor.start("Loading STL File", false, new Runnable() { + @Override + public void run() { + AffineTransform transform = transformations[0]; + + monitor.info(String.format("Loading %s ", file.getAbsolutePath())); + StlArea stlArea = model.getGeometry().getFactory().readSTLArea(file, monitor); + stlArea.setTransformation(transform); + postLoad(stlArea); + monitor.end(); + } + }); + } else { + JOptionPane.showMessageDialog(UiUtil.getActiveWindow(), "Unable to load selected STLs", "File Type Error", JOptionPane.ERROR_MESSAGE); + } + } + } + + public abstract void postLoad(StlArea stlArea); + +} diff --git a/src/eu/engys/gui/mesh/actions/DefaultMeshActions.java b/src/eu/engys/gui/mesh/actions/DefaultMeshActions.java index 90c3bc0..782cc3e 100644 --- a/src/eu/engys/gui/mesh/actions/DefaultMeshActions.java +++ b/src/eu/engys/gui/mesh/actions/DefaultMeshActions.java @@ -1,41 +1,35 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.mesh.actions; -import java.awt.BorderLayout; -import java.awt.FlowLayout; -import java.awt.GridLayout; -import java.awt.event.ActionEvent; +import static eu.engys.core.controller.AbstractController.MESH_CHECK; +import static eu.engys.core.controller.AbstractController.MESH_CREATE; +import static eu.engys.core.controller.AbstractController.MESH_DELETE; +import static eu.engys.core.controller.AbstractController.MESH_STRETCH; -import javax.swing.AbstractAction; import javax.swing.Action; -import javax.swing.Icon; -import javax.swing.JButton; -import javax.swing.JDialog; -import javax.swing.JPanel; import eu.engys.core.controller.Controller; import eu.engys.core.presentation.ActionManager; @@ -43,122 +37,40 @@ import eu.engys.core.project.Model; import eu.engys.gui.Actions; import eu.engys.gui.mesh.panels.DefaultMeshAdvancedOptionsPanel; import eu.engys.util.progress.ProgressMonitor; -import eu.engys.util.ui.ResourcesUtil; -import eu.engys.util.ui.UiUtil; -import eu.engys.util.ui.ViewAction; public abstract class DefaultMeshActions implements Actions { - public static final String ADVANCED_OPTIONS = "Advanced Options"; protected Model model; protected Controller controller; protected ProgressMonitor monitor; - protected DefaultMeshAdvancedOptionsPanel generalOptionsPanel; - protected final Action createMesh, checkMesh, deleteMesh, virtualMesh; + protected Action createMesh, stretchMesh, checkMesh, deleteMesh, advancedMeshOptions; - public DefaultMeshActions(Model model, Controller controller, ProgressMonitor monitor, DefaultMeshAdvancedOptionsPanel generalOptionsPanel) { + public DefaultMeshActions(Model model, Controller controller, ProgressMonitor monitor, DefaultMeshAdvancedOptionsPanel optionsPanel) { this.model = model; this.controller = controller; this.monitor = monitor; - this.generalOptionsPanel = generalOptionsPanel; + this.advancedMeshOptions = new OpenMeshAdvancedOptionsDialog(optionsPanel); - createMesh = ActionManager.getInstance().get("mesh.create"); - checkMesh = ActionManager.getInstance().get("mesh.check"); - deleteMesh = ActionManager.getInstance().get("mesh.delete"); - virtualMesh = ActionManager.getInstance().get("mesh.batch"); + createMesh = ActionManager.getInstance().get(MESH_CREATE); + if (ActionManager.getInstance().contains(MESH_STRETCH)) { + stretchMesh = ActionManager.getInstance().get(MESH_STRETCH); + } + checkMesh = ActionManager.getInstance().get(MESH_CHECK); + deleteMesh = ActionManager.getInstance().get(MESH_DELETE); } @Override public void update() { - createMesh.setEnabled(!model.getGeometry().isEmpty()); - checkMesh.setEnabled(!model.getPatches().isEmpty()); - deleteMesh.setEnabled(!model.getPatches().isEmpty()); + boolean geometryNotEmpty = !model.getGeometry().isEmpty(); + boolean meshNotEmpty = !model.getPatches().isEmpty(); + + createMesh.setEnabled(geometryNotEmpty); + if (ActionManager.getInstance().contains(MESH_STRETCH)) { + stretchMesh.setEnabled(meshNotEmpty); + } + checkMesh.setEnabled(meshNotEmpty); + deleteMesh.setEnabled(meshNotEmpty); } - protected final Action openOptionsDialog = new ViewAction(OPEN_OPTIONS_DIALOG_LABEL, OPT_ICON, OPEN_OPTIONS_DIALOG_TOOLTIP) { - - private JDialog dialog; - - public void actionPerformed(ActionEvent e) { - // Commented because there seems to be no reason to save the case - // here - // controller.save(null); - createGeneralOptionsDialog(); - generalOptionsPanel.load(); - dialog.setVisible(true); - } - - private void createGeneralOptionsDialog() { - if (dialog == null) { - dialog = new JDialog(UiUtil.getActiveWindow()); - dialog.setName("general.options.dialog"); - - JPanel mainPanel = new JPanel(new BorderLayout()); - mainPanel.setName("general.options.panel"); - - JPanel buttonsPanel = new JPanel(new GridLayout(1, 2)); - JPanel leftButtonsPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); - JPanel rightButtonsPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); - buttonsPanel.add(leftButtonsPanel); - buttonsPanel.add(rightButtonsPanel); - - generalOptionsPanel.layoutPanel(); - mainPanel.add(generalOptionsPanel.getPanel(), BorderLayout.CENTER); - - AbstractAction saveAndCloseDialogAction = new AbstractAction("OK") { - @Override - public void actionPerformed(ActionEvent e) { - generalOptionsPanel.save(); - generalOptionsPanel.handleClose(); - dialog.setVisible(false); - } - }; - - AbstractAction cancelAction = new AbstractAction("Cancel") { - @Override - public void actionPerformed(ActionEvent e) { - generalOptionsPanel.handleClose(); - dialog.setVisible(false); - } - }; - - AbstractAction resetToDefaultsAction = new AbstractAction("Reset") { - @Override - public void actionPerformed(ActionEvent e) { - generalOptionsPanel.resetToDefaults(); - } - }; - - JButton okButton = new JButton(saveAndCloseDialogAction); - okButton.setName("OK"); - rightButtonsPanel.add(okButton); - - JButton cancelButton = new JButton(cancelAction); - cancelButton.setName("Cancel"); - rightButtonsPanel.add(cancelButton); - - JButton resetButton = new JButton(resetToDefaultsAction); - resetButton.setName("Reset"); - leftButtonsPanel.add(resetButton); - - mainPanel.add(buttonsPanel, BorderLayout.SOUTH); - - dialog.setTitle(ADVANCED_OPTIONS); - dialog.add(mainPanel); - dialog.setSize(600, 420); - dialog.setLocationRelativeTo(null); - dialog.setModal(false); - dialog.getRootPane().setDefaultButton(okButton); - } - } - }; - - /** - * Resources - */ - - public static final String OPEN_OPTIONS_DIALOG_LABEL = ResourcesUtil.getString("mesh.options.label"); - public static final String OPEN_OPTIONS_DIALOG_TOOLTIP = ResourcesUtil.getString("mesh.options.tooltip"); - public static final Icon OPT_ICON = ResourcesUtil.getIcon("general.options.icon"); } diff --git a/src/eu/engys/gui/mesh/actions/IGESAccessory.java b/src/eu/engys/gui/mesh/actions/IGESAccessory.java index e369c72..f21ac78 100644 --- a/src/eu/engys/gui/mesh/actions/IGESAccessory.java +++ b/src/eu/engys/gui/mesh/actions/IGESAccessory.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.mesh.actions; import javax.swing.JCheckBox; diff --git a/src/eu/engys/gui/mesh/actions/IGESFileChooserWrapper.java b/src/eu/engys/gui/mesh/actions/IGESFileChooserWrapper.java index 1fcf7db..d3e7126 100644 --- a/src/eu/engys/gui/mesh/actions/IGESFileChooserWrapper.java +++ b/src/eu/engys/gui/mesh/actions/IGESFileChooserWrapper.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.mesh.actions; @@ -41,18 +40,20 @@ public class IGESFileChooserWrapper { private IGESAccessory igesAccessory; private HelyxFileChooser chooser; + public static final HelyxFileFilter ALL_FILTER = new HelyxFileFilter("All known formats (*.igs, *.iges, *.stp, *.step)", "igs", "iges", "stp", "step"); public static final HelyxFileFilter IGES_FILTER = new HelyxFileFilter("IGES File (*.igs, *.iges)", "igs", "iges"); + public static final HelyxFileFilter STEP_FILTER = new HelyxFileFilter("STEP File (*.stp, *.step)", "stp", "step"); public IGESFileChooserWrapper() { chooser = new HelyxFileChooser(PrefUtil.getWorkDir(PrefUtil.LAST_IMPORT_DIR).getAbsolutePath()); - chooser.setTitle("Open IGES"); + chooser.setTitle("Open IGES/STEP"); chooser.setSelectionMode(SelectionMode.FILES_ONLY); chooser.setMultiSelectionEnabled(true); igesAccessory = new IGESAccessory(chooser); } public ReturnValue showOpenDialog() throws HeadlessException { - ReturnValue returnedValue = chooser.showOpenDialog(igesAccessory, UiUtil.getPreferredScreenSize(), IGES_FILTER); + ReturnValue returnedValue = chooser.showOpenDialog(igesAccessory, UiUtil.getPreferredScreenSize(), ALL_FILTER, IGES_FILTER, STEP_FILTER); if (returnedValue.isApprove()) { final File[] files = getSelectedFiles(); if (files != null && files.length > 0) { diff --git a/src/eu/engys/gui/mesh/actions/OpenMeshAdvancedOptionsDialog.java b/src/eu/engys/gui/mesh/actions/OpenMeshAdvancedOptionsDialog.java new file mode 100644 index 0000000..1a6c32c --- /dev/null +++ b/src/eu/engys/gui/mesh/actions/OpenMeshAdvancedOptionsDialog.java @@ -0,0 +1,135 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.gui.mesh.actions; + +import static eu.engys.util.ui.UiUtil.DIALOG_CANCEL_LABEL; +import static eu.engys.util.ui.UiUtil.DIALOG_OK_LABEL; +import static eu.engys.util.ui.UiUtil.RESET_BUTTON_LABEL; + +import java.awt.BorderLayout; +import java.awt.FlowLayout; +import java.awt.GridLayout; +import java.awt.event.ActionEvent; + +import javax.swing.AbstractAction; +import javax.swing.Icon; +import javax.swing.JButton; +import javax.swing.JDialog; +import javax.swing.JPanel; + +import eu.engys.gui.mesh.panels.DefaultMeshAdvancedOptionsPanel; +import eu.engys.util.ui.ResourcesUtil; +import eu.engys.util.ui.UiUtil; +import eu.engys.util.ui.ViewAction; + +public class OpenMeshAdvancedOptionsDialog extends ViewAction { + + public static final String OPEN_OPTIONS_DIALOG_LABEL = ResourcesUtil.getString("mesh.options.label"); + public static final Icon OPEN_OPTIONS_ICON = ResourcesUtil.getIcon("mesh.options.icon"); + public static final String OPEN_OPTIONS_DIALOG_TOOLTIP = ResourcesUtil.getString("mesh.options.tooltip"); + + public static final String ADVANCED_OPTIONS = "Advanced Options"; + + private JDialog dialog; + private DefaultMeshAdvancedOptionsPanel optionsPanel; + + public OpenMeshAdvancedOptionsDialog(DefaultMeshAdvancedOptionsPanel optionsPanel) { + super(OPEN_OPTIONS_DIALOG_LABEL, OPEN_OPTIONS_ICON, OPEN_OPTIONS_DIALOG_TOOLTIP); + this.optionsPanel = optionsPanel; + } + + @Override + public void actionPerformed(ActionEvent e) { + createGeneralOptionsDialog(); + optionsPanel.load(); + dialog.setVisible(true); + + } + + private void createGeneralOptionsDialog() { + if (dialog == null) { + dialog = new JDialog(UiUtil.getActiveWindow()); + dialog.setName("general.options.dialog"); + + JPanel mainPanel = new JPanel(new BorderLayout()); + mainPanel.setName("general.options.panel"); + + JPanel buttonsPanel = new JPanel(new GridLayout(1, 2)); + JPanel leftButtonsPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); + JPanel rightButtonsPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); + buttonsPanel.add(leftButtonsPanel); + buttonsPanel.add(rightButtonsPanel); + + optionsPanel.layoutPanel(); + mainPanel.add(optionsPanel.getPanel(), BorderLayout.CENTER); + + AbstractAction saveAndCloseDialogAction = new AbstractAction(DIALOG_OK_LABEL) { + @Override + public void actionPerformed(ActionEvent e) { + optionsPanel.save(); + optionsPanel.handleClose(); + dialog.dispose(); + } + }; + + AbstractAction cancelAction = new AbstractAction(DIALOG_CANCEL_LABEL) { + @Override + public void actionPerformed(ActionEvent e) { + optionsPanel.handleClose(); + dialog.dispose(); + } + }; + + AbstractAction resetToDefaultsAction = new AbstractAction(RESET_BUTTON_LABEL) { + @Override + public void actionPerformed(ActionEvent e) { + optionsPanel.resetToDefaults(); + } + }; + + JButton okButton = new JButton(saveAndCloseDialogAction); + okButton.setName(DIALOG_OK_LABEL); + rightButtonsPanel.add(okButton); + + JButton cancelButton = new JButton(cancelAction); + cancelButton.setName(DIALOG_CANCEL_LABEL); + rightButtonsPanel.add(cancelButton); + + JButton resetButton = new JButton(resetToDefaultsAction); + resetButton.setName(RESET_BUTTON_LABEL); + leftButtonsPanel.add(resetButton); + + mainPanel.add(buttonsPanel, BorderLayout.SOUTH); + + dialog.setTitle(ADVANCED_OPTIONS); + dialog.add(mainPanel); + dialog.setSize(600, 420); + dialog.setLocationRelativeTo(null); + dialog.setModal(false); + dialog.getRootPane().setDefaultButton(okButton); + } + } + +} diff --git a/src/eu/engys/gui/mesh/actions/RunBlockMesh.java b/src/eu/engys/gui/mesh/actions/RunBlockMesh.java index f849f9e..10ca9a1 100644 --- a/src/eu/engys/gui/mesh/actions/RunBlockMesh.java +++ b/src/eu/engys/gui/mesh/actions/RunBlockMesh.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.mesh.actions; import static eu.engys.core.OpenFOAMEnvironment.getEnvironment; @@ -37,18 +36,19 @@ import static eu.engys.util.OpenFOAMCommands.DECOMPOSE_PAR; import java.io.File; import java.nio.file.Paths; +import java.util.Collections; +import java.util.concurrent.Executors; import org.apache.commons.io.FileUtils; import eu.engys.core.controller.Controller; -import eu.engys.core.controller.Controller.OpenOptions; +import eu.engys.core.controller.Controller.OpenMode; import eu.engys.core.controller.ScriptBuilder; import eu.engys.core.controller.actions.AbstractRunCommand; import eu.engys.core.executor.Executor; import eu.engys.core.executor.ExecutorHook; import eu.engys.core.executor.ExecutorListener.ExecutorState; import eu.engys.core.executor.ExecutorMonitor; -import eu.engys.core.executor.ExecutorTerminal; import eu.engys.core.executor.TerminalExecutorMonitor; import eu.engys.core.project.Model; import eu.engys.core.project.openFOAMProject; @@ -57,17 +57,21 @@ import eu.engys.util.Util; public class RunBlockMesh extends AbstractRunCommand { - public static final String ACTION_NAME = "Run Block Mesh"; + public static final String ACTION_NAME = "Block Mesh"; public static final String BLOCK_MESH_LOG = "blockMesh.log"; public static final String BLOCK_MESH_RUN = "block_mesh.run"; public static final String BLOCK_MESH_BAT = "block_mesh.bat"; private File logFile; + private String logName; + private String actionName; - public RunBlockMesh(Model model, Controller controller) { + public RunBlockMesh(Model model, Controller controller, String logName, String actionName) { super(model, controller); - this.logFile = Paths.get(model.getProject().getBaseDir().getAbsolutePath(), LOG, BLOCK_MESH_LOG).toFile(); + this.logName = logName; + this.actionName = actionName; + this.logFile = Paths.get(model.getProject().getBaseDir().getAbsolutePath(), LOG, logName).toFile(); } @Override @@ -90,14 +94,20 @@ public class RunBlockMesh extends AbstractRunCommand { @Override public void executeClient() { + if (terminal == null) { + this.terminal = new TerminalExecutorMonitor(controller.getTerminalManager(), logFile); + } + if (service == null) { + this.service = Executors.newSingleThreadExecutor(); + } + File baseDir = model.getProject().getBaseDir(); File script = getScript(); - ExecutorTerminal terminal = new TerminalExecutorMonitor(logFile); ExecutorMonitor monitor = new ExecutorMonitor(); monitor.addHook(ExecutorState.FINISH, new FinishHook()); - this.executor = Executor.script(script).description(ACTION_NAME).inFolder(baseDir).inTerminal(terminal).withMonitors(monitor).env(getEnvironment(model, BLOCK_MESH_LOG)); + this.executor = Executor.script(script).description(actionName).inFolder(baseDir).inTerminal(terminal).withMonitors(monitor).inService(service).env(getEnvironment(model, logName)); executor.exec(); } @@ -113,7 +123,7 @@ public class RunBlockMesh extends AbstractRunCommand { } private void writeScript(ScriptBuilder sb) { - printHeader(sb, ACTION_NAME.toUpperCase()); + printHeader(sb, ACTION_NAME); printVariables(sb); loadEnvironment(sb); writeCommand(sb); @@ -122,7 +132,7 @@ public class RunBlockMesh extends AbstractRunCommand { private void writeCommand(ScriptBuilder sb) { sb.append(BLOCK_MESH()); if (model.getProject().isParallel()) { - sb.append(DECOMPOSE_PAR()); + sb.append(DECOMPOSE_PAR(Collections.emptySet())); } } @@ -133,8 +143,8 @@ public class RunBlockMesh extends AbstractRunCommand { File polyMesh = Paths.get(model.getProject().getBaseDir().getAbsolutePath()).resolve(CONSTANT).resolve(POLY_MESH).toFile(); FileUtils.deleteQuietly(polyMesh); } - controller.reopenCase(OpenOptions.CURRENT_SETTINGS); - if(controller.getListener() != null){ + controller.reopenCase(OpenMode.CURRENT_SETTINGS); + if (controller.getListener() != null) { controller.getListener().afterBlockMesh(); } } diff --git a/src/eu/engys/gui/mesh/actions/RunBlockMeshAction.java b/src/eu/engys/gui/mesh/actions/RunBlockMeshAction.java index 414f1ef..3f6c615 100644 --- a/src/eu/engys/gui/mesh/actions/RunBlockMeshAction.java +++ b/src/eu/engys/gui/mesh/actions/RunBlockMeshAction.java @@ -1,38 +1,48 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.mesh.actions; +import static eu.engys.gui.mesh.actions.RunBlockMesh.ACTION_NAME; +import static eu.engys.gui.mesh.actions.RunBlockMesh.BLOCK_MESH_LOG; + import java.awt.event.ActionEvent; +import java.io.File; +import java.nio.file.Paths; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; import javax.swing.Icon; import eu.engys.core.OpenFOAMEnvironment; import eu.engys.core.controller.Controller; +import eu.engys.core.controller.ScriptFactory; +import eu.engys.core.controller.actions.CheckMesh; import eu.engys.core.controller.actions.RunCommand; +import eu.engys.core.executor.TerminalExecutorMonitor; import eu.engys.core.project.Model; +import eu.engys.core.project.openFOAMProject; import eu.engys.util.ui.ResourcesUtil; import eu.engys.util.ui.UiUtil; import eu.engys.util.ui.ViewAction; @@ -41,11 +51,13 @@ public class RunBlockMeshAction extends ViewAction { private Model model; private Controller controller; + private ScriptFactory scriptFactory; - public RunBlockMeshAction(Model model, Controller controller) { + public RunBlockMeshAction(Model model, Controller controller, ScriptFactory scriptFactory) { super(BLOCK_LABEL, BLOCK_ICON, BLOCK_TOOLTIP); this.model = model; this.controller = controller; + this.scriptFactory = scriptFactory; } @Override @@ -64,10 +76,26 @@ public class RunBlockMeshAction extends ViewAction { } private void blockMesh() { - RunCommand command = new RunBlockMesh(model, controller); - command.beforeExecute(); - command.executeClient(); + File logFile = Paths.get(model.getProject().getBaseDir().getAbsolutePath(), openFOAMProject.LOG, BLOCK_MESH_LOG).toFile(); + + TerminalExecutorMonitor terminal = new TerminalExecutorMonitor(controller.getTerminalManager(), logFile); + ExecutorService service = Executors.newSingleThreadExecutor(); + + RunCommand blockMeshCommand = new RunBlockMesh(model, controller, BLOCK_MESH_LOG, ACTION_NAME); + blockMeshCommand.inService(service); + blockMeshCommand.inTerminal(terminal); + + RunCommand checkCommand = new CheckMesh(model, controller, scriptFactory, BLOCK_MESH_LOG, ACTION_NAME); + checkCommand.inService(service); + checkCommand.inTerminal(terminal); + + blockMeshCommand.beforeExecute(); + checkCommand.beforeExecute(); + + blockMeshCommand.executeClient(); + checkCommand.executeClient(); } + private void fixDecomposeParDict() { model.getProject().getSystemFolder().getDecomposeParDict().toHierarchical(model); diff --git a/src/eu/engys/gui/mesh/actions/STLAccessory.java b/src/eu/engys/gui/mesh/actions/STLAccessory.java index 72d1b06..5cd13e6 100644 --- a/src/eu/engys/gui/mesh/actions/STLAccessory.java +++ b/src/eu/engys/gui/mesh/actions/STLAccessory.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.mesh.actions; import java.awt.BorderLayout; @@ -236,7 +235,7 @@ public class STLAccessory implements Accessory { double[] scale = new double[] { ((Double) table.getValueAt(row, 7)), ((Double) table.getValueAt(row, 8)), ((Double) table.getValueAt(row, 9)) }; AffineTransform t = new AffineTransform(); - t.setTranslate(translate); + t.setTranslation(translate); t.setRotation(rotation); t.setScale(scale); diff --git a/src/eu/engys/gui/mesh/actions/STLFileChooserWrapper.java b/src/eu/engys/gui/mesh/actions/STLFileChooserWrapper.java index 97fe4b5..270207f 100644 --- a/src/eu/engys/gui/mesh/actions/STLFileChooserWrapper.java +++ b/src/eu/engys/gui/mesh/actions/STLFileChooserWrapper.java @@ -1,31 +1,31 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.mesh.actions; +import static eu.engys.util.ui.FileChooserUtils.STL_FILTER; + import java.awt.HeadlessException; import java.io.File; @@ -39,41 +39,46 @@ import eu.engys.util.ui.UiUtil; public class STLFileChooserWrapper { - private STLAccessory stlAccessory; - private HelyxFileChooser chooser; - public static final HelyxFileFilter STL_FILTER = new HelyxFileFilter("STL File (*.stl)", "stl"); - public static final HelyxFileFilter ARCHIVE_FILTER = new HelyxFileFilter("Archive File (*.zip, *.gz, *.tar.gz, *tar.bz2)", "zip", "gz", "bz2"); + private STLAccessory stlAccessory; + private HelyxFileChooser chooser; + public static final HelyxFileFilter ARCHIVE_FILTER = new HelyxFileFilter("Archive File (*.zip, *.gz, *.tar.gz, *tar.bz2)", "zip", "gz", "bz2"); - public STLFileChooserWrapper() { - chooser = new HelyxFileChooser(PrefUtil.getWorkDir(PrefUtil.LAST_IMPORT_DIR).getAbsolutePath()); - chooser.setTitle("Open STL"); - chooser.setSelectionMode(SelectionMode.FILES_ONLY); - chooser.setMultiSelectionEnabled(true); - stlAccessory = new STLAccessory(chooser); - } + public STLFileChooserWrapper(boolean multiSelectionEnabled) { + chooser = new HelyxFileChooser(PrefUtil.getWorkDir(PrefUtil.LAST_IMPORT_DIR).getAbsolutePath()); + chooser.setTitle("Open STL"); + chooser.setSelectionMode(SelectionMode.FILES_ONLY); + chooser.setMultiSelectionEnabled(multiSelectionEnabled); + stlAccessory = new STLAccessory(chooser); + } - public ReturnValue showOpenDialog() throws HeadlessException { - ReturnValue returnedValue = chooser.showOpenDialog(stlAccessory, UiUtil.getPreferredScreenSize(), STL_FILTER, ARCHIVE_FILTER); - if (returnedValue.isApprove()) { - final File[] files = getSelectedFiles(); - if (files != null && files.length > 0) { - PrefUtil.putFile(PrefUtil.LAST_IMPORT_DIR, files[0].getParentFile()); - } - } - return returnedValue; - } + public ReturnValue showOpenDialog() throws HeadlessException { + ReturnValue returnedValue = chooser.showOpenDialog(stlAccessory, UiUtil.getPreferredScreenSize(), STL_FILTER, ARCHIVE_FILTER); + if (returnedValue.isApprove()) { + final File[] files = getSelectedFiles(); + if (files != null && files.length > 0) { + PrefUtil.putFile(PrefUtil.LAST_IMPORT_DIR, files[0].getParentFile()); + } + } + return returnedValue; + } - public File[] getSelectedFiles() { - if (chooser == null) - return new File[0]; - return chooser.getSelectedFiles(); - } + public File[] getSelectedFiles() { + if (chooser == null) + return new File[0]; + return chooser.getSelectedFiles(); + } - public AffineTransform[] getSelectedTransform() { - return stlAccessory.getTransformations(); - } + public File getSelectedFile() { + if (chooser == null) + return null; + return chooser.getSelectedFile(); + } - public STLAccessory getStlAccessory() { - return stlAccessory; - } + public AffineTransform[] getSelectedTransform() { + return stlAccessory.getTransformations(); + } + + public STLAccessory getStlAccessory() { + return stlAccessory; + } } diff --git a/src/eu/engys/gui/mesh/actions/StandardMeshActions.java b/src/eu/engys/gui/mesh/actions/StandardMeshActions.java index 07d62a6..7295f02 100644 --- a/src/eu/engys/gui/mesh/actions/StandardMeshActions.java +++ b/src/eu/engys/gui/mesh/actions/StandardMeshActions.java @@ -1,29 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.mesh.actions; import static eu.engys.util.ui.UiUtil.createToolBarButton; @@ -41,23 +39,23 @@ import eu.engys.util.ui.UiUtil; public class StandardMeshActions extends DefaultMeshActions { - @Inject - public StandardMeshActions(Model model, Controller controller, ProgressMonitor monitor, DefaultMeshAdvancedOptionsPanel generalOptionsPanel) { - super(model, controller, monitor, generalOptionsPanel); - } + @Inject + public StandardMeshActions(Model model, Controller controller, ProgressMonitor monitor, DefaultMeshAdvancedOptionsPanel generalOptionsPanel) { + super(model, controller, monitor, generalOptionsPanel); + } - @Override - public JToolBar toolbar() { - JToolBar toolbar = UiUtil.getToolbar("view.element.toolbar"); + @Override + public JToolBar toolbar() { + JToolBar toolbar = UiUtil.getToolbarWrapped(TOOLBAR_NAME); - toolbar.add(createToolBarButton(createMesh)); - toolbar.add(Box.createHorizontalStrut(2)); - toolbar.add(createToolBarButton(checkMesh)); - toolbar.add(createToolBarButton(deleteMesh)); - toolbar.addSeparator(); - toolbar.add(createToolBarButton(openOptionsDialog)); - toolbar.add(Box.createHorizontalGlue()); - - return toolbar; - } + toolbar.add(createToolBarButton(createMesh)); + toolbar.add(Box.createHorizontalStrut(2)); + toolbar.add(createToolBarButtonBar(checkMesh)); + toolbar.add(createToolBarButtonBar(deleteMesh)); + toolbar.addSeparator(); + toolbar.add(createToolBarButton(advancedMeshOptions)); + // toolbar.add(Box.createHorizontalGlue()); + + return toolbar; + } } diff --git a/src/eu/engys/gui/mesh/actions/geometry/CloneSurfaceAction.java b/src/eu/engys/gui/mesh/actions/geometry/CloneSurfaceAction.java index 9358e1c..0dbb3af 100644 --- a/src/eu/engys/gui/mesh/actions/geometry/CloneSurfaceAction.java +++ b/src/eu/engys/gui/mesh/actions/geometry/CloneSurfaceAction.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.mesh.actions.geometry; import java.awt.event.ActionEvent; @@ -80,8 +79,9 @@ public class CloneSurfaceAction extends AbstractAction { Surface original = surfaces[0]; Dictionary dictionary = original.toDictionary(); if (dictionary.isDictionary("surface") && dictionary.isDictionary("volume")) { - Surface surface = model.getGeometry().getFactory().loadSurface(new Dictionary("CopyOf" + dictionary.getName(), original.getGeometryDictionary()), model, null); - surface.fromDictionary(dictionary); + Surface surface = original.cloneSurface(); + surface.rename("CopyOf" + original.getName()); + model.getGeometry().addSurface(surface); model.geometryChanged(surface); diff --git a/src/eu/engys/gui/mesh/actions/geometry/CopySurfaceAction.java b/src/eu/engys/gui/mesh/actions/geometry/CopySurfaceAction.java index 664106e..97c034b 100644 --- a/src/eu/engys/gui/mesh/actions/geometry/CopySurfaceAction.java +++ b/src/eu/engys/gui/mesh/actions/geometry/CopySurfaceAction.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.mesh.actions.geometry; import java.awt.Toolkit; diff --git a/src/eu/engys/gui/mesh/actions/geometry/ExtractLineAction.java b/src/eu/engys/gui/mesh/actions/geometry/ExtractLineAction.java index d6dde76..44df777 100644 --- a/src/eu/engys/gui/mesh/actions/geometry/ExtractLineAction.java +++ b/src/eu/engys/gui/mesh/actions/geometry/ExtractLineAction.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.mesh.actions.geometry; import java.awt.event.ActionEvent; @@ -69,4 +68,4 @@ public class ExtractLineAction extends AbstractAction { this.surfaces = surfaces; setEnabled(enabled && surfaces.length == 1); } -} +} \ No newline at end of file diff --git a/src/eu/engys/gui/mesh/actions/geometry/ExtractLinesDialog.java b/src/eu/engys/gui/mesh/actions/geometry/ExtractLinesDialog.java index 3804908..8b432e0 100644 --- a/src/eu/engys/gui/mesh/actions/geometry/ExtractLinesDialog.java +++ b/src/eu/engys/gui/mesh/actions/geometry/ExtractLinesDialog.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.mesh.actions.geometry; import java.awt.BorderLayout; @@ -46,8 +45,6 @@ import javax.swing.JSeparator; import javax.swing.JToggleButton; import javax.swing.SwingConstants; -import vtk.vtkAppendPolyData; -import vtk.vtkPolyData; import eu.engys.core.dictionary.model.EventActionType; import eu.engys.core.project.Model; import eu.engys.core.project.geometry.FeatureLine; @@ -66,11 +63,13 @@ import eu.engys.util.ui.builder.PanelBuilder; import eu.engys.util.ui.textfields.DoubleField; import eu.engys.util.ui.textfields.StringField; import eu.engys.vtk.actions.ExtractLines; +import vtk.vtkAppendPolyData; +import vtk.vtkPolyData; public class ExtractLinesDialog { - private static final Icon ICON_ON = ResourcesUtil.getResourceIcon("eu/engys/resources/images/lightbulb16.png"); - private static final Icon ICON_OFF = ResourcesUtil.getResourceIcon("eu/engys/resources/images/lightbulb_off16.png"); + private static final Icon ICON_ON = ResourcesUtil.getIcon("light.on.icon"); + private static final Icon ICON_OFF = ResourcesUtil.getIcon("light.off.icon"); public static final String EXTRACT_LINES_DIALOG = "extract.lines.dialog"; @@ -217,6 +216,25 @@ public class ExtractLinesDialog { if (this.onShow != null) { this.onShow.run(); } + vtkPolyData dataset = getDatasetFrom(surface); + double[] bounds = dataset.GetBounds(); + + insideBoxMin[0].setDoubleValue(bounds[0]); + insideBoxMin[1].setDoubleValue(bounds[2]); + insideBoxMin[2].setDoubleValue(bounds[4]); + + insideBoxMax[0].setDoubleValue(bounds[1]); + insideBoxMax[1].setDoubleValue(bounds[3]); + insideBoxMax[2].setDoubleValue(bounds[5]); + + outsideBoxMin[0].setDoubleValue(bounds[0]); + outsideBoxMin[1].setDoubleValue(bounds[2]); + outsideBoxMin[2].setDoubleValue(bounds[4]); + + outsideBoxMax[0].setDoubleValue(bounds[1]); + outsideBoxMax[1].setDoubleValue(bounds[3]); + outsideBoxMax[2].setDoubleValue(bounds[5]); + ExecUtil.invokeLater(new Runnable() { @Override public void run() { diff --git a/src/eu/engys/gui/mesh/actions/geometry/PasteSurfaceAction.java b/src/eu/engys/gui/mesh/actions/geometry/PasteSurfaceAction.java index 660d3a5..1da0fb1 100644 --- a/src/eu/engys/gui/mesh/actions/geometry/PasteSurfaceAction.java +++ b/src/eu/engys/gui/mesh/actions/geometry/PasteSurfaceAction.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.mesh.actions.geometry; import java.awt.Toolkit; diff --git a/src/eu/engys/gui/mesh/actions/geometry/RemoveSurfaceAction.java b/src/eu/engys/gui/mesh/actions/geometry/RemoveSurfaceAction.java index a1ac14d..98e3ca9 100644 --- a/src/eu/engys/gui/mesh/actions/geometry/RemoveSurfaceAction.java +++ b/src/eu/engys/gui/mesh/actions/geometry/RemoveSurfaceAction.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.mesh.actions.geometry; import java.awt.event.ActionEvent; diff --git a/src/eu/engys/gui/mesh/actions/geometry/RenameSurfaceAction.java b/src/eu/engys/gui/mesh/actions/geometry/RenameSurfaceAction.java new file mode 100644 index 0000000..3138f83 --- /dev/null +++ b/src/eu/engys/gui/mesh/actions/geometry/RenameSurfaceAction.java @@ -0,0 +1,54 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.gui.mesh.actions.geometry; + +import javax.swing.JOptionPane; + +import eu.engys.core.project.Model; +import eu.engys.core.project.geometry.Surface; +import eu.engys.gui.events.EventManager; +import eu.engys.gui.events.view3D.RenameSurfaceEvent; +import eu.engys.util.ui.UiUtil; + +public class RenameSurfaceAction { + + private Model model; + + public RenameSurfaceAction(Model model) { + this.model = model; + } + + public void execute(Surface surface, String newName) { + if (model.getGeometry().contains(newName)) { + JOptionPane.showMessageDialog(UiUtil.getActiveWindow(), "Name already in use", "Name Error", JOptionPane.ERROR_MESSAGE); + return; + } + + String oldPatchName = surface.getPatchName(); + surface.rename(newName); + + EventManager.triggerEvent(this, new RenameSurfaceEvent(surface, oldPatchName, surface.getPatchName())); + } +} diff --git a/src/eu/engys/gui/mesh/panels/AbstractBaseMeshPanel.java b/src/eu/engys/gui/mesh/panels/AbstractBaseMeshPanel.java index 39e426e..ed4d0ae 100644 --- a/src/eu/engys/gui/mesh/panels/AbstractBaseMeshPanel.java +++ b/src/eu/engys/gui/mesh/panels/AbstractBaseMeshPanel.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.mesh.panels; import static eu.engys.gui.mesh.panels.lines.AutomaticBaseMeshPanel.AUTOMATIC_LABEL; @@ -39,8 +38,11 @@ import java.util.List; import javax.swing.JComponent; import javax.swing.JOptionPane; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import eu.engys.core.controller.Controller; -import eu.engys.core.dictionary.model.DictionaryPanelBuilder; +import eu.engys.core.controller.ScriptFactory; import eu.engys.core.project.Model; import eu.engys.core.project.geometry.Type; import eu.engys.core.project.geometry.surface.PlaneRegion; @@ -55,14 +57,16 @@ import eu.engys.gui.mesh.panels.lines.BoundingBoxFacesPanel; import eu.engys.gui.mesh.panels.lines.FromFileBaseMeshPanel; import eu.engys.gui.mesh.panels.lines.UserDefinedBaseMeshPanel; import eu.engys.gui.tree.TreeNodeManager; +import eu.engys.util.bean.BeanPanelBuilder; import eu.engys.util.ui.UiUtil; import eu.engys.util.ui.builder.JComboBoxController; import eu.engys.util.ui.textfields.StringField; public abstract class AbstractBaseMeshPanel extends AbstractGUIPanel { - public static final String BASE_MESH = "Base Mesh"; + private static final Logger logger = LoggerFactory.getLogger(AbstractBaseMeshPanel.class); + public static final String BASE_MESH = "Base Mesh"; public static final String BASE_MESH_TYPE_LABEL = "Base Mesh Type"; private BaseMeshTreeNodeManager treeNodeManager; @@ -73,26 +77,28 @@ public abstract class AbstractBaseMeshPanel extends AbstractGUIPanel { private PlaneRegion[] selectedPlane; private Controller controller; + private ScriptFactory scriptFactory; private AutomaticBaseMeshPanel automaticPanel; private UserDefinedBaseMeshPanel userDefinedPanel; private FromFileBaseMeshPanel fromFilePanel; private BoundingBoxFacesPanel facesPanel; - public AbstractBaseMeshPanel(Model model, Controller controller) { + + public AbstractBaseMeshPanel(Model model, Controller controller, ScriptFactory scriptFactory) { super(BASE_MESH, model); this.controller = controller; + this.scriptFactory = scriptFactory; this.treeNodeManager = new BaseMeshTreeNodeManager(model, this); model.addObserver(treeNodeManager); } protected JComponent layoutComponents() { - DictionaryPanelBuilder builder = new DictionaryPanelBuilder(); - + BeanPanelBuilder builder = new BeanPanelBuilder(); type = (JComboBoxController) builder.startChoice(BASE_MESH_TYPE_LABEL); automaticPanel = new AutomaticBaseMeshPanel(model, builder); userDefinedPanel = new UserDefinedBaseMeshPanel(model, builder); - fromFilePanel = new FromFileBaseMeshPanel(model, controller, builder); + fromFilePanel = new FromFileBaseMeshPanel(model, controller, scriptFactory, builder); builder.endChoice(); facesPanel = new BoundingBoxFacesPanel(new RenamePlaneListener()); @@ -143,9 +149,16 @@ public abstract class AbstractBaseMeshPanel extends AbstractGUIPanel { } else if (isFromFile()) { fromFilePanel.save(); } else if (isAutomatic()) { - automaticPanel.save(); + automaticPanel.save(getBaseMeshSpacing(), shouldConsiderSpacing()); } } + + protected abstract boolean shouldConsiderSpacing(); + + @Override + public void geometryChanged() { + userDefinedPanel.geometryChanged(); + } private void saveSelectedPlane() { if (selectedPlane != null) { @@ -243,11 +256,12 @@ public abstract class AbstractBaseMeshPanel extends AbstractGUIPanel { // To tell the Controller to delete mesh scripts EventManager.triggerEvent(this, new BaseMeshTypeChangedEvent()); updateBlock(); - save(); +// save(); } } private class RenamePlaneListener implements PropertyChangeListener { + @Override public void propertyChange(PropertyChangeEvent evt) { if (evt.getPropertyName().equals("value") && evt.getSource() instanceof StringField) { @@ -262,6 +276,7 @@ public abstract class AbstractBaseMeshPanel extends AbstractGUIPanel { String newName = facesPanel.getPlaneName(); if (model.getGeometry().contains(newName)) { + logger.error("Cannot use name \"{}\", it is already used: {}", newName, model.getGeometry().getAllSurfacesNames()); JOptionPane.showMessageDialog(UiUtil.getActiveWindow(), "Name already in use", "Name Error", JOptionPane.ERROR_MESSAGE); return; } diff --git a/src/eu/engys/gui/mesh/panels/AbstractBoundaryMeshPanel.java b/src/eu/engys/gui/mesh/panels/AbstractBoundaryMeshPanel.java new file mode 100644 index 0000000..dbb93f6 --- /dev/null +++ b/src/eu/engys/gui/mesh/panels/AbstractBoundaryMeshPanel.java @@ -0,0 +1,152 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.gui.mesh.panels; + +import static eu.engys.core.controller.AbstractController.MESH_CHECK; +import static eu.engys.core.controller.AbstractController.MESH_CHECK_EDIT; +import static eu.engys.core.controller.AbstractController.MESH_CREATE; +import static eu.engys.core.controller.AbstractController.MESH_CREATE_EDIT; +import static eu.engys.core.controller.AbstractController.MESH_DELETE; +import static eu.engys.util.ui.ComponentsFactory.labelField; + +import java.awt.Dimension; +import java.nio.file.Files; +import java.nio.file.Path; +import java.text.DateFormat; +import java.util.Date; + +import javax.swing.Action; +import javax.swing.JButton; +import javax.swing.JComponent; +import javax.swing.JLabel; + +import eu.engys.core.presentation.ActionManager; +import eu.engys.core.project.Model; +import eu.engys.gui.AbstractGUIPanel; +import eu.engys.gui.tree.TreeNodeManager; +import eu.engys.util.ui.builder.PanelBuilder; +import net.java.dev.designgridlayout.Componentizer; + +public abstract class AbstractBoundaryMeshPanel extends AbstractGUIPanel { + + public static final String TITLE = "Mesh"; + + private BoundaryMeshTreeNodeManager treeNodeManager; + + private JLabel name; + private JLabel path; + private JLabel created; + + protected PanelBuilder builder; + private MeshInfoPanel meshInfoPanel; + + public AbstractBoundaryMeshPanel(Model model) { + super(TITLE, model); + this.treeNodeManager = new BoundaryMeshTreeNodeManager(model, this); + model.addObserver(treeNodeManager); + } + + protected JComponent layoutComponents() { + Action createMesh = ActionManager.getInstance().get(MESH_CREATE); + Action editCreateMesh = ActionManager.getInstance().get(MESH_CREATE_EDIT); + Action checkMesh = ActionManager.getInstance().get(MESH_CHECK); + Action editCheckMesh = ActionManager.getInstance().get(MESH_CHECK_EDIT); + Action deleteMesh = ActionManager.getInstance().get(MESH_DELETE); + + JButton runMeshButton = new JButton(createMesh); + JButton editMeshScriptButton = new JButton(editCreateMesh); + JButton checkMeshButton = new JButton(checkMesh); + JButton editCheckMeshButton = new JButton(editCheckMesh); + JButton deleteMeshButton = new JButton(deleteMesh); + + runMeshButton.setPreferredSize(new Dimension(120, runMeshButton.getPreferredSize().height)); + checkMeshButton.setPreferredSize(new Dimension(120, checkMeshButton.getPreferredSize().height)); + deleteMeshButton.setPreferredSize(new Dimension(120, checkMeshButton.getPreferredSize().height)); + + JComponent c1 = Componentizer.create().minToPref(runMeshButton).fixedPref(editMeshScriptButton).minAndMore(new JLabel()).component(); + JComponent c2 = Componentizer.create().minToPref(checkMeshButton).fixedPref(editCheckMeshButton).minAndMore(new JLabel()).component(); + JComponent c3 = Componentizer.create().minToPref(deleteMeshButton).fixedPref(new JLabel()).minAndMore(new JLabel()).component(); + + PanelBuilder actions = new PanelBuilder(); + actions.addComponent(c1); + actions.addComponent(c2); + actions.addComponent(c3); + + name = labelField(""); + path = labelField(""); + created = labelField(""); + + PanelBuilder properties = new PanelBuilder(); + properties.addComponent("Name", name); + properties.addComponent("Path", path); + properties.addComponent("Created", created); + + meshInfoPanel = new MeshInfoPanel(); + + builder = new PanelBuilder(); + builder.addComponent(actions.withTitle("Actions").getPanel()); + builder.addComponent(properties.withTitle("Properties").getPanel()); + addExtraComponents(builder); + builder.addComponent(meshInfoPanel.getStatistics(), meshInfoPanel.getCellType()); + builder.addComponent(meshInfoPanel.getDataArrays()); + builder.addComponent(meshInfoPanel.getBounds()); + + return builder.removeMargins().getPanel(); + } + + protected void addExtraComponents(PanelBuilder builder) { + } + + @Override + public void start() { + load(); + } + + @Override + public void load() { + name.setText(model.getProject().getBaseDir().getName()); + path.setText(model.getProject().getBaseDir().getParent()); + + try { + Path basePath = model.getProject().getBaseDir().toPath(); + long lastModify = Files.getLastModifiedTime(basePath).toMillis(); + created.setText(DateFormat.getDateInstance().format(new Date(lastModify))); + } catch (Exception e) { + created.setText("-"); + } + + meshInfoPanel.load(model.getMesh()); + } + + @Override + public void save() { + } + + @Override + public TreeNodeManager getTreeNodeManager() { + return treeNodeManager; + } + +} diff --git a/src/eu/engys/gui/mesh/panels/AbstractGeometryPanel.java b/src/eu/engys/gui/mesh/panels/AbstractGeometryPanel.java index 1c0f1a1..aa538b4 100644 --- a/src/eu/engys/gui/mesh/panels/AbstractGeometryPanel.java +++ b/src/eu/engys/gui/mesh/panels/AbstractGeometryPanel.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.mesh.panels; import java.awt.BorderLayout; @@ -56,10 +55,10 @@ import eu.engys.gui.events.view3D.AddSurfaceEvent; import eu.engys.gui.events.view3D.ChangeSurfaceEvent; import eu.engys.gui.events.view3D.RenameSurfaceEvent; import eu.engys.gui.mesh.GeometryPanel; -import eu.engys.gui.mesh.actions.AddIGES; import eu.engys.gui.mesh.actions.AddSTL; import eu.engys.gui.tree.TreeNodeManager; import eu.engys.util.Util; +import eu.engys.util.progress.ProgressMonitor; import eu.engys.util.ui.UiUtil; import eu.engys.util.ui.builder.JComboBoxController; import eu.engys.util.ui.builder.PanelBuilder; @@ -103,14 +102,12 @@ public abstract class AbstractGeometryPanel extends AbstractGUIPanel implements public static final String OUTSIDE_LABEL = "Outside"; public static final String DISTANCE_LABEL = "Distance"; - private GeometryBuilder surfaceRegionsBuilder; - protected DictionaryModel surfaceModel; protected DictionaryModel volumeModel; protected DictionaryModel layerModel; protected DictionaryModel zoneModel; - private GeometriesPanelBuilder geometriesPanel; + private ShapesPanel shapesPanel; protected PanelBuilder layersBuilder; protected PanelBuilder surfaceBuilder; @@ -120,9 +117,13 @@ public abstract class AbstractGeometryPanel extends AbstractGUIPanel implements private JTabbedPane tabbedPane; protected final GeometryTreeNodeManager treeNodeManager; + private Controller controller; + private ProgressMonitor monitor; - public AbstractGeometryPanel(Model model, Controller controller) { + public AbstractGeometryPanel(Model model, Controller controller, ProgressMonitor monitor) { super(GEOMETRY, model); + this.controller = controller; + this.monitor = monitor; this.treeNodeManager = new GeometryTreeNodeManager(model, controller, this, getGeometryActions(controller)); model.addObserver(treeNodeManager); ActionManager.getInstance().parseActions(this); @@ -130,6 +131,8 @@ public abstract class AbstractGeometryPanel extends AbstractGUIPanel implements protected abstract DefaultGeometryActions getGeometryActions(Controller controller); + public abstract JButton[] getShapeButtons(); + @Override protected JComponent layoutComponents() { surfaceModel = new DictionaryModel(); @@ -137,8 +140,7 @@ public abstract class AbstractGeometryPanel extends AbstractGUIPanel implements layerModel = new DictionaryModel(); zoneModel = new DictionaryModel(); - geometriesPanel = new GeometriesPanelBuilder(this); - surfaceRegionsBuilder = new GeometryBuilder(geometriesPanel, surfaceModel, volumeModel, layerModel, zoneModel); + shapesPanel = new ShapesPanel(this); tabbedPane = new JTabbedPane(); tabbedPane.setName("geometry.tabbed.pane"); @@ -156,13 +158,8 @@ public abstract class AbstractGeometryPanel extends AbstractGUIPanel implements tabbedPane.addTab(LAYERS_LABEL, layersPanel); tabbedPane.addTab(ZONES_LABEL, zonesPanel); - PanelBuilder builder = new PanelBuilder(); - builder.addButtons(getShapeButtons()); - builder.addSeparator(""); - geometriesPanel.addComponents(builder); - JPanel mainPanel = new JPanel(new BorderLayout()); - mainPanel.add(builder.removeMargins().getPanel(), BorderLayout.NORTH); + mainPanel.add(shapesPanel, BorderLayout.NORTH); mainPanel.add(tabbedPane, BorderLayout.CENTER); tabbedPane.addChangeListener(new ChangeListener() { @@ -176,8 +173,6 @@ public abstract class AbstractGeometryPanel extends AbstractGUIPanel implements return mainPanel; } - protected abstract JButton[] getShapeButtons(); - private JPanel getRefinemetPanel() { PanelBuilder builder = new PanelBuilder(); @@ -261,17 +256,29 @@ public abstract class AbstractGeometryPanel extends AbstractGUIPanel implements @Override public void stop() { super.stop(); - geometriesPanel.stop(); + shapesPanel.stop(); } - public void saveSurfaces(Surface[] surfaces) { - surfaceRegionsBuilder.buildSurfaces(surfaces); + public void saveSurfaces(Surface... surfaces) { + Surface delegate = shapesPanel.getSelectedSurface(); + if (delegate != null) { + delegate.setSurfaceDictionary(surfaceModel.getDictionary()); + delegate.setVolumeDictionary(volumeModel.getDictionary()); + delegate.setLayerDictionary(layerModel.getDictionary()); + delegate.setZoneDictionary(zoneModel.getDictionary()); + + new SurfacesSaver().saveSurfaces(delegate, surfaces); + } } @Override - public void changeSurface(Surface surface) { - surfaceRegionsBuilder.buildSurfaces(surface); - EventManager.triggerEvent(this, new ChangeSurfaceEvent(surface, false)); + public void changeSurface() { + Surface[] selection = treeNodeManager.getSelectedValues(); + if (selection.length == 1) { + Surface surface = selection[0]; + saveSurfaces(surface); + EventManager.triggerEvent(this, new ChangeSurfaceEvent(surface, false)); + } } @Override @@ -288,7 +295,7 @@ public abstract class AbstractGeometryPanel extends AbstractGUIPanel implements String oldPatchName = surface.getPatchName(); surface.rename(newName); - surfaceRegionsBuilder.buildSurfaces(surface); + saveSurfaces(surface); treeNodeManager.refreshNode(surface); @@ -311,19 +318,12 @@ public abstract class AbstractGeometryPanel extends AbstractGUIPanel implements }.execute(); } - @Action(key = "mesh.igs") - public void addIGES() { - new AddIGES(model, monitor) { - @Override - public void postLoad(List stls) { - addSTL(stls.toArray(new Stl[0])); - } - }.execute(); - } - public void addSTL(Stl... stls) { if (Util.isVarArgsNotNull(stls)) { for (Stl stl : stls) { + String name = Util.replaceForbiddenCharacters(stl.getName()); + String newName = getModel().getGeometry().getAName(name); + stl.rename(newName); getModel().getGeometry().addSurface(stl); getModel().geometryChanged(stl); } @@ -401,7 +401,7 @@ public abstract class AbstractGeometryPanel extends AbstractGUIPanel implements public void selectSurface(Surface[] surfaces) { if (Util.isVarArgsNotNull(surfaces)) { - geometriesPanel.showPanel(surfaces); + shapesPanel.showPanel(surfaces); updateGUIOnSelection(surfaces[0]); @@ -424,7 +424,7 @@ public abstract class AbstractGeometryPanel extends AbstractGUIPanel implements } public void deselectAll() { - geometriesPanel.showPanel(null); + shapesPanel.showPanel(null); surfaceModel.setDictionary(new Dictionary("")); volumeModel.setDictionary(new Dictionary("")); diff --git a/src/eu/engys/gui/mesh/panels/BaseMeshTreeNodeManager.java b/src/eu/engys/gui/mesh/panels/BaseMeshTreeNodeManager.java index 2dfdddb..ee3a3ea 100644 --- a/src/eu/engys/gui/mesh/panels/BaseMeshTreeNodeManager.java +++ b/src/eu/engys/gui/mesh/panels/BaseMeshTreeNodeManager.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.mesh.panels; import java.awt.Component; diff --git a/src/eu/engys/gui/mesh/panels/BoundaryMeshTreeNodeManager.java b/src/eu/engys/gui/mesh/panels/BoundaryMeshTreeNodeManager.java index 08dc7e7..ef292ba 100644 --- a/src/eu/engys/gui/mesh/panels/BoundaryMeshTreeNodeManager.java +++ b/src/eu/engys/gui/mesh/panels/BoundaryMeshTreeNodeManager.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.mesh.panels; import java.awt.Component; @@ -41,11 +40,14 @@ import org.slf4j.LoggerFactory; import eu.engys.core.project.Model; import eu.engys.core.project.zero.cellzones.CellZone; import eu.engys.core.project.zero.cellzones.CellZones; +import eu.engys.core.project.zero.facezones.FaceZone; +import eu.engys.core.project.zero.facezones.FaceZones; import eu.engys.core.project.zero.patches.Patch; import eu.engys.core.project.zero.patches.Patches; import eu.engys.gui.GUIPanel; import eu.engys.gui.events.EventManager; import eu.engys.gui.events.view3D.SelectCellZonesEvent; +import eu.engys.gui.events.view3D.SelectFaceZonesEvent; import eu.engys.gui.events.view3D.SelectPatchesEvent; import eu.engys.gui.tree.AbstractSelectionHandler; import eu.engys.gui.tree.DefaultTreeNodeManager; @@ -63,10 +65,12 @@ public class BoundaryMeshTreeNodeManager extends DefaultTreeNodeManager patchesMap; private Map cellZonesMap; + private Map faceZonesMap; private SelectionHandler selectionHandler; private DefaultMutableTreeNode patches; private DefaultMutableTreeNode cellZones; +// private DefaultMutableTreeNode faceZones; public BoundaryMeshTreeNodeManager(Model model, GUIPanel panel) { super(model, panel); @@ -74,17 +78,20 @@ public class BoundaryMeshTreeNodeManager extends DefaultTreeNodeManager(); this.cellZonesMap = new HashMap<>(); + this.faceZonesMap = new HashMap<>(); patches = new RootVisibleLoadableTreeNode("Patches"); cellZones = new RootVisibleLoadableTreeNode("Cell Zones"); +// faceZones = new RootVisibleLoadableTreeNode("Face Zones"); root.add(patches); root.add(cellZones); +// root.add(faceZones); } @Override public void update(Observable o, final Object arg) { - if (arg instanceof Patches || arg instanceof CellZones) { - logger.debug("Observerd a change: arg is " + arg.getClass()); + if (arg instanceof Patches || arg instanceof CellZones || arg instanceof FaceZones) { + logger.debug("[CHANGE OBSERVERD] arg: " + arg.getClass().getSimpleName()); ExecUtil.invokeLater(new Runnable() { @Override public void run() { @@ -107,6 +114,9 @@ public class BoundaryMeshTreeNodeManager extends DefaultTreeNodeManager cellsPerRefinementLevel = model.getMesh().getCellsPerRefinementLevel(); - String text = ""; - for (int i = 0; i < cellsPerRefinementLevel.size(); i++) { - if (i > 0) - text += "\n"; - text += i + "\t" + cellsPerRefinementLevel.get(i); - } - cellsPerLevel.setText(text); - - // memory.setText(formatter.format(model.getMesh().getMemorySize()/1024D)); - - double[] bounds = model.getMesh().getBounds(); - - xBounds.setText(getTextForBounds(bounds[0], bounds[1])); - yBounds.setText(getTextForBounds(bounds[2], bounds[3])); - zBounds.setText(getTextForBounds(bounds[4], bounds[5])); - } else { - cells.setText("-"); - points.setText("-"); - faces.setText("-"); - cellsPerLevel.setText(" - "); - // memory.setText("-"); - xBounds.setText("[- , -]"); - yBounds.setText("[- , -]"); - zBounds.setText("[- , -]"); - } - } - - private String getTextForBounds(double min, double max) { - if (areValid(min, max)) { - return "[" + formatter.format(min) + " , " + formatter.format(max) + "] (Delta " + formatter.format(max - min) + ")"; - } else { - return "[0 , 0]"; - } - } - - private boolean areValid(double min, double max) { - return min < Double.MAX_VALUE && max > -Double.MAX_VALUE; - } - - @Override - public void save() { - } - - @Override - public TreeNodeManager getTreeNodeManager() { - return treeNodeManager; - } - -} diff --git a/src/eu/engys/gui/mesh/panels/DefaultGeometryActions.java b/src/eu/engys/gui/mesh/panels/DefaultGeometryActions.java index f77ce4c..13fd5aa 100644 --- a/src/eu/engys/gui/mesh/panels/DefaultGeometryActions.java +++ b/src/eu/engys/gui/mesh/panels/DefaultGeometryActions.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.mesh.panels; import static eu.engys.gui.mesh.actions.geometry.ExtractLineAction.EXTRACT_NAME; @@ -160,4 +159,4 @@ public class DefaultGeometryActions implements PopUpBuilder { actions.setEnabled(false); } } -} +} \ No newline at end of file diff --git a/src/eu/engys/gui/mesh/panels/DefaultMeshAdvancedOptionsPanel.java b/src/eu/engys/gui/mesh/panels/DefaultMeshAdvancedOptionsPanel.java index 04e0837..9825983 100644 --- a/src/eu/engys/gui/mesh/panels/DefaultMeshAdvancedOptionsPanel.java +++ b/src/eu/engys/gui/mesh/panels/DefaultMeshAdvancedOptionsPanel.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.mesh.panels; import static eu.engys.core.project.system.SnappyHexMeshDict.ADD_LAYERS_CONTROLS_KEY; @@ -44,6 +43,7 @@ import static eu.engys.core.project.system.SnappyHexMeshDict.MIN_VOL_KEY; import static eu.engys.core.project.system.SnappyHexMeshDict.MIN_VOL_RATIO_KEY; import static eu.engys.core.project.system.SnappyHexMeshDict.N_SMOOTH_SCALE_KEY; import static eu.engys.core.project.system.SnappyHexMeshDict.SNAP_CONTROLS_KEY; +import static eu.engys.util.TooltipUtils.NEW_LINE; import javax.swing.JComponent; import javax.swing.JPanel; @@ -54,7 +54,6 @@ import eu.engys.core.dictionary.model.DictionaryModel; import eu.engys.core.project.Model; import eu.engys.core.project.system.SnappyHexMeshDict; import eu.engys.gui.DefaultGUIPanel; -import eu.engys.util.TooltipUtils; import eu.engys.util.ui.builder.PanelBuilder; public abstract class DefaultMeshAdvancedOptionsPanel extends DefaultGUIPanel { @@ -75,7 +74,7 @@ public abstract class DefaultMeshAdvancedOptionsPanel extends DefaultGUIPanel { public static final String LAYERS_ADDITION_LABEL = "Layers Addition"; public static final String LAYERS_ADDITION_TOOLTIP = "Perform generation of layers"; public static final String DEBUG_LABEL = "Debug"; - public static final String DEBUG_TOOLTIP = "Control of debug output:" + TooltipUtils.NEW_LINE + "0: Write only final mesh" + TooltipUtils.NEW_LINE + "1: Write intermediate meshes" + TooltipUtils.NEW_LINE + "2: Write cell level information"; + public static final String DEBUG_TOOLTIP = "Control of debug output:" + NEW_LINE + "0: Write only final mesh" + NEW_LINE + "1: Write intermediate meshes" + NEW_LINE + "2: Write cell level information"; public static final String MERGE_TOLERANCE_LABEL = "Merge Tolerance"; public static final String MERGE_TOLERANCE_TOOLTIP = "Merge tolerance specified as a function of the initial bounding box size"; @@ -203,21 +202,21 @@ public abstract class DefaultMeshAdvancedOptionsPanel extends DefaultGUIPanel { protected JPanel createQualityPanel() { qualityBuilder = new PanelBuilder("options.quality.panel"); - qualityBuilder.addComponent(MAX_NON_ORTHO_LABEL, meshQualityControlsModel.bindDoubleAngle_180(MAX_NON_ORTHO_KEY), MAX_NON_ORTHO_TOOLTIP); - qualityBuilder.addComponent(MAX_BOUNDARY_SKEWNESS_LABEL, meshQualityControlsModel.bindInteger(MAX_BOUNDARY_SKEWNESS_KEY), MAX_BOUNDARY_SKEWNESS_TOOLTIP); - qualityBuilder.addComponent(MAX_INTERNAL_SKEWNESS_LABEL, meshQualityControlsModel.bindInteger(MAX_INTERNAL_SKEWNESS_KEY), MAX_INTERNAL_SKEWNESS_TOOLTIP); - qualityBuilder.addComponent(MAX_CONCAVE_LABEL, meshQualityControlsModel.bindDoubleAngle_180(MAX_CONCAVE_KEY), MAX_CONCAVE_TOOLTIP); - qualityBuilder.addComponent(MIN_FLATNESS_LABEL, meshQualityControlsModel.bindDouble(MIN_FLATNESS_KEY), MIN_FLATNESS_TOOLTIP); - qualityBuilder.addComponent(MIN_VOL_LABEL, meshQualityControlsModel.bindDouble(MIN_VOL_KEY), MIN_VOL_TOOLTIP); - qualityBuilder.addComponent(MIN_TET_QUALITY_LABEL, meshQualityControlsModel.bindDouble(MIN_TET_QUALITY_KEY), MIN_TET_QUALITY_TOOLTIP); - qualityBuilder.addComponent(MIN_AREA_LABEL, meshQualityControlsModel.bindDouble(MIN_AREA_KEY), MIN_AREA_TOOLTIP); - qualityBuilder.addComponent(MIN_TWIST_LABEL, meshQualityControlsModel.bindDouble(MIN_TWIST_KEY), MIN_TWIST_TOOLTIP); - qualityBuilder.addComponent(MIN_DETERMINANT_LABEL, meshQualityControlsModel.bindDouble(MIN_DETERMINANT_KEY), MIN_DETERMINANT_TOOLTIP); - qualityBuilder.addComponent(MIN_FACE_WEIGHT_LABEL, meshQualityControlsModel.bindDouble(MIN_FACE_WEIGHT_KEY), MIN_FACE_WEIGHT_TOOLTIP); - qualityBuilder.addComponent(MIN_VOL_RATIO_LABEL, meshQualityControlsModel.bindDouble(MIN_VOL_RATIO_KEY), MIN_VOL_RATIO_TOOLTIP); - qualityBuilder.addComponent(MIN_TRIANGLE_TWIST_LABEL, meshQualityControlsModel.bindDouble(MIN_TRIANGLE_TWIST_KEY), MIN_TRIANGLE_TWIST_TOOLTIP); - qualityBuilder.addComponent(SMOOTH_SCALE_LABEL, meshQualityControlsModel.bindIntegerPositive(N_SMOOTH_SCALE_KEY), SMOOTH_SCALE_TOOLTIP); - qualityBuilder.addComponent(ERROR_REDUCTION_LABEL, meshQualityControlsModel.bindDouble(ERROR_REDUCTION_KEY), ERROR_REDUCTION_TOOLTIP); + qualityBuilder.addComponent(MAX_NON_ORTHO_LABEL, MAX_NON_ORTHO_TOOLTIP, meshQualityControlsModel.bindDoubleAngle_180(MAX_NON_ORTHO_KEY)); + qualityBuilder.addComponent(MAX_BOUNDARY_SKEWNESS_LABEL, MAX_BOUNDARY_SKEWNESS_TOOLTIP, meshQualityControlsModel.bindInteger(MAX_BOUNDARY_SKEWNESS_KEY)); + qualityBuilder.addComponent(MAX_INTERNAL_SKEWNESS_LABEL, MAX_INTERNAL_SKEWNESS_TOOLTIP, meshQualityControlsModel.bindInteger(MAX_INTERNAL_SKEWNESS_KEY)); + qualityBuilder.addComponent(MAX_CONCAVE_LABEL, MAX_CONCAVE_TOOLTIP, meshQualityControlsModel.bindDoubleAngle_180(MAX_CONCAVE_KEY)); + qualityBuilder.addComponent(MIN_FLATNESS_LABEL, MIN_FLATNESS_TOOLTIP, meshQualityControlsModel.bindDouble(MIN_FLATNESS_KEY)); + qualityBuilder.addComponent(MIN_VOL_LABEL, MIN_VOL_TOOLTIP, meshQualityControlsModel.bindDouble(MIN_VOL_KEY)); + qualityBuilder.addComponent(MIN_TET_QUALITY_LABEL, MIN_TET_QUALITY_TOOLTIP, meshQualityControlsModel.bindDouble(MIN_TET_QUALITY_KEY)); + qualityBuilder.addComponent(MIN_AREA_LABEL, MIN_AREA_TOOLTIP, meshQualityControlsModel.bindDouble(MIN_AREA_KEY)); + qualityBuilder.addComponent(MIN_TWIST_LABEL, MIN_TWIST_TOOLTIP, meshQualityControlsModel.bindDouble(MIN_TWIST_KEY)); + qualityBuilder.addComponent(MIN_DETERMINANT_LABEL, MIN_DETERMINANT_TOOLTIP, meshQualityControlsModel.bindDouble(MIN_DETERMINANT_KEY)); + qualityBuilder.addComponent(MIN_FACE_WEIGHT_LABEL, MIN_FACE_WEIGHT_TOOLTIP, meshQualityControlsModel.bindDouble(MIN_FACE_WEIGHT_KEY)); + qualityBuilder.addComponent(MIN_VOL_RATIO_LABEL, MIN_VOL_RATIO_TOOLTIP, meshQualityControlsModel.bindDouble(MIN_VOL_RATIO_KEY)); + qualityBuilder.addComponent(MIN_TRIANGLE_TWIST_LABEL, MIN_TRIANGLE_TWIST_TOOLTIP, meshQualityControlsModel.bindDouble(MIN_TRIANGLE_TWIST_KEY)); + qualityBuilder.addComponent(SMOOTH_SCALE_LABEL, SMOOTH_SCALE_TOOLTIP, meshQualityControlsModel.bindIntegerPositive(N_SMOOTH_SCALE_KEY)); + qualityBuilder.addComponent(ERROR_REDUCTION_LABEL, ERROR_REDUCTION_TOOLTIP, meshQualityControlsModel.bindDouble(ERROR_REDUCTION_KEY)); return qualityBuilder.getPanel(); } diff --git a/src/eu/engys/gui/mesh/panels/FeatureLinesPanel.java b/src/eu/engys/gui/mesh/panels/FeatureLinesPanel.java index 9fe4d6e..1162b6e 100644 --- a/src/eu/engys/gui/mesh/panels/FeatureLinesPanel.java +++ b/src/eu/engys/gui/mesh/panels/FeatureLinesPanel.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.mesh.panels; import java.beans.PropertyChangeListener; @@ -35,7 +34,7 @@ import javax.swing.JComponent; import javax.swing.JOptionPane; import javax.swing.JPanel; -import net.java.dev.designgridlayout.Componentizer; +import org.apache.commons.lang.StringUtils; import com.google.inject.Inject; @@ -53,6 +52,7 @@ import eu.engys.util.ui.ComponentsFactory; import eu.engys.util.ui.UiUtil; import eu.engys.util.ui.builder.PanelBuilder; import eu.engys.util.ui.textfields.StringField; +import net.java.dev.designgridlayout.Componentizer; public class FeatureLinesPanel extends AbstractGUIPanel { @@ -100,7 +100,7 @@ public class FeatureLinesPanel extends AbstractGUIPanel { } } }; - nameField = ComponentsFactory.stringField(); + nameField = ComponentsFactory.stringField(true, true); nameField.addPropertyChangeListener(renameAction); refineOnly = ComponentsFactory.checkField(); @@ -153,12 +153,13 @@ public class FeatureLinesPanel extends AbstractGUIPanel { public void selectLine(FeatureLine[] currentSelection) { if (Util.isVarArgsNotNull(currentSelection)) { - StringBuilder sb = new StringBuilder(); - for (FeatureLine line : currentSelection) { - sb.append(line.getName()); - sb.append(" "); + String[] names = new String[currentSelection.length]; + for (int i = 0; i < names.length; i++) { + names[i] = currentSelection[i].getName(); } - nameField.setText(sb.toString()); + nameField.removePropertyChangeListener(renameAction); + nameField.setText(StringUtils.join(names, " ")); + nameField.addPropertyChangeListener(renameAction); if (currentSelection.length == 1) { builder.setEnabled(true); this.selectedLine = currentSelection[0]; @@ -197,7 +198,6 @@ public class FeatureLinesPanel extends AbstractGUIPanel { } public void deselectAll() { - nameField.setText(""); builder.setEnabled(false); } diff --git a/src/eu/engys/gui/mesh/panels/FeatureLinesTreeNodeManager.java b/src/eu/engys/gui/mesh/panels/FeatureLinesTreeNodeManager.java index e8b8acd..ec30ac1 100644 --- a/src/eu/engys/gui/mesh/panels/FeatureLinesTreeNodeManager.java +++ b/src/eu/engys/gui/mesh/panels/FeatureLinesTreeNodeManager.java @@ -1,52 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - -/*--------------------------------*- Java -*---------------------------------*\ - |o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2013 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - |License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.mesh.panels; import java.awt.Component; @@ -106,7 +81,7 @@ public class FeatureLinesTreeNodeManager extends DefaultTreeNodeManager @Override public void update(Observable o, final Object arg) { if (arg instanceof FeatureLine) { - logger.debug("Observerd a change: arg is " + arg.getClass()); + logger.debug("[CHANGE OBSERVERD] arg: " + arg.getClass().getSimpleName()); ExecUtil.invokeAndWait(new Runnable() { @Override public void run() { @@ -115,7 +90,7 @@ public class FeatureLinesTreeNodeManager extends DefaultTreeNodeManager } }); } else if (arg instanceof Geometry) { - logger.debug("Observerd a change: arg is Geometry"); + logger.debug("[CHANGE OBSERVERD] arg: " + arg.getClass().getSimpleName()); ExecUtil.invokeAndWait(new Runnable() { @Override public void run() { @@ -127,7 +102,7 @@ public class FeatureLinesTreeNodeManager extends DefaultTreeNodeManager } }); } else if (arg instanceof Patches) { - logger.debug("Observerd a change: arg is Patches"); + logger.debug("[CHANGE OBSERVERD] arg: " + arg.getClass().getSimpleName()); ExecUtil.invokeAndWait(new Runnable() { @Override public void run() { diff --git a/src/eu/engys/gui/mesh/panels/GeometriesPanelBuilder.java b/src/eu/engys/gui/mesh/panels/GeometriesPanelBuilder.java deleted file mode 100644 index 27926c7..0000000 --- a/src/eu/engys/gui/mesh/panels/GeometriesPanelBuilder.java +++ /dev/null @@ -1,517 +0,0 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - -package eu.engys.gui.mesh.panels; - -import static eu.engys.util.ui.ComponentsFactory.stringField; - -import java.awt.event.ActionEvent; -import java.beans.PropertyChangeListener; - -import javax.swing.BorderFactory; -import javax.swing.JLabel; -import javax.swing.SwingUtilities; - -import net.java.dev.designgridlayout.RowGroup; -import eu.engys.core.dictionary.Dictionary; -import eu.engys.core.dictionary.FieldChangeListener; -import eu.engys.core.dictionary.model.DictionaryModel; -import eu.engys.core.project.geometry.Surface; -import eu.engys.core.project.geometry.Type; -import eu.engys.core.project.geometry.surface.PlaneRegion; -import eu.engys.gui.mesh.GeometryPanel; -import eu.engys.gui.view3D.BoxEventButton; -import eu.engys.util.ui.builder.PanelBuilder; -import eu.engys.util.ui.textfields.DoubleField; -import eu.engys.util.ui.textfields.StringField; - -public class GeometriesPanelBuilder { - - public static final String BOX_NAME_LABEL = "Box Name"; - public static final String SPHERE_NAME_LABEL = "Sphere Name"; - public static final String CYLINDER_NAME_LABEL = "Cylinder Name"; - public static final String PLANE_NAME_LABEL = "Plane Name"; - public static final String RING_NAME_LABEL = "Ring Name"; - public static final String SURFACE_NAME_LABEL = "Surface Name"; - - public static final String OUTER_RADIUS_LABEL = "Outer Radius"; - public static final String INNER_RADIUS_LABEL = "Inner Radius"; - public static final String PATCH_NAME_LABEL = "Patch Name"; - public static final String NORMAL_LABEL = "Normal"; - public static final String ORIGIN_LABEL = "Origin"; - public static final String POINT_1_LABEL = "Point 1"; - public static final String POINT_2_LABEL = "Point 2"; - public static final String MIN_LABEL = "Min"; - public static final String MAX_LABEL = "Max"; - public static final String RADIUS_LABEL = "Radius"; - public static final String CENTRE_LABEL = "Centre"; - public static final int DECIMAL_PLACES = 4; - - private StringField stlNameField; - private StringField boxNameField; - private StringField cylinderNameField; - private StringField sphereNameField; - private StringField ringNameField; - private StringField planeNameField; - private StringField regionNameField; - - private DictionaryModel boxModel; - private DictionaryModel cylinderModel; - private DictionaryModel sphereModel; - private DictionaryModel ringModel; - private DictionaryModel planeModel; - private DictionaryModel planePointAndNormalModel; - - private PanelBuilder boxBuilder; - private PanelBuilder cylinderBuilder; - private PanelBuilder sphereBuilder; - private PanelBuilder ringBuilder; - private PanelBuilder planeBuilder; - private PanelBuilder regionBuilder; - private DictionaryModel stlModel; - PanelBuilder stlBuilder; - - private RowGroup boxGroup; - private RowGroup sphereGroup; - private RowGroup ringGroup; - private RowGroup planeGroup; - private RowGroup cylinderGroup; - private RowGroup stlGroup; - private RowGroup regionGroup; - private RowGroup noneGroup; - - private GeometryPanel meshPanel; - - private RowGroup selected; - Surface selectedSurface; - private PropertyChangeListener renameAction; - - private BoxEventButton showBoxButton; - - public GeometriesPanelBuilder(GeometryPanel panel) { - super(); - this.meshPanel = panel; - } - - public void addComponents(PanelBuilder builder) { - FieldChangeListener listener = new FieldChangeListener() { - - boolean adjusting = false; - - @Override - public void actionPerformed(ActionEvent e) { - } - - @Override - public void setAdjusting(boolean b) { - this.adjusting = b; - } - - @Override - public boolean isAdjusting() { - return adjusting; - } - - @Override - public void fieldChanged() { - if (!isAdjusting() && selectedSurface != null) { - meshPanel.changeSurface(selectedSurface); - } - } - }; - - addSTLComponent(builder, listener); - addBoxComponent(builder, listener); - addCylinderComponent(builder, listener); - addPlaneComponent(builder, listener); - addSphereComponent(builder, listener); - addRingComponent(builder, listener); - addNoneComponent(builder, listener); - - renameAction = new PropertyChangeListener() { - @Override - public void propertyChange(java.beans.PropertyChangeEvent evt) { - if (evt.getPropertyName().equals("value") && evt.getSource() instanceof StringField) { - StringField field = (StringField) evt.getSource(); - meshPanel.renameSurface(field.getText()); - } - } - }; - addRenameAction(); - - selected = noneGroup; - } - - private void addSTLComponent(PanelBuilder builder, FieldChangeListener listener) { - stlModel = new DictionaryModel(new Dictionary("")); - - stlBuilder = new PanelBuilder(); - stlBuilder.addComponent(SURFACE_NAME_LABEL, stlNameField = stringField()); - stlBuilder.getPanel().setBorder(BorderFactory.createTitledBorder("")); - - stlGroup = new RowGroup(); - builder.addComponentToGroup(stlGroup, stlBuilder.getPanel()); - stlGroup.hide(); - } - - private void addBoxComponent(PanelBuilder builder, FieldChangeListener listener) { - boxModel = new DictionaryModel(new Dictionary("")); - - DoubleField[] boxMin = boxModel.bindPoint(Surface.MIN_KEY, DECIMAL_PLACES, listener); - DoubleField[] boxMax = boxModel.bindPoint(Surface.MAX_KEY, DECIMAL_PLACES, listener); - showBoxButton = new BoxEventButton(boxMin, boxMax); - - boxBuilder = new PanelBuilder(); - boxBuilder.addComponent(BOX_NAME_LABEL, boxNameField = stringField()); - // boxBuilder.addComponent("", labelField("X"), labelField("Y"), labelField("Z")); - boxBuilder.addComponent(MIN_LABEL, boxMin[0], boxMin[1], boxMin[2], showBoxButton); - boxBuilder.addComponentAndSpan(MAX_LABEL, boxMax); - boxBuilder.getPanel().setBorder(BorderFactory.createTitledBorder("")); - - boxGroup = new RowGroup(); - builder.addComponentToGroup(boxGroup, boxBuilder.getPanel()); - boxGroup.hide(); - } - - private void addCylinderComponent(PanelBuilder builder, FieldChangeListener listener) { - cylinderModel = new DictionaryModel(new Dictionary("")); - - cylinderBuilder = new PanelBuilder(); - cylinderBuilder.addComponent(CYLINDER_NAME_LABEL, cylinderNameField = stringField()); - cylinderBuilder.addComponent(POINT_1_LABEL, cylinderModel.bindPoint(Surface.POINT1_KEY, DECIMAL_PLACES, listener)); - cylinderBuilder.addComponent(POINT_2_LABEL, cylinderModel.bindPoint(Surface.POINT2_KEY, DECIMAL_PLACES, listener)); - cylinderBuilder.addComponent(RADIUS_LABEL, cylinderModel.bindDouble(Surface.RADIUS_KEY, DECIMAL_PLACES, listener)); - cylinderBuilder.getPanel().setBorder(BorderFactory.createTitledBorder("")); - - cylinderGroup = new RowGroup(); - builder.addComponentToGroup(cylinderGroup, cylinderBuilder.getPanel()); - cylinderGroup.hide(); - } - - private void addPlaneComponent(PanelBuilder builder, FieldChangeListener listener) { - planeModel = new DictionaryModel(new Dictionary("")); - planePointAndNormalModel = new DictionaryModel(new Dictionary("")); - - planeBuilder = new PanelBuilder(); - planeBuilder.addComponent(PLANE_NAME_LABEL, planeNameField = stringField()); - planeBuilder.addComponent(ORIGIN_LABEL, planePointAndNormalModel.bindPoint(Surface.BASE_POINT_KEY, DECIMAL_PLACES, listener)); - planeBuilder.addComponent(NORMAL_LABEL, planePointAndNormalModel.bindPoint(Surface.NORMAL_VECTOR_KEY, DECIMAL_PLACES, listener)); - planeBuilder.getPanel().setBorder(BorderFactory.createTitledBorder("")); - - regionBuilder = new PanelBuilder(); - regionBuilder.addComponent(PATCH_NAME_LABEL, regionNameField = stringField()); - regionBuilder.getPanel().setBorder(BorderFactory.createTitledBorder("")); - - planeGroup = new RowGroup(); - builder.addComponentToGroup(planeGroup, planeBuilder.getPanel()); - planeGroup.hide(); - - regionGroup = new RowGroup(); - builder.addComponentToGroup(regionGroup, regionBuilder.getPanel()); - regionGroup.hide(); - } - - private void addSphereComponent(PanelBuilder builder, FieldChangeListener listener) { - sphereModel = new DictionaryModel(new Dictionary("")); - - sphereBuilder = new PanelBuilder(); - sphereBuilder.addComponent(SPHERE_NAME_LABEL, sphereNameField = stringField()); - sphereBuilder.addComponent(CENTRE_LABEL, sphereModel.bindPoint(Surface.CENTRE_KEY, DECIMAL_PLACES, listener)); - sphereBuilder.addComponent(RADIUS_LABEL, sphereModel.bindDouble(Surface.RADIUS_KEY, DECIMAL_PLACES, listener)); - sphereBuilder.getPanel().setBorder(BorderFactory.createTitledBorder("")); - - sphereGroup = new RowGroup(); - builder.addComponentToGroup(sphereGroup, sphereBuilder.getPanel()); - sphereGroup.hide(); - } - - private void addRingComponent(PanelBuilder builder, FieldChangeListener listener) { - ringModel = new DictionaryModel(new Dictionary("")); - - ringBuilder = new PanelBuilder(); - ringBuilder.addComponent(RING_NAME_LABEL, ringNameField = stringField()); - ringBuilder.addComponent(POINT_1_LABEL, ringModel.bindPoint(Surface.POINT1_KEY, DECIMAL_PLACES, listener)); - ringBuilder.addComponent(POINT_2_LABEL, ringModel.bindPoint(Surface.POINT2_KEY, DECIMAL_PLACES, listener)); - ringBuilder.addComponent(INNER_RADIUS_LABEL, ringModel.bindDouble(Surface.INNER_RADIUS_KEY, DECIMAL_PLACES, listener)); - ringBuilder.addComponent(OUTER_RADIUS_LABEL, ringModel.bindDouble(Surface.OUTER_RADIUS_KEY, DECIMAL_PLACES, listener)); - ringBuilder.getPanel().setBorder(BorderFactory.createTitledBorder("")); - - ringGroup = new RowGroup(); - builder.addComponentToGroup(ringGroup, ringBuilder.getPanel()); - ringGroup.hide(); - } - - private void addNoneComponent(PanelBuilder builder, FieldChangeListener listener) { - noneGroup = new RowGroup(); - builder.addComponentToGroup(noneGroup, new JLabel("Select or Add a geometry")); - noneGroup.show(); - } - - void addRenameAction() { - stlNameField.addPropertyChangeListener(renameAction); - boxNameField.addPropertyChangeListener(renameAction); - cylinderNameField.addPropertyChangeListener(renameAction); - sphereNameField.addPropertyChangeListener(renameAction); - ringNameField.addPropertyChangeListener(renameAction); - planeNameField.addPropertyChangeListener(renameAction); - regionNameField.addPropertyChangeListener(renameAction); - } - - void remRenameAction() { - stlNameField.removePropertyChangeListener(renameAction); - boxNameField.removePropertyChangeListener(renameAction); - cylinderNameField.removePropertyChangeListener(renameAction); - sphereNameField.removePropertyChangeListener(renameAction); - ringNameField.removePropertyChangeListener(renameAction); - planeNameField.removePropertyChangeListener(renameAction); - regionNameField.removePropertyChangeListener(renameAction); - } - - private void showSTL() { - hideSelectedInEDT(); - showInEDT(stlGroup); - } - - private void showBox() { - hideSelectedInEDT(); - showInEDT(boxGroup); - } - - private void showCylinder() { - hideSelectedInEDT(); - showInEDT(cylinderGroup); - } - - private void showSphere() { - hideSelectedInEDT(); - showInEDT(sphereGroup); - } - - private void showRing() { - hideSelectedInEDT(); - showInEDT(ringGroup); - } - - private void showPlane() { - hideSelectedInEDT(); - showInEDT(planeGroup); - } - - private void showRegion() { - hideSelectedInEDT(); - showInEDT(regionGroup); - } - - private void showNone() { - hideSelectedInEDT(); - showInEDT(noneGroup); - } - - private void showInEDT(final RowGroup group) { - SwingUtilities.invokeLater(new Runnable() { - @Override - public void run() { - group.show(); - selected = group; - } - }); - } - - private void hideSelectedInEDT() { - if (selected != null) - SwingUtilities.invokeLater(new Runnable() { - @Override - public void run() { - selected.hide(); - } - }); - } - - public void showPanel(Surface[] surfaces) { - stop(); - if (surfaces == null || surfaces.length == 0) { - showNone(); - selectedSurface = null; - return; - } - boolean singleSelection = surfaces.length == 1; - - Type type = surfaces[0].getType(); - String name; - boolean visible = true; - if (singleSelection) { - name = surfaces[0].getName(); - visible = surfaces[0].isVisible(); - } else { - StringBuilder sb = new StringBuilder(); - for (Surface surface : surfaces) { - sb.append(surface.getName()); - sb.append(" "); - visible = visible && surface.isVisible(); - } - name = sb.toString(); - } - - selectedSurface = surfaces[0]; - - Dictionary dict = surfaces[0].getGeometryDictionary(); - switch (type) { - case BOX: - showBox(); - boxModel.setDictionary(dict); - updatePanel(singleSelection, visible, name, boxNameField, boxBuilder); - break; - - case CYLINDER: - showCylinder(); - cylinderModel.setDictionary(dict); - updatePanel(singleSelection, visible, name, cylinderNameField, cylinderBuilder); - break; - - case SPHERE: - showSphere(); - sphereModel.setDictionary(dict); - updatePanel(singleSelection, visible, name, sphereNameField, sphereBuilder); - break; - case RING: - showRing(); - ringModel.setDictionary(dict); - updatePanel(singleSelection, visible, name, ringNameField, ringBuilder); - break; - - case STL: - showSTL(); - stlModel.setDictionary(dict); - updatePanel(singleSelection, visible, name, stlNameField, stlBuilder); - break; - - case PLANE: - showPlane(); - planePointAndNormalModel.setDictionary(dict.subDict("pointAndNormalDict")); - Dictionary copyDict = new Dictionary(dict); - copyDict.remove("pointAndNormalDict"); - planeModel.setDictionary(copyDict); - updatePanel(singleSelection, visible, name, planeNameField, planeBuilder); - break; - - case SOLID: - case REGION: - showRegion(); - updatePanel(singleSelection, visible, name, regionNameField, regionBuilder); - regionNameField.setEnabled(singleSelection && selectedSurface instanceof PlaneRegion); - break; - - case MULTI: - case LINE: - break; - } - } - - private void updatePanel(boolean singleSelection, boolean visible, String name, StringField nameField, PanelBuilder builder) { - remRenameAction(); - nameField.setValue(name); - if (visible) { - builder.setEnabled(true); - if (singleSelection) { - nameField.setEnabled(true); - builder.setEnabled(true); - } else { - nameField.setEnabled(false); - builder.setEnabled(false); - } - } else { - builder.setEnabled(false); - } - addRenameAction(); - } - - public Dictionary getBoxDictionary() { - Dictionary dict = boxModel.getDictionary(); - if (boxNameField.isEnabled()) { - String name = boxNameField.getText(); - dict.setName(name); - } - - return dict; - } - - public Dictionary getCylinderDictionary() { - Dictionary dict = cylinderModel.getDictionary(); - if (cylinderNameField.isEnabled()) { - String name = cylinderNameField.getText(); - dict.setName(name); - } - - return dict; - } - - public Dictionary getSphereDictionary() { - Dictionary dict = sphereModel.getDictionary(); - if (sphereNameField.isEnabled()) { - String name = sphereNameField.getText(); - dict.setName(name); - } - - return dict; - } - - public Dictionary getRingDictionary() { - Dictionary dict = ringModel.getDictionary(); - if (ringNameField.isEnabled()) { - String name = ringNameField.getText(); - dict.setName(name); - } - - return dict; - } - - public Dictionary getPlaneDictionary() { - Dictionary dict = planeModel.getDictionary(); - Dictionary subDict = planePointAndNormalModel.getDictionary(); - if (planeNameField.isEnabled()) { - String name = planeNameField.getText(); - dict.setName(name); - } - dict.add(subDict); - return dict; - } - - public Dictionary getSTLDictionary() { - Dictionary dict = stlModel.getDictionary(); - if (stlNameField.isEnabled()) - dict.add("name", stlNameField.getText()); - return dict; - } - - public String getRegionName() { - return regionNameField.getText(); - } - - public void stop() { - if (showBoxButton.isSelected()) { - showBoxButton.doClick(); - } - } -} diff --git a/src/eu/engys/gui/mesh/panels/GeometryBuilder.java b/src/eu/engys/gui/mesh/panels/GeometryBuilder.java deleted file mode 100644 index 071ca06..0000000 --- a/src/eu/engys/gui/mesh/panels/GeometryBuilder.java +++ /dev/null @@ -1,182 +0,0 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - - -package eu.engys.gui.mesh.panels; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import eu.engys.core.dictionary.model.DictionaryModel; -import eu.engys.core.project.geometry.Surface; -import eu.engys.core.project.geometry.Type; -import eu.engys.util.Util; -import eu.engys.util.ui.TreeUtil; - -public class GeometryBuilder { - - private static final Logger logger = LoggerFactory.getLogger(GeometryBuilder.class); - - private GeometriesPanelBuilder geometriesPanel; - private DictionaryModel surfaceModel; - private DictionaryModel volumeModel; - private DictionaryModel layerModel; - private DictionaryModel zoneModel; - private boolean changeSurface; - private boolean changeVolume; - private boolean changeLayer; - private boolean changeZone; - - public GeometryBuilder(GeometriesPanelBuilder geometriesPanel, DictionaryModel surfaceModel, DictionaryModel volumeModel, DictionaryModel layerModel, DictionaryModel zoneModel) { - this.geometriesPanel = geometriesPanel; - this.surfaceModel = surfaceModel; - this.volumeModel = volumeModel; - this.layerModel = layerModel; - this.zoneModel = zoneModel; - } - - public void buildSurfaces(Surface... surfaces) { - if (Util.isVarArgsNotNull(surfaces)) { - Type type = surfaces[0].getType(); - Class typeClass = surfaces[0].getClass(); - - if (TreeUtil.isConsistent(surfaces, typeClass)) { - _buildSurfaces(type, surfaces); - } else { - logger.warn("Inconsistent selection"); - } - } - } - - private void _buildSurfaces(Type type, Surface... surfaces) { - changeSurface = !surfaces[0].getSurfaceDictionary().equals(surfaceModel.getDictionary()); - changeVolume = !surfaces[0].getVolumeDictionary().equals(volumeModel.getDictionary()); - changeLayer = !surfaces[0].getLayerDictionary().equals(layerModel.getDictionary()); - changeZone = !surfaces[0].getZoneDictionary().equals(zoneModel.getDictionary()); - - switch (type) { - case BOX: - buildBox(surfaces); - break; - case CYLINDER: - buildCylinder(surfaces); - break; - case SPHERE: - buildSphere(surfaces); - break; - case RING: - buildRing(surfaces); - break; - case PLANE: - buildPlane(surfaces); - break; - case STL: - buildSTL(surfaces); - break; - case REGION: - case SOLID: - buildRegion(surfaces); - break; - - default: - break; - } - } - - private void buildSTL(Surface... surfaces) { - for (Surface surface : surfaces) { - if (surfaces.length == 1) - surface.buildGeometryDictionary(geometriesPanel.getSTLDictionary()); - if (changeSurface) surface.buildSurfaceDictionary(surfaceModel.getDictionary()); - if (changeVolume) surface.buildVolumeDictionary(volumeModel.getDictionary()); - if (changeLayer) surface.buildLayerDictionary(layerModel.getDictionary()); - if (changeZone) surface.buildZoneDictionary(zoneModel.getDictionary()); - } - } - - private void buildRegion(Surface... surfaces) { - for (Surface surface : surfaces) { - if (changeSurface) surface.buildSurfaceDictionary(surfaceModel.getDictionary()); - if (changeVolume) surface.buildVolumeDictionary(volumeModel.getDictionary()); - if (changeLayer) surface.buildLayerDictionary(layerModel.getDictionary()); -// if (changeZone) surface.buildZoneDictionary(zoneModel.getDictionary()); - } - } - - private void buildBox(Surface... surfaces) { - for (Surface surface : surfaces) { - if (surfaces.length == 1) - surface.buildGeometryDictionary(geometriesPanel.getBoxDictionary()); - if (changeSurface) surface.buildSurfaceDictionary(surfaceModel.getDictionary()); - if (changeVolume) surface.buildVolumeDictionary(volumeModel.getDictionary()); - if (changeLayer) surface.buildLayerDictionary(layerModel.getDictionary()); - if (changeZone) surface.buildZoneDictionary(zoneModel.getDictionary()); - } - } - - private void buildCylinder(Surface... surfaces) { - for (Surface surface : surfaces) { - if (surfaces.length == 1) - surface.buildGeometryDictionary(geometriesPanel.getCylinderDictionary()); - if (changeSurface) surface.buildSurfaceDictionary(surfaceModel.getDictionary()); - if (changeVolume) surface.buildVolumeDictionary(volumeModel.getDictionary()); - if (changeLayer) surface.buildLayerDictionary(layerModel.getDictionary()); - if (changeZone) surface.buildZoneDictionary(zoneModel.getDictionary()); - } - } - - private void buildSphere(Surface... surfaces) { - for (Surface surface : surfaces) { - if (surfaces.length == 1) - surface.buildGeometryDictionary(geometriesPanel.getSphereDictionary()); - if (changeSurface) surface.buildSurfaceDictionary(surfaceModel.getDictionary()); - if (changeVolume) surface.buildVolumeDictionary(volumeModel.getDictionary()); - if (changeLayer) surface.buildLayerDictionary(layerModel.getDictionary()); - if (changeZone) surface.buildZoneDictionary(zoneModel.getDictionary()); - } - } - - private void buildRing(Surface... surfaces) { - for (Surface surface : surfaces) { - if (surfaces.length == 1) - surface.buildGeometryDictionary(geometriesPanel.getRingDictionary()); - if (changeSurface) surface.buildSurfaceDictionary(surfaceModel.getDictionary()); - if (changeVolume) surface.buildVolumeDictionary(volumeModel.getDictionary()); - if (changeLayer) surface.buildLayerDictionary(layerModel.getDictionary()); - if (changeZone) surface.buildZoneDictionary(zoneModel.getDictionary()); - } - } - - private void buildPlane(Surface... surfaces) { - for (Surface surface : surfaces) { - if (surfaces.length == 1) - surface.buildGeometryDictionary(geometriesPanel.getPlaneDictionary()); - if (changeSurface) surface.buildSurfaceDictionary(surfaceModel.getDictionary()); - if (changeVolume) surface.buildVolumeDictionary(volumeModel.getDictionary()); - if (changeLayer) surface.buildLayerDictionary(layerModel.getDictionary()); - if (changeZone) surface.buildZoneDictionary(zoneModel.getDictionary()); - } - } -} diff --git a/src/eu/engys/gui/mesh/panels/GeometryTreeNodeManager.java b/src/eu/engys/gui/mesh/panels/GeometryTreeNodeManager.java index ab835f0..a6902b6 100644 --- a/src/eu/engys/gui/mesh/panels/GeometryTreeNodeManager.java +++ b/src/eu/engys/gui/mesh/panels/GeometryTreeNodeManager.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.mesh.panels; import java.awt.Component; @@ -80,7 +79,7 @@ public class GeometryTreeNodeManager extends DefaultTreeNodeManager { @Override public void update(Observable o, final Object arg) { if (!(arg instanceof FeatureLine) && (arg instanceof Stl || arg instanceof BaseSurface)) { - logger.debug("Observerd a change: arg is " + arg.getClass()); + logger.debug("[CHANGE OBSERVERD] arg: " + arg.getClass().getSimpleName()); ExecUtil.invokeAndWait(new Runnable() { @Override public void run() { @@ -92,7 +91,7 @@ public class GeometryTreeNodeManager extends DefaultTreeNodeManager { } }); } else if (arg instanceof Geometry) { - logger.debug("Observerd a change: arg is Geometry"); + logger.debug("[CHANGE OBSERVERD] arg: " + arg.getClass().getSimpleName()); ExecUtil.invokeAndWait(new Runnable() { @Override public void run() { @@ -104,7 +103,7 @@ public class GeometryTreeNodeManager extends DefaultTreeNodeManager { } }); } else if (arg instanceof Patches) { - logger.debug("Observerd a change: arg is Patches"); + logger.debug("[CHANGE OBSERVERD] arg: " + arg.getClass().getSimpleName()); ExecUtil.invokeAndWait(new Runnable() { @Override public void run() { @@ -270,6 +269,7 @@ public class GeometryTreeNodeManager extends DefaultTreeNodeManager { private void saveCurrentSelection() { if (Util.isVarArgsNotNull(currentSelection)) { + logger.debug("saveCurrentSelection: {} selected {}", currentSelection.length, currentSelection.length == 1 ? ", selection is: " + currentSelection[0] : ""); panel.saveSurfaces(currentSelection); } } diff --git a/src/eu/engys/gui/mesh/panels/MaterialPointsPanel.java b/src/eu/engys/gui/mesh/panels/MaterialPointsPanel.java index 49e11fb..52f4520 100644 --- a/src/eu/engys/gui/mesh/panels/MaterialPointsPanel.java +++ b/src/eu/engys/gui/mesh/panels/MaterialPointsPanel.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.mesh.panels; @@ -32,9 +31,14 @@ import static eu.engys.core.project.system.SnappyHexMeshDict.REFINEMENTS_REGIONS import static eu.engys.core.project.system.SnappyHexMeshDict.REFINEMENTS_SURFACES_KEY; import static eu.engys.core.project.system.SnappyHexMeshDict.WRAPPER_KEY; +import java.awt.Dimension; +import java.awt.event.ActionEvent; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; +import javax.swing.AbstractAction; +import javax.swing.Icon; +import javax.swing.JButton; import javax.swing.JComponent; import com.google.inject.Inject; @@ -44,22 +48,28 @@ import eu.engys.core.dictionary.model.DictionaryModel; import eu.engys.core.dictionary.model.PointInfo; import eu.engys.core.dictionary.model.ShowLocationAdapter; import eu.engys.core.project.Model; +import eu.engys.core.project.geometry.BoundingBox; import eu.engys.core.project.system.SnappyHexMeshDict; import eu.engys.gui.DefaultGUIPanel; import eu.engys.gui.events.EventManager; import eu.engys.gui.events.view3D.PointEvent; +import eu.engys.util.ui.ResourcesUtil; import eu.engys.util.ui.builder.PanelBuilder; +import eu.engys.util.ui.textfields.DoubleField; +import net.java.dev.designgridlayout.Componentizer; public class MaterialPointsPanel extends DefaultGUIPanel { - public static final String TITLE = "Material Point"; + public static final String MATERIAL_POINT = "Material Point"; + + private final static Icon CENTRE_ICON = ResourcesUtil.getIcon("centre.materialpoint.icon"); private DictionaryModel castellatedModel; private ShowLocationAdapter locationPanel; @Inject public MaterialPointsPanel(Model model) { - super(TITLE, model); + super(MATERIAL_POINT, model); } @Override @@ -77,10 +87,24 @@ public class MaterialPointsPanel extends DefaultGUIPanel { @Override protected JComponent layoutComponents() { castellatedModel = new DictionaryModel(new Dictionary("")); - + + JButton centreButton = new JButton(new AbstractAction("", CENTRE_ICON) { + @Override + public void actionPerformed(ActionEvent e) { + BoundingBox bb = model.getGeometry().computeBoundingBox(); + DoubleField[] fields = locationPanel.getFields(); + + fields[0].setDoubleValue(bb.getCenter()[0]); + fields[1].setDoubleValue(bb.getCenter()[1]); + fields[2].setDoubleValue(bb.getCenter()[2]); + } + }); + centreButton.setToolTipText("Move the material point to the centre of the bounding box"); + centreButton.setPreferredSize(new Dimension(22, 22)); + PanelBuilder builder = new PanelBuilder(); locationPanel = castellatedModel.bindLocation(LOCATION_IN_MESH, 4); - builder.addComponent(locationPanel); + builder.addComponent(Componentizer.create().minAndMore(locationPanel).fixedPref(centreButton).component()); locationPanel.addPropertyChangeListener(PointInfo.PROPERTY_NAME, new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { @@ -92,9 +116,8 @@ public class MaterialPointsPanel extends DefaultGUIPanel { }); return builder.removeMargins().getPanel(); - } - + @Override public void load() { SnappyHexMeshDict snappyDict = model.getProject().getSystemFolder().getSnappyHexMeshDict(); @@ -120,5 +143,5 @@ public class MaterialPointsPanel extends DefaultGUIPanel { castellated.add(LOCATION_IN_MESH, locations); } } - + } diff --git a/src/eu/engys/gui/mesh/panels/MeshInfoPanel.java b/src/eu/engys/gui/mesh/panels/MeshInfoPanel.java new file mode 100644 index 0000000..a4c9cc7 --- /dev/null +++ b/src/eu/engys/gui/mesh/panels/MeshInfoPanel.java @@ -0,0 +1,232 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.gui.mesh.panels; + +import static eu.engys.util.ui.ComponentsFactory.labelField; + +import java.text.DecimalFormat; +import java.text.DecimalFormatSymbols; +import java.util.Locale; + +import javax.swing.JLabel; +import javax.swing.JPanel; + +import eu.engys.core.project.geometry.BoundingBox; +import eu.engys.core.project.mesh.Mesh; +import eu.engys.core.project.mesh.MeshInfo; +import eu.engys.util.ui.builder.PanelBuilder; + +public class MeshInfoPanel { + + private static final String NONE = "-"; + private JLabel cells; + private JLabel points; + private JLabel faces; + private JLabel internalFaces; + + private JLabel patches; + private JLabel pointZones; + private JLabel faceZones; + private JLabel cellZones; + + private JLabel hexahedra; + private JLabel prisms; + private JLabel wedges; + private JLabel pyramids; + private JLabel tetWedges; + private JLabel tetrahedra; + private JLabel polyhedra; + + // private JTextArea cellsPerLevel; + // private JLabel memory; + + private JLabel xBounds; + private JLabel yBounds; + private JLabel zBounds; + + private PanelBuilder dataArrays; + private PanelBuilder cellTypes; + private PanelBuilder statistics; + private PanelBuilder bounds; + + public MeshInfoPanel() { + layoutComponents(); + } + + private void layoutComponents() { + points = labelField(NONE); + cells = labelField(NONE); + faces = labelField(NONE); + internalFaces = labelField(NONE); + + patches = labelField(NONE); + pointZones = labelField(NONE); + faceZones = labelField(NONE); + cellZones = labelField(NONE); + + hexahedra = labelField(NONE); + prisms = labelField(NONE); + wedges = labelField(NONE); + pyramids = labelField(NONE); + tetWedges = labelField(NONE); + tetrahedra = labelField(NONE); + polyhedra = labelField(NONE); + + // cellsPerLevel = ComponentsFactory.labelArea(); + // cellsPerLevel.setEditable(false); + // + // memory = labelField(""); + + xBounds = labelField(""); + yBounds = labelField(""); + zBounds = labelField(""); + + statistics = new PanelBuilder(); + statistics.addComponent("Points", points); + statistics.addComponent("Cells", cells); + statistics.addComponent("Faces", faces); + statistics.addComponent("Internal Faces", internalFaces); + + statistics.addComponent("Boundary Patches", patches); + statistics.addComponent("Point Zones", pointZones); + statistics.addComponent("Face Zones", faceZones); + statistics.addComponent("Cell Zones", cellZones); + + cellTypes = new PanelBuilder(); + cellTypes.addComponent("Hexahedra", hexahedra); + cellTypes.addComponent("Prisms", prisms); + cellTypes.addComponent("Wedges", wedges); + cellTypes.addComponent("Pyramids", pyramids); + cellTypes.addComponent("Tet Wedges", tetWedges); + cellTypes.addComponent("Tetrahedra", tetrahedra); + cellTypes.addComponent("Polyhedra", polyhedra); + cellTypes.addComponent("", new JLabel(" ")); + + // statistics.addComponent("Cells per Refinement Level", cellsPerLevel); + // statistics.addComponent("Memory [MB]", memory); + + dataArrays = new PanelBuilder(); + + bounds = new PanelBuilder(); + bounds.addComponent("X Range", xBounds); + bounds.addComponent("Y Range", yBounds); + bounds.addComponent("Z Range", zBounds); + } + + public void load(Mesh mesh) { + if (mesh != null) { + MeshInfo mi = mesh.getMeshInfo(); + if (mi.isValid()) { + cells.setText(mi.getCells() == -1 ? NONE : Long.toString(mi.getCells())); + points.setText(mi.getPoints() == -1 ? NONE : Long.toString(mi.getPoints())); + faces.setText(mi.getFaces() == -1 ? NONE : Long.toString(mi.getFaces())); + internalFaces.setText(mi.getInternalFaces() == -1 ? NONE : Long.toString(mi.getInternalFaces())); + + patches.setText(mi.getBoundaryPatches() == -1 ? NONE : Long.toString(mi.getBoundaryPatches())); + pointZones.setText(mi.getPointZones() == -1 ? NONE : Long.toString(mi.getPointZones())); + faceZones.setText(mi.getFaceZones() == -1 ? NONE : Long.toString(mi.getFaceZones())); + cellZones.setText(mi.getCellZones() == -1 ? NONE : Long.toString(mi.getCellZones())); + + hexahedra.setText(mi.getHexahedra() == -1 ? NONE : Long.toString(mi.getHexahedra())); + prisms.setText(mi.getPrisms() == -1 ? NONE : Long.toString(mi.getPrisms())); + wedges.setText(mi.getWedges() == -1 ? NONE : Long.toString(mi.getWedges())); + pyramids.setText(mi.getPyramids() == -1 ? NONE : Long.toString(mi.getPyramids())); + tetWedges.setText(mi.getTetWedges() == -1 ? NONE : Long.toString(mi.getTetWedges())); + tetrahedra.setText(mi.getTetrahedra() == -1 ? NONE : Long.toString(mi.getTetrahedra())); + polyhedra.setText(mi.getPolyhedra() == -1 ? NONE : Long.toString(mi.getPolyhedra())); + + BoundingBox bounds = mesh.getExternalMesh().getBounds(); + xBounds.setText(getTextForBounds(bounds.getXmin(), bounds.getXmax())); + yBounds.setText(getTextForBounds(bounds.getYmin(), bounds.getYmax())); + zBounds.setText(getTextForBounds(bounds.getZmin(), bounds.getZmax())); + } else { + reset(); + } + } else { + reset(); + } + } + + public JPanel getStatistics() { + return statistics.withTitle("Statistics").getPanel(); + } + + public JPanel getCellType() { + return cellTypes.withTitle("Cell Types").getPanel(); + } + + public JPanel getDataArrays() { + return dataArrays.withTitle("Data Arrays").getPanel(); + } + + public JPanel getBounds() { + return bounds.withTitle("Bounds").getPanel(); + } + + public void reset() { + cells.setText(NONE); + points.setText(NONE); + faces.setText(NONE); + + cells.setText(NONE); + points.setText(NONE); + faces.setText(NONE); + internalFaces.setText(NONE); + + patches.setText(NONE); + pointZones.setText(NONE); + faceZones.setText(NONE); + cellZones.setText(NONE); + + hexahedra.setText(NONE); + prisms.setText(NONE); + wedges.setText(NONE); + pyramids.setText(NONE); + tetWedges.setText(NONE); + tetrahedra.setText(NONE); + polyhedra.setText(NONE); + + // cellsPerLevel.setText(" - "); + // memory.setText("-"); + xBounds.setText("[- , -]"); + yBounds.setText("[- , -]"); + zBounds.setText("[- , -]"); + } + + private static final DecimalFormat formatter = new DecimalFormat("#.###", new DecimalFormatSymbols(Locale.US)); + + private String getTextForBounds(double min, double max) { + if (areValid(min, max)) { + return "[" + formatter.format(min) + " , " + formatter.format(max) + "] (Delta " + formatter.format(max - min) + ")"; + } else { + return "[0 , 0]"; + } + } + + private boolean areValid(double min, double max) { + return min < Double.MAX_VALUE && max > -Double.MAX_VALUE; + } + +} diff --git a/src/eu/engys/gui/mesh/panels/ShapesPanel.java b/src/eu/engys/gui/mesh/panels/ShapesPanel.java new file mode 100644 index 0000000..060ae11 --- /dev/null +++ b/src/eu/engys/gui/mesh/panels/ShapesPanel.java @@ -0,0 +1,511 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.gui.mesh.panels; + +import static eu.engys.util.ui.ComponentsFactory.stringField; + +import java.awt.BorderLayout; + +import javax.swing.BorderFactory; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JTextField; +import javax.swing.SwingUtilities; + +import eu.engys.core.project.geometry.Surface; +import eu.engys.core.project.geometry.Type; +import eu.engys.core.project.geometry.surface.Box; +import eu.engys.core.project.geometry.surface.Cylinder; +import eu.engys.core.project.geometry.surface.Plane; +import eu.engys.core.project.geometry.surface.PlaneRegion; +import eu.engys.core.project.geometry.surface.Ring; +import eu.engys.core.project.geometry.surface.Sphere; +import eu.engys.core.project.geometry.surface.Stl; +import eu.engys.gui.mesh.GeometryPanel; +import eu.engys.gui.view3D.BoxEventButton; +import eu.engys.util.Symbols; +import eu.engys.util.bean.BeanModel; +import eu.engys.util.ui.FieldChangeListener; +import eu.engys.util.ui.TreeUtil; +import eu.engys.util.ui.builder.PanelBuilder; +import eu.engys.util.ui.textfields.DoubleField; +import eu.engys.util.ui.textfields.StringField; +import net.java.dev.designgridlayout.RowGroup; + +public class ShapesPanel extends JPanel { + + private final class ChangeSurfaceAction extends FieldChangeListener { + @Override + public void fieldChanged(Object source) { + //System.err.println("ShapesPanel.ChangeSurfaceAction.fieldChanged() " + source); + meshPanel.changeSurface(); + } + } + + private final class RenameAction extends FieldChangeListener { + @Override + public void fieldChanged(Object source) { + //System.out.println("ShapesPanel.RenameAction.fieldChanged() " + source); + if (source instanceof StringField) { + StringField field = (StringField) source; + meshPanel.renameSurface(field.getText()); + } + } + } + + public static final String BOX_NAME_LABEL = "Box Name"; + public static final String SPHERE_NAME_LABEL = "Sphere Name"; + public static final String CYLINDER_NAME_LABEL = "Cylinder Name"; + public static final String PLANE_NAME_LABEL = "Plane Name"; + public static final String RING_NAME_LABEL = "Ring Name"; + public static final String SURFACE_NAME_LABEL = "Surface Name"; + + public static final String OUTER_RADIUS_LABEL = "Outer Radius " + Symbols.M; + public static final String INNER_RADIUS_LABEL = "Inner Radius " + Symbols.M; + public static final String PATCH_NAME_LABEL = "Patch Name"; + public static final String NORMAL_LABEL = "Normal"; + public static final String ORIGIN_LABEL = "Origin"; + public static final String POINT_1_LABEL = "Point 1"; + public static final String POINT_2_LABEL = "Point 2"; + public static final String MIN_LABEL = "Min " + Symbols.M; + public static final String MAX_LABEL = "Max " + Symbols.M; + public static final String RADIUS_LABEL = "Radius " + Symbols.M; + public static final String CENTRE_LABEL = "Centre"; + public static final String DELTA_LABEL = "Delta"; + public static final String ROTATION_LABEL = "Rotation"; + public static final String I_LABEL = "i" + Symbols.HAT; + public static final String J_LABEL = "j" + Symbols.HAT; + public static final String K_LABEL = "k" + Symbols.HAT; + + public static final String FILE_LABEL = "File"; + public static final String INCLUDE_CUT_LABEL = "Include Cut Cells"; + public static final String INCLUDE_INSIDE_LABEL = "Include Inside"; + public static final String INCLUDE_OUTSIDE_LABEL = "Include Outside"; + public static final String OUTSIDE_POINT_LABEL = "Outside Point"; + public static final int DECIMAL_PLACES = 4; + + private StringField stlNameField; + private StringField boxNameField; + private StringField cylinderNameField; + private StringField sphereNameField; + private StringField ringNameField; + private StringField planeNameField; + private StringField regionNameField; + + private BeanModel boxModel; + private BeanModel cylinderModel; + private BeanModel sphereModel; + private BeanModel ringModel; + private BeanModel planePointAndNormalModel; + private BeanModel stlModel; + + private PanelBuilder boxBuilder; + private PanelBuilder cylinderBuilder; + private PanelBuilder sphereBuilder; + private PanelBuilder ringBuilder; + private PanelBuilder planeBuilder; + private PanelBuilder regionBuilder; + private PanelBuilder stlBuilder; + + private RowGroup boxGroup; + private RowGroup sphereGroup; + private RowGroup ringGroup; + private RowGroup planeGroup; + private RowGroup cylinderGroup; + private RowGroup stlGroup; + private RowGroup regionGroup; + private RowGroup noneGroup; + + private GeometryPanel meshPanel; + + private RowGroup selected; + private Surface selectedSurface; + + private RenameAction renameAction; + private ChangeSurfaceAction changeSurfaceAction; + + private BoxEventButton showBoxButton; + public static final String MIN_MAX_BOX = "Min-Max"; + public static final String CENTRE_DELTA_BOX = "Centre-Delta"; + + public ShapesPanel(GeometryPanel panel) { + super(new BorderLayout()); + this.meshPanel = panel; + layoutComponents(); + } + + private void layoutComponents() { + PanelBuilder builder = new PanelBuilder(); + builder.addButtons(meshPanel.getShapeButtons()); + builder.addSeparator(""); + + changeSurfaceAction = new ChangeSurfaceAction(); + + addSTLComponent(builder); + addBoxComponent(builder); + addCylinderComponent(builder); + addPlaneComponent(builder); + addSphereComponent(builder); + addRingComponent(builder); + addNoneComponent(builder); + + renameAction = new RenameAction(); + addRenameAction(); + + selected = noneGroup; + + add(builder.removeMargins().getPanel()); + } + + private void addSTLComponent(PanelBuilder builder) { + stlModel = new BeanModel<>(); + + stlBuilder = new PanelBuilder(); + stlBuilder.addComponent(SURFACE_NAME_LABEL, stlNameField = stringField()); + stlBuilder.getPanel().setBorder(BorderFactory.createTitledBorder("")); + + stlGroup = new RowGroup(); + builder.addComponentToGroup(stlGroup, stlBuilder.getPanel()); + stlGroup.hide(); + } + + private void addBoxComponent(PanelBuilder builder) { + boxModel = new BeanModel<>(); + + boxNameField = stringField(); + DoubleField[] boxMin = boxModel.bindPoint(Surface.MIN_KEY, DECIMAL_PLACES); + DoubleField[] boxMax = boxModel.bindPoint(Surface.MAX_KEY, DECIMAL_PLACES); + + addChangeSurfaceAction(boxMin); + addChangeSurfaceAction(boxMax); + + showBoxButton = new BoxEventButton(boxMin, boxMax); + + boxBuilder = new PanelBuilder(); + boxBuilder.addComponent(BOX_NAME_LABEL, boxNameField); + // boxBuilder.addComponent("", labelField("X"), labelField("Y"), labelField("Z")); + boxBuilder.addComponent(MIN_LABEL, boxMin[0], boxMin[1], boxMin[2], showBoxButton); + boxBuilder.addComponentAndSpan(MAX_LABEL, boxMax); + boxBuilder.getPanel().setBorder(BorderFactory.createTitledBorder("")); + + boxGroup = new RowGroup(); + builder.addComponentToGroup(boxGroup, boxBuilder.getPanel()); + boxGroup.hide(); + } + + private void addCylinderComponent(PanelBuilder builder) { + cylinderModel = new BeanModel<>(); + + cylinderNameField = stringField(); + DoubleField[] point1 = cylinderModel.bindPoint(Surface.POINT1_KEY, DECIMAL_PLACES); + DoubleField[] point2 = cylinderModel.bindPoint(Surface.POINT2_KEY, DECIMAL_PLACES); + DoubleField radius = cylinderModel.bindDouble(Surface.RADIUS_KEY, DECIMAL_PLACES); + + cylinderBuilder = new PanelBuilder(); + cylinderBuilder.addComponent(CYLINDER_NAME_LABEL, cylinderNameField); + cylinderBuilder.addComponent(POINT_1_LABEL, point1); + cylinderBuilder.addComponent(POINT_2_LABEL, point2); + cylinderBuilder.addComponent(RADIUS_LABEL, radius); + cylinderBuilder.getPanel().setBorder(BorderFactory.createTitledBorder("")); + + addChangeSurfaceAction(point1); + addChangeSurfaceAction(point2); + addChangeSurfaceAction(radius); + + cylinderGroup = new RowGroup(); + builder.addComponentToGroup(cylinderGroup, cylinderBuilder.getPanel()); + cylinderGroup.hide(); + } + + private void addSphereComponent(PanelBuilder builder) { + sphereModel = new BeanModel<>(); + + sphereNameField = stringField(); + DoubleField[] centre = sphereModel.bindPoint(Surface.CENTRE_KEY, DECIMAL_PLACES); + DoubleField radius = sphereModel.bindDouble(Surface.RADIUS_KEY, DECIMAL_PLACES); + + sphereBuilder = new PanelBuilder(); + sphereBuilder.addComponent(SPHERE_NAME_LABEL, sphereNameField); + sphereBuilder.addComponent(CENTRE_LABEL, centre); + sphereBuilder.addComponent(RADIUS_LABEL, radius); + sphereBuilder.getPanel().setBorder(BorderFactory.createTitledBorder("")); + + addChangeSurfaceAction(centre); + addChangeSurfaceAction(radius); + + sphereGroup = new RowGroup(); + builder.addComponentToGroup(sphereGroup, sphereBuilder.getPanel()); + sphereGroup.hide(); + } + + private void addPlaneComponent(PanelBuilder builder) { + planePointAndNormalModel = new BeanModel<>(); + + planeNameField = stringField(); + DoubleField[] origin = planePointAndNormalModel.bindPoint(Surface.BASE_POINT_KEY, DECIMAL_PLACES); + DoubleField[] normal = planePointAndNormalModel.bindPoint(Surface.NORMAL_VECTOR_KEY, DECIMAL_PLACES); + + planeBuilder = new PanelBuilder(); + planeBuilder.addComponent(PLANE_NAME_LABEL, planeNameField); + planeBuilder.addComponent(ORIGIN_LABEL, origin); + planeBuilder.addComponent(NORMAL_LABEL, normal); + planeBuilder.getPanel().setBorder(BorderFactory.createTitledBorder("")); + + addChangeSurfaceAction(origin); + addChangeSurfaceAction(normal); + + regionBuilder = new PanelBuilder(); + regionBuilder.addComponent(PATCH_NAME_LABEL, regionNameField = stringField()); + regionBuilder.getPanel().setBorder(BorderFactory.createTitledBorder("")); + + planeGroup = new RowGroup(); + builder.addComponentToGroup(planeGroup, planeBuilder.getPanel()); + planeGroup.hide(); + + regionGroup = new RowGroup(); + builder.addComponentToGroup(regionGroup, regionBuilder.getPanel()); + regionGroup.hide(); + } + + private void addRingComponent(PanelBuilder builder) { + ringModel = new BeanModel<>(); + + ringNameField = stringField(); + DoubleField[] point1 = ringModel.bindPoint(Surface.POINT1_KEY, DECIMAL_PLACES); + DoubleField[] point2 = ringModel.bindPoint(Surface.POINT2_KEY, DECIMAL_PLACES); + DoubleField radius1 = ringModel.bindDouble(Surface.INNER_RADIUS_KEY, DECIMAL_PLACES); + DoubleField radius2 = ringModel.bindDouble(Surface.OUTER_RADIUS_KEY, DECIMAL_PLACES); + + ringBuilder = new PanelBuilder(); + ringBuilder.addComponent(RING_NAME_LABEL, ringNameField); + ringBuilder.addComponent(POINT_1_LABEL, point1); + ringBuilder.addComponent(POINT_2_LABEL, point2); + ringBuilder.addComponent(INNER_RADIUS_LABEL, radius1); + ringBuilder.addComponent(OUTER_RADIUS_LABEL, radius2); + ringBuilder.getPanel().setBorder(BorderFactory.createTitledBorder("")); + + addChangeSurfaceAction(point1); + addChangeSurfaceAction(point2); + addChangeSurfaceAction(radius1, radius2); + + ringGroup = new RowGroup(); + builder.addComponentToGroup(ringGroup, ringBuilder.getPanel()); + ringGroup.hide(); + } + + private void addNoneComponent(PanelBuilder builder) { + noneGroup = new RowGroup(); + builder.addComponentToGroup(noneGroup, new JLabel("Select or Add a geometry")); + noneGroup.show(); + } + + void addChangeSurfaceAction(JTextField... components) { + for (JTextField c : components) { + c.addPropertyChangeListener("value", changeSurfaceAction); + } + } + + void addRenameAction() { + stlNameField.addPropertyChangeListener("value", renameAction); + boxNameField.addPropertyChangeListener("value", renameAction); + cylinderNameField.addPropertyChangeListener("value", renameAction); + sphereNameField.addPropertyChangeListener("value", renameAction); + ringNameField.addPropertyChangeListener("value", renameAction); + planeNameField.addPropertyChangeListener("value", renameAction); + regionNameField.addPropertyChangeListener("value", renameAction); + } + + private void showSTL() { + hideSelectedInEDT(); + showInEDT(stlGroup); + } + + private void showBox() { + hideSelectedInEDT(); + showInEDT(boxGroup); + } + + private void showCylinder() { + hideSelectedInEDT(); + showInEDT(cylinderGroup); + } + + private void showSphere() { + hideSelectedInEDT(); + showInEDT(sphereGroup); + } + + private void showRing() { + hideSelectedInEDT(); + showInEDT(ringGroup); + } + + private void showPlane() { + hideSelectedInEDT(); + showInEDT(planeGroup); + } + + private void showRegion() { + hideSelectedInEDT(); + showInEDT(regionGroup); + } + + private void showNone() { + hideSelectedInEDT(); + showInEDT(noneGroup); + } + + private void showInEDT(final RowGroup group) { + SwingUtilities.invokeLater(new Runnable() { + @Override + public void run() { + group.show(); + selected = group; + } + }); + } + + private void hideSelectedInEDT() { + if (selected != null) + SwingUtilities.invokeLater(new Runnable() { + @Override + public void run() { + selected.hide(); + } + }); + } + + public void showPanel(Surface[] surfaces) { + stop(); + if (surfaces == null || surfaces.length == 0 || !TreeUtil.isConsistent(surfaces, surfaces[0].getClass())) { + showNone(); + selectedSurface = null; + return; + } + boolean singleSelection = surfaces.length == 1; + + Type type = surfaces[0].getType(); + String name; + boolean visible = true; + if (singleSelection) { + name = surfaces[0].getName(); + visible = surfaces[0].isVisible(); + } else { + StringBuilder sb = new StringBuilder(); + for (Surface surface : surfaces) { + sb.append(surface.getName()); + sb.append(" "); + visible = visible && surface.isVisible(); + } + name = sb.toString(); + } + + selectedSurface = surfaces[0].cloneSurface(); + + renameAction.setAdjusting(true); + changeSurfaceAction.setAdjusting(true); + + switch (type) { + case BOX: + showBox(); + boxModel.setBean((Box) selectedSurface); + updatePanel(singleSelection, visible, name, boxNameField, boxBuilder); + break; + + case CYLINDER: + showCylinder(); + cylinderModel.setBean((Cylinder) selectedSurface); + updatePanel(singleSelection, visible, name, cylinderNameField, cylinderBuilder); + break; + + case SPHERE: + showSphere(); + sphereModel.setBean((Sphere) selectedSurface); + updatePanel(singleSelection, visible, name, sphereNameField, sphereBuilder); + break; + case RING: + showRing(); + ringModel.setBean((Ring) selectedSurface); + updatePanel(singleSelection, visible, name, ringNameField, ringBuilder); + break; + + case STL: + showSTL(); + stlModel.setBean((Stl) selectedSurface); + updatePanel(singleSelection, visible, name, stlNameField, stlBuilder); + break; + + case PLANE: + showPlane(); + planePointAndNormalModel.setBean((Plane) selectedSurface); + updatePanel(singleSelection, visible, name, planeNameField, planeBuilder); + break; + + case SOLID: + case REGION: + showRegion(); + updatePanel(singleSelection, visible, name, regionNameField, regionBuilder); + regionNameField.setEnabled(singleSelection && selectedSurface instanceof PlaneRegion); + break; + + case MULTI: + case LINE: + break; + } + + renameAction.setAdjusting(false); + changeSurfaceAction.setAdjusting(false); + } + + private void updatePanel(boolean singleSelection, boolean visible, String name, StringField nameField, PanelBuilder builder) { + nameField.setValue(name); + if (visible) { + builder.setEnabled(true); + if (singleSelection) { + nameField.setEnabled(true); + builder.setEnabled(true); + } else { + nameField.setEnabled(false); + builder.setEnabled(false); + } + } else { + builder.setEnabled(false); + } + } + + public String getRegionName() { + return regionNameField.getText(); + } + + public void stop() { + if (showBoxButton.isSelected()) { + showBoxButton.doClick(); + } + } + + public Surface getSelectedSurface() { + return selectedSurface; + } +} diff --git a/src/eu/engys/gui/mesh/panels/SolverBoundaryMeshPanel.java b/src/eu/engys/gui/mesh/panels/SolverBoundaryMeshPanel.java index 5d216e0..062c57e 100644 --- a/src/eu/engys/gui/mesh/panels/SolverBoundaryMeshPanel.java +++ b/src/eu/engys/gui/mesh/panels/SolverBoundaryMeshPanel.java @@ -1,29 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.mesh.panels; import static eu.engys.util.ui.ComponentsFactory.labelField; @@ -34,19 +32,15 @@ import java.text.DateFormat; import java.text.DecimalFormat; import java.text.DecimalFormatSymbols; import java.util.Date; -import java.util.List; import java.util.Locale; import javax.inject.Inject; -import javax.swing.BorderFactory; import javax.swing.JComponent; import javax.swing.JLabel; -import javax.swing.JTextArea; import eu.engys.core.project.Model; import eu.engys.gui.AbstractGUIPanel; import eu.engys.gui.tree.TreeNodeManager; -import eu.engys.util.ui.ComponentsFactory; import eu.engys.util.ui.builder.PanelBuilder; public class SolverBoundaryMeshPanel extends AbstractGUIPanel { @@ -59,17 +53,9 @@ public class SolverBoundaryMeshPanel extends AbstractGUIPanel { private JLabel name; private JLabel path; private JLabel created; - private JLabel cells; - private JLabel points; - private JLabel faces; - private JTextArea cellsPerLevel; - private JLabel memory; - - private JLabel xBounds; - private JLabel yBounds; - private JLabel zBounds; private PanelBuilder dataArrays; + private MeshInfoPanel meshInfoPanel; @Inject public SolverBoundaryMeshPanel(Model model) { @@ -83,53 +69,25 @@ public class SolverBoundaryMeshPanel extends AbstractGUIPanel { path = labelField(""); created = labelField(""); - cells = labelField(""); - points = labelField(""); - faces = labelField(""); - - cellsPerLevel = ComponentsFactory.labelArea(); - cellsPerLevel.setEditable(false); - - memory = labelField(""); - - xBounds = labelField(""); - yBounds = labelField(""); - zBounds = labelField(""); + meshInfoPanel = new MeshInfoPanel(); PanelBuilder properties = new PanelBuilder(); - properties.getPanel().setBorder(BorderFactory.createTitledBorder("Properties")); properties.addComponent("Name", name); properties.addComponent("Path", path); properties.addComponent("Created", created); - PanelBuilder statistics = new PanelBuilder(); - statistics.getPanel().setBorder(BorderFactory.createTitledBorder("Statistics")); - statistics.addComponent("Number of Cells", cells); - statistics.addComponent("Number of Faces", faces); - statistics.addComponent("Number of Points", points); - statistics.addComponent("Cells per Refinement Level", cellsPerLevel); - // statistics.addComponent("Memory [MB]", memory); - - dataArrays = new PanelBuilder(); - dataArrays.getPanel().setBorder(BorderFactory.createTitledBorder("Data Arrays")); - - PanelBuilder bounds = new PanelBuilder(); - bounds.getPanel().setBorder(BorderFactory.createTitledBorder("Bounds")); - bounds.addComponent("X Range", xBounds); - bounds.addComponent("Y Range", yBounds); - bounds.addComponent("Z Range", zBounds); - PanelBuilder builder = new PanelBuilder(); - builder.addComponent(properties.getPanel()); - builder.addComponent(statistics.getPanel()); - builder.addComponent(dataArrays.getPanel()); - builder.addComponent(bounds.getPanel()); + builder.addComponent(properties.withTitle("Properties").getPanel()); + builder.addComponent(meshInfoPanel.getStatistics(), meshInfoPanel.getCellType()); + builder.addComponent(meshInfoPanel.getDataArrays()); + builder.addComponent(meshInfoPanel.getBounds()); + return builder.removeMargins().getPanel(); } - + @Override public void start() { - super.start(); + load(); } @Override @@ -145,49 +103,7 @@ public class SolverBoundaryMeshPanel extends AbstractGUIPanel { created.setText("-"); } - if (model.getMesh() != null) { - cells.setText(formatter.format(model.getMesh().getNumberOfCells())); - points.setText(formatter.format(model.getMesh().getNumberOfPoints())); - faces.setText(formatter.format(model.getMesh().getNumberOfFaces())); - - List cellsPerRefinementLevel = model.getMesh().getCellsPerRefinementLevel(); - String text = ""; - for (int i = 0; i < cellsPerRefinementLevel.size(); i++) { - if (i > 0) - text += "\n"; - text += i + "\t" + cellsPerRefinementLevel.get(i); - } - cellsPerLevel.setText(text); - - // memory.setText(formatter.format(model.getMesh().getMemorySize()/1024D)); - - double[] bounds = model.getMesh().getBounds(); - - xBounds.setText(getTextForBounds(bounds[0], bounds[1])); - yBounds.setText(getTextForBounds(bounds[2], bounds[3])); - zBounds.setText(getTextForBounds(bounds[4], bounds[5])); - } else { - cells.setText("-"); - points.setText("-"); - faces.setText("-"); - cellsPerLevel.setText(" - "); - // memory.setText("-"); - xBounds.setText("[- , -]"); - yBounds.setText("[- , -]"); - zBounds.setText("[- , -]"); - } - } - - private String getTextForBounds(double min, double max) { - if (areValid(min, max)) { - return "[" + formatter.format(min) + " , " + formatter.format(max) + "] (Delta " + formatter.format(max - min) + ")"; - } else { - return "[0 , 0]"; - } - } - - private boolean areValid(double min, double max) { - return min < Double.MAX_VALUE && max > -Double.MAX_VALUE; + meshInfoPanel.load(model.getMesh()); } @Override diff --git a/src/eu/engys/gui/mesh/panels/StandardBaseMeshPanel.java b/src/eu/engys/gui/mesh/panels/StandardBaseMeshPanel.java index e911afd..74d3ada 100644 --- a/src/eu/engys/gui/mesh/panels/StandardBaseMeshPanel.java +++ b/src/eu/engys/gui/mesh/panels/StandardBaseMeshPanel.java @@ -1,36 +1,37 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.mesh.panels; import static eu.engys.core.project.system.BlockMeshDict.SPACING_KEY; import static eu.engys.core.project.system.SnappyHexMeshDict.AUTO_BLOCK_MESH_KEY; +import static eu.engys.core.project.system.SnappyHexMeshDict.BLOCK_DATA_KEY; import com.google.inject.Inject; import eu.engys.core.controller.Controller; +import eu.engys.core.controller.ScriptFactory; import eu.engys.core.project.Model; import eu.engys.core.project.system.BlockMeshDict; import eu.engys.core.project.system.SnappyHexMeshDict; @@ -38,8 +39,8 @@ import eu.engys.core.project.system.SnappyHexMeshDict; public class StandardBaseMeshPanel extends AbstractBaseMeshPanel { @Inject - public StandardBaseMeshPanel(Model model, Controller controller) { - super(model, controller); + public StandardBaseMeshPanel(Model model, Controller controller, ScriptFactory scriptFactory) { + super(model, controller, scriptFactory); } @Override @@ -50,6 +51,11 @@ public class StandardBaseMeshPanel extends AbstractBaseMeshPanel { } } + @Override + protected boolean shouldConsiderSpacing() { + return true; + } + @Override public void save() { super.save(); @@ -60,11 +66,8 @@ public class StandardBaseMeshPanel extends AbstractBaseMeshPanel { private void fixAutoBlockMesh() { SnappyHexMeshDict snappyDict = model.getProject().getSystemFolder().getSnappyHexMeshDict(); if (snappyDict != null) { - if (model.getGeometry().isAutoBoundingBox()) { - snappyDict.add(AUTO_BLOCK_MESH_KEY, String.valueOf(true)); - } else { - snappyDict.add(AUTO_BLOCK_MESH_KEY, String.valueOf(false)); - } + snappyDict.remove(BLOCK_DATA_KEY); + snappyDict.add(AUTO_BLOCK_MESH_KEY, model.getGeometry().isAutoBoundingBox()); } } @@ -74,7 +77,7 @@ public class StandardBaseMeshPanel extends AbstractBaseMeshPanel { if (isUserDefined() || isFromFile()) { blockMeshDict.remove(SPACING_KEY); } else if (isAutomatic()) { - blockMeshDict.add(SPACING_KEY, Double.toString(getBaseMeshSpacing())); + blockMeshDict.add(SPACING_KEY, getBaseMeshSpacing()); } } } diff --git a/src/eu/engys/gui/mesh/panels/StandardFeatureLinesPanel.java b/src/eu/engys/gui/mesh/panels/StandardFeatureLinesPanel.java index d851cd5..010ca7f 100644 --- a/src/eu/engys/gui/mesh/panels/StandardFeatureLinesPanel.java +++ b/src/eu/engys/gui/mesh/panels/StandardFeatureLinesPanel.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.mesh.panels; import com.google.inject.Inject; diff --git a/src/eu/engys/gui/mesh/panels/StandardGeometryPanel.java b/src/eu/engys/gui/mesh/panels/StandardGeometryPanel.java index f1a9d78..b293371 100644 --- a/src/eu/engys/gui/mesh/panels/StandardGeometryPanel.java +++ b/src/eu/engys/gui/mesh/panels/StandardGeometryPanel.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.mesh.panels; import static eu.engys.core.project.system.SnappyHexMeshDict.BAFFLE_KEY; @@ -33,10 +32,11 @@ import static eu.engys.core.project.system.SnappyHexMeshDict.FACE_ZONE_KEY; import static eu.engys.core.project.system.SnappyHexMeshDict.FINAL_LAYER_THICKNESS_KEY; import static eu.engys.core.project.system.SnappyHexMeshDict.GAP_LEVEL_INCREMENT_KEY; import static eu.engys.core.project.system.SnappyHexMeshDict.INTERNAL_KEY; -import static eu.engys.core.project.system.SnappyHexMeshDict.IS_CELL_ZONE; +import static eu.engys.core.project.system.SnappyHexMeshDict.IS_CELL_ZONE_KEY; import static eu.engys.core.project.system.SnappyHexMeshDict.LEVEL_KEY; import static eu.engys.core.project.system.SnappyHexMeshDict.MIN_THICKNESS_KEY; import static eu.engys.core.project.system.SnappyHexMeshDict.NONE_KEY; +import static eu.engys.core.project.system.SnappyHexMeshDict.N_SURFACE_LAYERS_KEY; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; @@ -52,7 +52,7 @@ import com.google.inject.Inject; import eu.engys.core.controller.Controller; import eu.engys.core.presentation.ActionManager; import eu.engys.core.project.Model; -import eu.engys.core.project.system.SnappyHexMeshDict; +import eu.engys.util.progress.ProgressMonitor; import eu.engys.util.ui.builder.PanelBuilder; import eu.engys.util.ui.textfields.IntegerField; import eu.engys.util.ui.textfields.StringField; @@ -62,8 +62,8 @@ public class StandardGeometryPanel extends AbstractGeometryPanel { private static final String LAYER_MIN_THICKNESS_LABEL = "Layer Min Thickness"; @Inject - public StandardGeometryPanel(Model model, Controller controller) { - super(model, controller); + public StandardGeometryPanel(Model model, Controller controller, ProgressMonitor monitor) { + super(model, controller, monitor); } @Override @@ -83,10 +83,10 @@ public class StandardGeometryPanel extends AbstractGeometryPanel { @Override protected JPanel getLayersPanel() { layersBuilder = new PanelBuilder(); - layersBuilder.addComponent(NUMBER_OF_LAYERS_LABEL, layerModel.bindIntegerPositive(SnappyHexMeshDict.N_SURFACE_LAYERS_KEY)); + layersBuilder.addComponent(NUMBER_OF_LAYERS_LABEL, layerModel.bindIntegerPositive(N_SURFACE_LAYERS_KEY)); layersBuilder.addComponent(FINAL_LAYER_THICKNESS_LABEL, layerModel.bindDouble(FINAL_LAYER_THICKNESS_KEY, (Double) null)); - layersBuilder.addComponent(LAYER_MIN_THICKNESS_LABEL, layerModel.bindDouble(MIN_THICKNESS_KEY, (Double) null)); layersBuilder.addComponent(LAYER_STRETCHING_LABEL, layerModel.bindDouble(EXPANSION_RATIO_KEY, (Double) null)); + layersBuilder.addComponent(LAYER_MIN_THICKNESS_LABEL, layerModel.bindDouble(MIN_THICKNESS_KEY, (Double) null)); return layersBuilder.getPanel(); } @@ -97,7 +97,7 @@ public class StandardGeometryPanel extends AbstractGeometryPanel { String[] TYPE_LABELS = { NONE_LABEL, INTERNAL_LABEL, BOUNDARY_LABEL, BAFFLE_LABEL }; final JComboBox zoneType = zoneModel.bindSelection(FACE_TYPE_KEY, TYPE_KEYS, TYPE_LABELS); final StringField zoneName = zoneModel.bindLabel(FACE_ZONE_KEY, true); - final JCheckBox isCellZone = zoneModel.bindBoolean(IS_CELL_ZONE); + final JCheckBox isCellZone = zoneModel.bindBoolean(IS_CELL_ZONE_KEY); final IntegerField[] zoneLevel = zoneModel.bindIntegerArray(LEVEL_KEY, 2); zonesBuilder.addComponent(TYPE_LABEL, zoneType); @@ -138,7 +138,7 @@ public class StandardGeometryPanel extends AbstractGeometryPanel { // } @Override - protected JButton[] getShapeButtons() { + public JButton[] getShapeButtons() { JButton[] buttons = new JButton[5]; JButton stlButton = new JButton(ActionManager.getInstance().get("mesh.stl")); diff --git a/src/eu/engys/gui/mesh/panels/StandardMeshAdvancedOptionsPanel.java b/src/eu/engys/gui/mesh/panels/StandardMeshAdvancedOptionsPanel.java index 4e3e063..2669f94 100644 --- a/src/eu/engys/gui/mesh/panels/StandardMeshAdvancedOptionsPanel.java +++ b/src/eu/engys/gui/mesh/panels/StandardMeshAdvancedOptionsPanel.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.mesh.panels; @@ -114,12 +113,12 @@ public class StandardMeshAdvancedOptionsPanel extends DefaultMeshAdvancedOptions protected JPanel createGeneralPanel() { PanelBuilder builder = new PanelBuilder("options.general.panel"); - builder.addComponent(CASTELLATED_MESH_LABEL, snappyHexMeshModel.bindBoolean(CASTELLATED_MESH_KEY), CASTELLATED_MESH_TOOLTIP); - builder.addComponent(SNAPPING_LABEL, snappyHexMeshModel.bindBoolean(SNAP_KEY), SNAPPING_TOOLTIP); - builder.addComponent(LAYERS_ADDITION_LABEL, snappyHexMeshModel.bindBoolean(ADD_LAYERS_KEY), LAYERS_ADDITION_TOOLTIP); + builder.addComponent(CASTELLATED_MESH_LABEL, CASTELLATED_MESH_TOOLTIP, snappyHexMeshModel.bindBoolean(CASTELLATED_MESH_KEY)); + builder.addComponent(SNAPPING_LABEL, SNAPPING_TOOLTIP, snappyHexMeshModel.bindBoolean(SNAP_KEY)); + builder.addComponent(LAYERS_ADDITION_LABEL, LAYERS_ADDITION_TOOLTIP, snappyHexMeshModel.bindBoolean(ADD_LAYERS_KEY)); - builder.addComponent(DEBUG_LABEL, snappyHexMeshModel.bindInteger(DEBUG_KEY, 0, 2), DEBUG_TOOLTIP); - builder.addComponent(MERGE_TOLERANCE_LABEL, snappyHexMeshModel.bindDouble(MERGE_TOLERANCE_KEY), MERGE_TOLERANCE_TOOLTIP); + builder.addComponent(DEBUG_LABEL, DEBUG_TOOLTIP, snappyHexMeshModel.bindInteger(DEBUG_KEY, 0, 2)); + builder.addComponent(MERGE_TOLERANCE_LABEL, MERGE_TOLERANCE_TOOLTIP, snappyHexMeshModel.bindDouble(MERGE_TOLERANCE_KEY)); return builder.getPanel(); } @@ -127,51 +126,51 @@ public class StandardMeshAdvancedOptionsPanel extends DefaultMeshAdvancedOptions @Override protected JPanel createRefinementsPanel() { PanelBuilder builder = new PanelBuilder("options.geometry.panel"); - builder.addComponent(MAX_LOCAL_CELLS_LABEL, castellatedMeshControlsModel.bindIntegerPositive(MAX_LOCAL_CELLS_KEY), MAX_LOCAL_CELLS_TOOLTIP); - builder.addComponent(MAX_GLOBAL_CELLS_LABEL, castellatedMeshControlsModel.bindIntegerPositive(MAX_GLOBAL_CELLS_KEY), MAX_GLOBAL_CELLS_TOOLTIP); - builder.addComponent(MIN_REFINEMENT_CELLS_LABEL, castellatedMeshControlsModel.bindIntegerPositive(MIN_REFINEMENT_CELLS_KEY), MIN_REFINEMENT_CELLS_TOOLTIP); - builder.addComponent(CELLS_BETWEEN_LEVELS_LABEL, castellatedMeshControlsModel.bindInteger(N_CELLS_BETWEEN_LEVELS_KEY, 1, Integer.MAX_VALUE), CELLS_BETWEEN_LEVELS_TOOLTIP); - builder.addComponent(RESOLVE_FEATURE_ANGLE_LABEL, castellatedMeshControlsModel.bindDoubleAngle_360(RESOLVE_FEATURE_ANGLE_KEY), RESOLVE_FEATURE_ANGLE_TOOLTIP); - builder.addComponent(ALLOW_FREE_STANDING_ZONE_FACES_LABEL, castellatedMeshControlsModel.bindBoolean(ALLOW_FREE_STANDING_ZONE_FACES_KEY), ALLOW_FREE_STANDING_ZONE_FACES_TOOLTIP); - builder.addComponent(PLANAR_ANGLE_LABEL, castellatedMeshControlsModel.bindDoubleAngle_360(PLANAR_ANGLE_KEY), PLANAR_ANGLE_TOOLTIP); - builder.addComponent(MAX_LOAD_UNBALANCE_LABEL, castellatedMeshControlsModel.bindDoublePositive(MAX_LOAD_UNBALANCE_KEY), MAX_LOAD_UNBALANCE_TOOLTIP); + builder.addComponent(MAX_LOCAL_CELLS_LABEL, MAX_LOCAL_CELLS_TOOLTIP, castellatedMeshControlsModel.bindIntegerPositive(MAX_LOCAL_CELLS_KEY)); + builder.addComponent(MAX_GLOBAL_CELLS_LABEL, MAX_GLOBAL_CELLS_TOOLTIP, castellatedMeshControlsModel.bindIntegerPositive(MAX_GLOBAL_CELLS_KEY)); + builder.addComponent(MIN_REFINEMENT_CELLS_LABEL, MIN_REFINEMENT_CELLS_TOOLTIP, castellatedMeshControlsModel.bindIntegerPositive(MIN_REFINEMENT_CELLS_KEY)); + builder.addComponent(CELLS_BETWEEN_LEVELS_LABEL, CELLS_BETWEEN_LEVELS_TOOLTIP, castellatedMeshControlsModel.bindInteger(N_CELLS_BETWEEN_LEVELS_KEY, 1, Integer.MAX_VALUE)); + builder.addComponent(RESOLVE_FEATURE_ANGLE_LABEL, RESOLVE_FEATURE_ANGLE_TOOLTIP, castellatedMeshControlsModel.bindDoubleAngle_360(RESOLVE_FEATURE_ANGLE_KEY)); + builder.addComponent(ALLOW_FREE_STANDING_ZONE_FACES_LABEL, ALLOW_FREE_STANDING_ZONE_FACES_TOOLTIP, castellatedMeshControlsModel.bindBoolean(ALLOW_FREE_STANDING_ZONE_FACES_KEY)); + builder.addComponent(PLANAR_ANGLE_LABEL, PLANAR_ANGLE_TOOLTIP, castellatedMeshControlsModel.bindDoubleAngle_360(PLANAR_ANGLE_KEY)); + builder.addComponent(MAX_LOAD_UNBALANCE_LABEL, MAX_LOAD_UNBALANCE_TOOLTIP, castellatedMeshControlsModel.bindDoublePositive(MAX_LOAD_UNBALANCE_KEY)); return builder.getPanel(); } @Override protected JPanel createLayersPanel() { PanelBuilder builder = new PanelBuilder("options.layers.panel"); - builder.addComponent(EXPANSION_RATIO_LABEL, layersControlsModel.bindDouble(EXPANSION_RATIO_KEY), EXPANSION_RATIO_TOOLTIP); - builder.addComponent(FINAL_LAYER_THICKNESS_LABEL, layersControlsModel.bindDouble(FINAL_LAYER_THICKNESS_KEY), FINAL_LAYER_THICKNESS_TOOLTIP); + builder.addComponent(EXPANSION_RATIO_LABEL, EXPANSION_RATIO_TOOLTIP, layersControlsModel.bindDouble(EXPANSION_RATIO_KEY)); + builder.addComponent(FINAL_LAYER_THICKNESS_LABEL, FINAL_LAYER_THICKNESS_TOOLTIP, layersControlsModel.bindDouble(FINAL_LAYER_THICKNESS_KEY)); // builder.addComponent(RELATIVE_SIZES_LABEL, layersControlsModel.bindBoolean(RELATIVE_SIZES_KEY), RELATIVE_SIZES_TOOLTIP); - builder.addComponent(MIN_THICKNESS_LABEL, layersControlsModel.bindDouble(MIN_THICKNESS_KEY), MIN_THICKNESS_TOOLTIP); - builder.addComponent(FEATURE_ANGLE_LABEL, layersControlsModel.bindDoubleAngle_360(FEATURE_ANGLE_KEY), FEATURE_ANGLE_TOOLTIP); - builder.addComponent(SLIP_FEATURE_ANGLE_LABEL, layersControlsModel.bindDoubleAngle_360(SLIP_FEATURE_ANGLE_KEY), SLIP_FEATURE_ANGLE_TOOLTIP); - builder.addComponent(RELAX_ITERATIONS_LAYERS_LABEL, layersControlsModel.bindIntegerPositive(N_RELAX_ITER_LAYERS_KEY), RELAX_ITERATIONS_LAYERS_TOOLTIP); - builder.addComponent(RELAXED_ITERATIONS_LABEL, layersControlsModel.bindIntegerPositive(N_RELAXED_ITER_KEY), RELAXED_ITERATIONS_TOOLTIP); - builder.addComponent(SURFACE_NORMALS_SMOOTHING_ITERATIONS_LABEL, layersControlsModel.bindIntegerPositive(N_SMOOTH_SURFACE_NORMALS_KEY), SURFACE_NORMALS_SMOOTHING_ITERATIONS_TOOLTIP); - builder.addComponent(INTERIOR_MESH_SMOOTHING_ITERATIONS_LABEL, layersControlsModel.bindIntegerPositive(N_SMOOTH_NORMALS_KEY), INTERIOR_MESH_SMOOTHING_ITERATIONS_TOOLTIP); - builder.addComponent(SMOOTH_LAYER_THICKNESS_LABEL, layersControlsModel.bindIntegerPositive(N_SMOOTH_THICKNESS_KEY), SMOOTH_LAYER_THICKNESS_TOOLTIP); - builder.addComponent(MAX_FACE_THICKNESS_RATIO_LABEL, layersControlsModel.bindDouble(MAX_FACE_THICKNESS_RATIO_KEY), MAX_FACE_THICKNESS_RATIO_TOOLTIP); - builder.addComponent(MAX_THICKNESS_TO_MEDIAL_RATIO_LABEL, layersControlsModel.bindDouble(MAX_THICKNESS_TO_MEDIAL_RATIO_KEY), MAX_THICKNESS_TO_MEDIAL_RATIO_TOOLTIP); - builder.addComponent(MIN_MEDIAL_AXIS_ANGLE_LABEL, layersControlsModel.bindIntegerAngle_360(MIN_MEDIAL_AXIS_ANGLE_KEY), MIN_MEDIAL_AXIS_ANGLE_TOOLTIP); - builder.addComponent(NUMBER_OF_BUFFER_CELLS_LABEL, layersControlsModel.bindIntegerPositive(N_BUFFER_CELLS_NO_EXTRUDE_KEY), NUMBER_OF_BUFFER_CELLS_TOOLTIP); - builder.addComponent(LAYER_ADDITION_ITERATIONS_LABEL, layersControlsModel.bindIntegerPositive(N_LAYER_ITER_KEY), LAYER_ADDITION_ITERATIONS_TOOLTIP); - builder.addComponent(NUMBER_OF_LAYERS_NOT_GROWN_LABEL, layersControlsModel.bindIntegerPositive(N_GROW_KEY), NUMBER_OF_LAYERS_NOT_GROWN_TOOLTIP); + builder.addComponent(MIN_THICKNESS_LABEL, MIN_THICKNESS_TOOLTIP, layersControlsModel.bindDouble(MIN_THICKNESS_KEY)); + builder.addComponent(FEATURE_ANGLE_LABEL, FEATURE_ANGLE_TOOLTIP, layersControlsModel.bindDoubleAngle_360(FEATURE_ANGLE_KEY)); + builder.addComponent(SLIP_FEATURE_ANGLE_LABEL, SLIP_FEATURE_ANGLE_TOOLTIP, layersControlsModel.bindDoubleAngle_360(SLIP_FEATURE_ANGLE_KEY)); + builder.addComponent(RELAX_ITERATIONS_LAYERS_LABEL, RELAX_ITERATIONS_LAYERS_TOOLTIP, layersControlsModel.bindIntegerPositive(N_RELAX_ITER_LAYERS_KEY)); + builder.addComponent(RELAXED_ITERATIONS_LABEL, RELAXED_ITERATIONS_TOOLTIP, layersControlsModel.bindIntegerPositive(N_RELAXED_ITER_KEY)); + builder.addComponent(SURFACE_NORMALS_SMOOTHING_ITERATIONS_LABEL, SURFACE_NORMALS_SMOOTHING_ITERATIONS_TOOLTIP, layersControlsModel.bindIntegerPositive(N_SMOOTH_SURFACE_NORMALS_KEY)); + builder.addComponent(INTERIOR_MESH_SMOOTHING_ITERATIONS_LABEL, INTERIOR_MESH_SMOOTHING_ITERATIONS_TOOLTIP, layersControlsModel.bindIntegerPositive(N_SMOOTH_NORMALS_KEY)); + builder.addComponent(SMOOTH_LAYER_THICKNESS_LABEL, SMOOTH_LAYER_THICKNESS_TOOLTIP, layersControlsModel.bindIntegerPositive(N_SMOOTH_THICKNESS_KEY)); + builder.addComponent(MAX_FACE_THICKNESS_RATIO_LABEL, MAX_FACE_THICKNESS_RATIO_TOOLTIP, layersControlsModel.bindDouble(MAX_FACE_THICKNESS_RATIO_KEY)); + builder.addComponent(MAX_THICKNESS_TO_MEDIAL_RATIO_LABEL, MAX_THICKNESS_TO_MEDIAL_RATIO_TOOLTIP, layersControlsModel.bindDouble(MAX_THICKNESS_TO_MEDIAL_RATIO_KEY)); + builder.addComponent(MIN_MEDIAL_AXIS_ANGLE_LABEL, MIN_MEDIAL_AXIS_ANGLE_TOOLTIP, layersControlsModel.bindIntegerAngle_360(MIN_MEDIAL_AXIS_ANGLE_KEY)); + builder.addComponent(NUMBER_OF_BUFFER_CELLS_LABEL, NUMBER_OF_BUFFER_CELLS_TOOLTIP, layersControlsModel.bindIntegerPositive(N_BUFFER_CELLS_NO_EXTRUDE_KEY)); + builder.addComponent(LAYER_ADDITION_ITERATIONS_LABEL, LAYER_ADDITION_ITERATIONS_TOOLTIP, layersControlsModel.bindIntegerPositive(N_LAYER_ITER_KEY)); + builder.addComponent(NUMBER_OF_LAYERS_NOT_GROWN_LABEL, NUMBER_OF_LAYERS_NOT_GROWN_TOOLTIP, layersControlsModel.bindIntegerPositive(N_GROW_KEY)); return builder.getPanel(); } @Override protected JPanel createSnappingPanel() { PanelBuilder builder = new PanelBuilder("options.snapping.panel"); - builder.addComponent(SOLVER_ITERATIONS_LABEL, snapControlsModel.bindIntegerPositive(N_SOLVER_ITER_KEY), SOLVER_ITERATIONS_TOOLTIP); - builder.addComponent(SMOOTH_PATCH_LABEL, snapControlsModel.bindIntegerPositive(N_SMOOTH_PATCH_KEY), SMOOTH_PATCH_TOOLTIP); - builder.addComponent(TOLERANCE_LABEL, snapControlsModel.bindDoublePositive(TOLERANCE_KEY), TOLERANCE_TOOLTIP); - builder.addComponent(RELAX_ITERATIONS_SNAP_LABEL, snapControlsModel.bindIntegerPositive(N_RELAX_ITER_SNAP_KEY), RELAX_ITERATIONS_SNAP_TOOLTIP); - builder.addComponent(SNAP_FEATURE_ITERATIONS_LABEL, snapControlsModel.bindIntegerPositive(N_FEATURE_SNAP_ITER_KEY), SNAP_FEATURE_ITERATIONS_TOOLTIP); - builder.addComponent(IMPLICIT_SNAP_FEATURE_LABEL, snapControlsModel.bindBoolean(IMPLICIT_FEATURE_SNAP_KEY), IMPLICIT_SNAP_FEATURE_TOOLTIP); - builder.addComponent(EXPLICIT_SNAP_FEATURE_LABEL, snapControlsModel.bindBoolean(EXPLICIT_FEATURE_SNAP_KEY), EXPLICIT_SNAP_FEATURE_TOOLTIP); - builder.addComponent(MULTI_REGION_FEATURE_LABEL, snapControlsModel.bindBoolean(MULTI_REGION_FEATURE_SNAP_KEY), MULTI_REGION_FEATURE_TOOLTIP); + builder.addComponent(SOLVER_ITERATIONS_LABEL, SOLVER_ITERATIONS_TOOLTIP, snapControlsModel.bindIntegerPositive(N_SOLVER_ITER_KEY)); + builder.addComponent(SMOOTH_PATCH_LABEL, SMOOTH_PATCH_TOOLTIP, snapControlsModel.bindIntegerPositive(N_SMOOTH_PATCH_KEY)); + builder.addComponent(TOLERANCE_LABEL, TOLERANCE_TOOLTIP, snapControlsModel.bindDoublePositive(TOLERANCE_KEY)); + builder.addComponent(RELAX_ITERATIONS_SNAP_LABEL, RELAX_ITERATIONS_SNAP_TOOLTIP, snapControlsModel.bindIntegerPositive(N_RELAX_ITER_SNAP_KEY)); + builder.addComponent(SNAP_FEATURE_ITERATIONS_LABEL, SNAP_FEATURE_ITERATIONS_TOOLTIP, snapControlsModel.bindIntegerPositive(N_FEATURE_SNAP_ITER_KEY)); + builder.addComponent(IMPLICIT_SNAP_FEATURE_LABEL, IMPLICIT_SNAP_FEATURE_TOOLTIP, snapControlsModel.bindBoolean(IMPLICIT_FEATURE_SNAP_KEY)); + builder.addComponent(EXPLICIT_SNAP_FEATURE_LABEL, EXPLICIT_SNAP_FEATURE_TOOLTIP, snapControlsModel.bindBoolean(EXPLICIT_FEATURE_SNAP_KEY)); + builder.addComponent(MULTI_REGION_FEATURE_LABEL, MULTI_REGION_FEATURE_TOOLTIP, snapControlsModel.bindBoolean(MULTI_REGION_FEATURE_SNAP_KEY)); return builder.getPanel(); } diff --git a/src/eu/engys/gui/mesh/panels/SurfacesSaver.java b/src/eu/engys/gui/mesh/panels/SurfacesSaver.java new file mode 100644 index 0000000..2ba318c --- /dev/null +++ b/src/eu/engys/gui/mesh/panels/SurfacesSaver.java @@ -0,0 +1,177 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ + +package eu.engys.gui.mesh.panels; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import eu.engys.core.dictionary.Dictionary; +import eu.engys.core.project.geometry.Surface; +import eu.engys.util.Util; +import eu.engys.util.ui.TreeUtil; + +public class SurfacesSaver { + + private static final Logger logger = LoggerFactory.getLogger(SurfacesSaver.class); + + private boolean changeSurface; + private boolean changeVolume; + private boolean changeLayer; + private boolean changeZone; + + private boolean changeGeometry; + + public void saveSurfaces(Surface delegate, Surface... surfaces) { + if (Util.isVarArgsNotNull(surfaces)) { + if (TreeUtil.isConsistent(surfaces, delegate.getClass())) { + _saveSurfaces(delegate, surfaces); + } else { + logger.warn("Inconsistent selection"); + } + } + } + + private void _saveSurfaces(Surface delegate, Surface... surfaces) { + Dictionary surfaceDict = delegate.getSurfaceDictionary(); + Dictionary volumeDict = delegate.getVolumeDictionary(); + Dictionary layerDict = delegate.getLayerDictionary(); + Dictionary zoneDict = delegate.getZoneDictionary(); + + changeGeometry = surfaces.length == 1; + changeSurface = !surfaces[0].getSurfaceDictionary().equals(surfaceDict); + changeVolume = !surfaces[0].getVolumeDictionary().equals(volumeDict); + changeLayer = !surfaces[0].getLayerDictionary().equals(layerDict); + changeZone = !surfaces[0].getZoneDictionary().equals(zoneDict); + + for (Surface surface : surfaces) { +// if (changeGeometry) surface.buildGeometryDictionary(geometriesPanel.getBoxDictionary()); +// if (changeSurface) surface.buildSurfaceDictionary(surfaceDict); +// if (changeVolume) surface.buildVolumeDictionary(volumeDict); +// if (changeLayer) surface.buildLayerDictionary(layerDict); +// if (changeZone) surface.buildZoneDictionary(zoneDict); + surface.copyFrom(delegate, changeGeometry, changeSurface, changeVolume, changeLayer, changeZone); + //System.err.println("SurfacesSaver._saveSurfaces() " + surface); + } + +// switch (delegate.getType()) { +// case BOX: +// buildBox(surfaces); +// break; +// case CYLINDER: +// buildCylinder(surfaces); +// break; +// case SPHERE: +// buildSphere(surfaces); +// break; +// case RING: +// buildRing(surfaces); +// break; +// case PLANE: +// buildPlane(surfaces); +// break; +// case STL: +// buildSTL(surfaces); +// break; +// case REGION: +// case SOLID: +// buildRegion(surfaces); +// break; +// +// default: +// break; +// } + } + +// private void buildBox(Surface... surfaces) { +// for (Surface surface : surfaces) { +// if (changeGeometry) surface.buildGeometryDictionary(geometriesPanel.getBoxDictionary()); +// if (changeSurface) surface.buildSurfaceDictionary(surfaceDict); +// if (changeVolume) surface.buildVolumeDictionary(volumeDict); +// if (changeLayer) surface.buildLayerDictionary(layerDict); +// if (changeZone) surface.buildZoneDictionary(zoneDict); +// } +// } +// +// private void buildSTL(Surface... surfaces) { +// for (Surface surface : surfaces) { +// if (changeGeometry) +// surface.buildGeometryDictionary(geometriesPanel.getSTLDictionary()); +// if (changeSurface) surface.buildSurfaceDictionary(surfaceDict); +// if (changeVolume) surface.buildVolumeDictionary(volumeDict); +// if (changeLayer) surface.buildLayerDictionary(layerDict); +// if (changeZone) surface.buildZoneDictionary(zoneDict); +// } +// } +// +// private void buildRegion(Surface... surfaces) { +// for (Surface surface : surfaces) { +// if (changeSurface) surface.buildSurfaceDictionary(surfaceDict); +// if (changeVolume) surface.buildVolumeDictionary(volumeDict); +// if (changeLayer) surface.buildLayerDictionary(layerDict); +//// if (changeZone) surface.buildZoneDictionary(zoneModel.getDictionary()); +// } +// } +// +// private void buildCylinder(Surface... surfaces) { +// for (Surface surface : surfaces) { +// if (changeGeometry) surface.buildGeometryDictionary(geometriesPanel.getCylinderDictionary()); +// if (changeSurface) surface.buildSurfaceDictionary(surfaceDict); +// if (changeVolume) surface.buildVolumeDictionary(volumeDict); +// if (changeLayer) surface.buildLayerDictionary(layerDict); +// if (changeZone) surface.buildZoneDictionary(zoneDict); +// } +// } +// +// private void buildSphere(Surface... surfaces) { +// for (Surface surface : surfaces) { +// if (changeGeometry) surface.buildGeometryDictionary(geometriesPanel.getSphereDictionary()); +// if (changeSurface) surface.buildSurfaceDictionary(surfaceDict); +// if (changeVolume) surface.buildVolumeDictionary(volumeDict); +// if (changeLayer) surface.buildLayerDictionary(layerDict); +// if (changeZone) surface.buildZoneDictionary(zoneDict); +// } +// } +// +// private void buildRing(Surface... surfaces) { +// for (Surface surface : surfaces) { +// if (changeGeometry) surface.buildGeometryDictionary(geometriesPanel.getRingDictionary()); +// if (changeSurface) surface.buildSurfaceDictionary(surfaceDict); +// if (changeVolume) surface.buildVolumeDictionary(volumeDict); +// if (changeLayer) surface.buildLayerDictionary(layerDict); +// if (changeZone) surface.buildZoneDictionary(zoneDict); +// } +// } +// +// private void buildPlane(Surface... surfaces) { +// for (Surface surface : surfaces) { +// if (changeGeometry) surface.buildGeometryDictionary(geometriesPanel.getPlaneDictionary()); +// if (changeSurface) surface.buildSurfaceDictionary(surfaceDict); +// if (changeVolume) surface.buildVolumeDictionary(volumeDict); +// if (changeLayer) surface.buildLayerDictionary(layerDict); +// if (changeZone) surface.buildZoneDictionary(zoneDict); +// } +// } +} diff --git a/src/eu/engys/gui/mesh/panels/lines/AutomaticBaseMeshPanel.java b/src/eu/engys/gui/mesh/panels/lines/AutomaticBaseMeshPanel.java index b93b5d2..b1f25ef 100644 --- a/src/eu/engys/gui/mesh/panels/lines/AutomaticBaseMeshPanel.java +++ b/src/eu/engys/gui/mesh/panels/lines/AutomaticBaseMeshPanel.java @@ -1,50 +1,51 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.mesh.panels.lines; import static eu.engys.util.ui.ComponentsFactory.doubleField; -import eu.engys.core.dictionary.model.DictionaryPanelBuilder; + import eu.engys.core.project.Model; import eu.engys.core.project.geometry.Geometry; import eu.engys.gui.events.EventManager; import eu.engys.gui.events.view3D.RemoveSurfaceEvent; +import eu.engys.util.Symbols; +import eu.engys.util.bean.BeanPanelBuilder; import eu.engys.util.ui.textfields.DoubleField; public class AutomaticBaseMeshPanel { public static final String AUTOMATIC_LABEL = "Automatic"; - public static final String BASE_MESHSPACING_LABEL = "Base Mesh Spacing"; + public static final String BASE_MESHSPACING_LABEL = "Base Mesh Spacing " + Symbols.M; - private DictionaryPanelBuilder builder; + private BeanPanelBuilder builder; protected DoubleField meshSpacing; private Model model; - public AutomaticBaseMeshPanel(Model model, DictionaryPanelBuilder builder) { + public AutomaticBaseMeshPanel(Model model, BeanPanelBuilder builder) { this.model = model; this.builder = builder; @@ -58,11 +59,11 @@ public class AutomaticBaseMeshPanel { builder.addComponent(BASE_MESHSPACING_LABEL, meshSpacing); } - public void save() { + public void save(double spacing, boolean shouldConsiderSpacing) { model.getProject().getSystemFolder().getBlockMeshDict().setFromFile(false); model.getGeometry().setAutoBoundingBox(true); model.getGeometry().setCellSize(new double[] { meshSpacing.getDoubleValue(), meshSpacing.getDoubleValue(), meshSpacing.getDoubleValue() }); - model.getGeometry().saveAutoBlock(model); + model.getGeometry().saveAutoBlock(model, spacing, shouldConsiderSpacing); } public void updateBlock() { diff --git a/src/eu/engys/gui/mesh/panels/lines/BoundingBoxFacesPanel.java b/src/eu/engys/gui/mesh/panels/lines/BoundingBoxFacesPanel.java index 32d3770..a1c596e 100644 --- a/src/eu/engys/gui/mesh/panels/lines/BoundingBoxFacesPanel.java +++ b/src/eu/engys/gui/mesh/panels/lines/BoundingBoxFacesPanel.java @@ -1,34 +1,32 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.mesh.panels.lines; import static eu.engys.core.project.system.SnappyHexMeshDict.EXPANSION_RATIO_KEY; -import static eu.engys.core.project.system.SnappyHexMeshDict.FCH_KEY; import static eu.engys.core.project.system.SnappyHexMeshDict.FINAL_LAYER_THICKNESS_KEY; -import static eu.engys.core.project.system.SnappyHexMeshDict.MAX_LAYER_THICKNESS_KEY; +import static eu.engys.core.project.system.SnappyHexMeshDict.MIN_THICKNESS_KEY; import static eu.engys.core.project.system.SnappyHexMeshDict.N_SURFACE_LAYERS_KEY; import static eu.engys.util.ui.ComponentsFactory.stringField; @@ -47,10 +45,9 @@ import eu.engys.util.ui.textfields.StringField; public class BoundingBoxFacesPanel { public static final String NUMBER_OF_LAYERS_LABEL = "Number of Layers"; - public static final String FIRST_CELL_HEIGHT_LABEL = "First Cell Height"; public static final String LAYER_STRETCHING_LABEL = "Layer Stretching"; public static final String FINAL_LAYER_THICKNESS_LABEL = "Final Layer Thickness"; - public static final String TOTAL_LAYER_THICKNESS_LABEL = "Total Layer Thickness"; + private static final String LAYER_MIN_THICKNESS_LABEL = "Layer Min Thickness"; public static final String FACE_NAME_LABEL = "Face Name"; public static final String BOUNDING_BOX_FACES_LABEL = "Bounding Box Faces"; @@ -73,10 +70,9 @@ public class BoundingBoxFacesPanel { planeBuilder = new DictionaryPanelBuilder(); planeBuilder.addComponent(FACE_NAME_LABEL, planeName = stringField()); planeBuilder.addComponent(NUMBER_OF_LAYERS_LABEL, planeModel.bindIntegerPositive(N_SURFACE_LAYERS_KEY)); - planeBuilder.addComponent(TOTAL_LAYER_THICKNESS_LABEL, planeModel.bindDouble(MAX_LAYER_THICKNESS_KEY, (Double) null)); planeBuilder.addComponent(FINAL_LAYER_THICKNESS_LABEL, planeModel.bindDouble(FINAL_LAYER_THICKNESS_KEY, (Double) null)); planeBuilder.addComponent(LAYER_STRETCHING_LABEL, planeModel.bindDouble(EXPANSION_RATIO_KEY, (Double) null)); - planeBuilder.addComponent(FIRST_CELL_HEIGHT_LABEL, planeModel.bindDouble(FCH_KEY, (Double) null)); + planeBuilder.addComponent(LAYER_MIN_THICKNESS_LABEL, planeModel.bindDouble(MIN_THICKNESS_KEY, (Double) null)); planeBuilder.setEnabled(false); } @@ -120,11 +116,11 @@ public class BoundingBoxFacesPanel { return planeName.getText(); } - public void addNameListener() { + private void addNameListener() { planeName.addPropertyChangeListener(listener); } - public void removeNameListener() { + private void removeNameListener() { planeName.removePropertyChangeListener(listener); } diff --git a/src/eu/engys/gui/mesh/panels/lines/ColorFeatureLineAction.java b/src/eu/engys/gui/mesh/panels/lines/ColorFeatureLineAction.java index fef37d4..624bcaa 100644 --- a/src/eu/engys/gui/mesh/panels/lines/ColorFeatureLineAction.java +++ b/src/eu/engys/gui/mesh/panels/lines/ColorFeatureLineAction.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.mesh.panels.lines; import java.awt.Color; @@ -53,7 +52,7 @@ public class ColorFeatureLineAction extends AbstractAction { @Override public void actionPerformed(ActionEvent e) { - this.currentColor = JColorChooser.showDialog(SwingUtilities.getWindowAncestor(linesPanel), "Select a color", currentColor); + this.currentColor = JColorChooser.showDialog(SwingUtilities.getWindowAncestor(linesPanel), "", currentColor); changeColor(currentColor, (JButton) e.getSource()); } diff --git a/src/eu/engys/gui/mesh/panels/lines/FeatureLinesRefinementTable.java b/src/eu/engys/gui/mesh/panels/lines/FeatureLinesRefinementTable.java index 22fee06..9d67ca8 100644 --- a/src/eu/engys/gui/mesh/panels/lines/FeatureLinesRefinementTable.java +++ b/src/eu/engys/gui/mesh/panels/lines/FeatureLinesRefinementTable.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.mesh.panels.lines; import java.awt.BorderLayout; diff --git a/src/eu/engys/gui/mesh/panels/lines/FromFileBaseMeshPanel.java b/src/eu/engys/gui/mesh/panels/lines/FromFileBaseMeshPanel.java index 8e318ba..a3705b6 100644 --- a/src/eu/engys/gui/mesh/panels/lines/FromFileBaseMeshPanel.java +++ b/src/eu/engys/gui/mesh/panels/lines/FromFileBaseMeshPanel.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.mesh.panels.lines; import java.awt.HeadlessException; @@ -40,17 +39,18 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import eu.engys.core.controller.Controller; -import eu.engys.core.dictionary.FileEditor; -import eu.engys.core.dictionary.model.DictionaryPanelBuilder; +import eu.engys.core.controller.ScriptFactory; import eu.engys.core.project.Model; import eu.engys.core.project.geometry.Geometry; import eu.engys.core.project.system.BlockMeshDict; +import eu.engys.gui.FileEditor; import eu.engys.gui.events.EventManager; import eu.engys.gui.events.view3D.RemoveSurfaceEvent; import eu.engys.gui.mesh.actions.RunBlockMeshAction; -import eu.engys.util.LineSeparator; +import eu.engys.util.IOUtils; import eu.engys.util.PrefUtil; import eu.engys.util.Util; +import eu.engys.util.bean.BeanPanelBuilder; import eu.engys.util.filechooser.HelyxFileChooser; import eu.engys.util.filechooser.util.HelyxFileFilter; import eu.engys.util.filechooser.util.SelectionMode; @@ -63,19 +63,22 @@ public class FromFileBaseMeshPanel { public static final HelyxFileFilter BLOCKMESHDICT_FILE_FILTER = new HelyxFileFilter("Block Mesh Dictionary", BlockMeshDict.BLOCK_DICT); public static final String FROM_FILE_LABEL = "From File"; - + public static final String EDIT_LABEL = "Edit"; public static final String IMPORT_LABEL = "Import"; public static final String CREATE_LABEL = "Create"; private Model model; private Controller controller; - private DictionaryPanelBuilder builder; + private BeanPanelBuilder builder; private JButton editButton, previewButton, importButton; - public FromFileBaseMeshPanel(Model model, Controller controller, DictionaryPanelBuilder builder) { + private ScriptFactory scriptFactory; + + public FromFileBaseMeshPanel(Model model, Controller controller, ScriptFactory scriptFactory, BeanPanelBuilder builder) { this.model = model; this.controller = controller; + this.scriptFactory = scriptFactory; this.builder = builder; builder.startGroup(FROM_FILE_LABEL); layoutComponents(); @@ -83,7 +86,7 @@ public class FromFileBaseMeshPanel { } private void layoutComponents() { - previewButton = new JButton(new RunBlockMeshAction(model, controller)); + previewButton = new JButton(new RunBlockMeshAction(model, controller, scriptFactory)); previewButton.setName(CREATE_LABEL); editButton = new JButton(new AbstractAction(EDIT_LABEL, ResourcesUtil.getIcon("mesh.create.edit.icon")) { @@ -109,13 +112,13 @@ public class FromFileBaseMeshPanel { builder.addSeparator(""); builder.addComponent(importButton, editButton, previewButton); } - - public void save(){ + + public void save() { model.getProject().getSystemFolder().getBlockMeshDict().setFromFile(true); model.getGeometry().setAutoBoundingBox(false); } - - public void updateBlock(){ + + public void updateBlock() { if (model.getGeometry().hasBlock()) { EventManager.triggerEvent(this, new RemoveSurfaceEvent(model.getGeometry().getBlock())); model.getGeometry().setBlock(Geometry.FAKE_BLOCK); @@ -153,7 +156,7 @@ public class FromFileBaseMeshPanel { File currentBlockMeshDict = new File(model.getProject().getSystemFolder().getFileManager().getFile(), BlockMeshDict.BLOCK_DICT); newBlockMeshDictContent.add(BlockMeshDict.FROM_FILE_LINE); - String lineEnding = Util.isWindowsScriptStyle() ? LineSeparator.DOS.getSeparator() : LineSeparator.UNIX.getSeparator(); + String lineEnding = Util.isWindowsScriptStyle() ? IOUtils.WIN_EOL : IOUtils.LNX_EOL; FileUtils.writeLines(currentBlockMeshDict, null, newBlockMeshDictContent, lineEnding); showEditor(); @@ -178,7 +181,7 @@ public class FromFileBaseMeshPanel { editButton.setEnabled(true); previewButton.setEnabled(true); try { - String lineEnding = Util.isWindowsScriptStyle() ? LineSeparator.DOS.getSeparator() : LineSeparator.UNIX.getSeparator(); + String lineEnding = Util.isWindowsScriptStyle() ? IOUtils.WIN_EOL : IOUtils.LNX_EOL; FileUtils.writeLines(blockMeshDictFile, null, lines, lineEnding); } catch (IOException e) { logger.error("Error saving blockMeshDict" + e.getMessage()); diff --git a/src/eu/engys/gui/mesh/panels/lines/ImportFeatureLineAction.java b/src/eu/engys/gui/mesh/panels/lines/ImportFeatureLineAction.java index 6fa7158..3772fc8 100644 --- a/src/eu/engys/gui/mesh/panels/lines/ImportFeatureLineAction.java +++ b/src/eu/engys/gui/mesh/panels/lines/ImportFeatureLineAction.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.mesh.panels.lines; import java.awt.Color; diff --git a/src/eu/engys/gui/mesh/panels/lines/UserDefinedBaseMeshPanel.java b/src/eu/engys/gui/mesh/panels/lines/UserDefinedBaseMeshPanel.java index a0544b1..66c5afa 100644 --- a/src/eu/engys/gui/mesh/panels/lines/UserDefinedBaseMeshPanel.java +++ b/src/eu/engys/gui/mesh/panels/lines/UserDefinedBaseMeshPanel.java @@ -1,33 +1,32 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.mesh.panels.lines; +import static eu.engys.core.project.geometry.Surface.ELEMENTS_KEY; import static eu.engys.core.project.geometry.Surface.MAX_KEY; import static eu.engys.core.project.geometry.Surface.MIN_KEY; -import static eu.engys.core.project.system.BlockMeshDict.ELEMENTS_KEY; import static eu.engys.util.ui.ComponentsFactory.doublePointField; import static eu.engys.util.ui.ComponentsFactory.labelField; @@ -37,12 +36,9 @@ import java.awt.event.ActionEvent; import javax.swing.AbstractAction; import javax.swing.Icon; import javax.swing.JButton; +import javax.swing.JComponent; import javax.swing.JToggleButton; -import eu.engys.core.dictionary.Dictionary; -import eu.engys.core.dictionary.FieldChangeListener; -import eu.engys.core.dictionary.model.DictionaryModel; -import eu.engys.core.dictionary.model.DictionaryPanelBuilder; import eu.engys.core.project.Model; import eu.engys.core.project.geometry.BoundingBox; import eu.engys.core.project.geometry.surface.MultiPlane; @@ -50,6 +46,10 @@ import eu.engys.core.project.system.SystemFolder; import eu.engys.gui.events.EventManager; import eu.engys.gui.events.view3D.ChangeSurfaceEvent; import eu.engys.gui.view3D.BoxEventButton; +import eu.engys.util.Symbols; +import eu.engys.util.bean.BeanModel; +import eu.engys.util.bean.BeanPanelBuilder; +import eu.engys.util.ui.FieldChangeListener; import eu.engys.util.ui.ResourcesUtil; import eu.engys.util.ui.textfields.DoubleField; import eu.engys.util.ui.textfields.IntegerField; @@ -58,14 +58,14 @@ public class UserDefinedBaseMeshPanel { public static final String USER_DEFINED_LABEL = "User Defined"; - public static final String CELL_SIZE_LABEL = "Cell Size [m]"; + public static final String MIN_LABEL = "Min " + Symbols.M; + public static final String MAX_LABEL = "Max " + Symbols.M; public static final String N_ELEMENTS_LABEL = "Elements"; - public static final String MAX_LABEL = "Max"; - public static final String MIN_LABEL = "Min"; + public static final String CELL_SIZE_LABEL = "Cell Size " + Symbols.M; private final static Icon FIT_ICON = ResourcesUtil.getIcon("fit.boundingbox.icon"); - private DictionaryPanelBuilder builder; + private BeanPanelBuilder builder; private DoubleField[] boxMin; private DoubleField[] boxMax; @@ -74,34 +74,40 @@ public class UserDefinedBaseMeshPanel { private Model model; - private DictionaryModel minMaxModel; +// private DictionaryModel minMaxModel; + private BeanModel minMaxModel; private UpdateBlockListener blockListener; + private JButton fitButton; - public UserDefinedBaseMeshPanel(Model model, DictionaryPanelBuilder builder) { + public UserDefinedBaseMeshPanel(Model model, BeanPanelBuilder builder) { this.model = model; this.builder = builder; - minMaxModel = new DictionaryModel(new Dictionary(defaultBoxModelDict)); - builder.startDictionary(USER_DEFINED_LABEL, minMaxModel); + minMaxModel = new BeanModel<>(new MultiPlane("BoundingBox")); + builder.startBean(USER_DEFINED_LABEL, minMaxModel); layoutComponents(); - builder.endDictionary(); + builder.endBean(); } private void layoutComponents() { blockListener = new UpdateBlockListener(); - boxMin = minMaxModel.bindPoint(MIN_KEY, 4, blockListener); - boxMax = minMaxModel.bindPoint(MAX_KEY, 4, blockListener); + boxMin = minMaxModel.bindPoint(MIN_KEY, 4); + boxMax = minMaxModel.bindPoint(MAX_KEY, 4); + showBoxButton = new BoxEventButton(boxMin, boxMax); builder.addComponent("", labelField("X"), labelField("Y"), labelField("Z")); builder.addComponent(MIN_LABEL, boxMin[0], boxMin[1], boxMin[2], showBoxButton); builder.addComponentAndSpan(MAX_LABEL, boxMax); - IntegerField[] elements = minMaxModel.bindIntegerArray(ELEMENTS_KEY, 3, blockListener); - JButton fitButton = new JButton(new FitBoundingBoxAction()); + elements = minMaxModel.bindIntegerArray(ELEMENTS_KEY, 3); + fitButton = new JButton(new FitBoundingBoxAction()); fitButton.setPreferredSize(new Dimension(36, 48)); - + fitButton.setEnabled(false); + + addBlockListener(); + builder.addComponent(N_ELEMENTS_LABEL, elements[0], elements[1], elements[2], fitButton); cellSize = doublePointField(3); cellSize[0].setEnabled(false); @@ -114,7 +120,7 @@ public class UserDefinedBaseMeshPanel { blockListener.setAdjusting(true); MultiPlane block = model.getGeometry().getBlock(); - minMaxModel.setDictionary(block.getGeometryDictionary()); + minMaxModel.setBean(block); updateDelta(); blockListener.setAdjusting(false); @@ -124,10 +130,11 @@ public class UserDefinedBaseMeshPanel { model.getProject().getSystemFolder().getBlockMeshDict().setFromFile(false); model.getGeometry().setAutoBoundingBox(false); model.getGeometry().setCellSize(new double[] { cellSize[0].getDoubleValue(), cellSize[1].getDoubleValue(), cellSize[2].getDoubleValue() }); - model.getGeometry().saveUserDefinedBlock(model, minMaxModel.getDictionary()); + model.getGeometry().saveUserDefinedBlock(model, minMaxModel.getBean()); } public void updateBlock() { + blockListener.setAdjusting(true); if (model.getGeometry().hasBlock()) { editBlock(); } else { @@ -135,20 +142,20 @@ public class UserDefinedBaseMeshPanel { } updateDelta(); save(); + blockListener.setAdjusting(false); } private void editBlock() { MultiPlane block = model.getGeometry().getBlock(); - block.setGeometryDictionary(minMaxModel.getDictionary()); - - EventManager.triggerEvent(this, new ChangeSurfaceEvent(block, false)); + block.updatePlanes(); + EventManager.triggerEvent(this, new ChangeSurfaceEvent(minMaxModel.getBean(), false)); } private void addBlock() { SystemFolder systemFolder = model.getProject().getSystemFolder(); model.getGeometry().loadBlock(systemFolder.getBlockMeshDict(), systemFolder.getSnappyHexMeshDict()); model.blockChanged(); - minMaxModel.setDictionary(model.getGeometry().getBlock().getGeometryDictionary()); + minMaxModel.setBean(model.getGeometry().getBlock()); EventManager.triggerEvent(this, new ChangeSurfaceEvent(model.getGeometry().getBlock(), true)); } @@ -166,46 +173,49 @@ public class UserDefinedBaseMeshPanel { } public void resetToDefault() { - minMaxModel.setDictionary(new Dictionary(defaultBoxModelDict)); + blockListener.setAdjusting(true); + minMaxModel.setBean(new MultiPlane("BoundingBox")); + blockListener.setAdjusting(false); +// minMaxModel.setDictionary(new Dictionary(defaultBoxModelDict)); } - private Dictionary defaultBoxModelDict = new Dictionary("block") { - { - add(MIN_KEY, new String[] { "-1.0", "-1.0", "-1.0" }); - add(MAX_KEY, new String[] { "1.0", "1.0", "1.0" }); - add("patch0", "ffminx"); - add("patch1", "ffminx"); - add("patch2", "ffminx"); - add("patch3", "ffmaxx"); - add("patch4", "ffminz"); - add("patch5", "ffmaxz"); - add(ELEMENTS_KEY, new String[] { "10", "10", "10" }); +// private Dictionary defaultBoxModelDict = new Dictionary("block") { +// { +// add(MIN_KEY, new String[] { "-1.0", "-1.0", "-1.0" }); +// add(MAX_KEY, new String[] { "1.0", "1.0", "1.0" }); +// add("patch0", "ffminx"); +// add("patch1", "ffminx"); +// add("patch2", "ffminx"); +// add("patch3", "ffmaxx"); +// add("patch4", "ffminz"); +// add("patch5", "ffmaxz"); +// add(ELEMENTS_KEY, new String[] { "10", "10", "10" }); +// } +// }; + + private IntegerField[] elements; + + void addBlockListener() { + addBlockListener(boxMin); + addBlockListener(boxMax); + addBlockListener(elements); + } + + void addBlockListener(JComponent... components) { + for (JComponent c : components) { + c.addPropertyChangeListener("value", blockListener); } - }; + } - private class UpdateBlockListener implements FieldChangeListener { - - boolean adjusting = false; + public void geometryChanged(){ + fitButton.setEnabled(model.getGeometry().getSurfaces().length > 0); + } + + private class UpdateBlockListener extends FieldChangeListener { @Override - public void actionPerformed(ActionEvent e) { - } - - @Override - public void setAdjusting(boolean b) { - this.adjusting = b; - } - - @Override - public boolean isAdjusting() { - return adjusting; - } - - @Override - public void fieldChanged() { - if (!isAdjusting()) { - updateBlock(); - } + public void fieldChanged(Object source) { + updateBlock(); } } @@ -231,7 +241,7 @@ public class UserDefinedBaseMeshPanel { boxMax[2].setDoubleValue(bb.getZmax()); blockListener.setAdjusting(false); - + updateBlock(); } diff --git a/src/eu/engys/gui/solver/DefaultRunOptionsPanel.java b/src/eu/engys/gui/solver/DefaultRunOptionsPanel.java index 4f0fae9..e628ea6 100644 --- a/src/eu/engys/gui/solver/DefaultRunOptionsPanel.java +++ b/src/eu/engys/gui/solver/DefaultRunOptionsPanel.java @@ -1,30 +1,32 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.solver; +import static eu.engys.core.controller.AbstractController.SOLVER_RUN; +import static eu.engys.core.controller.AbstractController.SOLVER_RUN_EDIT; +import static eu.engys.core.project.openFOAMProject.LOG; import static eu.engys.util.ui.ComponentsFactory.labelField; import static eu.engys.util.ui.ComponentsFactory.stringField; @@ -33,19 +35,18 @@ import java.io.File; import java.nio.file.Paths; import javax.inject.Inject; -import javax.swing.Action; import javax.swing.BorderFactory; import javax.swing.JButton; import javax.swing.JComponent; import javax.swing.JLabel; import javax.swing.JPanel; -import net.java.dev.designgridlayout.Componentizer; import eu.engys.core.presentation.ActionManager; import eu.engys.core.project.Model; import eu.engys.gui.DefaultGUIPanel; import eu.engys.util.ui.builder.PanelBuilder; import eu.engys.util.ui.textfields.StringField; +import net.java.dev.designgridlayout.Componentizer; public class DefaultRunOptionsPanel extends DefaultGUIPanel { @@ -80,7 +81,7 @@ public class DefaultRunOptionsPanel extends DefaultGUIPanel { protected JComponent getQueuePanel() { return new JPanel(); } - + protected JComponent getPropertiesPanel() { PanelBuilder properties = new PanelBuilder(); properties.getPanel().setBorder(BorderFactory.createTitledBorder(PROPERTIES_LABEL)); @@ -104,16 +105,14 @@ public class DefaultRunOptionsPanel extends DefaultGUIPanel { PanelBuilder actions = new PanelBuilder(); actions.getPanel().setBorder(BorderFactory.createTitledBorder("Actions")); - Action runSolverAction = ActionManager.getInstance().get("solver.run"); - Action editRunSolverAction = ActionManager.getInstance().get("solver.run.edit"); + if (ActionManager.getInstance().contains(SOLVER_RUN) && ActionManager.getInstance().contains(SOLVER_RUN_EDIT)) { + JButton runSolverButton = new JButton(ActionManager.getInstance().get(SOLVER_RUN)); + JButton editRunSolverButton = new JButton(ActionManager.getInstance().get(SOLVER_RUN_EDIT)); + runSolverButton.setPreferredSize(new Dimension(120, runSolverButton.getPreferredSize().height)); - JButton runSolverButton = new JButton(runSolverAction); - JButton editRunSolverButton = new JButton(editRunSolverAction); - - runSolverButton.setPreferredSize(new Dimension(120, runSolverButton.getPreferredSize().height)); - - JComponent c1 = Componentizer.create().minToPref(runSolverButton).fixedPref(editRunSolverButton).minAndMore(new JLabel()).component(); - actions.addComponent(c1); + JComponent c1 = Componentizer.create().minToPref(runSolverButton).fixedPref(editRunSolverButton).minAndMore(new JLabel()).component(); + actions.addComponent(c1); + } JComponent[] cs = getExtraButtons(); for (JComponent c : cs) { @@ -129,7 +128,7 @@ public class DefaultRunOptionsPanel extends DefaultGUIPanel { @Override public void load() { if (model.getSolverModel().getLogFile() != null) { - File logFile = Paths.get(model.getProject().getBaseDir().getAbsolutePath(), "log", model.getSolverModel().getLogFile()).toFile(); + File logFile = Paths.get(model.getProject().getBaseDir().getAbsolutePath(), LOG, model.getSolverModel().getLogFile()).toFile(); if (logFile == null || !logFile.exists() || !logFile.isFile()) { setDefaultLogName(); } else { diff --git a/src/eu/engys/gui/solver/ReloadOnFinish.java b/src/eu/engys/gui/solver/ReloadOnFinish.java index 3ae8610..7c075fe 100644 --- a/src/eu/engys/gui/solver/ReloadOnFinish.java +++ b/src/eu/engys/gui/solver/ReloadOnFinish.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.solver; import eu.engys.core.controller.Command; diff --git a/src/eu/engys/gui/solver/ReopenOnInitialised.java b/src/eu/engys/gui/solver/ReopenOnInitialised.java index 6565ef3..cf4a0f4 100644 --- a/src/eu/engys/gui/solver/ReopenOnInitialised.java +++ b/src/eu/engys/gui/solver/ReopenOnInitialised.java @@ -1,33 +1,32 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.solver; import eu.engys.core.controller.Command; import eu.engys.core.controller.Controller; -import eu.engys.core.controller.Controller.OpenOptions; +import eu.engys.core.controller.Controller.OpenMode; import eu.engys.core.project.state.ServerState; import eu.engys.gui.solver.postprocessing.ServerListener; @@ -44,7 +43,7 @@ public class ReopenOnInitialised implements ServerListener { if (serverState.getCommand().equals(Command.INITIALISE_FIELDS)) { if (serverState.getSolverState().isInitialised()) { if (controller.getListener() != null) { - controller.reopenCase(OpenOptions.MESH_ONLY); + controller.reopenCase(OpenMode.MESH_ONLY); } } } diff --git a/src/eu/engys/gui/solver/ReopenOnMeshed.java b/src/eu/engys/gui/solver/ReopenOnMeshed.java index 04199e0..4a6133b 100644 --- a/src/eu/engys/gui/solver/ReopenOnMeshed.java +++ b/src/eu/engys/gui/solver/ReopenOnMeshed.java @@ -1,33 +1,32 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.solver; import eu.engys.core.controller.Command; import eu.engys.core.controller.Controller; -import eu.engys.core.controller.Controller.OpenOptions; +import eu.engys.core.controller.Controller.OpenMode; import eu.engys.core.project.state.ServerState; import eu.engys.gui.solver.postprocessing.ServerListener; @@ -44,7 +43,7 @@ public class ReopenOnMeshed implements ServerListener { if (serverState.getCommand().equals(Command.CREATE_MESH)) { if (serverState.getSolverState().isMeshed()) { if (controller.getListener() != null) { - controller.reopenCase(OpenOptions.MESH_ONLY); + controller.reopenCase(OpenMode.MESH_ONLY); } } } diff --git a/src/eu/engys/gui/solver/Solver.java b/src/eu/engys/gui/solver/Solver.java index fe1cdcf..244caf3 100644 --- a/src/eu/engys/gui/solver/Solver.java +++ b/src/eu/engys/gui/solver/Solver.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.solver; diff --git a/src/eu/engys/gui/solver/Solver3DElement.java b/src/eu/engys/gui/solver/Solver3DElement.java index 1c29c4c..b9aee56 100644 --- a/src/eu/engys/gui/solver/Solver3DElement.java +++ b/src/eu/engys/gui/solver/Solver3DElement.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.solver; diff --git a/src/eu/engys/gui/solver/SolverElement.java b/src/eu/engys/gui/solver/SolverElement.java index 170f83d..049a177 100644 --- a/src/eu/engys/gui/solver/SolverElement.java +++ b/src/eu/engys/gui/solver/SolverElement.java @@ -1,30 +1,30 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.solver; +import java.util.HashSet; import java.util.Observable; import java.util.Observer; import java.util.Set; @@ -35,9 +35,12 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import eu.engys.core.modules.ApplicationModule; +import eu.engys.core.modules.ModulePanel; +import eu.engys.core.modules.ModulesUtil; import eu.engys.core.project.Model; import eu.engys.core.project.ProjectReader; import eu.engys.core.project.ProjectWriter; +import eu.engys.core.project.state.State; import eu.engys.gui.Actions; import eu.engys.gui.GUIPanel; import eu.engys.gui.view.AbstractViewElement; @@ -73,6 +76,15 @@ public class SolverElement extends AbstractViewElement { }; super.layoutComponents(); } + + @Override + protected Set getModulePanels() { + Set allPanels = new HashSet(); + for (ModulePanel panel : ModulesUtil.getSolverPanels(modules)) { + allPanels.add((GUIPanel) panel); + } + return allPanels; + } @Override public int getPreferredWidth() { @@ -99,6 +111,16 @@ public class SolverElement extends AbstractViewElement { @Override public void load(Model model) { super.load(model); + ModulesUtil.updateSolverTree(modules, getPanel()); + } + + @Override + public void changeObserved(Object arg) { + if (arg instanceof State) { + ModulesUtil.updateSolverTree(modules, getPanel()); + getActions().update(); + } + super.changeObserved(arg); } @Override diff --git a/src/eu/engys/gui/solver/SolverRuntimeControlsPanel.java b/src/eu/engys/gui/solver/SolverRuntimeControlsPanel.java index 4ca6b13..d62a208 100644 --- a/src/eu/engys/gui/solver/SolverRuntimeControlsPanel.java +++ b/src/eu/engys/gui/solver/SolverRuntimeControlsPanel.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.solver; import static eu.engys.core.project.system.ControlDict.ADJUSTABLE_RUN_TIME_KEY; @@ -365,9 +364,8 @@ public class SolverRuntimeControlsPanel extends DefaultGUIPanel { @Override public void actionPerformed(ActionEvent e) { - // TODO check remote case save(); - model.getProject().getSystemFolder().writeControlDict(new SilentMonitor()); + model.getProject().getSystemFolder().writeControlDict(model, new SilentMonitor()); } } } diff --git a/src/eu/engys/gui/solver/UpdateClientState.java b/src/eu/engys/gui/solver/UpdateClientState.java index 84a88f6..8bc11f2 100644 --- a/src/eu/engys/gui/solver/UpdateClientState.java +++ b/src/eu/engys/gui/solver/UpdateClientState.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.solver; import eu.engys.core.project.Model; diff --git a/src/eu/engys/gui/solver/actions/DefaultSolverActions.java b/src/eu/engys/gui/solver/actions/DefaultSolverActions.java index 640d140..fb2b541 100644 --- a/src/eu/engys/gui/solver/actions/DefaultSolverActions.java +++ b/src/eu/engys/gui/solver/actions/DefaultSolverActions.java @@ -1,35 +1,33 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.solver.actions; +import static eu.engys.core.controller.AbstractController.SOLVER_RUN; import static eu.engys.util.ui.UiUtil.createToolBarButton; import javax.inject.Inject; -import javax.swing.Action; -import javax.swing.Box; import javax.swing.JToolBar; import eu.engys.core.controller.Controller; @@ -41,25 +39,24 @@ import eu.engys.util.ui.UiUtil; public abstract class DefaultSolverActions implements Actions { - private final Action launchAction; - private JToolBar toolbar; protected Model model; @Inject public DefaultSolverActions(Model model, Controller controller) { this.model = model; - this.launchAction = ActionManager.getInstance().get("solver.run"); } @Override public JToolBar toolbar() { - toolbar = UiUtil.getToolbar("view.element.toolbar"); + toolbar = UiUtil.getToolbarWrapped(TOOLBAR_NAME); - toolbar.add(createToolBarButton(launchAction)); - toolbar.addSeparator(); + if (ActionManager.getInstance().contains(SOLVER_RUN)) { + toolbar.add(createToolBarButton(ActionManager.getInstance().get(SOLVER_RUN))); + toolbar.addSeparator(); + } addExtraActions(); - toolbar.add(Box.createHorizontalGlue()); +// toolbar.add(Box.createHorizontalGlue()); return toolbar; } @@ -74,11 +71,12 @@ public abstract class DefaultSolverActions implements Actions { ExecUtil.invokeLater(new Runnable() { @Override public void run() { - boolean isRemote = model.getSolverModel().isRemote(); - boolean hasMesh = !model.getPatches().isEmpty(); - boolean isRunning = model.getSolverModel() != null && model.getSolverModel().getServerState() != null && model.getSolverModel().getServerState().getSolverState().isRunning(); - boolean isSolutionSet = model.getState().areTimeAndFlowAndTurbulenceChoosen(); - launchAction.setEnabled(hasMesh && !isRunning && isSolutionSet); + if (ActionManager.getInstance().contains(SOLVER_RUN)) { + boolean hasMesh = !model.getPatches().isEmpty(); + boolean isRunning = model.getSolverModel() != null && model.getSolverModel().getServerState() != null && model.getSolverModel().getServerState().getSolverState().isRunning(); + boolean isSolutionSet = model.getState().areTimeAndFlowAndTurbulenceChoosen(); + ActionManager.getInstance().get(SOLVER_RUN).setEnabled(hasMesh && !isRunning && isSolutionSet); + } } }); } diff --git a/src/eu/engys/gui/solver/actions/EditRunSolverAction.java b/src/eu/engys/gui/solver/actions/EditRunSolverAction.java index dfe61de..95e9605 100644 --- a/src/eu/engys/gui/solver/actions/EditRunSolverAction.java +++ b/src/eu/engys/gui/solver/actions/EditRunSolverAction.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.solver.actions; diff --git a/src/eu/engys/gui/solver/actions/OpenParaviewAction.java b/src/eu/engys/gui/solver/actions/OpenParaviewAction.java index 985e864..bd43b43 100644 --- a/src/eu/engys/gui/solver/actions/OpenParaviewAction.java +++ b/src/eu/engys/gui/solver/actions/OpenParaviewAction.java @@ -1,43 +1,44 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.solver.actions; import static eu.engys.core.OpenFOAMEnvironment.getEnvironment; +import static eu.engys.util.OpenFOAMCommands.PARA_FOAM; import java.awt.event.ActionEvent; import java.io.File; import java.io.FilenameFilter; +import java.util.Map; import javax.swing.Icon; import javax.swing.JOptionPane; +import eu.engys.core.DockerUtil; import eu.engys.core.OpenFOAMEnvironment; import eu.engys.core.executor.Executor; import eu.engys.core.project.Model; -import eu.engys.util.OpenFOAMCommands; import eu.engys.util.PrefUtil; import eu.engys.util.Util; import eu.engys.util.ui.ResourcesUtil; @@ -57,33 +58,42 @@ public class OpenParaviewAction extends ViewAction { @Override public void actionPerformed(ActionEvent e) { - launchParaView(); + launchParaView(model.getProject().getBaseDir(), getEnvironment(model)); } - private void launchParaView() { + public static void launchParaView(File baseDir, Map env) { File paraView = PrefUtil.getParaViewEntry(); - if (OpenFOAMEnvironment.isParaviewPathSet()) { - String foamFile = getCaseFoamFile(); - if (foamFile != null) { - Executor.command(paraView, "--data=" + foamFile).inFolder(model.getProject().getBaseDir()).description(PARAVIEW_LABEL).exec(); - } else { - JOptionPane.showMessageDialog(UiUtil.getActiveWindow(), "No .foam file found!", "Missing file", JOptionPane.ERROR_MESSAGE); - } - } else { + + if(PrefUtil.isUsingDocker()){ if(Util.isWindows()){ UiUtil.showEnvironmentNotLoadedWarning(PARAVIEW_LABEL); } else { - if(OpenFOAMEnvironment.isEnvironementLoaded()){ - Executor.command(OpenFOAMCommands.PARA_FOAM).inFolder(model.getProject().getBaseDir()).withOpenFoamEnv().env(getEnvironment(model)).description(PARAVIEW_LABEL).exec(); + Executor.command(DockerUtil.paraview(baseDir)).inFolder(baseDir).description(PARAVIEW_LABEL).exec(); + } + } else { + if (OpenFOAMEnvironment.isParaviewPathSet()) { + String foamFile = getCaseFoamFile(baseDir); + if (foamFile != null) { + Executor.command(paraView, "--data=" + foamFile).inFolder(baseDir).description(PARAVIEW_LABEL).exec(); } else { - UiUtil.showCoreEnvironmentNotLoadedWarning(); + JOptionPane.showMessageDialog(UiUtil.getActiveWindow(), "No .foam file found!", "Missing file", JOptionPane.ERROR_MESSAGE); + } + } else { + if(Util.isWindows()){ + UiUtil.showEnvironmentNotLoadedWarning(PARAVIEW_LABEL); + } else { + if(OpenFOAMEnvironment.isEnvironementLoaded()){ + Executor.command(PARA_FOAM).inFolder(baseDir).withOpenFoamEnv().env(env).description(PARAVIEW_LABEL).exec(); + } else { + UiUtil.showCoreEnvironmentNotLoadedWarning(); + } } } } + } - private String getCaseFoamFile() { - File baseDir = model.getProject().getBaseDir(); + private static String getCaseFoamFile(File baseDir) { String[] foamFiles = baseDir.list(new FilenameFilter() { @Override public boolean accept(File dir, String name) { diff --git a/src/eu/engys/gui/solver/actions/RunSolverAction.java b/src/eu/engys/gui/solver/actions/RunSolverAction.java index b135eb0..3797bb5 100644 --- a/src/eu/engys/gui/solver/actions/RunSolverAction.java +++ b/src/eu/engys/gui/solver/actions/RunSolverAction.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.solver.actions; diff --git a/src/eu/engys/gui/solver/actions/StandardSolverActions.java b/src/eu/engys/gui/solver/actions/StandardSolverActions.java index 8639c1f..e916f71 100644 --- a/src/eu/engys/gui/solver/actions/StandardSolverActions.java +++ b/src/eu/engys/gui/solver/actions/StandardSolverActions.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.solver.actions; import static eu.engys.util.ui.UiUtil.createToolBarButton; diff --git a/src/eu/engys/gui/solver/postprocessing/ParsersHandler.java b/src/eu/engys/gui/solver/postprocessing/ParsersHandler.java index 4f73861..a91b05c 100644 --- a/src/eu/engys/gui/solver/postprocessing/ParsersHandler.java +++ b/src/eu/engys/gui/solver/postprocessing/ParsersHandler.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.solver.postprocessing; import java.util.ArrayList; @@ -30,16 +29,20 @@ import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Set; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import eu.engys.core.modules.ApplicationModule; +import eu.engys.core.modules.ModulesUtil; import eu.engys.core.project.Model; import eu.engys.core.project.system.monitoringfunctionobjects.MonitoringFunctionObject; import eu.engys.core.project.system.monitoringfunctionobjects.Parser; import eu.engys.core.project.system.monitoringfunctionobjects.TimeBlocks; import eu.engys.gui.solver.postprocessing.parsers.ResidualsParser; import eu.engys.gui.solver.postprocessing.parsers.ResidualsUtils; +import eu.engys.gui.solver.postprocessing.parsers.SimpleResidualsParser; public class ParsersHandler { @@ -49,8 +52,11 @@ public class ParsersHandler { private Map> parsersMap; - public ParsersHandler(Model model) { + private Set modules; + + public ParsersHandler(Model model, Set modules) { this.model = model; + this.modules = modules; this.parsersMap = Collections.synchronizedMap(new HashMap>()); // this will syncro add/remove/indexof/size BUT iterating should be // sync'd manually! @@ -61,6 +67,7 @@ public class ParsersHandler { for (MonitoringFunctionObject fo : model.getMonitoringFunctionObjects()) { fo.getType().getFactory().deleteUselessLogFiles(fo); } + ModulesUtil.deleteUselessLogFiles(modules); } /* @@ -68,7 +75,10 @@ public class ParsersHandler { */ private void registerParsersForFunctionObject(String foName) { if (foName.equals(ResidualsParser.KEY)) { - ResidualsParser residualsParser = new ResidualsParser(ResidualsUtils.fileToParse(model)); + Parser residualsParser = ModulesUtil.createResidualsParser(modules, ResidualsUtils.fileToParse(model)); + if (residualsParser == null) { + residualsParser = new SimpleResidualsParser(ResidualsUtils.fileToParse(model)); + } register(residualsParser); } for (MonitoringFunctionObject fo : model.getMonitoringFunctionObjects()) { @@ -79,6 +89,10 @@ public class ParsersHandler { } } } + List parsers = ModulesUtil.createParsers(modules); + for (Parser parser : parsers) { + register(parser); + } } private void register(Parser parser) { @@ -172,7 +186,7 @@ public class ParsersHandler { } private void endParsersForFunctionObject(String functionObjectName) { - if(parsersMap.containsKey(functionObjectName)){ + if (parsersMap.containsKey(functionObjectName)) { for (Parser parser : parsersMap.get(functionObjectName)) { parser.end(); } diff --git a/src/eu/engys/gui/solver/postprocessing/ParsersViewHandler.java b/src/eu/engys/gui/solver/postprocessing/ParsersViewHandler.java index 21d7bc8..bb44d38 100644 --- a/src/eu/engys/gui/solver/postprocessing/ParsersViewHandler.java +++ b/src/eu/engys/gui/solver/postprocessing/ParsersViewHandler.java @@ -1,34 +1,34 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.solver.postprocessing; import java.rmi.RemoteException; import java.util.ArrayList; import java.util.Collections; import java.util.List; +import java.util.Set; import java.util.concurrent.ThreadPoolExecutor; import org.slf4j.Logger; @@ -36,197 +36,201 @@ import org.slf4j.LoggerFactory; import eu.engys.core.controller.ParsersManager; import eu.engys.core.executor.Executor; +import eu.engys.core.modules.ApplicationModule; +import eu.engys.core.modules.ModulesUtil; import eu.engys.core.project.Model; import eu.engys.core.project.state.ServerState; import eu.engys.core.project.system.monitoringfunctionobjects.MonitoringFunctionObject; import eu.engys.core.project.system.monitoringfunctionobjects.ParserView; import eu.engys.core.project.system.monitoringfunctionobjects.TimeBlocks; -import eu.engys.gui.solver.postprocessing.panels.residuals.ResidualsView; import eu.engys.util.ui.ExecUtil; public class ParsersViewHandler implements ServerListener { - private static final Logger logger = LoggerFactory.getLogger(ParsersViewHandler.class); + private static final Logger logger = LoggerFactory.getLogger(ParsersViewHandler.class); - private final Model model; + private final Model model; - private List views; - private ResidualsView residualsView; - private ThreadPoolExecutor executor; + private List views; + private ParserView residualsView; + private ThreadPoolExecutor executor; - private ParsersManager parserManager; + private ParsersManager parserManager; - public ParsersViewHandler(Model model, ParsersManager parserManager, ResidualsView residualsView) { - this.model = model; - this.parserManager = parserManager; - this.residualsView = residualsView; - this.views = Collections.synchronizedList(new ArrayList()); - this.executor = Executor.newExecutor("ParserViewHandler"); - registerViews(); - } + public ParsersViewHandler(Model model, Set modules, ParsersManager parserManager, ParserView residualsView) { + this.model = model; + this.parserManager = parserManager; + this.residualsView = residualsView; + this.views = Collections.synchronizedList(new ArrayList()); + this.executor = Executor.newExecutor("ParserViewHandler"); + registerViews(modules); + } - private void registerViews() { - register(residualsView); - for (MonitoringFunctionObject fo : model.getMonitoringFunctionObjects()) { - ParserView view = fo.getView(); - register(view); + private void registerViews(Set modules) { + register(residualsView); + for (MonitoringFunctionObject fo : model.getMonitoringFunctionObjects()) { + ParserView view = fo.getView(); + register(view); + } + for (ParserView view : ModulesUtil.createParserViews(modules)) { + register(view); } - } + } - private void register(ParserView view) { - if (view != null) { - logger.debug("REGISTERING {} VIEW", view.getKey()); - views.add(view); - } - } + private void register(ParserView view) { + if (view != null) { + logger.debug("REGISTERING {} VIEW", view.getKey()); + views.add(view); + } + } - @Override - public void serverChanged(ServerState serverState) { - switch (serverState.getSolverState()) { - case STARTED: - started(); - break; - case RUNNING: - running(); - break; - case ERROR: - error(); - break; - case FINISHED: - running();// Needed by OS - finished(); - break; + @Override + public void serverChanged(ServerState serverState) { + switch (serverState.getSolverState()) { + case STARTED: + started(); + break; + case RUNNING: + running(); + break; + case ERROR: + error(); + break; + case FINISHED: + running();// Needed by OS + finished(); + break; - default: - break; - } - } + default: + break; + } + } - private void started() { - logger.debug("STARTED"); - for (ParserView view : views) { - view.setParsingEnabled(true); - view.handleSolverStarted(); - } - } + private void started() { + logger.debug("STARTED"); + for (ParserView view : views) { + view.setParsingEnabled(true); + view.handleSolverStarted(); + } + } - private void finished() { - logger.debug("FINISHED"); - executor.submit(new Runnable() { - @Override - public void run() { - try { - logger.debug("ENDING PARSERS"); - parserManager.endParsers(); - } catch (RemoteException e) { - logger.error("ERROR ENDING PARSERS", e); - } - } - }); - executor.shutdown(); - } + private void finished() { + logger.debug("FINISHED"); + executor.submit(new Runnable() { + @Override + public void run() { + try { + logger.debug("ENDING PARSERS"); + parserManager.endParsers(); + } catch (RemoteException e) { + logger.error("ERROR ENDING PARSERS", e); + } + } + }); + executor.shutdown(); + } - private void running() { - for (final ParserView view : views) { - if (view.isParsingEnabled()) { - if (notInQueue(view)) { - executor.submit(new ParserUpdateTask(view)); - } - } - } - } + private void running() { + for (final ParserView view : views) { + if (view.isParsingEnabled()) { + if (notInQueue(view)) { + executor.submit(new ParserUpdateTask(view)); + } + } + } + } - private boolean notInQueue(ParserView view) { - for (Runnable r : executor.getQueue()) { - if (r instanceof ParserUpdateTask) { - ParserUpdateTask task = (ParserUpdateTask) r; - if (task.getView() == view) { - return false; - } - } - } + private boolean notInQueue(ParserView view) { + for (Runnable r : executor.getQueue()) { + if (r instanceof ParserUpdateTask) { + ParserUpdateTask task = (ParserUpdateTask) r; + if (task.getView() == view) { + return false; + } + } + } - return true; - } + return true; + } - public void refreshOnce() { - logger.info("REFRESH ONCE"); - for (final ParserView view : views) { - if (view.isParsingEnabled()) { - executor.submit(new Runnable() { - @Override - public void run() { - view.showLoading(); - List timeBlocks = updateParserOnce(parserManager, view.getKey()); - logger.debug("RETRIVED {} TIME BLOCKS FOR {}", timeBlocks.size(), view.getKey()); - updateView(view, timeBlocks); - view.stopLoading(); - } - }); - } - } - executor.shutdown(); - } + public void refreshOnce() { + logger.info("REFRESH ONCE"); + for (final ParserView view : views) { + if (view.isParsingEnabled()) { + executor.submit(new Runnable() { + @Override + public void run() { + view.showLoading(); + List timeBlocks = updateParserOnce(parserManager, view.getKey()); + logger.debug("RETRIVED {} TIME BLOCKS FOR {}", timeBlocks.size(), view.getKey()); + updateView(view, timeBlocks); + view.stopLoading(); + } + }); + } + } + executor.shutdown(); + } - private List updateParser(ParsersManager parsersManager, String key) { - logger.debug("REFRESH PARSER {}", key); - try { - return parsersManager.updateParser(key); - } catch (RemoteException e) { - logger.error("ERROR ON REFRESH", e); - } - return Collections.emptyList(); - } + private List updateParser(ParsersManager parsersManager, String key) { + logger.debug("REFRESH PARSER {}", key); + try { + return parsersManager.updateParser(key); + } catch (RemoteException e) { + logger.error("ERROR ON REFRESH", e); + } + return Collections.emptyList(); + } - private List updateParserOnce(ParsersManager parsersManager, String key) { - logger.debug("REFRESH PARSER ONCE {}", key); - try { - return parsersManager.updateParserOnce(key); - } catch (RemoteException e) { - logger.error("ERROR ON REFRESH ONCE", e); - } - return Collections.emptyList(); - } + private List updateParserOnce(ParsersManager parsersManager, String key) { + logger.debug("REFRESH PARSER ONCE {}", key); + try { + return parsersManager.updateParserOnce(key); + } catch (RemoteException e) { + logger.error("ERROR ON REFRESH ONCE", e); + } + return Collections.emptyList(); + } - private void updateView(final ParserView view, final List newTimeBlocks) { - ExecUtil.invokeLater(new Runnable() { - @Override - public void run() { - if (newTimeBlocks != null) { - view.updateParsing(newTimeBlocks); - } else { - logger.warn("EMPTY TIME BLOCK"); - } - } - }); - } + private void updateView(final ParserView view, final List newTimeBlocks) { + ExecUtil.invokeLater(new Runnable() { + @Override + public void run() { + if (newTimeBlocks != null) { + view.updateParsing(newTimeBlocks); + } else { + logger.warn("EMPTY TIME BLOCK"); + } + } + }); + } - private void error() { - logger.debug("ERROR"); - executor.shutdown(); - } + private void error() { + logger.debug("ERROR"); + executor.shutdown(); + } - class ParserUpdateTask implements Runnable { + class ParserUpdateTask implements Runnable { - private ParserView view; + private ParserView view; - public ParserUpdateTask(ParserView view) { - this.view = view; - } + public ParserUpdateTask(ParserView view) { + this.view = view; + } - @Override - public void run() { - view.showLoading(); - List timeBlocks = updateParser(parserManager, view.getKey()); - logger.debug("RETRIVED {} TIME BLOCKS FOR {}", timeBlocks.size(), view.getKey()); - updateView(view, timeBlocks); - view.stopLoading(); - } + @Override + public void run() { + view.showLoading(); + List timeBlocks = updateParser(parserManager, view.getKey()); + logger.debug("RETRIVED {} TIME BLOCKS FOR {}", timeBlocks.size(), view.getKey()); + updateView(view, timeBlocks); + view.stopLoading(); + } - public ParserView getView() { - return view; - } + public ParserView getView() { + return view; + } - } + } } diff --git a/src/eu/engys/gui/solver/postprocessing/ServerListener.java b/src/eu/engys/gui/solver/postprocessing/ServerListener.java index b9cf5c2..c56a94d 100644 --- a/src/eu/engys/gui/solver/postprocessing/ServerListener.java +++ b/src/eu/engys/gui/solver/postprocessing/ServerListener.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.solver.postprocessing; import eu.engys.core.project.state.ServerState; @@ -31,4 +30,4 @@ public interface ServerListener { void serverChanged(ServerState serverState); -} +} \ No newline at end of file diff --git a/src/eu/engys/gui/solver/postprocessing/ServerStateMonitor.java b/src/eu/engys/gui/solver/postprocessing/ServerStateMonitor.java index 3b2beca..a970e77 100644 --- a/src/eu/engys/gui/solver/postprocessing/ServerStateMonitor.java +++ b/src/eu/engys/gui/solver/postprocessing/ServerStateMonitor.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.solver.postprocessing; import java.rmi.RemoteException; @@ -201,7 +200,7 @@ public class ServerStateMonitor { } if (endState != null) { - if (endState.equals(state) || state.getSolverState().isError()) { + if (endState.equals(state) || (state.getCommand().equals(endState.getCommand()) && state.getSolverState().isError())) { logger.info("STATE IS {}, END STATE IS {}", state.getSolverState(), endState); stopTimer(); } diff --git a/src/eu/engys/gui/solver/postprocessing/data/DoubleListTimeBlockUnit.java b/src/eu/engys/gui/solver/postprocessing/data/DoubleListTimeBlockUnit.java index cbe57dd..5301c80 100644 --- a/src/eu/engys/gui/solver/postprocessing/data/DoubleListTimeBlockUnit.java +++ b/src/eu/engys/gui/solver/postprocessing/data/DoubleListTimeBlockUnit.java @@ -1,30 +1,30 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.solver.postprocessing.data; +import java.util.Collection; import java.util.LinkedList; import java.util.List; @@ -43,6 +43,15 @@ public class DoubleListTimeBlockUnit extends TimeBlockUnit { this.values = new LinkedList(); } + public DoubleListTimeBlockUnit(String varName, Collectionvalues) { + super(varName); + this.values = new LinkedList(values); + } + + public int size(){ + return values.size(); + } + public List getValues() { return values; } @@ -51,4 +60,4 @@ public class DoubleListTimeBlockUnit extends TimeBlockUnit { public String toString() { return "[" + getVarName() + ", " + values + "]"; } -} +} \ No newline at end of file diff --git a/src/eu/engys/gui/solver/postprocessing/data/DoubleTimeBlockUnit.java b/src/eu/engys/gui/solver/postprocessing/data/DoubleTimeBlockUnit.java index 3e3437b..3e8865d 100644 --- a/src/eu/engys/gui/solver/postprocessing/data/DoubleTimeBlockUnit.java +++ b/src/eu/engys/gui/solver/postprocessing/data/DoubleTimeBlockUnit.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.solver.postprocessing.data; import eu.engys.core.project.system.monitoringfunctionobjects.TimeBlockUnit; @@ -49,4 +48,4 @@ public class DoubleTimeBlockUnit extends TimeBlockUnit { public String toString() { return "[" + getVarName() + ", " + getValue() + "]"; } -} +} \ No newline at end of file diff --git a/src/eu/engys/gui/solver/postprocessing/data/PointTimeBlockUnit.java b/src/eu/engys/gui/solver/postprocessing/data/PointTimeBlockUnit.java index cdf20e9..209bcdc 100644 --- a/src/eu/engys/gui/solver/postprocessing/data/PointTimeBlockUnit.java +++ b/src/eu/engys/gui/solver/postprocessing/data/PointTimeBlockUnit.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.solver.postprocessing.data; import javax.vecmath.Point3d; @@ -51,4 +50,4 @@ public class PointTimeBlockUnit extends TimeBlockUnit { public String toString() { return "[" + getVarName() + ", " + getPoint() + "]"; } -} +} \ No newline at end of file diff --git a/src/eu/engys/gui/solver/postprocessing/panels/AbstractChartPanel.java b/src/eu/engys/gui/solver/postprocessing/panels/AbstractChartPanel.java deleted file mode 100644 index 2b7dbd6..0000000 --- a/src/eu/engys/gui/solver/postprocessing/panels/AbstractChartPanel.java +++ /dev/null @@ -1,148 +0,0 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - -package eu.engys.gui.solver.postprocessing.panels; - -import static org.jfree.chart.ChartPanel.DEFAULT_HEIGHT; -import static org.jfree.chart.ChartPanel.DEFAULT_MAXIMUM_DRAW_HEIGHT; -import static org.jfree.chart.ChartPanel.DEFAULT_MAXIMUM_DRAW_WIDTH; -import static org.jfree.chart.ChartPanel.DEFAULT_MINIMUM_DRAW_HEIGHT; -import static org.jfree.chart.ChartPanel.DEFAULT_MINIMUM_DRAW_WIDTH; -import static org.jfree.chart.ChartPanel.DEFAULT_WIDTH; - -import java.awt.BasicStroke; -import java.awt.BorderLayout; -import java.awt.Color; -import java.text.DecimalFormat; - -import javax.swing.JPanel; - -import org.jfree.chart.ChartPanel; -import org.jfree.chart.JFreeChart; -import org.jfree.chart.block.BlockBorder; -import org.jfree.chart.labels.CrosshairLabelGenerator; -import org.jfree.chart.panel.CrosshairOverlay; -import org.jfree.chart.plot.Crosshair; -import org.jfree.chart.title.LegendTitle; -import org.jfree.ui.RectangleEdge; - -import eu.engys.core.project.system.monitoringfunctionobjects.TimeBlocks; - -public abstract class AbstractChartPanel extends JPanel { - - protected static final String TIME_LABEL = "Time [s]"; - - protected String title; - protected String domainAxisLabel; - protected String rangeAxisLabel; - - protected ChartPanel chartPanel; - protected JFreeChart chart; - - protected CrosshairOverlay overlay; - - public AbstractChartPanel(String title, String domainAxisLabel, String rangeAxisLabel) { - super(new BorderLayout()); - this.title = title; - this.domainAxisLabel = domainAxisLabel; - this.rangeAxisLabel = rangeAxisLabel; - } - - public void layoutComponents() { - createChart(); - this.chart.setBackgroundPaint(new Color(0, 0, 0, 0)); - this.chartPanel = createChartPanel(); - layoutLegend(); - } - - protected abstract void createChart(); - - public abstract void stop(); - - public abstract void addToDataSet(TimeBlocks list); - - public abstract void clearData(); - - private ChartPanel createChartPanel() { - boolean useBuffer = true; - boolean showPropertiesMenu = true; - boolean showCopyMenu = true; - boolean showSaveMenu = false; - boolean showPrintMenu = true; - boolean showZoomMenu = true; - boolean showTooltipsMenu = true; - ChartPanel panel = new ChartPanel(chart, DEFAULT_WIDTH, DEFAULT_HEIGHT, DEFAULT_MINIMUM_DRAW_WIDTH, DEFAULT_MINIMUM_DRAW_HEIGHT, DEFAULT_MAXIMUM_DRAW_WIDTH, DEFAULT_MAXIMUM_DRAW_HEIGHT, useBuffer, showPropertiesMenu, showCopyMenu, showSaveMenu, showPrintMenu, showZoomMenu, showTooltipsMenu); - this.overlay = createOverlay(); - return panel; - } - - private CrosshairOverlay createOverlay() { - CrosshairOverlay crosshairOverlay = new CrosshairOverlay(); - Crosshair xCrosshair = new Crosshair(Double.NaN, Color.BLUE.brighter(), new BasicStroke(0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 1.0f, new float[] { 1.0f }, 0.0f)); - xCrosshair.setLabelGenerator(new CrosshairLabelGenerator() { - @Override - public String generateLabel(Crosshair crosshair) { - DecimalFormat decimalFormat = new DecimalFormat("#.######"); - return decimalFormat.format(crosshair.getValue()); - } - }); - xCrosshair.setLabelBackgroundPaint(Color.WHITE); - xCrosshair.setLabelOutlineVisible(false); - xCrosshair.setLabelVisible(true); - - Crosshair yCrosshair = new Crosshair(Double.NaN, Color.BLUE.brighter(), new BasicStroke(0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 1.0f, new float[] { 1.0f }, 0.0f)); - yCrosshair.setLabelGenerator(new CrosshairLabelGenerator() { - @Override - public String generateLabel(Crosshair crosshair) { - DecimalFormat decimalFormat = new DecimalFormat("#.######"); - return decimalFormat.format(crosshair.getValue()); - } - }); - yCrosshair.setLabelBackgroundPaint(Color.WHITE); - yCrosshair.setLabelOutlineVisible(false); - yCrosshair.setLabelVisible(true); - - crosshairOverlay.addDomainCrosshair(xCrosshair); - crosshairOverlay.addRangeCrosshair(yCrosshair); - return crosshairOverlay; - } - - private void layoutLegend() { - LegendTitle legend = chart.getLegend(); - if (legend != null) { - legend.setFrame(BlockBorder.NONE); - legend.setBackgroundPaint(null); - legend.setPosition(RectangleEdge.RIGHT); - legend.setVisible(false); - } - } - - public JFreeChart getChart() { - return chart; - } - - public void initSeries() { - } -} diff --git a/src/eu/engys/gui/solver/postprocessing/panels/AbstractParserView.java b/src/eu/engys/gui/solver/postprocessing/panels/AbstractParserView.java index 1f51633..1571be3 100644 --- a/src/eu/engys/gui/solver/postprocessing/panels/AbstractParserView.java +++ b/src/eu/engys/gui/solver/postprocessing/panels/AbstractParserView.java @@ -1,35 +1,36 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.solver.postprocessing.panels; +import static eu.engys.core.controller.AbstractController.REFRESH_ONCE; + import java.awt.BorderLayout; import java.awt.Color; -import java.awt.Component; import java.io.File; import java.io.IOException; +import java.util.ArrayList; import java.util.List; import javax.swing.JComponent; @@ -38,13 +39,16 @@ import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JTabbedPane; import javax.swing.SwingUtilities; +import javax.swing.event.ChangeEvent; +import javax.swing.event.ChangeListener; -import org.apache.commons.io.FilenameUtils; import org.jfree.chart.ChartUtilities; +import org.jfree.chart.JFreeChart; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import eu.engys.core.executor.FileManagerSupport; +import eu.engys.core.modules.AbstractChart; import eu.engys.core.presentation.ActionManager; import eu.engys.core.project.Model; import eu.engys.core.project.system.monitoringfunctionobjects.MonitoringFunctionObject; @@ -69,17 +73,25 @@ public abstract class AbstractParserView extends JPanel implements ParserView { public AbstractParserView(Model model, MonitoringFunctionObject functionObject, ProgressMonitor monitor) { super(new BorderLayout()); + if (functionObject != null) + setName(functionObject.getName()); this.model = model; this.functionObject = functionObject; this.monitor = monitor; this.tabbedPane = new JTabbedPane(); + this.tabbedPane.addChangeListener(new ChangeListener() { + public void stateChanged(ChangeEvent e) { + stop(); + } + }); + this.parsingEnabled = false; JPanel mainPanel = new JPanel(new BorderLayout()); mainPanel.add(tabbedPane, BorderLayout.CENTER); loadingPane = new WaitLayerUI(new EnableParsing()); - JLayer layer = new JLayer(mainPanel, loadingPane); + JLayer layer = new JLayer<>(mainPanel, loadingPane); add(layer, BorderLayout.CENTER); } @@ -128,31 +140,58 @@ public abstract class AbstractParserView extends JPanel implements ParserView { } @Override - public void setCrosshairVisibile(boolean visible) { - for (Component c : tabbedPane.getComponents()) { - if (c instanceof MovingAverageChartPanel) { - ((MovingAverageChartPanel) c).setCrosshairVisible(visible); + public void showLogFile() { + try { + if (Util.isWindows()) { + showLogFileWindows(); + } else { + showLogFileLinux(); + } + } catch (Exception e) { + showErrorMessage(e); + } + } + + private void showLogFileLinux() { + List parsersList = getReportParsersList(); + for (Parser parser : parsersList) { + File logFile = parser.getFile(); + if (logFile != null && logFile.exists()) { + FileManagerSupport.open(logFile); } } } - @Override - public void showLogFile() { - try { - List parsersList = gerReportParsersList(); - for (Parser parser : parsersList) { - File logFile = parser.getFile(); - if (logFile != null && logFile.exists()) { - if (Util.isWindows() && FilenameUtils.getExtension(logFile.getName()).isEmpty()) { - FileManagerSupport.open(logFile.getParentFile()); - } else { - FileManagerSupport.open(logFile); - } + private void showLogFileWindows() { + List logFiles = new ArrayList<>(); + for (Parser parser : getReportParsersList()) { + File logFile = parser.getFile(); + if (logFile != null && logFile.exists()) { + logFiles.add(logFile); + } + } + if (logFiles.isEmpty()) { + return; + } else if (logFiles.size() == 1) { + // 1 file -> open it + FileManagerSupport.open(logFiles.get(0)); + } else { + // 1+ files -> retrive parent folders + List parentFolders = new ArrayList<>(); + for (File logFile : logFiles) { + File parentFile = logFile.getParentFile(); + if (!parentFolders.contains(parentFile)) { + parentFolders.add(parentFile); } } - } catch (Exception e1) { - JOptionPane.showMessageDialog(SwingUtilities.getWindowAncestor(AbstractParserView.this), e1.getMessage(), "Export Error", JOptionPane.ERROR_MESSAGE); - logger.error("Cannot open log file", e1.getMessage()); + if (parentFolders.size() == 1) { + // 1 parent folder -> open it + FileManagerSupport.open(parentFolders.get(0)); + } else { + // 1+ parent folders -> open common parent folder that is the function object folder + FileManagerSupport.open(parentFolders.get(0).getParentFile()); + + } } } @@ -198,28 +237,30 @@ public abstract class AbstractParserView extends JPanel implements ParserView { @Override public void exportToPNG() { - AbstractChartPanel chartPanel = (AbstractChartPanel) tabbedPane.getSelectedComponent(); + AbstractChart chart = getSelectedChart(); File pngFile = FileChooserUtils.getPNGFile(); - if (pngFile != null && chartPanel != null) { + if (pngFile != null && chart != null) { + JFreeChart jfreeChart = chart.getChartPanel().getChart(); // PRE-SAVE - chartPanel.getChart().setBackgroundPaint(Color.WHITE); - if (chartPanel.getChart().getLegend() != null) { - chartPanel.getChart().getLegend().setBackgroundPaint(Color.WHITE); - chartPanel.getChart().getLegend().setVisible(true); + jfreeChart.setBackgroundPaint(Color.WHITE); + if (jfreeChart.getLegend() != null) { + jfreeChart.getLegend().setBackgroundPaint(Color.WHITE); + jfreeChart.getLegend().setVisible(true); } // SAVE try { - ChartUtilities.saveChartAsPNG(pngFile, chartPanel.getChart(), chartPanel.getSize().width, chartPanel.getSize().height); + ChartUtilities.saveChartAsPNG(pngFile, jfreeChart, chart.getChartPanel().getSize().width, chart.getChartPanel().getSize().height); } catch (IOException e1) { e1.printStackTrace(); } // POST-SAVE - chartPanel.getChart().setBackgroundPaint(new Color(0, 0, 0, 0)); - if (chartPanel.getChart().getLegend() != null) { - chartPanel.getChart().getLegend().setBackgroundPaint(new Color(0, 0, 0, 0)); - chartPanel.getChart().getLegend().setVisible(false); + jfreeChart.setBackgroundPaint(new Color(0, 0, 0, 0)); + if (jfreeChart.getLegend() != null) { + jfreeChart.getLegend().setBackgroundPaint(new Color(0, 0, 0, 0)); + jfreeChart.getLegend().setVisible(false); } + FileManagerSupport.open(pngFile); } else { logger.error("Problem saving chart to PNG"); @@ -232,11 +273,13 @@ public abstract class AbstractParserView extends JPanel implements ParserView { @Override public void run() { JOptionPane.showMessageDialog(SwingUtilities.getWindowAncestor(AbstractParserView.this), e.getMessage(), "Export Error", JOptionPane.ERROR_MESSAGE); - logger.error("Cannot export", e.getMessage()); + logger.error("Export Error", e.getMessage()); } }); } + public abstract AbstractChart getSelectedChart(); + @Override public boolean isParsingEnabled() { return parsingEnabled; @@ -252,11 +295,15 @@ public abstract class AbstractParserView extends JPanel implements ParserView { return this; } + @Override + public void stop() { + } + protected class EnableParsing implements Runnable { @Override public void run() { setParsingEnabled(true); - ActionManager.getInstance().invoke("solver.refresh.once"); + ActionManager.getInstance().invoke(REFRESH_ONCE); if (!model.getSolverModel().getServerState().getSolverState().isDoingSomething()) { setParsingEnabled(false); } diff --git a/src/eu/engys/gui/solver/postprocessing/panels/HistoryChart.java b/src/eu/engys/gui/solver/postprocessing/panels/HistoryChart.java new file mode 100644 index 0000000..d764986 --- /dev/null +++ b/src/eu/engys/gui/solver/postprocessing/panels/HistoryChart.java @@ -0,0 +1,93 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.gui.solver.postprocessing.panels; + +import org.jfree.chart.ChartFactory; +import org.jfree.chart.JFreeChart; +import org.jfree.chart.axis.NumberAxis; +import org.jfree.chart.labels.StandardXYToolTipGenerator; +import org.jfree.chart.plot.DatasetRenderingOrder; +import org.jfree.chart.plot.PlotOrientation; +import org.jfree.chart.plot.XYPlot; +import org.jfree.chart.renderer.xy.StandardXYItemRenderer; +import org.jfree.data.xy.XYSeriesCollection; + +import eu.engys.core.modules.AbstractChart; +import eu.engys.util.ui.textfields.DoubleField; + +public abstract class HistoryChart extends OverlayableMovingAverageChart { + + public HistoryChart() { + super(); + } + + @Override + protected JFreeChart createChart() { + JFreeChart chart = ChartFactory.createXYLineChart("", "", "", new XYSeriesCollection(), PlotOrientation.VERTICAL, true, true, false); + + NumberAxis domainAxis = new NumberAxis(""); + domainAxis.setAutoRangeIncludesZero(false); + domainAxis.setAutoRange(true); + + NumberAxis rangeAxis = new NumberAxis(""); + rangeAxis.setNumberFormatOverride(DoubleField.getFormatForDISPLAY(10)); + rangeAxis.setAutoRangeIncludesZero(false); + rangeAxis.setAutoRange(true); + + XYPlot xyplot = chart.getXYPlot(); + xyplot.setDomainAxis(domainAxis); + xyplot.setRangeAxis(rangeAxis); + xyplot.setDataset(AbstractChart.MOVING_AVERAGE_DATASET_INDEX, movingAverageDataSet); + + StandardXYItemRenderer movingAverageRenderer = new StandardXYItemRenderer(); + movingAverageRenderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator()); + chart.getXYPlot().setRenderer(MOVING_AVERAGE_DATASET_INDEX, movingAverageRenderer); + chart.getXYPlot().setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD); + + return chart; + } + + @Override + public XYSeriesCollection getXYDataset(int index) { + return (XYSeriesCollection) super.getXYDataset(index); + } + + @Override + public void _clearData() { + super._clearData(); + getXYDataset(DATASET_INDEX).removeAllSeries(); + } + + @Override + protected void notifySeries(boolean notify) { + super.notifySeries(notify); + XYSeriesCollection dataset = (XYSeriesCollection) getXYDataset(DATASET_INDEX); + dataset.setNotify(notify); + for (int i = 0; i < dataset.getSeriesCount(); i++) { + dataset.getSeries(i).setNotify(notify); + } + } + +} diff --git a/src/eu/engys/gui/solver/postprocessing/panels/HistoryChartPanel.java b/src/eu/engys/gui/solver/postprocessing/panels/HistoryChartPanel.java deleted file mode 100644 index 0031cf6..0000000 --- a/src/eu/engys/gui/solver/postprocessing/panels/HistoryChartPanel.java +++ /dev/null @@ -1,87 +0,0 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - -package eu.engys.gui.solver.postprocessing.panels; - -import java.util.List; - -import org.jfree.chart.ChartFactory; -import org.jfree.chart.axis.NumberAxis; -import org.jfree.chart.labels.StandardXYToolTipGenerator; -import org.jfree.chart.plot.PlotOrientation; -import org.jfree.chart.renderer.xy.StandardXYItemRenderer; -import org.jfree.data.xy.XYSeries; -import org.jfree.data.xy.XYSeriesCollection; - -import eu.engys.util.ui.textfields.DoubleField; - -public abstract class HistoryChartPanel extends MovingAverageChartPanel { - - private static final long serialVersionUID = 1L; - - protected List seriesNames; - - public HistoryChartPanel(String title, List seriesNames, String domainAxisLabel, String rangeAxisLabel, boolean showMovingAverage) { - super(title, domainAxisLabel, rangeAxisLabel, showMovingAverage); - this.seriesNames = seriesNames; - this.dataset = new XYSeriesCollection(); - } - - @Override - public void initSeries() { - for (String serieName : seriesNames) { - XYSeries series = new XYSeries(serieName); - dataset.addSeries(series); - populateSeriesPanel(dataset.getSeriesIndex(series.getKey()), series.getKey().toString()); - } - } - - @Override - protected void createChart() { - this.chart = ChartFactory.createXYLineChart("", "", "", dataset, PlotOrientation.VERTICAL, true, true, false); - - NumberAxis domainAxis = new NumberAxis(domainAxisLabel); - domainAxis.setAutoRangeIncludesZero(false); - - NumberAxis rangeAxis = new NumberAxis(rangeAxisLabel); - rangeAxis.setNumberFormatOverride(DoubleField.getFormatForDISPLAY(10)); - - chart.getXYPlot().setDomainAxis(domainAxis); - chart.getXYPlot().setRangeAxis(rangeAxis); - chart.getXYPlot().setDataset(1, movingAverageDataSet); - - StandardXYItemRenderer movingAverageRenderer = new StandardXYItemRenderer(); - movingAverageRenderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator()); - chart.getXYPlot().setRenderer(1, movingAverageRenderer); - } - - @Override - protected void clearDataset() { - for (int i = 0; i < dataset.getSeriesCount(); i++) { - dataset.getSeries(i).clear(); - } - } - -} diff --git a/src/eu/engys/gui/solver/postprocessing/panels/MovingAverageChart.java b/src/eu/engys/gui/solver/postprocessing/panels/MovingAverageChart.java new file mode 100644 index 0000000..90628ce --- /dev/null +++ b/src/eu/engys/gui/solver/postprocessing/panels/MovingAverageChart.java @@ -0,0 +1,110 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.gui.solver.postprocessing.panels; + +import static eu.engys.gui.solver.postprocessing.panels.utils.SeriesInfo.SERIES_INFO_PROPERTY; + +import java.awt.Color; +import java.util.HashMap; +import java.util.Map; + +import javax.swing.BorderFactory; +import javax.swing.JPanel; +import javax.swing.JScrollPane; + +import org.jfree.data.xy.XYSeriesCollection; + +import eu.engys.core.project.state.State; +import eu.engys.gui.solver.postprocessing.panels.utils.ChartUtils; +import eu.engys.gui.solver.postprocessing.panels.utils.MavgSeriesPanel; +import eu.engys.gui.solver.postprocessing.panels.utils.SeriesInfo; +import eu.engys.gui.solver.postprocessing.panels.utils.SeriesVisibilityListener; + +public abstract class MovingAverageChart extends SeriesChart { + + protected XYSeriesCollection movingAverageDataSet; + private MavgSeriesPanel movingAverageSeriesPanel; + private Map mavgSeriesInfoMap = new HashMap<>(); + + public MovingAverageChart() { + super(); + this.movingAverageDataSet = new XYSeriesCollection(); + } + + @Override + protected JPanel createRightPanel() { + this.movingAverageSeriesPanel = new MavgSeriesPanel(getXYDataset(DATASET_INDEX), movingAverageDataSet); + movingAverageSeriesPanel.addPropertyChangeListener(SERIES_INFO_PROPERTY, new SeriesVisibilityListener()); + + JPanel rightPanel = super.createRightPanel(); + + JScrollPane movingAverageSeriesScrollPane = new JScrollPane(movingAverageSeriesPanel); + movingAverageSeriesScrollPane.setBorder(BorderFactory.createEmptyBorder()); + + rightPanel.add(movingAverageSeriesScrollPane); + + return rightPanel; + } + + protected void applyMavgGraphicProperties(String seriesKey) { + if (!mavgSeriesInfoMap.containsKey(seriesKey)) { + int mavgSeriesIndex = ChartUtils.getSeriesIndex(movingAverageDataSet, seriesKey); + Color mavgColor = ChartUtils.coloForMAVGSerie(getXYPlot(), mavgSeriesIndex); + boolean defaultVisibility = false; + mavgSeriesInfoMap.put(seriesKey, new SeriesInfo(getXYPlot(), MOVING_AVERAGE_DATASET_INDEX, seriesKey, mavgColor, defaultVisibility)); + } + ChartUtils.applyGraphicProperties(getXYPlot(), mavgSeriesInfoMap.get(seriesKey)); + } + + protected void populateMovingAverageSeriesPanel(String seriesKey) { + movingAverageSeriesPanel.addSeries(mavgSeriesInfoMap.get(seriesKey)); + } + + @Override + public void postAddToDataSet() { + movingAverageSeriesPanel.updateMovingAverage(); + } + + @Override + public void _clearData() { + super._clearData(); + movingAverageSeriesPanel.clear(); + movingAverageDataSet.removeAllSeries(); + } + + @Override + protected void notifySeries(boolean notify) { + movingAverageDataSet.setNotify(notify); + for (int i = 0; i < movingAverageDataSet.getSeriesCount(); i++) { + movingAverageDataSet.getSeries(i).setNotify(notify); + } + } + + @Override + public void handleStateChanged(State state) { + ChartUtils.updateDomainAxisLabel(state, getXYPlot()); + } + +} diff --git a/src/eu/engys/gui/solver/postprocessing/panels/MovingAverageChartPanel.java b/src/eu/engys/gui/solver/postprocessing/panels/MovingAverageChartPanel.java deleted file mode 100644 index e54469e..0000000 --- a/src/eu/engys/gui/solver/postprocessing/panels/MovingAverageChartPanel.java +++ /dev/null @@ -1,235 +0,0 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - -package eu.engys.gui.solver.postprocessing.panels; - -import java.awt.BasicStroke; -import java.awt.BorderLayout; -import java.awt.Color; -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; - -import javax.swing.BorderFactory; -import javax.swing.JScrollPane; -import javax.swing.JSplitPane; - -import org.jfree.chart.ChartMouseEvent; -import org.jfree.chart.ChartMouseListener; -import org.jfree.chart.plot.Crosshair; -import org.jfree.chart.plot.XYPlot; -import org.jfree.chart.renderer.xy.XYItemRenderer; -import org.jfree.data.general.DatasetUtilities; -import org.jfree.data.xy.AbstractIntervalXYDataset; -import org.jfree.data.xy.XYSeriesCollection; -import org.jfree.ui.RectangleEdge; - -import eu.engys.core.project.system.monitoringfunctionobjects.TimeBlock; -import eu.engys.core.project.system.monitoringfunctionobjects.TimeBlocks; -import eu.engys.gui.solver.postprocessing.panels.utils.MovingAveragePanel; -import eu.engys.gui.solver.postprocessing.panels.utils.SeriesPanel; -import eu.engys.util.ui.ExecUtil; - -public abstract class MovingAverageChartPanel extends AbstractChartPanel { - - private static final long serialVersionUID = 1L; - - protected SeriesPanel seriesPanel; - protected MovingAveragePanel movingAveragePanel; - - protected D dataset; - protected XYSeriesCollection movingAverageDataSet; - private boolean showMovingAverage; - - private CrosshairListener crosshairListener; - - public MovingAverageChartPanel(String title, String domainAxisLabel, String rangeAxisLabel, boolean showMovingAverage) { - super(title, domainAxisLabel, rangeAxisLabel); - setName(title + ".chart.panel"); - this.showMovingAverage = showMovingAverage; - this.movingAverageDataSet = new XYSeriesCollection(); - this.crosshairListener = new CrosshairListener(); - } - - @Override - public void layoutComponents() { - super.layoutComponents(); - chartPanel.addOverlay(overlay); - - this.seriesPanel = new SeriesPanel(showMovingAverage ? movingAveragePanel = new MovingAveragePanel(dataset, movingAverageDataSet) : null); - - JScrollPane seriesScrollPane = new JScrollPane(seriesPanel); - seriesScrollPane.setBorder(BorderFactory.createEmptyBorder()); - - JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT); - splitPane.setOneTouchExpandable(false); - splitPane.setLeftComponent(chartPanel); - splitPane.setRightComponent(seriesScrollPane); - - double scrollPaneWidth = splitPane.getPreferredSize().getWidth(); - double seriesPanelWidth = seriesPanel.getPreferredSize().getWidth(); - if (seriesPanelWidth != 0 && scrollPaneWidth != 0) { - double value = 1 - (seriesPanelWidth / scrollPaneWidth) - 0.07; - splitPane.setResizeWeight(value); - } else { - splitPane.setResizeWeight(0.9); - } - add(splitPane, BorderLayout.CENTER); - } - - public void setCrosshairVisible(boolean visible) { - if (visible) { - chartPanel.addChartMouseListener(crosshairListener); - chartPanel.addMouseListener(crosshairListener); - } else { - chartPanel.removeChartMouseListener(crosshairListener); - chartPanel.removeMouseListener(crosshairListener); - removeCrosshair(); - } - } - - @Override - public void addToDataSet(final TimeBlocks list) { - synchronized (list) { - ExecUtil.invokeLater(new Runnable() { - @Override - public void run() { - notifySeries(false); - for (final TimeBlock block : list) { - addTimeBlock(block); - } - if(showMovingAverage){ - movingAveragePanel.updateMovingAverageDataset(); - } - notifySeries(true); - refreshGUI(); - } - }); - } - } - - protected abstract void addTimeBlock(final TimeBlock block); - - protected void populateSeriesPanel(int seriesIndex, String seriesTitle) { - XYItemRenderer baseRenderer = chart.getXYPlot().getRenderer(); - seriesPanel.addSeries(baseRenderer, seriesIndex, seriesTitle); - - if (showMovingAverage) { - XYItemRenderer renderer = chart.getXYPlot().getRenderer(1); - renderer.setSeriesPaint(seriesIndex, ((Color) baseRenderer.getItemPaint(seriesIndex, 0)).darker().darker()); - renderer.setSeriesStroke(seriesIndex, new BasicStroke(1)); - seriesPanel.addMovingAverageSeries(renderer, seriesIndex, seriesTitle); - } - } - - @Override - public void clearData() { - notifySeries(false); - clearDataset(); - clearMovingAverageDataset(); - notifySeries(true); - removeCrosshair(); - chartPanel.restoreAutoDomainBounds(); - } - - protected abstract void clearDataset(); - - private void clearMovingAverageDataset() { - for (int i = 0; i < movingAverageDataSet.getSeriesCount(); i++) { - movingAverageDataSet.getSeries(i).clear(); - } - } - - protected void notifySeries(boolean notify) { - dataset.setNotify(notify); - movingAverageDataSet.setNotify(notify); - } - - protected void refreshGUI() { - ExecUtil.invokeLater(new Runnable() { - @Override - public void run() { - seriesPanel.revalidate(); - chartPanel.revalidate(); - chartPanel.repaint(); - } - }); - } - - private void removeCrosshair() { - ((Crosshair) overlay.getDomainCrosshairs().get(0)).setValue(Double.NaN); - ((Crosshair) overlay.getRangeCrosshairs().get(0)).setValue(Double.NaN); - } - - @Override - public void stop() { - } - - private class CrosshairListener extends MouseAdapter implements ChartMouseListener { - - @Override - public void chartMouseClicked(ChartMouseEvent arg0) { - } - - @Override - public void chartMouseMoved(ChartMouseEvent event) { - if (chart.getPlot() instanceof XYPlot) { - XYPlot plot = (XYPlot) chart.getPlot(); - double x = plot.getDomainAxis().java2DToValue(event.getTrigger().getX(), chartPanel.getScreenDataArea(), RectangleEdge.BOTTOM); - // make the crosshairs disappear if the mouse is out of range - if (!plot.getDomainAxis().getRange().contains(x)) { - x = Double.NaN; - } - ((Crosshair) overlay.getDomainCrosshairs().get(0)).setValue(x); - - double y = DatasetUtilities.findYValue(dataset, getClosestSeriesIndex(x, event.getTrigger().getY()), x); - ((Crosshair) overlay.getRangeCrosshairs().get(0)).setValue(y); - } - - } - - private int getClosestSeriesIndex(double x, int compare) { - int series = 0; - double distance = Double.MAX_VALUE; - for (int i = 0; i < dataset.getSeriesCount(); i++) { - double y = DatasetUtilities.findYValue(dataset, i, x); - double toCompare = ((XYPlot) chart.getPlot()).getRangeAxis().java2DToValue(compare, chartPanel.getScreenDataArea(), ((XYPlot) chart.getPlot()).getRangeAxisEdge()); - - if (Math.abs(y - toCompare) < distance) { - distance = Math.abs(y - toCompare); - series = i; - } - } - - return series; - } - - @Override - public void mouseExited(MouseEvent e) { - removeCrosshair(); - } - - } - -} diff --git a/src/eu/engys/gui/solver/postprocessing/panels/NonPredefinedSeriesChart.java b/src/eu/engys/gui/solver/postprocessing/panels/NonPredefinedSeriesChart.java new file mode 100644 index 0000000..c239f63 --- /dev/null +++ b/src/eu/engys/gui/solver/postprocessing/panels/NonPredefinedSeriesChart.java @@ -0,0 +1,84 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.gui.solver.postprocessing.panels; + +import org.jfree.data.xy.XYSeries; +import org.jfree.data.xy.XYSeriesCollection; + +import eu.engys.core.project.system.monitoringfunctionobjects.TimeBlock; +import eu.engys.core.project.system.monitoringfunctionobjects.TimeBlockUnit; +import eu.engys.core.project.system.monitoringfunctionobjects.TimeBlocks; + +public abstract class NonPredefinedSeriesChart extends HistoryChart { + + public NonPredefinedSeriesChart() { + super(); + } + + @Override + public void _addToDataSet(TimeBlocks list) { + for (TimeBlock block : list) { + for (TimeBlockUnit unit : block.getUnitsMap().values()) { + addTimeUnit(block.getTime(), unit); + } + } + for (TimeBlock block : list) { + for (TimeBlockUnit unit : block.getUnitsMap().values()) { + addMovingAverageSerie(unit); + } + } + } + + protected abstract void addTimeUnit(double time, TimeBlockUnit unit); + + protected abstract void addMovingAverageSerie(TimeBlockUnit unit); + + protected XYSeriesCollection addSerie(TimeBlockUnit unit) { + XYSeriesCollection dataset = getXYDataset(DATASET_INDEX); + if (dataset.getSeriesIndex(unit.getVarName()) == -1) { + XYSeries serie = new XYSeries(unit.getVarName()); + serie.setNotify(false); + dataset.addSeries(serie); + + applyGraphicProperties(unit.getVarName()); + populateSeriesPanel(unit.getVarName()); + } + return dataset; + } + + protected void _addMovingAverageSerie(TimeBlockUnit unit) { + String varName = unit.getVarName(); + XYSeriesCollection mavgDataset = getXYDataset(MOVING_AVERAGE_DATASET_INDEX); + if (mavgDataset.getSeriesIndex(varName) == -1) { + XYSeries serie = new XYSeries(varName); + serie.setNotify(false); + movingAverageDataSet.addSeries(serie); + + applyMavgGraphicProperties(varName); + populateMovingAverageSeriesPanel(varName); + } + } + +} \ No newline at end of file diff --git a/src/eu/engys/gui/solver/postprocessing/panels/OverlayableMovingAverageChart.java b/src/eu/engys/gui/solver/postprocessing/panels/OverlayableMovingAverageChart.java new file mode 100644 index 0000000..d0d14b7 --- /dev/null +++ b/src/eu/engys/gui/solver/postprocessing/panels/OverlayableMovingAverageChart.java @@ -0,0 +1,199 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.gui.solver.postprocessing.panels; + +import java.awt.BasicStroke; +import java.awt.Color; +import java.awt.event.MouseListener; +import java.util.ArrayList; +import java.util.EventListener; +import java.util.List; + +import javax.swing.JComponent; +import javax.swing.JSplitPane; + +import org.jfree.chart.ChartMouseListener; +import org.jfree.chart.panel.CrosshairOverlay; +import org.jfree.chart.plot.Crosshair; +import org.jfree.chart.plot.ValueMarker; +import org.jfree.ui.TextAnchor; + +import eu.engys.gui.events.EventManager; +import eu.engys.gui.events.EventManager.Event; +import eu.engys.gui.events.EventManager.GenericEventListener; +import eu.engys.gui.events.application.ApplicationEvent; +import eu.engys.gui.solver.postprocessing.panels.utils.ChartUtils; +import eu.engys.gui.solver.postprocessing.panels.utils.CrosshairListener; +import eu.engys.gui.solver.postprocessing.panels.utils.MarkersTable; +import eu.engys.gui.solver.postprocessing.panels.utils.events.AddMarkerEvent; +import eu.engys.gui.solver.postprocessing.panels.utils.events.CrosshairChangedEvent; +import eu.engys.gui.solver.postprocessing.panels.utils.events.ShowCrosshairEvent; +import eu.engys.gui.solver.postprocessing.panels.utils.events.ShowMarkersTableEvent; +import eu.engys.gui.solver.postprocessing.panels.utils.markers.Marker; +import eu.engys.util.ui.ExecUtil; +import eu.engys.util.ui.UiUtil; + +public abstract class OverlayableMovingAverageChart extends MovingAverageChart implements GenericEventListener { + + private static final Color MARKER_COLOR = Color.BLACK; + private static final BasicStroke MARKER_STROKE = new BasicStroke(1f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 1.0f, new float[]{1.0f}, 0.0f); + + private CrosshairOverlay overlay; + private MarkersTable markersTable; + private CrosshairListener crosshairListener; + private JSplitPane mainPanel; + + private List markers; + + public OverlayableMovingAverageChart() { + super(); + this.markers = new ArrayList(); + EventManager.registerEventListener(this, ApplicationEvent.class); + } + + @Override + public void layoutComponents() { + super.layoutComponents(); + + this.overlay = ChartUtils.createOverlay(); + getChartPanel().addOverlay(overlay); + + this.markersTable = new MarkersTable(getChartPanel()); + this.crosshairListener = new CrosshairListener(getChartPanel(), overlay); + + this.mainPanel = new JSplitPane(JSplitPane.VERTICAL_SPLIT); + this.mainPanel.setOneTouchExpandable(false); + this.mainPanel.setTopComponent(super.getPanel()); + this.mainPanel.setBottomComponent(markersTable.getPanel()); + + setMarkersTableVisible(false); + } + + @Override + public void eventTriggered(Object obj, final Event event) { + ExecUtil.invokeLater(new Runnable() { + @Override + public void run() { + if (event instanceof ShowCrosshairEvent) { + // from crosshair button in toolbar + setCrosshairVisible(((ShowCrosshairEvent) event).isActive()); + } else if (event instanceof ShowMarkersTableEvent) { + // from X button on table + setMarkersTableVisible(((ShowMarkersTableEvent) event).isVisible()); + } else if (event instanceof AddMarkerEvent) { + addMarker(((AddMarkerEvent) event).getX()); + } else if (event instanceof CrosshairChangedEvent) { + Marker oldValue = ((CrosshairChangedEvent) event).getOldValue(); + Marker newValue = ((CrosshairChangedEvent) event).getNewValue(); + markers.remove(oldValue); + markers.add(newValue); + + loadMarkers(); + markersTable.loadMarkers(markers); + } + } + }); + } + + @Override + public void _clearData() { + super._clearData(); + clearMarkers(); + } + + private void clearMarkers() { + markers.clear(); + loadMarkers(); + markersTable.clear(); + } + + @Override + public void postAddToDataSet() { + super.postAddToDataSet(); + markersTable.loadMarkers(markers); + } + + private void addMarker(Double iteration) { + markers.add(new Marker(iteration)); + loadMarkers(); + markersTable.loadMarkers(markers); + setMarkersTableVisible(true); + } + + private void loadMarkers() { + getChartPanel().getChart().getXYPlot().clearDomainMarkers(); + for (Marker marker : markers) { + ValueMarker valueMarker = new ValueMarker(marker.getValue(), MARKER_COLOR, MARKER_STROKE); + valueMarker.setLabel(ChartUtils.SERIES_DECIMAL_FORMAT.format(marker.getValue())); + valueMarker.setLabelTextAnchor(TextAnchor.TOP_CENTER); + getXYPlot().addDomainMarker(valueMarker); + } + } + + // public for test purposes only + public void setCrosshairVisible(boolean visible) { + if (visible) { + for (EventListener chartListener : getChartPanel().getListeners(ChartMouseListener.class)) { + if (chartListener instanceof CrosshairListener) { + getChartPanel().removeChartMouseListener((ChartMouseListener) chartListener); + } + } + for (MouseListener mouseListener : getChartPanel().getMouseListeners()) { + if (mouseListener instanceof CrosshairListener) { + getChartPanel().removeMouseListener(mouseListener); + } + } + getChartPanel().addChartMouseListener(crosshairListener); + getChartPanel().addMouseListener(crosshairListener); + } else { + getChartPanel().removeChartMouseListener(crosshairListener); + getChartPanel().removeMouseListener(crosshairListener); + + ((Crosshair) overlay.getDomainCrosshairs().get(0)).setValue(Double.NaN); + ((Crosshair) overlay.getRangeCrosshairs().get(0)).setValue(Double.NaN); + } + } + + // public for test purposes only + public void setMarkersTableVisible(boolean visible) { + if (visible) { + UiUtil.expandSplitPane(mainPanel, markersTable.getPanel(), 0.9, 100); + } else { + clearMarkers(); + UiUtil.collapseSplitPane(mainPanel); + } + + } + + public List getMarkers() { + return markers; + } + + @Override + public JComponent getPanel() { + return mainPanel; + } + +} diff --git a/src/eu/engys/gui/solver/postprocessing/panels/PredefinedSeriesChart.java b/src/eu/engys/gui/solver/postprocessing/panels/PredefinedSeriesChart.java new file mode 100644 index 0000000..23de46c --- /dev/null +++ b/src/eu/engys/gui/solver/postprocessing/panels/PredefinedSeriesChart.java @@ -0,0 +1,77 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.gui.solver.postprocessing.panels; + +import java.util.List; + +import org.jfree.data.xy.XYSeries; +import org.jfree.data.xy.XYSeriesCollection; + +import eu.engys.core.project.system.monitoringfunctionobjects.TimeBlock; +import eu.engys.core.project.system.monitoringfunctionobjects.TimeBlockUnit; +import eu.engys.core.project.system.monitoringfunctionobjects.TimeBlocks; + +public abstract class PredefinedSeriesChart extends HistoryChart { + + protected List seriesNames; + + public PredefinedSeriesChart(List seriesNames) { + super(); + this.seriesNames = seriesNames; + } + + @Override + public void _addToDataSet(TimeBlocks list) { + for (TimeBlock block : list) { + XYSeriesCollection dataset = getXYDataset(DATASET_INDEX); + for (String serieName : seriesNames) { + if (dataset.getSeriesIndex(serieName) == -1) { + XYSeries serie = new XYSeries(serieName); + serie.setNotify(false); + dataset.addSeries(serie); + applyGraphicProperties(serieName); + populateSeriesPanel(serieName); + } + addTimeUnit(block.getTime(), block.getUnitsMap().get(serieName)); + } + for (String varName : seriesNames) { + if (movingAverageDataSet.getSeriesIndex(varName) == -1) { + XYSeries serie = new XYSeries(varName); + serie.setNotify(false); + movingAverageDataSet.addSeries(serie); + applyMavgGraphicProperties(varName); + populateMovingAverageSeriesPanel(varName); + } + } + } + } + + protected abstract void addTimeUnit(double time, TimeBlockUnit unit); + + public List getSeriesNames() { + return seriesNames; + } + +} \ No newline at end of file diff --git a/src/eu/engys/gui/solver/postprocessing/panels/SeriesChart.java b/src/eu/engys/gui/solver/postprocessing/panels/SeriesChart.java new file mode 100644 index 0000000..7498ea6 --- /dev/null +++ b/src/eu/engys/gui/solver/postprocessing/panels/SeriesChart.java @@ -0,0 +1,135 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.gui.solver.postprocessing.panels; + +import static eu.engys.gui.solver.postprocessing.panels.utils.SeriesInfo.SERIES_INFO_PROPERTY; + +import java.awt.BorderLayout; +import java.awt.Color; +import java.awt.GridLayout; +import java.util.HashMap; +import java.util.Map; + +import javax.swing.BorderFactory; +import javax.swing.JComponent; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JSplitPane; + +import eu.engys.core.modules.AbstractChart; +import eu.engys.core.project.state.State; +import eu.engys.gui.solver.postprocessing.panels.utils.ChartUtils; +import eu.engys.gui.solver.postprocessing.panels.utils.SeriesInfo; +import eu.engys.gui.solver.postprocessing.panels.utils.SeriesPanel; +import eu.engys.gui.solver.postprocessing.panels.utils.SeriesVisibilityListener; + +public abstract class SeriesChart extends AbstractChart { + + private JSplitPane mainPanel; + private SeriesPanel seriesPanel; + protected Map seriesInfoMap = new HashMap<>(); + + public SeriesChart() { + super(); + } + + @Override + public void layoutComponents() { + super.layoutComponents(); + + JPanel chartPanel = new JPanel(new BorderLayout()); + + JComponent accessory = createChartAccessory(); + if (accessory != null) { + JSplitPane accessorySplit = new JSplitPane(JSplitPane.VERTICAL_SPLIT); + accessorySplit.setTopComponent(getChartPanel()); + + JScrollPane scroll = new JScrollPane(accessory); + scroll.setBorder(BorderFactory.createEmptyBorder()); + accessorySplit.setBottomComponent(scroll); + accessorySplit.setResizeWeight(0.9); + accessorySplit.setOneTouchExpandable(false); + chartPanel.add(accessorySplit, BorderLayout.CENTER); + } else { + chartPanel.add(getChartPanel(), BorderLayout.CENTER); + } + + this.mainPanel = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT); + mainPanel.setOneTouchExpandable(false); + mainPanel.setLeftComponent(chartPanel); + mainPanel.setRightComponent(createRightPanel()); + mainPanel.setResizeWeight(0.8); + } + + protected JPanel createRightPanel() { + this.seriesPanel = new SeriesPanel(); + seriesPanel.addPropertyChangeListener(SERIES_INFO_PROPERTY, new SeriesVisibilityListener()); + + JScrollPane seriesScrollPane = new JScrollPane(seriesPanel); + seriesScrollPane.setBorder(BorderFactory.createEmptyBorder()); + + JPanel rightPanel = new JPanel(new GridLayout(0, 1)); + rightPanel.add(seriesScrollPane); + + return rightPanel; + } + + protected JComponent createChartAccessory() { + return null; + } + + @Override + public JComponent getPanel() { + return mainPanel; + } + + protected void applyGraphicProperties(String seriesKey) { + if (!seriesInfoMap.containsKey(seriesKey)) { + int seriesIndex = ChartUtils.getSeriesIndex(getXYDataset(DATASET_INDEX), seriesKey); + Color color = ChartUtils.colorForSerie(getXYPlot(), seriesIndex); + boolean defaultVisibility = true; + seriesInfoMap.put(seriesKey, new SeriesInfo(getXYPlot(), DATASET_INDEX, seriesKey, color, defaultVisibility)); + } + ChartUtils.applyGraphicProperties(getXYPlot(), seriesInfoMap.get(seriesKey)); + } + + protected void populateSeriesPanel(String seriesKey) { + seriesPanel.addSeries(seriesInfoMap.get(seriesKey)); + } + + @Override + public void handleStateChanged(State state) { + } + + @Override + public void _clearData() { + seriesPanel.clear(); + } + + public SeriesPanel getSeriesPanel() { + return seriesPanel; + } + +} diff --git a/src/eu/engys/gui/solver/postprocessing/panels/actions/DeleteLogFileAction.java b/src/eu/engys/gui/solver/postprocessing/panels/actions/DeleteLogFileAction.java new file mode 100644 index 0000000..54498e1 --- /dev/null +++ b/src/eu/engys/gui/solver/postprocessing/panels/actions/DeleteLogFileAction.java @@ -0,0 +1,51 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.gui.solver.postprocessing.panels.actions; + +import java.awt.event.ActionEvent; + +import javax.swing.AbstractAction; +import javax.swing.Icon; + +import eu.engys.gui.solver.postprocessing.panels.utils.SelectedViewProvider; +import eu.engys.util.ui.ResourcesUtil; + +public class DeleteLogFileAction extends AbstractAction { + + private static final Icon LOG_FILE_ICON = ResourcesUtil.getIcon("delete.log.file"); + private SelectedViewProvider selector; + + public DeleteLogFileAction(SelectedViewProvider selector) { + super("", LOG_FILE_ICON); + this.selector = selector; + putValue(SHORT_DESCRIPTION, "Delete log files"); + } + + @Override + public void actionPerformed(ActionEvent e) { + selector.getSelectedView().deleteLogFiles(); + + } +} \ No newline at end of file diff --git a/src/eu/engys/gui/solver/postprocessing/panels/actions/ExportToCSVAction.java b/src/eu/engys/gui/solver/postprocessing/panels/actions/ExportToCSVAction.java index 9415791..7dd09ed 100644 --- a/src/eu/engys/gui/solver/postprocessing/panels/actions/ExportToCSVAction.java +++ b/src/eu/engys/gui/solver/postprocessing/panels/actions/ExportToCSVAction.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.solver.postprocessing.panels.actions; import java.awt.event.ActionEvent; @@ -35,7 +34,7 @@ import eu.engys.util.ui.ResourcesUtil; public class ExportToCSVAction extends AbstractAction { - private static final Icon CSV_ICON = ResourcesUtil.getIcon("file"); + private static final Icon CSV_ICON = ResourcesUtil.getIcon("file.icon"); private SelectedViewProvider selector; public ExportToCSVAction(SelectedViewProvider selector) { @@ -49,4 +48,4 @@ public class ExportToCSVAction extends AbstractAction { selector.getSelectedView().exportToCSV(); } -} +} \ No newline at end of file diff --git a/src/eu/engys/gui/solver/postprocessing/panels/actions/ExportToExcelAction.java b/src/eu/engys/gui/solver/postprocessing/panels/actions/ExportToExcelAction.java index ab6ec01..1aba4bd 100644 --- a/src/eu/engys/gui/solver/postprocessing/panels/actions/ExportToExcelAction.java +++ b/src/eu/engys/gui/solver/postprocessing/panels/actions/ExportToExcelAction.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.solver.postprocessing.panels.actions; import java.awt.event.ActionEvent; @@ -48,4 +47,4 @@ public class ExportToExcelAction extends AbstractAction { public void actionPerformed(ActionEvent e) { selector.getSelectedView().exportToExcel(); } -} +} \ No newline at end of file diff --git a/src/eu/engys/gui/solver/postprocessing/panels/actions/ExportToPNGAction.java b/src/eu/engys/gui/solver/postprocessing/panels/actions/ExportToPNGAction.java index d36d294..e0d1cd8 100644 --- a/src/eu/engys/gui/solver/postprocessing/panels/actions/ExportToPNGAction.java +++ b/src/eu/engys/gui/solver/postprocessing/panels/actions/ExportToPNGAction.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.solver.postprocessing.panels.actions; import java.awt.event.ActionEvent; @@ -49,4 +48,4 @@ public class ExportToPNGAction extends AbstractAction { selector.getSelectedView().exportToPNG(); } -} +} \ No newline at end of file diff --git a/src/eu/engys/gui/solver/postprocessing/panels/actions/ShowCrosshairAction.java b/src/eu/engys/gui/solver/postprocessing/panels/actions/ShowCrosshairAction.java index 4581e64..93511dc 100644 --- a/src/eu/engys/gui/solver/postprocessing/panels/actions/ShowCrosshairAction.java +++ b/src/eu/engys/gui/solver/postprocessing/panels/actions/ShowCrosshairAction.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.solver.postprocessing.panels.actions; import java.awt.event.ActionEvent; @@ -31,26 +30,22 @@ import javax.swing.AbstractAction; import javax.swing.AbstractButton; import javax.swing.Icon; -import eu.engys.core.project.Model; -import eu.engys.core.project.system.monitoringfunctionobjects.MonitoringFunctionObject; +import eu.engys.gui.events.EventManager; +import eu.engys.gui.solver.postprocessing.panels.utils.events.ShowCrosshairEvent; import eu.engys.util.ui.ResourcesUtil; public class ShowCrosshairAction extends AbstractAction { private static final Icon CROSSHAIR_ICON = ResourcesUtil.getIcon("crosshair.icon"); - private Model model; - public ShowCrosshairAction(Model model) { + public ShowCrosshairAction() { super("", CROSSHAIR_ICON); - this.model = model; putValue(SHORT_DESCRIPTION, "Show a crosshair over the chart"); } @Override public void actionPerformed(ActionEvent e) { boolean visible = ((AbstractButton) e.getSource()).isSelected(); - for (MonitoringFunctionObject fo : model.getMonitoringFunctionObjects()) { - fo.getView().setCrosshairVisibile(visible); - } + EventManager.triggerEvent(this, new ShowCrosshairEvent(visible)); } -} +} \ No newline at end of file diff --git a/src/eu/engys/gui/solver/postprocessing/panels/actions/ShowCrosshairForResidualsAction.java b/src/eu/engys/gui/solver/postprocessing/panels/actions/ShowCrosshairForResidualsAction.java deleted file mode 100644 index bf89aec..0000000 --- a/src/eu/engys/gui/solver/postprocessing/panels/actions/ShowCrosshairForResidualsAction.java +++ /dev/null @@ -1,53 +0,0 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - -package eu.engys.gui.solver.postprocessing.panels.actions; - -import java.awt.event.ActionEvent; - -import javax.swing.AbstractAction; -import javax.swing.AbstractButton; -import javax.swing.Icon; - -import eu.engys.gui.solver.postprocessing.panels.residuals.ResidualsView; -import eu.engys.util.ui.ResourcesUtil; - -public class ShowCrosshairForResidualsAction extends AbstractAction { - - private static final Icon CROSSHAIR_ICON = ResourcesUtil.getIcon("crosshair.icon"); - private ResidualsView residualsView; - - public ShowCrosshairForResidualsAction(ResidualsView residualsView) { - super("", CROSSHAIR_ICON); - this.residualsView = residualsView; - putValue(SHORT_DESCRIPTION, "Show a crosshair over the chart"); - } - - @Override - public void actionPerformed(ActionEvent e) { - boolean visible = ((AbstractButton) e.getSource()).isSelected(); - residualsView.setCrosshairVisibile(visible); - } -} diff --git a/src/eu/engys/gui/solver/postprocessing/panels/actions/ShowLogFileAction.java b/src/eu/engys/gui/solver/postprocessing/panels/actions/ShowLogFileAction.java index 54d50be..6c250cc 100644 --- a/src/eu/engys/gui/solver/postprocessing/panels/actions/ShowLogFileAction.java +++ b/src/eu/engys/gui/solver/postprocessing/panels/actions/ShowLogFileAction.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.solver.postprocessing.panels.actions; import java.awt.event.ActionEvent; @@ -48,4 +47,4 @@ public class ShowLogFileAction extends AbstractAction { public void actionPerformed(ActionEvent e) { selector.getSelectedView().showLogFile(); } -} +} \ No newline at end of file diff --git a/src/eu/engys/gui/solver/postprocessing/panels/residuals/ResidualsChart.java b/src/eu/engys/gui/solver/postprocessing/panels/residuals/ResidualsChart.java new file mode 100644 index 0000000..a1132ef --- /dev/null +++ b/src/eu/engys/gui/solver/postprocessing/panels/residuals/ResidualsChart.java @@ -0,0 +1,84 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.gui.solver.postprocessing.panels.residuals; + +import org.jfree.chart.JFreeChart; +import org.jfree.chart.axis.LogarithmicAxis; +import org.jfree.data.xy.XYSeriesCollection; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import eu.engys.core.project.system.monitoringfunctionobjects.TimeBlockUnit; +import eu.engys.gui.solver.postprocessing.data.DoubleListTimeBlockUnit; +import eu.engys.gui.solver.postprocessing.panels.NonPredefinedSeriesChart; +import eu.engys.util.ui.textfields.DoubleField; + +public class ResidualsChart extends NonPredefinedSeriesChart { + + private static final Logger logger = LoggerFactory.getLogger(ResidualsChart.class); + + @Override + protected JFreeChart createChart() { + JFreeChart chart = super.createChart(); + + LogarithmicAxis rangeAxis = new LogarithmicAxis(""); + rangeAxis.setNumberFormatOverride(DoubleField.getFormatForDISPLAY(10)); + rangeAxis.setAutoRangeIncludesZero(false); + rangeAxis.setAutoRange(true); + rangeAxis.setExpTickLabelsFlag(true); + + chart.getXYPlot().setRangeAxis(rangeAxis); + return chart; + } + + @Override + protected void addTimeUnit(double time, TimeBlockUnit unit) { + if (unit instanceof DoubleListTimeBlockUnit) { + XYSeriesCollection dataset = addSerie(unit); + + DoubleListTimeBlockUnit doubleListUnit = (DoubleListTimeBlockUnit) unit; + for (Double value : doubleListUnit.getValues()) { + if (value > 0) { + dataset.getSeries(unit.getVarName()).add(time, value); + } + } + } + } + + @Override + protected void addMovingAverageSerie(TimeBlockUnit unit) { + if (unit instanceof DoubleListTimeBlockUnit) { + _addMovingAverageSerie(unit); + } else { + logger.error("Invalid unit type {}", (unit != null ? unit.getClass().getCanonicalName() : "null")); + } + + } + + @Override + public void stop() { + } + +} diff --git a/src/eu/engys/gui/solver/postprocessing/panels/residuals/ResidualsChartPanel.java b/src/eu/engys/gui/solver/postprocessing/panels/residuals/ResidualsChartPanel.java deleted file mode 100644 index d99d9fe..0000000 --- a/src/eu/engys/gui/solver/postprocessing/panels/residuals/ResidualsChartPanel.java +++ /dev/null @@ -1,94 +0,0 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - -package eu.engys.gui.solver.postprocessing.panels.residuals; - -import org.jfree.chart.ChartFactory; -import org.jfree.chart.axis.LogarithmicAxis; -import org.jfree.chart.axis.NumberAxis; -import org.jfree.chart.plot.PlotOrientation; -import org.jfree.chart.plot.XYPlot; -import org.jfree.data.xy.XYSeries; - -import eu.engys.core.project.system.monitoringfunctionobjects.TimeBlock; -import eu.engys.core.project.system.monitoringfunctionobjects.TimeBlockUnit; -import eu.engys.gui.solver.postprocessing.data.DoubleListTimeBlockUnit; -import eu.engys.gui.solver.postprocessing.panels.HistoryChartPanel; - -public class ResidualsChartPanel extends HistoryChartPanel { - - public ResidualsChartPanel() { - super("Residuals", null, TIME_LABEL, "", false); - } - - @Override - protected void createChart() { - this.chart = ChartFactory.createXYLineChart("", "", "", dataset, PlotOrientation.VERTICAL, true, true, false); - NumberAxis domainAxis = new NumberAxis(domainAxisLabel); - domainAxis.setAutoRangeIncludesZero(false); - - LogarithmicAxis rangeAxis = new LogarithmicAxis(rangeAxisLabel); - rangeAxis.setExpTickLabelsFlag(true); - - XYPlot xyPlot = chart.getXYPlot(); - xyPlot.setDomainAxis(domainAxis); - xyPlot.setRangeAxis(rangeAxis); - } - - @Override - protected void addTimeBlock(TimeBlock block) { - for (TimeBlockUnit unit : block.getUnitsMap().values()) { - if (unit instanceof DoubleListTimeBlockUnit) { - addTimeUnit(block.getTime(), (DoubleListTimeBlockUnit) unit); - } - } - } - - private void addTimeUnit(double time, DoubleListTimeBlockUnit unit) { - String varName = unit.getVarName(); - if (dataset.getSeriesIndex(varName) == -1) { - XYSeries series = new XYSeries(varName); - dataset.addSeries(series); - populateSeriesPanel(dataset.getSeriesIndex(series.getKey()), series.getKey().toString()); - } - XYSeries xyserie = dataset.getSeries(varName); - DoubleListTimeBlockUnit doubleListUnit = (DoubleListTimeBlockUnit) unit; - for (Double value : doubleListUnit.getValues()) { - if (value > 0) { - xyserie.add(time, value); - } - } - } - - @Override - public void clearData() { - // Chart is recreated everytime so we remove all - dataset.removeAllSeries(); - chartPanel.restoreAutoDomainBounds(); - seriesPanel.clear(); - refreshGUI(); - } - -} diff --git a/src/eu/engys/gui/solver/postprocessing/panels/residuals/ResidualsExporter.java b/src/eu/engys/gui/solver/postprocessing/panels/residuals/ResidualsExporter.java index 80dd5a5..53e8379 100644 --- a/src/eu/engys/gui/solver/postprocessing/panels/residuals/ResidualsExporter.java +++ b/src/eu/engys/gui/solver/postprocessing/panels/residuals/ResidualsExporter.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.solver.postprocessing.panels.residuals; import static eu.engys.core.report.excel.ExcelUtils.addDoubleCell; diff --git a/src/eu/engys/gui/solver/postprocessing/panels/residuals/ResidualsPanel.java b/src/eu/engys/gui/solver/postprocessing/panels/residuals/ResidualsPanel.java index b7db9fd..6179871 100644 --- a/src/eu/engys/gui/solver/postprocessing/panels/residuals/ResidualsPanel.java +++ b/src/eu/engys/gui/solver/postprocessing/panels/residuals/ResidualsPanel.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.solver.postprocessing.panels.residuals; import javax.inject.Inject; @@ -36,20 +35,21 @@ import eu.engys.gui.DefaultGUIPanel; import eu.engys.gui.solver.postprocessing.panels.actions.ExportToCSVAction; import eu.engys.gui.solver.postprocessing.panels.actions.ExportToExcelAction; import eu.engys.gui.solver.postprocessing.panels.actions.ExportToPNGAction; -import eu.engys.gui.solver.postprocessing.panels.actions.ShowCrosshairForResidualsAction; +import eu.engys.gui.solver.postprocessing.panels.actions.ShowCrosshairAction; import eu.engys.gui.solver.postprocessing.panels.actions.ShowLogFileAction; import eu.engys.gui.solver.postprocessing.panels.utils.SelectedViewProvider; import eu.engys.util.ui.UiUtil; public class ResidualsPanel extends DefaultGUIPanel implements SelectedViewProvider { - private static final String TITLE = "Residuals"; + public static final String RESIDUALS = "Residuals"; + private ResidualsView residualsView; private JToggleButton showCrosshairButton; @Inject public ResidualsPanel(Model model, Controller controller) throws Exception { - super(TITLE, model); + super(RESIDUALS, model); this.residualsView = (ResidualsView) controller.getResidualView(); } @@ -58,7 +58,7 @@ public class ResidualsPanel extends DefaultGUIPanel implements SelectedViewProvi populateToolbar(); return residualsView.getPanel(); } - + @Override public void stop() { super.stop(); @@ -72,13 +72,12 @@ public class ResidualsPanel extends DefaultGUIPanel implements SelectedViewProvi } private void populateToolbar() { - titleToolbar.add(showCrosshairButton = UiUtil.createToolBarToggleButton(new ShowCrosshairForResidualsAction(residualsView), true)); + titleToolbar.add(showCrosshairButton = UiUtil.createToolBarToggleButton(new ShowCrosshairAction(), true)); titleToolbar.addSeparator(); titleToolbar.add(UiUtil.createToolBarButton(new ShowLogFileAction(this))); titleToolbar.add(UiUtil.createToolBarButton(new ExportToExcelAction(this))); titleToolbar.add(UiUtil.createToolBarButton(new ExportToCSVAction(this))); titleToolbar.add(UiUtil.createToolBarButton(new ExportToPNGAction(this))); - } @Override @@ -93,7 +92,19 @@ public class ResidualsPanel extends DefaultGUIPanel implements SelectedViewProvi @Override public void load() { - residualsView.reset(); + residualsView.updateConfiguration(); + if (model.getSolverModel().getServerState().getSolverState().isDoingSomething()) { + // do nothing + } else { + residualsView.reset(); + } + residualsView.handleStateChanged(model.getState()); + } + + @Override + public void stateChanged() { + residualsView.updateConfiguration(); + residualsView.handleStateChanged(model.getState()); } } diff --git a/src/eu/engys/gui/solver/postprocessing/panels/residuals/ResidualsView.java b/src/eu/engys/gui/solver/postprocessing/panels/residuals/ResidualsView.java index cf8deff..ebb64f2 100644 --- a/src/eu/engys/gui/solver/postprocessing/panels/residuals/ResidualsView.java +++ b/src/eu/engys/gui/solver/postprocessing/panels/residuals/ResidualsView.java @@ -1,76 +1,95 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.solver.postprocessing.panels.residuals; -import java.util.ArrayList; +import java.util.Collections; import java.util.List; +import java.util.Set; +import javax.swing.JTabbedPane; + +import eu.engys.core.modules.AbstractChart; +import eu.engys.core.modules.ApplicationModule; +import eu.engys.core.modules.residuals.ResidualsViewConfigurator; +import eu.engys.core.modules.residuals.ResidualsViewManager; import eu.engys.core.project.Model; +import eu.engys.core.project.state.State; import eu.engys.core.project.system.monitoringfunctionobjects.Parser; import eu.engys.core.project.system.monitoringfunctionobjects.TimeBlocks; import eu.engys.core.report.Exporter; import eu.engys.gui.solver.postprocessing.panels.AbstractParserView; import eu.engys.gui.solver.postprocessing.parsers.ResidualsParser; -import eu.engys.gui.solver.postprocessing.parsers.ResidualsUtils; import eu.engys.util.progress.ProgressMonitor; -import eu.engys.util.ui.UiUtil; public class ResidualsView extends AbstractParserView { - private ResidualsChartPanel chartPanel; + private ResidualsViewManager manager; + private Set modules; - // public static void main(String[] args) { - // new HelyxLookAndFeel().init(); - // Model model = new Model(); - // model.init(); - // ResidualsView panel = new ResidualsView(model, null); - // JFrame f = UiUtil.defaultTestFrame("a", panel); - // f.setSize(600, 500); - // f.setVisible(true); - // } - - public ResidualsView(Model model, ProgressMonitor monitor) { + public ResidualsView(Model model, Set modules, ProgressMonitor monitor) { super(model, null, monitor); - this.chartPanel = new ResidualsChartPanel(); - chartPanel.layoutComponents(); + setName(getKey()); + this.modules = modules; + ResidualsViewConfigurator simpleResiduals = new SimpleResidualsViewConfigurator(model, tabbedPane, monitor); + this.manager = new ResidualsViewManager(model, tabbedPane, simpleResiduals); + } - tabbedPane.addTab("Residuals", chartPanel); - UiUtil.setOneTabHide(tabbedPane); + public void updateConfiguration() { + manager.updateConfiguration(modules); + manager.getActiveConfigurator().reloadPanel(); } @Override - public List gerReportParsersList() { - List reportParsersList = new ArrayList<>(); - reportParsersList.add(new ResidualsParser(ResidualsUtils.fileToParse(model))); - return reportParsersList; + public AbstractChart getSelectedChart() { + if(activeConfiguratorNotnull()) { + return manager.getActiveConfigurator().getSelectedChart(); + } + return null; + } + + @Override + public void handleStateChanged(State state) { + if(activeConfiguratorNotnull()) { + manager.getActiveConfigurator().handleStateChanged(state); + } + } + + @Override + public List getReportParsersList() { + if(activeConfiguratorNotnull()) { + return manager.getActiveConfigurator().getReportParsersList(); + } + return Collections.emptyList(); } @Override public Exporter getExporter() { - return new ResidualsExporter(gerReportParsersList(), monitor); + if(activeConfiguratorNotnull()) { + return manager.getActiveConfigurator().getExporter(); + } + return null; } @Override @@ -80,22 +99,39 @@ public class ResidualsView extends AbstractParserView { @Override public void clearData() { - chartPanel.clearData(); + if(activeConfiguratorNotnull()) { + manager.getActiveConfigurator().clearData(); + } } @Override public void handleFunctionObjectChanged() { } - @Override - public void stop() { - } - @Override public void updateParsing(List newTimeBlocks) { if (!newTimeBlocks.isEmpty()) { - chartPanel.addToDataSet(newTimeBlocks.get(0)); + if(activeConfiguratorNotnull()){ + manager.getActiveConfigurator().updateParsing(newTimeBlocks); + } } } + private boolean activeConfiguratorNotnull() { + return manager.getActiveConfigurator() != null; + } + + public JTabbedPane getTabbedPane() { + return tabbedPane; + } + + // For test purposes only + public ResidualsViewManager getManager() { + return manager; + } + + @Override + public void deleteLogFiles() { + } + } diff --git a/src/eu/engys/gui/solver/postprocessing/panels/residuals/SimpleResidualsViewConfigurator.java b/src/eu/engys/gui/solver/postprocessing/panels/residuals/SimpleResidualsViewConfigurator.java new file mode 100644 index 0000000..ce877fd --- /dev/null +++ b/src/eu/engys/gui/solver/postprocessing/panels/residuals/SimpleResidualsViewConfigurator.java @@ -0,0 +1,110 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.gui.solver.postprocessing.panels.residuals; + +import java.util.ArrayList; +import java.util.List; + +import javax.swing.JTabbedPane; + +import eu.engys.core.modules.AbstractChart; +import eu.engys.core.modules.residuals.ResidualsViewConfigurator; +import eu.engys.core.project.Model; +import eu.engys.core.project.state.State; +import eu.engys.core.project.system.monitoringfunctionobjects.Parser; +import eu.engys.core.project.system.monitoringfunctionobjects.TimeBlocks; +import eu.engys.core.report.Exporter; +import eu.engys.gui.solver.postprocessing.parsers.ResidualsParser; +import eu.engys.gui.solver.postprocessing.parsers.ResidualsUtils; +import eu.engys.gui.solver.postprocessing.parsers.SimpleResidualsParser; +import eu.engys.util.progress.ProgressMonitor; +import eu.engys.util.ui.UiUtil; + +public class SimpleResidualsViewConfigurator implements ResidualsViewConfigurator { + + private Model model; + private AbstractChart chart; + private ProgressMonitor monitor; + + private JTabbedPane tabbedPane; + + public SimpleResidualsViewConfigurator(Model model, JTabbedPane tabbedPane, ProgressMonitor monitor) { + this.model = model; + this.tabbedPane = tabbedPane; + this.monitor = monitor; + this.chart = new ResidualsChart(); + chart.layoutComponents(); + } + + @Override + public AbstractChart getSelectedChart() { + return chart; + } + + @Override + public void handleStateChanged(State state) { + chart.handleStateChanged(state); + } + + @Override + public void reloadPanel() { + tabbedPane.removeAll(); + tabbedPane.addTab(ResidualsPanel.RESIDUALS, chart.getPanel()); + UiUtil.setOneTabHide(tabbedPane); + } + + @Override + public String getKey() { + return ResidualsParser.KEY; + } + + @Override + public boolean isActive() { + return false; + } + + @Override + public List getReportParsersList() { + List reportParsersList = new ArrayList<>(); + reportParsersList.add(new SimpleResidualsParser(ResidualsUtils.fileToParse(model))); + return reportParsersList; + } + + @Override + public void clearData() { + chart.clear(); + } + + @Override + public void updateParsing(List newTimeBlocks) { + chart.addToDataSet(newTimeBlocks.get(0)); + } + + @Override + public Exporter getExporter() { + return new ResidualsExporter(getReportParsersList(), monitor); + } + +} diff --git a/src/eu/engys/gui/solver/postprocessing/panels/utils/ChartUtils.java b/src/eu/engys/gui/solver/postprocessing/panels/utils/ChartUtils.java new file mode 100644 index 0000000..c062340 --- /dev/null +++ b/src/eu/engys/gui/solver/postprocessing/panels/utils/ChartUtils.java @@ -0,0 +1,149 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.gui.solver.postprocessing.panels.utils; + +import static eu.engys.core.modules.AbstractChart.DATASET_INDEX; +import static eu.engys.core.modules.AbstractChart.WEIGHTING_DATASET_INDEX; + +import java.awt.BasicStroke; +import java.awt.Color; +import java.text.DecimalFormat; + +import org.jfree.chart.labels.CrosshairLabelGenerator; +import org.jfree.chart.panel.CrosshairOverlay; +import org.jfree.chart.plot.Crosshair; +import org.jfree.chart.plot.XYPlot; +import org.jfree.chart.renderer.xy.XYItemRenderer; +import org.jfree.data.general.SeriesDataset; +import org.jfree.data.xy.XYDataset; + +import eu.engys.core.project.state.State; + +public class ChartUtils { + + public static final Color SERIES_RED = new Color(255, 85, 85); + public static final Color SERIES_BLUE = new Color(85, 85, 255); + public static final Color SERIES_GREEN = new Color(85, 255, 85); + + private static final String STEADY_DOMAIN_AXIS_LABEL = "Iteration [-]"; + private static final String TRANSIENT_DOMAIN_AXIS_LABEL = "Time [s]"; + + private static final Color CROSSHAIR_COLOR = Color.BLACK; + private static final BasicStroke CROSSHAIR_STROKE = new BasicStroke(1f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 1.0f, new float[] { 1.0f }, 0.0f); + + public static final DecimalFormat SERIES_DECIMAL_FORMAT = new DecimalFormat("#,###,##0.0###"); + + public static int getSeriesIndex(SeriesDataset dataset, String key) { + for (int i = 0; i < dataset.getSeriesCount(); i++) { + String seriesKey = (String) dataset.getSeriesKey(i); + if (key.equals(seriesKey)) { + return i; + } + } + return -1; + } + + public static Color colorForSerie(XYPlot plot, int seriesIndex) { + XYItemRenderer baseRenderer = plot.getRenderer(DATASET_INDEX); + Color colorWithTransparency = (Color) baseRenderer.getItemPaint(seriesIndex, 0); + return new Color(colorWithTransparency.getRed(), colorWithTransparency.getGreen(), colorWithTransparency.getBlue()); + } + + public static Color coloForMAVGSerie(XYPlot plot, int seriesIndex) { + XYItemRenderer baseRenderer = plot.getRenderer(DATASET_INDEX); + Color colorWithTransparency = ((Color) baseRenderer.getItemPaint(seriesIndex, 0)).darker().darker(); + return new Color(colorWithTransparency.getRed(), colorWithTransparency.getGreen(), colorWithTransparency.getBlue()); + } + + public static Color coloForWeightedSerie(XYPlot plot, int seriesIndex) { + XYItemRenderer baseRenderer = plot.getRenderer(WEIGHTING_DATASET_INDEX); + Color colorWithTransparency = ((Color) baseRenderer.getItemPaint(seriesIndex, 0)); + return new Color(colorWithTransparency.getRed(), colorWithTransparency.getGreen(), colorWithTransparency.getBlue()); + } + + public static void applyGraphicProperties(XYPlot plot, SeriesInfo info){ + setSeriesVisible(plot, info.getDatasetIndex(), info.getSeriesKey(), info.isVisible()); + setSeriesColor(plot, info.getDatasetIndex(), info.getSeriesKey(), info.getColor(), 1); + } + + public static void applyWeightedGraphicProperties(XYPlot plot, SeriesInfo info){ + setSeriesVisible(plot, info.getDatasetIndex(), info.getSeriesKey(), info.isVisible()); +// setSeriesColor(plot, info.getDatasetIndex(), info.getSeriesKey(), info.getColor(), 1); + } + + public static void setSeriesVisible(XYPlot plot, int datasetIndex, String seriesKey, boolean visible) { + XYDataset dataset = plot.getDataset(datasetIndex); + XYItemRenderer renderer = plot.getRenderer(datasetIndex); + if (dataset instanceof NormalizedWeightDataSet) { + if (visible) { + ((NormalizedWeightDataSet) dataset).restoreSerie(); + } else { + ((NormalizedWeightDataSet) dataset).backupAndRemoveSerie(); + } + } else { + renderer.setSeriesVisible(getSeriesIndex(dataset, seriesKey), visible, true); + } + } + + private static void setSeriesColor(XYPlot plot, int datasetIndex, String seriesKey, Color color, int strokeWidth) { + int seriesIndex = getSeriesIndex(plot.getDataset(datasetIndex), seriesKey); + plot.getRenderer(datasetIndex).setSeriesPaint(seriesIndex, color); + plot.getRenderer(datasetIndex).setSeriesStroke(seriesIndex, new BasicStroke(strokeWidth)); + } + + public static void updateDomainAxisLabel(State state, XYPlot plot) { + plot.getDomainAxis().setLabel(state.isSteady() ? STEADY_DOMAIN_AXIS_LABEL : TRANSIENT_DOMAIN_AXIS_LABEL); + } + + public static CrosshairOverlay createOverlay() { + CrosshairOverlay crosshairOverlay = new CrosshairOverlay(); + Crosshair xCrosshair = new Crosshair(Double.NaN, CROSSHAIR_COLOR, CROSSHAIR_STROKE); + xCrosshair.setLabelGenerator(new CrosshairLabelGenerator() { + @Override + public String generateLabel(Crosshair crosshair) { + return ChartUtils.SERIES_DECIMAL_FORMAT.format(crosshair.getValue()); + } + }); + xCrosshair.setLabelBackgroundPaint(Color.WHITE); + xCrosshair.setLabelOutlineVisible(false); + xCrosshair.setLabelVisible(true); + + Crosshair yCrosshair = new Crosshair(Double.NaN, CROSSHAIR_COLOR, CROSSHAIR_STROKE); + yCrosshair.setLabelGenerator(new CrosshairLabelGenerator() { + @Override + public String generateLabel(Crosshair crosshair) { + return ChartUtils.SERIES_DECIMAL_FORMAT.format(crosshair.getValue()); + } + }); + yCrosshair.setLabelBackgroundPaint(Color.WHITE); + yCrosshair.setLabelOutlineVisible(false); + yCrosshair.setLabelVisible(true); + + crosshairOverlay.addDomainCrosshair(xCrosshair); + crosshairOverlay.addRangeCrosshair(yCrosshair); + return crosshairOverlay; + } + +} diff --git a/src/eu/engys/gui/solver/postprocessing/panels/utils/CrosshairListener.java b/src/eu/engys/gui/solver/postprocessing/panels/utils/CrosshairListener.java new file mode 100644 index 0000000..be3a07b --- /dev/null +++ b/src/eu/engys/gui/solver/postprocessing/panels/utils/CrosshairListener.java @@ -0,0 +1,110 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.gui.solver.postprocessing.panels.utils; + +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; + +import org.jfree.chart.ChartMouseEvent; +import org.jfree.chart.ChartMouseListener; +import org.jfree.chart.ChartPanel; +import org.jfree.chart.panel.CrosshairOverlay; +import org.jfree.chart.plot.Crosshair; +import org.jfree.chart.plot.XYPlot; +import org.jfree.data.general.DatasetUtilities; +import org.jfree.data.xy.XYDataset; +import org.jfree.ui.RectangleEdge; + +import eu.engys.gui.events.EventManager; +import eu.engys.gui.solver.postprocessing.panels.utils.events.AddMarkerEvent; + +public class CrosshairListener extends MouseAdapter implements ChartMouseListener { + + private ChartPanel chartPanel; + private CrosshairOverlay overlay; + + public CrosshairListener(ChartPanel chartPanel, CrosshairOverlay overlay) { + this.chartPanel = chartPanel; + this.overlay = overlay; + } + + @Override + public void chartMouseClicked(ChartMouseEvent event) { + XYPlot xyPlot = chartPanel.getChart().getXYPlot(); + if(xyPlot.getDataset().getSeriesCount() == 0){ + // do nothing + } else { + double x = xyPlot.getDomainAxis().java2DToValue(event.getTrigger().getX(), chartPanel.getScreenDataArea(), RectangleEdge.BOTTOM); + EventManager.triggerEvent(this, new AddMarkerEvent(x)); + } + } + + @Override + public void chartMouseMoved(ChartMouseEvent event) { + XYPlot plot = chartPanel.getChart().getXYPlot(); + if (plot.getDataset().getSeriesCount() > 0) { + double x = plot.getDomainAxis().java2DToValue(event.getTrigger().getX(), chartPanel.getScreenDataArea(), RectangleEdge.BOTTOM); + // make the crosshairs disappear if the mouse is out of range + if (!plot.getDomainAxis().getRange().contains(x)) { + x = Double.NaN; + } + ((Crosshair) overlay.getDomainCrosshairs().get(0)).setValue(x); + + double y = getClosestY(x, event.getTrigger().getY()); + ((Crosshair) overlay.getRangeCrosshairs().get(0)).setValue(y); + } + } + + private double getClosestY(double x, int compare) { + XYPlot xyPlot = chartPanel.getChart().getXYPlot(); + + int series = 0; + XYDataset closestDataset = xyPlot.getDataset(); + + double distance = Double.MAX_VALUE; + + for (int i = 0; i < xyPlot.getDatasetCount(); i++) { + XYDataset dataset = xyPlot.getDataset(i); + for (int j = 0; j < dataset.getSeriesCount(); j++) { + double y = DatasetUtilities.findYValue(dataset, j, x); + double toCompare = xyPlot.getRangeAxis().java2DToValue(compare, chartPanel.getScreenDataArea(), xyPlot.getRangeAxisEdge()); + + if (Math.abs(y - toCompare) < distance) { + distance = Math.abs(y - toCompare); + closestDataset = dataset; + series = j; + } + } + } + return DatasetUtilities.findYValue(closestDataset, series, x); + } + + @Override + public void mouseExited(MouseEvent e) { + ((Crosshair) overlay.getDomainCrosshairs().get(0)).setValue(Double.NaN); + ((Crosshair) overlay.getRangeCrosshairs().get(0)).setValue(Double.NaN); + } + +} diff --git a/src/eu/engys/gui/solver/postprocessing/panels/utils/MarkersTable.java b/src/eu/engys/gui/solver/postprocessing/panels/utils/MarkersTable.java new file mode 100644 index 0000000..2c50a35 --- /dev/null +++ b/src/eu/engys/gui/solver/postprocessing/panels/utils/MarkersTable.java @@ -0,0 +1,117 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.gui.solver.postprocessing.panels.utils; + +import java.awt.BorderLayout; +import java.awt.Component; +import java.awt.event.KeyEvent; +import java.util.Collections; +import java.util.EventObject; +import java.util.List; + +import javax.swing.BorderFactory; +import javax.swing.JComponent; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JTable; +import javax.swing.SwingConstants; +import javax.swing.table.DefaultTableCellRenderer; +import javax.swing.text.JTextComponent; + +import org.jfree.chart.ChartPanel; + +import eu.engys.gui.events.EventManager; +import eu.engys.gui.solver.postprocessing.panels.utils.events.ShowMarkersTableEvent; +import eu.engys.gui.solver.postprocessing.panels.utils.markers.Marker; +import eu.engys.gui.solver.postprocessing.panels.utils.markers.MarkersTableModel; +import eu.engys.gui.table.editors.DoubleCellEditor; +import eu.engys.gui.table.renderers.DoubleCellRender; +import eu.engys.util.ui.CopyPasteSupport; +import eu.engys.util.ui.TitledBorderWithAction; + +public class MarkersTable extends JTable { + + private static final String MARKERS = "Markers"; + public static final String MARKERS_TABLE = "markers.table"; + private JComponent mainPanel; + + public MarkersTable(ChartPanel chartPanel) { + super(); + + setName(MARKERS_TABLE); + setModel(new MarkersTableModel(chartPanel)); + + setDefaultEditor(Double.class, new DoubleCellEditor()); + setDefaultRenderer(Double.class, new DoubleCellRender()); + + ((DefaultTableCellRenderer) tableHeader.getDefaultRenderer()).setHorizontalAlignment(SwingConstants.CENTER); + CopyPasteSupport.addSupportTo(this); + + layoutComponents(); + } + + public void loadMarkers(List markers) { + ((MarkersTableModel) getModel()).load(markers); + } + + public void clear() { + ((MarkersTableModel) getModel()).load(Collections.emptyList()); + } + + @Override + public boolean editCellAt(int row, int column, EventObject e) { + boolean result = super.editCellAt(row, column, e); + final Component editor = getEditorComponent(); + if (e instanceof KeyEvent && editor instanceof JTextComponent) { + ((JTextComponent) editor).selectAll(); + } + return result; + } + + private void layoutComponents() { + JPanel tablePanel = new JPanel(new BorderLayout()); + + tablePanel.add(tableHeader, BorderLayout.NORTH); + tablePanel.add(this, BorderLayout.CENTER); + + JScrollPane scroll = new JScrollPane(tablePanel); + scroll.setBorder(BorderFactory.createEmptyBorder()); + + mainPanel = new JPanel(new BorderLayout()); + mainPanel.setBorder(new TitledBorderWithAction(MARKERS, mainPanel, new Runnable() { + @Override + public void run() { + EventManager.triggerEvent(this, new ShowMarkersTableEvent(false)); + } + })); + mainPanel.add(scroll, BorderLayout.CENTER); + + } + + public JComponent getPanel() { + return mainPanel; + } + +} diff --git a/src/eu/engys/gui/solver/postprocessing/panels/utils/MavgAccessory.java b/src/eu/engys/gui/solver/postprocessing/panels/utils/MavgAccessory.java new file mode 100644 index 0000000..d21e201 --- /dev/null +++ b/src/eu/engys/gui/solver/postprocessing/panels/utils/MavgAccessory.java @@ -0,0 +1,112 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.gui.solver.postprocessing.panels.utils; + +import java.awt.BorderLayout; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; + +import javax.swing.JComboBox; +import javax.swing.JPanel; + +import org.jfree.data.xy.XYDataset; + +import eu.engys.util.ui.ComponentsFactory; +import eu.engys.util.ui.builder.PanelBuilder; +import eu.engys.util.ui.textfields.IntegerField; + +public class MavgAccessory extends JPanel { + + public static final String MOVING_AVERAGE_PANEL = "moving.average.panel"; + + public static final String TYPE_LABEL = "Type"; + public static final String PERIOD_LABEL = "Period"; + + private JComboBox type; + private IntegerField periodField; + + private XYDataset sourceDataSet; + private XYDataset movingAverageDataset; + + private MavgType movingAverageType = MavgType.TRAILING; + private int movingAveragePeriod = 1; + + public MavgAccessory(XYDataset sourceDataSet, XYDataset movingAverageDataSet) { + super(new BorderLayout()); + setName(MOVING_AVERAGE_PANEL); + this.sourceDataSet = sourceDataSet; + this.movingAverageDataset = movingAverageDataSet; + layoutComponents(); + } + + private void layoutComponents() { + PanelBuilder builder = new PanelBuilder(); + + type = ComponentsFactory.selectField(new String[] { MavgType.TRAILING.getLabel(), MavgType.CENTERED.getLabel() }); + type.setPrototypeDisplayValue(MavgType.CENTERED.getLabel()); + type.setSelectedItem(movingAverageType.getLabel()); + builder.addComponent(TYPE_LABEL, type); + + periodField = ComponentsFactory.intField(1, Integer.MAX_VALUE); + builder.addComponent(PERIOD_LABEL, periodField); + add(builder.removeMargins().getPanel(), BorderLayout.CENTER); + + type.addPropertyChangeListener(new PropertyChangeListener() { + + @Override + public void propertyChange(PropertyChangeEvent evt) { + if (evt.getPropertyName().equals("value")) { + updateMovingAverageType((String) type.getSelectedItem()); + } + } + }); + + periodField.addPropertyChangeListener(new PropertyChangeListener() { + + @Override + public void propertyChange(PropertyChangeEvent evt) { + if (evt.getPropertyName().equals("value")) { + updateMovingAveragePeriod(periodField.getIntValue()); + } + } + }); + + } + + private void updateMovingAveragePeriod(int period) { + this.movingAveragePeriod = period; + updateMovingAverageDataset(); + } + + private void updateMovingAverageType(String label) { + this.movingAverageType = MavgType.getTypeByLabel(label); + updateMovingAverageDataset(); + } + + public void updateMovingAverageDataset() { + MavgCalculator.calculate(sourceDataSet, movingAverageDataset, movingAverageType, movingAveragePeriod); + } + +} diff --git a/src/eu/engys/gui/solver/postprocessing/panels/utils/MovingAverageCalculator.java b/src/eu/engys/gui/solver/postprocessing/panels/utils/MavgCalculator.java similarity index 53% rename from src/eu/engys/gui/solver/postprocessing/panels/utils/MovingAverageCalculator.java rename to src/eu/engys/gui/solver/postprocessing/panels/utils/MavgCalculator.java index b8d963d..eba7cfb 100644 --- a/src/eu/engys/gui/solver/postprocessing/panels/utils/MovingAverageCalculator.java +++ b/src/eu/engys/gui/solver/postprocessing/panels/utils/MavgCalculator.java @@ -1,52 +1,51 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.solver.postprocessing.panels.utils; -import org.jfree.data.xy.AbstractIntervalXYDataset; import org.jfree.data.xy.XYDataItem; +import org.jfree.data.xy.XYDataset; import org.jfree.data.xy.XYSeries; import org.jfree.data.xy.XYSeriesCollection; import org.jfree.data.xy.YIntervalDataItem; import org.jfree.data.xy.YIntervalSeries; import org.jfree.data.xy.YIntervalSeriesCollection; -public class MovingAverageCalculator { +public class MavgCalculator { - public static void calculate(AbstractIntervalXYDataset sourceDataset, AbstractIntervalXYDataset movingAverageDataSet, MovingAverageType type, int period) { + public static void calculate(XYDataset sourceDataset, XYDataset movingAverageDataSet, MavgType type, int period) { if (type.isTrailing()) { - if(sourceDataset instanceof XYSeriesCollection){ - calculateTrailing((XYSeriesCollection)sourceDataset, (XYSeriesCollection)movingAverageDataSet, period); - } else if(sourceDataset instanceof YIntervalSeriesCollection){ - calculateTrailing((YIntervalSeriesCollection)sourceDataset, (XYSeriesCollection)movingAverageDataSet, period); + if (sourceDataset instanceof XYSeriesCollection) { + calculateTrailing((XYSeriesCollection) sourceDataset, (XYSeriesCollection) movingAverageDataSet, period); + } else if (sourceDataset instanceof YIntervalSeriesCollection) { + calculateTrailing((YIntervalSeriesCollection) sourceDataset, (XYSeriesCollection) movingAverageDataSet, period); } } else { - if(sourceDataset instanceof XYSeriesCollection){ - calculateCentral((XYSeriesCollection)sourceDataset, (XYSeriesCollection)movingAverageDataSet, period); - } else if(sourceDataset instanceof YIntervalSeriesCollection){ - calculateCentral((YIntervalSeriesCollection)sourceDataset, (XYSeriesCollection)movingAverageDataSet, period); + if (sourceDataset instanceof XYSeriesCollection) { + calculateCentral((XYSeriesCollection) sourceDataset, (XYSeriesCollection) movingAverageDataSet, period); + } else if (sourceDataset instanceof YIntervalSeriesCollection) { + calculateCentral((YIntervalSeriesCollection) sourceDataset, (XYSeriesCollection) movingAverageDataSet, period); } } } @@ -57,11 +56,11 @@ public class MovingAverageCalculator { // Sum of the left N-values, divided by N private static void calculateTrailing(XYSeriesCollection sourceDataset, XYSeriesCollection movingAverageDataSet, int period) { - movingAverageDataSet.removeAllSeries(); - for (int i = 0; i < sourceDataset.getSeriesCount(); i++) { XYSeries origSeries = sourceDataset.getSeries(i); - XYSeries maSeries = new XYSeries(origSeries.getKey() + "-MAVG"); + XYSeries maSeries = movingAverageDataSet.getSeries(origSeries.getKey()); + maSeries.setNotify(false); + maSeries.clear(); for (int j = 0; j < origSeries.getItemCount(); j++) { XYDataItem origItem = origSeries.getDataItem(j); @@ -75,16 +74,17 @@ public class MovingAverageCalculator { maSeries.add(origItem.getXValue(), (yValue / period)); } } - movingAverageDataSet.addSeries(maSeries); + maSeries.setNotify(true); } } // Sum of the N/2 left-values and of the N/2 right-values, divided by N private static void calculateCentral(XYSeriesCollection sourceDataset, XYSeriesCollection movingAverageDataSet, int period) { - movingAverageDataSet.removeAllSeries(); for (int i = 0; i < sourceDataset.getSeriesCount(); i++) { XYSeries origSeries = sourceDataset.getSeries(i); - XYSeries maSeries = new XYSeries(origSeries.getKey() + "-MAVG"); + XYSeries maSeries = movingAverageDataSet.getSeries(origSeries.getKey()); + maSeries.setNotify(false); + maSeries.clear(); int limit = (int) Math.floor(period / 2); @@ -102,7 +102,7 @@ public class MovingAverageCalculator { maSeries.add(origItem.getXValue(), (yValue / period)); } } - movingAverageDataSet.addSeries(maSeries); + maSeries.setNotify(true); } } @@ -111,11 +111,11 @@ public class MovingAverageCalculator { */ private static void calculateTrailing(YIntervalSeriesCollection sourceDataset, XYSeriesCollection movingAverageDataSet, int period) { - movingAverageDataSet.removeAllSeries(); - for (int i = 0; i < sourceDataset.getSeriesCount(); i++) { YIntervalSeries origSeries = sourceDataset.getSeries(i); - XYSeries maSeries = new XYSeries(origSeries.getKey() + "-MAVG"); + XYSeries maSeries = movingAverageDataSet.getSeries(origSeries.getKey()); + maSeries.setNotify(false); + maSeries.clear(); for (int j = 0; j < origSeries.getItemCount(); j++) { YIntervalDataItem origItem = (YIntervalDataItem) origSeries.getDataItem(j); @@ -129,15 +129,16 @@ public class MovingAverageCalculator { maSeries.add(origItem.getX().doubleValue(), (yValue / period)); } } - movingAverageDataSet.addSeries(maSeries); + maSeries.setNotify(true); } } private static void calculateCentral(YIntervalSeriesCollection sourceDataset, XYSeriesCollection movingAverageDataSet, int period) { - movingAverageDataSet.removeAllSeries(); for (int i = 0; i < sourceDataset.getSeriesCount(); i++) { YIntervalSeries origSeries = sourceDataset.getSeries(i); - XYSeries maSeries = new XYSeries(origSeries.getKey() + "-MAVG"); + XYSeries maSeries = movingAverageDataSet.getSeries(origSeries.getKey()); + maSeries.setNotify(false); + maSeries.clear(); int limit = (int) Math.floor(period / 2); @@ -155,7 +156,7 @@ public class MovingAverageCalculator { maSeries.add(origItem.getX().doubleValue(), (yValue / period)); } } - movingAverageDataSet.addSeries(maSeries); + maSeries.setNotify(true); } } } diff --git a/src/eu/engys/gui/solver/postprocessing/panels/utils/MavgSeriesPanel.java b/src/eu/engys/gui/solver/postprocessing/panels/utils/MavgSeriesPanel.java new file mode 100644 index 0000000..ad2f4eb --- /dev/null +++ b/src/eu/engys/gui/solver/postprocessing/panels/utils/MavgSeriesPanel.java @@ -0,0 +1,86 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.gui.solver.postprocessing.panels.utils; + +import static eu.engys.gui.solver.postprocessing.panels.utils.SeriesInfo.SERIES_INFO_PROPERTY; + +import java.awt.BorderLayout; +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; +import java.awt.Insets; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +import javax.swing.BorderFactory; +import javax.swing.JCheckBox; +import javax.swing.JPanel; + +import org.jfree.data.xy.XYDataset; + +import eu.engys.util.ui.ComponentsFactory; + +public class MavgSeriesPanel extends JPanel { + + public static final String MOVING_AVERAGE = "Moving Average"; + + private JPanel seriesPanel; + private MavgAccessory accessory; + + public MavgSeriesPanel(XYDataset dataset, XYDataset movingAverageDataset) { + super(new BorderLayout()); + setName(MOVING_AVERAGE); + setBorder(BorderFactory.createTitledBorder(MOVING_AVERAGE)); + this.seriesPanel = new JPanel(new GridBagLayout()); + + this.accessory = new MavgAccessory(dataset, movingAverageDataset); + + add(accessory, BorderLayout.NORTH); + add(seriesPanel, BorderLayout.CENTER); + } + + public void clear() { + seriesPanel.removeAll(); + } + + public void addSeries(final SeriesInfo info) { + JCheckBox checkBox = ComponentsFactory.checkField(info.getSeriesKey(), info.isVisible(), info.getColor()); + checkBox.setName(info.getSeriesKey()); + checkBox.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + JCheckBox check = (JCheckBox) e.getSource(); + info.setVisible(check.isSelected()); + firePropertyChange(SERIES_INFO_PROPERTY, null, info); + } + }); + int seriesIndex = seriesPanel.getComponentCount(); + seriesPanel.add(checkBox, new GridBagConstraints(0, seriesIndex, 1, 1, 1.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); + } + + public void updateMovingAverage() { + accessory.updateMovingAverageDataset(); + } + +} diff --git a/src/eu/engys/gui/solver/postprocessing/panels/utils/MavgType.java b/src/eu/engys/gui/solver/postprocessing/panels/utils/MavgType.java new file mode 100644 index 0000000..9579f8e --- /dev/null +++ b/src/eu/engys/gui/solver/postprocessing/panels/utils/MavgType.java @@ -0,0 +1,56 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.gui.solver.postprocessing.panels.utils; + +public enum MavgType { + + TRAILING("Trailing"), CENTERED("Centered"); + + private String label; + + private MavgType(String label) { + this.label = label; + } + + public String getLabel() { + return label; + } + + public boolean isTrailing() { + return equals(TRAILING); + } + + public static MavgType getTypeByLabel(String label) { + MavgType[] all = values(); + for (MavgType type : all) { + if (type.getLabel().equals(label)) { + return type; + } + } + return null; + + } + +} diff --git a/src/eu/engys/gui/solver/postprocessing/panels/utils/MovingAveragePanel.java b/src/eu/engys/gui/solver/postprocessing/panels/utils/MovingAveragePanel.java deleted file mode 100644 index 2934ed8..0000000 --- a/src/eu/engys/gui/solver/postprocessing/panels/utils/MovingAveragePanel.java +++ /dev/null @@ -1,105 +0,0 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - -package eu.engys.gui.solver.postprocessing.panels.utils; - -import java.awt.BorderLayout; -import java.beans.PropertyChangeEvent; -import java.beans.PropertyChangeListener; - -import javax.swing.JComboBox; -import javax.swing.JPanel; - -import org.jfree.data.xy.AbstractIntervalXYDataset; - -import eu.engys.util.ui.ComponentsFactory; -import eu.engys.util.ui.builder.PanelBuilder; -import eu.engys.util.ui.textfields.IntegerField; - -public class MovingAveragePanel extends JPanel { - - private JComboBox type; - private IntegerField periodField; - - private AbstractIntervalXYDataset sourceDataSet; - private AbstractIntervalXYDataset movingAverageDataset; - - private MovingAverageType movingAverageType = MovingAverageType.TRAILING; - private int movingAveragePeriod = 1; - - public MovingAveragePanel(AbstractIntervalXYDataset sourceDataSet, AbstractIntervalXYDataset movingAverageDataSet) { - super(new BorderLayout()); - this.sourceDataSet = sourceDataSet; - this.movingAverageDataset = movingAverageDataSet; - layoutComponents(); - } - - private void layoutComponents() { - PanelBuilder builder = new PanelBuilder(); - - type = ComponentsFactory.selectField(new String[] { MovingAverageType.TRAILING.getLabel(), MovingAverageType.CENTERED.getLabel() }); - type.setPrototypeDisplayValue(MovingAverageType.CENTERED.getLabel()); - type.addPropertyChangeListener(new PropertyChangeListener() { - - @Override - public void propertyChange(PropertyChangeEvent evt) { - if (evt.getPropertyName().equals("value")) { - updateMovingAverageType((String) type.getSelectedItem()); - } - } - }); - type.setSelectedItem(movingAverageType.getLabel()); - builder.addComponent("Type", type); - - periodField = ComponentsFactory.intField(1, Integer.MAX_VALUE); - periodField.addPropertyChangeListener(new PropertyChangeListener() { - - @Override - public void propertyChange(PropertyChangeEvent evt) { - if (evt.getPropertyName().equals("value")) { - updateMovingAveragePeriod(periodField.getIntValue()); - } - } - }); - builder.addComponent("Period", periodField); - - add(builder.removeMargins().getPanel(), BorderLayout.CENTER); - } - - private void updateMovingAveragePeriod(int period) { - this.movingAveragePeriod = period; - updateMovingAverageDataset(); - } - - private void updateMovingAverageType(String label) { - this.movingAverageType = MovingAverageType.getTypeByLabel(label); - updateMovingAverageDataset(); - } - - public void updateMovingAverageDataset() { - MovingAverageCalculator.calculate(sourceDataSet, movingAverageDataset, movingAverageType, movingAveragePeriod); - } - -} diff --git a/src/eu/engys/gui/solver/postprocessing/panels/utils/MovingAverageType.java b/src/eu/engys/gui/solver/postprocessing/panels/utils/MovingAverageType.java deleted file mode 100644 index 52eef9b..0000000 --- a/src/eu/engys/gui/solver/postprocessing/panels/utils/MovingAverageType.java +++ /dev/null @@ -1,57 +0,0 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - -package eu.engys.gui.solver.postprocessing.panels.utils; - -public enum MovingAverageType { - - TRAILING("Trailing"), CENTERED("Centered"); - - private String label; - - private MovingAverageType(String label) { - this.label = label; - } - - public String getLabel() { - return label; - } - - public boolean isTrailing() { - return equals(TRAILING); - } - - public static MovingAverageType getTypeByLabel(String label) { - MovingAverageType[] all = values(); - for (MovingAverageType type : all) { - if (type.getLabel().equals(label)) { - return type; - } - } - return null; - - } - -} diff --git a/src/eu/engys/gui/solver/postprocessing/panels/utils/NormalizedWeightDataSet.java b/src/eu/engys/gui/solver/postprocessing/panels/utils/NormalizedWeightDataSet.java new file mode 100644 index 0000000..d27380b --- /dev/null +++ b/src/eu/engys/gui/solver/postprocessing/panels/utils/NormalizedWeightDataSet.java @@ -0,0 +1,83 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.gui.solver.postprocessing.panels.utils; + +import org.jfree.data.xy.XYSeries; +import org.jfree.data.xy.XYSeriesCollection; + +public class NormalizedWeightDataSet extends XYSeriesCollection { + + /* + * This class fixes a bug of JFreeChart that causes a strange rendering behaviour when using the method "setPlotArea(true|false)" or even worst the method setSeriesVisible(true | false) + * The fix consists in adding/removing the series when toggling its visibility + */ + + private XYSeries backupSeries; + + public void backupAndRemoveSerie() { + if (getSeriesCount() > 0) { + removeSeries(backupSeries = getSeries(0)); + } + + } + + public void restoreSerie() { + if (backupSeries != null) { + addSeries(backupSeries); + } + } + + public boolean isCompletelyRemoved(Comparable key){ + if(getSeriesIndex(key) == -1 && backupSeries == null){ + return true; + }else{ + return false; + } + } + + @Override + public XYSeries getSeries(Comparable key) { + if(backupSeries == null) + return super.getSeries(key); + else{ + return backupSeries; + } + } + + @Override + public XYSeries getSeries(int series) { + if(super.getSeries(series) != null){ + return super.getSeries(series); + }else { + return backupSeries; + } + } + + @Override + public void removeAllSeries() { + this.backupSeries = null; + super.removeAllSeries(); + } +} diff --git a/src/eu/engys/gui/solver/postprocessing/panels/utils/SelectedViewProvider.java b/src/eu/engys/gui/solver/postprocessing/panels/utils/SelectedViewProvider.java index 434bb7d..070c16b 100644 --- a/src/eu/engys/gui/solver/postprocessing/panels/utils/SelectedViewProvider.java +++ b/src/eu/engys/gui/solver/postprocessing/panels/utils/SelectedViewProvider.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.solver.postprocessing.panels.utils; import eu.engys.core.project.system.monitoringfunctionobjects.ParserView; diff --git a/src/eu/engys/gui/solver/postprocessing/panels/utils/SeriesInfo.java b/src/eu/engys/gui/solver/postprocessing/panels/utils/SeriesInfo.java new file mode 100644 index 0000000..f3e0fea --- /dev/null +++ b/src/eu/engys/gui/solver/postprocessing/panels/utils/SeriesInfo.java @@ -0,0 +1,74 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.gui.solver.postprocessing.panels.utils; + +import java.awt.Color; + +import org.jfree.chart.plot.XYPlot; + +public class SeriesInfo { + + public static final String SERIES_INFO_PROPERTY = "series.info"; + + private XYPlot plot; + private Integer datasetIndex; + private String seriesKey; + private boolean visible; + private Color color; + + public SeriesInfo(XYPlot plot, Integer datasetIndex, String seriesKey, Color color, boolean visible) { + this.plot = plot; + this.datasetIndex = datasetIndex; + this.seriesKey = seriesKey; + this.color = color; + this.visible = visible; + } + + public XYPlot getPlot() { + return plot; + } + + public Integer getDatasetIndex() { + return datasetIndex; + } + + public String getSeriesKey() { + return seriesKey; + } + + public boolean isVisible() { + return visible; + } + + public void setVisible(boolean visible) { + this.visible = visible; + } + + + public Color getColor() { + return color; + } + +} diff --git a/src/eu/engys/gui/solver/postprocessing/panels/utils/SeriesPanel.java b/src/eu/engys/gui/solver/postprocessing/panels/utils/SeriesPanel.java index b8b05a8..d0d1a55 100644 --- a/src/eu/engys/gui/solver/postprocessing/panels/utils/SeriesPanel.java +++ b/src/eu/engys/gui/solver/postprocessing/panels/utils/SeriesPanel.java @@ -1,136 +1,78 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.solver.postprocessing.panels.utils; +import static eu.engys.gui.solver.postprocessing.panels.utils.SeriesInfo.SERIES_INFO_PROPERTY; + import java.awt.BorderLayout; -import java.awt.Color; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; -import java.awt.GridLayout; import java.awt.Insets; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; -import java.util.HashMap; -import java.util.Map; import javax.swing.BorderFactory; import javax.swing.JCheckBox; import javax.swing.JPanel; -import org.jfree.chart.renderer.xy.XYItemRenderer; - import eu.engys.util.ui.ComponentsFactory; public class SeriesPanel extends JPanel { - private Map seriesVisibility = new HashMap<>(); - private Map movingAverageSeriesVisibility = new HashMap<>(); + public static final String SERIES = "Series"; + private JPanel seriesPanel; - private JPanel seriesAveragePanel; - public SeriesPanel(JPanel movingAveragePanel) { - super(); - seriesPanel = new JPanel(new GridBagLayout()); - seriesAveragePanel = new JPanel(new GridBagLayout()); - - if (movingAveragePanel != null) { - setLayout(new GridLayout(2, 1)); - - JPanel movingAveragepanel = new JPanel(new BorderLayout()); - movingAveragepanel.setBorder(BorderFactory.createTitledBorder("Moving Average")); - movingAveragepanel.add(movingAveragePanel, BorderLayout.NORTH); - movingAveragepanel.add(seriesAveragePanel, BorderLayout.CENTER); - - seriesPanel.setBorder(BorderFactory.createTitledBorder("Series")); - add(seriesPanel); - add(movingAveragepanel); - } else { - setLayout(new BorderLayout()); - add(seriesPanel, BorderLayout.CENTER); - } + public SeriesPanel() { + super(new BorderLayout()); + setBorder(BorderFactory.createTitledBorder(SERIES)); + this.seriesPanel = new JPanel(new GridBagLayout()); + this.seriesPanel.setName(SERIES); + add(seriesPanel, BorderLayout.CENTER); } public void clear() { - // do not clear visibility maps seriesPanel.removeAll(); - seriesAveragePanel.removeAll(); } - public void addSeries(final XYItemRenderer renderer, final int seriesIndex, final String label) { - boolean visible = true; - if (seriesVisibility.containsKey(label)) { - visible = seriesVisibility.get(label); - } else { - seriesVisibility.put(label, visible); - } - final JCheckBox checkBox = ComponentsFactory.checkField(label, visible, getColorOfSeries(renderer, seriesIndex)); + public void addSeries(final SeriesInfo info) { + JCheckBox checkBox = ComponentsFactory.checkField(info.getSeriesKey(), info.isVisible(), info.getColor()); + checkBox.setName(info.getSeriesKey()); checkBox.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - if (checkBox.isSelected()) { - seriesVisibility.put(label, true); - renderer.setSeriesVisible(seriesIndex, true, true); - } else { - seriesVisibility.put(label, false); - renderer.setSeriesVisible(seriesIndex, false, true); - } + JCheckBox check = (JCheckBox) e.getSource(); + info.setVisible(check.isSelected()); + firePropertyChange(SERIES_INFO_PROPERTY, null, info); } }); + int seriesIndex = seriesPanel.getComponentCount(); seriesPanel.add(checkBox, new GridBagConstraints(0, seriesIndex, 1, 1, 1.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); - } - - public void addMovingAverageSeries(final XYItemRenderer renderer, final int seriesIndex, final String label) { - boolean visible = false; - if (movingAverageSeriesVisibility.containsKey(label)) { - visible = movingAverageSeriesVisibility.get(label); - } else { - movingAverageSeriesVisibility.put(label, visible); - } - final JCheckBox checkBox = ComponentsFactory.checkField(label, visible, getColorOfSeries(renderer, seriesIndex)); - checkBox.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - if (checkBox.isSelected()) { - seriesVisibility.put(label, true); - renderer.setSeriesVisible(seriesIndex, true, true); - } else { - seriesVisibility.put(label, false); - renderer.setSeriesVisible(seriesIndex, false, true); - } - } - }); - - seriesAveragePanel.add(checkBox, new GridBagConstraints(0, seriesIndex, 1, 1, 1.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); - renderer.setSeriesVisible(seriesIndex, visible, true); - } - - // Used to colour points in the 3D - public static Color getColorOfSeries(XYItemRenderer renderer, int seriesIndex) { - Color colorWithTransparency = (Color) renderer.getItemPaint(seriesIndex, 0); - return new Color(colorWithTransparency.getRed(), colorWithTransparency.getGreen(), colorWithTransparency.getBlue()); + + revalidate(); + repaint(); } } diff --git a/src/eu/engys/gui/solver/postprocessing/panels/utils/SeriesVisibilityListener.java b/src/eu/engys/gui/solver/postprocessing/panels/utils/SeriesVisibilityListener.java new file mode 100644 index 0000000..0da5171 --- /dev/null +++ b/src/eu/engys/gui/solver/postprocessing/panels/utils/SeriesVisibilityListener.java @@ -0,0 +1,48 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.gui.solver.postprocessing.panels.utils; + +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; + +import org.jfree.chart.plot.XYPlot; + +public class SeriesVisibilityListener implements PropertyChangeListener { + + public SeriesVisibilityListener() { + } + + @Override + public void propertyChange(PropertyChangeEvent evt) { + SeriesInfo info = (SeriesInfo) evt.getNewValue(); + XYPlot plot = info.getPlot(); + Integer datasetIndex = info.getDatasetIndex(); + String seriesKey = info.getSeriesKey(); + boolean visible = info.isVisible(); + + ChartUtils.setSeriesVisible(plot, datasetIndex, seriesKey, visible); + } + +} diff --git a/src/eu/engys/gui/solver/postprocessing/panels/utils/WaitLayerUI.java b/src/eu/engys/gui/solver/postprocessing/panels/utils/WaitLayerUI.java index a8f1875..298b593 100644 --- a/src/eu/engys/gui/solver/postprocessing/panels/utils/WaitLayerUI.java +++ b/src/eu/engys/gui/solver/postprocessing/panels/utils/WaitLayerUI.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.solver.postprocessing.panels.utils; import static java.awt.AlphaComposite.SRC_OVER; diff --git a/src/eu/engys/gui/solver/postprocessing/panels/utils/events/AddMarkerEvent.java b/src/eu/engys/gui/solver/postprocessing/panels/utils/events/AddMarkerEvent.java new file mode 100644 index 0000000..3685b68 --- /dev/null +++ b/src/eu/engys/gui/solver/postprocessing/panels/utils/events/AddMarkerEvent.java @@ -0,0 +1,43 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.gui.solver.postprocessing.panels.utils.events; + +import eu.engys.gui.events.EventObject; +import eu.engys.gui.events.application.ApplicationEvent; + +public class AddMarkerEvent extends EventObject implements ApplicationEvent { + + private double x; + + public AddMarkerEvent(double x) { + super(); + this.x = x; + } + + public double getX() { + return x; + } + +} diff --git a/src/eu/engys/gui/solver/postprocessing/panels/utils/events/CrosshairChangedEvent.java b/src/eu/engys/gui/solver/postprocessing/panels/utils/events/CrosshairChangedEvent.java new file mode 100644 index 0000000..19f1bdb --- /dev/null +++ b/src/eu/engys/gui/solver/postprocessing/panels/utils/events/CrosshairChangedEvent.java @@ -0,0 +1,49 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.gui.solver.postprocessing.panels.utils.events; + +import eu.engys.gui.events.EventObject; +import eu.engys.gui.events.application.ApplicationEvent; +import eu.engys.gui.solver.postprocessing.panels.utils.markers.Marker; + +public class CrosshairChangedEvent extends EventObject implements ApplicationEvent { + + private Marker oldValue; + private Marker newValue; + + public CrosshairChangedEvent(Marker oldValue, Marker newValue) { + this.oldValue = oldValue; + this.newValue = newValue; + } + + public Marker getOldValue() { + return oldValue; + } + + public Marker getNewValue() { + return newValue; + } + +} diff --git a/src/eu/engys/gui/solver/postprocessing/panels/utils/events/ShowCrosshairEvent.java b/src/eu/engys/gui/solver/postprocessing/panels/utils/events/ShowCrosshairEvent.java new file mode 100644 index 0000000..ccc0b2c --- /dev/null +++ b/src/eu/engys/gui/solver/postprocessing/panels/utils/events/ShowCrosshairEvent.java @@ -0,0 +1,43 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.gui.solver.postprocessing.panels.utils.events; + +import eu.engys.gui.events.EventObject; +import eu.engys.gui.events.application.ApplicationEvent; + +public class ShowCrosshairEvent extends EventObject implements ApplicationEvent { + + private boolean active; + + public ShowCrosshairEvent(boolean active) { + super(); + this.active = active; + } + + public boolean isActive() { + return active; + } + +} diff --git a/src/eu/engys/gui/solver/postprocessing/panels/utils/events/ShowMarkersTableEvent.java b/src/eu/engys/gui/solver/postprocessing/panels/utils/events/ShowMarkersTableEvent.java new file mode 100644 index 0000000..d76309e --- /dev/null +++ b/src/eu/engys/gui/solver/postprocessing/panels/utils/events/ShowMarkersTableEvent.java @@ -0,0 +1,43 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.gui.solver.postprocessing.panels.utils.events; + +import eu.engys.gui.events.EventObject; +import eu.engys.gui.events.application.ApplicationEvent; + +public class ShowMarkersTableEvent extends EventObject implements ApplicationEvent { + + private boolean visible; + + public ShowMarkersTableEvent(boolean active) { + super(); + this.visible = active; + } + + public boolean isVisible() { + return visible; + } + +} diff --git a/src/eu/engys/gui/solver/postprocessing/panels/utils/markers/Marker.java b/src/eu/engys/gui/solver/postprocessing/panels/utils/markers/Marker.java new file mode 100644 index 0000000..2bfb306 --- /dev/null +++ b/src/eu/engys/gui/solver/postprocessing/panels/utils/markers/Marker.java @@ -0,0 +1,68 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.gui.solver.postprocessing.panels.utils.markers; + +import org.apache.commons.lang.builder.EqualsBuilder; +import org.apache.commons.lang.builder.HashCodeBuilder; + +public class Marker implements Comparable{ + + private Double value; + + public Marker(Double value) { + this.value = value; + } + + public Double getValue() { + return value; + } + + public void setValue(Double value) { + this.value = value; + } + + @Override + public boolean equals(Object obj) { + if (!(obj instanceof Marker)) { + return false; + } + if (obj == this) { + return true; + } + Marker fz = (Marker) obj; + return new EqualsBuilder().append(value, fz.value).isEquals(); + } + + @Override + public int hashCode() { + return new HashCodeBuilder(17, 31).append(value).toHashCode(); + } + + @Override + public int compareTo(Marker o) { + return value.compareTo(o.getValue()); + } + +} diff --git a/src/eu/engys/gui/solver/postprocessing/panels/utils/markers/MarkersTableCell.java b/src/eu/engys/gui/solver/postprocessing/panels/utils/markers/MarkersTableCell.java new file mode 100644 index 0000000..3a226b8 --- /dev/null +++ b/src/eu/engys/gui/solver/postprocessing/panels/utils/markers/MarkersTableCell.java @@ -0,0 +1,49 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.gui.solver.postprocessing.panels.utils.markers; + +public class MarkersTableCell { + + private String serieName; + private Double value; + + public MarkersTableCell(String serieName, Double value) { + this.serieName = serieName; + this.value = value; + } + + public String getSerieName() { + return serieName; + } + + public Double getValue() { + return value; + } + + @Override + public String toString() { + return "[" + serieName + ", " + value + "]"; + } +} diff --git a/src/eu/engys/gui/solver/postprocessing/panels/utils/markers/MarkersTableModel.java b/src/eu/engys/gui/solver/postprocessing/panels/utils/markers/MarkersTableModel.java new file mode 100644 index 0000000..c8cf130 --- /dev/null +++ b/src/eu/engys/gui/solver/postprocessing/panels/utils/markers/MarkersTableModel.java @@ -0,0 +1,133 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.gui.solver.postprocessing.panels.utils.markers; + +import java.util.LinkedList; +import java.util.List; +import java.util.SortedMap; +import java.util.TreeMap; + +import javax.swing.table.AbstractTableModel; + +import org.jfree.chart.ChartPanel; +import org.jfree.chart.plot.XYPlot; +import org.jfree.data.general.DatasetUtilities; + +import com.google.common.collect.Lists; + +import eu.engys.gui.events.EventManager; +import eu.engys.gui.solver.postprocessing.panels.utils.events.CrosshairChangedEvent; + +public class MarkersTableModel extends AbstractTableModel { + + public static final String NO_DATA = "-"; + + private ChartPanel chartPanel; + private SortedMap> seriesValues; + + public MarkersTableModel(ChartPanel chartPanel) { + this.chartPanel = chartPanel; + this.seriesValues = new TreeMap<>(); + } + + public void load(List markers) { + seriesValues.clear(); + for (Marker marker : markers) { + addRow(marker); + } + } + + private void addRow(Marker marker) { + XYPlot xyPlot = chartPanel.getChart().getXYPlot(); + + List values = new LinkedList<>(); + for (int i = 0; i < xyPlot.getDataset().getSeriesCount(); i++) { + String seriesName = (String) xyPlot.getDataset().getSeriesKey(i); + Double value = DatasetUtilities.findYValue(xyPlot.getDataset(), i, marker.getValue()); + values.add(new MarkersTableCell(seriesName, value)); + } + seriesValues.put(marker, values); + fireTableStructureChanged(); + } + + @Override + public Object getValueAt(int rowIndex, int columnIndex) { + if (seriesValues.isEmpty()) { + return Double.NaN; + } else { + if (columnIndex == 0) { + return Lists.newArrayList(seriesValues.keySet()).get(rowIndex).getValue(); + } else { + Marker key = Lists.newArrayList(seriesValues.keySet()).get(rowIndex); + return seriesValues.get(key).get(columnIndex - 1).getValue(); + } + } + } + + @Override + public void setValueAt(Object aValue, int rowIndex, int columnIndex) { + if (columnIndex == 0) { + Marker existingKey = Lists.newArrayList(seriesValues.keySet()).get(rowIndex); + Marker newKey = new Marker((Double) aValue); + EventManager.triggerEvent(this, new CrosshairChangedEvent(existingKey, newKey)); + } + } + + @Override + public int getRowCount() { + return seriesValues.size(); + } + + @Override + public String getColumnName(int columnIndex) { + if (seriesValues.isEmpty()) { + return NO_DATA; + } else { + if (columnIndex == 0) { + return chartPanel.getChart().getXYPlot().getDomainAxis().getLabel(); + } else { + Marker firstKey = seriesValues.keySet().iterator().next(); + List firstItem = seriesValues.get(firstKey); + return firstItem.get(columnIndex - 1).getSerieName(); + } + } + } + + @Override + public int getColumnCount() { + return chartPanel.getChart().getXYPlot().getDataset().getSeriesCount() + 1; + } + + @Override + public boolean isCellEditable(int rowIndex, int columnIndex) { + return columnIndex == 0; + } + + @Override + public Class getColumnClass(int column) { + return Double.class; + } + +} diff --git a/src/eu/engys/gui/solver/postprocessing/parsers/AbstractParser.java b/src/eu/engys/gui/solver/postprocessing/parsers/AbstractParser.java index 90da429..100fd0f 100644 --- a/src/eu/engys/gui/solver/postprocessing/parsers/AbstractParser.java +++ b/src/eu/engys/gui/solver/postprocessing/parsers/AbstractParser.java @@ -1,34 +1,35 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.solver.postprocessing.parsers; import java.io.BufferedReader; import java.io.File; -import java.io.FileReader; +import java.io.FileInputStream; import java.io.IOException; +import java.io.InputStreamReader; +import java.io.Reader; import java.util.ArrayList; import java.util.List; @@ -42,7 +43,7 @@ import eu.engys.util.Util; public abstract class AbstractParser implements Parser { - private static final int MAX_LINES_PARSED_AT_A_TIME = 100_000; + public static final int MAX_LINES_PARSED_AT_A_TIME = 100_000; private static final Logger logger = LoggerFactory.getLogger(AbstractParser.class); @@ -77,7 +78,9 @@ public abstract class AbstractParser implements Parser { try { File file = getFile(); if (file.exists()) { - in = new BufferedReader(new FileReader(file), 2048); + Reader reader = new InputStreamReader(new FileInputStream(file), Util.UTF_8); +// in = new BufferedReader(new FileReader(file), 2048); + in = new BufferedReader(reader, 2048); logger.info("{} Parsing file {}", getClass().getCanonicalName(), file); } } catch (Exception e) { @@ -121,8 +124,6 @@ public abstract class AbstractParser implements Parser { List newFileLines = updateNewFileLines(); if (newFileLines.size() > 0) { TimeBlocks timeBlocks = updateNewTimeBlocks(newFileLines); - removeInconsistentBlocks(timeBlocks); - checkTimeBlockConsistency(timeBlocks); newFileLines = null; System.gc(); @@ -154,13 +155,8 @@ public abstract class AbstractParser implements Parser { return newFileLines; } - protected void removeInconsistentBlocks(TimeBlocks newTimeBlocks) { - } - protected abstract TimeBlocks updateNewTimeBlocks(List newFileLines); - public abstract boolean checkTimeBlockConsistency(TimeBlocks newTimeBlocks); - @Override public File getFile() { return file; diff --git a/src/eu/engys/gui/solver/postprocessing/parsers/ParserUtils.java b/src/eu/engys/gui/solver/postprocessing/parsers/ParserUtils.java deleted file mode 100644 index 185e7f1..0000000 --- a/src/eu/engys/gui/solver/postprocessing/parsers/ParserUtils.java +++ /dev/null @@ -1,52 +0,0 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - -package eu.engys.gui.solver.postprocessing.parsers; - -import org.slf4j.Logger; - -import eu.engys.core.project.system.monitoringfunctionobjects.TimeBlock; -import eu.engys.core.project.system.monitoringfunctionobjects.TimeBlocks; - -public class ParserUtils { - - public static boolean checkTimeBlockConsistency(TimeBlocks newTimeBlocks, int variablesSize, Logger logger) { - if(newTimeBlocks.isEmpty() || variablesSize < 0){ - return true; - } - for (TimeBlock timeBlock : newTimeBlocks) { - if(timeBlock.getSize() < variablesSize){ - logger.error("The number of units is smaller than the number of variables : {} < {}", timeBlock.getSize(), variablesSize); - return false; - } - if(timeBlock.getSize() > variablesSize){ - logger.error("The number of units is bigger than the number of variables : {} > {}", timeBlock.getSize(), variablesSize); - return false; - } - } - return true; - } - -} diff --git a/src/eu/engys/gui/solver/postprocessing/parsers/ResidualsParser.java b/src/eu/engys/gui/solver/postprocessing/parsers/ResidualsParser.java index 3bd9109..a10d3a1 100644 --- a/src/eu/engys/gui/solver/postprocessing/parsers/ResidualsParser.java +++ b/src/eu/engys/gui/solver/postprocessing/parsers/ResidualsParser.java @@ -1,72 +1,46 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.solver.postprocessing.parsers; import java.io.File; import java.util.List; import java.util.Map; -import org.apache.commons.lang.StringUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import eu.engys.core.project.system.monitoringfunctionobjects.TimeBlock; import eu.engys.core.project.system.monitoringfunctionobjects.TimeBlockUnit; import eu.engys.core.project.system.monitoringfunctionobjects.TimeBlocks; import eu.engys.gui.solver.postprocessing.data.DoubleListTimeBlockUnit; -public class ResidualsParser extends AbstractParser { +public abstract class ResidualsParser extends AbstractParser { - private static final Logger logger = LoggerFactory.getLogger(ResidualsParser.class); public static final String KEY = "residuals"; - private static final String CHECK_STRING1 = ", Initial residual = "; - private static final String CHECK_STRING2 = ", Final residual"; - private static final String CHECK_STRING3 = "Solving for "; - private static final String ILAMBDA = "ILambda"; - public static final String TIME_PREFIX = "Time = "; - - // COUPLED - private static final String TIME_PREFIX_COUPLED = "PHYSICAL TIME = "; - private static final String U_MOM = "U-Mom"; - private static final String V_MOM = "V-Mom"; - private static final String W_MOM = "W-Mom"; - private static final String P_MASS = "p-Mass"; - private static final String K_EQN = "K-Eqn"; - private static final String OMEGA_EQN = "Omega-Eqn"; - private static final String EPSILON_EQN = "Epsilon-Eqn"; - - private TimeBlock incompleteBlock;// from previous parsing - - private int timeBlockSize = -1; + protected Double time; public ResidualsParser(File file) { super(null, file); - this.incompleteBlock = null; - this.timeBlockSize = -1; } @Override @@ -74,161 +48,41 @@ public class ResidualsParser extends AbstractParser { return KEY; } - @Override - public void clear() { - super.clear(); - this.timeBlockSize = -1; - this.incompleteBlock = null; - } - @Override public TimeBlocks updateNewTimeBlocks(List newFileLines) { - // newTimeBlocks.clear(); TimeBlocks newTimeBlocks = new TimeBlocks(blockKey); - - if (incompleteBlock != null) { - newTimeBlocks.add(incompleteBlock); - incompleteBlock = null; - } for (String row : newFileLines) { - if (isValidTimeRow(row)) { - TimeBlock timeBlock = new TimeBlock(Double.parseDouble(extractTimeValue(row))); - newTimeBlocks.add(timeBlock); - } else if (newTimeBlocks.size() > 0 && isValidDataRow(row)) { - String extractVarName = extractVarName(row); - TimeBlock lastTimeBlock = newTimeBlocks.getLast(); - Map unitsMap = lastTimeBlock.getUnitsMap(); - if (!unitsMap.containsKey(extractVarName)) { - unitsMap.put(extractVarName, new DoubleListTimeBlockUnit(extractVarName)); - } - DoubleListTimeBlockUnit unit = (DoubleListTimeBlockUnit) unitsMap.get(extractVarName); - unit.getValues().add(extractInitialResidual(row)); - } + parseRow(newTimeBlocks, row); } - return newTimeBlocks; } - public boolean checkTimeBlockConsistency(TimeBlocks newTimeBlocks) { - return ParserUtils.checkTimeBlockConsistency(newTimeBlocks, timeBlockSize, logger); - } - - @Override - public void removeInconsistentBlocks(TimeBlocks newTimeBlocks) { - boolean timeBlockSizeNotSet = timeBlockSize == -1; - if (newTimeBlocks.size() == 0) { - return; - } else { - if (newTimeBlocks.size() == 1 && timeBlockSizeNotSet) { - // E' il primo blocco in assoluto e non so se e' completo - this.incompleteBlock = newTimeBlocks.removeLast(); - return; - } else { - // Ho piu' di un blocco (quindi almeno il primo e' completo) - // Oppure ho un blocco solo ma non e' il primo (lo capisco dal - // fatto che timeBlockSize e' settata) - - if (timeBlockSizeNotSet) { - timeBlockSize = newTimeBlocks.get(0).getUnitsMap().size(); - } - - if (lastBlockIsIncomplete(newTimeBlocks)) { - this.incompleteBlock = newTimeBlocks.removeLast(); - logger.debug("Block {} is smaller than it should: {} < {} and will be reprocessed", incompleteBlock.getTime(), incompleteBlock.getUnitsMap().size(), timeBlockSize); - } else if (lastBlockIsOK(newTimeBlocks)) { - /* is OK */ - } else { - logger.debug("Block {} is bigger than it should: {} > {}", newTimeBlocks.getLast().getTime(), newTimeBlocks.getLast().getUnitsMap().size(), timeBlockSize); - } + protected void parseRow(TimeBlocks newTimeBlocks, String row) { + if (isValidTimeRow(row)) { + time = Double.parseDouble(extractTimeValue(row)); + newTimeBlocks.add(new TimeBlock(time)); + } else if (isValidDataRow(row) && time != null) { + /* + * It may happen that the previous parse has not completely parsed the last time block + * If this is the case I should create a time block with the same time as the incomplete block and add the missing data + */ + if (newTimeBlocks.size() == 0) { + newTimeBlocks.add(new TimeBlock(time)); } - } - } - - private boolean lastBlockIsIncomplete(TimeBlocks newTimeBlocks) { - TimeBlock lastBlock = newTimeBlocks.getLast(); - return lastBlock.getUnitsMap().size() < timeBlockSize; - } - - private boolean lastBlockIsOK(TimeBlocks newTimeBlocks) { - TimeBlock lastBlock = newTimeBlocks.getLast(); - return lastBlock.getUnitsMap().size() == timeBlockSize; - } - - @Override - public boolean isValidTimeRow(String row) { - boolean isResidualsTimeRow = row.startsWith(TIME_PREFIX); - boolean isCoupledResidualsTimeRow = row.startsWith(TIME_PREFIX_COUPLED); - return isResidualsTimeRow || isCoupledResidualsTimeRow; - } - - @Override - public boolean isValidDataRow(String row) { - return isValidResidualsDataRow(row) || isValidCoupledResidualsDataRow(row); - } - - private boolean isValidResidualsDataRow(String row) { - return row.contains(CHECK_STRING1) && row.contains(CHECK_STRING2) && row.contains(CHECK_STRING3) && !row.contains(ILAMBDA); - } - - private boolean isValidCoupledResidualsDataRow(String row) { - return row.contains(U_MOM) || row.contains(V_MOM) || row.contains(W_MOM) || row.contains(P_MASS) || row.contains(K_EQN) || row.contains(OMEGA_EQN) || row.contains(EPSILON_EQN); - } - - public String extractTimeValue(String row) { - if (row.startsWith(TIME_PREFIX)) { - return row.substring(row.indexOf(TIME_PREFIX) + TIME_PREFIX.length()); - } else if (row.startsWith(TIME_PREFIX_COUPLED)) { - return row.substring(row.indexOf(TIME_PREFIX_COUPLED) + TIME_PREFIX_COUPLED.length()); - } - return ""; - } - - public String extractVarName(String row) { - if (isValidResidualsDataRow(row)) { - return row.substring(row.indexOf(CHECK_STRING3) + CHECK_STRING3.length(), row.indexOf(CHECK_STRING1)); - } else if (isValidCoupledResidualsDataRow(row)) { - if (row.contains(U_MOM)) { - return "Ux"; - } else if (row.contains(V_MOM)) { - return "Uy"; - } else if (row.contains(W_MOM)) { - return "Uz"; - } else if (row.contains(P_MASS)) { - return "p"; - } else if (row.contains(K_EQN)) { - return "k"; - } else if (row.contains(OMEGA_EQN)) { - return "omega"; - } else if (row.contains(EPSILON_EQN)) { - return "epsilon"; - } else { - return ""; + String extractVarName = extractVarName(row); + Map unitsMap = newTimeBlocks.getLast().getUnitsMap(); + if (!unitsMap.containsKey(extractVarName)) { + unitsMap.put(extractVarName, new DoubleListTimeBlockUnit(extractVarName)); } - } else { - return ""; + DoubleListTimeBlockUnit unit = (DoubleListTimeBlockUnit) unitsMap.get(extractVarName); + unit.getValues().add(extractInitialResidual(row)); } } - public Double extractInitialResidual(String row) { - if (isValidResidualsDataRow(row)) { - return Double.parseDouble(row.substring(row.indexOf(CHECK_STRING1) + CHECK_STRING1.length(), row.indexOf(CHECK_STRING2))); - } else if (isValidCoupledResidualsDataRow(row)) { - // the value is beetween the 4th and 5th "|" - int initialDelimiter = StringUtils.ordinalIndexOf(row, "|", 4); - int finalDelimiter = StringUtils.ordinalIndexOf(row, "|", 5); - String stringValue = row.substring(initialDelimiter + 1, finalDelimiter).trim(); - return Double.parseDouble(stringValue); - } - return 0.0; - } + protected abstract String extractTimeValue(String row); - // For test purpose only - public void setIncompleteBlock(TimeBlock incompleteBlock) { - this.incompleteBlock = incompleteBlock; - } - - public void setTimeBlockSize(int timeBlockSize) { - this.timeBlockSize = timeBlockSize; - } + protected abstract String extractVarName(String row); + + protected abstract Double extractInitialResidual(String row); } diff --git a/src/eu/engys/gui/solver/postprocessing/parsers/ResidualsUtils.java b/src/eu/engys/gui/solver/postprocessing/parsers/ResidualsUtils.java index 5a05f60..3671da4 100644 --- a/src/eu/engys/gui/solver/postprocessing/parsers/ResidualsUtils.java +++ b/src/eu/engys/gui/solver/postprocessing/parsers/ResidualsUtils.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.solver.postprocessing.parsers; import java.io.File; @@ -33,14 +32,14 @@ import eu.engys.core.project.openFOAMProject; import eu.engys.util.IOUtils; public class ResidualsUtils { - + public static void clearLogFile(Model model) { File logFile = fileToParse(model); if (logFile != null && logFile.exists()) { IOUtils.clearFile(logFile); } } - + public static File fileToParse(Model model) { String logFile = model.getSolverModel().getLogFile(); if (logFile.isEmpty()) { diff --git a/src/eu/engys/gui/solver/postprocessing/parsers/SimpleResidualsParser.java b/src/eu/engys/gui/solver/postprocessing/parsers/SimpleResidualsParser.java new file mode 100644 index 0000000..3d44278 --- /dev/null +++ b/src/eu/engys/gui/solver/postprocessing/parsers/SimpleResidualsParser.java @@ -0,0 +1,76 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.gui.solver.postprocessing.parsers; + +import java.io.File; + +public class SimpleResidualsParser extends ResidualsParser { + + public static final String CHECK_STRING1 = ", Initial residual = "; + public static final String CHECK_STRING2 = ", Final residual"; + public static final String CHECK_STRING3 = "Solving for "; + public static final String ILAMBDA = "ILambda"; + public static final String TIME_PREFIX = "Time = "; + + public SimpleResidualsParser(File file) { + super(file); + } + + @Override + public boolean isValidTimeRow(String row) { + return row.startsWith(TIME_PREFIX); + } + + @Override + public boolean isValidDataRow(String row) { + return row.contains(CHECK_STRING1) && row.contains(CHECK_STRING2) && row.contains(CHECK_STRING3) && !row.contains(ILAMBDA); + } + + @Override + public String extractTimeValue(String row) { + if (row.startsWith(TIME_PREFIX)) { + return row.substring(row.indexOf(TIME_PREFIX) + TIME_PREFIX.length()); + } + return ""; + } + + @Override + public String extractVarName(String row) { + if (isValidDataRow(row)) { + return row.substring(row.indexOf(CHECK_STRING3) + CHECK_STRING3.length(), row.indexOf(CHECK_STRING1)); + } else { + return ""; + } + } + + @Override + public Double extractInitialResidual(String row) { + if (isValidDataRow(row)) { + return Double.parseDouble(row.substring(row.indexOf(CHECK_STRING1) + CHECK_STRING1.length(), row.indexOf(CHECK_STRING2))); + } + return 0.0; + } + +} diff --git a/src/eu/engys/gui/table/editors/DoubleCellEditor.java b/src/eu/engys/gui/table/editors/DoubleCellEditor.java new file mode 100644 index 0000000..ab2e6d9 --- /dev/null +++ b/src/eu/engys/gui/table/editors/DoubleCellEditor.java @@ -0,0 +1,46 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.gui.table.editors; + +import java.awt.Insets; + +import javax.swing.DefaultCellEditor; + +import eu.engys.util.ui.textfields.DoubleField; + +public class DoubleCellEditor extends DefaultCellEditor { + + public DoubleCellEditor() { + super(new DoubleField(new Insets(0, 0, 0, 0))); + } + + public Object getCellEditorValue() { + try { + return Double.valueOf(Double.parseDouble((String) super.getCellEditorValue())); + } catch (NumberFormatException e) { + return Double.valueOf(((DoubleField) getComponent()).getDoubleValue()); + } + } +} diff --git a/src/eu/engys/gui/table/editors/IntegerCellEditor.java b/src/eu/engys/gui/table/editors/IntegerCellEditor.java new file mode 100644 index 0000000..291e0ed --- /dev/null +++ b/src/eu/engys/gui/table/editors/IntegerCellEditor.java @@ -0,0 +1,46 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.gui.table.editors; + +import java.awt.Insets; + +import javax.swing.DefaultCellEditor; + +import eu.engys.util.ui.textfields.IntegerField; + +public class IntegerCellEditor extends DefaultCellEditor { + + public IntegerCellEditor() { + super(new IntegerField(new Insets(0, 0, 0, 0))); + } + + public Object getCellEditorValue() { + try { + return Integer.valueOf(Integer.parseInt((String) super.getCellEditorValue())); + } catch (NumberFormatException e) { + return Integer.valueOf(((IntegerField) getComponent()).getIntValue()); + } + } +} diff --git a/src/eu/engys/gui/table/editors/StringCellEditor.java b/src/eu/engys/gui/table/editors/StringCellEditor.java new file mode 100644 index 0000000..181770f --- /dev/null +++ b/src/eu/engys/gui/table/editors/StringCellEditor.java @@ -0,0 +1,38 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.gui.table.editors; + +import java.awt.Insets; + +import javax.swing.DefaultCellEditor; + +import eu.engys.util.ui.textfields.StringField; + +public class StringCellEditor extends DefaultCellEditor { + + public StringCellEditor() { + super(new StringField(new Insets(0, 0, 0, 0))); + } +} diff --git a/src/eu/engys/gui/table/editors/TextCellEditor.java b/src/eu/engys/gui/table/editors/TextCellEditor.java new file mode 100644 index 0000000..856e77e --- /dev/null +++ b/src/eu/engys/gui/table/editors/TextCellEditor.java @@ -0,0 +1,182 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.gui.table.editors; + +import java.awt.BorderLayout; +import java.awt.Color; +import java.awt.Component; +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; +import java.awt.Insets; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.KeyEvent; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; + +import javax.swing.AbstractAction; +import javax.swing.AbstractCellEditor; +import javax.swing.BorderFactory; +import javax.swing.Icon; +import javax.swing.JButton; +import javax.swing.JComponent; +import javax.swing.JDialog; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JTable; +import javax.swing.JTextArea; +import javax.swing.KeyStroke; +import javax.swing.SwingUtilities; +import javax.swing.table.TableCellEditor; + +import eu.engys.util.ui.ResourcesUtil; +import eu.engys.util.ui.UiUtil; +import eu.engys.util.ui.textfields.PromptTextField; + +public class TextCellEditor extends AbstractCellEditor implements ActionListener, TableCellEditor { + + private static final Icon ICON_EDIT = ResourcesUtil.getIcon("edit.icon"); + private JPanel component; + private PromptTextField textField; + private JButton button; + private String label; + + public TextCellEditor() { + component = new JPanel() { + @Override + protected boolean processKeyBinding(KeyStroke ks, KeyEvent e, int condition, boolean pressed) { + return textField.processKeyBinding(ks, e, WHEN_FOCUSED, pressed); + } + + @Override + public void validate() { + super.validate(); + repaint(); + } + }; + textField = new PromptTextField(); + textField.addActionListener(this); + textField.setBorder(BorderFactory.createEmptyBorder()); + textField.setBackground(Color.ORANGE); + button = new JButton(ICON_EDIT); + button.addActionListener(this); + button.setBorder(BorderFactory.createEmptyBorder()); + button.setContentAreaFilled(false); + button.setOpaque(false); + + component.setLayout(new GridBagLayout()); + component.setBackground(Color.ORANGE); + component.add(textField, new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); + component.add(button, new GridBagConstraints(1, 0, 1, 1, 0.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.VERTICAL, new Insets(0, 0, 0, 0), 0, 0)); + } + + public void actionPerformed(ActionEvent evt) { + if (evt.getSource() == textField) { + fireEditingStopped(); + } else if (evt.getSource() == button) { + TextEditor dialog = new TextEditor(); + int result = dialog.showEditor(component, label, textField.getText()); + if (result == TextEditor.OK_OPTION) { + textField.setText(dialog.getText()); + fireEditingStopped(); + } + } + } + + public Object getCellEditorValue() { + return textField.getText(); + } + + public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { + this.label = table.getColumnName(column); + + textField.setText(value == null ? "" : value.toString()); + textField.selectAll(); + component.validate(); + return component; + } + + class TextEditor { + static final int OK_OPTION = 0; + static final int CANCEL_OPTION = 0; + + private JTextArea area = new JTextArea(); + private JButton okButton = new JButton(new OkAction()); + private JButton cancelButton = new JButton(new CancelAction()); + private int result; + private JDialog dialog; + + public String getText() { + return area.getText(); + } + + public int showEditor(JComponent parent, String title, String text) { + dialog = new JDialog(SwingUtilities.getWindowAncestor(parent), JDialog.DEFAULT_MODALITY_TYPE); + dialog.setTitle(title); + dialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE); + dialog.addWindowListener(new WindowAdapter() { + @Override + public void windowClosing(WindowEvent e) { + new CancelAction().actionPerformed(null); + } + }); + dialog.getContentPane().add(new JLabel("Enter a description"), BorderLayout.NORTH); + dialog.getContentPane().add(new JScrollPane(area), BorderLayout.CENTER); + dialog.getContentPane().add(UiUtil.getCommandRow(okButton, cancelButton), BorderLayout.SOUTH); + dialog.setSize(300, 200); + dialog.setLocationRelativeTo(null); + dialog.setVisible(true); + return result; + } + + class OkAction extends AbstractAction { + public OkAction() { + super("OK"); + } + @Override + public void actionPerformed(ActionEvent e) { + result = OK_OPTION; + if (dialog != null) { + dialog.dispose(); + } + } + + } + class CancelAction extends AbstractAction { + public CancelAction() { + super("Cancel"); + } + @Override + public void actionPerformed(ActionEvent e) { + result = CANCEL_OPTION; + if (dialog != null) { + dialog.dispose(); + } + } + + } + } +} \ No newline at end of file diff --git a/src/eu/engys/gui/table/renderers/DoubleCellRender.java b/src/eu/engys/gui/table/renderers/DoubleCellRender.java new file mode 100644 index 0000000..99778b5 --- /dev/null +++ b/src/eu/engys/gui/table/renderers/DoubleCellRender.java @@ -0,0 +1,60 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.gui.table.renderers; + +import java.awt.Component; +import java.text.NumberFormat; + +import javax.swing.JLabel; +import javax.swing.JTable; +import javax.swing.table.TableCellRenderer; + +import eu.engys.util.ui.textfields.DoubleField; + +public class DoubleCellRender implements TableCellRenderer { + + private NumberFormat formatter; + private TableCellRenderer defaultRender; + + public DoubleCellRender() { + this.formatter = DoubleField.getFormatForDISPLAY(4); + this.defaultRender = new JTable().getDefaultRenderer(Double.class); + } + + @Override + public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { + JLabel label = (JLabel) defaultRender.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); + if (value instanceof Double) { + Double dValue = (Double) value; + if (dValue.isNaN()) { + label.setText("-"); + } else { + label.setText(formatter.format(value)); + } + } + return label; + } + +} diff --git a/src/eu/engys/gui/tree/AbstractSelectionHandler.java b/src/eu/engys/gui/tree/AbstractSelectionHandler.java index fcb7859..1dfa6a4 100644 --- a/src/eu/engys/gui/tree/AbstractSelectionHandler.java +++ b/src/eu/engys/gui/tree/AbstractSelectionHandler.java @@ -1,30 +1,33 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.tree; +import eu.engys.gui.view3D.Actor; +import eu.engys.gui.view3D.Picker; +import eu.engys.util.ui.checkboxtree.VisibleItem; + public abstract class AbstractSelectionHandler implements SelectionHandler { @@ -44,4 +47,16 @@ public abstract class AbstractSelectionHandler implements SelectionHandler { return enabled; } + @Override + public void handleVisibility(VisibleItem item) { + } + + @Override + public void process3DSelectionEvent(Picker picker, Actor actor, boolean keep) { + } + + @Override + public void process3DVisibilityEvent(boolean selected) { + } + } diff --git a/src/eu/engys/gui/tree/DefaultTreeNodeManager.java b/src/eu/engys/gui/tree/DefaultTreeNodeManager.java index bb59bb3..9914e74 100644 --- a/src/eu/engys/gui/tree/DefaultTreeNodeManager.java +++ b/src/eu/engys/gui/tree/DefaultTreeNodeManager.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.tree; @@ -46,7 +45,7 @@ public class DefaultTreeNodeManager implements TreeNodeManager public DefaultTreeNodeManager(Model model, GUIPanel guiPanel) { this.model = model; - this.nodeMap = new HashMap(); + this.nodeMap = new HashMap<>(); this.root = new DefaultMutableTreeNode(guiPanel); } @@ -54,10 +53,6 @@ public class DefaultTreeNodeManager implements TreeNodeManager public void update(Observable o, Object arg) { } - @Override - public void clear() { - } - @Override public DefaultMutableTreeNode getRoot() { return root; @@ -104,7 +99,9 @@ public class DefaultTreeNodeManager implements TreeNodeManager } public void refreshNode(K key) { - getTree().getModel().nodeChanged(nodeMap.get(key)); + if(key != null && nodeMap.containsKey(key)){ + getTree().getModel().nodeChanged(nodeMap.get(key)); + } } protected void clearNode(DefaultMutableTreeNode node) { diff --git a/src/eu/engys/gui/tree/GUIPanelHandler.java b/src/eu/engys/gui/tree/GUIPanelHandler.java index ad964d4..cf9c43f 100644 --- a/src/eu/engys/gui/tree/GUIPanelHandler.java +++ b/src/eu/engys/gui/tree/GUIPanelHandler.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.tree; diff --git a/src/eu/engys/gui/tree/SelectionHandler.java b/src/eu/engys/gui/tree/SelectionHandler.java index c3e0ab4..ddb3741 100644 --- a/src/eu/engys/gui/tree/SelectionHandler.java +++ b/src/eu/engys/gui/tree/SelectionHandler.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.tree; diff --git a/src/eu/engys/gui/tree/Tree.java b/src/eu/engys/gui/tree/Tree.java index 63cc198..9141463 100644 --- a/src/eu/engys/gui/tree/Tree.java +++ b/src/eu/engys/gui/tree/Tree.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.tree; import java.awt.Component; @@ -59,6 +58,7 @@ import eu.engys.gui.events.view3D.VisibleItemEvent; import eu.engys.gui.tree.TreeNodeManager.PopUpBuilder; import eu.engys.gui.view3D.Actor; import eu.engys.gui.view3D.Picker; +import eu.engys.util.bean.AbstractBean; import eu.engys.util.ui.ExecUtil; import eu.engys.util.ui.TreeUtil; import eu.engys.util.ui.UiUtil; @@ -145,11 +145,13 @@ public class Tree extends JScrollPane { nodesMap.put(guiPanel, node); - int childIndex = guiPanel.getIndex(); - if (childIndex >= 0 && childIndex <= root.getChildCount()) { - root.insert(node, childIndex); - } else { - root.add(node); + if (node != null) { + int childIndex = guiPanel.getIndex(); + if (childIndex >= 0 && childIndex <= root.getChildCount()) { + root.insert(node, childIndex); + } else { + root.add(node); + } } getModel().reload(); @@ -279,12 +281,12 @@ public class Tree extends JScrollPane { ExecUtil.invokeAndWait(new Runnable() { @Override public void run() { - processTreeCheckBoxSelectionEvent(select); + processActorVisibilityEvent(select); } }); } - private void processTreeCheckBoxSelectionEvent(boolean selected) { + private void processActorVisibilityEvent(boolean selected) { for (SelectionHandler handler : selectionHandlersMap.values()) { if (handler.isEnabled()) { handler.process3DVisibilityEvent(selected); @@ -444,7 +446,7 @@ public class Tree extends JScrollPane { return klass; } - if (klass.getSuperclass() != null && klass.getSuperclass() != Object.class) { + if (klass.getSuperclass() != null && klass.getSuperclass() != Object.class && klass.getSuperclass() != AbstractBean.class) { return containsClass(klass.getSuperclass()); } diff --git a/src/eu/engys/gui/tree/TreeNodeManager.java b/src/eu/engys/gui/tree/TreeNodeManager.java index c48f0c5..07e8940 100644 --- a/src/eu/engys/gui/tree/TreeNodeManager.java +++ b/src/eu/engys/gui/tree/TreeNodeManager.java @@ -1,29 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.tree; import java.util.Observer; @@ -32,11 +30,8 @@ import javax.swing.JPopupMenu; import javax.swing.tree.DefaultMutableTreeNode; import javax.swing.tree.DefaultTreeCellRenderer; - public interface TreeNodeManager extends Observer { - public void clear(); - public DefaultMutableTreeNode getRoot(); public void setTree(Tree tree); @@ -49,9 +44,9 @@ public interface TreeNodeManager extends Observer { public SelectionHandler getSelectionHandler(); - public PopUpBuilder getPopUpBuilder(); + public PopUpBuilder getPopUpBuilder(); - public interface PopUpBuilder { - void populate(JPopupMenu popUp); - } + public interface PopUpBuilder { + void populate(JPopupMenu popUp); + } } diff --git a/src/eu/engys/gui/tree/TreeSelectionModel.java b/src/eu/engys/gui/tree/TreeSelectionModel.java index 2a2fca5..f00c1a8 100644 --- a/src/eu/engys/gui/tree/TreeSelectionModel.java +++ b/src/eu/engys/gui/tree/TreeSelectionModel.java @@ -1,29 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.tree; import java.util.List; @@ -36,43 +34,44 @@ import eu.engys.util.ui.TreeUtil; public class TreeSelectionModel extends DefaultTreeSelectionModel { - public TreeSelectionModel() { - super(); - } - - @Override - public void setSelectionPaths(TreePath[] selectionPath) { - if ((selectionPath != null) && (selectionPath.length > 0)) { - TreePath firstPathParent = selectionPath[0].getParentPath(); + public TreeSelectionModel() { + super(); + } - if (firstPathParent == null) { - TreePath[] paths = new TreePath[] {selectionPath[0]}; - super.setSelectionPaths(paths); - return; - } + @Override + public void setSelectionPaths(TreePath[] selectionPath) { + if ((selectionPath != null) && (selectionPath.length > 0)) { + TreePath firstPathParent = selectionPath[0].getParentPath(); - if (TreeUtil.areSiblings(selectionPath, firstPathParent)) { - TreePath[] consistentPath = TreeUtil.getAConsistentSelection(selectionPath); - if (consistentPath.length > 0) { - super.setSelectionPaths(consistentPath); - } -// } - } - } - } - - @Override + if (firstPathParent == null) { + TreePath[] paths = new TreePath[] { selectionPath[0] }; + super.setSelectionPaths(paths); + return; + } + + if (TreeUtil.areSiblings(selectionPath, firstPathParent)) { + TreePath[] consistentPath = TreeUtil.getAConsistentSelection(selectionPath); + if (consistentPath.length > 0) { + super.setSelectionPaths(consistentPath); + } + } + } + } + + @Override public void addSelectionPaths(TreePath[] selectionPath) { if (getSelectionPath() != null) { TreePath firstPathParent = getSelectionPath().getParentPath(); if (TreeUtil.areSiblings(selectionPath, firstPathParent)) { Class leadSelectionClass = ((DefaultMutableTreeNode) getSelectionPath().getLastPathComponent()).getUserObject().getClass(); List selection = TreeUtil.toUserObjects(selectionPath); - - if (TreeUtil.isConsistent(selection.toArray(), leadSelectionClass)) { - super.addSelectionPaths(selectionPath); + + if (((DefaultMutableTreeNode) selectionPath[0].getLastPathComponent()).getLevel() > 1) { + if (TreeUtil.isConsistent(selection.toArray(), leadSelectionClass)) { + super.addSelectionPaths(selectionPath); + } } - } - } - } + } + } + } } diff --git a/src/eu/engys/gui/view/AbstractView3DElement.java b/src/eu/engys/gui/view/AbstractView3DElement.java index c1ecff9..f911257 100644 --- a/src/eu/engys/gui/view/AbstractView3DElement.java +++ b/src/eu/engys/gui/view/AbstractView3DElement.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.view; diff --git a/src/eu/engys/gui/view/AbstractViewElement.java b/src/eu/engys/gui/view/AbstractViewElement.java index a73874a..5911f4b 100644 --- a/src/eu/engys/gui/view/AbstractViewElement.java +++ b/src/eu/engys/gui/view/AbstractViewElement.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.view; import java.util.HashSet; @@ -36,13 +35,17 @@ import org.slf4j.LoggerFactory; import eu.engys.core.modules.ApplicationModule; import eu.engys.core.project.Model; import eu.engys.core.project.openFOAMProject; +import eu.engys.core.project.geometry.Geometry; +import eu.engys.core.project.geometry.Surface; import eu.engys.core.project.materials.Materials; import eu.engys.core.project.runtimefields.RuntimeFields; import eu.engys.core.project.state.Solver; import eu.engys.core.project.state.State; import eu.engys.core.project.system.fieldmanipulationfunctionobjects.FieldManipulationFunctionObjects; +import eu.engys.core.project.system.monitoringfunctionobjects.MonitoringFunctionObject; import eu.engys.core.project.system.monitoringfunctionobjects.MonitoringFunctionObjects; import eu.engys.core.project.zero.fields.Fields; +import eu.engys.core.project.zero.patches.BoundaryType; import eu.engys.gui.Actions; import eu.engys.gui.GUIError; import eu.engys.gui.GUIPanel; @@ -197,7 +200,6 @@ public abstract class AbstractViewElement implements ViewElement { public void changeObserved(Object arg) { for (ModelObserver observer : getPanel().getObservers()) { logger.trace("[CHANGE OBSERVED] [{}] -> Panel: {}", arg.getClass().getSimpleName(), observer.getTitle()); - if (arg instanceof State) { observer.stateChanged(); } else if (arg instanceof Solver) { @@ -206,6 +208,12 @@ public abstract class AbstractViewElement implements ViewElement { observer.materialsChanged(); } else if (arg instanceof Fields) { observer.fieldsChanged(); + } else if (arg instanceof BoundaryType) { + observer.boundaryTypeChanged((BoundaryType) arg); + } else if(arg instanceof Geometry){ + observer.geometryChanged(); + }else if(arg instanceof Surface){ + observer.geometryChanged(); } else if (arg instanceof RuntimeFields) { observer.runtimeFieldsChanged(); } else if (arg instanceof openFOAMProject) { @@ -214,6 +222,8 @@ public abstract class AbstractViewElement implements ViewElement { observer.fieldManipulationFunctionObjectsChanged(); } else if (arg instanceof MonitoringFunctionObjects) { observer.monitoringFunctionObjectsChanged(); + } else if (arg instanceof MonitoringFunctionObject) { + observer.monitoringFunctionObjectChanged((MonitoringFunctionObject) arg); } } } diff --git a/src/eu/engys/gui/view/ApplicationToolBar.java b/src/eu/engys/gui/view/ApplicationToolBar.java index 17e6467..1a5341c 100644 --- a/src/eu/engys/gui/view/ApplicationToolBar.java +++ b/src/eu/engys/gui/view/ApplicationToolBar.java @@ -1,102 +1,146 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.view; +import static eu.engys.core.controller.AbstractController.OPEN_PARAMETERS_MANAGER; +import static eu.engys.core.controller.AbstractController.OPEN_RUN_MODE; +import static eu.engys.core.controller.AbstractController.PARALLEL_WORKS; +import static eu.engys.gui.view.View.BROWSE_CASE; +import static eu.engys.gui.view.View.EXIT; +import static eu.engys.gui.view.View.NEW_CASE; +import static eu.engys.gui.view.View.OPEN_CASE; +import static eu.engys.gui.view.View.OPEN_TERMINAL; +import static eu.engys.gui.view.View.RECENT_CASES; +import static eu.engys.gui.view.View.SAVE_AS_CASE; +import static eu.engys.gui.view.View.SAVE_CASE; import static eu.engys.util.ui.UiUtil.createToolBarButton; -import javax.swing.BorderFactory; -import javax.swing.Box; import javax.swing.JToolBar; import javax.swing.SwingUtilities; import eu.engys.core.presentation.ActionManager; import eu.engys.core.project.Model; import eu.engys.launcher.StartUpMonitor; +import eu.engys.util.ui.UiUtil; import eu.engys.util.ui.ViewAction; -public class ApplicationToolBar extends JToolBar { +public class ApplicationToolBar { + + public static final String APPLICATION_TOOLBAR = "application.toolbar"; private Model model; + private JToolBar toolbar; + public ApplicationToolBar(Model model) { - super(JToolBar.HORIZONTAL); this.model = model; + this.toolbar = UiUtil.getToolbarWrapped(APPLICATION_TOOLBAR); StartUpMonitor.info("Loading Toolbar"); - setFloatable(false); - setRollover(true); - setOpaque(false); - setBorder(BorderFactory.createEmptyBorder()); - layoutComponents(); } private void layoutComponents() { - add(createToolBarButton(ActionManager.getInstance().get("application.create"))); - add(createToolBarButton(ActionManager.getInstance().get("application.open"))); - add(createToolBarButton(ActionManager.getInstance().get("application.recent"))); - add(createToolBarButton(ActionManager.getInstance().get("application.save"))); - add(createToolBarButton(ActionManager.getInstance().get("application.saveAs"))); - addSeparator(); - add(createToolBarButton(ActionManager.getInstance().get("application.open.terminal"))); - add(createToolBarButton(ActionManager.getInstance().get("application.browse.case"))); + if (ActionManager.getInstance().contains(NEW_CASE)) { + toolbar.add(createToolBarButton(ActionManager.getInstance().get(NEW_CASE))); + } + toolbar.add(createToolBarButton(ActionManager.getInstance().get(OPEN_CASE))); + toolbar.add(createToolBarButton(ActionManager.getInstance().get(RECENT_CASES))); + if (ActionManager.getInstance().contains(SAVE_CASE)) { + toolbar.add(createToolBarButton(ActionManager.getInstance().get(SAVE_CASE))); + ActionManager.getInstance().get(SAVE_CASE).setEnabled(false); + } + if (ActionManager.getInstance().contains(SAVE_AS_CASE)) { + toolbar.add(createToolBarButton(ActionManager.getInstance().get(SAVE_AS_CASE))); + ActionManager.getInstance().get(SAVE_AS_CASE).setEnabled(false); + } + toolbar.addSeparator(); + toolbar.add(createToolBarButton(ActionManager.getInstance().get(OPEN_TERMINAL))); + toolbar.add(createToolBarButton(ActionManager.getInstance().get(BROWSE_CASE))); - if (ActionManager.getInstance().contains("application.support.window")) { - addSeparator(); - add(createToolBarButton(ActionManager.getInstance().get("application.support.window"))); + // add the run cloud button + toolbar.addSeparator(); + if (ActionManager.getInstance().contains(PARALLEL_WORKS)) { + toolbar.add(createToolBarButton(ActionManager.getInstance().get(PARALLEL_WORKS))); + ActionManager.getInstance().get(PARALLEL_WORKS).setEnabled(false); } - ViewAction connectionAction = ActionManager.getInstance().get("application.connection.window"); - if (ActionManager.getInstance().contains("application.connection.window")) { - addSeparator(); - add(createToolBarButton(connectionAction)); + ViewAction connectionAction = ActionManager.getInstance().get(OPEN_RUN_MODE); + if (ActionManager.getInstance().contains(OPEN_RUN_MODE)) { + toolbar.addSeparator(); + toolbar.add(createToolBarButton(connectionAction)); connectionAction.setEnabled(false); } - add(Box.createHorizontalGlue()); - add(createToolBarButton(ActionManager.getInstance().get("application.exit"))); + if (ActionManager.getInstance().contains(OPEN_PARAMETERS_MANAGER)) { + toolbar.add(createToolBarButton(ActionManager.getInstance().get(OPEN_PARAMETERS_MANAGER))); + } + // if (ActionManager.getInstance().contains(EXIT)) { + // toolbar.add(Box.createHorizontalGlue()); + // toolbar.add(createToolBarButton(ActionManager.getInstance().get(EXIT))); + // } - ActionManager.getInstance().get("application.save").setEnabled(false); - ActionManager.getInstance().get("application.saveAs").setEnabled(false); - ActionManager.getInstance().get("application.open.terminal").setEnabled(false); - ActionManager.getInstance().get("application.browse.case").setEnabled(false); + ActionManager.getInstance().get(OPEN_TERMINAL).setEnabled(false); + ActionManager.getInstance().get(BROWSE_CASE).setEnabled(false); + } + + public JToolBar getExitButton() { + if (ActionManager.getInstance().contains(EXIT)) { + return UiUtil.createButtonToolbarStyle(createToolBarButton(ActionManager.getInstance().get(EXIT))); + } + return null; } public void refresh() { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { - ActionManager.getInstance().get("application.save").setEnabled(model.getProject() != null); - ActionManager.getInstance().get("application.saveAs").setEnabled(model.getProject() != null); - ActionManager.getInstance().get("application.open.terminal").setEnabled(model.getProject() != null); - ActionManager.getInstance().get("application.browse.case").setEnabled(model.getProject() != null); - if (ActionManager.getInstance().contains("application.connection.window")) { - ActionManager.getInstance().get("application.connection.window").setEnabled(model.getProject() != null); + boolean hasProject = model.getProject() != null; + + if (ActionManager.getInstance().contains(SAVE_CASE)) { + ActionManager.getInstance().get(SAVE_CASE).setEnabled(hasProject); + } + if (ActionManager.getInstance().contains(SAVE_AS_CASE)) { + ActionManager.getInstance().get(SAVE_AS_CASE).setEnabled(hasProject); + } + ActionManager.getInstance().get(OPEN_TERMINAL).setEnabled(hasProject); + ActionManager.getInstance().get(BROWSE_CASE).setEnabled(hasProject); + if (ActionManager.getInstance().contains(OPEN_RUN_MODE)) { + ActionManager.getInstance().get(OPEN_RUN_MODE).setEnabled(hasProject); + } + if (ActionManager.getInstance().contains(PARALLEL_WORKS)) { + ActionManager.getInstance().get(PARALLEL_WORKS).setEnabled(model.getProject() != null); + } + if (ActionManager.getInstance().contains(OPEN_PARAMETERS_MANAGER)) { + ActionManager.getInstance().get(OPEN_PARAMETERS_MANAGER).setEnabled(hasProject); } } }); } + public JToolBar getToolbar() { + return toolbar; + } + } diff --git a/src/eu/engys/gui/view/DefaultControllerListener.java b/src/eu/engys/gui/view/DefaultControllerListener.java index 01c003a..db737de 100644 --- a/src/eu/engys/gui/view/DefaultControllerListener.java +++ b/src/eu/engys/gui/view/DefaultControllerListener.java @@ -1,45 +1,56 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.view; +import java.util.Set; + +import javax.swing.JOptionPane; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import eu.engys.core.controller.Controller; import eu.engys.core.controller.ControllerListener; import eu.engys.core.controller.GeometryToMesh; -import eu.engys.core.executor.TerminalManager; +import eu.engys.core.modules.ApplicationModule; +import eu.engys.core.modules.ModulesUtil; +import eu.engys.core.project.InvalidProjectException; import eu.engys.core.project.Model; +import eu.engys.util.ui.UiUtil; public class DefaultControllerListener implements ControllerListener { private static final Logger logger = LoggerFactory.getLogger(DefaultControllerListener.class); private View view; private ElementSelector selector; + private Set modules; + private Controller controller; - public DefaultControllerListener(Model model, View view) { + public DefaultControllerListener(Model model, Controller controller, Set modules, View view) { + this.controller = controller; + this.modules = modules; this.view = view; this.selector = new ElementSelector(model, view); } @@ -65,43 +76,51 @@ public class DefaultControllerListener implements ControllerListener { @Override public void beforeNewCase() { logger.debug("BEFORE NEW CASE"); - TerminalManager.getInstance().clear(); - view.clear(); + view.clear(true); if (view.getController().getClient() != null) { view.getController().getClient().reset(); } } @Override - public void afterNewCase() { + public void afterNewCase(boolean loadMesh) { logger.debug("AFTER NEW CASE"); - view.loadView(); + view.loadView(loadMesh); selector.goToFirstElement(); } @Override public void beforeLoadCase() { logger.debug("BEFORE LOAD CASE"); - view.clear(); - TerminalManager.getInstance().clear(); + view.clear(true); + if (view.getController().getClient() != null) { + view.getController().getClient().reset(); + } } @Override - public void afterLoadCase() { + public void afterLoadCase(boolean loadMesh) { logger.debug("AFTER LOAD CASE"); - view.loadView(); + try { + ModulesUtil.checkIfCanOpenCase(modules); + view.loadView(loadMesh); + } catch (InvalidProjectException e) { + logger.error(e.getMessage()); + JOptionPane.showMessageDialog(UiUtil.getActiveWindow(), e.getMessage(), "Project error", JOptionPane.ERROR_MESSAGE); + controller.clearModel(); + } } @Override public void beforeReopenCase() { logger.debug("BEFORE REOPEN CASE"); - view.clear(); + view.clear(false); } @Override public void afterReopenCase() { logger.debug("AFTER REOPEN CASE"); - afterLoadCase(); + afterLoadCase(true); } @Override @@ -115,7 +134,7 @@ public class DefaultControllerListener implements ControllerListener { logger.debug("AFTER SAVE CASE"); view.loadToolbars(); } - + /* * Base mesh from file */ @@ -130,10 +149,12 @@ public class DefaultControllerListener implements ControllerListener { @Override public void beforeCheckMesh() { + logger.debug("BEFORE CHECK MESH"); } @Override public void afterCheckMesh() { + logger.debug("AFTER CHECK MESH"); view.getCanvasPanel().getMeshController().readTimeSteps(); view.getCanvasPanel().loadWidgets(); selector.goToBoundaryMesh(); @@ -171,4 +192,10 @@ public class DefaultControllerListener implements ControllerListener { view.getCanvasPanel().loadWidgets(); } + @SuppressWarnings("unchecked") + @Override + public void afterSetupCase() { + view.getMainPanel().load(ElementSelector.getMeshElementClass(), ElementSelector.getCaseSetupElementClass()); + } + } diff --git a/src/eu/engys/gui/view/ElementSelector.java b/src/eu/engys/gui/view/ElementSelector.java index 37505b1..e02bbc3 100644 --- a/src/eu/engys/gui/view/ElementSelector.java +++ b/src/eu/engys/gui/view/ElementSelector.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.view; import org.slf4j.Logger; @@ -33,9 +32,9 @@ import eu.engys.core.project.SolverState; import eu.engys.util.ui.ExecUtil; public class ElementSelector { - + private static final Logger logger = LoggerFactory.getLogger(ElementSelector.class); - + public static final String MESH = "Mesh"; private static final String MESH_ELEMENT = "eu.engys.gui.mesh.MeshElement"; @@ -44,10 +43,10 @@ public class ElementSelector { private static final String SOLVER_ELEMENT = "eu.engys.gui.solver.SolverElement"; public static final String RESIDUALS = "Residuals"; - + private Model model; private View view; - + private Class currentTab; private String currentNode; @@ -57,26 +56,26 @@ public class ElementSelector { } public void selectDestinationAndGo() { - if(model.hasProject()){ + if (model.hasProject()) { if (model.getSolverModel() != null && model.getSolverModel().getServerState() != null && model.getSolverModel().getServerState().getSolverState().isDoingSomething()) { SolverState solverState = model.getSolverModel().getServerState().getSolverState(); - if(solverState.isMeshing()){ + if (solverState.isMeshing()) { goToTabAndPanel(getMeshElementClass(), null); - } else if (solverState.isInitialising()){ + } else if (solverState.isInitialising()) { goToFieldsInitialisation(); - } else if (solverState.isRunning()){ + } else if (solverState.isRunning()) { goToResiduals(); } else { goToFirstElement(); } } else { goToFirstElement(); - } + } } } - + public void saveLocation() { - if(view.getMainPanel().getCurrentElement() != null){ + if (view.getMainPanel().getCurrentElement() != null) { this.currentTab = view.getMainPanel().getCurrentElement().getClass(); this.currentNode = view.getMainPanel().getElement(currentTab).getPanel().getSelectedNode(); } else { @@ -89,43 +88,52 @@ public class ElementSelector { public void goToLocation() { goToTabAndPanel(currentTab, currentNode); } - + public void goToFirstElement() { - goToTabAndPanel((Class)null, null); + goToTabAndPanel((Class) null, null); } public void goToBoundaryMesh() { - goToTabAndPanel(getMeshElementClass(), MESH); - view.getMainPanel().getElement(getMeshElementClass()).getPanel().getNode(MESH).start(); + try { + goToTabAndPanel(getMeshElementClass(), MESH); + view.getMainPanel().getElement(getMeshElementClass()).getPanel().getNode(MESH).start(); + } catch (Exception e) { + // TO avoid null pointer from HELYX-SAS + } } private void goToFieldsInitialisation() { goToTabAndPanel(getCaseSetupElementClass(), FIELDS_INITIALISATION); } - + public void goToResiduals() { goToTabAndPanel(getSolverElementClass(), RESIDUALS); } - + private void goToTabAndPanel(final Class klass, final String panel) { ExecUtil.invokeLater(new Runnable() { @Override public void run() { - view.getMainPanel().stop(null); - view.getMainPanel().start(klass); - view.getCanvasPanel().start(klass); - - if(panel != null){ - view.getMainPanel().getElement(klass).getPanel().selectNode(panel); + try { + view.getMainPanel().stop(null); + view.getCanvasPanel().stop(null); + view.getMainPanel().start(klass); + view.getCanvasPanel().start(klass); + + if (panel != null) { + view.getMainPanel().getElement(klass).getPanel().selectNode(panel); + } + + logger.debug("Location selected: {} - {}", klass, panel); + } catch (Exception e) { + // TO avoid null pointer from HELYX-SAS } - - logger.debug("Location selected: {} - {}", klass, panel); } }); } - + @SuppressWarnings("unchecked") - private Class getCaseSetupElementClass() { + static Class getCaseSetupElementClass() { try { return (Class) Class.forName(CASE_SETUP_ELEMENT); } catch (ClassNotFoundException e) { @@ -134,7 +142,7 @@ public class ElementSelector { } @SuppressWarnings("unchecked") - private Class getSolverElementClass() { + static Class getSolverElementClass() { try { return (Class) Class.forName(SOLVER_ELEMENT); } catch (ClassNotFoundException e) { @@ -143,7 +151,7 @@ public class ElementSelector { } @SuppressWarnings("unchecked") - private Class getMeshElementClass() { + static Class getMeshElementClass() { try { return (Class) Class.forName(MESH_ELEMENT); } catch (ClassNotFoundException e) { diff --git a/src/eu/engys/gui/view/GlassLayerUI.java b/src/eu/engys/gui/view/GlassLayerUI.java new file mode 100644 index 0000000..187907a --- /dev/null +++ b/src/eu/engys/gui/view/GlassLayerUI.java @@ -0,0 +1,91 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.gui.view; + +import static java.awt.AlphaComposite.SRC_OVER; + +import java.awt.AWTEvent; +import java.awt.AlphaComposite; +import java.awt.Color; +import java.awt.Composite; +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.RenderingHints; +import java.awt.event.InputEvent; + +import javax.swing.JComponent; +import javax.swing.JLayer; +import javax.swing.JPanel; +import javax.swing.plaf.LayerUI; + +public class GlassLayerUI extends LayerUI { + + private boolean active = false; + + @Override + public void eventDispatched(AWTEvent e, JLayer l) { + if (e instanceof InputEvent && active) { + ((InputEvent) e).consume(); + } + } + + @Override + public void installUI(JComponent c) { + super.installUI(c); + JLayer jlayer = (JLayer) c; + jlayer.setLayerEventMask(AWTEvent.MOUSE_EVENT_MASK | AWTEvent.MOUSE_MOTION_EVENT_MASK); + } + + @Override + public void uninstallUI(JComponent c) { + JLayer jlayer = (JLayer) c; + jlayer.setLayerEventMask(0); + super.uninstallUI(c); + } + + @Override + public void paint(Graphics g, JComponent c) { + super.paint(g, c); + Graphics2D g2 = (Graphics2D) g.create(); + + int w = c.getWidth(); + int h = c.getHeight(); + + // float alpha = 1.0f; + float alpha = 0.0f; + Color color = Color.BLUE; + g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); + Composite backupComposite = g2.getComposite(); + g2.setColor(color); + g2.setComposite(AlphaComposite.getInstance(SRC_OVER, alpha)); + g2.fillRect(0, 0, w, h); + g2.setComposite(backupComposite); + g2.dispose(); + } + + public void setActive(boolean active) { + this.active = active; + } +} \ No newline at end of file diff --git a/src/eu/engys/gui/view/MainPanel.java b/src/eu/engys/gui/view/MainPanel.java index 4c0abfa..bfcaf6d 100644 --- a/src/eu/engys/gui/view/MainPanel.java +++ b/src/eu/engys/gui/view/MainPanel.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.view; import java.awt.BorderLayout; @@ -76,10 +75,12 @@ public class MainPanel extends JPanel { private ViewElement currentElement; private TabChangeListener tabChangeListener; + private TerminalManager terminalManager; - public MainPanel(Model model, Set viewElements, ProgressMonitor monitor) { + public MainPanel(Model model, Set viewElements, TerminalManager terminalManager, ProgressMonitor monitor) { this.model = model; this.viewElements = viewElements; + this.terminalManager = terminalManager; this.monitor = monitor; } @@ -96,9 +97,10 @@ public class MainPanel extends JPanel { JSplitPane terminalSplitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT); terminalSplitPane.setTopComponent(tabbedPane); - terminalSplitPane.setBottomComponent(TerminalManager.getInstance().getComponent()); - terminalSplitPane.setResizeWeight(1); + terminalSplitPane.setBottomComponent(terminalManager.getComponent()); terminalSplitPane.setOneTouchExpandable(false); + terminalManager.setParent(terminalSplitPane); + terminalManager.collapse(); add(terminalSplitPane); @@ -153,6 +155,14 @@ public class MainPanel extends JPanel { } } + @SuppressWarnings("unchecked") + public void load(Class... klasses) { + for (Class klass : klasses) { + final ViewElement element = elementsByClass.get(klass); + _load(element); + } + } + public void load() { for (ViewElement element : viewElements) { _load(element); diff --git a/src/eu/engys/gui/view/StatusBar.java b/src/eu/engys/gui/view/StatusBar.java index 321ed81..adb759b 100644 --- a/src/eu/engys/gui/view/StatusBar.java +++ b/src/eu/engys/gui/view/StatusBar.java @@ -1,63 +1,75 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.view; +import static eu.engys.util.SystemEnv.LICENSE_STATUS; + +import java.awt.BorderLayout; import java.awt.Dimension; import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; +import java.awt.event.MouseEvent; import javax.swing.BorderFactory; -import javax.swing.Box; -import javax.swing.BoxLayout; import javax.swing.Icon; import javax.swing.JButton; import javax.swing.JComponent; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JToolBar; -import javax.swing.JToolBar.Separator; -import javax.swing.SwingConstants; import org.apache.commons.lang.StringUtils; -import eu.engys.core.executor.TerminalManager; +import eu.engys.core.controller.Controller; import eu.engys.core.project.Model; import eu.engys.core.project.openFOAMProject; import eu.engys.gui.events.EventManager; import eu.engys.gui.events.application.OpenMonitorEvent; +import eu.engys.launcher.StartUpMonitor; import eu.engys.util.ApplicationInfo; import eu.engys.util.MemoryWidget; import eu.engys.util.ui.ExecUtil; import eu.engys.util.ui.ResourcesUtil; +import eu.engys.util.ui.UiUtil; +import eu.engys.util.ui.ViewAction; public class StatusBar extends JPanel { private static final Icon consoleIcon = ResourcesUtil.getIcon("console.tab.icon"); - private static final Icon monitorIcon = ResourcesUtil.getIcon("console.tab.icon"); + private static final Icon monitorIcon = ResourcesUtil.getIcon("application.icon"); + private static final String SERIAL = "Serial"; + private static final String PARALLEL = "Parallel"; + private static final String REMOTE = "REMOTE"; + private static final String LOCAL = "LOCAL"; + private static final String OPEN_STATUS_DIALOG = "Open Status Dialog"; + private static final String OPEN_TERMINAL_DIALOG = "Hide/Open Terminal Bar"; + private static final String TEXT_OFFSET = " "; + private static final String DOTS = "..."; + private static final String DEFAULT_TEXT = StringUtils.repeat(" ", 10); + private static final int MAX_PROJECT_PATH_WIDTH = 600; private JButton terminalButton; private JLabel nameLabel; @@ -67,46 +79,50 @@ public class StatusBar extends JPanel { private JLabel licenseLabel; private JButton monitorButton; private MemoryWidget memoryWidget; + private Controller controller; - public StatusBar() { - super(); + public StatusBar(Controller controller) { + super(new BorderLayout()); + StartUpMonitor.info("Loading Status Bar"); + this.controller = controller; layoutComponents(); } private void layoutComponents() { - setLayout(new BoxLayout(this, BoxLayout.X_AXIS)); - + setOpaque(false); + terminalButton = createTerminalButton(); nameLabel = createLabel(ApplicationInfo.getName()); versionLabel = createLabel(ApplicationInfo.getVersion() + " " + "[" + ApplicationInfo.getBuildDate() + "]"); caseLabel = createLabel(DEFAULT_TEXT); typeLabel = createLabel(DEFAULT_TEXT); - licenseLabel = createLabel(DEFAULT_TEXT); + licenseLabel = createLabel("License: " + System.getProperty(LICENSE_STATUS)); monitorButton = createMonitorButton(); memoryWidget = createMemoryWidget(); - add(terminalButton); - addSeparator(); - add(nameLabel); - addSeparator(); - add(versionLabel); - addSeparator(); - add(caseLabel); - addSeparator(); - add(typeLabel); - addSeparator(); - add(licenseLabel); - add(Box.createHorizontalGlue()); - add(monitorButton); - addSeparator(); - add(memoryWidget); - } + JToolBar leftPanel = UiUtil.getToolbarWrapped(); + leftPanel.add(terminalButton); + leftPanel.add(nameLabel); + leftPanel.addSeparator(); + leftPanel.add(versionLabel); + if (System.getProperty(LICENSE_STATUS) != null) { + leftPanel.addSeparator(); + leftPanel.add(licenseLabel); + } + leftPanel.addSeparator(); + leftPanel.add(caseLabel); + leftPanel.addSeparator(); + leftPanel.add(typeLabel); - private void addSeparator() { - Separator separator = new JToolBar.Separator(); - separator.setOrientation(SwingConstants.VERTICAL); - add(separator); + JToolBar rightPanel = UiUtil.getToolbarWrapped(); + rightPanel.addSeparator(); + rightPanel.add(monitorButton); + rightPanel.addSeparator(); + rightPanel.add(memoryWidget); + + add(leftPanel, BorderLayout.CENTER); + add(rightPanel, BorderLayout.EAST); } private MemoryWidget createMemoryWidget() { @@ -116,20 +132,23 @@ public class StatusBar extends JPanel { } private JButton createMonitorButton() { - JButton button = new JButton(monitorIcon); - button.setFocusable(false); - button.setBorder(BorderFactory.createEmptyBorder()); - button.addActionListener(new ActionListener() { + ViewAction monitorAction = new ViewAction(monitorIcon, OPEN_STATUS_DIALOG) { @Override public void actionPerformed(ActionEvent e) { EventManager.triggerEvent(this, new OpenMonitorEvent()); } - }); - return button; + + }; + JButton monitorButton = new JButton(monitorAction) { + public java.awt.Point getToolTipLocation(MouseEvent event) { + return new java.awt.Point(0, -20); + } + }; + return monitorButton; } private JLabel createLabel(String text) { - JLabel label = new JLabel(text); + JLabel label = new JLabel(TEXT_OFFSET + text + TEXT_OFFSET); label.setBorder(BorderFactory.createEmptyBorder()); setupDimensions(label, label.getText()); @@ -144,15 +163,20 @@ public class StatusBar extends JPanel { } private JButton createTerminalButton() { - JButton button = new JButton(consoleIcon); - button.setFocusable(false); - button.setBorder(BorderFactory.createEmptyBorder()); - button.addActionListener(new ActionListener() { + ViewAction terminalAction = new ViewAction(consoleIcon, OPEN_TERMINAL_DIALOG) { @Override public void actionPerformed(ActionEvent e) { - TerminalManager.getInstance().toggleVisibility(); + if (controller != null) { + controller.getTerminalManager().toggleVisibility(); + } } - }); + + }; + JButton button = new JButton(terminalAction) { + public java.awt.Point getToolTipLocation(MouseEvent event) { + return new java.awt.Point(0, -20); + } + }; return button; } @@ -160,12 +184,18 @@ public class StatusBar extends JPanel { ExecUtil.invokeLater(new Runnable() { public void run() { openFOAMProject project = model.getProject(); + if (project != null) { - caseLabel.setText(project.getBaseDir().getAbsolutePath()); - typeLabel.setText(project.isParallel() ? "Parallel" : "Serial"); + String parallel = project.isParallel() ? PARALLEL + " (" + project.getProcessors() + ")" : SERIAL; + String remote = model.getSolverModel().isRemote() ? REMOTE : LOCAL; + + typeLabel.setText(TEXT_OFFSET + parallel + TEXT_OFFSET + remote + TEXT_OFFSET); + caseLabel.setText(TEXT_OFFSET + getProjectPath(project.getBaseDir().getAbsolutePath()) + TEXT_OFFSET); + caseLabel.setToolTipText(project.getBaseDir().getAbsolutePath()); } else { - caseLabel.setText(""); typeLabel.setText(""); + caseLabel.setText(""); + caseLabel.setToolTipText(""); } setupDimensions(caseLabel, caseLabel.getText()); @@ -175,10 +205,32 @@ public class StatusBar extends JPanel { repaint(); } }); - + } + + private String getProjectPath(String projectPath) { + int projectPathWidth = getCasePathWidth(projectPath); + if (projectPathWidth < MAX_PROJECT_PATH_WIDTH - 5) { + return projectPath; + } else { + return truncateCasePath(projectPath); + } + } + + private String truncateCasePath(String path) { + int width = getCasePathWidth(DOTS + path); + if (width < MAX_PROJECT_PATH_WIDTH - 5) { + return DOTS + path; + } else { + return truncateCasePath(path.substring(1)); + } + } + + private int getCasePathWidth(String projectPath) { + return caseLabel.getFontMetrics(caseLabel.getFont()).stringWidth(TEXT_OFFSET + projectPath + TEXT_OFFSET); } public void updateLicenseField() { + licenseLabel.setText(TEXT_OFFSET + "License: " + System.getProperty(LICENSE_STATUS) + TEXT_OFFSET); } } diff --git a/src/eu/engys/gui/view/SurfacesCombo.java b/src/eu/engys/gui/view/SurfacesCombo.java index 287ab7a..e5e73f9 100644 --- a/src/eu/engys/gui/view/SurfacesCombo.java +++ b/src/eu/engys/gui/view/SurfacesCombo.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.view; import java.awt.Component; diff --git a/src/eu/engys/gui/view/View.java b/src/eu/engys/gui/view/View.java index 5024561..6a2f437 100644 --- a/src/eu/engys/gui/view/View.java +++ b/src/eu/engys/gui/view/View.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.view; import java.awt.BorderLayout; @@ -41,6 +40,7 @@ import javax.swing.AbstractAction; import javax.swing.Icon; import javax.swing.JDialog; import javax.swing.JFrame; +import javax.swing.JLayer; import javax.swing.JMenuItem; import javax.swing.JOptionPane; import javax.swing.JPanel; @@ -54,8 +54,9 @@ import org.slf4j.LoggerFactory; import com.google.inject.Inject; import eu.engys.application.AbstractApplication; -import eu.engys.core.Arguments; import eu.engys.core.controller.Controller; +import eu.engys.core.controller.Controller.OpenMode; +import eu.engys.core.controller.OpenOptions; import eu.engys.core.executor.FileManagerSupport; import eu.engys.core.executor.TerminalSupport; import eu.engys.core.modules.ApplicationModule; @@ -64,13 +65,13 @@ import eu.engys.core.presentation.Action; import eu.engys.core.presentation.ActionContainer; import eu.engys.core.presentation.ActionManager; import eu.engys.core.project.Model; -import eu.engys.core.project.geometry.surface.Stl; -import eu.engys.gui.CreateCaseDialog; import eu.engys.gui.MenuBar; import eu.engys.gui.RecentItems; import eu.engys.gui.StartPanel; import eu.engys.gui.events.EventManager; -import eu.engys.gui.events.view3D.AddSurfaceEvent; +import eu.engys.gui.events.EventManager.GenericEventListener; +import eu.engys.gui.events.application.ApplicationEvent; +import eu.engys.gui.events.view3D.GlassPaneEvent; import eu.engys.gui.view3D.CanvasPanel; import eu.engys.launcher.StartUpMonitor; import eu.engys.util.ApplicationInfo; @@ -79,10 +80,23 @@ import eu.engys.util.progress.ProgressMonitor; import eu.engys.util.ui.ResourcesUtil; import eu.engys.util.ui.UiUtil; -public class View extends JPanel implements Observer, ActionContainer { +public class View extends JPanel implements Observer, ActionContainer, GenericEventListener { private static final Logger logger = LoggerFactory.getLogger(View.class); + public static final String NEW_CASE = "application.create"; + public static final String OPEN_CASE = "application.open"; + public static final String RECENT_CASES = "application.recent"; + public static final String SAVE_CASE = "application.save"; + public static final String SAVE_AS_CASE = "application.saveAs"; + public static final String BROWSE_CASE = "application.browse.case"; + public static final String EXIT = "application.exit"; + public static final String OPEN_TERMINAL = "application.open.terminal"; + public static final String SPLIT_PANE_3D = "split.pane.3d"; + public static final String VIEW = "view"; + public static final String ELEMENT = "element"; + public static final String LOADING_VIEW = "Loading View"; + private final Model model; private final Controller controller; @@ -100,6 +114,7 @@ public class View extends JPanel implements Observer, ActionContainer { private ApplicationToolBar applicationToolBar; private JDialog startupDialog; + private GlassLayerUI glassPane; @Override public boolean isDemo() { @@ -122,13 +137,14 @@ public class View extends JPanel implements Observer, ActionContainer { controller.getWriter().registerWriter(element.getWriter()); } - controller.addListener(new DefaultControllerListener(model, this)); + controller.addListener(new DefaultControllerListener(model, controller, modules, this)); model.addObserver(this); - StartUpMonitor.info("Loading View"); - logger.info("Loading View"); + StartUpMonitor.info(LOADING_VIEW); + logger.info(LOADING_VIEW); ActionManager.getInstance().parseActions(this); + EventManager.registerEventListener(this, ApplicationEvent.class); } public void setProgressMonitorParent(JFrame frame) { @@ -137,30 +153,37 @@ public class View extends JPanel implements Observer, ActionContainer { public void layoutComponents() { menuBar = new MenuBar(this); - statusBar = new StatusBar(); + statusBar = new StatusBar(controller); applicationToolBar = new ApplicationToolBar(model); - mainPanel = new MainPanel(model, viewElements, monitor); + mainPanel = new MainPanel(model, viewElements, controller.getTerminalManager(), monitor); mainPanel.layoutComponents(); canvasPanel.layoutComponents(); setLayout(new BorderLayout()); - setName("view"); + setName(VIEW); + glassPane = new GlassLayerUI(); splitPane = new JSplitPane(); - splitPane.setName("split.pane.3d"); - splitPane.setLeftComponent(mainPanel); + splitPane.setName(SPLIT_PANE_3D); + splitPane.setLeftComponent(new JLayer<>(mainPanel, glassPane)); splitPane.setRightComponent(canvasPanel.getPanel()); splitPane.setDividerLocation(lookAndFeel.getMainWidth()); splitPane.setOneTouchExpandable(false); - add(applicationToolBar, BorderLayout.NORTH); + + JPanel toolbarPanel = new JPanel(new BorderLayout()); + toolbarPanel.add(applicationToolBar.getToolbar(), BorderLayout.CENTER); + toolbarPanel.add(applicationToolBar.getExitButton(), BorderLayout.EAST); + + add(toolbarPanel, BorderLayout.NORTH); add(splitPane, BorderLayout.CENTER); // updateSplitPosition(elementByIndex(0)); - mainPanel.addPropertyChangeListener("element", new PropertyChangeListener() { + mainPanel.addPropertyChangeListener(ELEMENT, new PropertyChangeListener() { + @SuppressWarnings("unchecked") @Override public void propertyChange(PropertyChangeEvent evt) { Class oldKlass = (Class) evt.getOldValue(); @@ -185,10 +208,6 @@ public class View extends JPanel implements Observer, ActionContainer { return menuBar; } - public ApplicationToolBar getToolBar() { - return applicationToolBar; - } - public MainPanel getMainPanel() { return mainPanel; } @@ -197,9 +216,12 @@ public class View extends JPanel implements Observer, ActionContainer { return canvasPanel; } - public void clear() { + public void clear(boolean clearTerminalManager) { canvasPanel.clear(); mainPanel.clear(); + if (clearTerminalManager) { + controller.getTerminalManager().clear(); + } } public void saveView() { @@ -211,13 +233,13 @@ public class View extends JPanel implements Observer, ActionContainer { ModulesUtil.save(modules); } - public void loadView() { + public void loadView(boolean loadMesh) { loadToolbars(); if (model.hasProject()) { monitor.info(""); monitor.info("Loading 3D"); - canvasPanel.load(); + canvasPanel.load(loadMesh); monitor.info(""); monitor.info("Loading GUI"); @@ -254,65 +276,28 @@ public class View extends JPanel implements Observer, ActionContainer { if (o instanceof Model) { if (arg != null) { for (ViewElement element : viewElements) { - logger.debug("[CHANGE OBSERVERD] {}", element.getClass().getName()); + logger.debug("[CHANGE OBSERVERD] arg: {}, observer: {}", arg.getClass().getSimpleName(), element.getClass().getSimpleName()); element.changeObserved(arg); } } } } - @Action(key = "application.create") + @Action(key = NEW_CASE) public void createCase() { if (controller.allowActionsOnRunning(false)) { - SwingUtilities.invokeLater(new Runnable() { - @Override - public void run() { - final CreateCaseDialog createCaseDialog = new CreateCaseDialog(); - createCaseDialog.showDialog(); - if (createCaseDialog.isOK()) { - hideStartupDialog(); - controller.createCase(createCaseDialog.getParameters()); - } - importFiles(); - } - }); + controller.createCase(null, null); } } - @Action(key = "application.open") + @Action(key = OPEN_CASE) public void openCase() { if (controller.allowActionsOnRunning(false)) { - if (Arguments.baseDir != null) { - controller.openCase(Arguments.baseDir); - Arguments.baseDir = null; - } else { - controller.openCase(null); - } - importFiles(); + controller.openCase(null); } } - public void importFiles() { - if (Arguments.stlFiles != null) { - monitor.setIndeterminate(false); - monitor.start("Loading STL Files", false, new Runnable() { - @Override - public void run() { - for (File file : Arguments.stlFiles) { - Stl stl = model.getGeometry().getFactory().readSTL(file, monitor); - model.getGeometry().addSurface(stl); - model.geometryChanged(stl); - - EventManager.triggerEvent(this, new AddSurfaceEvent(stl)); - } - Arguments.stlFiles = null; - monitor.end(); - } - }); - } - } - - @Action(key = "application.recent") + @Action(key = RECENT_CASES) public void open() { try { Point location = MouseInfo.getPointerInfo().getLocation(); @@ -339,7 +324,7 @@ public class View extends JPanel implements Observer, ActionContainer { @Override public void actionPerformed(ActionEvent e) { if (controller.allowActionsOnRunning(false)) { - controller.openCase(new File(item)); + controller.openCase(OpenOptions.file(new File(item), OpenMode.CHECK_FOLDER_ASK_USER)); } } }); @@ -355,7 +340,7 @@ public class View extends JPanel implements Observer, ActionContainer { return popup; } - @Action(key = "application.save", checkLicense = true) + @Action(key = SAVE_CASE, checkLicense = true) public void save() { File baseDir = model.getProject().getBaseDir(); if (baseDir.exists()) { @@ -366,28 +351,28 @@ public class View extends JPanel implements Observer, ActionContainer { } } - @Action(key = "application.saveAs", checkLicense = true) + @Action(key = SAVE_AS_CASE, checkLicense = true) public void saveAs() { controller.saveCase(null); } - @Action(key = "application.exit") + @Action(key = EXIT) public void exit() { if (controller.allowActionsOnRunning(true)) { _exit(); } } - @Action(key = "application.browse.case") + @Action(key = BROWSE_CASE) public void browseCase() { - if (model.getProject() != null && model.getProject().getBaseDir() != null) { + if (model.getProject() != null && model.getProject().getBaseDir() != null && model.getProject().getBaseDir().exists()) { FileManagerSupport.open(model.getProject().getBaseDir()); } else { JOptionPane.showMessageDialog(UiUtil.getActiveWindow(), "No project directory", "File System error", JOptionPane.ERROR_MESSAGE); } } - @Action(key = "application.open.terminal", checkEnv = true, checkLicense = true) + @Action(key = OPEN_TERMINAL, checkEnv = true, checkLicense = true) public void openTerminal() { if (model.getProject() != null && model.getProject().getBaseDir() != null) { TerminalSupport.openTerminal(model); @@ -404,7 +389,7 @@ public class View extends JPanel implements Observer, ActionContainer { startupDialog.setName("engys.cfd.dialog"); startupDialog.getContentPane().add(new StartPanel(abstractApplication, this), BorderLayout.CENTER); startupDialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); - startupDialog.setResizable(false); + startupDialog.setResizable(true); startupDialog.setTitle(controller.isDemo() ? "(Demo mode)" : ""); abstractApplication.checkVersion(); // dialog.getRootPane().setWindowDecorationStyle(JRootPane.NONE); @@ -427,4 +412,19 @@ public class View extends JPanel implements Observer, ActionContainer { return controller; } + // Called just by case manager + public void removeExitButton() { + ActionManager.getInstance().remove(EXIT); + } + + @Override + public void eventTriggered(Object obj, EventManager.Event event) { + if(event instanceof GlassPaneEvent){ + setGlassPaneActive(((GlassPaneEvent) event).isActive()); + } + } + + private void setGlassPaneActive(boolean active) { + glassPane.setActive(active); + } } diff --git a/src/eu/engys/gui/view/View3DElement.java b/src/eu/engys/gui/view/View3DElement.java index 81f4916..9d4d8a7 100644 --- a/src/eu/engys/gui/view/View3DElement.java +++ b/src/eu/engys/gui/view/View3DElement.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.view; diff --git a/src/eu/engys/gui/view/ViewElement.java b/src/eu/engys/gui/view/ViewElement.java index 1a56d6d..908c05f 100644 --- a/src/eu/engys/gui/view/ViewElement.java +++ b/src/eu/engys/gui/view/ViewElement.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.view; import java.util.Set; diff --git a/src/eu/engys/gui/view/ViewElementNavigator.java b/src/eu/engys/gui/view/ViewElementNavigator.java index 222a81e..65df40a 100644 --- a/src/eu/engys/gui/view/ViewElementNavigator.java +++ b/src/eu/engys/gui/view/ViewElementNavigator.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.view; diff --git a/src/eu/engys/gui/view/ViewElementPanel.java b/src/eu/engys/gui/view/ViewElementPanel.java index c6b77b7..e25b2bc 100644 --- a/src/eu/engys/gui/view/ViewElementPanel.java +++ b/src/eu/engys/gui/view/ViewElementPanel.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.view; import java.awt.BorderLayout; @@ -197,7 +196,9 @@ public class ViewElementPanel extends JPanel implements GUIPanelHandler, ModuleE if (!modulePanelsMap.containsKey(key)) { JComponent panel = modulePanel.getPanel(); - guiPanelContainer.add(panel, key); + if(panel != null){ + guiPanelContainer.add(panel, key); + } modulePanelsMap.put(key, modulePanel); } diff --git a/src/eu/engys/gui/view/ViewElementPanelTopNavigator.java b/src/eu/engys/gui/view/ViewElementPanelTopNavigator.java index ae81547..3224879 100644 --- a/src/eu/engys/gui/view/ViewElementPanelTopNavigator.java +++ b/src/eu/engys/gui/view/ViewElementPanelTopNavigator.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.view; import java.awt.BorderLayout; @@ -129,4 +128,12 @@ public class ViewElementPanelTopNavigator extends ViewElementPanel { navigator.setSelectedIndex(0); } } + + @Override + public void stop() { + super.stop(); + if (selectedPanel != null) { + selectedPanel.stop(); + } + } } diff --git a/src/eu/engys/gui/view/ViewElementTopNavigator.java b/src/eu/engys/gui/view/ViewElementTopNavigator.java index 4e4db9b..c52696f 100644 --- a/src/eu/engys/gui/view/ViewElementTopNavigator.java +++ b/src/eu/engys/gui/view/ViewElementTopNavigator.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.view; import java.util.Set; diff --git a/src/eu/engys/gui/view/fallback/FallbackViewElement.java b/src/eu/engys/gui/view/fallback/FallbackViewElement.java index 47015c2..d65238e 100644 --- a/src/eu/engys/gui/view/fallback/FallbackViewElement.java +++ b/src/eu/engys/gui/view/fallback/FallbackViewElement.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.view.fallback; import java.util.Collections; diff --git a/src/eu/engys/gui/view3D/Actor.java b/src/eu/engys/gui/view3D/Actor.java index 797a14d..80151a4 100644 --- a/src/eu/engys/gui/view3D/Actor.java +++ b/src/eu/engys/gui/view3D/Actor.java @@ -1,39 +1,38 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.view3D; +import eu.engys.core.project.geometry.stl.AffineTransform; +import eu.engys.core.project.mesh.FieldItem; +import eu.engys.util.ui.checkboxtree.VisibleItem; import vtk.vtkActor; import vtk.vtkLookupTable; import vtk.vtkMapper; import vtk.vtkPolyData; import vtk.vtkTransform; import vtk.vtkUnstructuredGrid; -import eu.engys.core.project.geometry.stl.AffineTransform; -import eu.engys.core.project.mesh.FieldItem; -import eu.engys.util.ui.checkboxtree.VisibleItem; public interface Actor { @@ -81,6 +80,6 @@ public interface Actor { int getMemorySize(); - - + void filterActor(); + void unfilterActor(); } diff --git a/src/eu/engys/gui/view3D/Axis.java b/src/eu/engys/gui/view3D/Axis.java index c8c5c2a..f70fc33 100644 --- a/src/eu/engys/gui/view3D/Axis.java +++ b/src/eu/engys/gui/view3D/Axis.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.view3D; diff --git a/src/eu/engys/gui/view3D/BoxEventButton.java b/src/eu/engys/gui/view3D/BoxEventButton.java index 73d0529..1bf56b9 100644 --- a/src/eu/engys/gui/view3D/BoxEventButton.java +++ b/src/eu/engys/gui/view3D/BoxEventButton.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.view3D; import java.awt.Dimension; @@ -41,8 +40,8 @@ import eu.engys.util.ui.textfields.DoubleField; public class BoxEventButton extends JToggleButton { - private static final Icon ICON_ON = ResourcesUtil.getResourceIcon("eu/engys/resources/images/lightbulb16.png"); - private static final Icon ICON_OFF = ResourcesUtil.getResourceIcon("eu/engys/resources/images/lightbulb_off16.png"); + private static final Icon ICON_ON = ResourcesUtil.getIcon("light.on.icon"); + private static final Icon ICON_OFF = ResourcesUtil.getIcon("light.off.icon"); public BoxEventButton(final DoubleField[] boxMin, final DoubleField[] boxMax) { super(); diff --git a/src/eu/engys/gui/view3D/CameraManager.java b/src/eu/engys/gui/view3D/CameraManager.java index 0862568..f42b293 100644 --- a/src/eu/engys/gui/view3D/CameraManager.java +++ b/src/eu/engys/gui/view3D/CameraManager.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.view3D; @@ -32,4 +31,9 @@ public interface CameraManager { } void setCameraPosition(Position pos); + + double[] getCameraDirection(); + + double[] getFocusPoint(); + } diff --git a/src/eu/engys/gui/view3D/CanvasPanel.java b/src/eu/engys/gui/view3D/CanvasPanel.java index fc67a43..fc08656 100644 --- a/src/eu/engys/gui/view3D/CanvasPanel.java +++ b/src/eu/engys/gui/view3D/CanvasPanel.java @@ -1,29 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.view3D; import java.awt.Color; @@ -37,56 +35,85 @@ import eu.engys.core.project.geometry.BoundingBox; import eu.engys.gui.events.view3D.VolumeReportVisibilityEvent.Kind; import eu.engys.gui.view.View3DElement; import eu.engys.gui.view.ViewElement; +import eu.engys.gui.view3D.quality.QualityInfo; import eu.engys.gui.view3D.widget.Widget; import eu.engys.util.ui.textfields.DoubleField; public interface CanvasPanel { -// public void start(); -// public void stop(); -// public void load(); - public void start(Class klass); - public void stop(Class klass); - public void load(); - public void save(); + // public void start(); + // public void stop(); + // public void load(); + public void start(Class klass); + + public void stop(Class klass); + + public void load(boolean loadMesh); + + public void save(); + public void clear(); - + public void geometryToMesh(GeometryToMesh g2m); public JPanel getPanel(); public void showBox(DoubleField[] min, DoubleField[] max, EventActionType actions); - public void showPoint(DoubleField[] point, String key, EventActionType action, Color color); - public void showPlane(DoubleField[] origin, DoubleField[] normal, EventActionType actions); - public void showPlaneDisplay(DoubleField[] origin, DoubleField[] normal, EventActionType actions); - public void showAxis(DoubleField[] origin, DoubleField[] normal, EventActionType actions); + + public void showRotatedBox(DoubleField[] center, DoubleField[] delta, DoubleField[] rotation, EventActionType actions); + + public void showPoint(String key, DoubleField[] point, EventActionType action, Color color); + + public void showPlane(String key, DoubleField[] origin, DoubleField[] normal, EventActionType actions); + + public void showPlaneDisplay(String key, DoubleField[] origin, DoubleField[] normal, EventActionType actions); + + public void showAxis(DoubleField[] origin, DoubleField[] normal, double magnitude, EventActionType actions); + + public void showAxis(DoubleField[] origin, DoubleField angle1, DoubleField angle2, double magnitude, int sign, EventActionType actions); + +// public void activateCOR(EventActionType action); + +// public void activateLocation(EventActionType action); + public void activateSelection(Selection selection, EventActionType action); + public void showQualityFields(QualityInfo qualityInfo, EventActionType action); + public void showLayersCoverage(LayerInfo layerInfo, JPanel colorBar, EventActionType action); public void layoutComponents(); - public void updateMinAndMaxForFields(String varName, Point3d min, Point3d max); - public void showMinMaxFieldPoints(String key, Kind kind, boolean visible); - + public void updateMinAndMaxForFields(String varName, Point3d min, Point3d max); + + public void showMinMaxFieldPoints(String key, Kind kind, boolean visible); + public Geometry3DController getGeometryController(); + public Mesh3DController getMeshController(); - + public T getController(Class klass); - + public BoundingBox computeBoundingBox(boolean visibleOnly); - + public void showWidgetPanel(Widget widget); + public void hideWidgetPanel(Widget widget); public boolean showWidget(Widget widget); + public void hideWidget(Widget widget); + public void resetZoom(); + public void loadWidgets(); - + void registerController(Controller3D context); - + public void applyContext(Class klass); + public void dumpContext(Class klass); + public RenderPanel getRenderPanel(); + } diff --git a/src/eu/engys/gui/view3D/CellPicker.java b/src/eu/engys/gui/view3D/CellPicker.java index 6792a0e..ed96dca 100644 --- a/src/eu/engys/gui/view3D/CellPicker.java +++ b/src/eu/engys/gui/view3D/CellPicker.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.view3D; diff --git a/src/eu/engys/gui/view3D/Context.java b/src/eu/engys/gui/view3D/Context.java index 9f59cef..3eae4ec 100644 --- a/src/eu/engys/gui/view3D/Context.java +++ b/src/eu/engys/gui/view3D/Context.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.view3D; @@ -31,13 +30,12 @@ public class Context { protected Representation representation; - public Context(Representation representation) { - this.representation = representation; - } - public Representation getRepresentation() { return representation; } + public void setRepresentation(Representation representation) { + this.representation = representation; + } public boolean isEmpty() { return false; diff --git a/src/eu/engys/gui/view3D/Controller3D.java b/src/eu/engys/gui/view3D/Controller3D.java index cae00ef..d8f2368 100644 --- a/src/eu/engys/gui/view3D/Controller3D.java +++ b/src/eu/engys/gui/view3D/Controller3D.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.view3D; diff --git a/src/eu/engys/gui/view3D/Geometry3DController.java b/src/eu/engys/gui/view3D/Geometry3DController.java index 33b3a11..91720a4 100644 --- a/src/eu/engys/gui/view3D/Geometry3DController.java +++ b/src/eu/engys/gui/view3D/Geometry3DController.java @@ -1,29 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.view3D; import java.awt.Color; @@ -33,37 +31,35 @@ import java.util.Map; import eu.engys.core.project.geometry.BoundingBox; import eu.engys.core.project.geometry.Surface; import eu.engys.core.project.geometry.stl.AffineTransform; -import eu.engys.core.project.mesh.FieldItem; public interface Geometry3DController extends Controller3D { - public void updateSurfacesSelection(Surface... selection); + public void updateSurfacesSelection(Surface... selection); - void updateSurfaceVisibility(Surface... selection); + public void updateSurfacesFilter(Surface... selection); - void updateSurfaceColor(Color color, Surface... selection); + void updateSurfaceVisibility(Surface... selection); - void addSurfaces(Surface... surface); + void updateSurfaceColor(Color color, Surface... selection); - void transformSurfaces(AffineTransform t, boolean save, Surface... surfaces); + void addSurfaces(Surface... surface); - void changeSurface(Surface... surface); + void transformSurfaces(AffineTransform t, boolean save, Surface... surfaces); - void removeSurfaces(Surface... surfaces); + void changeSurface(Surface... surface); - public BoundingBox computeBoundingBox(Surface... surfaces); + void removeSurfaces(Surface... surfaces); - void clear(); + public BoundingBox computeBoundingBox(Surface... surfaces); - Collection getActorsList(); + void clear(); - public Map getActorsMap(); + Collection getActorsList(); - public void showInternalMesh(); + public Map getActorsMap(); - public void hideInternalMesh(); - - public void showField(FieldItem fieldItem); + public void showInternalMesh(); + public void hideInternalMesh(); } diff --git a/src/eu/engys/gui/view3D/Geometry3DEventListener.java b/src/eu/engys/gui/view3D/Geometry3DEventListener.java index 652566a..517d04a 100644 --- a/src/eu/engys/gui/view3D/Geometry3DEventListener.java +++ b/src/eu/engys/gui/view3D/Geometry3DEventListener.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.view3D; @@ -36,6 +35,7 @@ import eu.engys.gui.events.EventManager.Event; import eu.engys.gui.events.view3D.AddSurfaceEvent; import eu.engys.gui.events.view3D.ChangeSurfaceEvent; import eu.engys.gui.events.view3D.ColorSurfaceEvent; +import eu.engys.gui.events.view3D.FilterSurfaceEvent; import eu.engys.gui.events.view3D.RemoveSurfaceEvent; import eu.engys.gui.events.view3D.RenameSurfaceEvent; import eu.engys.gui.events.view3D.SelectSurfaceEvent; @@ -68,6 +68,8 @@ public class Geometry3DEventListener implements View3DEventListener { handleTransformSurface((TransformSurfaceEvent) event); } else if (event instanceof SelectSurfaceEvent) { handleSelectSurface((SelectSurfaceEvent) event); + } else if (event instanceof FilterSurfaceEvent) { + handleFilterSurface((FilterSurfaceEvent) event); } else if (event instanceof VisibleItemEvent) { handleVisibleItem((VisibleItemEvent) event); } else if (event instanceof ColorSurfaceEvent) { @@ -95,6 +97,11 @@ public class Geometry3DEventListener implements View3DEventListener { Surface selection[] = event.getSelection(); controller.updateSurfacesSelection(selection); } + + private void handleFilterSurface(FilterSurfaceEvent event) { + Surface selection[] = event.getSelection(); + controller.updateSurfacesFilter(selection); + } private void handleAddSurface(AddSurfaceEvent e) { Surface[] surfaces = e.getSurfaces(); diff --git a/src/eu/engys/gui/view3D/Interactor.java b/src/eu/engys/gui/view3D/Interactor.java index 234a00a..778c395 100644 --- a/src/eu/engys/gui/view3D/Interactor.java +++ b/src/eu/engys/gui/view3D/Interactor.java @@ -1,34 +1,40 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.view3D; import vtk.vtkInteractorObserver; public interface Interactor { + public interface InteractorListener { + void rotate(); + void pan(); + void spin(); + void zoom(); + } + void setStyleToDefault(); void setStyleToArea(); void setStyleToZoom(); @@ -43,6 +49,12 @@ public interface Interactor { void wheelBackwardEvent(); void addObserver(vtkInteractorObserver widget); + + void addListener(InteractorListener corWidget); + void removeListener(InteractorListener corWidget); + + double[] getCenter(); + void setCenter(double[] center); } diff --git a/src/eu/engys/gui/view3D/LayerInfo.java b/src/eu/engys/gui/view3D/LayerInfo.java index a4faea5..01d6b2c 100644 --- a/src/eu/engys/gui/view3D/LayerInfo.java +++ b/src/eu/engys/gui/view3D/LayerInfo.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.view3D; public enum LayerInfo { @@ -43,4 +42,4 @@ public enum LayerInfo { public boolean isDiscrete() { return discrete; } -} +} \ No newline at end of file diff --git a/src/eu/engys/gui/view3D/Mesh3DController.java b/src/eu/engys/gui/view3D/Mesh3DController.java index 887e80a..fe98c55 100644 --- a/src/eu/engys/gui/view3D/Mesh3DController.java +++ b/src/eu/engys/gui/view3D/Mesh3DController.java @@ -1,81 +1,92 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.view3D; +import java.io.File; import java.util.Collection; +import java.util.List; -import vtk.vtkPlane; import eu.engys.core.project.geometry.BoundingBox; import eu.engys.core.project.mesh.FieldItem; -import eu.engys.core.project.mesh.ScalarBarType; import eu.engys.core.project.zero.cellzones.CellZone; +import eu.engys.core.project.zero.facezones.FaceZone; import eu.engys.core.project.zero.patches.Patch; +import vtk.vtkPlane; public interface Mesh3DController extends Controller3D { - void updatePatchesSelection(Patch[] selection); - void updatePatchesVisibility(Patch... selection); + void updatePatchesSelection(Patch[] selection); - void updateCellZonesSelection(CellZone[] selection); - void updateCellZonesVisibility(CellZone... selection); + void updatePatchesVisibility(Patch... selection); - void clear(); + void updateCellZonesSelection(CellZone[] selection); + + void updateCellZonesVisibility(CellZone... selection); + + void updateFaceZonesSelection(FaceZone[] selection); + + void updateFaceZonesVisibility(FaceZone... selection); + + void clear(); BoundingBox computeBoundingBox(); - void showTimeStep(double value); - void showField(FieldItem fieldItem); - - void clip(vtkPlane plane); - void slice(vtkPlane plane); - void crinkle(vtkPlane plane); - void disconnectFiltersFromInternalMesh(); - - void insideOut(boolean selected); - - void showExternalMesh(); - - void showInternalMesh(); - void hideInternalMesh(); - boolean isInternalMeshLoaded(); - - void readTimeSteps(); - FieldItem getCurrentFieldItem(); - double getCurrentTimeStep(); - - Collection getActorsList(); - - - void setAutomaticRangeCalculation(boolean autoRange); - void setManualRangeCalculation(double[] rangeField); + void changeTimeStep(double value); - void setScalarsActorsResolution(int resolution); + void showField(FieldItem fieldItem); - void resetScalarsActorsRangeAndResolutionAndHue(); - void setScalarsBarType(ScalarBarType hueRangeType); + void clip(vtkPlane plane, boolean insideOut); + + void slice(vtkPlane plane, List values); + + void crinkle(vtkPlane plane); + + void contour(String field, List values, int smoothingIterations, double smoothingConvergence); + + void exportContourAsSTL(File stlFile); + + void disconnectFiltersFromInternalMesh(); + + void showExternalMesh(); + + void showInternalMesh(); + + void hideInternalMesh(); + + boolean isInternalMeshLoaded(); + + boolean isInternalMeshVisible(); + + void readTimeSteps(); + + FieldItem getCurrentFieldItem(); + + double getCurrentTimeStep(); + + Collection getActorsList(); + + void updateActorsColors(); } diff --git a/src/eu/engys/gui/view3D/Mesh3DEventListener.java b/src/eu/engys/gui/view3D/Mesh3DEventListener.java index cc7c094..203dd52 100644 --- a/src/eu/engys/gui/view3D/Mesh3DEventListener.java +++ b/src/eu/engys/gui/view3D/Mesh3DEventListener.java @@ -1,37 +1,37 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.view3D; import javax.swing.SwingUtilities; import eu.engys.core.project.zero.cellzones.CellZone; +import eu.engys.core.project.zero.facezones.FaceZone; import eu.engys.core.project.zero.patches.Patch; import eu.engys.gui.events.EventManager.Event; import eu.engys.gui.events.view3D.SelectCellZonesEvent; +import eu.engys.gui.events.view3D.SelectFaceZonesEvent; import eu.engys.gui.events.view3D.SelectPatchesEvent; import eu.engys.gui.events.view3D.VisibleItemEvent; import eu.engys.util.ui.checkboxtree.VisibleItem; @@ -52,7 +52,9 @@ public class Mesh3DEventListener implements View3DEventListener { if (event instanceof SelectPatchesEvent) { handleSelectPatches((SelectPatchesEvent) event); } else if (event instanceof SelectCellZonesEvent) { - handleSelectZones((SelectCellZonesEvent) event); + handleSelectCellZones((SelectCellZonesEvent) event); + } else if (event instanceof SelectFaceZonesEvent) { + handleSelectFaceZones((SelectFaceZonesEvent) event); } else if (event instanceof VisibleItemEvent) { handleVisibility((VisibleItemEvent) event); } @@ -65,17 +67,24 @@ public class Mesh3DEventListener implements View3DEventListener { mesh3DController.updatePatchesSelection(selection); } - private void handleSelectZones(SelectCellZonesEvent event) { + private void handleSelectCellZones(SelectCellZonesEvent event) { CellZone selection[] = ((SelectCellZonesEvent) event).getSelection(); mesh3DController.updateCellZonesSelection(selection); } + private void handleSelectFaceZones(SelectFaceZonesEvent event) { + FaceZone selection[] = ((SelectFaceZonesEvent) event).getSelection(); + mesh3DController.updateFaceZonesSelection(selection); + } + private void handleVisibility(VisibleItemEvent event) { VisibleItem selection = event.getSelection(); if (selection instanceof Patch) { mesh3DController.updatePatchesVisibility((Patch) selection); } else if (selection instanceof CellZone) { mesh3DController.updateCellZonesVisibility((CellZone) selection); + } else if (selection instanceof FaceZone) { + mesh3DController.updateFaceZonesVisibility((FaceZone) selection); } } } diff --git a/src/eu/engys/gui/view3D/PickInfo.java b/src/eu/engys/gui/view3D/PickInfo.java index ec0e7fb..08f3826 100644 --- a/src/eu/engys/gui/view3D/PickInfo.java +++ b/src/eu/engys/gui/view3D/PickInfo.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.view3D; import vtk.vtkDataSet; @@ -33,6 +32,7 @@ public class PickInfo { public Actor actor; public vtkDataSet dataSet; public int cellId; + public int pointId; public int[] cellIJK; public double[] normal; public double[] position; diff --git a/src/eu/engys/gui/view3D/PickManager.java b/src/eu/engys/gui/view3D/PickManager.java index 0ec9352..f45e9b2 100644 --- a/src/eu/engys/gui/view3D/PickManager.java +++ b/src/eu/engys/gui/view3D/PickManager.java @@ -1,43 +1,48 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.view3D; public interface PickManager { void registerPickerForActors(Picker picker); + void unregisterPickerForActors(Picker picker); void registerPickerForCells(CellPicker picker); void unregisterPickerForCells(CellPicker picker); + void registerPickerForPoints(CellPicker picker); + void unregisterPickerForPoints(CellPicker picker); + + void pickForPoints(); + void pickForCells(); void pickForActors(); - double[] pickPoint(); + PickInfo pickPoint(); } diff --git a/src/eu/engys/gui/view3D/Picker.java b/src/eu/engys/gui/view3D/Picker.java index 9546249..cd8ba4c 100644 --- a/src/eu/engys/gui/view3D/Picker.java +++ b/src/eu/engys/gui/view3D/Picker.java @@ -1,35 +1,32 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.view3D; - public interface Picker { public boolean containsActor(Actor actor); -// public String getActorName(Actor pickedActor); - public boolean canPickCells(Actor pickedActor); public boolean canPickMesh(); + public void pickActor(PickInfo pi); } diff --git a/src/eu/engys/gui/view3D/QualityInfo.java b/src/eu/engys/gui/view3D/QualityInfo.java deleted file mode 100644 index 3d4920f..0000000 --- a/src/eu/engys/gui/view3D/QualityInfo.java +++ /dev/null @@ -1,102 +0,0 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - -package eu.engys.gui.view3D; - -import static eu.engys.gui.view3D.QualityInfo.Test.LESS_THAN; -import static eu.engys.gui.view3D.QualityInfo.Test.MORE_THAN; - -import java.awt.Color; - -import eu.engys.util.bean.AbstractBean; - - -public class QualityInfo extends AbstractBean { - -// metrics[0] = "nonOrthogonality"; -// metrics[1] = "pyramids"; -// metrics[2] = "skewness" ; -// metrics[3] = "weights"; -// metrics[4] = "volumeRatio"; -// metrics[5] = "determinant"; - public enum Test { - MORE_THAN, LESS_THAN; - } - - public enum QualityMeasure { - NON_ORTHOGONALITY("nonOrthogonality", MORE_THAN), - PYRAMIDS("pyramids", MORE_THAN), - SKEWNESS("skewness", LESS_THAN), - WEIGHTS("weights", MORE_THAN), - VOLUME_RATIO("volumeRatio", MORE_THAN), - DETERMINANT("determinant", MORE_THAN); - - private String fieldName; - private Test test; - - private QualityMeasure(String fieldName, Test test) { - this.fieldName = fieldName; - this.test = test; - } - - public String getFieldName() { - return fieldName; - } - - public Test getTest() { - return test; - } - } - - private QualityInfo.QualityMeasure measure; - private double threshold; - private Color color; - - public QualityInfo.QualityMeasure getMeasure() { - return measure; - } - public void setMeasure(QualityInfo.QualityMeasure measure) { - this.measure = measure; - } - public double getThreshold() { - return threshold; - } - public void setThreshold(double threshold) { - firePropertyChange("threshold", this.threshold, this.threshold = threshold); - } - - public Color getColor() { - return color; - } - public void setColor(Color color) { - this.color = color; - } - - @Override - public String toString() { - return "fieldName: " + getMeasure().getFieldName() + ", test: " + getMeasure().getTest() + ", threshold: " + getThreshold(); - } - -} diff --git a/src/eu/engys/gui/view3D/RenderPanel.java b/src/eu/engys/gui/view3D/RenderPanel.java index b486ebd..9932f64 100644 --- a/src/eu/engys/gui/view3D/RenderPanel.java +++ b/src/eu/engys/gui/view3D/RenderPanel.java @@ -1,36 +1,35 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.view3D; import java.awt.Color; import java.awt.event.KeyListener; +import eu.engys.gui.view3D.CameraManager.Position; import vtk.vtkAssembly; import vtk.vtkImageData; -import eu.engys.gui.view3D.CameraManager.Position; public interface RenderPanel { @@ -66,11 +65,14 @@ public interface RenderPanel { void addActor(Actor actor); void removeActor(Actor actor); + void removeActor(vtkAssembly cor); - void selectActors(boolean keepSelected, Actor... pickedActor); + void filterActors(Actor... actors); + void selectActors(boolean keepSelected, Actor... actors); void setLowRendering(); void setHighRendering(); + void DestroyTimer(); void setActorColor(Color c, Actor... actor); @@ -84,6 +86,8 @@ public interface RenderPanel { void ParallelProjectionOff(); PickManager getPickManager(); + + CameraManager getCameraManager(); Interactor getInteractor(); diff --git a/src/eu/engys/gui/view3D/Representation.java b/src/eu/engys/gui/view3D/Representation.java index 28ade97..47c63c3 100644 --- a/src/eu/engys/gui/view3D/Representation.java +++ b/src/eu/engys/gui/view3D/Representation.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.view3D; diff --git a/src/eu/engys/gui/view3D/RotatedBoxEventButton.java b/src/eu/engys/gui/view3D/RotatedBoxEventButton.java new file mode 100644 index 0000000..7ed6dd4 --- /dev/null +++ b/src/eu/engys/gui/view3D/RotatedBoxEventButton.java @@ -0,0 +1,65 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.gui.view3D; + +import java.awt.Dimension; +import java.awt.event.ActionEvent; + +import javax.swing.AbstractAction; +import javax.swing.Icon; +import javax.swing.JToggleButton; +import javax.swing.SwingConstants; + +import eu.engys.core.dictionary.model.EventActionType; +import eu.engys.gui.events.EventManager; +import eu.engys.gui.events.view3D.RotatedBoxEvent; +import eu.engys.util.ui.ResourcesUtil; +import eu.engys.util.ui.textfields.DoubleField; + +public class RotatedBoxEventButton extends JToggleButton { + + private static final Icon ICON_ON = ResourcesUtil.getIcon("light.on.icon"); + private static final Icon ICON_OFF = ResourcesUtil.getIcon("light.off.icon"); + + public RotatedBoxEventButton(final DoubleField[] center, final DoubleField[] delta, final DoubleField[] rotation) { + super(); + setAction(new AbstractAction() { + @Override + public void actionPerformed(ActionEvent e) { + if (isSelected()) { + EventManager.triggerEvent(this, new RotatedBoxEvent(center, delta, rotation, EventActionType.SHOW)); + } else { + EventManager.triggerEvent(this, new RotatedBoxEvent(center, delta, rotation, EventActionType.HIDE)); + } + } + }); + setPreferredSize(new Dimension(36, 48)); + setIcon(ICON_OFF); + setSelectedIcon(ICON_ON); + setPressedIcon(ICON_ON); +// setVerticalAlignment(SwingConstants.TOP); + setVerticalTextPosition(SwingConstants.CENTER); + } +} diff --git a/src/eu/engys/gui/view3D/Selection.java b/src/eu/engys/gui/view3D/Selection.java index caeb094..f386d25 100644 --- a/src/eu/engys/gui/view3D/Selection.java +++ b/src/eu/engys/gui/view3D/Selection.java @@ -1,36 +1,37 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.view3D; +import eu.engys.util.bean.AbstractBean; import vtk.vtkIdTypeArray; import vtk.vtkPolyData; -import eu.engys.util.bean.AbstractBean; public class Selection extends AbstractBean { - + + public static final String SELECTION_DATA = "selectionData"; + public enum SelectionType { CELL, AREA, FEATURE } @@ -46,75 +47,93 @@ public class Selection extends AbstractBean { private Selection.SelectionType type = SelectionType.FEATURE; private Selection.SelectionMode mode = SelectionMode.SELECT; private Selection.SelectionTarget target = SelectionTarget.CELL; - + private double featureAngle = 30.0; private boolean keepSelection = true; - + private vtkPolyData selectionData; private vtkPolyData inverseSelectionData; private vtkIdTypeArray idList; private vtkPolyData dataSet; - + public void setType(Selection.SelectionType type) { firePropertyChange("type", this.type, this.type = type); } + public Selection.SelectionType getType() { return type; } - + public void setMode(Selection.SelectionMode mode) { this.mode = mode; } + public Selection.SelectionMode getMode() { return mode; } - + public void setTarget(Selection.SelectionTarget target) { this.target = target; } + public Selection.SelectionTarget getTarget() { return target; } - + public void setFeatureAngle(double featureAngle) { this.featureAngle = featureAngle; } + public double getFeatureAngle() { return featureAngle; } - + public void setKeepSelection(boolean keepSelection) { this.keepSelection = keepSelection; } + public boolean isKeepSelection() { return keepSelection; } - + public void setSelectionData(vtkPolyData selectionData) { - this.selectionData = selectionData; + firePropertyChange(SELECTION_DATA, this.selectionData, this.selectionData = selectionData); } + public vtkPolyData getSelectionData() { return selectionData; } - + public void setInverseSelectionData(vtkPolyData inverseSelectionData) { this.inverseSelectionData = inverseSelectionData; } + public vtkPolyData getInverseSelectionData() { return inverseSelectionData; } - + public void setIdList(vtkIdTypeArray list) { this.idList = list; } + public vtkIdTypeArray getIdList() { return idList; } - + public void setDataSet(vtkPolyData dataSet) { firePropertyChange("dataSet", this.dataSet, this.dataSet = dataSet); } + public vtkPolyData getDataSet() { return dataSet; } -} + + public boolean isEmpty() { + if(selectionData == null) return true; + if(selectionData.GetPointData() == null) return true; + if(selectionData.GetCellData() == null) return true; + int points = selectionData.GetPointData().GetNumberOfArrays(); + int cells = selectionData.GetCellData().GetNumberOfArrays(); + return points == 0 && cells == 0; + } +} \ No newline at end of file diff --git a/src/eu/engys/gui/view3D/View3DEventListener.java b/src/eu/engys/gui/view3D/View3DEventListener.java index 5d85152..b4ba395 100644 --- a/src/eu/engys/gui/view3D/View3DEventListener.java +++ b/src/eu/engys/gui/view3D/View3DEventListener.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.view3D; diff --git a/src/eu/engys/gui/view3D/fallback/Fallback3DElement.java b/src/eu/engys/gui/view3D/fallback/Fallback3DElement.java index 3fc3dd9..06c1e99 100644 --- a/src/eu/engys/gui/view3D/fallback/Fallback3DElement.java +++ b/src/eu/engys/gui/view3D/fallback/Fallback3DElement.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.view3D.fallback; diff --git a/src/eu/engys/gui/view3D/fallback/FallbackGeometry3DController.java b/src/eu/engys/gui/view3D/fallback/FallbackGeometry3DController.java index 91f20fc..98cce4a 100644 --- a/src/eu/engys/gui/view3D/fallback/FallbackGeometry3DController.java +++ b/src/eu/engys/gui/view3D/fallback/FallbackGeometry3DController.java @@ -1,29 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.view3D.fallback; import java.awt.Color; @@ -34,7 +32,6 @@ import eu.engys.core.controller.GeometryToMesh; import eu.engys.core.project.geometry.BoundingBox; import eu.engys.core.project.geometry.Surface; import eu.engys.core.project.geometry.stl.AffineTransform; -import eu.engys.core.project.mesh.FieldItem; import eu.engys.gui.view.View3DElement; import eu.engys.gui.view3D.Actor; import eu.engys.gui.view3D.Context; @@ -43,107 +40,108 @@ import eu.engys.gui.view3D.RenderPanel; public class FallbackGeometry3DController implements Geometry3DController { - @Override - public Context getCurrentContext() { - return null; - } + @Override + public Context getCurrentContext() { + return null; + } - @Override - public void setRenderPanel(RenderPanel renderPanel) { - } - - @Override - public void clearContext() { - } + @Override + public void setRenderPanel(RenderPanel renderPanel) { + } + + @Override + public void clearContext() { + } @Override public void geometryToMesh(GeometryToMesh g2m) { } - @Override - public void updateSurfacesSelection(Surface... selection) { - } + @Override + public void updateSurfacesSelection(Surface... selection) { + } - @Override - public void updateSurfaceVisibility(Surface... selection) { - } + @Override + public void updateSurfaceVisibility(Surface... selection) { + } @Override public void updateSurfaceColor(Color color, Surface... selection) { } - @Override - public void addSurfaces(Surface... surface) { - } + @Override + public void updateSurfacesFilter(Surface... selection) { + } - @Override - public void transformSurfaces(AffineTransform t, boolean save, Surface... surfaces) { - } + @Override + public void addSurfaces(Surface... surface) { + } - @Override - public void removeSurfaces(Surface... surfaces) { - } + @Override + public void transformSurfaces(AffineTransform t, boolean save, Surface... surfaces) { + } - @Override - public BoundingBox computeBoundingBox(Surface... surfaces) { - return new BoundingBox(0, 0, 0, 0, 0, 0); - } + @Override + public void removeSurfaces(Surface... surfaces) { + } - @Override - public void clear() { - } + @Override + public BoundingBox computeBoundingBox(Surface... surfaces) { + return new BoundingBox(0, 0, 0, 0, 0, 0); + } - @Override - public void dumpContext(Class klass) { - } + @Override + public void clear() { + } - @Override - public void applyContext(Class klass) { - } + @Override + public void dumpContext(Class klass) { + } - @Override - public Collection getActorsList() { - return null; - } + @Override + public void applyContext(Class klass) { + } - @Override - public Map getActorsMap() { - return null; - } + @Override + public Collection getActorsList() { + return null; + } - @Override - public void loadActors() { - } + @Override + public Map getActorsMap() { + return null; + } - @Override - public void newContext(Class klass) { - } + @Override + public void loadActors() { + } - @Override - public void newEmptyContext(Class klass) { - } + @Override + public void newContext(Class klass) { + } - @Override - public void showInternalMesh() { - } + @Override + public void newEmptyContext(Class klass) { + } - @Override - public void hideInternalMesh() { - } + @Override + public void showInternalMesh() { + } - @Override - public void changeSurface(Surface... surface) { - } + @Override + public void hideInternalMesh() { + } - @Override - public void render() { - } - - @Override - public void zoomReset() { - } + @Override + public void changeSurface(Surface... surface) { + } + + @Override + public void render() { + } + + @Override + public void zoomReset() { + } - @Override - public void showField(FieldItem fieldItem) { - } } diff --git a/src/eu/engys/gui/view3D/fallback/FallbackMesh3DController.java b/src/eu/engys/gui/view3D/fallback/FallbackMesh3DController.java index 2175962..d0fda04 100644 --- a/src/eu/engys/gui/view3D/fallback/FallbackMesh3DController.java +++ b/src/eu/engys/gui/view3D/fallback/FallbackMesh3DController.java @@ -1,44 +1,45 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.view3D.fallback; +import java.io.File; import java.util.Collection; +import java.util.List; -import vtk.vtkPlane; import eu.engys.core.controller.GeometryToMesh; import eu.engys.core.project.geometry.BoundingBox; import eu.engys.core.project.mesh.FieldItem; -import eu.engys.core.project.mesh.ScalarBarType; import eu.engys.core.project.zero.cellzones.CellZone; +import eu.engys.core.project.zero.facezones.FaceZone; import eu.engys.core.project.zero.patches.Patch; import eu.engys.gui.view.View3DElement; import eu.engys.gui.view3D.Actor; import eu.engys.gui.view3D.Context; import eu.engys.gui.view3D.Mesh3DController; import eu.engys.gui.view3D.RenderPanel; +import vtk.vtkPlane; public class FallbackMesh3DController implements Mesh3DController { @@ -62,6 +63,14 @@ public class FallbackMesh3DController implements Mesh3DController { public void updateCellZonesSelection(CellZone[] selection) { } + @Override + public void updateFaceZonesSelection(FaceZone[] selection) { + } + + @Override + public void updateFaceZonesVisibility(FaceZone... selection) { + } + @Override public void loadActors() { } @@ -79,29 +88,17 @@ public class FallbackMesh3DController implements Mesh3DController { public void clear() { } + @Override + public void exportContourAsSTL(File stlFile) { + } + @Override public BoundingBox computeBoundingBox() { return null; } @Override - public void setManualRangeCalculation(double[] rangeField) { - } - - @Override - public void setScalarsActorsResolution(int resolution) { - } - - @Override - public void setScalarsBarType(ScalarBarType hueRangeType) { - } - - @Override - public void resetScalarsActorsRangeAndResolutionAndHue() { - } - - @Override - public void setAutomaticRangeCalculation(boolean autoRange) { + public void updateActorsColors() { } @Override @@ -125,7 +122,7 @@ public class FallbackMesh3DController implements Mesh3DController { } @Override - public void showTimeStep(double value) { + public void changeTimeStep(double value) { } @Override @@ -143,21 +140,21 @@ public class FallbackMesh3DController implements Mesh3DController { } @Override - public void clip(vtkPlane plane) { + public void clip(vtkPlane plane, boolean insideOut) { } @Override - public void slice(vtkPlane plane) { + public void slice(vtkPlane plane, List values) { + } + + @Override + public void contour(String field, List values, int smoothingIterations, double smoothingConvergence) { } @Override public void crinkle(vtkPlane plane) { } - @Override - public void insideOut(boolean selected) { - } - @Override public void showInternalMesh() { } @@ -184,6 +181,11 @@ public class FallbackMesh3DController implements Mesh3DController { return false; } + @Override + public boolean isInternalMeshVisible() { + return false; + } + @Override public void render() { } @@ -195,4 +197,5 @@ public class FallbackMesh3DController implements Mesh3DController { @Override public void disconnectFiltersFromInternalMesh() { } + } diff --git a/src/eu/engys/gui/view3D/fallback/FallbackView3D.java b/src/eu/engys/gui/view3D/fallback/FallbackView3D.java index fe88214..1d687af 100644 --- a/src/eu/engys/gui/view3D/fallback/FallbackView3D.java +++ b/src/eu/engys/gui/view3D/fallback/FallbackView3D.java @@ -1,29 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.view3D.fallback; import java.awt.AlphaComposite; @@ -54,8 +52,9 @@ import eu.engys.gui.view3D.Controller3D; import eu.engys.gui.view3D.Geometry3DController; import eu.engys.gui.view3D.LayerInfo; import eu.engys.gui.view3D.Mesh3DController; -import eu.engys.gui.view3D.QualityInfo; +import eu.engys.gui.view3D.RenderPanel; import eu.engys.gui.view3D.Selection; +import eu.engys.gui.view3D.quality.QualityInfo; import eu.engys.gui.view3D.widget.Widget; import eu.engys.util.ApplicationInfo; import eu.engys.util.ui.ResourcesUtil; @@ -63,189 +62,210 @@ import eu.engys.util.ui.textfields.DoubleField; public class FallbackView3D implements CanvasPanel { - private JPanel panel; - private Icon engysLogo = ResourcesUtil.getIcon(ApplicationInfo.getVendor().toLowerCase() + ".logo.full"); + private JPanel panel; + private Icon engysLogo = ResourcesUtil.getIcon(ApplicationInfo.getVendor().toLowerCase() + ".logo.full"); - private Runnable r = new Runnable() { - @Override - public void run() { - final ImageIcon image = (ImageIcon) engysLogo; - panel = new JPanel() { - @Override - public void paintComponent(final Graphics g) { - super.paintComponent(g); - Graphics2D g2d = (Graphics2D) g; - g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); - if (image != null) { - // int xCoord = 30; - // int yCoord = getHeight() - image.getIconHeight() - - // 30; - int xCoord = (getWidth() / 2) - (image.getIconWidth() / 2); - int yCoord = (getHeight() / 2) - (image.getIconHeight() / 2); - g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.3f)); - g.drawImage(image.getImage(), xCoord, yCoord, null); - g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1.0f)); - } - } - }; - panel.setBorder(BorderFactory.createLineBorder(Color.LIGHT_GRAY)); - panel.add(new JLabel("3D graphics not available")); - } - }; + private Runnable r = new Runnable() { + @Override + public void run() { + final ImageIcon image = (ImageIcon) engysLogo; + panel = new JPanel() { + @Override + public void paintComponent(final Graphics g) { + super.paintComponent(g); + Graphics2D g2d = (Graphics2D) g; + g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); + if (image != null) { + // int xCoord = 30; + // int yCoord = getHeight() - image.getIconHeight() - + // 30; + int xCoord = (getWidth() / 2) - (image.getIconWidth() / 2); + int yCoord = (getHeight() / 2) - (image.getIconHeight() / 2); + g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.3f)); + g.drawImage(image.getImage(), xCoord, yCoord, null); + g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1.0f)); + } + } + }; + panel.setBorder(BorderFactory.createLineBorder(Color.LIGHT_GRAY)); + panel.add(new JLabel("3D graphics not available")); + } + }; - @Override - public void registerController(Controller3D context) { - } + @Override + public void registerController(Controller3D context) { + } - @Override - public void layoutComponents() { - } + @Override + public void layoutComponents() { + } - @Override - public void load() { - } + @Override + public void load(boolean loadMesh) { + } - @Override - public void save() { - } + @Override + public void save() { + } - @Override - public void start(Class klass) { - } + @Override + public void start(Class klass) { + } + + @Override + public void stop(Class klass) { + } + + @Override + public void loadWidgets() { + } + + @Override + public BoundingBox computeBoundingBox(boolean visibleOnly) { + return new BoundingBox(); + } + + public void updatePatchesSelection(Patch[] selection) { + } + + public void updatePatchVisibility(Patch selection, boolean b) { + } + + public void updateCellZonesSelection(CellZone[] selection) { + } + + public void updateCellZoneVisibility(CellZone selection, boolean b) { + } + + @Override + public void clear() { + } + + public Dimension getMinimumSize() { + return new Dimension(50, 50); + } + + @Override + public JPanel getPanel() { + if (SwingUtilities.isEventDispatchThread()) { + r.run(); + } else { + try { + SwingUtilities.invokeAndWait(r); + } catch (Exception e) { + e.printStackTrace(); + } + } + return panel; + } + + @Override + public void showPoint(String key, DoubleField[] point, EventActionType action, Color color) { + } + + @Override + public void showBox(DoubleField[] min, DoubleField[] max, EventActionType actions) { + } + + @Override + public void showRotatedBox(DoubleField[] center, DoubleField[] delta, DoubleField[] rotation, EventActionType actions) { + } + + @Override + public void updateMinAndMaxForFields(String varName, Point3d min, Point3d max) { + } + + @Override + public void showMinMaxFieldPoints(String key, Kind kind, boolean visible) { + } + +// @Override +// public void activateCOR(EventActionType action) { +// } - @Override - public void stop(Class klass) { - } - - @Override - public void loadWidgets() { - } +// @Override +// public void activateLocation(EventActionType action) { +// } - @Override - public BoundingBox computeBoundingBox(boolean visibleOnly) { - return new BoundingBox(); - } - public void updatePatchesSelection(Patch[] selection) { - } + @Override + public void activateSelection(Selection selection, EventActionType action) { + } - public void updatePatchVisibility(Patch selection, boolean b) { - } + @Override + public void showQualityFields(QualityInfo qualityInfo, EventActionType action) { + } - public void updateCellZonesSelection(CellZone[] selection) { - } + @Override + public void showLayersCoverage(LayerInfo layerInfo, JPanel colorBar, EventActionType action) { + } - public void updateCellZoneVisibility(CellZone selection, boolean b) { - } + @Override + public void geometryToMesh(GeometryToMesh g2m) { + } - @Override - public void clear() { - } + @Override + public boolean showWidget(Widget widget) { + return false; + } - public Dimension getMinimumSize() { - return new Dimension(50, 50); - } - - @Override - public JPanel getPanel() { - if (SwingUtilities.isEventDispatchThread()) { - r.run(); - } else { - try { - SwingUtilities.invokeAndWait(r); - } catch (Exception e) { - e.printStackTrace(); - } - } - return panel; - } + @Override + public void showWidgetPanel(Widget widget) { + } - @Override - public void showPoint(DoubleField[] point, String key, EventActionType action, Color color) { - } - - @Override - public void showBox(DoubleField[] min, DoubleField[] max, EventActionType actions) { - } + @Override + public void hideWidgetPanel(Widget widget) { + } - @Override - public void updateMinAndMaxForFields(String varName, Point3d min, Point3d max) { - } + @Override + public void hideWidget(Widget widget) { + } - @Override - public void showMinMaxFieldPoints(String key, Kind kind, boolean visible) { - } + @Override + public Geometry3DController getGeometryController() { + return new FallbackGeometry3DController(); + } - @Override - public void activateSelection(Selection selection, EventActionType action) { - } + @Override + public Mesh3DController getMeshController() { + return new FallbackMesh3DController(); + } - @Override - public void showQualityFields(QualityInfo qualityInfo, EventActionType action) { - } - - @Override - public void showLayersCoverage(LayerInfo layerInfo, JPanel colorBar, EventActionType action) { - } - - @Override - public void geometryToMesh(GeometryToMesh g2m) { - } + @Override + public T getController(Class klass) { + return null; + } - @Override - public boolean showWidget(Widget widget) { - return false; - } + @Override + public void resetZoom() { + } - @Override - public void showWidgetPanel(Widget widget) { - } + @Override + public void showPlane(String key, DoubleField[] origin, DoubleField[] normal, EventActionType action) { + } - @Override - public void hideWidgetPanel(Widget widget) { - } + @Override + public void showPlaneDisplay(String key, DoubleField[] origin, DoubleField[] normal, EventActionType actions) { + } - @Override - public void hideWidget(Widget widget) { - } + @Override + public void showAxis(DoubleField[] origin, DoubleField[] normal, double magnitude, EventActionType actions) { + } - @Override - public Geometry3DController getGeometryController() { - return new FallbackGeometry3DController(); - } + @Override + public void showAxis(DoubleField[] origin, DoubleField angle1, DoubleField angle2, double magnitude, int sign, EventActionType actions) { + } - @Override - public Mesh3DController getMeshController() { - return new FallbackMesh3DController(); - } + @Override + public void applyContext(Class klass) { + } - @Override - public T getController(Class klass) { - return null; - } - - @Override - public void resetZoom() { - } - - @Override - public void showPlane(DoubleField[] origin, DoubleField[] normal, EventActionType action) { - } - - @Override - public void showPlaneDisplay(DoubleField[] origin, DoubleField[] normal, EventActionType actions) { - } - - @Override - public void showAxis(DoubleField[] origin, DoubleField[] normal, EventActionType actions) { - } - - @Override - public void applyContext(Class klass) { - } - - @Override - public void dumpContext(Class klass) { - } + @Override + public void dumpContext(Class klass) { + } + @Override + public RenderPanel getRenderPanel() { + return null; + } } diff --git a/src/eu/engys/gui/view3D/quality/QualityInfo.java b/src/eu/engys/gui/view3D/quality/QualityInfo.java new file mode 100644 index 0000000..e78897d --- /dev/null +++ b/src/eu/engys/gui/view3D/quality/QualityInfo.java @@ -0,0 +1,66 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.gui.view3D.quality; + +import java.awt.Color; + +import eu.engys.util.bean.AbstractBean; + +public class QualityInfo extends AbstractBean { + + private QualityMeasure measure; + private double threshold; + private Color color; + + public QualityMeasure getMeasure() { + return measure; + } + + public void setMeasure(QualityMeasure measure) { + this.measure = measure; + } + + public double getThreshold() { + return threshold; + } + + public void setThreshold(double threshold) { + firePropertyChange("threshold", this.threshold, this.threshold = threshold); + } + + public Color getColor() { + return color; + } + + public void setColor(Color color) { + this.color = color; + } + + @Override + public String toString() { + return "fieldName: " + getMeasure().getFieldName() + ", type: " + getMeasure().getType() + ", threshold: " + getThreshold(); + } + +} \ No newline at end of file diff --git a/src/eu/engys/gui/view3D/quality/QualityMeasure.java b/src/eu/engys/gui/view3D/quality/QualityMeasure.java new file mode 100644 index 0000000..c5b3887 --- /dev/null +++ b/src/eu/engys/gui/view3D/quality/QualityMeasure.java @@ -0,0 +1,55 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.gui.view3D.quality; + +import static eu.engys.gui.view3D.quality.QualityThresholdType.LESS_THAN; +import static eu.engys.gui.view3D.quality.QualityThresholdType.MORE_THAN; + +public enum QualityMeasure { + + NON_ORTHOGONALITY("nonOrthogonality", MORE_THAN), + PYRAMIDS("pyramids", MORE_THAN), + SKEWNESS("skewness", LESS_THAN), + WEIGHTS("weights", MORE_THAN), + VOLUME_RATIO("volumeRatio", MORE_THAN), + DETERMINANT("determinant", MORE_THAN); + + private String fieldName; + private QualityThresholdType type; + + private QualityMeasure(String fieldName, QualityThresholdType type) { + this.fieldName = fieldName; + this.type = type; + } + + public String getFieldName() { + return fieldName; + } + + public QualityThresholdType getType() { + return type; + } + +} diff --git a/src/eu/engys/gui/view3D/quality/QualityThresholdType.java b/src/eu/engys/gui/view3D/quality/QualityThresholdType.java new file mode 100644 index 0000000..7c26a8d --- /dev/null +++ b/src/eu/engys/gui/view3D/quality/QualityThresholdType.java @@ -0,0 +1,31 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.gui.view3D.quality; + +public enum QualityThresholdType { + + MORE_THAN, LESS_THAN; + +} diff --git a/src/eu/engys/gui/view3D/widget/Widget.java b/src/eu/engys/gui/view3D/widget/Widget.java index d59bbee..d95ffd0 100644 --- a/src/eu/engys/gui/view3D/widget/Widget.java +++ b/src/eu/engys/gui/view3D/widget/Widget.java @@ -1,29 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.view3D.widget; import javax.swing.JToolBar; @@ -32,26 +30,37 @@ import eu.engys.gui.view3D.CanvasPanel; public interface Widget { - void populate(CanvasPanel view3D); - void populate(JToolBar toolbar); - - boolean canShow(); - - void show(); - void hide(); - - void clear(); - - void stop(); - - WidgetComponent getWidgetComponent(); - void load(); - - void applyContext(); - - void handleFieldChanged(); + void populate(CanvasPanel view3D); + + void populate(JToolBar toolbar); + + boolean canShow(); + + void show(); + + void hide(); + + void clear(); + + void stop(); + + WidgetComponent getWidgetComponent(); + + void load(); + + void applyContext(); + + void handleFieldChanged(); + void handleTimeStepChanged(); - void handleNewTimeStepsRead(); -// void handleInitializeFieldsStarted(); -// void handleInitializeFieldsFinished(); + + void handleWidgetShow(Class wClass); + + void handleWidgetHide(Class wClass); + + void handleInternalMeshShow(); + + void handleInternalMeshHide(); + + void handleZoomReset(); } diff --git a/src/eu/engys/gui/view3D/widget/WidgetComponent.java b/src/eu/engys/gui/view3D/widget/WidgetComponent.java index 8a43a1c..8e2d8ae 100644 --- a/src/eu/engys/gui/view3D/widget/WidgetComponent.java +++ b/src/eu/engys/gui/view3D/widget/WidgetComponent.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.gui.view3D.widget; @@ -31,6 +30,7 @@ import javax.swing.JPanel; public interface WidgetComponent { void handleShow(); + void handleHide(); JPanel getPanel(); diff --git a/src/eu/engys/launcher/AbstractApplicationLauncher.java b/src/eu/engys/launcher/AbstractApplicationLauncher.java index ee2d33a..c09974d 100644 --- a/src/eu/engys/launcher/AbstractApplicationLauncher.java +++ b/src/eu/engys/launcher/AbstractApplicationLauncher.java @@ -1,43 +1,44 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.launcher; import static eu.engys.launcher.StartUpMonitor.info; import java.net.URL; +import java.util.ArrayList; +import java.util.List; import javax.inject.Inject; import javax.swing.Icon; -import javax.swing.SwingUtilities; import com.google.inject.Injector; import com.google.inject.Module; import eu.engys.application.Application; import eu.engys.application.Batch; +import eu.engys.core.Arguments; import eu.engys.launcher.modules.Modules; public abstract class AbstractApplicationLauncher implements ApplicationLauncher { @@ -63,10 +64,12 @@ public abstract class AbstractApplicationLauncher implements ApplicationLauncher public abstract void checkLicense(); @Override - public void launch() throws Exception { + public void launch(Arguments arguments) throws Exception { info("Loading application modules"); URL url = getClass().getProtectionDomain().getCodeSource().getLocation(); - Iterable modules = Modules.loadApplicationModules(url); + List modules = new ArrayList<>(); + modules.addAll(Modules.load3DModules(null, arguments.no3D)); + modules.addAll(Modules.loadApplicationModules(url)); info("Starting Modules"); Injector appInjector = injector.createChildInjector(modules); @@ -75,11 +78,11 @@ public abstract class AbstractApplicationLauncher implements ApplicationLauncher Application application = appInjector.getInstance(Application.class); info("Layout Application"); - SwingUtilities.invokeLater(application); + application.start(arguments); } @Override - public void batch() throws Exception { + public void batch(Arguments arguments) throws Exception { info("Loading modules"); URL url = getClass().getProtectionDomain().getCodeSource().getLocation(); Iterable modules = Modules.loadBatchModules(url); @@ -91,6 +94,6 @@ public abstract class AbstractApplicationLauncher implements ApplicationLauncher Batch batch = appInjector.getInstance(Batch.class); info("Launch Batch"); - batch.run(); + batch.start(arguments); } } diff --git a/src/eu/engys/launcher/ApplicationLauncher.java b/src/eu/engys/launcher/ApplicationLauncher.java index 87f2d7f..e0d3713 100644 --- a/src/eu/engys/launcher/ApplicationLauncher.java +++ b/src/eu/engys/launcher/ApplicationLauncher.java @@ -1,44 +1,43 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.launcher; import javax.swing.Icon; +import eu.engys.core.Arguments; public interface ApplicationLauncher { - - - public void checkLicense() throws Exception; - public void launch() throws Exception; - public void batch() throws Exception; + + public void checkLicense() throws Exception; + + public void launch(Arguments arguments) throws Exception; + + public void batch(Arguments arguments) throws Exception; public String getTitle(); public Icon getIcon(); } - diff --git a/src/eu/engys/launcher/HELYXOSLauncher.java b/src/eu/engys/launcher/HELYXOSLauncher.java index db9ca29..c4cfea3 100644 --- a/src/eu/engys/launcher/HELYXOSLauncher.java +++ b/src/eu/engys/launcher/HELYXOSLauncher.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.launcher; @@ -30,6 +29,8 @@ import javax.inject.Inject; import com.google.inject.Injector; +import eu.engys.core.Arguments; + public class HELYXOSLauncher extends AbstractApplicationLauncher { @Inject @@ -42,8 +43,8 @@ public class HELYXOSLauncher extends AbstractApplicationLauncher { /* do not remove this method*/ } - @Override - public void batch() throws Exception { + @Override + public void batch(Arguments arguments) throws Exception { /* do not remove this method*/ } diff --git a/src/eu/engys/launcher/Launcher.java b/src/eu/engys/launcher/Launcher.java index 576c30b..b439838 100644 --- a/src/eu/engys/launcher/Launcher.java +++ b/src/eu/engys/launcher/Launcher.java @@ -1,37 +1,33 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.launcher; import static eu.engys.launcher.StartUpMonitor.info; import java.util.List; -import javax.swing.SwingUtilities; - import com.google.inject.Guice; import com.google.inject.Injector; import com.google.inject.Module; @@ -39,10 +35,10 @@ import com.google.inject.Module; import eu.engys.application.Application; import eu.engys.application.Batch; import eu.engys.core.Arguments; -import eu.engys.core.LoggerUtil; import eu.engys.launcher.modules.Modules; import eu.engys.suite.Suite; import eu.engys.util.ApplicationInfo; +import eu.engys.util.LoggerUtil; import eu.engys.util.Util; import eu.engys.util.plaf.ILookAndFeel; import eu.engys.util.ui.UiUtil; @@ -50,31 +46,34 @@ import eu.engys.util.ui.UiUtil; public class Launcher { public static void main(String[] args) throws Exception { - + + info("Initialize Arguments"); + Arguments arguments = new Arguments(); + arguments.parse(args); + info("Set Application Info"); ApplicationInfo.init(); printOut(ApplicationInfo.getHeaderInfo()); - - info("Initialize Arguments"); - Arguments.init(args); info("Initialize Logger"); - if (Arguments.isBatch()) - LoggerUtil.initFlatLogger(); + if (arguments.isBatch()) + LoggerUtil.initFlatLogger(arguments.logLevel); else - LoggerUtil.initLogger(); + LoggerUtil.initLogger(arguments.logLevel); info("Initialize Locale"); LocaleUtil.initLocale(); + info("Initialize Script"); Util.initScriptStyle(); info("Loading modules"); List modules = Modules.loadSuiteModules(); if (modules.isEmpty()) { - if (Arguments.isBatch() ) { + if (arguments.isBatch() ) { + modules = Modules.loadBatchModules(null); info("Starting modules"); @@ -82,11 +81,16 @@ public class Launcher { info("Go to Batch"); Batch batch = injector.getInstance(Batch.class); + + info("Check License"); + batch.checkLicense(); info("Launch Batch"); - batch.run(); + batch.start(arguments); } else { - modules = Modules.loadApplicationModules(null); + + modules.addAll(Modules.load3DModules(null, arguments.no3D)); + modules.addAll(Modules.loadApplicationModules(null)); info("Starting modules"); Injector injector = Guice.createInjector(modules); @@ -95,17 +99,18 @@ public class Launcher { ILookAndFeel laf = injector.getInstance(ILookAndFeel.class); laf.init(); - info("Check License"); ApplicationLauncher launcher = injector.getInstance(ApplicationLauncher.class); + + info("Check License"); launcher.checkLicense(); info("Loading Application"); Application application = injector.getInstance(Application.class); - + UiUtil.renameUIThread(); - info("Layout Application"); - SwingUtilities.invokeLater(application); + info("Start Application"); + application.start(arguments); } } else { info("Starting modules"); @@ -118,19 +123,20 @@ public class Launcher { info("Loading Suite"); Suite suite = injector.getInstance(Suite.class); - if (Arguments.isBatch() ) { + if (arguments.isBatch() ) { info("Go to Batch"); - suite.batch(); + suite.batch(arguments); } else { info("Start Suite"); UiUtil.installExceptionHandler(); UiUtil.renameUIThread(); - suite.launch(); + suite.launch(arguments); } } } - private static void printOut(String msg) { + + private static void printOut(String msg) { System.out.println(msg); } diff --git a/src/eu/engys/launcher/LocaleUtil.java b/src/eu/engys/launcher/LocaleUtil.java index 9e1b57d..f4fa840 100644 --- a/src/eu/engys/launcher/LocaleUtil.java +++ b/src/eu/engys/launcher/LocaleUtil.java @@ -1,29 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.launcher; import java.util.Locale; diff --git a/src/eu/engys/launcher/StartUpMonitor.java b/src/eu/engys/launcher/StartUpMonitor.java index 2069cad..3b3abb0 100644 --- a/src/eu/engys/launcher/StartUpMonitor.java +++ b/src/eu/engys/launcher/StartUpMonitor.java @@ -1,29 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.launcher; import java.awt.Color; @@ -42,6 +40,8 @@ import java.net.URL; import java.net.URLDecoder; import java.util.concurrent.atomic.AtomicBoolean; +import eu.engys.util.Util; + public class StartUpMonitor { private static StartUpMonitor instance; @@ -52,7 +52,7 @@ public class StartUpMonitor { public static void info(final String msg) { if (GraphicsEnvironment.isHeadless()) { System.out.println("+++ " + msg + " +++"); - } else { + } else { if (instance == null) { instance = new StartUpMonitor(); pwnSplashScreen(); @@ -65,7 +65,7 @@ public class StartUpMonitor { private static void setApplicationType() { try { URL coreGuiJarURL = StartUpMonitor.class.getProtectionDomain().getCodeSource().getLocation(); - String decodedCoreGuiJarURL = URLDecoder.decode(coreGuiJarURL.getFile(), "UTF-8"); + String decodedCoreGuiJarURL = URLDecoder.decode(coreGuiJarURL.getFile(), Util.UTF_8); File libDir = new File(decodedCoreGuiJarURL).getParentFile(); isElements = new File(libDir, "ELEMENTS.jar").exists(); isHelyxOS = new File(libDir, "HELYX-OS.jar").exists(); @@ -90,7 +90,7 @@ public class StartUpMonitor { } } - public static void close() { + public static void closeSplash() { SplashScreen splash = getSplashScreen(); if (splash != null) { splash.close(); @@ -139,9 +139,20 @@ public class StartUpMonitor { int splashWidth = getSplashScreen().getSize().width; int width = Math.min(10 * counter, splashWidth - (leftPadding * 2)); - g.setColor(isHelyxOS ? Color.BLUE.darker() : Color.RED.darker()); + Color firstColor; + Color secondColor; + + if (isHelyxOS) { + firstColor = Color.BLUE.darker(); + secondColor = Color.BLUE.brighter(); + } else { + firstColor = Color.RED.darker(); + secondColor = Color.RED.brighter(); + } + + g.setColor(firstColor); g.fillRect(leftPadding, topPadding, width, 2); - g.setColor(isHelyxOS ? Color.BLUE.brighter() : Color.RED.brighter()); + g.setColor(secondColor); g.fillRect(leftPadding, topPadding, width, 1); } @@ -221,4 +232,53 @@ public class StartUpMonitor { ((Graphics2D) g).setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); } + // public static void main(String[] args) { + // new HelyxLookAndFeel().init(); + // Model model = new Model(); + // model.init(); + // JPanel panel = new JPanel(new GridLayout(4, 2)); + // JLabel l1 = new JLabel("HELYX OS 1"); + // JLabel l2 = new JLabel("HELYX OS 2"); + // JLabel l3 = new JLabel("HELYX 1"); + // JLabel l4 = new JLabel("HELYX 2"); + // JLabel l5 = new JLabel("ELEMENTS 1"); + // JLabel l6 = new JLabel("ELEMENTS 2"); + // JLabel l7 = new JLabel("CASE MANAGER 1"); + // JLabel l8 = new JLabel("CASE MANAGER 2"); + // + // l1.setOpaque(true); + // l2.setOpaque(true); + // l3.setOpaque(true); + // l4.setOpaque(true); + // l5.setOpaque(true); + // l6.setOpaque(true); + // l7.setOpaque(true); + // l8.setOpaque(true); + // + // l1.setBackground(Color.BLUE.brighter()); + // l2.setBackground(Color.BLUE.darker()); + // + // l3.setBackground(Color.RED.brighter()); + // l4.setBackground(Color.RED.darker()); + // + // l5.setBackground(Color.GREEN.brighter()); + // l6.setBackground(Color.GREEN.darker()); + // + // l7.setBackground(Color.YELLOW.brighter()); + // l8.setBackground(Color.YELLOW.darker()); + // + // panel.add(l1); + // panel.add(l2); + // panel.add(l3); + // panel.add(l4); + // panel.add(l5); + // panel.add(l6); + // panel.add(l7); + // panel.add(l8); + // + // JFrame f = UiUtil.defaultTestFrame("a", panel); + // f.setSize(600, 300); + // f.setVisible(true); + // } + } diff --git a/src/eu/engys/launcher/modules/Modules.java b/src/eu/engys/launcher/modules/Modules.java index 458acd3..7b94199 100644 --- a/src/eu/engys/launcher/modules/Modules.java +++ b/src/eu/engys/launcher/modules/Modules.java @@ -1,29 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.launcher.modules; import java.io.File; @@ -42,6 +40,8 @@ import org.slf4j.LoggerFactory; import com.google.inject.Module; +import eu.engys.util.Util; + public class Modules { private static final Logger logger = LoggerFactory.getLogger(Modules.class); @@ -53,18 +53,22 @@ public class Modules { private static URL url; public static List loadSuiteModules() { - return loadModules("eu.engys.suite.modules", Module.class, null); + return loadModules("eu.engys.suite.modules", Module.class, null, null); } public static List loadApplicationModules(URL url) { - return loadModules("eu.engys.application.modules", Module.class, url); + return loadModules("eu.engys.application.modules", Module.class, url, null); + } + + public static List load3DModules(URL url, boolean no3D) { + return loadModules("eu.engys.vtk.modules", Module.class, url, no3D); } public static List loadBatchModules(URL url) { - return loadModules("eu.engys.batch.modules", Module.class, url); + return loadModules("eu.engys.batch.modules", Module.class, url, null); } - - static List loadModules(String pkgName, Class interfaceClass, URL classURL) { + + static List loadModules(String pkgName, Class interfaceClass, URL classURL, Object arg) { List modules = new ArrayList(); interfase = interfaceClass; @@ -77,11 +81,16 @@ public class Modules { for(Class clazz : classes) { try { - M newInstance = clazz.newInstance(); - logger.info("[Modules] {} loaded", clazz.getName()); - modules.add(newInstance); + M module = null; + if (arg != null) { + module = clazz.getConstructor(arg.getClass()).newInstance(arg); + } else { + module = clazz.newInstance(); + } + logger.info("[Modules] {} loaded", clazz.getName()); + modules.add(module); } catch (Exception e) { - logger.error(e.getMessage()); + logger.error(e.getMessage(), e); } } } catch (Exception e) { @@ -132,12 +141,12 @@ public class Modules { for(URL packageURL : Collections.list(packageURLs)) { if (packageURL.getProtocol().equals("jar")) { // build jar file name - String jarFileName = URLDecoder.decode(packageURL.getFile(), "UTF-8"); + String jarFileName = URLDecoder.decode(packageURL.getFile(), Util.UTF_8); jarFileName = jarFileName.substring(5, jarFileName.indexOf("!")); if (url == null ){ names.addAll(extractClassName(packageName, jarFileName)); } else { - String parentJarFileName = URLDecoder.decode(url.getFile(), "UTF-8"); + String parentJarFileName = URLDecoder.decode(url.getFile(), Util.UTF_8); if (jarFileName.startsWith(parentJarFileName)){ names.addAll(extractClassName(packageName, jarFileName)); diff --git a/src/eu/engys/parallelworks/CloudPanel.java b/src/eu/engys/parallelworks/CloudPanel.java new file mode 100644 index 0000000..cd78e13 --- /dev/null +++ b/src/eu/engys/parallelworks/CloudPanel.java @@ -0,0 +1,296 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.parallelworks; + +import static eu.engys.parallelworks.ParallelWorksData.LOCALHOST; +import static eu.engys.parallelworks.ParallelWorksData.PARALLEL_WORKS; +import static eu.engys.util.ui.ComponentsFactory.selectField; +import static eu.engys.util.ui.ComponentsFactory.stringField; +import static eu.engys.util.ui.UiUtil.DIALOG_CANCEL_LABEL; +import static eu.engys.util.ui.UiUtil.DIALOG_OK_LABEL; + +import java.awt.BorderLayout; +import java.awt.Color; +import java.awt.Dialog.ModalityType; +import java.awt.FlowLayout; +import java.awt.GridLayout; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.net.URI; + +import javax.swing.AbstractAction; +import javax.swing.BorderFactory; +import javax.swing.JButton; +import javax.swing.JCheckBox; +import javax.swing.JComboBox; +import javax.swing.JDialog; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JTextArea; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import eu.engys.core.controller.Controller; +import eu.engys.core.controller.Controller.OpenMode; +import eu.engys.core.project.Model; +import eu.engys.util.Util; +import eu.engys.util.progress.ProgressMonitor; +import eu.engys.util.ui.ComponentsFactory; +import eu.engys.util.ui.UiUtil; +import eu.engys.util.ui.builder.PanelBuilder; +import eu.engys.util.ui.textfields.StringField; + +public class CloudPanel extends JPanel { + + private static final Logger logger = LoggerFactory.getLogger(CloudPanel.class); + + public static final String GET_A_PARALLEL_WORKS_API_KEY = "Get a Parallel Works API key"; + private static final String WEBSITE = "https://eval.parallel.works/signup?starter=helyxos"; + + private static final String CLOUD_SETTINGS = "Cloud Settings"; + + private static final String[] DRIVERS = { LOCALHOST, PARALLEL_WORKS }; + + public static final String EXECUTION_DRIVER = "Execution Driver"; + public static final String API_KEY = "API Key"; + public static final String RUN_WORKSPACE = "Run Workspace"; + public static final String RUN_WORKFLOW = "Run Workflow"; + public static final String PULL_RESULTS = "Pull Results from Cloud"; + + public static final String DOWNLOAD_LABEL = "Download Last Cloud Result"; + + private JDialog dialog; + + private JComboBox driverCombo; + private StringField driverAPIKEY; + private StringField driverWorkflow; + private StringField driverWorkspace; + private JCheckBox driverPullResults; + + private JButton downloadButton; + private JButton websiteButton; + + private DriverComboListener listener; + + private Model model; + private ProgressMonitor monitor; + + private Controller controller; + + private JTextArea infoArea; + + public CloudPanel(Model model, Controller controller, ProgressMonitor monitor) { + super(new BorderLayout()); + this.model = model; + this.controller = controller; + this.monitor = monitor; + layoutComponents(); + } + + private void layoutComponents() { + JScrollPane scrollPane = new JScrollPane(createMainPanel()); + scrollPane.setBorder(BorderFactory.createEmptyBorder()); + scrollPane.getVerticalScrollBar().setUnitIncrement(20); + + add(scrollPane, BorderLayout.CENTER); + add(createButtonsPanel(), BorderLayout.SOUTH); + + dialog = new JDialog(UiUtil.getActiveWindow(), CLOUD_SETTINGS, ModalityType.APPLICATION_MODAL); + dialog.getContentPane().setLayout(new BorderLayout()); + dialog.getContentPane().add(this); + dialog.setSize(520, 320); + dialog.setLocationRelativeTo(null); + + this.listener = new DriverComboListener(); + } + + private JPanel createMainPanel() { + PanelBuilder builder = new PanelBuilder(); + builder.addComponent(EXECUTION_DRIVER, driverCombo = selectField(DRIVERS)); + builder.addComponent(API_KEY, driverAPIKEY = stringField("")); + builder.addComponent(RUN_WORKFLOW, driverWorkflow = stringField("", false, false)); + builder.addComponent(RUN_WORKSPACE, driverWorkspace = stringField("", false, false)); + builder.addComponent(PULL_RESULTS, driverPullResults = ComponentsFactory.checkField(true)); + + infoArea = new JTextArea("Mesh, initialise fields and solver scripts, will be executed on the Parallel Works cloud using OpenFOAM v4.0."); + infoArea.setLineWrap(true); + infoArea.setEditable(false); + infoArea.setOpaque(false); + infoArea.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createMatteBorder(1, 0, 1, 0, Color.WHITE), BorderFactory.createEmptyBorder(10, 0, 10, 0))); + + websiteButton = UiUtil.createURLOpenerButton(new WebSiteAction()); + websiteButton.setForeground(Color.BLUE); + websiteButton.setBorderPainted(false); + websiteButton.setName(GET_A_PARALLEL_WORKS_API_KEY); + + JPanel mainPanel = new JPanel(new BorderLayout(10, 10)); + mainPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); + mainPanel.add(builder.removeMargins().getPanel(), BorderLayout.NORTH); + mainPanel.add(infoArea, BorderLayout.CENTER); + mainPanel.add(websiteButton, BorderLayout.SOUTH); + + return mainPanel; + } + + private JPanel createButtonsPanel() { + JPanel leftPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); + leftPanel.add(downloadButton = new JButton(new DownloadAction())); + downloadButton.setName(DOWNLOAD_LABEL); + + JPanel rightPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); + JButton okButton = new JButton(new OkAction()); + okButton.setName(UiUtil.DIALOG_OK_LABEL); + JButton cancelButton = new JButton(new CancelAction()); + cancelButton.setName(UiUtil.DIALOG_CANCEL_LABEL); + rightPanel.add(okButton); + rightPanel.add(cancelButton); + + JPanel buttonsPanel = new JPanel(new GridLayout(1, 2)); + buttonsPanel.add(leftPanel); + buttonsPanel.add(rightPanel); + return buttonsPanel; + } + + public void showDialog(ParallelWorksData data) { + load(data); + dialog.setVisible(true); + } + + private void closeDialog() { + dialog.dispose(); + } + + void load(ParallelWorksData data) { + driverCombo.removeActionListener(listener); + + driverCombo.setSelectedItem(data.getType()); + driverAPIKEY.setStringValue(data.getKey()); + driverWorkflow.setStringValue(data.getWorkflow()); + driverWorkspace.setStringValue(data.getWorkspace()); + driverPullResults.setSelected(data.isPullResults()); + + enableEditing(data.isLocalhost()); + + driverCombo.addActionListener(listener); + } + + private void enableEditing(boolean isLocalhost) { + driverAPIKEY.setEnabled(!isLocalhost); + driverWorkflow.setEnabled(!isLocalhost); + driverWorkspace.setEnabled(!isLocalhost); + driverPullResults.setEnabled(!isLocalhost); + websiteButton.setVisible(!isLocalhost); + downloadButton.setVisible(!isLocalhost); + infoArea.setVisible(!isLocalhost); + } + + ParallelWorksData save() { + ParallelWorksData data = new ParallelWorksData(); + data.setType(driverCombo.getItemAt(driverCombo.getSelectedIndex())); + data.setKey(driverAPIKEY.getStringValue()); + data.setWorkflow(driverWorkflow.getStringValue()); + data.setWorkspace(driverWorkspace.getStringValue()); + data.setPullResults(driverPullResults.isSelected()); + return data; + } + + private class DriverComboListener implements ActionListener { + + @Override + public void actionPerformed(ActionEvent e) { + enableEditing(driverCombo.getItemAt(driverCombo.getSelectedIndex()).equals(ParallelWorksData.LOCALHOST)); + } + + } + + private class OkAction extends AbstractAction { + + public OkAction() { + super(DIALOG_OK_LABEL); + } + + @Override + public void actionPerformed(ActionEvent e) { + ParallelWorksData data = save(); + ParallelWorksData.toPreferences(data); + closeDialog(); + } + + } + + private class CancelAction extends AbstractAction { + + public CancelAction() { + super(DIALOG_CANCEL_LABEL); + } + + @Override + public void actionPerformed(ActionEvent e) { + closeDialog(); + } + + } + + private class DownloadAction extends AbstractAction { + + public DownloadAction() { + super(DOWNLOAD_LABEL); + } + + @Override + public void actionPerformed(ActionEvent event) { + int retVal = showWarningMessage("This action will override current data. Continue?"); + if (retVal == JOptionPane.OK_OPTION) { + closeDialog(); + new ParallelWorksDownloader(model, monitor).downloadCloudResults(); + controller.reopenCase(OpenMode.CURRENT_SETTINGS); + } + } + } + + private int showWarningMessage(String message) { + return JOptionPane.showConfirmDialog(dialog, message, "Warning", JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE); + } + + private class WebSiteAction extends AbstractAction { + + public WebSiteAction() { + super(GET_A_PARALLEL_WORKS_API_KEY); + } + + @Override + public void actionPerformed(ActionEvent e) { + try { + Util.openWebpage(new URI(WEBSITE).toURL()); + } catch (Exception ex) { + logger.error(ex.getMessage()); + } + } + + } + +} \ No newline at end of file diff --git a/src/eu/engys/parallelworks/ParallelWorksCleaner.java b/src/eu/engys/parallelworks/ParallelWorksCleaner.java new file mode 100644 index 0000000..e4de0f8 --- /dev/null +++ b/src/eu/engys/parallelworks/ParallelWorksCleaner.java @@ -0,0 +1,52 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.parallelworks; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; + +import org.apache.commons.io.FileUtils; +import org.apache.commons.io.filefilter.FileFilterUtils; + +import eu.engys.core.project.system.ControlDict; + +public class ParallelWorksCleaner { + + public static void cleanBaseDir(File baseDir) { + List tempFiles = new ArrayList(FileUtils.listFiles(baseDir, FileFilterUtils.prefixFileFilter("_"), null)); + for (File f : tempFiles) { + FileUtils.deleteQuietly(f); + } + + List supportFiles = new ArrayList(FileUtils.listFiles(baseDir, new String[] { "tgz", "gz", "job", "py", "pyc", "sh", "env" }, false)); + for (File f : supportFiles) { + FileUtils.deleteQuietly(f); + } + + FileUtils.deleteQuietly(new File(baseDir, ControlDict.CONTROL_DICT)); + } + +} diff --git a/src/eu/engys/parallelworks/ParallelWorksClient.java b/src/eu/engys/parallelworks/ParallelWorksClient.java new file mode 100644 index 0000000..a72c83d --- /dev/null +++ b/src/eu/engys/parallelworks/ParallelWorksClient.java @@ -0,0 +1,217 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.parallelworks; + +import static eu.engys.parallelworks.ParallelWorksData.PW_SITE; + +import java.io.File; +import java.io.IOException; + +import javax.ws.rs.client.Client; +import javax.ws.rs.client.ClientBuilder; +import javax.ws.rs.client.Entity; +import javax.ws.rs.client.WebTarget; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + +import org.glassfish.jersey.media.multipart.FormDataMultiPart; +import org.glassfish.jersey.media.multipart.file.FileDataBodyPart; +import org.glassfish.jersey.media.multipart.internal.MultiPartWriter; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider; + +import eu.engys.parallelworks.json.Dataset; +import eu.engys.parallelworks.json.Histories; +import eu.engys.parallelworks.json.HistoryEntry; +import eu.engys.parallelworks.json.JobId; +import eu.engys.parallelworks.json.JobInfo; +import eu.engys.parallelworks.json.JobState; +import eu.engys.parallelworks.json.Resource; +import eu.engys.parallelworks.json.Resources; +import eu.engys.parallelworks.json.StartJobInputs; +import eu.engys.parallelworks.json.StartJobResponse; +import eu.engys.parallelworks.json.UploadDatasetResponse; +import eu.engys.util.PrefUtil; + +public class ParallelWorksClient { + + /* + * TODO: it would be nice to add some more checks/error messages + * e.g. if you insert an invalid workspace_id a meaningless message is shown instead of something like: invalid connection parameters or, if possible, workspace id not found + */ + + private static ParallelWorksClient instance; + + private static String apiKey; + private static Client client; + private static WebTarget baseTarget; + + private JobId jobID; + private String datasetID; + + private ParallelWorksClient() { + apiKey = PrefUtil.getString(PrefUtil.PW_APIKEY); + + client = ClientBuilder.newClient(); + client.register(JacksonJsonProvider.class); + client.register(MultiPartWriter.class); + // client.register(new LoggingFilter()); + baseTarget = client.target(PW_SITE).path("api"); + } + + public static ParallelWorksClient getInstance() { + if (instance == null) { + instance = new ParallelWorksClient(); + } + return instance; + } + + public String getWorkspaceID(String name) { + Histories histories = getHistories(); + for (HistoryEntry e : histories) { + if (name.equals(e.getName())) { + return e.getId(); + } + } + + return null; + } + + public void uploadDataset(String workspaceID, File archivedCase) throws IOException { + FileDataBodyPart filePart = new FileDataBodyPart("files_0|file_data", archivedCase); + FormDataMultiPart formData = new FormDataMultiPart(); + formData.field("key", apiKey); + formData.field("tool_id", "upload1"); + formData.field("workspace_id", workspaceID); + formData.bodyPart(filePart); + + Response response = baseTarget.path("tools").request().post(Entity.entity(formData, formData.getMediaType())); + formData.close(); + this.datasetID = response.readEntity(UploadDatasetResponse.class).getOutputs().get(0).getId(); + } + + public Histories getHistories() { + return baseTarget.path("histories").queryParam("key", apiKey).request().get(Histories.class); + } + + public String getDatasetState() { + if (datasetID != null) { + return baseTarget.path("datasets").path(datasetID).queryParam("key", apiKey).request().get(Dataset.class).getState(); + } + return null; + } + + public boolean isPoolOn() { + Resources res = baseTarget.path("resources").queryParam("key", apiKey).request().get(Resources.class); + for (Resource resource : res) { + if (resource.getStatus().equals("on")) { + return true; + } + } + return false; + } + + public String getWorkflowName(String workflow) { + return client.target(PW_SITE).path("workflow_name").path(workflow).queryParam("key", apiKey).request().get(String.class); + } + + /* + * JOBS + */ + + public void startJob(String command) throws IOException { + ObjectMapper mapper = new ObjectMapper(); + StartJobInputs inputs = new StartJobInputs(datasetID, command); + + FormDataMultiPart formData = new FormDataMultiPart(); + formData.field("key", apiKey); + formData.field("tool_id", getWorkflowName(PrefUtil.getString(PrefUtil.PW_WORKFLOW))); + formData.field("workspace_id", getWorkspaceID(PrefUtil.getString(PrefUtil.PW_WORKSPACE))); + formData.close(); + try { + formData.field("inputs", mapper.writeValueAsString(inputs)); + } catch (JsonProcessingException e) { + throw new RuntimeException(e); + } + + Response resp = baseTarget.path("tools").request().post(Entity.entity(formData, formData.getMediaType())); + StartJobResponse sjr = resp.readEntity(StartJobResponse.class); + + this.jobID = new JobId(sjr.getJobs().get(0).getId(), sjr.getDecodedJobId()); + } + + public JobState getJobState() { + // galaxy is sending the JSON back as text/html + try { + String resp = baseTarget.path("jobs").path(jobID.getId()).path("state").queryParam("key", apiKey).request(MediaType.APPLICATION_JSON_TYPE).get(String.class); + ObjectMapper mapper = new ObjectMapper(); + return mapper.readValue(resp, JobState.class); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + public String getJobTail(int lastLine) { + if (jobID != null) { + return client.target(PW_SITE).path("tail_change").path(jobID.getDecodedId()).queryParam("file", "_stdout_1.txt").queryParam("line", lastLine).request().get(String.class); + } else { + return "No JOB"; + } + } + + public String getDownloadUrl() { + String resID = baseTarget.path("jobs").path(jobID.getId()).queryParam("key", apiKey).request().get(JobInfo.class).getOutput("results").getId(); + Dataset dataset = baseTarget.path("datasets").path(resID).queryParam("key", apiKey).request().get(Dataset.class); + return PW_SITE + dataset.getDownloadUrl(); + } + + public String uploadFileToJob(File file) throws IOException { + FileDataBodyPart filePart = new FileDataBodyPart("file", file); + FormDataMultiPart formData = new FormDataMultiPart(); + formData.bodyPart(filePart); + + Response response = baseTarget.path("jobs").path(jobID.getId()).path("upload").queryParam("key", apiKey).request().post(Entity.entity(formData, formData.getMediaType())); + formData.close(); + return response.readEntity(String.class); + } + + public String cancelJob() { + if (jobID != null) { + return baseTarget.path("jobs").path(jobID.getId()).path("cancel").queryParam("key", apiKey).request().get(String.class); + } + return null; + } + + public JobId getJobID() { + return jobID; + } + + public String getDatasetID() { + return datasetID; + } + +} diff --git a/src/eu/engys/parallelworks/ParallelWorksData.java b/src/eu/engys/parallelworks/ParallelWorksData.java new file mode 100644 index 0000000..c239c42 --- /dev/null +++ b/src/eu/engys/parallelworks/ParallelWorksData.java @@ -0,0 +1,121 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.parallelworks; + +import eu.engys.util.PrefUtil; + +public class ParallelWorksData { + + public static final String PW_SITE = "https://eval.parallel.works"; + + public static final String CASE_ENV_NAME = "case.env"; + public static final String PROJECT_JOB_FILE_NAME = "cloud.job"; + public static final String PROJECT_URL_FILE_NAME = "cloud.out"; + public static final String PROJECT_ARCHIVE_FILE_NAME = "cloud.tar.gz"; + public static final String INPUTS_ARCHIVE_FILE_NAME = "inputs.tgz"; + + public static final String LOCALHOST = "Localhost"; + public static final String PARALLEL_WORKS = "Parallel Works"; + + public static final String ENTER_EXECUTABLE_HERE = "Enter executable here"; + public static final String ENTER_API_KEY_HERE = "Enter API key here"; + public static final String DEFAULT_WORKSPACE = "helyxos_workspace"; + public static final String DEFAULT_WORKFLOW = "helyxos_runner"; + + private String type; + private String key; + private String workflow; + private String workspace; + private boolean pullResults; + + public static ParallelWorksData fromPrefences() { + String type = PrefUtil.getString(PrefUtil.PW_DRIVER, LOCALHOST); + String key = PrefUtil.getString(PrefUtil.PW_APIKEY, ENTER_API_KEY_HERE); + String workspace = PrefUtil.getString(PrefUtil.PW_WORKSPACE, DEFAULT_WORKSPACE); + String workflow = PrefUtil.getString(PrefUtil.PW_WORKFLOW, DEFAULT_WORKFLOW); + boolean pullResults = PrefUtil.getBoolean(PrefUtil.PW_PULL_RESULTS, true); + + ParallelWorksData data = new ParallelWorksData(); + data.setType(type); + data.setKey(key); + data.setWorkspace(workspace); + data.setWorkflow(workflow); + data.setPullResults(pullResults); + return data; + } + + public static void toPreferences(ParallelWorksData data) { + PrefUtil.putString(PrefUtil.PW_DRIVER, data.getType()); + PrefUtil.putString(PrefUtil.PW_APIKEY, data.getKey()); + PrefUtil.putString(PrefUtil.PW_WORKSPACE, data.getWorkspace()); + PrefUtil.putString(PrefUtil.PW_WORKFLOW, data.getWorkflow()); + PrefUtil.putBoolean(PrefUtil.PW_PULL_RESULTS, data.isPullResults()); + } + + public boolean isLocalhost() { + return type.equals(LOCALHOST); + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public String getKey() { + return key; + } + + public void setKey(String key) { + this.key = key; + } + + public String getWorkspace() { + return workspace; + } + + public void setWorkspace(String workspace) { + this.workspace = workspace; + } + + public String getWorkflow() { + return workflow; + } + + public void setWorkflow(String workflow) { + this.workflow = workflow; + } + + public boolean isPullResults() { + return pullResults; + } + + public void setPullResults(boolean pullResults) { + this.pullResults = pullResults; + } + +} diff --git a/src/eu/engys/parallelworks/ParallelWorksDownloader.java b/src/eu/engys/parallelworks/ParallelWorksDownloader.java new file mode 100644 index 0000000..9e6ba25 --- /dev/null +++ b/src/eu/engys/parallelworks/ParallelWorksDownloader.java @@ -0,0 +1,103 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.parallelworks; + +import static eu.engys.parallelworks.ParallelWorksData.PROJECT_ARCHIVE_FILE_NAME; +import static eu.engys.parallelworks.ParallelWorksData.PROJECT_URL_FILE_NAME; + +import java.io.File; +import java.net.URL; + +import javax.swing.JOptionPane; + +import org.apache.commons.io.FileUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import eu.engys.core.project.Model; +import eu.engys.util.ArchiveUtils; +import eu.engys.util.progress.ProgressMonitor; +import eu.engys.util.ui.UiUtil; + +public class ParallelWorksDownloader { + + private static final Logger logger = LoggerFactory.getLogger(ParallelWorksDownloader.class); + + private Model model; + private ProgressMonitor monitor; + + public ParallelWorksDownloader(Model model, ProgressMonitor monitor) { + this.model = model; + this.monitor = monitor; + } + + public void downloadCloudResults() { + monitor.setIndeterminate(true); + monitor.start("Downloading results...", true, new Runnable() { + @Override + public void run() { + File caseURLFile = new File(model.getProject().getBaseDir(), PROJECT_URL_FILE_NAME); + URL remoteCaseURL = extractCaseURL(caseURLFile); + if (remoteCaseURL != null) { + File destination = downloadCase(remoteCaseURL); + if (destination != null) { + ArchiveUtils.unarchive(destination, model.getProject().getBaseDir()); + } + } + ParallelWorksCleaner.cleanBaseDir(model.getProject().getBaseDir()); + monitor.setIndeterminate(false); + monitor.end(); + } + }); + } + + private URL extractCaseURL(File caseURLFile) { + try { + String fileContent = FileUtils.readFileToString(caseURLFile); + return new URL(fileContent); + } catch (Exception e) { + logger.error(e.getMessage()); + showErrorMessage("Unable to download remote case. Cause: " + e.getMessage()); + } + return null; + } + + private File downloadCase(URL remoteCaseURL) { + File destination = new File(model.getProject().getBaseDir(), PROJECT_ARCHIVE_FILE_NAME); + try { + FileUtils.copyURLToFile(remoteCaseURL, destination); + return destination; + } catch (Exception e) { + logger.error(e.getMessage()); + showErrorMessage("Unable to download remote case. Cause: " + e.getMessage()); + } + return null; + } + + private void showErrorMessage(String message) { + JOptionPane.showConfirmDialog(UiUtil.getActiveWindow(), message, "Error", JOptionPane.OK_OPTION, JOptionPane.ERROR_MESSAGE); + } + +} diff --git a/src/eu/engys/parallelworks/ParallelWorksExecutor.java b/src/eu/engys/parallelworks/ParallelWorksExecutor.java new file mode 100644 index 0000000..b157dfc --- /dev/null +++ b/src/eu/engys/parallelworks/ParallelWorksExecutor.java @@ -0,0 +1,134 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.parallelworks; + +import static eu.engys.parallelworks.ParallelWorksData.PROJECT_JOB_FILE_NAME; +import static eu.engys.parallelworks.ParallelWorksData.PROJECT_URL_FILE_NAME; + +import java.io.File; +import java.io.IOException; + +import org.apache.commons.exec.CommandLine; +import org.apache.commons.io.FileUtils; + +import eu.engys.core.executor.AbstractExecutor; +import eu.engys.parallelworks.json.JobState; + +public class ParallelWorksExecutor extends AbstractExecutor { + + int lastLine = 0; + + private File baseDir; + private String command; + private File log; + + private String lastStatus; + + public ParallelWorksExecutor(File baseDir, String command, File log) { + this.baseDir = baseDir; + this.command = command; + this.log = log; + } + + @Override + protected int _exec() { + notifyStart(); + + try { + ParallelWorksClient.getInstance().startJob(command); + FileUtils.writeStringToFile(new File(baseDir, PROJECT_JOB_FILE_NAME), ParallelWorksClient.getInstance().getJobID().getId()); + } catch (IOException e1) { + notifyError(-1, "Error starting JOB"); + return 0; + } + + while (true) { + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + notifyError(-1, "Killed"); + return 0; + } + + JobState js; + try { + js = ParallelWorksClient.getInstance().getJobState(); + } catch (Exception e) { + js = new JobState("starting", ""); + } + + String status = js.getStatus(); + if (status != null && !status.equals(lastStatus)) { + try { + FileUtils.writeStringToFile(log, status+"\n", true); + } catch (IOException e) { + } + } + lastStatus = status; + + switch (js.getState()) { + case "ok": + try { + FileUtils.writeStringToFile(new File(baseDir, PROJECT_URL_FILE_NAME), ParallelWorksClient.getInstance().getDownloadUrl()); + } catch (IOException e1) { + } + notifyFinish(0); + return 0; + case "deleted": + case "error": + notifyError(-1, "Simulation had an error. Please try again"); + return 0; + default: + String tail = ParallelWorksClient.getInstance().getJobTail(lastLine); + if (!tail.isEmpty()) { + try { + FileUtils.writeStringToFile(log, tail, true); + } catch (IOException e) { + e.printStackTrace(); + } + lastLine += count(tail, '\n'); + } + notifyRefresh(); + break; + } + } + } + + private int count(String s, char c) { + int count = 0; + for (int i = 0; i < s.length(); i++) { + if (c == s.charAt(i)) { + count++; + } + } + return count; + } + + @Override + protected CommandLine getCommandLine() { + return null; + } + +} diff --git a/src/eu/engys/parallelworks/ParallelWorksExecutorMonitor.java b/src/eu/engys/parallelworks/ParallelWorksExecutorMonitor.java new file mode 100644 index 0000000..602c5ca --- /dev/null +++ b/src/eu/engys/parallelworks/ParallelWorksExecutorMonitor.java @@ -0,0 +1,83 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.parallelworks; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; + +import org.apache.commons.io.input.Tailer; +import org.apache.commons.io.input.TailerListenerAdapter; + +import eu.engys.core.executor.TerminalExecutorMonitor; +import eu.engys.core.executor.TerminalManager; + +public class ParallelWorksExecutorMonitor extends TerminalExecutorMonitor { + + private File logFile; + private List tailers; + + public ParallelWorksExecutorMonitor(TerminalManager terminalManager, File logFile) { + super(terminalManager, logFile); + this.logFile = logFile; + this.tailers = new ArrayList<>(); + } + + @Override + public void start() { + tailers.add(Tailer.create(logFile, new MyListener(), 100L)); + super.start(); + } + + @Override + public void finish(int returnValue) { + super.finish(returnValue); + for (Tailer tailer : tailers) { + tailer.stop(); + } + } + + @Override + public void error(int returnValue, String msg) { + super.error(returnValue, msg); + for (Tailer tailer : tailers) { + tailer.stop(); + } + } + + class MyListener extends TailerListenerAdapter { + + @Override + public void handle(String line) { + _refresh(line + "\n", ""); + } + + @Override + public void handle(Exception exception) { + _refresh("", exception.getMessage() + "\n"); + } + + } +} diff --git a/src/eu/engys/parallelworks/ParallelWorksUploader.java b/src/eu/engys/parallelworks/ParallelWorksUploader.java new file mode 100644 index 0000000..72ff8a9 --- /dev/null +++ b/src/eu/engys/parallelworks/ParallelWorksUploader.java @@ -0,0 +1,125 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.parallelworks; + +import static eu.engys.parallelworks.ParallelWorksData.CASE_ENV_NAME; +import static eu.engys.parallelworks.ParallelWorksData.INPUTS_ARCHIVE_FILE_NAME; +import static eu.engys.util.IOUtils.LNX_EOL; + +import java.io.File; +import java.io.FilenameFilter; +import java.io.IOException; +import java.util.Map; + +import org.apache.commons.io.FileUtils; + +import eu.engys.util.ArchiveUtils; +import eu.engys.util.PrefUtil; +import eu.engys.util.progress.ProgressMonitor; + +public class ParallelWorksUploader {// + + private ProgressMonitor monitor; + + public ParallelWorksUploader(ProgressMonitor monitor) { + this.monitor = monitor; + } + + public void uploadCloudResults(final String command, final Map environment) { + monitor.setIndeterminate(true); + monitor.start("Uploading case...", true, new Runnable() { + @Override + public void run() { + try { + File baseDir = new File(environment.get("CASE")); + + writeCaseEnvFile(baseDir, environment); + compressCase(baseDir, command); + uploadCase(baseDir); + + } catch (Exception e) { + monitor.error(e.getMessage()); + } finally { + monitor.setIndeterminate(false); + monitor.end(); + } + } + }); + } + + private void writeCaseEnvFile(File baseDir, Map environment) { + File caseEnv = new File(baseDir, CASE_ENV_NAME); + FileUtils.deleteQuietly(caseEnv); + try { + FileUtils.writeStringToFile(caseEnv, "export CASE=" + environment.get("CASE") + LNX_EOL, false); + FileUtils.writeStringToFile(caseEnv, "export NP=" + environment.get("NP") + LNX_EOL, true); + FileUtils.writeStringToFile(caseEnv, "export LOG=" + environment.get("LOG") + LNX_EOL, true); + FileUtils.writeStringToFile(caseEnv, "export ENV_LOADER=" + "/opt/openfoam4/etc/bashrc" + LNX_EOL, true); + FileUtils.writeStringToFile(caseEnv, "export VENDOR_HOME=" + "/opt" + LNX_EOL, true); + FileUtils.writeStringToFile(caseEnv, "export PV_VERSION=" + environment.get("PV_VERSION") + LNX_EOL, true); + FileUtils.writeStringToFile(caseEnv, "export MACHINEFILE=" + environment.get("MACHINEFILE") + LNX_EOL, true); + FileUtils.writeStringToFile(caseEnv, "export SOLVER=" + environment.get("SOLVER") + LNX_EOL, true); + } catch (IOException e) { + e.printStackTrace(); + } + } + + private void compressCase(File baseDir, final String command) { + File baseDirArchive = new File(baseDir, INPUTS_ARCHIVE_FILE_NAME); + + FileUtils.deleteQuietly(baseDirArchive); + ArchiveUtils.tarGZ(baseDirArchive, baseDir.listFiles(new FilenameFilter() { + @Override + public boolean accept(File dir, String name) { + if (name.equals(INPUTS_ARCHIVE_FILE_NAME)) { + return false; + } else if (command.startsWith("mesh") && name.startsWith("processor")) { + return false; + } else { + try { + Double.parseDouble(name); + return false; + } catch (NumberFormatException e) { + return true; + } + } + + } + })); + } + + private void uploadCase(File baseDir) throws IOException, InterruptedException { + File baseDirArchive = new File(baseDir, INPUTS_ARCHIVE_FILE_NAME); + String workspace = PrefUtil.getString(PrefUtil.PW_WORKSPACE); + ParallelWorksClient client = ParallelWorksClient.getInstance(); + String workspaceID = client.getWorkspaceID(workspace); + client.uploadDataset(workspaceID, baseDirArchive); + // Wait for upload to finish + while (!client.getDatasetState().equals("ok")) { + Thread.sleep(1000); + } + } + +} diff --git a/src/eu/engys/parallelworks/actions/ParallelWorksInitialiseFields.java b/src/eu/engys/parallelworks/actions/ParallelWorksInitialiseFields.java new file mode 100644 index 0000000..4b2c927 --- /dev/null +++ b/src/eu/engys/parallelworks/actions/ParallelWorksInitialiseFields.java @@ -0,0 +1,124 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.parallelworks.actions; + +import static eu.engys.core.OpenFOAMEnvironment.getEnvironment; +import static eu.engys.core.controller.AbstractScriptFactory.INITIALISE_FIELDS_PARALLEL; +import static eu.engys.core.controller.AbstractScriptFactory.INITIALISE_FIELDS_SERIAL; + +import java.io.File; +import java.nio.file.Paths; +import java.util.Map; +import java.util.concurrent.ExecutorService; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import eu.engys.core.controller.Controller; +import eu.engys.core.controller.Controller.OpenMode; +import eu.engys.core.controller.KillCommandOS; +import eu.engys.core.controller.ScriptFactory; +import eu.engys.core.controller.actions.InitialiseFields; +import eu.engys.core.executor.Executor; +import eu.engys.core.executor.ExecutorHook; +import eu.engys.core.executor.ExecutorListener.ExecutorState; +import eu.engys.core.executor.ExecutorMonitor; +import eu.engys.core.executor.TerminalExecutorMonitor; +import eu.engys.core.project.Model; +import eu.engys.core.project.openFOAMProject; +import eu.engys.parallelworks.ParallelWorksCleaner; +import eu.engys.parallelworks.ParallelWorksClient; +import eu.engys.parallelworks.ParallelWorksData; +import eu.engys.parallelworks.ParallelWorksDownloader; +import eu.engys.parallelworks.ParallelWorksExecutor; +import eu.engys.parallelworks.ParallelWorksExecutorMonitor; +import eu.engys.parallelworks.ParallelWorksUploader; +import eu.engys.util.Util; +import eu.engys.util.Util.ScriptStyle; +import eu.engys.util.progress.ProgressMonitor; + +public class ParallelWorksInitialiseFields extends InitialiseFields { + + private static final Logger logger = LoggerFactory.getLogger(ParallelWorksInitialiseFields.class); + private ProgressMonitor monitor; + + public ParallelWorksInitialiseFields(Model model, Controller controller, ScriptFactory scriptFactory, ProgressMonitor monitor) { + super(model, controller, scriptFactory); + this.monitor = monitor; + } + + @Override + public void beforeExecute() { + super.beforeExecute(); + String command = model.getProject().isSerial() ? INITIALISE_FIELDS_SERIAL : INITIALISE_FIELDS_PARALLEL; + Map environment = getEnvironment(model, LOG_NAME); + + Util.setScriptStyle(ScriptStyle.LINUX); + scriptFactory.getInitialiseScript(model); + Util.initScriptStyle(); + + ParallelWorksUploader uploader = new ParallelWorksUploader(monitor); + uploader.uploadCloudResults(command, environment); + } + + @Override + public void executeClient() { + logger.debug("EXECUTE ON PARALLEL WORKS"); + File baseDir = model.getProject().getBaseDir(); + File logFile = Paths.get(baseDir.getAbsolutePath(), openFOAMProject.LOG, LOG_NAME).toFile(); + + ExecutorMonitor exeMonitor = new ExecutorMonitor(); + exeMonitor.addHook(ExecutorState.FINISH, new FinishHook()); + + ExecutorService service = Executor.newExecutor(ACTION_NAME); + + String command = model.getProject().isSerial() ? INITIALISE_FIELDS_SERIAL : INITIALISE_FIELDS_PARALLEL; + TerminalExecutorMonitor terminal = new ParallelWorksExecutorMonitor(controller.getTerminalManager(), logFile); + terminal.setStopCommand(new KillCommandOS(controller)); + + this.executor = new ParallelWorksExecutor(baseDir, command, logFile).description(ACTION_NAME).inFolder(baseDir).inTerminal(terminal).withMonitors(exeMonitor).inService(service).env(getEnvironment(model, LOG_NAME)); + executor.exec(); + } + + @Override + public void kill() { + super.kill(); + ParallelWorksClient.getInstance().cancelJob(); + ParallelWorksCleaner.cleanBaseDir(model.getProject().getBaseDir()); + } + + private class FinishHook implements ExecutorHook { + @Override + public void run(ExecutorMonitor m) { + if (ParallelWorksData.fromPrefences().isPullResults()) { + new ParallelWorksDownloader(model, monitor).downloadCloudResults(); + } else { + ParallelWorksCleaner.cleanBaseDir(model.getProject().getBaseDir()); + } + controller.reopenCase(OpenMode.CURRENT_SETTINGS); + } + } + +} diff --git a/src/eu/engys/parallelworks/actions/ParallelWorksRunCase.java b/src/eu/engys/parallelworks/actions/ParallelWorksRunCase.java new file mode 100644 index 0000000..5f98e9e --- /dev/null +++ b/src/eu/engys/parallelworks/actions/ParallelWorksRunCase.java @@ -0,0 +1,155 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.parallelworks.actions; + +import static eu.engys.core.OpenFOAMEnvironment.getEnvironment; +import static eu.engys.core.controller.AbstractScriptFactory.SOLVER_PARALLEL; +import static eu.engys.core.controller.AbstractScriptFactory.SOLVER_SERIAL; + +import java.io.File; +import java.nio.file.Paths; +import java.util.Map; +import java.util.concurrent.ExecutorService; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import eu.engys.core.controller.Command; +import eu.engys.core.controller.Controller; +import eu.engys.core.controller.ScriptFactory; +import eu.engys.core.controller.StopOrKillCommandOS; +import eu.engys.core.controller.actions.RunCase; +import eu.engys.core.executor.Executor; +import eu.engys.core.executor.ExecutorHook; +import eu.engys.core.executor.ExecutorListener.ExecutorState; +import eu.engys.core.executor.ExecutorMonitor; +import eu.engys.core.executor.TerminalExecutorMonitor; +import eu.engys.core.project.Model; +import eu.engys.core.project.SolverState; +import eu.engys.core.project.openFOAMProject; +import eu.engys.core.project.state.ServerState; +import eu.engys.parallelworks.ParallelWorksCleaner; +import eu.engys.parallelworks.ParallelWorksClient; +import eu.engys.parallelworks.ParallelWorksData; +import eu.engys.parallelworks.ParallelWorksDownloader; +import eu.engys.parallelworks.ParallelWorksExecutor; +import eu.engys.parallelworks.ParallelWorksExecutorMonitor; +import eu.engys.parallelworks.ParallelWorksUploader; +import eu.engys.util.Util; +import eu.engys.util.Util.ScriptStyle; +import eu.engys.util.progress.ProgressMonitor; + +public class ParallelWorksRunCase extends RunCase { + + private static final Logger logger = LoggerFactory.getLogger(ParallelWorksRunCase.class); + private ProgressMonitor monitor; + + public ParallelWorksRunCase(Model model, Controller controller, ScriptFactory scriptFactory, ProgressMonitor monitor) { + super(model, controller, scriptFactory); + this.monitor = monitor; + } + + @Override + public void beforeExecute() { + super.beforeExecute(); + String command = model.getProject().isSerial() ? SOLVER_SERIAL : SOLVER_PARALLEL; + Map environment = getEnvironment(model, model.getSolverModel().getLogFile()); + + Util.setScriptStyle(ScriptStyle.LINUX); + scriptFactory.getSolverScript(model); + Util.initScriptStyle(); + + ParallelWorksUploader uploader = new ParallelWorksUploader(monitor); + uploader.uploadCloudResults(command, environment); + } + + @Override + public void executeClient() { + logger.debug("EXECUTE ON PARALLEL WORKS"); + File baseDir = model.getProject().getBaseDir(); + File logFile = Paths.get(baseDir.getAbsolutePath(), openFOAMProject.LOG, model.getSolverModel().getLogFile()).toFile(); + + ExecutorMonitor exeMonitor = new ExecutorMonitor(); + exeMonitor.addHook(ExecutorState.START, new StartHook()); + exeMonitor.addHook(ExecutorState.RUNNING, new RunningHook()); + exeMonitor.addHook(ExecutorState.ERROR, new ErrorHook()); + exeMonitor.addHook(ExecutorState.FINISH, new FinishHook()); + + ExecutorService service = Executor.newExecutor(ACTION_NAME); + + String command = model.getProject().isSerial() ? SOLVER_SERIAL : SOLVER_PARALLEL; + TerminalExecutorMonitor terminal = new ParallelWorksExecutorMonitor(controller.getTerminalManager(), logFile); + terminal.setStopCommand(new StopOrKillCommandOS(controller)); + + this.executor = new ParallelWorksExecutor(baseDir, command, logFile).description(ACTION_NAME).inFolder(baseDir).inTerminal(terminal).withMonitors(exeMonitor).inService(service).env(getEnvironment(model, model.getSolverModel().getLogFile())); + executor.exec(); + } + + @Override + public void kill() { + super.kill(); + ParallelWorksClient.getInstance().cancelJob(); + ParallelWorksCleaner.cleanBaseDir(model.getProject().getBaseDir()); + } + + @Override + public void stop() throws Exception { + new ParallelWorksStopper(model, executor).stop(); + } + + private class StartHook implements ExecutorHook { + @Override + public void run(ExecutorMonitor m) { + model.getSolverModel().setServerState(new ServerState(Command.RUN_CASE, SolverState.STARTED)); + } + } + + private class RunningHook implements ExecutorHook { + @Override + public void run(ExecutorMonitor m) { + model.getSolverModel().setServerState(new ServerState(Command.RUN_CASE, SolverState.RUNNING)); + } + } + + private class FinishHook implements ExecutorHook { + @Override + public void run(ExecutorMonitor m) { + model.getSolverModel().setServerState(new ServerState(Command.RUN_CASE, SolverState.FINISHED)); + if (ParallelWorksData.fromPrefences().isPullResults()) { + new ParallelWorksDownloader(model, monitor).downloadCloudResults(); + } else { + ParallelWorksCleaner.cleanBaseDir(model.getProject().getBaseDir()); + } + } + } + + private class ErrorHook implements ExecutorHook { + @Override + public void run(ExecutorMonitor m) { + model.getSolverModel().setServerState(new ServerState(Command.RUN_CASE, SolverState.ERROR)); + } + } + +} diff --git a/src/eu/engys/parallelworks/actions/ParallelWorksRunMesh.java b/src/eu/engys/parallelworks/actions/ParallelWorksRunMesh.java new file mode 100644 index 0000000..4b75fc9 --- /dev/null +++ b/src/eu/engys/parallelworks/actions/ParallelWorksRunMesh.java @@ -0,0 +1,124 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.parallelworks.actions; + +import static eu.engys.core.OpenFOAMEnvironment.getEnvironment; +import static eu.engys.core.controller.AbstractScriptFactory.MESH_PARALLEL; +import static eu.engys.core.controller.AbstractScriptFactory.MESH_SERIAL; + +import java.io.File; +import java.nio.file.Paths; +import java.util.Map; +import java.util.concurrent.ExecutorService; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import eu.engys.core.controller.Controller; +import eu.engys.core.controller.KillCommandOS; +import eu.engys.core.controller.ScriptFactory; +import eu.engys.core.controller.actions.RunMesh; +import eu.engys.core.executor.Executor; +import eu.engys.core.executor.ExecutorHook; +import eu.engys.core.executor.ExecutorListener.ExecutorState; +import eu.engys.core.executor.ExecutorMonitor; +import eu.engys.core.executor.TerminalExecutorMonitor; +import eu.engys.core.project.Model; +import eu.engys.core.project.openFOAMProject; +import eu.engys.parallelworks.ParallelWorksCleaner; +import eu.engys.parallelworks.ParallelWorksClient; +import eu.engys.parallelworks.ParallelWorksData; +import eu.engys.parallelworks.ParallelWorksDownloader; +import eu.engys.parallelworks.ParallelWorksExecutor; +import eu.engys.parallelworks.ParallelWorksExecutorMonitor; +import eu.engys.parallelworks.ParallelWorksUploader; +import eu.engys.util.Util; +import eu.engys.util.Util.ScriptStyle; +import eu.engys.util.progress.ProgressMonitor; + +public class ParallelWorksRunMesh extends RunMesh { + + private static final Logger logger = LoggerFactory.getLogger(ParallelWorksRunMesh.class); + private ProgressMonitor monitor; + + public ParallelWorksRunMesh(Model model, Controller controller, ScriptFactory scriptFactory, ProgressMonitor monitor) { + super(model, controller, scriptFactory); + this.monitor = monitor; + } + + @Override + public void beforeExecute() { + super.beforeExecute(); + + String command = model.getProject().isSerial() ? MESH_SERIAL : MESH_PARALLEL; + Map environment = getEnvironment(model, LOG_NAME); + + Util.setScriptStyle(ScriptStyle.LINUX); + scriptFactory.getMeshScript(model); + Util.initScriptStyle(); + + ParallelWorksUploader uploader = new ParallelWorksUploader(monitor); + uploader.uploadCloudResults(command, environment); + } + + @Override + public void executeClient() { + logger.debug("EXECUTE ON PARALLEL WORKS"); + File baseDir = model.getProject().getBaseDir(); + File logFile = Paths.get(baseDir.getAbsolutePath(), openFOAMProject.LOG, LOG_NAME).toFile(); + + ExecutorMonitor exeMonitor = new ExecutorMonitor(); + exeMonitor.addHook(ExecutorState.FINISH, new FinishHook()); + + ExecutorService service = Executor.newExecutor(ACTION_NAME); + + String command = model.getProject().isSerial() ? MESH_SERIAL : MESH_PARALLEL; + TerminalExecutorMonitor terminal = new ParallelWorksExecutorMonitor(controller.getTerminalManager(), logFile); + terminal.setStopCommand(new KillCommandOS(controller)); + + this.executor = new ParallelWorksExecutor(baseDir, command, logFile).description(ACTION_NAME).inFolder(baseDir).inTerminal(terminal).withMonitors(exeMonitor).inService(service).env(getEnvironment(model, LOG_NAME)); + executor.exec(); + } + + @Override + public void kill() { + super.kill(); + ParallelWorksClient.getInstance().cancelJob(); + ParallelWorksCleaner.cleanBaseDir(model.getProject().getBaseDir()); + } + + private class FinishHook implements ExecutorHook { + @Override + public void run(ExecutorMonitor m) { + if (ParallelWorksData.fromPrefences().isPullResults()) { + new ParallelWorksDownloader(model, monitor).downloadCloudResults(); + controller.setupCase(); + } else { + ParallelWorksCleaner.cleanBaseDir(model.getProject().getBaseDir()); + } + } + } + +} diff --git a/src/eu/engys/parallelworks/actions/ParallelWorksStopper.java b/src/eu/engys/parallelworks/actions/ParallelWorksStopper.java new file mode 100644 index 0000000..96207f8 --- /dev/null +++ b/src/eu/engys/parallelworks/actions/ParallelWorksStopper.java @@ -0,0 +1,53 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.parallelworks.actions; + +import java.io.File; +import java.io.IOException; + +import eu.engys.core.controller.actions.Stopper; +import eu.engys.core.executor.Executor; +import eu.engys.core.project.Model; +import eu.engys.core.project.system.ControlDict; +import eu.engys.parallelworks.ParallelWorksClient; + +public class ParallelWorksStopper extends Stopper { + + public ParallelWorksStopper(Model model, Executor executor) { + super(model, executor); + } + + @Override + protected void waitForExecutorToStop() throws Exception { + uploadControlDict(); + super.waitForExecutorToStop(); + } + + private void uploadControlDict() throws IOException { + File controlDict = model.getProject().getSystemFolder().getFileManager().getFile(ControlDict.CONTROL_DICT); + ParallelWorksClient.getInstance().uploadFileToJob(controlDict); + } + +} diff --git a/src/eu/engys/parallelworks/json/Dataset.java b/src/eu/engys/parallelworks/json/Dataset.java new file mode 100644 index 0000000..757f1be --- /dev/null +++ b/src/eu/engys/parallelworks/json/Dataset.java @@ -0,0 +1,53 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.parallelworks.json; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; + +@JsonIgnoreProperties(ignoreUnknown = true) +public class Dataset { + + private String state; + + @JsonProperty("download_url") + private String downloadUrl; + + public String getState() { + return state; + } + + public void setState(String state) { + this.state = state; + } + + public String getDownloadUrl() { + return downloadUrl; + } + + public void setDownloadUrl(String downloadUrl) { + this.downloadUrl = downloadUrl; + } +} diff --git a/src/eu/engys/parallelworks/json/Histories.java b/src/eu/engys/parallelworks/json/Histories.java new file mode 100644 index 0000000..5443b44 --- /dev/null +++ b/src/eu/engys/parallelworks/json/Histories.java @@ -0,0 +1,31 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.parallelworks.json; + +import java.util.ArrayList; + +public class Histories extends ArrayList { + +} diff --git a/src/eu/engys/parallelworks/json/HistoryEntry.java b/src/eu/engys/parallelworks/json/HistoryEntry.java new file mode 100644 index 0000000..ed98e8d --- /dev/null +++ b/src/eu/engys/parallelworks/json/HistoryEntry.java @@ -0,0 +1,139 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.parallelworks.json; + +import java.util.List; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/* + * { + * "name": "helyxos_workspace", + * "tags": [], + * "deleted": false, + * "purged": false, + * "annotation": null, + * "url": "/api/histories/fab535a3ae44be6d", + * "published": false, + * "model_class": "History", + * "id": "fab535a3ae44be6d"} + */ +public class HistoryEntry { + private String name; + + private List tags; + + private boolean deleted; + + private boolean purged; + + private String annotation; + + private String url; + + private boolean published; + + @JsonProperty("model_class") + private String modelClass; + + private String id; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public List getTags() { + return tags; + } + + public void setTags(List tags) { + this.tags = tags; + } + + public boolean getDeleted() { + return deleted; + } + + public void setDeleted(boolean deleted) { + this.deleted = deleted; + } + + public boolean getPurged() { + return purged; + } + + public void setPurged(boolean purged) { + this.purged = purged; + } + + public String getAnnotation() { + return annotation; + } + + public void setAnnotation(String annotation) { + this.annotation = annotation; + } + + public String getUrl() { + return url; + } + + public void setUrl(String url) { + this.url = url; + } + + public boolean getPublished() { + return published; + } + + public void setPublished(boolean published) { + this.published = published; + } + + public String getModelClass() { + return modelClass; + } + + public void setModelClass(String modelClass) { + this.modelClass = modelClass; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + @Override + public String toString() { + return "HistoryEntry [name=" + name + ", tags=" + tags + ", deleted=" + deleted + ", purged=" + purged + ", annotation=" + annotation + ", url=" + url + ", published=" + published + ", modelClass=" + modelClass + ", id=" + id + "]"; + } +} diff --git a/src/eu/engys/parallelworks/json/JobId.java b/src/eu/engys/parallelworks/json/JobId.java new file mode 100644 index 0000000..8ee591e --- /dev/null +++ b/src/eu/engys/parallelworks/json/JobId.java @@ -0,0 +1,55 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.parallelworks.json; + +public class JobId { + private String id, decodedId; + + public JobId(String id, String decodedId) { + this.id = id; + this.decodedId = decodedId; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getDecodedId() { + return decodedId; + } + + public void setDecodedId(String decodedId) { + this.decodedId = decodedId; + } + + @Override + public String toString() { + return "JobId [id=" + id + ", decodedId=" + decodedId + "]"; + } +} diff --git a/src/eu/engys/parallelworks/json/JobInfo.java b/src/eu/engys/parallelworks/json/JobInfo.java new file mode 100644 index 0000000..ee093eb --- /dev/null +++ b/src/eu/engys/parallelworks/json/JobInfo.java @@ -0,0 +1,64 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.parallelworks.json; + +import java.util.Map; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; + +@JsonIgnoreProperties(ignoreUnknown = true) +public class JobInfo { + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class Output { + private String id; + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + } + + private Map outputs; + + public Map getOutputs() { + return outputs; + } + + public void setOutputs(Map outputs) { + this.outputs = outputs; + } + + public Output getOutput(String name) { + Output o = outputs.get(name); + if (o == null) { + throw new IllegalArgumentException("No such output: " + name); + } + return o; + } +} diff --git a/src/eu/engys/parallelworks/json/JobState.java b/src/eu/engys/parallelworks/json/JobState.java new file mode 100644 index 0000000..4148725 --- /dev/null +++ b/src/eu/engys/parallelworks/json/JobState.java @@ -0,0 +1,58 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.parallelworks.json; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; + +@JsonIgnoreProperties(ignoreUnknown = true) +public class JobState { + private String state; + + private String status; + + public JobState() { + } + + public JobState(String state, String status) { + this.state = state; + this.status = status; + } + + public String getState() { + return state; + } + + public void setState(String state) { + this.state = state; + } + + public String getStatus() { + return status; + } + + public void setStatus(String status) { + this.status = status; + } +} diff --git a/src/eu/engys/parallelworks/json/Resource.java b/src/eu/engys/parallelworks/json/Resource.java new file mode 100644 index 0000000..7ce5ff9 --- /dev/null +++ b/src/eu/engys/parallelworks/json/Resource.java @@ -0,0 +1,59 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.parallelworks.json; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; + +@JsonIgnoreProperties(ignoreUnknown = true) +public class Resource { + + private String name; + private String status; + + public Resource() { + } + + public Resource(String name, String status) { + this.name = name; + this.status = status; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getStatus() { + return status; + } + + public void setStatus(String status) { + this.status = status; + } + +} diff --git a/src/eu/engys/parallelworks/json/Resources.java b/src/eu/engys/parallelworks/json/Resources.java new file mode 100644 index 0000000..5022613 --- /dev/null +++ b/src/eu/engys/parallelworks/json/Resources.java @@ -0,0 +1,31 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.parallelworks.json; + +import java.util.ArrayList; + +public class Resources extends ArrayList { + +} diff --git a/src/eu/engys/parallelworks/json/StartJobInputs.java b/src/eu/engys/parallelworks/json/StartJobInputs.java new file mode 100644 index 0000000..eaa60ce --- /dev/null +++ b/src/eu/engys/parallelworks/json/StartJobInputs.java @@ -0,0 +1,110 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.parallelworks.json; + +import java.util.Collections; +import java.util.List; + +import com.fasterxml.jackson.annotation.JsonProperty; + +public class StartJobInputs { + + public static class Value { + private String src; + private String id; + + public Value() { + } + + public Value(String did) { + this.src = "hda"; + this.id = did; + } + + public String getSrc() { + return src; + } + + public void setSrc(String src) { + this.src = src; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + } + + public static class Case { + private List values; + + public Case() { + } + + public Case(String did) { + values = Collections.singletonList(new Value(did)); + } + + public List getValues() { + return values; + } + + public void setValues(List values) { + this.values = values; + } + } + + @JsonProperty("case") + private Case _case; + + private String command; + + public StartJobInputs() { + } + + public StartJobInputs(String did, String helyxosCommand) { + this._case = new Case(did); + this.command = helyxosCommand; + } + + public Case getCase() { + return _case; + } + + public void setCase(Case _case) { + this._case = _case; + } + + public String getCommand() { + return command; + } + + public void setCommand(String command) { + this.command = command; + } +} diff --git a/src/eu/engys/parallelworks/json/StartJobResponse.java b/src/eu/engys/parallelworks/json/StartJobResponse.java new file mode 100644 index 0000000..c855af1 --- /dev/null +++ b/src/eu/engys/parallelworks/json/StartJobResponse.java @@ -0,0 +1,68 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.parallelworks.json; + +import java.util.List; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; + +@JsonIgnoreProperties(ignoreUnknown = true) +public class StartJobResponse { + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class Job { + private String id; + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + } + + @JsonProperty("decoded_job_id") + private String decodedJobId; + + private List jobs; + + public String getDecodedJobId() { + return decodedJobId; + } + + public void setDecodedJobId(String decodedJobId) { + this.decodedJobId = decodedJobId; + } + + public List getJobs() { + return jobs; + } + + public void setJobs(List jobs) { + this.jobs = jobs; + } +} diff --git a/src/eu/engys/parallelworks/json/UploadDatasetResponse.java b/src/eu/engys/parallelworks/json/UploadDatasetResponse.java new file mode 100644 index 0000000..511502f --- /dev/null +++ b/src/eu/engys/parallelworks/json/UploadDatasetResponse.java @@ -0,0 +1,58 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.parallelworks.json; + +import java.util.List; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; + +@JsonIgnoreProperties(ignoreUnknown = true) +public class UploadDatasetResponse { + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class Output { + private String id; + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + } + + @JsonProperty("outputs") + private List outputs; + + public List getOutputs() { + return outputs; + } + + public void setOutputs(List outputs) { + this.outputs = outputs; + } +} diff --git a/src/eu/engys/resources/application.properties b/src/eu/engys/resources/application.properties index 3a0606a..b7ff47e 100644 --- a/src/eu/engys/resources/application.properties +++ b/src/eu/engys/resources/application.properties @@ -27,6 +27,8 @@ max.log.rows 100000 # PATCHES hide.empty.patches true +hide.processor.patches true +hide.processor.cyclic.patches true # DEFAULT HOST FILE default.hostfile.none false diff --git a/src/eu/engys/resources/bundle.properties b/src/eu/engys/resources/bundle.properties index dd7a143..8549b52 100644 --- a/src/eu/engys/resources/bundle.properties +++ b/src/eu/engys/resources/bundle.properties @@ -28,11 +28,11 @@ mesh.check.edit.icon eu/engys/resources/images/pencil16.png mesh.batch.label Virtualise mesh.batch.tooltip Use Geometry Objects To Simulate The Mesh -mesh.batch.icon eu/engys/resources/images/lightning.png +mesh.batch.icon eu/engys/resources/images/geometry2mesh16.png mesh.options.label Options mesh.options.tooltip Open Advanced Options Dialog -mesh.options.icon eu/engys/resources/images/cog16.png +mesh.options.icon eu/engys/resources/images/settings16.png mesh.import.label Import mesh.import.tooltip Import Mesh From 3rd Party @@ -42,13 +42,50 @@ mesh.export.label Export mesh.export.tooltip Export Mesh For 3rd Party mesh.export.icon eu/engys/resources/images/export16.png -mesh.operations.label Operate -mesh.operations.tooltip Operate on 3D geometry items -mesh.operations.icon eu/engys/resources/images/toolbox16.png +mesh.stretch.label Stretch +mesh.stretch.tooltip Stretch an existing hex-based mesh in order to create cells with aspect ratios larger than 1, thus reducing the number of elements in the final mesh +mesh.stretch.icon eu/engys/resources/images/stretch16.png mesh.merge.label Merge +mesh.merge.icon eu/engys/resources/images/merge16.png mesh.merge.tooltip Merge Mesh From 3rd Party +import.openfoam.label OpenFOAM +import.openfoam.icon eu/engys/resources/images/openFoam16.png +import.openfoam.tooltip Import From OpenFOAM + +import.pointwise.label Pointwise +import.pointwise.icon eu/engys/resources/images/gridgen16.png +import.pointwise.tooltip Import From PointWise + +import.fluent.label Fluent +import.fluent.icon eu/engys/resources/images/fluent16.png +import.fluent.tooltip Import From Fluent + +merge.openfoam.label OpenFOAM +merge.openfoam.icon eu/engys/resources/images/openFoam16.png +merge.openfoam.tooltip Merge From OpenFOAM + +merge.pointwise.label PointWise +merge.pointwise.icon eu/engys/resources/images/gridgen16.png +merge.pointwise.tooltip Merge From PointWise + +merge.fluent.label Fluent +merge.fluent.icon eu/engys/resources/images/fluent16.png +merge.fluent.tooltip Merge From Fluent + +export.fluent.label Fluent +export.fluent.icon eu/engys/resources/images/fluent16.png +export.fluent.tooltip Export To Fluent + +export.star.label STAR-CD +export.star.icon eu/engys/resources/images/starcd16.png +export.star.tooltip Export To STAR-CD + +export.fieldview.label FieldView +export.fieldview.icon eu/engys/resources/images/fieldview16.png +export.fieldview.tooltip Export To FieldView + mesh.stl.label mesh.stl.icon eu/engys/resources/images/stl24.png mesh.stl.tooltip STL @@ -87,8 +124,9 @@ best.practices.all.label Apply Defaults best.practices.all.icon eu/engys/resources/images/tick16.png best.practices.all.tooltip Setup Case -casesetup.decompose.label Decompose -casesetup.decompose.tooltip Decompose Case +decompose.label Decompose +decompose.icon eu/engys/resources/images/decompose16.png +decompose.tooltip Decompose Case calculate.frontal.area.label Calculate calculate.frontal.area.tooltip Calculate frontal area from available vehicle geometry @@ -102,14 +140,14 @@ parmap.fields.icon eu/engys/resources/images/parMap16.png parmap.fields.label Map Fields parmap.fields.tooltip Map Fields From External Case +delete.fields.icon eu/engys/resources/images/deleteFields16.png +delete.fields.label Delete Fields +delete.fields.tooltip Delete all fields and all time folders > 0 + initialise.fields.edit.icon eu/engys/resources/images/pencil16.png initialise.fields.edit.label Edit Script initialise.fields.edit.tooltip Edit Script -extrude.to.region.icon eu/engys/resources/images/extrude16.png -extrude.to.region.label Extrude To Region -extrude.to.region.tooltip Extrude To Region - # # RESULTS # @@ -121,9 +159,9 @@ results.export.edit.label Edit Script results.export.edit.icon eu/engys/resources/images/pencil16.png results.export.edit.tooltip Edit Script -results.export.edit.python.label Edit Results -results.export.edit.python.icon eu/engys/resources/images/pencil16.png -results.export.edit.python.tooltip Edit Results +results.report.edit.label Edit Script +results.report.edit.icon eu/engys/resources/images/pencil16.png +results.report.edit.tooltip Edit Script results.show.label Show Report results.show.icon eu/engys/resources/images/showResults16.png @@ -200,6 +238,8 @@ queue.edit.tooltip Properties # # APPLICATION # +application.icon eu/engys/resources/images/application16.png + application.create.label New application.create.tooltip Create New Case application.create.icon eu/engys/resources/images/new16.png @@ -214,75 +254,120 @@ application.saveAs.icon eu/engys/resources/images/saveAs16.png application.open.label Open application.open.tooltip Open Case -application.open.icon eu/engys/resources/images/open16.png +application.open.icon eu/engys/resources/images/folder16.png application.recent.label application.recent.tooltip Open Recent Case -application.recent.icon eu/engys/resources/images/arrow_down16.png +application.recent.icon eu/engys/resources/images/recents16.png application.exit.label Exit application.exit.tooltip Exit Application application.exit.icon eu/engys/resources/images/exit16.png +application.exit.big.icon eu/engys/resources/images/exit32.png + +application.parameters.manager.label Parameters +application.parameters.manager.tooltip Parameters Manager +application.parameters.manager.icon eu/engys/resources/images/folderParameters16.png + +application.open.terminal.label Terminal +application.open.terminal.tooltip Open Terminal in case folder +application.open.terminal.icon eu/engys/resources/images/terminal16.png + +application.browse.case.label Browse +application.browse.case.tooltip Browse Case Folder +application.browse.case.icon eu/engys/resources/images/browseFolder16.png + +application.connection.window.label Run Mode +application.connection.window.icon eu/engys/resources/images/runMode16.png +application.connection.window.tooltip Edit Connection Parameters + +application.support.window.label Support +application.support.window.icon eu/engys/resources/images/info16.png +application.support.window.tooltip Obtain support for HELYX-OS # # 3D # +3d.zoom.in.label 3d.zoom.in.tooltip Zoom In 3d.zoom.in.icon eu/engys/resources/images/zoomIn16.png +3d.zoom.out.label 3d.zoom.out.tooltip Zoom Out 3d.zoom.out.icon eu/engys/resources/images/zoomOut16.png +3d.zoom.reset.label 3d.zoom.reset.tooltip Reset Zoom 3d.zoom.reset.icon eu/engys/resources/images/zoomReset16.png +3d.zoom.tobox.label 3d.zoom.tobox.tooltip Zoom To Area 3d.zoom.tobox.icon eu/engys/resources/images/zoomToArea16.png +3d.axis.xpos.label 3d.axis.xpos.tooltip +X 3d.axis.xpos.icon eu/engys/resources/images/XPos16.png +3d.axis.xneg.label 3d.axis.xneg.tooltip -X 3d.axis.xneg.icon eu/engys/resources/images/XNeg16.png +3d.axis.ypos.label 3d.axis.ypos.tooltip +Y 3d.axis.ypos.icon eu/engys/resources/images/YPos16.png +3d.axis.yneg.label 3d.axis.yneg.tooltip -Y 3d.axis.yneg.icon eu/engys/resources/images/YNeg16.png +3d.axis.zpos.label 3d.axis.zpos.tooltip +Z 3d.axis.zpos.icon eu/engys/resources/images/ZPos16.png +3d.axis.zneg.label 3d.axis.zneg.tooltip -Z 3d.axis.zneg.icon eu/engys/resources/images/ZNeg16.png +3d.view.surface.label 3d.view.surface.tooltip Surface 3d.view.surface.icon eu/engys/resources/images/shape_surface16.png +3d.view.edges.label 3d.view.edges.tooltip Surface With Edges 3d.view.edges.icon eu/engys/resources/images/shape_surface_edges16.png +3d.view.profile.label 3d.view.profile.tooltip Boundary Edges 3d.view.profile.icon eu/engys/resources/images/shape_boundary_edges16.png +3d.view.wireframe.label 3d.view.wireframe.tooltip Wireframe 3d.view.wireframe.icon eu/engys/resources/images/shape_wireframe16.png +3d.view.outline.label 3d.view.outline.tooltip Outline 3d.view.outline.icon eu/engys/resources/images/shape_outline16.png +3d.load.mesh.label 3d.load.mesh.tooltip Load External Mesh 3d.load.mesh.icon eu/engys/resources/images/externalMesh16.png +3d.view.projections.perspective.label 3d.view.projections.perspective.tooltip Parallel Projection 3d.view.projections.perspective.icon eu/engys/resources/images/transform_perspective16.png + +3d.view.projections.parallel.label 3d.view.projections.parallel.tooltip Perspective Projection 3d.view.projections.parallel.icon eu/engys/resources/images/transform_parallel16.png # # WIDGETS # + + +3d.widget.contour.tooltip Contour Widget +3d.widget.contour.icon eu/engys/resources/images/contourWidget16.png + 3d.widget.plane.tooltip Plane Widget 3d.widget.plane.icon eu/engys/resources/images/planeWidget16.png @@ -292,19 +377,19 @@ application.exit.icon eu/engys/resources/images/exit16.png 3d.widget.times.refresh.tooltip Reload Time Steps 3d.widget.times.tooltip Time Steps -3d.widget.times.prev.icon eu/engys/resources/images/prev_grey16.png +3d.widget.times.prev.icon eu/engys/resources/images/fieldPrev16.png 3d.widget.times.prev.tooltip Display PREVIOUS Time -3d.widget.times.next.icon eu/engys/resources/images/next_grey16.png +3d.widget.times.next.icon eu/engys/resources/images/fieldNext16.png 3d.widget.times.next.tooltip Display NEXT Time -3d.widget.times.first.icon eu/engys/resources/images/first_grey16.png +3d.widget.times.first.icon eu/engys/resources/images/fieldFirst16.png 3d.widget.times.first.tooltip Display FIRST Time -3d.widget.times.last.icon eu/engys/resources/images/last_grey16.png +3d.widget.times.last.icon eu/engys/resources/images/fieldLast16.png 3d.widget.times.last.tooltip Display LAST Time -3d.widget.times.refresh.icon eu/engys/resources/images/refresh_grey16.png +3d.widget.times.refresh.icon eu/engys/resources/images/fieldRefresh16.png 3d.widget.times.refresh.tooltip Rescan Times 3d.widget.export.icon eu/engys/resources/images/exportImage16.png @@ -316,6 +401,15 @@ application.exit.icon eu/engys/resources/images/exit16.png 3d.widget.editscalarbar.icon eu/engys/resources/images/scalarbarEdit16.png 3d.widget.editscalarbar.tooltip Edit Scalar Bar +3d.widget.cor.icon eu/engys/resources/images/cor16.png +3d.widget.cor.tooltip Show/Hide the Center of Rotation + +3d.widget.editcor.icon eu/engys/resources/images/corEdit16.png +3d.widget.editcor.tooltip Edit/Pick a new Center of Rotation + +3d.widget.location.icon eu/engys/resources/images/location16.png +3d.widget.location.tooltip Locate a Point in the 3D space + 3d.widget.fields.tooltip Fields 3d.widget.fields.point.icon eu/engys/resources/images/pointField16.png 3d.widget.fields.cell.icon eu/engys/resources/images/cellField16.png @@ -323,25 +417,21 @@ application.exit.icon eu/engys/resources/images/exit16.png 3d.widget.feature.tooltip Split Surface Widget 3d.widget.feature.icon eu/engys/resources/images/table_select_big.png -scalarbar.rainbow.icon eu/engys/resources/images/scalarbar/rainbow16.png -scalarbar.rainbow.inverted.icon eu/engys/resources/images/scalarbar/rainbowInverted16.png +scalarbar.bluetored.hsv.icon eu/engys/resources/images/scalarbar/blueToRedHSV16.png +scalarbar.bluetored.rgb.icon eu/engys/resources/images/scalarbar/blueToRedRGB16.png +scalarbar.bluetored.div.icon eu/engys/resources/images/scalarbar/blueToRedDIV16.png +scalarbar.bluetored.jet.icon eu/engys/resources/images/scalarbar/blueToRedJET16.png +scalarbar.bluetored.des.icon eu/engys/resources/images/scalarbar/blueToRedDES16.png +scalarbar.bluetored.coldhot.icon eu/engys/resources/images/scalarbar/blueToRedCOLDHOT16.png -scalarbar.bluetored.hsv.icon eu/engys/resources/images/scalarbar/HSVBlueToRed16.png -scalarbar.redtoblue.hsv.icon eu/engys/resources/images/scalarbar/HSVRedToBlue16.png -scalarbar.bluetored.rgb.icon eu/engys/resources/images/scalarbar/RGBBlueToRed16.png -scalarbar.redtoblue.rgb.icon eu/engys/resources/images/scalarbar/RGBRedToBlue16.png -scalarbar.bluetored.div.icon eu/engys/resources/images/scalarbar/DIVBlueToRed16.png -scalarbar.redtoblue.div.icon eu/engys/resources/images/scalarbar/DIVRedToBlue16.png - -scalarbar.bluetoyellow.hsv.icon eu/engys/resources/images/scalarbar/HSVBlueToYellow16.png -scalarbar.yellowtoblue.hsv.icon eu/engys/resources/images/scalarbar/HSVYellowToBlue16.png -scalarbar.bluetoyellow.rgb.icon eu/engys/resources/images/scalarbar/RGBBlueToYellow16.png -scalarbar.yellowtoblue.rgb.icon eu/engys/resources/images/scalarbar/RGBYellowToBlue16.png -scalarbar.bluetoyellow.div.icon eu/engys/resources/images/scalarbar/DIVBlueToYellow16.png -scalarbar.yellowtoblue.div.icon eu/engys/resources/images/scalarbar/DIVYellowToBlue16.png +scalarbar.bluetoyellow.hsv.icon eu/engys/resources/images/scalarbar/blueToYellowHSV16.png +scalarbar.bluetoyellow.rgb.icon eu/engys/resources/images/scalarbar/blueToYellowRGB16.png +scalarbar.bluetoyellow.div.icon eu/engys/resources/images/scalarbar/blueToYellowDIV16.png scalarbar.blacktowhite.icon eu/engys/resources/images/scalarbar/blackToWhite16.png -scalarbar.whitetoblack.icon eu/engys/resources/images/scalarbar/whiteToBlack16.png +scalarbar.blackbluewhite.icon eu/engys/resources/images/scalarbar/blackToBlueToWhite16.png +scalarbar.blackorangewhite.icon eu/engys/resources/images/scalarbar/blackToOrangeToWhite16.png +scalarbar.blackbodyradiation.icon eu/engys/resources/images/scalarbar/blackBodyRadiation16.png scalarbar.lock.opened.icon eu/engys/resources/images/lockOpen16.png scalarbar.lock.closed.icon eu/engys/resources/images/lockClose16.png @@ -349,31 +439,91 @@ scalarbar.lock.closed.icon eu/engys/resources/images/lockClose16.png slider.locked.icon eu/engys/resources/images/sliderLock16.png slider.unlocked.icon eu/engys/resources/images/sliderUnlock16.png +clipper.clip.icon eu/engys/resources/images/clip24.png +clipper.slice.icon eu/engys/resources/images/slice24.png +clipper.crinkle.icon eu/engys/resources/images/crinkle24.png +contour.icon eu/engys/resources/images/contour24.png + +pick.point.icon eu/engys/resources/images/pickPoint16.png +pick.surface.icon eu/engys/resources/images/pickSurface16.png + # # CASE MANAGER # +case.manager.create.label New +case.manager.create.tooltip Create New Study +case.manager.create.icon eu/engys/resources/images/new16.png + +case.manager.save.label Save +case.manager.save.tooltip Save Study +case.manager.save.icon eu/engys/resources/images/save16.png + +case.manager.saveAs.label Save As... +case.manager.saveAs.tooltip Save Study With Different Name +case.manager.saveAs.icon eu/engys/resources/images/saveAs16.png + +case.manager.open.label Open +case.manager.open.tooltip Open Study +case.manager.open.icon eu/engys/resources/images/folder16.png + +case.manager.recent.label +case.manager.recent.tooltip Open Recent Study +case.manager.recent.icon eu/engys/resources/images/recents16.png + +case.manager.exit.label Exit +case.manager.exit.icon eu/engys/resources/images/exit16.png +case.manager.exit.big.icon eu/engys/resources/images/exit32.png +case.manager.exit.tooltip Exit Application + +case.manager.open.terminal.label Terminal +case.manager.open.terminal.tooltip Open Terminal in study folder +case.manager.open.terminal.icon eu/engys/resources/images/terminal16.png + +case.manager.browse.study.label Browse +case.manager.browse.study.tooltip Browse Study Folder +case.manager.browse.study.icon eu/engys/resources/images/browseFolder16.png + +case.manager.connection.window.label Run Mode +case.manager.connection.window.icon eu/engys/resources/images/runMode16.png +case.manager.connection.window.tooltip Edit Connection Parameters + case.manager.start.label Start -case.manager.start.icon eu/engys/resources/images/file16.png - +case.manager.start.tooltip Start the execution of the scheduled cases +case.manager.start.icon eu/engys/resources/images/start16.png + case.manager.stop.label Stop -case.manager.stop.icon eu/engys/resources/images/file16.png - +case.manager.stop.tooltip Stop running cases and interrupt scheduling +case.manager.stop.icon eu/engys/resources/images/stop16.png case.manager.start.case.label Start -case.manager.start.case.icon eu/engys/resources/images/file16.png +case.manager.start.case.icon eu/engys/resources/images/start16.png + case.manager.stop.case.label Stop -case.manager.stop.case.icon eu/engys/resources/images/file16.png +case.manager.stop.case.icon eu/engys/resources/images/stop16.png + case.manager.open.case.label Open -case.manager.open.case.icon eu/engys/resources/images/file16.png +case.manager.open.case.icon eu/engys/resources/images/engys16.png + case.manager.view.case.label View -case.manager.view.case.icon eu/engys/resources/images/file16.png -case.manager.add.label Add -case.manager.add.icon eu/engys/resources/images/file16.png -case.manager.remove.label Remove -case.manager.remove.icon eu/engys/resources/images/file16.png -case.manager.clone.label Clone -case.manager.clone.icon eu/engys/resources/images/file16.png +case.manager.view.case.icon eu/engys/resources/images/paraview16.png + +case.manager.add.case.label Add +case.manager.add.case.icon eu/engys/resources/images/table_add16.png +case.manager.remove.case.label Remove +case.manager.remove.case.icon eu/engys/resources/images/table_delete16.png +case.manager.clone.case.label Clone +case.manager.clone.case.icon eu/engys/resources/images/table_clone16.png +case.manager.import.cases.label Import +case.manager.import.cases.icon eu/engys/resources/images/import16.png + +case.manager.preferences.label Preferences +case.manager.preferences.tooltip Opens Preferences Dialog +case.manager.preferences.icon eu/engys/resources/images/settings16.png + +case.manager.license.label License Manager +case.manager.license.icon eu/engys/resources/images/license16.png +case.manager.license.tooltip Opens License Manager Dialog # # EXTERNAL APPLICATIONS @@ -383,77 +533,60 @@ paraview.label ParaView paraview.icon eu/engys/resources/images/paraview16.png paraview.tooltip Open ParaView -fieldview.label FieldView -fieldview.icon eu/engys/resources/images/fieldview16.png -fieldview.tooltip Open FieldView - ensight.label EnSight ensight.icon eu/engys/resources/images/ensight16.png ensight.tooltip Open EnSight -fluent.label Fluent -fluent.icon eu/engys/resources/images/fluent16.png -fluent.import.tooltip Import From Fluent -fluent.merge.tooltip Merge From Fluent -fluent.export.tooltip Export To Fluent - -starcd.label STAR-CD -starcd.icon eu/engys/resources/images/starcd16.png -starcd.tooltip Export To STAR-CD - -pointwise.label PointWise -pointwise.icon eu/engys/resources/images/gridgen16.png -pointwise.import.tooltip Import From PointWise -pointwise.merge.tooltip Merge From PointWise - -openfoam.label OpenFOAM -openfoam.icon eu/engys/resources/images/openFoam16.png -openfoam.import.tooltip Import From OpenFOAM -openfoam.merge.tooltip Merge From OpenFOAM - # # ICONS # +check.icon eu/engys/resources/images/check16.png +uncheck.icon eu/engys/resources/images/uncheck16.png + +parameter.icon eu/engys/resources/images/parameter16.png +edit.icon eu/engys/resources/images/pencil16.png +delete.icon eu/engys/resources/images/delete16.png + +light.on.icon eu/engys/resources/images/lightOn16.png +light.off.icon eu/engys/resources/images/lightOff16.png + +centre.materialpoint.icon eu/engys/resources/images/centre16.png fit.boundingbox.icon eu/engys/resources/images/fit16.png script.edit.icon eu/engys/resources/images/edit16.png browse.file eu/engys/resources/images/browseFile16.png save.log.file eu/engys/resources/images/fileSave16.png +delete.log.file eu/engys/resources/images/deleteFile16.png -general.options.icon eu/engys/resources/images/cog16.png import.icon eu/engys/resources/images/import16.png merge.icon eu/engys/resources/images/merge16.png -decompose.icon eu/engys/resources/images/decompose16.png solver.start.icon eu/engys/resources/images/start16.png solver.stop.icon eu/engys/resources/images/stop16.png -solver.refresh.icon eu/engys/resources/images/refresh16.png - -application.exit.big.icon eu/engys/resources/images/exit32.png console.stop.icon eu/engys/resources/images/stop16.png -console.copy.icon eu/engys/resources/images/copy16.png -console.email.icon eu/engys/resources/images/email16.png +console.copy.icon eu/engys/resources/images/clipboard16.png console.browse.icon eu/engys/resources/images/browseFile16.png -console.scroll.icon eu/engys/resources/images/scroll_pane16.png -console.scroll.lock.icon eu/engys/resources/images/scroll_pane_lock16.png + +console.scroll.icon eu/engys/resources/images/scroll16.png +console.scroll.lock.icon eu/engys/resources/images/scrollLock16.png + console.tab.icon eu/engys/resources/images/console16.png -console.tab.close.icon eu/engys/resources/images/win_close16.png -console.tab.closeall.icon eu/engys/resources/images/win_closeAll16.png -console.tab.max.icon eu/engys/resources/images/win_maximize16.png -console.tab.restore.icon eu/engys/resources/images/win_restore16.png +console.tab.close.icon eu/engys/resources/images/delete16.png +console.tab.closeall.icon eu/engys/resources/images/deleteAll16.png +console.tab.max.icon eu/engys/resources/images/windowMaximise16.png +console.tab.restore.icon eu/engys/resources/images/windowRestore16.png -application.open.terminal.label Terminal -application.open.terminal.tooltip Open Terminal in case folder -application.open.terminal.icon eu/engys/resources/images/terminal16.png - -application.browse.case.label Browse -application.browse.case.tooltip Browse Case Folder -application.browse.case.icon eu/engys/resources/images/browseFolder16.png +table.delete.row.icon eu/engys/resources/images/deleteRow16.png engys.logo eu/engys/resources/engys_logo.png engys.logo.medium eu/engys/resources/engys_logo_medium.png engys.logo.big eu/engys/resources/engys_logo_big.png + +engys.logo.cm eu/engys/resources/engys_logo_cm.png +engys.logo.cm.medium eu/engys/resources/engys_logo_cm_medium.png +engys.logo.cm.big eu/engys/resources/engys_logo_cm_big.png + engys.logo.full eu/engys/resources/engys_logo_full.png engys.terminal.icon eu/engys/resources/engys_terminal_logo.png @@ -466,8 +599,12 @@ helyxsas.startup eu/engys/resources/helyxsas_startup.png helyxmesh.banner eu/engys/resources/helyxmesh_banner.png helyxmesh.startup eu/engys/resources/helyxmesh_startup.png +helyxpost.banner eu/engys/resources/helyxpost_banner.png +helyxpost.startup eu/engys/resources/helyxpost_startup.png + helyxos.banner eu/engys/resources/helyxos_banner.png helyxos.startup eu/engys/resources/helyxos_startup.png + helyxos.faq eu/engys/resources/helyxos_faq.png helyxos.products eu/engys/resources/helyxos_products.png helyxos.helyx.box eu/engys/resources/helyxBox.png @@ -485,11 +622,12 @@ elements.banner eu/engys/resources/elements_banner.png elements.background.image eu/engys/resources/elements_startup.png file.pdf eu/engys/resources/images/pdf16.png -file.excel eu/engys/resources/images/excel16.png -file.png eu/engys/resources/images/png16.png +file.excel eu/engys/resources/images/fileExcel16.png +file.png eu/engys/resources/images/exportImage16.png +file.openfoam eu/engys/resources/images/openFoam16.png info.icon eu/engys/resources/images/info16.png license.icon eu/engys/resources/images/license16.png -preferences.icon eu/engys/resources/images/preferences16.png +preferences.icon eu/engys/resources/images/settings16.png monitoring.functions eu/engys/resources/images/monitoringFunction16.png crosshair.icon eu/engys/resources/images/crosshair16.png @@ -517,84 +655,82 @@ relnotes.helyxmesh.gui.tooltip Open HELYX-MESH GUI Release Notes # FILE CHOOSER # -new.folder.label New Folder -new.folder.icon eu/engys/resources/images/folder_add16.png +file.icon eu/engys/resources/images/file16.png +folder.icon eu/engys/resources/images/folder16.png -delete.file.label Delete File -delete.file.icon eu/engys/resources/images/folder_delete16.png +new.folder.label New +new.folder.tooltip New folder +new.folder.icon eu/engys/resources/images/folderAdd16.png + +rename.file.label Rename +rename.file.tooltip Rename file +rename.file.icon eu/engys/resources/images/pencil16.png + +clone.file.label Clone +clone.file.tooltip Clone file +clone.file.icon eu/engys/resources/images/fileClone16.png + +rename.favorite.label Rename +rename.favorite.tooltip Rename favourite +rename.favorite.icon eu/engys/resources/images/pencil16.png + +delete.file.label Delete +delete.file.tooltip Delete file +delete.file.icon eu/engys/resources/images/folderDelete16.png extract.archive.label Extract -extract.archive.icon eu/engys/resources/images/extract16.png +extract.archive.tooltip Extract file +extract.archive.icon eu/engys/resources/images/unarchive16.png + +add.favorite.label Add to favourites +add.favorite.icon eu/engys/resources/images/favoritesAdd16.png +add.favorite.tooltip Add current location to favourites + +open.favorite.label Open favourite +open.favorite.tooltip Open selected favourite -authenticator.browse Browse -authenticator.domain Domain -authenticator.enterCredentials Enter credentials -authenticator.enterCredentialsForUrl Enter credentials for URL {0} -authenticator.password Password: -authenticator.selectSshKey Select SSH key file -authenticator.sshKeyFile SSH key file: -authenticator.sshKeyFileDescription Your key has to be without paraphrase -authenticator.username User name: -browser.checkingSFtpLinksTask Checking for symbolic links -favorites.favorites Favorites -browser.folderContainsXElements Folder contains {0} elements -preview.loadedX Loaded {0}{1} -preview.loadedXOf Loaded {0} of {1} {2} -browser.loading Loading -browser.loading... Loading... -model.dateLastMod Last modification model.name Name model.size Size model.type Type -preview.n/a N/A -nav.AddToFavorites Add current location to favorites -nav.goFolderUp Go folder up +model.dateLastMod Last modification + +browser.checkingSFtpLinksTask Checking for symbolic links +browser.loading Loading +browser.loading... Loading... nav.pathTooltip Path -nav.refreshActionLabelText Refresh -nav.ToolBarName Navigation tool bar -preview.enable Enable preview -preview.errorLoadingFile Error loading file -preview.fileContent File content: -preview.label Preview -authenticator.savePassword Save password -browser.skipCheckingLinks Skip checking links -favorites.systemLocations System locations -favorites.action Edit/rename -favorites.name Name: -favorites.url URL: -favorites.title Edit favorite -favorites.tooltip Edit selected favorite location -arrowCircleDouble eu/engys/resources/images/update16.png -arrowTurn90 eu/engys/resources/images/arrow-turn16.png -computer eu/engys/resources/images/computer16.png -drive eu/engys/resources/images/drive16.png -sambaShare eu/engys/resources/images/share16.png -favorites.edit eu/engys/resources/images/edit16.png -file eu/engys/resources/images/file16.png -folderOpen eu/engys/resources/images/folder-open16.png -folderNew eu/engys/resources/images/folder_add16.png -folderZipper eu/engys/resources/images/zip16.png -minusButton eu/engys/resources/images/folder_delete16.png -jarIcon eu/engys/resources/images/jar16.png -networkCloud eu/engys/resources/images/network-cloud16.png -shortCut eu/engys/resources/images/shortcut16.png -star eu/engys/resources/images/favourites16.png -starPlus eu/engys/resources/images/favouritesAdd16.png -home eu/engys/resources/images/homeFolder16.png -desktop eu/engys/resources/images/desktop16.png -documents eu/engys/resources/images/documents16.png +favorites.user.label Favourites +favorites.user.icon eu/engys/resources/images/favorites16.png + +favorites.system.label System locations +favorites.system.icon eu/engys/resources/images/computer16.png + +favorites.delete.label Delete favourite +favorites.delete.icon eu/engys/resources/images/delete16.png + +path.refresh.label +path.refresh.icon eu/engys/resources/images/folderRefresh16.png +path.refresh.tooltip Refresh + +path.move.up.label +path.move.up.icon eu/engys/resources/images/folderUp16.png +path.move.up.tooltip Go folder up + +folder.user eu/engys/resources/images/folderUser16.png +folder.desktop eu/engys/resources/images/folderDesktop16.png +folder.documents eu/engys/resources/images/folderDocuments16.png + +archive.icon eu/engys/resources/images/zip16.png +network.icon eu/engys/resources/images/network-cloud16.png +samba.icon eu/engys/resources/images/share16.png +jar.icon eu/engys/resources/images/jar16.png +drive.icon eu/engys/resources/images/drive16.png +shortcut.icon eu/engys/resources/images/shortcut16.png + engys.case eu/engys/resources/images/engys16.png +engys.study eu/engys/resources/images/engys_study16.png streamlinesolutions.case eu/engys/resources/images/streamlinesolutions16.png -application.support.window.label Support -application.support.window.icon eu/engys/resources/images/info16.png -application.support.window.tooltip Obtain support for HELYX-OS - -application.connection.window.label Run Mode -application.connection.window.icon eu/engys/resources/images/runMode16.png -application.connection.window.tooltip Edit Connection Parameters - # # REPORT # @@ -602,3 +738,11 @@ application.connection.window.tooltip Edit Connection Parameters elements.report.watermark eu/engys/resources/report/elementsWatermark.png elements.report.frontpage.watermark eu/engys/resources/report/elementsFrontPageWatermark.png elements.report.logo.full eu/engys/resources/report/elements_logo_full.png + +# +# PARALLEL WORKS +# +application.parallel.works.label Run Cloud +application.parallel.works.icon eu/engys/resources/images/network-cloud16.png +application.parallel.works.tooltip Edit Cloud Connection Parameters + diff --git a/src/eu/engys/resources/driver.pbs b/src/eu/engys/resources/driver.pbs deleted file mode 100644 index 13a3c83..0000000 --- a/src/eu/engys/resources/driver.pbs +++ /dev/null @@ -1,12 +0,0 @@ - -#module add openmpi/1.4.5 -#module load paraview - -#Initialize Environments -source $ENV_LOADER -source $PY_LOADER - -### Set OpenFOAM Environment -export WM_64=ON -export MPI_OPTIONS="-mca btl openib,sm,self" - \ No newline at end of file diff --git a/src/eu/engys/resources/elementsBox.png b/src/eu/engys/resources/elementsBox.png deleted file mode 100644 index c25dd87..0000000 Binary files a/src/eu/engys/resources/elementsBox.png and /dev/null differ diff --git a/src/eu/engys/resources/elements_logo_full.png b/src/eu/engys/resources/elements_logo_full.png deleted file mode 100644 index 0be705b..0000000 Binary files a/src/eu/engys/resources/elements_logo_full.png and /dev/null differ diff --git a/src/eu/engys/resources/engys_logo_cm.png b/src/eu/engys/resources/engys_logo_cm.png new file mode 100644 index 0000000..6a58a39 Binary files /dev/null and b/src/eu/engys/resources/engys_logo_cm.png differ diff --git a/src/eu/engys/resources/engys_logo_cm_big.png b/src/eu/engys/resources/engys_logo_cm_big.png new file mode 100644 index 0000000..b635a0c Binary files /dev/null and b/src/eu/engys/resources/engys_logo_cm_big.png differ diff --git a/src/eu/engys/resources/engys_logo_cm_medium.png b/src/eu/engys/resources/engys_logo_cm_medium.png new file mode 100644 index 0000000..93da204 Binary files /dev/null and b/src/eu/engys/resources/engys_logo_cm_medium.png differ diff --git a/src/eu/engys/resources/images/application_view_list16.png b/src/eu/engys/resources/images/application16.png similarity index 100% rename from src/eu/engys/resources/images/application_view_list16.png rename to src/eu/engys/resources/images/application16.png diff --git a/src/eu/engys/resources/images/centre16.png b/src/eu/engys/resources/images/centre16.png new file mode 100644 index 0000000..289cbe2 Binary files /dev/null and b/src/eu/engys/resources/images/centre16.png differ diff --git a/src/eu/engys/resources/images/check16.png b/src/eu/engys/resources/images/check16.png new file mode 100644 index 0000000..cf874b6 Binary files /dev/null and b/src/eu/engys/resources/images/check16.png differ diff --git a/src/eu/engys/resources/images/clip24.png b/src/eu/engys/resources/images/clip24.png index 986e1eb..88e47a7 100644 Binary files a/src/eu/engys/resources/images/clip24.png and b/src/eu/engys/resources/images/clip24.png differ diff --git a/src/eu/engys/resources/images/copy16.png b/src/eu/engys/resources/images/clipboard16.png similarity index 100% rename from src/eu/engys/resources/images/copy16.png rename to src/eu/engys/resources/images/clipboard16.png diff --git a/src/eu/engys/resources/images/contour24.png b/src/eu/engys/resources/images/contour24.png new file mode 100644 index 0000000..754df99 Binary files /dev/null and b/src/eu/engys/resources/images/contour24.png differ diff --git a/src/eu/engys/resources/images/contourWidget16.png b/src/eu/engys/resources/images/contourWidget16.png new file mode 100644 index 0000000..272e59a Binary files /dev/null and b/src/eu/engys/resources/images/contourWidget16.png differ diff --git a/src/eu/engys/resources/images/cor16.png b/src/eu/engys/resources/images/cor16.png new file mode 100644 index 0000000..5b4601e Binary files /dev/null and b/src/eu/engys/resources/images/cor16.png differ diff --git a/src/eu/engys/resources/images/corEdit16.png b/src/eu/engys/resources/images/corEdit16.png new file mode 100644 index 0000000..f1024d5 Binary files /dev/null and b/src/eu/engys/resources/images/corEdit16.png differ diff --git a/src/eu/engys/resources/images/crinkle24.png b/src/eu/engys/resources/images/crinkle24.png index 94430b5..dc432e7 100644 Binary files a/src/eu/engys/resources/images/crinkle24.png and b/src/eu/engys/resources/images/crinkle24.png differ diff --git a/src/eu/engys/resources/images/cube24.png b/src/eu/engys/resources/images/cube24.png index 5329b95..28bca89 100644 Binary files a/src/eu/engys/resources/images/cube24.png and b/src/eu/engys/resources/images/cube24.png differ diff --git a/src/eu/engys/resources/images/cursor16.png b/src/eu/engys/resources/images/cursor16.png deleted file mode 100644 index 0382407..0000000 Binary files a/src/eu/engys/resources/images/cursor16.png and /dev/null differ diff --git a/src/eu/engys/resources/images/cylinder24.png b/src/eu/engys/resources/images/cylinder24.png index 6b5e3d0..beefc23 100644 Binary files a/src/eu/engys/resources/images/cylinder24.png and b/src/eu/engys/resources/images/cylinder24.png differ diff --git a/src/eu/engys/resources/images/delete16.png b/src/eu/engys/resources/images/delete16.png new file mode 100644 index 0000000..55e3138 Binary files /dev/null and b/src/eu/engys/resources/images/delete16.png differ diff --git a/src/eu/engys/resources/images/deleteAll16.png b/src/eu/engys/resources/images/deleteAll16.png new file mode 100644 index 0000000..2c6a1af Binary files /dev/null and b/src/eu/engys/resources/images/deleteAll16.png differ diff --git a/src/eu/engys/resources/images/deleteFields16.png b/src/eu/engys/resources/images/deleteFields16.png new file mode 100644 index 0000000..e2f2a81 Binary files /dev/null and b/src/eu/engys/resources/images/deleteFields16.png differ diff --git a/src/eu/engys/resources/images/deleteFile16.png b/src/eu/engys/resources/images/deleteFile16.png new file mode 100644 index 0000000..d70f26d Binary files /dev/null and b/src/eu/engys/resources/images/deleteFile16.png differ diff --git a/src/eu/engys/resources/images/deleteRow16.png b/src/eu/engys/resources/images/deleteRow16.png new file mode 100644 index 0000000..c9b3eb8 Binary files /dev/null and b/src/eu/engys/resources/images/deleteRow16.png differ diff --git a/src/eu/engys/resources/images/edit16.png b/src/eu/engys/resources/images/edit16.png deleted file mode 100644 index bca3433..0000000 Binary files a/src/eu/engys/resources/images/edit16.png and /dev/null differ diff --git a/src/eu/engys/resources/images/email16.png b/src/eu/engys/resources/images/email16.png deleted file mode 100644 index 8327873..0000000 Binary files a/src/eu/engys/resources/images/email16.png and /dev/null differ diff --git a/src/eu/engys/resources/images/engys_study16.png b/src/eu/engys/resources/images/engys_study16.png new file mode 100644 index 0000000..5bd5815 Binary files /dev/null and b/src/eu/engys/resources/images/engys_study16.png differ diff --git a/src/eu/engys/resources/images/exportImage16.png b/src/eu/engys/resources/images/exportImage16.png index 07af88b..0e2f0e9 100644 Binary files a/src/eu/engys/resources/images/exportImage16.png and b/src/eu/engys/resources/images/exportImage16.png differ diff --git a/src/eu/engys/resources/images/externalMesh16.png b/src/eu/engys/resources/images/externalMesh16.png index 650396f..09dc8ff 100644 Binary files a/src/eu/engys/resources/images/externalMesh16.png and b/src/eu/engys/resources/images/externalMesh16.png differ diff --git a/src/eu/engys/resources/images/extrude16.png b/src/eu/engys/resources/images/extrude16.png deleted file mode 100644 index 94dbad7..0000000 Binary files a/src/eu/engys/resources/images/extrude16.png and /dev/null differ diff --git a/src/eu/engys/resources/images/eye16.png b/src/eu/engys/resources/images/eye16.png deleted file mode 100644 index 973a4a0..0000000 Binary files a/src/eu/engys/resources/images/eye16.png and /dev/null differ diff --git a/src/eu/engys/resources/images/eye_no16.png b/src/eu/engys/resources/images/eye_no16.png deleted file mode 100644 index ce6ed31..0000000 Binary files a/src/eu/engys/resources/images/eye_no16.png and /dev/null differ diff --git a/src/eu/engys/resources/images/favourites16.png b/src/eu/engys/resources/images/favorites16.png similarity index 100% rename from src/eu/engys/resources/images/favourites16.png rename to src/eu/engys/resources/images/favorites16.png diff --git a/src/eu/engys/resources/images/favouritesAdd16.png b/src/eu/engys/resources/images/favoritesAdd16.png similarity index 100% rename from src/eu/engys/resources/images/favouritesAdd16.png rename to src/eu/engys/resources/images/favoritesAdd16.png diff --git a/src/eu/engys/resources/images/fieldFirst16.png b/src/eu/engys/resources/images/fieldFirst16.png new file mode 100644 index 0000000..df00cc3 Binary files /dev/null and b/src/eu/engys/resources/images/fieldFirst16.png differ diff --git a/src/eu/engys/resources/images/fieldLast16.png b/src/eu/engys/resources/images/fieldLast16.png new file mode 100644 index 0000000..e69fa3d Binary files /dev/null and b/src/eu/engys/resources/images/fieldLast16.png differ diff --git a/src/eu/engys/resources/images/fieldNext16.png b/src/eu/engys/resources/images/fieldNext16.png new file mode 100644 index 0000000..eac3be1 Binary files /dev/null and b/src/eu/engys/resources/images/fieldNext16.png differ diff --git a/src/eu/engys/resources/images/fieldPrev16.png b/src/eu/engys/resources/images/fieldPrev16.png new file mode 100644 index 0000000..bf5c961 Binary files /dev/null and b/src/eu/engys/resources/images/fieldPrev16.png differ diff --git a/src/eu/engys/resources/images/fieldRefresh16.png b/src/eu/engys/resources/images/fieldRefresh16.png new file mode 100644 index 0000000..c54ba86 Binary files /dev/null and b/src/eu/engys/resources/images/fieldRefresh16.png differ diff --git a/src/eu/engys/resources/images/fileClone16.png b/src/eu/engys/resources/images/fileClone16.png new file mode 100644 index 0000000..680bb98 Binary files /dev/null and b/src/eu/engys/resources/images/fileClone16.png differ diff --git a/src/eu/engys/resources/images/excel16.png b/src/eu/engys/resources/images/fileExcel16.png similarity index 100% rename from src/eu/engys/resources/images/excel16.png rename to src/eu/engys/resources/images/fileExcel16.png diff --git a/src/eu/engys/resources/images/first16.png b/src/eu/engys/resources/images/first16.png deleted file mode 100644 index 172a73c..0000000 Binary files a/src/eu/engys/resources/images/first16.png and /dev/null differ diff --git a/src/eu/engys/resources/images/first_grey16.png b/src/eu/engys/resources/images/first_grey16.png deleted file mode 100644 index 1319cbb..0000000 Binary files a/src/eu/engys/resources/images/first_grey16.png and /dev/null differ diff --git a/src/eu/engys/resources/images/fit16.png b/src/eu/engys/resources/images/fit16.png index d4625ec..143c58d 100644 Binary files a/src/eu/engys/resources/images/fit16.png and b/src/eu/engys/resources/images/fit16.png differ diff --git a/src/eu/engys/resources/images/folder-open16.png b/src/eu/engys/resources/images/folder16.png similarity index 100% rename from src/eu/engys/resources/images/folder-open16.png rename to src/eu/engys/resources/images/folder16.png diff --git a/src/eu/engys/resources/images/folder_add16.png b/src/eu/engys/resources/images/folderAdd16.png similarity index 100% rename from src/eu/engys/resources/images/folder_add16.png rename to src/eu/engys/resources/images/folderAdd16.png diff --git a/src/eu/engys/resources/images/folder_delete16.png b/src/eu/engys/resources/images/folderDelete16.png similarity index 100% rename from src/eu/engys/resources/images/folder_delete16.png rename to src/eu/engys/resources/images/folderDelete16.png diff --git a/src/eu/engys/resources/images/desktop16.png b/src/eu/engys/resources/images/folderDesktop16.png similarity index 100% rename from src/eu/engys/resources/images/desktop16.png rename to src/eu/engys/resources/images/folderDesktop16.png diff --git a/src/eu/engys/resources/images/documents16.png b/src/eu/engys/resources/images/folderDocuments16.png similarity index 100% rename from src/eu/engys/resources/images/documents16.png rename to src/eu/engys/resources/images/folderDocuments16.png diff --git a/src/eu/engys/resources/images/folderParameters16.png b/src/eu/engys/resources/images/folderParameters16.png new file mode 100644 index 0000000..275cf0e Binary files /dev/null and b/src/eu/engys/resources/images/folderParameters16.png differ diff --git a/src/eu/engys/resources/images/update16.png b/src/eu/engys/resources/images/folderRefresh16.png similarity index 100% rename from src/eu/engys/resources/images/update16.png rename to src/eu/engys/resources/images/folderRefresh16.png diff --git a/src/eu/engys/resources/images/arrow-turn16.png b/src/eu/engys/resources/images/folderUp16.png similarity index 100% rename from src/eu/engys/resources/images/arrow-turn16.png rename to src/eu/engys/resources/images/folderUp16.png diff --git a/src/eu/engys/resources/images/homeFolder16.png b/src/eu/engys/resources/images/folderUser16.png similarity index 100% rename from src/eu/engys/resources/images/homeFolder16.png rename to src/eu/engys/resources/images/folderUser16.png diff --git a/src/eu/engys/resources/images/lightning.png b/src/eu/engys/resources/images/geometry2mesh16.png similarity index 100% rename from src/eu/engys/resources/images/lightning.png rename to src/eu/engys/resources/images/geometry2mesh16.png diff --git a/src/eu/engys/resources/images/igs24.png b/src/eu/engys/resources/images/igs24.png index 10e4c45..e82b47c 100644 Binary files a/src/eu/engys/resources/images/igs24.png and b/src/eu/engys/resources/images/igs24.png differ diff --git a/src/eu/engys/resources/images/info16.png b/src/eu/engys/resources/images/info16.png index 85c1876..b73e1b8 100644 Binary files a/src/eu/engys/resources/images/info16.png and b/src/eu/engys/resources/images/info16.png differ diff --git a/src/eu/engys/resources/images/last16.png b/src/eu/engys/resources/images/last16.png deleted file mode 100644 index 88dc738..0000000 Binary files a/src/eu/engys/resources/images/last16.png and /dev/null differ diff --git a/src/eu/engys/resources/images/last_grey16.png b/src/eu/engys/resources/images/last_grey16.png deleted file mode 100644 index 9f5a749..0000000 Binary files a/src/eu/engys/resources/images/last_grey16.png and /dev/null differ diff --git a/src/eu/engys/resources/images/lightbulb_off16.png b/src/eu/engys/resources/images/lightOff16.png similarity index 100% rename from src/eu/engys/resources/images/lightbulb_off16.png rename to src/eu/engys/resources/images/lightOff16.png diff --git a/src/eu/engys/resources/images/lightbulb16.png b/src/eu/engys/resources/images/lightOn16.png similarity index 100% rename from src/eu/engys/resources/images/lightbulb16.png rename to src/eu/engys/resources/images/lightOn16.png diff --git a/src/eu/engys/resources/images/location16.png b/src/eu/engys/resources/images/location16.png new file mode 100644 index 0000000..c457826 Binary files /dev/null and b/src/eu/engys/resources/images/location16.png differ diff --git a/src/eu/engys/resources/images/merge_disk16.png b/src/eu/engys/resources/images/merge_disk16.png deleted file mode 100644 index 113927e..0000000 Binary files a/src/eu/engys/resources/images/merge_disk16.png and /dev/null differ diff --git a/src/eu/engys/resources/images/next16.png b/src/eu/engys/resources/images/next16.png deleted file mode 100644 index 184be23..0000000 Binary files a/src/eu/engys/resources/images/next16.png and /dev/null differ diff --git a/src/eu/engys/resources/images/next_grey16.png b/src/eu/engys/resources/images/next_grey16.png deleted file mode 100644 index ce7e4cc..0000000 Binary files a/src/eu/engys/resources/images/next_grey16.png and /dev/null differ diff --git a/src/eu/engys/resources/images/open16.png b/src/eu/engys/resources/images/open16.png deleted file mode 100644 index f1ed9ab..0000000 Binary files a/src/eu/engys/resources/images/open16.png and /dev/null differ diff --git a/src/eu/engys/resources/images/openFoam16.png b/src/eu/engys/resources/images/openFoam16.png index 55293f8..c1b61e8 100644 Binary files a/src/eu/engys/resources/images/openFoam16.png and b/src/eu/engys/resources/images/openFoam16.png differ diff --git a/src/eu/engys/resources/images/parameter16.png b/src/eu/engys/resources/images/parameter16.png new file mode 100644 index 0000000..459a025 Binary files /dev/null and b/src/eu/engys/resources/images/parameter16.png differ diff --git a/src/eu/engys/resources/images/pickPoint16.png b/src/eu/engys/resources/images/pickPoint16.png new file mode 100644 index 0000000..1540238 Binary files /dev/null and b/src/eu/engys/resources/images/pickPoint16.png differ diff --git a/src/eu/engys/resources/images/pickSurface16.png b/src/eu/engys/resources/images/pickSurface16.png new file mode 100644 index 0000000..825a9e6 Binary files /dev/null and b/src/eu/engys/resources/images/pickSurface16.png differ diff --git a/src/eu/engys/resources/images/plane24.png b/src/eu/engys/resources/images/plane24.png index 9f646e8..dda9e89 100644 Binary files a/src/eu/engys/resources/images/plane24.png and b/src/eu/engys/resources/images/plane24.png differ diff --git a/src/eu/engys/resources/images/planeWidget16.png b/src/eu/engys/resources/images/planeWidget16.png index 5adbbef..5b62534 100644 Binary files a/src/eu/engys/resources/images/planeWidget16.png and b/src/eu/engys/resources/images/planeWidget16.png differ diff --git a/src/eu/engys/resources/images/png16.png b/src/eu/engys/resources/images/png16.png deleted file mode 100644 index 0e2f0e9..0000000 Binary files a/src/eu/engys/resources/images/png16.png and /dev/null differ diff --git a/src/eu/engys/resources/images/preferences16.png b/src/eu/engys/resources/images/preferences16.png deleted file mode 100644 index 305e2ca..0000000 Binary files a/src/eu/engys/resources/images/preferences16.png and /dev/null differ diff --git a/src/eu/engys/resources/images/prev_grey16.png b/src/eu/engys/resources/images/prev_grey16.png deleted file mode 100644 index aa7d07a..0000000 Binary files a/src/eu/engys/resources/images/prev_grey16.png and /dev/null differ diff --git a/src/eu/engys/resources/images/arrow_down16.png b/src/eu/engys/resources/images/recents16.png similarity index 100% rename from src/eu/engys/resources/images/arrow_down16.png rename to src/eu/engys/resources/images/recents16.png diff --git a/src/eu/engys/resources/images/refresh16.png b/src/eu/engys/resources/images/refresh16.png deleted file mode 100644 index bc323e3..0000000 Binary files a/src/eu/engys/resources/images/refresh16.png and /dev/null differ diff --git a/src/eu/engys/resources/images/refresh_grey16.png b/src/eu/engys/resources/images/refresh_grey16.png deleted file mode 100644 index b9717ad..0000000 Binary files a/src/eu/engys/resources/images/refresh_grey16.png and /dev/null differ diff --git a/src/eu/engys/resources/images/ring24.png b/src/eu/engys/resources/images/ring24.png index a75b251..a4e5ff3 100644 Binary files a/src/eu/engys/resources/images/ring24.png and b/src/eu/engys/resources/images/ring24.png differ diff --git a/src/eu/engys/resources/images/rulerWidget16.png b/src/eu/engys/resources/images/rulerWidget16.png index 38c6c42..5f95cbb 100644 Binary files a/src/eu/engys/resources/images/rulerWidget16.png and b/src/eu/engys/resources/images/rulerWidget16.png differ diff --git a/src/eu/engys/resources/images/scalarbar/DIVBlueToRed16.png b/src/eu/engys/resources/images/scalarbar/DIVBlueToRed16.png deleted file mode 100644 index c4819af..0000000 Binary files a/src/eu/engys/resources/images/scalarbar/DIVBlueToRed16.png and /dev/null differ diff --git a/src/eu/engys/resources/images/scalarbar/DIVBlueToYellow16.png b/src/eu/engys/resources/images/scalarbar/DIVBlueToYellow16.png deleted file mode 100644 index 9d98932..0000000 Binary files a/src/eu/engys/resources/images/scalarbar/DIVBlueToYellow16.png and /dev/null differ diff --git a/src/eu/engys/resources/images/scalarbar/DIVRedToBlue16.png b/src/eu/engys/resources/images/scalarbar/DIVRedToBlue16.png deleted file mode 100644 index 525aa58..0000000 Binary files a/src/eu/engys/resources/images/scalarbar/DIVRedToBlue16.png and /dev/null differ diff --git a/src/eu/engys/resources/images/scalarbar/DIVYellowToBlue16.png b/src/eu/engys/resources/images/scalarbar/DIVYellowToBlue16.png deleted file mode 100644 index 13fcbd8..0000000 Binary files a/src/eu/engys/resources/images/scalarbar/DIVYellowToBlue16.png and /dev/null differ diff --git a/src/eu/engys/resources/images/scalarbar/HSVBlueToRed16.png b/src/eu/engys/resources/images/scalarbar/HSVBlueToRed16.png deleted file mode 100644 index b360fc4..0000000 Binary files a/src/eu/engys/resources/images/scalarbar/HSVBlueToRed16.png and /dev/null differ diff --git a/src/eu/engys/resources/images/scalarbar/HSVBlueToYellow16.png b/src/eu/engys/resources/images/scalarbar/HSVBlueToYellow16.png deleted file mode 100644 index 6877523..0000000 Binary files a/src/eu/engys/resources/images/scalarbar/HSVBlueToYellow16.png and /dev/null differ diff --git a/src/eu/engys/resources/images/scalarbar/HSVRedToBlue16.png b/src/eu/engys/resources/images/scalarbar/HSVRedToBlue16.png deleted file mode 100644 index 1f8d74e..0000000 Binary files a/src/eu/engys/resources/images/scalarbar/HSVRedToBlue16.png and /dev/null differ diff --git a/src/eu/engys/resources/images/scalarbar/HSVYellowToBlue16.png b/src/eu/engys/resources/images/scalarbar/HSVYellowToBlue16.png deleted file mode 100644 index d269202..0000000 Binary files a/src/eu/engys/resources/images/scalarbar/HSVYellowToBlue16.png and /dev/null differ diff --git a/src/eu/engys/resources/images/scalarbar/RGBBlueToRed16.png b/src/eu/engys/resources/images/scalarbar/RGBBlueToRed16.png deleted file mode 100644 index 3f6d418..0000000 Binary files a/src/eu/engys/resources/images/scalarbar/RGBBlueToRed16.png and /dev/null differ diff --git a/src/eu/engys/resources/images/scalarbar/RGBBlueToYellow16.png b/src/eu/engys/resources/images/scalarbar/RGBBlueToYellow16.png deleted file mode 100644 index 08b321d..0000000 Binary files a/src/eu/engys/resources/images/scalarbar/RGBBlueToYellow16.png and /dev/null differ diff --git a/src/eu/engys/resources/images/scalarbar/RGBRedToBlue16.png b/src/eu/engys/resources/images/scalarbar/RGBRedToBlue16.png deleted file mode 100644 index 13b74d3..0000000 Binary files a/src/eu/engys/resources/images/scalarbar/RGBRedToBlue16.png and /dev/null differ diff --git a/src/eu/engys/resources/images/scalarbar/RGBYellowToBlue16.png b/src/eu/engys/resources/images/scalarbar/RGBYellowToBlue16.png deleted file mode 100644 index 0426420..0000000 Binary files a/src/eu/engys/resources/images/scalarbar/RGBYellowToBlue16.png and /dev/null differ diff --git a/src/eu/engys/resources/images/scalarbar/blackBodyRadiation16.png b/src/eu/engys/resources/images/scalarbar/blackBodyRadiation16.png new file mode 100644 index 0000000..13650bb Binary files /dev/null and b/src/eu/engys/resources/images/scalarbar/blackBodyRadiation16.png differ diff --git a/src/eu/engys/resources/images/scalarbar/blackToBlueToWhite16.png b/src/eu/engys/resources/images/scalarbar/blackToBlueToWhite16.png new file mode 100644 index 0000000..16dd458 Binary files /dev/null and b/src/eu/engys/resources/images/scalarbar/blackToBlueToWhite16.png differ diff --git a/src/eu/engys/resources/images/scalarbar/blackToOrangeToWhite16.png b/src/eu/engys/resources/images/scalarbar/blackToOrangeToWhite16.png new file mode 100644 index 0000000..1b3b386 Binary files /dev/null and b/src/eu/engys/resources/images/scalarbar/blackToOrangeToWhite16.png differ diff --git a/src/eu/engys/resources/images/scalarbar/blackToWhite16.png b/src/eu/engys/resources/images/scalarbar/blackToWhite16.png index 326d480..46113ec 100644 Binary files a/src/eu/engys/resources/images/scalarbar/blackToWhite16.png and b/src/eu/engys/resources/images/scalarbar/blackToWhite16.png differ diff --git a/src/eu/engys/resources/images/scalarbar/blueToRedCOLDHOT16.png b/src/eu/engys/resources/images/scalarbar/blueToRedCOLDHOT16.png new file mode 100644 index 0000000..451f9e2 Binary files /dev/null and b/src/eu/engys/resources/images/scalarbar/blueToRedCOLDHOT16.png differ diff --git a/src/eu/engys/resources/images/scalarbar/blueToRedDES16.png b/src/eu/engys/resources/images/scalarbar/blueToRedDES16.png new file mode 100644 index 0000000..4028bfa Binary files /dev/null and b/src/eu/engys/resources/images/scalarbar/blueToRedDES16.png differ diff --git a/src/eu/engys/resources/images/scalarbar/blueToRedDIV16.png b/src/eu/engys/resources/images/scalarbar/blueToRedDIV16.png new file mode 100644 index 0000000..d2b8ebb Binary files /dev/null and b/src/eu/engys/resources/images/scalarbar/blueToRedDIV16.png differ diff --git a/src/eu/engys/resources/images/scalarbar/blueToRedHSV16.png b/src/eu/engys/resources/images/scalarbar/blueToRedHSV16.png new file mode 100644 index 0000000..6bb7b16 Binary files /dev/null and b/src/eu/engys/resources/images/scalarbar/blueToRedHSV16.png differ diff --git a/src/eu/engys/resources/images/scalarbar/blueToRedJET16.png b/src/eu/engys/resources/images/scalarbar/blueToRedJET16.png new file mode 100644 index 0000000..0195890 Binary files /dev/null and b/src/eu/engys/resources/images/scalarbar/blueToRedJET16.png differ diff --git a/src/eu/engys/resources/images/scalarbar/blueToRedRGB16.png b/src/eu/engys/resources/images/scalarbar/blueToRedRGB16.png new file mode 100644 index 0000000..5c1b886 Binary files /dev/null and b/src/eu/engys/resources/images/scalarbar/blueToRedRGB16.png differ diff --git a/src/eu/engys/resources/images/scalarbar/blueToYellowDIV16.png b/src/eu/engys/resources/images/scalarbar/blueToYellowDIV16.png new file mode 100644 index 0000000..c400b7f Binary files /dev/null and b/src/eu/engys/resources/images/scalarbar/blueToYellowDIV16.png differ diff --git a/src/eu/engys/resources/images/scalarbar/blueToYellowHSV16.png b/src/eu/engys/resources/images/scalarbar/blueToYellowHSV16.png new file mode 100644 index 0000000..b1dd5d6 Binary files /dev/null and b/src/eu/engys/resources/images/scalarbar/blueToYellowHSV16.png differ diff --git a/src/eu/engys/resources/images/scalarbar/blueToYellowRGB16.png b/src/eu/engys/resources/images/scalarbar/blueToYellowRGB16.png new file mode 100644 index 0000000..bbb86a7 Binary files /dev/null and b/src/eu/engys/resources/images/scalarbar/blueToYellowRGB16.png differ diff --git a/src/eu/engys/resources/images/scalarbar/rainbow16.png b/src/eu/engys/resources/images/scalarbar/rainbow16.png deleted file mode 100644 index 57c384b..0000000 Binary files a/src/eu/engys/resources/images/scalarbar/rainbow16.png and /dev/null differ diff --git a/src/eu/engys/resources/images/scalarbar/rainbowInverted16.png b/src/eu/engys/resources/images/scalarbar/rainbowInverted16.png deleted file mode 100644 index ad2f41b..0000000 Binary files a/src/eu/engys/resources/images/scalarbar/rainbowInverted16.png and /dev/null differ diff --git a/src/eu/engys/resources/images/scalarbar/whiteToBlack16.png b/src/eu/engys/resources/images/scalarbar/whiteToBlack16.png deleted file mode 100644 index db23658..0000000 Binary files a/src/eu/engys/resources/images/scalarbar/whiteToBlack16.png and /dev/null differ diff --git a/src/eu/engys/resources/images/scalarbar16.png b/src/eu/engys/resources/images/scalarbar16.png index 4af75ed..13e3d5a 100644 Binary files a/src/eu/engys/resources/images/scalarbar16.png and b/src/eu/engys/resources/images/scalarbar16.png differ diff --git a/src/eu/engys/resources/images/scalarbarEdit16.png b/src/eu/engys/resources/images/scalarbarEdit16.png index 07288f3..5633212 100644 Binary files a/src/eu/engys/resources/images/scalarbarEdit16.png and b/src/eu/engys/resources/images/scalarbarEdit16.png differ diff --git a/src/eu/engys/resources/images/scroll_pane16.png b/src/eu/engys/resources/images/scroll16.png similarity index 100% rename from src/eu/engys/resources/images/scroll_pane16.png rename to src/eu/engys/resources/images/scroll16.png diff --git a/src/eu/engys/resources/images/scroll_pane_lock16.png b/src/eu/engys/resources/images/scrollLock16.png similarity index 100% rename from src/eu/engys/resources/images/scroll_pane_lock16.png rename to src/eu/engys/resources/images/scrollLock16.png diff --git a/src/eu/engys/resources/images/cog16.png b/src/eu/engys/resources/images/settings16.png similarity index 100% rename from src/eu/engys/resources/images/cog16.png rename to src/eu/engys/resources/images/settings16.png diff --git a/src/eu/engys/resources/images/shape_boundary_edges16.png b/src/eu/engys/resources/images/shape_boundary_edges16.png index a560b67..c901dae 100644 Binary files a/src/eu/engys/resources/images/shape_boundary_edges16.png and b/src/eu/engys/resources/images/shape_boundary_edges16.png differ diff --git a/src/eu/engys/resources/images/slice24.png b/src/eu/engys/resources/images/slice24.png index 23874c4..4d97665 100644 Binary files a/src/eu/engys/resources/images/slice24.png and b/src/eu/engys/resources/images/slice24.png differ diff --git a/src/eu/engys/resources/images/sphere24.png b/src/eu/engys/resources/images/sphere24.png index 2e1e8fb..deebd14 100644 Binary files a/src/eu/engys/resources/images/sphere24.png and b/src/eu/engys/resources/images/sphere24.png differ diff --git a/src/eu/engys/resources/images/stretch16.png b/src/eu/engys/resources/images/stretch16.png new file mode 100644 index 0000000..b048b0e Binary files /dev/null and b/src/eu/engys/resources/images/stretch16.png differ diff --git a/src/eu/engys/resources/images/table_add16.png b/src/eu/engys/resources/images/table_add16.png new file mode 100644 index 0000000..09662da Binary files /dev/null and b/src/eu/engys/resources/images/table_add16.png differ diff --git a/src/eu/engys/resources/images/table_clone16.png b/src/eu/engys/resources/images/table_clone16.png new file mode 100644 index 0000000..82fafb2 Binary files /dev/null and b/src/eu/engys/resources/images/table_clone16.png differ diff --git a/src/eu/engys/resources/images/table_delete16.png b/src/eu/engys/resources/images/table_delete16.png new file mode 100644 index 0000000..e2f2a81 Binary files /dev/null and b/src/eu/engys/resources/images/table_delete16.png differ diff --git a/src/eu/engys/resources/images/extract16.png b/src/eu/engys/resources/images/unarchive16.png similarity index 100% rename from src/eu/engys/resources/images/extract16.png rename to src/eu/engys/resources/images/unarchive16.png diff --git a/src/eu/engys/resources/images/uncheck16.png b/src/eu/engys/resources/images/uncheck16.png new file mode 100644 index 0000000..43d0f77 Binary files /dev/null and b/src/eu/engys/resources/images/uncheck16.png differ diff --git a/src/eu/engys/resources/images/win_close16.png b/src/eu/engys/resources/images/win_close16.png deleted file mode 100644 index e44a306..0000000 Binary files a/src/eu/engys/resources/images/win_close16.png and /dev/null differ diff --git a/src/eu/engys/resources/images/win_closeAll16.png b/src/eu/engys/resources/images/win_closeAll16.png deleted file mode 100644 index 2c82f08..0000000 Binary files a/src/eu/engys/resources/images/win_closeAll16.png and /dev/null differ diff --git a/src/eu/engys/resources/images/win_maximize16.png b/src/eu/engys/resources/images/win_maximize16.png deleted file mode 100644 index 3a04256..0000000 Binary files a/src/eu/engys/resources/images/win_maximize16.png and /dev/null differ diff --git a/src/eu/engys/resources/images/win_restore16.png b/src/eu/engys/resources/images/win_restore16.png deleted file mode 100644 index 9df9498..0000000 Binary files a/src/eu/engys/resources/images/win_restore16.png and /dev/null differ diff --git a/src/eu/engys/resources/images/windowMaximise16.png b/src/eu/engys/resources/images/windowMaximise16.png new file mode 100644 index 0000000..f6bce84 Binary files /dev/null and b/src/eu/engys/resources/images/windowMaximise16.png differ diff --git a/src/eu/engys/resources/images/windowRestore16.png b/src/eu/engys/resources/images/windowRestore16.png new file mode 100644 index 0000000..1856ef7 Binary files /dev/null and b/src/eu/engys/resources/images/windowRestore16.png differ diff --git a/src/eu/engys/resources/old/splash.png b/src/eu/engys/resources/old/splash.png deleted file mode 100644 index e07df8e..0000000 Binary files a/src/eu/engys/resources/old/splash.png and /dev/null differ diff --git a/src/eu/engys/resources/old/splash_HelyxOS.gif b/src/eu/engys/resources/old/splash_HelyxOS.gif deleted file mode 100644 index 0b3b88e..0000000 Binary files a/src/eu/engys/resources/old/splash_HelyxOS.gif and /dev/null differ diff --git a/src/eu/engys/resources/pbs.run b/src/eu/engys/resources/pbs.run deleted file mode 100644 index 25b5bb0..0000000 --- a/src/eu/engys/resources/pbs.run +++ /dev/null @@ -1,173 +0,0 @@ -#!/bin/bash - -echo -echo "---------------------------------" -echo " PBS QUEUE LAUNCHER " -echo "---------------------------------" - -HEADER() { - [[ -e ~/.profile ]] && source ~/.profile - [[ -e ~/.bash_profile ]] && source ~/.bash_profile - - echo " Environment" - echo "---------------------------------" - echo " APPLICATION = $APPLICATION" - echo " APP_OPT = $APP_OPT" - echo " ENV_LOADER = $ENV_LOADER" - echo " HOSTFILE = $HOSTFILE" - echo " CASE = $CASE" - echo " LOG = $LOG" - echo " NP = $NP" - echo " OPTIONS = $1" - echo "---------------------------------" - echo " PBS_O_WORKDIR = $PBS_O_WORKDIR" - echo " PBS_NODEFILE = $PBS_NODEFILE" - echo "---------------------------------" - echo " SYSTEM = `uname -a`" - echo " PWD = `pwd`" - echo " HOSTNAME = `hostname`" - echo " TIME = `date`" - echo " PWD = `pwd`" - -} - -setJobId() { - # Save job ID information - if [[ -e JOBID.log ]] - then - JOBID=$(cat JOBID.log) - echo " JOBID = $JOBID" - echo "---------------------------------" - else - echo "No running jobs. Aborting." - exit 1 - fi -} - -do_kill() { - JOB_STATUS=$(qstat $JOBID | awk 'NR==3''{print $5}') - echo ">> Deleting $JOBID" - qdel $JOBID - echo ">> Job DELETED" - exit 0 -} - -do_monitor() { - typeset -i n=0 - typeset -i TIMEOUT=1000 - - # Check job status and wait for job start - while : - do - JOB_STATUS=$(qstat $JOBID | awk 'NR==3''{print $5}') - STATUS=${JOB_STATUS:=E} - #echo "STATUS = '$STATUS'" - case "$STATUS" in - C) - #tail -n +1 out.log - echo ">> Job $JOBID COMPLETED!" - - JOB_EXIT_STATUS=$(qstat -f $JOBID | awk '/exit_status/''{print $3}') - echo ">> Exit Status: $JOB_EXIT_STATUS" - exit $JOB_EXIT_STATUS - ;; - E) - echo ">> Job $JOBID ERROR!?" - - JOB_EXIT_STATUS=$(qstat -f $JOBID | awk '/exit_status/''{print $3}') - echo ">> Exit Status: $JOB_EXIT_STATUS" - exit $JOB_EXIT_STATUS - ;; - R) - echo ">> Job $JOBID RUNNING" - break 1 - ;; - *) - sleep 10 - echo ">> Job $JOBID QUEUED. Waiting." - ;; - esac - - if [[ $n -gt $TIMEOUT ]] - then - echo ">> EXIT: Timeout Exceeded!" - exit 1 - fi - n=$(echo "$n+1" | bc -l) - done - - #tail -n +1 -F out.log & - #PID=$! - while : - do - JOB_STATUS=$(qstat $JOBID | awk 'NR==3''{print $5}') - STATUS=${JOB_STATUS:=E} - #echo "STATUS = '$STATUS'" - case "$STATUS" in - C) - sleep 10 - echo ">> Job COMPLETED!" - JOB_EXIT_STATUS=$(qstat -f $JOBID | awk '/exit_status/''{print $3}') - echo ">> Exit Status: $JOB_EXIT_STATUS" - kill -9 $PID - exit $JOB_EXIT_STATUS - ;; - E) - echo ">> Job $JOBID ERROR!?" - - JOB_EXIT_STATUS=$(qstat -f $JOBID | awk '/exit_status/''{print $3}') - echo ">> Exit Status: $JOB_EXIT_STATUS" - exit $JOB_EXIT_STATUS - ;; - *) - sleep 10 - echo ">> Job RUNNING." - ;; - esac - done -} - -check_command() { - echo -n "Check command '$1': " - # Check if pbs commands are available - command -v $1 >/dev/null 2>&1 || { echo >&2 "Not installed! Aborting."; exit 1; } - echo "OK" -} - -do_launch() { - check_command "qsub" - check_command "qdel" - check_command "qstat" - - # Submit ELEMENTS job to PBS queue system - qsub < driver.pbs > JOBID.log - - setJobId - echo ">> Job SUBMITTED." -} - -case "$1" in - -kill) - HEADER - setJobId - do_kill - ;; - -launch) - HEADER - do_launch - do_monitor - ;; - -monitor) - HEADER - setJobId - do_monitor - ;; - *) - HEADER - do_launch - do_monitor - ;; -esac - -echo "Fail: Unexpected termination" -exit 1 \ No newline at end of file diff --git a/src/eu/engys/standardDynamic/StandardDynamicModule.java b/src/eu/engys/standardDynamic/StandardDynamicModule.java new file mode 100644 index 0000000..49bfac3 --- /dev/null +++ b/src/eu/engys/standardDynamic/StandardDynamicModule.java @@ -0,0 +1,57 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.standardDynamic; + +import java.util.HashSet; +import java.util.Set; + +import javax.inject.Inject; + +import eu.engys.core.modules.ModulePanel; +import eu.engys.core.project.Model; +import eu.engys.dynamic.DynamicModule; +import eu.engys.standardDynamic.cellzones.StandardDynamicCellZonesView; +import eu.engys.standardDynamic.domain.StandardSolidBodyDynamicPanel; + +public class StandardDynamicModule extends DynamicModule { + + @Inject + public StandardDynamicModule(Model model) { + super(model); + this.cellZonesView = new StandardDynamicCellZonesView(model, this); + this.solutionView = new StandardDynamicSolutionView(model, this); + this.solidBodyPanel = new StandardSolidBodyDynamicPanel(model, this); + this.treeView = new StandardDynamicTreeView(this, sixDoFPanel, solidBodyPanel); + } + + @Override + public Set getCaseSetupPanels() { + Set panels = new HashSet<>(); + panels.add(sixDoFPanel); + panels.add(solidBodyPanel); + return panels; + } + +} diff --git a/src/eu/engys/standardDynamic/StandardDynamicSolutionView.java b/src/eu/engys/standardDynamic/StandardDynamicSolutionView.java new file mode 100644 index 0000000..ae6cddb --- /dev/null +++ b/src/eu/engys/standardDynamic/StandardDynamicSolutionView.java @@ -0,0 +1,58 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.standardDynamic; + +import javax.swing.JRadioButton; + +import eu.engys.core.project.Model; +import eu.engys.dynamic.DynamicModule; +import eu.engys.dynamic.DynamicSolutionView; +import eu.engys.util.ui.builder.PanelBuilder; + +public class StandardDynamicSolutionView extends DynamicSolutionView { + + public StandardDynamicSolutionView(Model model, DynamicModule module) { + super(model, module); + } + + @Override + public void buildDynamic(PanelBuilder builder) { + this.panel = new StandardDynamicPanel(); + builder.addFill(panel); + } + + private class StandardDynamicPanel extends DynamicPanel { + + @Override + protected void addChoices() { + JRadioButton offChoice = addChoice(OFF_LABEL); + offChoice.setName(DYNAMIC_OFF_NAME); + addChoice(SIX_DOF_LABEL); + addChoice(SOLID_RIGID_BODY_LABEL); + addChoice(MULTI_RIGID_BODY_LABEL); + } + } + +} diff --git a/src/eu/engys/standardDynamic/StandardDynamicTreeView.java b/src/eu/engys/standardDynamic/StandardDynamicTreeView.java new file mode 100644 index 0000000..fa9174a --- /dev/null +++ b/src/eu/engys/standardDynamic/StandardDynamicTreeView.java @@ -0,0 +1,61 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.standardDynamic; + +import eu.engys.core.modules.tree.AbstractTreeViewAdapter; +import eu.engys.core.modules.tree.ModuleElementPanel; +import eu.engys.dynamic.DynamicModule; +import eu.engys.gui.GUIPanel; + +public class StandardDynamicTreeView extends AbstractTreeViewAdapter { + + private DynamicModule module; + + private GUIPanel sixDoFPanel; + private GUIPanel solidBodyPanel; + + public StandardDynamicTreeView(DynamicModule module, GUIPanel sixDoFPanel, GUIPanel solidBodyPanel) { + this.module = module; + this.sixDoFPanel = sixDoFPanel; + this.solidBodyPanel = solidBodyPanel; + } + + @Override + public void updateCaseSetupTree(ModuleElementPanel viewElementPanel) { + if (module.getDynamicData().getAlgorithm().getType().isSolidRigidBody()) { + viewElementPanel.removePanel(sixDoFPanel); + viewElementPanel.addPanel(solidBodyPanel); + solidBodyPanel.load(); + } else if (module.getDynamicData().getAlgorithm().getType().is6DOF()) { + viewElementPanel.removePanel(solidBodyPanel); + viewElementPanel.addPanel(sixDoFPanel); + sixDoFPanel.load(); + } else { + viewElementPanel.removePanel(solidBodyPanel); + viewElementPanel.removePanel(sixDoFPanel); + } + } + +} diff --git a/src/eu/engys/standardDynamic/cellzones/StandardDynamicCellZonesView.java b/src/eu/engys/standardDynamic/cellzones/StandardDynamicCellZonesView.java new file mode 100644 index 0000000..de0f56d --- /dev/null +++ b/src/eu/engys/standardDynamic/cellzones/StandardDynamicCellZonesView.java @@ -0,0 +1,48 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.standardDynamic.cellzones; + +import java.util.ArrayList; +import java.util.List; + +import eu.engys.core.project.Model; +import eu.engys.core.project.zero.cellzones.CellZoneType; +import eu.engys.dynamic.DynamicModule; +import eu.engys.dynamic.cellzones.DynamicCellZonesView; + +public class StandardDynamicCellZonesView extends DynamicCellZonesView { + + public StandardDynamicCellZonesView(Model model, DynamicModule module) { + super(model, module); + } + + @Override + public List getCellZoneTypes() { + List types = new ArrayList(); + types.add(new StandardDynamicMesh(model, module)); + return types; + } + +} diff --git a/src/eu/engys/standardDynamic/cellzones/StandardDynamicMesh.java b/src/eu/engys/standardDynamic/cellzones/StandardDynamicMesh.java new file mode 100644 index 0000000..35be5d7 --- /dev/null +++ b/src/eu/engys/standardDynamic/cellzones/StandardDynamicMesh.java @@ -0,0 +1,43 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.standardDynamic.cellzones; + +import eu.engys.core.modules.cellzones.CellZonePanel; +import eu.engys.core.project.Model; +import eu.engys.dynamic.DynamicModule; +import eu.engys.dynamic.cellzones.DynamicMesh; + +public class StandardDynamicMesh extends DynamicMesh { + + + public StandardDynamicMesh(Model model, DynamicModule module) { + super(model, module); + } + + protected CellZonePanel createCellZonePanel(){ + return new StandardMultiBodyDynamicMeshPanel(model, module); + } + +} diff --git a/src/eu/engys/standardDynamic/cellzones/StandardMultiBodyDynamicMeshPanel.java b/src/eu/engys/standardDynamic/cellzones/StandardMultiBodyDynamicMeshPanel.java new file mode 100644 index 0000000..923bb30 --- /dev/null +++ b/src/eu/engys/standardDynamic/cellzones/StandardMultiBodyDynamicMeshPanel.java @@ -0,0 +1,44 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.standardDynamic.cellzones; + +import eu.engys.core.project.Model; +import eu.engys.dynamic.DynamicModule; +import eu.engys.dynamic.cellzones.MultiBodyDynamicMeshPanel; +import eu.engys.dynamic.domain.SolidBodyDynamicPanel; +import eu.engys.standardDynamic.domain.StandardSolidBodyDynamicPanel; + +public class StandardMultiBodyDynamicMeshPanel extends MultiBodyDynamicMeshPanel { + + public StandardMultiBodyDynamicMeshPanel(Model model, DynamicModule module) { + super(model, module); + } + + @Override + protected SolidBodyDynamicPanel createSolidBodyPanel() { + return new StandardSolidBodyDynamicPanel(model, module); + } + +} diff --git a/src/eu/engys/standardDynamic/domain/StandardSolidBodyDynamicPanel.java b/src/eu/engys/standardDynamic/domain/StandardSolidBodyDynamicPanel.java new file mode 100644 index 0000000..dc10c2e --- /dev/null +++ b/src/eu/engys/standardDynamic/domain/StandardSolidBodyDynamicPanel.java @@ -0,0 +1,59 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.standardDynamic.domain; + +import eu.engys.core.project.Model; +import eu.engys.dynamic.DynamicModule; +import eu.engys.dynamic.domain.SolidBodyDynamicPanel; +import eu.engys.util.bean.BeanModel; +import eu.engys.util.bean.BeanPanelBuilder; + +public class StandardSolidBodyDynamicPanel extends SolidBodyDynamicPanel { + + public StandardSolidBodyDynamicPanel(Model model, DynamicModule module) { + super(model, module); + } + + @Override + protected BeanModel[] getBeanModels(){ + BeanModel[] models = new BeanModel[5]; + models[0] = linearMotionModel; + models[1] = rotatingMotionModel; + models[2] = oscillatingLinearMotionModel; + models[3] = oscillatingRotatingMotionModel; + models[4] = sdaMotionModel; + return models; + } + + @Override + protected void addEngysTypes(BeanPanelBuilder builder) { + } + + @Override + public void stateChanged() { + typeCombo.clearDisabledIndexes(); + } + +} diff --git a/src/eu/engys/standardDynamic/resources/dynamic.fields b/src/eu/engys/standardDynamic/resources/dynamic.fields new file mode 100644 index 0000000..3e7602e --- /dev/null +++ b/src/eu/engys/standardDynamic/resources/dynamic.fields @@ -0,0 +1,179 @@ +displacement +{ + allowedFieldInitialisationMethods (fixedValue); + + initialisation + { + type fixedValue; + value uniform (0 0 0); + } + + + fieldDefinition + { + type vector; + meshType point; + dimensions [ 0 1 0 0 0 0 0 ]; + internalField uniform (0 0 0); + + boundaryConditions + { + regionDefaults + { + wall + { + type fixedValue; + value uniform (0 0 0); + } + + mappedWall + { + type fixedValue; + value uniform (0 0 0); + } + + outlet + { + type fixedValue; + value uniform (0 0 0); + } + + inlet + { + type fixedValue; + value uniform (0 0 0); + } + + patch + { + type fixedValue; + value uniform (0 0 0); + } + } + + partialNamed {} + + exactNamed{} + } + } +} +motion +{ + allowedFieldInitialisationMethods (fixedValue); + + initialisation + { + type fixedValue; + value uniform (0 0 0); + } + + + fieldDefinition + { + type point; + meshType point; + dimensions [ 0 1 -1 0 0 0 0 ]; + internalField uniform (0 0 0); + + boundaryConditions + { + regionDefaults + { + wall + { + type fixedValue; + value uniform (0 0 0); + } + + mappedWall + { + type fixedValue; + value uniform (0 0 0); + } + + outlet + { + type fixedValue; + value uniform (0 0 0); + } + + inlet + { + type fixedValue; + value uniform (0 0 0); + } + + patch + { + type fixedValue; + value uniform (0 0 0); + } + } + + partialNamed {} + + exactNamed{} + } + } +} +pmultiphaseDyM +{ + allowedFieldInitialisationMethods (default fixedValue potentialFlow boundaryValue cellSet ); + + initialisation + { + type default; + } + + + fieldDefinition + { + type scalar; + dimensions [ 1 -1 -2 0 0 0 0 ]; + internalField uniform 0; + + boundaryConditions + { + regionDefaults + { + wall + { + type zeroGradient; + //type fixedFluxPressure; + //value uniform 0; + //phi phiAbs; + } + mappedWall + { + type zeroGradient; + //type fixedFluxPressure; + //value uniform 0; + //phi phiAbs; + } + + outlet {type fixedValue; value uniform 0;} + + inlet + { + type zeroGradient; + //type fixedFluxPressure; + //value uniform 0; + //phi phiAbs; + } + + patch + { + type totalPressure; + p0 uniform 0; + U U; + value uniform 0; + gamma 1.4; + } + } + + partialNamed {} + + exactNamed{} + } + } +} \ No newline at end of file diff --git a/src/eu/engys/standardDynamic/resources/dynamic.stateData b/src/eu/engys/standardDynamic/resources/dynamic.stateData new file mode 100644 index 0000000..38cae8a --- /dev/null +++ b/src/eu/engys/standardDynamic/resources/dynamic.stateData @@ -0,0 +1,178 @@ +states +{ + pimpleFoamRAS (PIMPLE incompressible ras); + pimpleFoamLES (PIMPLE incompressible les); + + rhoPimpleFoamRAS (PIMPLE compressible ras); + rhoPimpleFoamLES (PIMPLE compressible les); + + interFoamRAS (PIMPLE incompressible ras VOF); + interFoamLES (PIMPLE incompressible les VOF); +} + +"pimpleFoam.*" {$dynamic;} +"rhoPimpleFoam.*" {$rhodynamic;} +"interFoam.*" {$dynamic;} + +dynamic +{ + fieldMaps + { + pointMotionU motion; + pointDisplacement displacement; + p_rgh pmultiphaseDyM; + } + + system + { + fvSchemes + { + laplacianSchemes + { + laplacian(diffusivity,cellDisplacement) Gauss linear uncorrected; + laplacian(diffusivity,cellMotionU) Gauss linear uncorrected; + } + fluxRequired + { + pcorr ; + } + } + fvSolution + { + solvers + { + pcorr + { + solver GAMG; + agglomerator faceAreaPair; + mergeLevels 1; + cacheAgglomeration true; + nCellsInCoarsestLevel 200; + tolerance 1e-10; + relTol 0.01; + smoother GaussSeidel; + nPreSweeps 0; + nPostSweeps 2; + nFinestSweeps 2; + minIter 1; + } + cellMotionU + { + solver PCG; + preconditioner DIC; + tolerance 1e-08; + relTol 0; + minIter 1; + } + cellDisplacement + { + solver GAMG; + tolerance 1e-08; + relTol 0; + smoother GaussSeidel; + cacheAgglomeration true; + nCellsInCoarsestLevel 10; + agglomerator faceAreaPair; + mergeLevels 1; + minIter 1; + } + + } + + PIMPLE + { + correctPhi true; + turbOnFinalIterOnly false; + //ddtPhiCorr true; + } + } + + controlDict + { + } + } + + constant {} + +} + +rhodynamic +{ + fieldMaps + { + pointMotionU motion; + pointDisplacement displacement; + } + + system + { + fvSchemes + { + laplacianSchemes + { + laplacian(diffusivity,cellDisplacement) Gauss linear uncorrected; + laplacian(diffusivity,cellMotionU) Gauss linear uncorrected; + } + fluxRequired + { + pcorr ; + } + } + fvSolution + { + solvers + { + pcorr + { + solver GAMG; + agglomerator faceAreaPair; + mergeLevels 1; + cacheAgglomeration true; + nCellsInCoarsestLevel 200; + tolerance 1e-10; + relTol 0.01; + smoother GaussSeidel; + nPreSweeps 0; + nPostSweeps 2; + nFinestSweeps 2; + minIter 1; + } + cellMotionU + { + solver PCG; + preconditioner DIC; + tolerance 1e-08; + relTol 0; + minIter 1; + } + cellDisplacement + { + solver GAMG; + tolerance 1e-08; + relTol 0; + smoother GaussSeidel; + cacheAgglomeration true; + nCellsInCoarsestLevel 10; + agglomerator faceAreaPair; + mergeLevels 1; + minIter 1; + } + + } + + PIMPLE + { + correctPhi true; + turbOnFinalIterOnly false; + //ddtPhiCorr true; + } + } + + controlDict + { + } + } + + constant {} + +} \ No newline at end of file diff --git a/src/eu/engys/standardDynamic/resources/dynamicMeshDict b/src/eu/engys/standardDynamic/resources/dynamicMeshDict new file mode 100644 index 0000000..a39c62b --- /dev/null +++ b/src/eu/engys/standardDynamic/resources/dynamicMeshDict @@ -0,0 +1 @@ +dynamicFvMesh staticFvMesh; diff --git a/src/eu/engys/standardVOF/StandardVOFBoundaryConditionsView.java b/src/eu/engys/standardVOF/StandardVOFBoundaryConditionsView.java index 568c422..15b5d55 100644 --- a/src/eu/engys/standardVOF/StandardVOFBoundaryConditionsView.java +++ b/src/eu/engys/standardVOF/StandardVOFBoundaryConditionsView.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.standardVOF; import eu.engys.core.modules.boundaryconditions.BoundaryConditionsView; @@ -32,10 +31,11 @@ import eu.engys.core.project.Model; import eu.engys.core.project.zero.patches.BoundaryType; import eu.engys.gui.casesetup.boundaryconditions.panels.patch.MomentumPatch; import eu.engys.gui.casesetup.boundaryconditions.panels.wall.StandardMomentumWall; +import eu.engys.gui.casesetup.boundaryconditions.parameterspanel.MomentumParametersPanel; public class StandardVOFBoundaryConditionsView implements BoundaryConditionsView { - private static final String MOMENTUM = " " + BoundaryTypePanel.MOMENTUM + " "; + public static final String MOMENTUM = " " + MomentumParametersPanel.MOMENTUM + " "; private StandardVOFModule module; public StandardVOFBoundaryConditionsView(StandardVOFModule module) { diff --git a/src/eu/engys/standardVOF/StandardVOFModule.java b/src/eu/engys/standardVOF/StandardVOFModule.java index cabe261..179d176 100644 --- a/src/eu/engys/standardVOF/StandardVOFModule.java +++ b/src/eu/engys/standardVOF/StandardVOFModule.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.standardVOF; import java.util.HashSet; @@ -52,10 +51,12 @@ public class StandardVOFModule extends ApplicationModuleAdapter { private static final String MODULE_NAME = "standardVOF"; + public static final Solver INTER_FOAM = new Solver("interFoam"); + public static final Solver INTER_DYM_FOAM = new Solver("interDyMFoam"); + public static final String VOF_LABEL = "VOF"; public static final String VOF_KEY = "VOF"; - - public static final Solver INTER_FOAM = new Solver("interFoam"); + public static final MultiphaseModel VOF_MODEL = new MultiphaseModel(VOF_LABEL, VOF_KEY, true, true); private StandardVOFSolutionView solutionView; @@ -67,8 +68,8 @@ public class StandardVOFModule extends ApplicationModuleAdapter { private double sigma; private Model model; - private DefaultsProvider defaults; + private StandardVOFReader reader; @Inject @@ -118,10 +119,14 @@ public class StandardVOFModule extends ApplicationModuleAdapter { @Override public void updateSolver(State state) { - if (state.isTransient()) { + if (state.getMultiphaseModel().equals(VOF_MODEL)) { if (state.isIncompressible()) { - if (state.getMultiphaseModel().equals(VOF_MODEL)) { - state.setSolver(INTER_FOAM); + if (state.isTransient()) { + if (state.isDynamic()) { + state.setSolver(INTER_DYM_FOAM); + } else { + state.setSolver(INTER_FOAM); + } } } } @@ -142,10 +147,6 @@ public class StandardVOFModule extends ApplicationModuleAdapter { new StandardVOFWriter(model, this).write(); } - @Override - public void write() { - } - @Override public void saveDefaultsToProject() { if (isVOF()) { @@ -157,7 +158,7 @@ public class StandardVOFModule extends ApplicationModuleAdapter { @Override public Fields loadDefaultsFields(String region) { if (isVOF()) { - return FieldsDefaults.loadFieldsFromDefaults(model.getState(), defaults, model.getPatches(), region); + return FieldsDefaults.loadFieldsFromDefaults(model.getProject().getBaseDir(), model.getState(), defaults, model.getPatches(), region); } else { return new Fields(); } diff --git a/src/eu/engys/standardVOF/StandardVOFPhasesView.java b/src/eu/engys/standardVOF/StandardVOFPhasesView.java index dcfbb5c..929bffd 100644 --- a/src/eu/engys/standardVOF/StandardVOFPhasesView.java +++ b/src/eu/engys/standardVOF/StandardVOFPhasesView.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.standardVOF; import static eu.engys.core.project.constant.TransportProperties.SIGMA_KEY; diff --git a/src/eu/engys/standardVOF/StandardVOFReader.java b/src/eu/engys/standardVOF/StandardVOFReader.java index 40e7111..0e79a26 100644 --- a/src/eu/engys/standardVOF/StandardVOFReader.java +++ b/src/eu/engys/standardVOF/StandardVOFReader.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.standardVOF; import static eu.engys.core.project.constant.ThermophysicalProperties.MATERIAL_NAME_KEY; @@ -38,6 +37,7 @@ import eu.engys.core.project.constant.ConstantFolder; import eu.engys.core.project.constant.TransportProperties; import eu.engys.core.project.materials.Material; import eu.engys.core.project.materials.Materials; +import eu.engys.gui.casesetup.materials.StandardMaterialsReader; public class StandardVOFReader { @@ -54,14 +54,14 @@ public class StandardVOFReader { } public void loadState() { - if (isVOF()) { + if (isMultiphaseVOF()) { model.getState().setMultiphaseModel(StandardVOFModule.VOF_MODEL); model.getState().setPhases(2); } } public void loadMaterials() { - if (isVOF()) { + if (isMultiphaseVOF()) { if (model.getState().isIncompressible()) { readIncompressibleMaterials(); } else { @@ -70,7 +70,7 @@ public class StandardVOFReader { } } - boolean isVOF() { + private boolean isMultiphaseVOF() { ConstantFolder constantFolder = model.getProject().getConstantFolder(); TransportProperties transportProperties = constantFolder.getTransportProperties(); if (transportProperties != null) { @@ -101,7 +101,8 @@ public class StandardVOFReader { } String name1 = dict1.lookup(MATERIAL_NAME_KEY); dict1.setName(name1); - materials.add(new Material(name1, dict1)); + Material m1 = new StandardMaterialsReader().readIncompressibleMaterial(dict1); + materials.add(m1); } Dictionary dict2 = new Dictionary(transportProperties.subDict(phases.split(" ")[1])); @@ -111,7 +112,8 @@ public class StandardVOFReader { } String name2 = dict2.lookup(MATERIAL_NAME_KEY); dict2.setName(name2); - materials.add(new Material(name2, dict2)); + Material m2 = new StandardMaterialsReader().readIncompressibleMaterial(dict2); + materials.add(m2); } if (transportProperties.found(SIGMA_KEY)) { diff --git a/src/eu/engys/standardVOF/StandardVOFSolutionView.java b/src/eu/engys/standardVOF/StandardVOFSolutionView.java index d059de6..3f9116c 100644 --- a/src/eu/engys/standardVOF/StandardVOFSolutionView.java +++ b/src/eu/engys/standardVOF/StandardVOFSolutionView.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.standardVOF; import org.slf4j.Logger; diff --git a/src/eu/engys/standardVOF/StandardVOFTreeView.java b/src/eu/engys/standardVOF/StandardVOFTreeView.java index 50b5f4f..22358f0 100644 --- a/src/eu/engys/standardVOF/StandardVOFTreeView.java +++ b/src/eu/engys/standardVOF/StandardVOFTreeView.java @@ -1,36 +1,35 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.standardVOF; import eu.engys.core.modules.ModulePanel; +import eu.engys.core.modules.tree.AbstractTreeViewAdapter; import eu.engys.core.modules.tree.ModuleElementPanel; -import eu.engys.core.modules.tree.TreeView; import eu.engys.gui.casesetup.phases.PhasesPanel; -public class StandardVOFTreeView implements TreeView { +public class StandardVOFTreeView extends AbstractTreeViewAdapter { private StandardVOFModule module; private ModulePanel phasesPanel; @@ -41,7 +40,7 @@ public class StandardVOFTreeView implements TreeView { } @Override - public void updateTree(ModuleElementPanel viewElementPanel) { + public void updateCaseSetupTree(ModuleElementPanel viewElementPanel) { if (module.isVOF()) { viewElementPanel.addPanel(phasesPanel); } else { diff --git a/src/eu/engys/standardVOF/StandardVOFWriter.java b/src/eu/engys/standardVOF/StandardVOFWriter.java index aa15350..5814e11 100644 --- a/src/eu/engys/standardVOF/StandardVOFWriter.java +++ b/src/eu/engys/standardVOF/StandardVOFWriter.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.standardVOF; import static eu.engys.core.project.constant.TransportProperties.PHASES_KEY; @@ -38,6 +37,7 @@ import eu.engys.core.project.constant.ConstantFolder; import eu.engys.core.project.constant.TransportProperties; import eu.engys.core.project.materials.Material; import eu.engys.core.project.materials.Materials; +import eu.engys.gui.casesetup.materials.StandardMaterialsWriter; public class StandardVOFWriter { @@ -81,12 +81,12 @@ public class StandardVOFWriter { transportProperties.add(PHASES_KEY, "(" + mat1Name + " " + mat2Name + ")"); - Dictionary dict1 = new Dictionary(mat1.getDictionary()); + Dictionary dict1 = new StandardMaterialsWriter(model).writeSingle_IncompressibleMaterial(mat1); dict1.remove(SIGMA_KEY); dict1.setName(mat1Name); transportProperties.add(dict1); - Dictionary dict2 = new Dictionary(mat2.getDictionary()); + Dictionary dict2 = new StandardMaterialsWriter(model).writeSingle_IncompressibleMaterial(mat2); dict2.remove(SIGMA_KEY); dict2.setName(mat2Name); transportProperties.add(dict2); diff --git a/src/eu/engys/standardVOF/resources/standardVOF.fields b/src/eu/engys/standardVOF/resources/standardVOF.fields index 6a910a8..8018a11 100644 --- a/src/eu/engys/standardVOF/resources/standardVOF.fields +++ b/src/eu/engys/standardVOF/resources/standardVOF.fields @@ -1,6 +1,6 @@ U { - allowedFieldInitialisationMethods (default fixedValue ); + allowedFieldInitialisationMethods (default fixedValue potentialFlow); initialisation { @@ -38,7 +38,7 @@ U pmultiphase { - allowedFieldInitialisationMethods (default fixedValue ); + allowedFieldInitialisationMethods (default fixedValue potentialFlow); initialisation { diff --git a/src/eu/engys/standardVOF/resources/standardVOF.stateData b/src/eu/engys/standardVOF/resources/standardVOF.stateData index 4e7dffb..76c7103 100644 --- a/src/eu/engys/standardVOF/resources/standardVOF.stateData +++ b/src/eu/engys/standardVOF/resources/standardVOF.stateData @@ -114,7 +114,7 @@ states $fvSolution_solvers_PIMPLE; - pcorr + "pcorr.*" { solver PCG; preconditioner @@ -200,12 +200,15 @@ states runTimeModifiable yes; adjustTimeStep yes; maxCo 0.5; - maxAlphaCo 0.25; + maxAlphaCo 0.2; maxDeltaT 1.0; } fvSchemes { - ddtSchemes {$fvSchemes_ddtSchemes_les;} + ddtSchemes + { + default CrankNicolson 0.9; + } gradSchemes { @@ -242,9 +245,6 @@ states nCorrectors 5; nOuterCorrectors 1; nNonOrthogonalCorrectors 1; - nAlphaCorr 1; - nAlphaSubCycles 5; - cAlpha 1.5; correctPhi yes; pRefCell 0; pRefValue 0; @@ -266,7 +266,7 @@ states } solvers { - pcorr + "pcorr.*" { solver PCG; preconditioner @@ -449,8 +449,8 @@ states relTol 0; nSweeps 1; minIter 1; - nAlphaCorr 1; - nAlphaSubCycles 3; + nAlphaCorr 2; + nAlphaSubCycles 1; cAlpha 1.5; } } diff --git a/src/eu/engys/suite/Suite.java b/src/eu/engys/suite/Suite.java index 34058ce..029ccd9 100644 --- a/src/eu/engys/suite/Suite.java +++ b/src/eu/engys/suite/Suite.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.suite; @@ -63,11 +62,11 @@ public class Suite { return applications; } - public void batch() { + public void batch(Arguments arguments) { // if (applications.size() == 1) { try { ApplicationLauncher application = applications.iterator().next(); - application.batch(); + application.batch(arguments); } catch (Exception e) { e.printStackTrace(); System.exit(-1); @@ -78,29 +77,29 @@ public class Suite { // } } - public void launch() { + public void launch(final Arguments arguments) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { - if (applications.size() == 1 || Arguments.baseDir != null) { + if (applications.size() == 1 || arguments.baseDir != null) { try { ApplicationLauncher application = applications.iterator().next(); application.checkLicense(); - application.launch(); + application.launch(arguments); } catch (Exception e) { e.printStackTrace(); } } else { - JFrame frame = createAndShowFrame(); + JFrame frame = createAndShowFrame(arguments); UiUtil.centerAndShow(frame); } } }); } - protected JFrame createAndShowFrame() { + protected JFrame createAndShowFrame(Arguments arguments) { JFrame frame = new JFrame(product); - List actions = createActions(); + List actions = createActions(arguments); frame.getContentPane().setLayout(new BorderLayout()); frame.getContentPane().add(new SuitePanel(actions, "Select Application"), BorderLayout.CENTER); @@ -110,7 +109,7 @@ public class Suite { return frame; } - private List createActions() { + private List createActions(final Arguments arguments) { List actions = new ArrayList(); for (final ApplicationLauncher app : applications) { AbstractAction action = new AbstractAction(app.getTitle(), app.getIcon()) { @@ -122,7 +121,7 @@ public class Suite { public void run() { try { app.checkLicense(); - app.launch(); + app.launch(arguments); } catch (Exception e1) { e1.printStackTrace(); } diff --git a/src/eu/engys/suite/SuitePanel.java b/src/eu/engys/suite/SuitePanel.java index 829fb1c..b261e01 100644 --- a/src/eu/engys/suite/SuitePanel.java +++ b/src/eu/engys/suite/SuitePanel.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.suite; diff --git a/src/eu/engys/util/ApplicationInfo.java b/src/eu/engys/util/ApplicationInfo.java index b98f2a7..9f04999 100644 --- a/src/eu/engys/util/ApplicationInfo.java +++ b/src/eu/engys/util/ApplicationInfo.java @@ -1,29 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util; import java.io.File; @@ -38,6 +36,7 @@ import java.util.ResourceBundle; import java.util.Scanner; import org.apache.commons.io.FileUtils; +import org.slf4j.LoggerFactory; import eu.engys.util.ui.ASCIIArt; @@ -67,23 +66,23 @@ public class ApplicationInfo { private static String site; private static String copyright; - public static void init() { - try { - ResourceBundle version = ResourceBundle.getBundle("eu.engys.resources.version"); + public static void init() { + try { + ResourceBundle version = ResourceBundle.getBundle("eu.engys.resources.version"); name = version.getString(NAME_KEY); vendor = version.getString(VENDOR_KEY); mail = version.getString(MAIL_KEY); site = version.getString(SITE_KEY); copyright = version.getString(COPYRIGHT_KEY); - + String v = version.getString(VERSION_KEY); - - try (Scanner s = new Scanner(v)) { - s.useDelimiter("\\."); - versionNumber = s.next(); - majorNumber = s.next(); - minorNumber = s.next(); - } catch (Exception e) { + + try (Scanner s = new Scanner(v)) { + s.useDelimiter("\\."); + versionNumber = s.next(); + majorNumber = s.next(); + minorNumber = s.next(); + } catch (Exception e) { name = DEFAULT_NAME; vendor = DEFAULT_VENDOR; versionNumber = DEFAULT_NUMBER; @@ -92,11 +91,11 @@ public class ApplicationInfo { mail = DEFAULT_MAIL; site = DEFAULT_SITE; copyright = DEFAULT_COPYRIGHT; - } - + } + buildDate = version.getString(BUILD_KEY); - } catch (Exception e) { - e.printStackTrace(); + } catch (Exception e) { + LoggerFactory.getLogger(ApplicationInfo.class).warn(e.getMessage()); name = DEFAULT_NAME; vendor = DEFAULT_VENDOR; versionNumber = DEFAULT_NUMBER; @@ -105,12 +104,12 @@ public class ApplicationInfo { mail = DEFAULT_MAIL; site = DEFAULT_SITE; copyright = DEFAULT_COPYRIGHT; - } - } - - public static String getTitle() { + } + } + + public static String getTitle() { return name != null ? ASCIIArt.toAA(name) : ""; - } + } public static String getName() { return name != null ? name : DEFAULT_NAME; @@ -118,11 +117,11 @@ public class ApplicationInfo { public static String getLicenseServerName() { return name != null ? name + "_LICENSE_SERVER_NAME" : DEFAULT_NAME; - } + } public static String getLicenseServerPort() { return name != null ? name + "_LICENSE_SERVER_PORT" : DEFAULT_NAME; - } + } public static String getVendor() { return vendor != null ? vendor : DEFAULT_VENDOR; @@ -161,15 +160,15 @@ public class ApplicationInfo { } public static String getRootPath() { - URL appJarURL = ApplicationInfo.class.getProtectionDomain().getCodeSource().getLocation(); - File appJarFile; - try { - appJarFile = new File(appJarURL.toURI()); - } catch (URISyntaxException e) { - appJarFile = new File(appJarURL.getPath()); - } - return appJarFile.getParentFile().getParent(); - } + URL appJarURL = ApplicationInfo.class.getProtectionDomain().getCodeSource().getLocation(); + File appJarFile; + try { + appJarFile = new File(appJarURL.toURI()); + } catch (URISyntaxException e) { + appJarFile = new File(appJarURL.getPath()); + } + return appJarFile.getParentFile().getParent(); + } public static File getHome() { String userHome = FileUtils.getUserDirectoryPath(); @@ -189,8 +188,8 @@ public class ApplicationInfo { public static File getPrefsFile() { final File userHome = getHome(); - final File userPrefs = new File(userHome, "application.properties"); - return userPrefs; + final File userPrefs = new File(userHome, "application.properties"); + return userPrefs; } public static String getHeaderInfo() { @@ -209,7 +208,7 @@ public class ApplicationInfo { sb.append("\n SYSTEM"); sb.append("\n -----------------------------------------------------"); sb.append("\n Date: " + new SimpleDateFormat("EEE MMM dd HH:mm:ss z yyyy").format(new Date())); - sb.append("\n OS: " + System.getProperty("os.name") + " " + System.getProperty("os.version") + " " + System.getProperty("os.arch")); + sb.append("\n OS: " + getSystemPropertyOrEmpty(SystemEnv.OS_NAME) + " " + getSystemPropertyOrEmpty(SystemEnv.OS_VERSION) + " " + getSystemPropertyOrEmpty(SystemEnv.OS_ARCH)); sb.append("\n Language " + Locale.getDefault().getLanguage()); sb.append("\n Country " + Locale.getDefault().getCountry()); sb.append("\n"); @@ -225,33 +224,41 @@ public class ApplicationInfo { } sb.append("\n NETWORK"); sb.append("\n -----------------------------------------------------"); - sb.append("\n Hostname " + hostName); - sb.append("\n Ip " + hostIp); + sb.append("\n Hostname " + hostName); + sb.append("\n Ip " + hostIp); sb.append("\n"); sb.append("\n JAVA"); sb.append("\n -----------------------------------------------------"); - sb.append("\n Version " + System.getProperty("java.version")); - sb.append("\n Vendor " + System.getProperty("java.vendor")); - sb.append("\n Home " + System.getProperty("java.home")); - sb.append("\n ClassVersion " + System.getProperty("java.class.version")); - sb.append("\n ClassPath " + getClassPath()); + sb.append("\n Version " + getSystemPropertyOrEmpty(SystemEnv.JAVA_VERSION)); + sb.append("\n Vendor " + getSystemPropertyOrEmpty(SystemEnv.JAVA_VENDOR)); + sb.append("\n Home " + getSystemPropertyOrEmpty(SystemEnv.JAVA_HOME)); + sb.append("\n ClassVersion " + getSystemPropertyOrEmpty(SystemEnv.JAVA_CLASS_VERSION)); + sb.append("\n ClassPath " + getClassPath()); sb.append("\n"); sb.append("\n USER"); sb.append("\n -----------------------------------------------------"); - sb.append("\n Name " + System.getProperty("user.name")); - sb.append("\n Home " + System.getProperty("user.home")); - sb.append("\n Dir " + System.getProperty("user.dir")); - if (System.getProperty("license.status") != null) { - sb.append("\n LICENSE"); - sb.append("\n -----------------------------------------------------"); - sb.append("\n " + System.getProperty("license.status")); - sb.append("\n Register " + System.getProperty("license.register")); - sb.append("\n Exp. Date " + System.getProperty("license.exp.date")); - } + sb.append("\n Name " + getSystemPropertyOrEmpty(SystemEnv.USER_NAME)); + sb.append("\n Home " + getSystemPropertyOrEmpty(SystemEnv.USER_HOME)); + sb.append("\n Dir " + getSystemPropertyOrEmpty(SystemEnv.USER_DIR)); + sb.append("\n"); + sb.append("\n RMI"); + sb.append("\n -----------------------------------------------------"); + sb.append("\n Client Logging " + getSystemPropertyOrEmpty(SystemEnv.RMI_CLIENT_LOG)); + sb.append("\n Client Level " + getSystemPropertyOrEmpty(SystemEnv.RMI_CLIENT_LOG_LEVEL)); + sb.append("\n Server Logging " + getSystemPropertyOrEmpty(SystemEnv.RMI_SERVER_LOG)); + sb.append("\n Server Level " + getSystemPropertyOrEmpty(SystemEnv.RMI_SERVER_LOG_LEVEL)); + sb.append("\n Transport Level " + getSystemPropertyOrEmpty(SystemEnv.RMI_TRANSPORT_LOG_LEVEL)); + sb.append("\n Server Hostname " + getSystemPropertyOrEmpty(SystemEnv.RMI_SERVER_HOSTNAME)); + sb.append("\n"); return sb.toString(); } + + private static String getSystemPropertyOrEmpty(String propertyName){ + String prop = System.getProperty(propertyName); + return prop == null ? "-" : prop; + } public static String getClassPath() { - return System.getProperty("java.class.path").replace(File.pathSeparator, "\n "); + return System.getProperty(SystemEnv.JAVA_CLASS_PATH).replace(File.pathSeparator, "\n "); } } diff --git a/src/eu/engys/util/ArchiveUtils.java b/src/eu/engys/util/ArchiveUtils.java index 9fa5568..1ca33ef 100644 --- a/src/eu/engys/util/ArchiveUtils.java +++ b/src/eu/engys/util/ArchiveUtils.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util; import java.io.BufferedInputStream; @@ -54,6 +53,8 @@ import org.apache.commons.io.FilenameUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import eu.engys.util.progress.ProgressMonitor; + public class ArchiveUtils { private final static int BUFFER = 2048; @@ -92,11 +93,17 @@ public class ArchiveUtils { */ public static void zip(File zipFile, File... sourceFiles) { + zip(zipFile, null, sourceFiles); + } + + public static void zip(File zipFile, ProgressMonitor monitor, File... sourceFiles) { try { ZipArchiveOutputStream zOut = new ZipArchiveOutputStream(zipFile); + if (monitor != null) monitor.info("Creating archive " + zipFile.getName()); for (File file : sourceFiles) { - addToZipArchive(zOut, file, ""); + addToZipArchive(zOut, file, "", monitor); } + if (monitor != null) monitor.info("Done with " + zipFile.getName()); IOUtils.closeQuietly(zOut); } catch (IOException e) { logger.error("Error creating archive", e); @@ -274,13 +281,15 @@ public class ArchiveUtils { return isZip(file.getName()) || isGz(file.getName()) || isTarGz(file.getName()) || isTarBz2(file.getName()); } - private static void addToZipArchive(ArchiveOutputStream zOut, File fileToAdd, String basePath) throws IOException { + private static void addToZipArchive(ArchiveOutputStream zOut, File fileToAdd, String basePath, ProgressMonitor monitor) throws IOException { String entryName = basePath + fileToAdd.getName(); ArchiveEntry entry = new ZipArchiveEntry(fileToAdd, entryName); zOut.putArchiveEntry(entry); if (fileToAdd.isFile()) { + if (monitor != null) monitor.info(" -> " + entryName); + FileInputStream fInputStream = new FileInputStream(fileToAdd); IOUtils.copy(fInputStream, zOut); zOut.closeArchiveEntry(); @@ -288,7 +297,7 @@ public class ArchiveUtils { } else { zOut.closeArchiveEntry(); for (File child : fileToAdd.listFiles()) { - addToZipArchive(zOut, child, entryName + File.separator); + addToZipArchive(zOut, child, entryName + "/", monitor); } } } @@ -307,7 +316,7 @@ public class ArchiveUtils { } else { zOut.closeArchiveEntry(); for (File child : fileToAdd.listFiles()) { - addToTarArchive(zOut, child, entryName + File.separator); + addToTarArchive(zOut, child, entryName + "/"); } } } diff --git a/src/eu/engys/util/ColorUtil.java b/src/eu/engys/util/ColorUtil.java index e07c4f9..555b469 100644 --- a/src/eu/engys/util/ColorUtil.java +++ b/src/eu/engys/util/ColorUtil.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util; import java.awt.Color; @@ -53,8 +52,7 @@ public class ColorUtil { } public static Color getColor(int index) { - Color color = colors.size() > index ? colors.get(index) : null; - return color; + return colors.get(index % colors.size()); } } diff --git a/src/eu/engys/util/CompactCharSequence.java b/src/eu/engys/util/CompactCharSequence.java index ba2b094..28a5d9b 100644 --- a/src/eu/engys/util/CompactCharSequence.java +++ b/src/eu/engys/util/CompactCharSequence.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util; import java.io.Serializable; diff --git a/src/eu/engys/util/CompactStringBuilder.java b/src/eu/engys/util/CompactStringBuilder.java index fd2a247..64bc9dd 100644 --- a/src/eu/engys/util/CompactStringBuilder.java +++ b/src/eu/engys/util/CompactStringBuilder.java @@ -1,89 +1,67 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util; import java.util.Arrays; - public class CompactStringBuilder { - /** - * The value is used for character storage. - */ byte[] value; - /** - * The count is the number of characters used. - */ int count; - - /** - * Creates an CompactStringBuilder of 16 . - */ + public CompactStringBuilder() { value = new byte[16]; } - /** - * Creates an CompactStringBuilder of the specified capacity. - */ public CompactStringBuilder(int capacity) { - value = new byte[capacity]; + value = new byte[capacity]; } - + public int length() { return count; } - - public void append(String str) { - if (str == null) str = "null"; + + public void append(String str) { + if (str == null) + str = "null"; int len = str.length(); - + ensureCapacityInternal(count + len); - + CompactCharSequence compactString = new CompactCharSequence(str); compactString.getBytes(0, len, value, count); - - count += len; - } - - /** - * This method has the same contract as ensureCapacity, but is - * never synchronized. - */ + + count += len; + } + private void ensureCapacityInternal(int minimumCapacity) { - // overflow-conscious code if (minimumCapacity - value.length > 0) expandCapacity(minimumCapacity); } - /** - * This implements the expansion semantics of ensureCapacity with no - * size check or synchronization. - */ void expandCapacity(int minimumCapacity) { int newCapacity = value.length * 2 + 2; if (newCapacity - minimumCapacity < 0) @@ -95,13 +73,13 @@ public class CompactStringBuilder { } value = Arrays.copyOf(value, newCapacity); } - + @Override public String toString() { - return new CompactCharSequence(value, 0, count).toString(); + return new CompactCharSequence(value, 0, count).toString(); } - public CharSequence toCompactCharSequence() { - return new CompactCharSequence(value, 0, count); - } + public CharSequence toCompactCharSequence() { + return new CompactCharSequence(value, 0, count); + } } diff --git a/src/eu/engys/util/DialogExitStatus.java b/src/eu/engys/util/DialogExitStatus.java new file mode 100644 index 0000000..364a4f6 --- /dev/null +++ b/src/eu/engys/util/DialogExitStatus.java @@ -0,0 +1,43 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.util; + +public enum DialogExitStatus { + + OK, CANCEL, ERROR; + + public boolean isOK() { + return this == OK; + } + + public boolean isCancel() { + return this == CANCEL; + } + + public boolean isError() { + return this == ERROR; + } + +} diff --git a/src/eu/engys/util/DimensionalUnits.java b/src/eu/engys/util/DimensionalUnits.java index 7bab234..0cf8a7e 100644 --- a/src/eu/engys/util/DimensionalUnits.java +++ b/src/eu/engys/util/DimensionalUnits.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util; public class DimensionalUnits { @@ -43,6 +42,7 @@ public class DimensionalUnits { public static final String _K = "[0 0 0 -1 0 0 0]"; public static final String K = "[0 0 0 1 0 0 0]"; public static final String S = "[0 0 1 0 0 0 0]"; + public static final String M_S = "[0 1 -1 0 0 0 0]"; public static final String _M = "[0 -1 0 0 0 0 0]"; public static final String _M2 = "[0 -2 0 0 0 0 0]"; public static final String M2_S = "[0 2 -1 0 0 0 0]"; diff --git a/src/eu/engys/util/FormatUtil.java b/src/eu/engys/util/FormatUtil.java index f6bc9fb..22574d5 100644 --- a/src/eu/engys/util/FormatUtil.java +++ b/src/eu/engys/util/FormatUtil.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util; diff --git a/src/eu/engys/util/IOUtils.java b/src/eu/engys/util/IOUtils.java index 30c7a06..7833d52 100644 --- a/src/eu/engys/util/IOUtils.java +++ b/src/eu/engys/util/IOUtils.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util; import java.io.File; @@ -40,9 +39,9 @@ import org.slf4j.LoggerFactory; public class IOUtils { private static final Logger logger = LoggerFactory.getLogger(IOUtils.class); - - public static final String EOL = LineSeparator.UNIX.getSeparator(); - public static final String WIN_EOL = LineSeparator.DOS.getSeparator(); + + public static final String LNX_EOL = "\n"; + public static final String WIN_EOL = "\r\n"; /* * Write File @@ -59,13 +58,13 @@ public class IOUtils { } public static void writeStringToFile(File file, String text) { - String lineEnding = Util.isWindowsScriptStyle() ? WIN_EOL : EOL; + String lineEnding = Util.isWindowsScriptStyle() ? WIN_EOL : LNX_EOL; List lines = Arrays.asList(text.split(lineEnding)); writeLinesToFile(file, lines); } public static void writeLinesToFile(File file, List lines) { - String lineEnding = Util.isWindowsScriptStyle() ? WIN_EOL : EOL; + String lineEnding = Util.isWindowsScriptStyle() ? WIN_EOL : LNX_EOL; try { FileUtils.writeLines(file, null, lines, lineEnding); } catch (IOException e) { @@ -81,7 +80,7 @@ public class IOUtils { try { return FileUtils.readLines(file, (Charset) null); } catch (IOException e) { - logger.error("Error reading file {}: {} ", file, e.getMessage()); + logger.warn("Error reading file {}: {} ", file, e.getMessage()); } return Collections.emptyList(); } @@ -90,7 +89,7 @@ public class IOUtils { try { return FileUtils.readFileToString(file, (Charset) null); } catch (IOException e) { - logger.error("Error reading file {}: {} ", file, e.getMessage()); + logger.warn("Error reading file {}: {} ", file, e.getMessage()); } return ""; } @@ -98,7 +97,7 @@ public class IOUtils { public static String readStringFromStream(InputStream input) throws IOException { return org.apache.commons.io.IOUtils.toString(input); } - + public static File getSupportFile(File pwd) { String extension = Util.isWindows() ? ".bat" : ".run"; String name = "temp" + System.currentTimeMillis() + extension; diff --git a/src/eu/engys/util/LineSeparator.java b/src/eu/engys/util/LineSeparator.java deleted file mode 100644 index cbae5f5..0000000 --- a/src/eu/engys/util/LineSeparator.java +++ /dev/null @@ -1,64 +0,0 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - -package eu.engys.util; - -public enum LineSeparator { - - DOS("\r\n", "DOS (CR+LF)"), - UNIX("\n", "UNIX (LF)"), - MAC("\r", "Mac (CR)"), - PLATFORM_DEPENDENT(System.getProperty("line.separator"), "Platform dependent"); - - private String separator; - private String label; - - LineSeparator(String separator, String label) { - this.separator = separator; - this.label = label; - } - - public String getSeparator() { - return separator; - } - - public String getLabel() { - return label; - } - - public static LineSeparator getLineSeparator(String separator) { - for (LineSeparator lineSeparator : LineSeparator.values()) { - if (separator.equals(lineSeparator.getSeparator())) { - return lineSeparator; - } - } - throw new IllegalArgumentException("Unknown line separator: " + separator); - } - - public static LineSeparator getDefaultLineSeparator() { - return getLineSeparator(System.getProperty("line.separator")); - } - -} diff --git a/src/eu/engys/core/LoggerUtil.java b/src/eu/engys/util/LoggerUtil.java similarity index 60% rename from src/eu/engys/core/LoggerUtil.java rename to src/eu/engys/util/LoggerUtil.java index 3e9eec8..c62abe2 100644 --- a/src/eu/engys/core/LoggerUtil.java +++ b/src/eu/engys/util/LoggerUtil.java @@ -1,30 +1,28 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - - -package eu.engys.core; +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.util; import java.io.File; import java.io.IOException; @@ -37,42 +35,43 @@ import org.apache.log4j.PatternLayout; import org.apache.log4j.Priority; import org.apache.log4j.spi.LoggingEvent; -import eu.engys.util.Symbols; -import eu.engys.util.Util; - public class LoggerUtil { - public static void initLogger() { - if (Util.isWindows()) { - initNormalLogger(); - } else { - initColorLogger(); - } + public static void initLogger(Level level) { + if (Util.isWindows()) { + if(Util.isCygwin()){ + initColorLogger(level); + } else { + initNormalLogger(level); + } + } else { + initColorLogger(level); + } } - private static void initColorLogger() { + private static void initColorLogger(Level level) { org.apache.log4j.Logger.getRootLogger().addAppender(new ColorConsoleAppender(new PatternLayout("%6r - %-30.30t - %-5p %-30.30c{1} %x - %m%n"))); - org.apache.log4j.Logger.getRootLogger().setLevel(Arguments.logLevel); + org.apache.log4j.Logger.getRootLogger().setLevel(level); } - private static void initNormalLogger() { + private static void initNormalLogger(Level level) { org.apache.log4j.Logger.getRootLogger().addAppender(new ConsoleAppender(new PatternLayout("%6r - %-30.30t - %-5p %-30.30c{1} %x - %m%n"))); - org.apache.log4j.Logger.getRootLogger().setLevel(Arguments.logLevel); + org.apache.log4j.Logger.getRootLogger().setLevel(level); } - public static void initFlatLogger() { + public static void initFlatLogger(Level level) { org.apache.log4j.Logger.getRootLogger().addAppender(new ConsoleAppender(new PatternLayout("%-5p %m%n"))); - org.apache.log4j.Logger.getRootLogger().setLevel(Arguments.logLevel); + org.apache.log4j.Logger.getRootLogger().setLevel(level); } public static void initTestLogger() { - org.apache.log4j.Logger.getRootLogger().addAppender(new ConsoleAppender(new PatternLayout("%r [%t] %p %c %x - %m%n"))); - org.apache.log4j.Logger.getRootLogger().setLevel(Level.INFO); + initTestLogger(Level.INFO); } public static void initTestLogger(Level level) { org.apache.log4j.Logger.getRootLogger().addAppender(new ConsoleAppender(new PatternLayout("%r [%t] %p %c %x - %m%n"))); org.apache.log4j.Logger.getRootLogger().setLevel(level); + org.apache.log4j.Logger.getLogger("org.apache.sshd").setLevel(Level.OFF); } public static void initFileLogger(String file, Level level) throws IOException { @@ -122,7 +121,6 @@ public class LoggerUtil { super(layout); } - @Override protected void subAppend(LoggingEvent event) { this.qw.write(getColour(event.getLevel())); super.subAppend(event); diff --git a/src/eu/engys/util/MemoryWidget.java b/src/eu/engys/util/MemoryWidget.java index dd0808f..4b0adc0 100644 --- a/src/eu/engys/util/MemoryWidget.java +++ b/src/eu/engys/util/MemoryWidget.java @@ -1,27 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util; import java.awt.Color; @@ -131,7 +131,7 @@ public class MemoryWidget extends JComponent implements ActionListener { g2.setColor(progressBackground); g2.fillRect(insets.left, insets.top, (int) (width * fraction), height); - String str = (used / 1024 / 1024) + " / " + (max / 1024 / 1024) + " MB"; + String str = (used / 1024 / 1024) + " / " + (max / 1024 / 1024) + "MB"; FontRenderContext frc = new FontRenderContext(null, false, false); Rectangle2D bounds = g2.getFont().getStringBounds(str, frc); diff --git a/src/eu/engys/util/OpenFOAMCommands.java b/src/eu/engys/util/OpenFOAMCommands.java index 722aa32..85695d0 100644 --- a/src/eu/engys/util/OpenFOAMCommands.java +++ b/src/eu/engys/util/OpenFOAMCommands.java @@ -1,38 +1,44 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util; import static eu.engys.util.IOUtils.WIN_EOL; import java.io.File; +import java.util.ArrayList; +import java.util.List; +import java.util.Set; public class OpenFOAMCommands { + public static final String FRONTAL_AREA = "frontalArea"; + public static final String MOVE_TO_CASE_FOLDER_WIN = "cd /D \"%CASE%\""; + public static final String PARA_FOAM = "paraFoam"; private static final String _ALL_REGIONS = "-allRegions"; private static final String _NO_FUNCTION_OBJECTS = "-noFunctionObjects"; + private static final String _WRITE_P = "-writep"; private static final String _FORCE = "-force"; private static final String _CONSTANT = "-constant"; private static final String _ZERO_TIME = "-zeroTime"; @@ -40,10 +46,9 @@ public class OpenFOAMCommands { private static final String _OVERWRITE = "-overwrite"; private static final String _SCALE = "-scale"; private static final String _PARALLEL = "-parallel"; - + private static final String _TIME = "-time"; // Flag to solve a problem with mpirun on OpenSUSE 12.3 where a default file is not installed correctly private static final String _DEFAULT_HOST_FILE = PrefUtil.getBoolean(PrefUtil.DEFAULT_HOSTFILE_NONE) ? "--default-hostfile none" : ""; - private static final String GENVLIST = "-genvlist HOME,PATH,USERNAME,WM_PROJECT_DIR,WM_PROJECT_INST_DIR,WM_OPTIONS,FOAM_LIBBIN,FOAM_APPBIN,FOAM_USER_APPBIN,FOAM_CONFIG,MPI_BUFFER_SIZE"; private static final String CASE() { @@ -90,59 +95,98 @@ public class OpenFOAMCommands { } } + public static final String BLOCK_MESH_COMMAND = "blockMesh"; + public static final String CHECK_MESH_COMMAND = "checkMesh"; + public static final String CASE_SETUP_COMMAND = "caseSetup"; + public static final String DECOMPOSE_PAR_COMMAND = "decomposePar"; + public static final String EXTRUDE_TO_REGION_MESH_COMMAND = "extrudeToRegionMesh"; + public static final String FOAM_MESH_TO_FLUENT_COMMAND = "foamMeshToFluent"; + public static final String FOAM_TO_STAR_MESH_COMMAND = "foamToStarMesh"; + public static final String FLUENT_3D_MESH_TO_FOAM_COMMAND = "fluent3DMeshToFoam"; + public static final String MERGE_MESHES_COMMAND = "mergeMeshes"; + public static final String PAR_MAP_FIELDS_COMMAND = "parMapFields"; + public static final String POTENTIAL_FOAM_COMMAND = "potentialFoam"; + public static final String RECONSTRUCT_PAR_COMMAND = "reconstructPar"; + public static final String RECONSTRUCT_PAR_MESH_COMMAND = "reconstructParMesh"; + public static final String RENUMBER_MESH_COMMAND = "renumberMesh"; + public static final String STRETCH_MESH_COMMAND = "stretchMesh"; + public static final String SET_FIELDS_COMMAND = "setFields"; + public static final String SNAPPY_CHECK_MESH_COMMAND = "snappyCheckMesh"; + public static final String SNAPPY_HEX_MESH_COMMAND = "snappyHexMesh"; + /* * MESH Commands */ public static final String BLOCK_MESH() { - return COMMAND("blockMesh " + _BLOCK_MESH_DICT() + " " + _CASE(), _TEE_LOG()); + return COMMAND(BLOCK_MESH_COMMAND + " " + _BLOCK_MESH_DICT() + " " + _CASE(), _TEE_LOG()); } public static final String MERGE_MESHES(String filePath) { - return COMMAND("mergeMeshes " + _OVERWRITE + " " + _NO_FUNCTION_OBJECTS + " " + _CASE() + " " + CASE() + " \"" + filePath + "\"", _TEE_LOG()); + return COMMAND(MERGE_MESHES_COMMAND + " " + _OVERWRITE + " " + _NO_FUNCTION_OBJECTS + " " + _CASE() + " " + CASE() + " \"" + filePath + "\"", _TEE_LOG()); } public static final String RECONSTRUCT_PAR_MESH() { - return COMMAND("reconstructParMesh " + _NO_FUNCTION_OBJECTS + " " + _CASE(), _TEE_LOG()); + return COMMAND(RECONSTRUCT_PAR_MESH_COMMAND + " " + _NO_FUNCTION_OBJECTS + " " + _CASE(), _TEE_LOG()); } public static final String RECONSTRUCT_PAR_MESH_CONSTANT() { - return COMMAND("reconstructParMesh " + _NO_FUNCTION_OBJECTS + " " + _CASE() + " " + _CONSTANT, _TEE_LOG()); + return COMMAND(RECONSTRUCT_PAR_MESH_COMMAND + " " + _NO_FUNCTION_OBJECTS + " " + _CASE() + " " + _CONSTANT, _TEE_LOG()); } public static final String RECONSTRUCT_PAR_MESH_ALLREGIONS() { - return COMMAND("reconstructParMesh " + " " + _NO_FUNCTION_OBJECTS + " " + _CASE() + " " + _ALL_REGIONS, _TEE_LOG()); + return COMMAND(RECONSTRUCT_PAR_MESH_COMMAND + " " + _NO_FUNCTION_OBJECTS + " " + _CASE() + " " + _ALL_REGIONS, _TEE_LOG()); } public static final String RECONSTRUCT_PAR_MESH_CONSTANT_ALLREGIONS() { - return COMMAND("reconstructParMesh " + " " + _NO_FUNCTION_OBJECTS + " " + _CASE() + " " + _CONSTANT + " " + _ALL_REGIONS, _TEE_LOG()); + return COMMAND(RECONSTRUCT_PAR_MESH_COMMAND + " " + _NO_FUNCTION_OBJECTS + " " + _CASE() + " " + _CONSTANT + " " + _ALL_REGIONS, _TEE_LOG()); } public static final String CHECK_MESH_SERIAL() { - return COMMAND("checkMesh " + _CASE(), _TEE_LOG()); + return COMMAND(CHECK_MESH_COMMAND + " " + _CASE(), _TEE_LOG()); + } + + public static final String CHECK_MESH_SERIAL_CONSTANT() { + return COMMAND(CHECK_MESH_COMMAND + " " + _CONSTANT + " " + _CASE(), _TEE_LOG()); } public static final String CHECK_MESH_PARALLEL() { - return COMMAND(_MPI_NP() + " checkMesh " + _PARALLEL + " " + _CASE(), _TEE_LOG()); + return COMMAND(_MPI_NP() + " " + CHECK_MESH_COMMAND + " " + _PARALLEL + " " + _CASE(), _TEE_LOG()); + } + + public static final String CHECK_MESH_PARALLEL_CONSTANT() { + return COMMAND(_MPI_NP() + " " + CHECK_MESH_COMMAND + " " + _PARALLEL + " " + _CONSTANT + " " + _CASE(), _TEE_LOG()); + } + + public static final String STRETCH_MESH_SERIAL() { + return COMMAND(STRETCH_MESH_COMMAND + " " + " " + _NO_FUNCTION_OBJECTS + " " + _CASE(), _TEE_LOG()); + } + + public static final String STRETCH_MESH_PARALLEL() { + return COMMAND(_MPI_NP() + " " + STRETCH_MESH_COMMAND + " " + _NO_FUNCTION_OBJECTS + " " + _PARALLEL + " " + _CASE(), _TEE_LOG()); } public static final String SNAPPY_CHECK_MESH_SERIAL() { - return COMMAND("snappyCheckMesh -writeAllMetrics " + _CASE(), _TEE_LOG()); + return COMMAND(SNAPPY_CHECK_MESH_COMMAND + " -writeAllMetrics " + _CASE(), _TEE_LOG()); } public static final String SNAPPY_CHECK_MESH_PARALLEL() { - return COMMAND(_MPI_NP() + " snappyCheckMesh -writeAllMetrics " + _PARALLEL + " " + _CASE(), _TEE_LOG()); + return COMMAND(_MPI_NP() + " " + SNAPPY_CHECK_MESH_COMMAND + " -writeAllMetrics " + _PARALLEL + " " + _CASE(), _TEE_LOG()); } public static final String RUN_MESH_SERIAL() { - return COMMAND("snappyHexMesh " + _OVERWRITE + " " + _CASE(), _TEE_LOG()); + return COMMAND(SNAPPY_HEX_MESH_COMMAND + " " + _OVERWRITE + " " + _CASE(), _TEE_LOG()); } public static final String RUN_MESH_PARALLEL() { - return COMMAND(_MPI_NP() + " snappyHexMesh " + _PARALLEL + " " + _OVERWRITE + " " + _CASE(), _TEE_LOG()); + return COMMAND(_MPI_NP() + " " + SNAPPY_HEX_MESH_COMMAND + " " + _PARALLEL + " " + _OVERWRITE + " " + _CASE(), _TEE_LOG()); } + /* + * Fields + */ + public static final String EXTRUDE_REGION_TO_MESH() { - return COMMAND("extrudeToRegionMesh " + _OVERWRITE + " " + _NO_FUNCTION_OBJECTS + " " + _CASE(), _TEE_LOG()); + return COMMAND(EXTRUDE_TO_REGION_MESH_COMMAND + " " + _OVERWRITE + " " + _NO_FUNCTION_OBJECTS + " " + _CASE(), _TEE_LOG()); } /* @@ -156,81 +200,85 @@ public class OpenFOAMCommands { return COMMAND(_MPI_NP() + " " + SOLVER() + " " + _PARALLEL + " " + _CASE(), _TEE_LOG()); } - /* - * Fields - */ - public static final String SET_FIELDS_SERIAL() { - return COMMAND("setFields " + _NO_FUNCTION_OBJECTS + " " + _CASE(), _TEE_LOG()); + return COMMAND(SET_FIELDS_COMMAND + " " + _NO_FUNCTION_OBJECTS + " " + _CASE(), _TEE_LOG()); } public static final String SET_FIELDS_PARALLEL() { - return COMMAND(_MPI_NP() + " setFields " + _PARALLEL + " " + _NO_FUNCTION_OBJECTS + " " + _CASE(), _TEE_LOG()); + return COMMAND(_MPI_NP() + " " + SET_FIELDS_COMMAND + " " + _PARALLEL + " " + _NO_FUNCTION_OBJECTS + " " + _CASE(), _TEE_LOG()); + } + + public static final String POTENTIAL_FOAM_SERIAL(boolean initialiseUBCs) { + return COMMAND(POTENTIAL_FOAM_COMMAND + " " + (initialiseUBCs ? "-initialiseUBCs " : "") + _WRITE_P + " " + _NO_FUNCTION_OBJECTS + " " + _CASE(), _TEE_LOG()); + } + + public static final String POTENTIAL_FOAM_PARALLEL(boolean initialiseUBCs) { + return COMMAND(_MPI_NP() + " " + POTENTIAL_FOAM_COMMAND + " " + (initialiseUBCs ? "-initialiseUBCs " : "") + _WRITE_P + " "+ _PARALLEL + " " + _NO_FUNCTION_OBJECTS + " " + _CASE(), _TEE_LOG()); } public static final String INITIALISE_FIELDS_SERIAL() { - return COMMAND("caseSetup " + _CASE(), _TEE_LOG()); - } - - public static final String INITIALISE_FIELDS_PARALLEL() { - return COMMAND(_MPI_NP() + " caseSetup " + _PARALLEL + " " + _CASE(), _TEE_LOG()); - } - - public static final String PAR_MAP_FIELDS_SERIAL() { - return COMMAND("parMapFields " + _NO_FUNCTION_OBJECTS + " " + _CASE(), _TEE_LOG()); - } - - public static final String PAR_MAP_FIELDS_PARALLEL() { - return COMMAND(_MPI_NP() + " parMapFields " + _PARALLEL + " " + _NO_FUNCTION_OBJECTS + " " + _CASE(), _TEE_LOG()); + return COMMAND(CASE_SETUP_COMMAND + " " + _CASE(), _TEE_LOG()); } /* * Other */ - public static final String DECOMPOSE_PAR() { - return COMMAND("decomposePar " + _FORCE + " " + _NO_FUNCTION_OBJECTS + " " + _CASE(), _TEE_LOG()); + public static final String INITIALISE_FIELDS_PARALLEL() { + return COMMAND(_MPI_NP() + " " + CASE_SETUP_COMMAND + " " + _PARALLEL + " " + _CASE(), _TEE_LOG()); } - public static final String DECOMPOSE_PAR_CONSTANT() { - return COMMAND("decomposePar " + _FORCE + " " + _NO_FUNCTION_OBJECTS + " " + _CASE() + " " + _CONSTANT, _TEE_LOG()); + public static final String PAR_MAP_FIELDS_SERIAL() { + return COMMAND(PAR_MAP_FIELDS_COMMAND + " " + _NO_FUNCTION_OBJECTS + " " + _CASE(), _TEE_LOG()); } - public static final String DECOMPOSE_PAR_ALLREGIONS() { - return COMMAND("decomposePar " + _FORCE + " " + _NO_FUNCTION_OBJECTS + " " + _CASE() + " " + _ALL_REGIONS, _TEE_LOG()); + public static final String PAR_MAP_FIELDS_PARALLEL() { + return COMMAND(_MPI_NP() + " " + PAR_MAP_FIELDS_COMMAND + " " + _PARALLEL + " " + _NO_FUNCTION_OBJECTS + " " + _CASE(), _TEE_LOG()); } - public static final String DECOMPOSE_PAR_CONSTANT_ALLREGIONS() { - return COMMAND("decomposePar " + _FORCE + " " + _NO_FUNCTION_OBJECTS + " " + _CASE() + " " + _CONSTANT + " " + _ALL_REGIONS, _TEE_LOG()); + public static final String DECOMPOSE_PAR(Set timeSteps) { + return COMMAND(DECOMPOSE_PAR_COMMAND + " " + _FORCE + " " + _NO_FUNCTION_OBJECTS + " " + createTimeFlag(timeSteps) + " " + _CASE(), _TEE_LOG()); + } + + public static final String DECOMPOSE_PAR_CONSTANT(Set timeSteps) { + return COMMAND(DECOMPOSE_PAR_COMMAND + " " + _FORCE + " " + _NO_FUNCTION_OBJECTS + " " + createTimeFlag(timeSteps) + " " + _CASE() + " " + _CONSTANT, _TEE_LOG()); + } + + public static final String DECOMPOSE_PAR_ALLREGIONS(Set timeSteps) { + return COMMAND(DECOMPOSE_PAR_COMMAND + " " + _FORCE + " " + _NO_FUNCTION_OBJECTS + " " + createTimeFlag(timeSteps) + " " + _CASE() + " " + _ALL_REGIONS, _TEE_LOG()); + } + + public static final String DECOMPOSE_PAR_CONSTANT_ALLREGIONS(Set timeSteps) { + return COMMAND(DECOMPOSE_PAR_COMMAND + " " + _FORCE + " " + _NO_FUNCTION_OBJECTS + " " + createTimeFlag(timeSteps) + " " + _CASE() + " " + _CONSTANT + " " + _ALL_REGIONS, _TEE_LOG()); } public static final String RECONSTRUCT_PAR(boolean useWithZeroFlag) { - return COMMAND("reconstructPar " + (useWithZeroFlag ? _WITH_ZERO : _ZERO_TIME) + " " + _NO_FUNCTION_OBJECTS + " " + _CASE(), _TEE_LOG()); + return COMMAND(RECONSTRUCT_PAR_COMMAND + " " + (useWithZeroFlag ? _WITH_ZERO : _ZERO_TIME) + " " + _NO_FUNCTION_OBJECTS + " " + _CASE(), _TEE_LOG()); } public static final String RECONSTRUCT_PAR_ALLREGIONS(boolean useWithZeroFlag) { - return COMMAND("reconstructPar " + (useWithZeroFlag ? _WITH_ZERO : _ZERO_TIME) + " " + _NO_FUNCTION_OBJECTS + " " + _CASE() + " " + _ALL_REGIONS, _TEE_LOG()); + return COMMAND(RECONSTRUCT_PAR_COMMAND + " " + (useWithZeroFlag ? _WITH_ZERO : _ZERO_TIME) + " " + _NO_FUNCTION_OBJECTS + " " + _CASE() + " " + _ALL_REGIONS, _TEE_LOG()); } public static final String FLUENT_TO_FOAM(Double scale, String fluentFileName) { String separator = Util.isWindowsScriptStyle() ? "\\" : "/"; - return COMMAND("fluent3DMeshToFoam " + _SCALE + " " + scale + " " + _NO_FUNCTION_OBJECTS + " " + _CASE() + " " + CASE() + separator + fluentFileName, _TEE_LOG()); + return COMMAND(FLUENT_3D_MESH_TO_FOAM_COMMAND + " " + _SCALE + " " + scale + " " + _NO_FUNCTION_OBJECTS + " " + _CASE() + " " + CASE() + separator + fluentFileName, _TEE_LOG()); } - public static final String RENUMBER_SERIAL() { - return COMMAND("renumberMesh " + _OVERWRITE + " " + _NO_FUNCTION_OBJECTS + " " + _CASE(), _TEE_LOG()); + public static final String RENUMBER_MESH_SERIAL() { + return COMMAND(RENUMBER_MESH_COMMAND + " " + _OVERWRITE + " " + _NO_FUNCTION_OBJECTS + " " + _CASE(), _TEE_LOG()); } - public static final String RENUMBER_PARALLEL() { - return COMMAND(_MPI_NP() + " renumberMesh " + _PARALLEL + " " + _OVERWRITE + " " + _NO_FUNCTION_OBJECTS + " " + _CASE(), _TEE_LOG()); + public static final String RENUMBER_MESH_PARALLEL() { + return COMMAND(_MPI_NP() + " " + RENUMBER_MESH_COMMAND + " " + _PARALLEL + " " + _OVERWRITE + " " + _NO_FUNCTION_OBJECTS + " " + _CASE(), _TEE_LOG()); } public static final String FOAM_MESH_TO_STAR() { - return COMMAND("foamToStarMesh " + _NO_FUNCTION_OBJECTS + " " + _CASE(), _TEE_LOG()); + return COMMAND(FOAM_TO_STAR_MESH_COMMAND + " " + _NO_FUNCTION_OBJECTS + " " + _CASE(), _TEE_LOG()); } public static final String FOAM_MESH_TO_FLUENT() { - return COMMAND("foamMeshToFluent " + _NO_FUNCTION_OBJECTS + " " + _CASE(), _TEE_LOG()); + return COMMAND(FOAM_MESH_TO_FLUENT_COMMAND + " " + _NO_FUNCTION_OBJECTS + " " + _CASE(), _TEE_LOG()); } public static final String CAD_TOOL(boolean split, double precision, File input, File output) { @@ -242,8 +290,29 @@ public class OpenFOAMCommands { return COMMAND("CADtoSurface" + byComponentFlag + " " + precisionFlag + " " + inputFlag + " " + outputFlag, _TEE_LOG()); } - public static final String FRONTAL_AREA = "frontalArea"; - public static final String MOVE_TO_CASE_FOLDER_WIN = "cd /D \"%CASE%\""; - public static final String PARA_FOAM = "paraFoam"; + public static final String PVBATCH_SERIAL() { + return COMMAND("pvbatch --use-offscreen-rendering export.py", _TEE_LOG()); + } + + public static final String PVBATCH_PARALLEL() { + return COMMAND(_MPI_NP() + " pvbatch --use-offscreen-rendering export.py", _TEE_LOG()); + } + + /* + * Utils + */ + private static String createTimeFlag(Set timeSteps) { + if (timeSteps.isEmpty()) { + return ""; + } else { + String times = _TIME + " "; + List list = new ArrayList<>(timeSteps); + for (int i = 0; i < timeSteps.size() - 1; i++) { + times += list.get(i) + ","; + } + times += list.get(timeSteps.size() - 1); + return times; + } + } } diff --git a/src/eu/engys/util/PDFFileFilter.java b/src/eu/engys/util/PDFFileFilter.java index 392fdae..ff27e17 100644 --- a/src/eu/engys/util/PDFFileFilter.java +++ b/src/eu/engys/util/PDFFileFilter.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util; import java.io.File; diff --git a/src/eu/engys/util/PrefUtil.java b/src/eu/engys/util/PrefUtil.java index a086f0f..f611c51 100644 --- a/src/eu/engys/util/PrefUtil.java +++ b/src/eu/engys/util/PrefUtil.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util; @@ -43,14 +42,18 @@ public class PrefUtil { public static final String USER_NAME = System.getProperty("user.name"); public static final String USER_HOME = System.getProperty("user.home"); public static final String USER_DIR = System.getProperty("user.dir"); + public static final String DISPLAY = System.getenv("DISPLAY"); public static final String FAVORITES_KEY = "filechooser.favorites"; -// public static final String DOC_KEY = "doc.basedir"; + // public static final String DOC_KEY = "doc.basedir"; public static final String OPENFOAM_KEY = "openfoam.basedir"; public static final String PARAVIEW_KEY = "paraview.basedir"; + public static final String PARAVIEW_BATCH_KEY = "paraview.batch.basedir"; public static final String FIELDVIEW_KEY = "fieldview.basedir"; public static final String ENSIGHT_KEY = "ensight.basedir"; + public static final String USE_DOCKER = "use.docker"; + public static final String DOCKER_IMAGE = "docker.image"; // batch public static final String SERVER_CONNECTION_MAX_TRIES = "batch.connection.max.tries"; @@ -69,12 +72,15 @@ public class PrefUtil { // misc public static final String RECENT_PROJECTS = "recent.projects"; + public static final String RECENT_STUDIES = "recent.studies"; public static final String HELYX_DEFAULT_TERMINAL = "helyx.default.terminal"; public static final String DEFAULT_HOSTFILE_NONE = "default.hostfile.none"; public static final String HELYX_DEFAULT_FILE_MANAGER = "default.file.manager"; public static final String HELYX_DEFAULT_FILE_OPENER = "default.file.opener"; public static final String MATERIALS_USER_LIB = "materials.user.lib."; public static final String HIDE_EMPTY_PATCHES = "hide.empty.patches"; + public static final String HIDE_PROCESSOR_PATCHES = "hide.processor.patches"; + public static final String HIDE_PROCESSOR_CYCLIC_PATCHES = "hide.processor.cyclic.patches"; // files public static final String WORK_DIR = "last.open.dir"; @@ -85,6 +91,13 @@ public class PrefUtil { public static final String LICENSE_SERVER_NAME = "license.server.name"; public static final String LICENSE_SERVER_PORT = "license.server.port"; + // Parallel Works + public static final String PW_DRIVER = "parallel.works.driver"; + public static final String PW_APIKEY = "parallel.works.apikey"; + public static final String PW_WORKSPACE = "parallel.works.workspace"; + public static final String PW_WORKFLOW = "parallel.works.workflow"; + public static final String PW_PULL_RESULTS = "parallel.works.pull"; + private static CompositeConfiguration configuration; private static CompositeConfiguration configuration() { @@ -93,7 +106,7 @@ public class PrefUtil { } return configuration; } - + public static void reload() { try { deleteOldPrefsFolders(); @@ -140,8 +153,8 @@ public class PrefUtil { List fileLines = FileUtils.readLines(file); Set lines = new LinkedHashSet<>(fileLines); boolean hasDuplicateLines = fileLines.size() > lines.size(); - if(hasDuplicateLines){ - String lineEnding = Util.isWindowsScriptStyle() ? LineSeparator.DOS.getSeparator() : LineSeparator.UNIX.getSeparator(); + if (hasDuplicateLines) { + String lineEnding = Util.isWindowsScriptStyle() ? IOUtils.WIN_EOL : IOUtils.LNX_EOL; FileUtils.writeLines(file, null, lines, lineEnding); } } @@ -193,7 +206,11 @@ public class PrefUtil { } public static Boolean getBoolean(String key) { - return configuration().getBoolean(key); + return configuration().getBoolean(key, false); + } + + public static Boolean getBoolean(String key, boolean b) { + return configuration().getBoolean(key, b); } public static InetAddress getInetAddress(String key, InetAddress def) { @@ -232,6 +249,14 @@ public class PrefUtil { putFile(PARAVIEW_KEY, value); } + public static File getParaViewBatchEntry() { + return getFile(PARAVIEW_BATCH_KEY); + } + + public static void setParaViewBatchEntry(File value) { + putFile(PARAVIEW_BATCH_KEY, value); + } + public static File getOpenFoamEntry() { return getFile(OPENFOAM_KEY); } @@ -244,6 +269,35 @@ public class PrefUtil { configuration().clearProperty(key); } + public static boolean isUsingDocker() { + if (Util.isWindows()) { + return false; + } else { + boolean useDocker = getBoolean(USE_DOCKER); + String dockerImage = getString(DOCKER_IMAGE); + return useDocker && !dockerImage.isEmpty(); + } + } + + public static boolean isRunningOnCloud() { + String driver = PrefUtil.getString(PW_DRIVER); + return !driver.isEmpty() && !driver.equals("Localhost"); + } + + public static void cloudOff() { + putString(PW_DRIVER, ""); + } + + public static void dockerOn(String dockerImage) { + putBoolean(USE_DOCKER, true); + putString(DOCKER_IMAGE, dockerImage); + } + + public static void dockerOff() { + putBoolean(USE_DOCKER, false); + putString(DOCKER_IMAGE, ""); + } + public static Object getDefaultValue(String key) { try { PropertiesConfiguration defaults = new PropertiesConfiguration("eu/engys/resources/application.properties"); diff --git a/src/eu/engys/util/RegexpUtils.java b/src/eu/engys/util/RegexpUtils.java index 5562f13..09e22cf 100644 --- a/src/eu/engys/util/RegexpUtils.java +++ b/src/eu/engys/util/RegexpUtils.java @@ -1,44 +1,51 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util; public class RegexpUtils { public static final String DOUBLE = "\\-?\\d+\\.?\\d*(?:[eE][+-]?\\d+)?"; public static final String INTEGER = "\\-?\\d+[^.eE\\d+]"; - + public static final String POINT = "\\(\\s*" + DOUBLE + "\\s" + DOUBLE + "\\s" + DOUBLE + "\\s*\\)"; - - public static final String SPACES = "\\s*"; - + public static final String SYM_TENSOR = "\\(\\s*" + DOUBLE + "\\s" + DOUBLE + "\\s" + DOUBLE + "\\s" + DOUBLE + "\\s" + DOUBLE + "\\s" + DOUBLE + "\\s*\\)"; + + public static final String NONE_OR_MORE_SPACES = "\\s*"; + public static final String ONE_OR_MORE_SPACES = "\\s+"; + public static final String OPEN_BRACKET = "\\("; public static final String CLOSED_BRACKET = "\\)"; + public static final String ANY_CHAR = ".*"; public static final String OPEN_TAG_BRACKET = "\\<"; public static final String CLOSED_TAG_BRACKET = "\\>"; public static final String COMA = "\\s*,\\s*"; - + + public static final String SCALAR_PATTERN = OPEN_BRACKET + NONE_OR_MORE_SPACES + DOUBLE + ONE_OR_MORE_SPACES + DOUBLE + NONE_OR_MORE_SPACES + CLOSED_BRACKET; + public static final String ATMOSPHERIC_PATTERN = OPEN_BRACKET + NONE_OR_MORE_SPACES + DOUBLE + ONE_OR_MORE_SPACES + SYM_TENSOR + NONE_OR_MORE_SPACES + CLOSED_BRACKET; + public static final String VECTOR_PATTERN = OPEN_BRACKET + NONE_OR_MORE_SPACES + DOUBLE + ONE_OR_MORE_SPACES + POINT + NONE_OR_MORE_SPACES + CLOSED_BRACKET; + public static final String SYM_TENSOR_PATTERN = OPEN_BRACKET + NONE_OR_MORE_SPACES + DOUBLE + ONE_OR_MORE_SPACES + POINT + NONE_OR_MORE_SPACES + CLOSED_BRACKET; + } diff --git a/src/eu/engys/util/Symbols.java b/src/eu/engys/util/Symbols.java index 34d6f10..9ff9ba6 100644 --- a/src/eu/engys/util/Symbols.java +++ b/src/eu/engys/util/Symbols.java @@ -1,42 +1,45 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util; public class Symbols { + public static final String THETA = "\u03B8"; public static final String PHI = "\u03C6"; + public static final String CHI = "\u03F0"; + public static final String E_ACUTE = "\u00E9"; + public static final String OMEGA = "[\u03C9]"; public static final String CUBE = "\u00B3"; public static final String SQUARE = "\u00B2"; public static final String SUBSCRIPT_2 = "\u2082"; public static final String MINUS_ONE = "\u02C9\u00B9"; public static final String DOT = "\u00B7"; - + public static final String PASCAL = "[Pa]"; public static final String KELVIN = "[K]"; public static final String KELVIN_ON_SECONDS = "[K/s]"; @@ -44,10 +47,22 @@ public class Symbols { public static final String M2_S2 = "[m" + SQUARE + "/s" + SQUARE + "]"; public static final String M2_S = "[m" + SQUARE + "/s]"; + public static final String S = "[s]"; + public static final String M = "[m]"; public static final String M_S = "[m/s]"; + public static final String DEG = "[deg]"; + public static final String RAD = "[rad]"; public static final String K_SYMBOL = "[m" + SQUARE + "/s" + SQUARE + "]"; public static final String EPSILON_SYMBOL = "[m" + SQUARE + "/s" + CUBE + "]"; - public static final String OMEGA_SYMBOL = "[1/s]"; + public static final String OMEGA_SYMBOL_S = "[1/s]"; + public static final String OMEGA_SYMBOL_RAD = "[rad/s]"; + public static final String KG = "[kg]"; + public static final String KGM2 = "[kg"+DOT+"m"+SQUARE+"]"; + + public static final String N_M = "[N/m]"; + public static final String NS_M = "[Ns/m]"; + public static final String NM_RAD = "[Nm/rad]"; + public static final String NMS_RAD = "[Nms/rad]"; public static final String MU_MEASURE = "[Pa" + DOT + "s]"; public static final String NU_MEASURE = "[m" + SQUARE + "/s]"; @@ -84,6 +99,7 @@ public class Symbols { public static final String PLUS_UPPERCASE = "\u207A"; public static final String DOUBLE_ARROW = "\u2194"; public static final String DEGREE_SIGN = "\u00B0"; + public static final String HAT = "\u0302"; public static String PEDICE(int number) { String numberToString = String.valueOf(number); diff --git a/src/eu/engys/util/SystemEnv.java b/src/eu/engys/util/SystemEnv.java new file mode 100644 index 0000000..e505b31 --- /dev/null +++ b/src/eu/engys/util/SystemEnv.java @@ -0,0 +1,70 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.util; + +public class SystemEnv { + + /* + * LICENSE + */ + public static final String LICENSE_STATUS = "license.status"; + public static final String LICENSE_ERROR_MESSAGE = "license.error.message"; + public static final String LICENSE_REGISTER = "license.register"; + public static final String LICENSE_EXP_DATE = "license.exp.date"; + + /* + * OS + */ + public static final String OS_NAME = "os.name"; + public static final String OS_ARCH = "os.arch"; + public static final String OS_VERSION = "os.version"; + + /* + * JAVA + */ + public static final String JAVA_HOME = "java.home"; + public static final String JAVA_VENDOR = "java.vendor"; + public static final String JAVA_VERSION = "java.version"; + public static final String JAVA_CLASS_PATH = "java.class.path"; + public static final String JAVA_CLASS_VERSION = "java.class.version"; + + /* + * USER + */ + public static final String USER_DIR = "user.dir"; + public static final String USER_HOME = "user.home"; + public static final String USER_NAME = "user.name"; + + /* + * RMI + */ + public static final String RMI_CLIENT_LOG = "sun.rmi.client.logCalls"; //client-side remote calls and exceptions + public static final String RMI_CLIENT_LOG_LEVEL = "sun.rmi.client.logLevel"; //client-side remote reference activity + public static final String RMI_SERVER_LOG = "java.rmi.server.logCalls"; // server-side remote calls and exceptions + public static final String RMI_SERVER_LOG_LEVEL = "sun.rmi.server.logLevel"; //server-side remote reference activity + public static final String RMI_TRANSPORT_LOG_LEVEL = "sun.rmi.transport.logLevel"; //transport-layer activity + public static final String RMI_TRANSPORT_TCP_LOG_LEVEL = "sun.rmi.transport.tcp.logLevel"; //TCP binding and connection activity + public static final String RMI_SERVER_HOSTNAME = "java.rmi.server.hostname"; +} diff --git a/src/eu/engys/util/TempFolder.java b/src/eu/engys/util/TempFolder.java index 6ae3eb7..b5a2cef 100644 --- a/src/eu/engys/util/TempFolder.java +++ b/src/eu/engys/util/TempFolder.java @@ -1,27 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util; import java.io.File; diff --git a/src/eu/engys/util/TooltipUtils.java b/src/eu/engys/util/TooltipUtils.java index 068a251..a661b26 100644 --- a/src/eu/engys/util/TooltipUtils.java +++ b/src/eu/engys/util/TooltipUtils.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util; import java.util.ArrayList; @@ -30,13 +29,20 @@ import java.util.List; public class TooltipUtils { - private static final int TOOLTIP_MAX_SIZE = 80; + private static final int TOOLTIP_SIZE = 80; + private static final int OFFSET = 10; + private static final String HTML_START = ""; private static final String HTML_END = ""; public static final String NEW_LINE = "
"; + /** + * Format the tooltip string in a multine html-style string. Manual line breaks added via the <br> tag, are taken in consideration + */ + public static String format(String tooltip) { - if(tooltip == null) return null; + if (tooltip == null) + return null; List chunks = getChunks(tooltip); StringBuilder sb = new StringBuilder(HTML_START); for (int i = 0; i < chunks.size() - 1; i++) { @@ -47,16 +53,27 @@ public class TooltipUtils { return sb.toString(); } + /* + * First step: split the string using the br tag delimiter (if any) Second step: split the chunks (from first step) that are bigger than the desired maximum size (plus a offset to avoid too short lines) + */ private static List getChunks(String tooltip) { List chunks = new ArrayList<>(); - if (tooltip.length() <= TOOLTIP_MAX_SIZE || tooltip.contains(NEW_LINE)) { - chunks.add(tooltip); + if (tooltip.contains(NEW_LINE)) { + String[] newLineChunks = tooltip.split(NEW_LINE); + for (String nlc : newLineChunks) { + chunks.addAll(getChunks(nlc)); + } } else { - int splitIndex = tooltip.substring(0, TOOLTIP_MAX_SIZE + 1).lastIndexOf(" "); - chunks.add(tooltip.substring(0, splitIndex)); - chunks.addAll(getChunks(tooltip.substring(splitIndex + 1, tooltip.length()))); + if (tooltip.length() <= TOOLTIP_SIZE + OFFSET) { + chunks.add(tooltip); + } else { + int lastSpaceIndex = tooltip.substring(0, TOOLTIP_SIZE + 1).lastIndexOf(" "); + int splitIndex = lastSpaceIndex == -1 ? TOOLTIP_SIZE : lastSpaceIndex; + chunks.add(tooltip.substring(0, splitIndex)); + chunks.addAll(getChunks(tooltip.substring(splitIndex + 1, tooltip.length()))); + } } return chunks; - } -} + +} \ No newline at end of file diff --git a/src/eu/engys/util/Util.java b/src/eu/engys/util/Util.java index c4d036b..2c24a14 100644 --- a/src/eu/engys/util/Util.java +++ b/src/eu/engys/util/Util.java @@ -1,33 +1,30 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util; -import static java.nio.file.LinkOption.NOFOLLOW_LINKS; -import static java.nio.file.StandardWatchEventKinds.ENTRY_CREATE; -import static java.nio.file.StandardWatchEventKinds.OVERFLOW; +import static eu.engys.util.PrefUtil.USER_NAME; import java.awt.Desktop; import java.io.BufferedReader; @@ -37,18 +34,10 @@ import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.lang.reflect.Field; -import java.net.InetAddress; import java.net.URI; import java.net.URISyntaxException; import java.net.URL; -import java.nio.file.FileSystem; -import java.nio.file.Files; -import java.nio.file.Path; import java.nio.file.Paths; -import java.nio.file.WatchEvent; -import java.nio.file.WatchEvent.Kind; -import java.nio.file.WatchKey; -import java.nio.file.WatchService; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -56,6 +45,7 @@ import java.util.Comparator; import java.util.HashMap; import java.util.Iterator; import java.util.LinkedHashMap; +import java.util.LinkedList; import java.util.List; import java.util.Map; @@ -69,6 +59,8 @@ import com.sun.jna.platform.win32.WinNT; public final class Util { + public static final String UTF_8 = "UTF-8"; + public enum ScriptStyle { WINDOWS, LINUX; } @@ -118,13 +110,17 @@ public final class Util { if (Character.isDigit(charArray[0])) charArray[0] = '_'; for (int i = 0; i < charArray.length; i++) { - if (Util.isForbidden(charArray[i])) { + if (isForbidden(charArray[i])) { charArray[i] = '_'; } } return new String(charArray); } + public static boolean isForbidden(char ch) { + return !Character.isLetterOrDigit(ch) && " \"/\\*#$;&".indexOf(ch) >= 0; + } + public static String padWithSpaces(String string, int lenght) { if (string.length() > lenght) { return string; @@ -138,48 +134,30 @@ public final class Util { } } - public static String[] fromKeystoLabels(String[] keys) { - String[] labels = new String[keys.length]; - for (int i = 0; i < labels.length; i++) { - labels[i] = fromKeyToLabel(keys[i]); - } - return labels; - } - - private static String fromKeyToLabel(String key) { - StringBuilder sb = new StringBuilder(); - sb.append(Character.toUpperCase(key.charAt(0))); - for (int i = 1; i < key.length(); i++) { - char c = key.charAt(i); - if (Character.isUpperCase(c)) - sb.append(" "); - sb.append(c); - } - return sb.toString(); - } - public static boolean isWindows() { String os = System.getProperty("os.name").toLowerCase(); - // windows return (os.indexOf("win") >= 0); } public static boolean isMac() { String os = System.getProperty("os.name").toLowerCase(); - // Mac return (os.indexOf("mac") >= 0); } public static boolean isUnix() { String os = System.getProperty("os.name").toLowerCase(); - // linux or unix return (os.indexOf("nix") >= 0 || os.indexOf("nux") >= 0); } - - public static boolean isSolaris() { - String os = System.getProperty("os.name").toLowerCase(); - // Solaris - return (os.indexOf("sunos") >= 0); + + public static boolean isCygwin() { + ProcessBuilder pb = new ProcessBuilder("uname", "-o"); + try { + Process start = pb.start(); + start.waitFor(); + return true; + } catch (Exception e) { + return false; + } } public static int[] getFactorsFor(int np) { @@ -227,12 +205,12 @@ public final class Util { public static int getWindowsProcessId(Process proc) throws Exception { if (proc.getClass().getName().equals("java.lang.Win32Process") || proc.getClass().getName().equals("java.lang.ProcessImpl")) { - /* determine the pid on windows plattforms */ Field f = proc.getClass().getDeclaredField("handle"); f.setAccessible(true); long handl = f.getLong(proc); Kernel32 kernel = Kernel32.INSTANCE; WinNT.HANDLE handle = new WinNT.HANDLE(); + handle.setPointer(Pointer.createConstant(handl)); return kernel.GetProcessId(handle); } @@ -253,7 +231,6 @@ public final class Util { } } else { String listOfProcesses = getCommandOutput("ps -f"); - // System.err.println(listOfProcesses); if (listOfProcesses == null || listOfProcesses.isEmpty()) { return false; } else { @@ -266,7 +243,11 @@ public final class Util { } } - public static String getCommandOutput(String command) { + public static String getLastNChars(String string, int n) { + return string.length() > n ? string.substring(string.length() - n) : string; + } + + private static String getCommandOutput(String command) { String output = null; // the string to return Process process = null; @@ -277,23 +258,29 @@ public final class Util { try { process = Runtime.getRuntime().exec(command); - // Get stream of the console running the command stream = process.getInputStream(); streamReader = new InputStreamReader(stream); reader = new BufferedReader(streamReader); - String currentLine = null; // store current line of output from the - // cmd - StringBuilder commandOutput = new StringBuilder(); // build up the - // output from - // cmd + String currentLine = null; + List processes = new LinkedList(); while ((currentLine = reader.readLine()) != null) { - commandOutput.append(currentLine + "\n"); + processes.add(currentLine); } + Collections.sort(processes, new Comparator() { + + @Override + public int compare(String o1, String o2) { + return o1.compareToIgnoreCase(o2); + } + }); int returnCode = process.waitFor(); if (returnCode == 0) { - output = commandOutput.toString(); + output = new String(); + for (String p : processes) { + output += p + "\n"; + } } System.err.println(output); } catch (IOException e) { @@ -304,8 +291,6 @@ public final class Util { System.err.println("Cannot retrieve output of command"); System.err.println(e); } finally { - // Close all inputs / readers - if (stream != null) { try { stream.close(); @@ -328,33 +313,9 @@ public final class Util { } } } - // Return the output from the command - may be null if an error occured return output; } - public static void deepCopy(double[] source, double[] target) { - if (source == null || target == null) - throw new IllegalArgumentException("Arrays should be not null"); - if (source.length != target.length) - throw new IllegalArgumentException("Arrays should have same length"); - - for (int i = 0; i < source.length; i++) { - target[i] = source[i]; - } - } - - public static void deepCopy(int[] source, int[] target) { - if (source == null || target == null) - throw new IllegalArgumentException("Arrays should be not null"); - if (source.length != target.length) - throw new IllegalArgumentException("Arrays should have same length"); - - for (int i = 0; i < source.length; i++) { - target[i] = source[i]; - } - - } - @SuppressWarnings("unchecked") public static boolean isVarArgsNotNull(O... objs) { return isVarArgsNotNullAndOfSize(-1, objs); @@ -508,64 +469,6 @@ public final class Util { } } - public static void watchDirectoryPath(Path path) { - // Sanity check - Check if path is a folder - try { - Boolean isFolder = (Boolean) Files.getAttribute(path, "basic:isDirectory", NOFOLLOW_LINKS); - if (!isFolder) { - throw new IllegalArgumentException("Path: " + path + " is not a folder"); - } - } catch (IOException ioe) { - // Folder does not exists - ioe.printStackTrace(); - } - - // System.out.println("Watching path: " + path); - - // We obtain the file system of the Path - FileSystem fs = path.getFileSystem(); - - // We create the new WatchService using the new try() block - try (WatchService service = fs.newWatchService()) { - - // We register the path to the service - // We watch for creation events - path.register(service, ENTRY_CREATE); - - // Start the infinite polling loop - WatchKey key = null; - while (true) { - key = service.take(); - - // Dequeueing events - Kind kind = null; - for (WatchEvent watchEvent : key.pollEvents()) { - // Get the type of the event - kind = watchEvent.kind(); - if (OVERFLOW == kind) { - continue; // loop - } else if (ENTRY_CREATE == kind) { - // A new Path was created - // Path newPath = ((WatchEvent) - // watchEvent).context(); - // Output - // System.out.println("New path created: " + newPath); - } - } - - if (!key.reset()) { - break; // loop - } - } - - } catch (IOException ioe) { - ioe.printStackTrace(); - } catch (InterruptedException ie) { - ie.printStackTrace(); - } - - } - public static String generateID() { byte[] foo = new byte[4]; Util.rnd.fill(foo, 0, foo.length); @@ -573,14 +476,6 @@ public final class Util { return id; } - public static String getMachineName() { - try { - return InetAddress.getLocalHost().getHostName(); - } catch (Exception e) { - return ""; - } - } - public static final Random rnd = new Random(); public static final int WINDOWS_MAX_FILENAME_LENGTH = 200; @@ -588,8 +483,35 @@ public final class Util { return b ? 1 : 0; } - public static boolean isForbidden(char ch) { - return !Character.isLetterOrDigit(ch) && " \"/\\*#$;".indexOf(ch) >= 0; + public static void round(double[] d) { + for (int i = 0; i < d.length; i++) { + d[i] = Math.round(d[i] * 100_000) / 100_000.0; + } + } + + public static void printMatrix(Object[][] matrix) { + for (int i = 0; i < matrix.length; i++) { + for (int j = 0; j < matrix[0].length; j++) { + System.out.print(matrix[i][j] + " "); + } + System.out.print("\n"); + } + } + + public static String getUID() { + StringBuffer sb = new StringBuffer(); + try { + Process proc = Runtime.getRuntime().exec("id -u " + USER_NAME); + InputStream in = proc.getInputStream(); + int c; + while ((c = in.read()) != -1) { + sb.append((char) c); + } + in.close(); + } catch (Exception e) { + return "1000"; + } + return sb.toString(); } } diff --git a/src/eu/engys/util/VTKSettings.java b/src/eu/engys/util/VTKSettings.java index 34744e3..91bfbc8 100644 --- a/src/eu/engys/util/VTKSettings.java +++ b/src/eu/engys/util/VTKSettings.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util; import org.slf4j.Logger; @@ -74,9 +73,15 @@ public class VTKSettings { } } catch (UnsatisfiedLinkError e) { isEveryThingLoaded = false; - //e.printStackTrace(); + e.printStackTrace(); } } +// try { +// System.loadLibrary("vtkmyCommonJava"); +// } catch (UnsatisfiedLinkError e) { +// isEveryThingLoaded = false; +// e.printStackTrace(); +// } return isEveryThingLoaded; } diff --git a/src/eu/engys/util/VersionChecker.java b/src/eu/engys/util/VersionChecker.java index 587f68a..ee7c442 100644 --- a/src/eu/engys/util/VersionChecker.java +++ b/src/eu/engys/util/VersionChecker.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util; import java.io.BufferedReader; @@ -63,6 +62,7 @@ public class VersionChecker { try { String actual = getActualVersion(); String online = getOnlineVersion(); + logger.info("Acutal Version: " + actual + ", Latest Version: " + online); if (actual.isEmpty() || online.isEmpty()) { return VersionType.NOT_AVAILABLE; } diff --git a/src/eu/engys/util/bean/AbstractBean.java b/src/eu/engys/util/bean/AbstractBean.java index d8fbfef..ed98730 100644 --- a/src/eu/engys/util/bean/AbstractBean.java +++ b/src/eu/engys/util/bean/AbstractBean.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.bean; import java.beans.PropertyChangeListener; @@ -33,24 +32,47 @@ import org.apache.commons.lang.ArrayUtils; public class AbstractBean { private transient PropertyChangeSupport support; - + public void addPropertyChangeListener(PropertyChangeListener listener) { if (support == null) { support = new PropertyChangeSupport(this); } support.addPropertyChangeListener(listener); } - + + public void addPropertyChangeListener(String propertyName, PropertyChangeListener listener) { + if (support == null) { + support = new PropertyChangeSupport(this); + } + support.addPropertyChangeListener(propertyName, listener); + } + public void removePropertyChangeListener(PropertyChangeListener listener) { if (support != null) { support.removePropertyChangeListener(listener); } } - + + public void removePropertyChangeListener(String propertyName, PropertyChangeListener listener) { + if (support != null) { + support.removePropertyChangeListener(propertyName, listener); + } + } + + /** + * If the property change listener has been added with the propertyName is better to use the + * "isListenedBy(String propertyName, PropertyChangeListener listener)" method otherwise an instance of + * PropertyChangeListenerProxy may be returned (read the javadoc of PropertyChangeSupport for more details) + */ + @Deprecated public boolean isListenedBy(PropertyChangeListener listener) { return ArrayUtils.contains(support.getPropertyChangeListeners(), listener); } + public boolean isListenedBy(String propertyName, PropertyChangeListener listener) { + return ArrayUtils.contains(support.getPropertyChangeListeners(propertyName), listener); + } + protected void firePropertyChange(String propertyName, Object oldValue, Object newValue) { if (support == null) { support = new PropertyChangeSupport(this); diff --git a/src/eu/engys/util/bean/BeanComboBoxController.java b/src/eu/engys/util/bean/BeanComboBoxController.java new file mode 100644 index 0000000..d59e1f5 --- /dev/null +++ b/src/eu/engys/util/bean/BeanComboBoxController.java @@ -0,0 +1,109 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ + +package eu.engys.util.bean; + +import java.awt.event.ActionListener; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.swing.JComponent; + +import eu.engys.util.ui.JComboBoxWithItemsSupport; +import eu.engys.util.ui.builder.GroupController; + +public class BeanComboBoxController extends JComboBoxWithItemsSupport> implements GroupController { + + private Map> itemsMap = new HashMap<>(); + private List keys = new ArrayList<>(); + private Map childControllers = new HashMap<>(); + + public BeanComboBoxController(BeanModel[] items) { + super(); + for (int i = 0; i < items.length; i++) { + addItem(items[i]); + itemsMap.put(items[i].getBean().getClass().getCanonicalName(), items[i]); + } + } + + @Override + public void addActionListener(ActionListener action) { + super.addActionListener(action); + } + + @Override + public void addGroup(String groupKey, String groupName) { + if (!keys.contains(groupKey)) { + keys.add(groupKey); + if (itemsMap.containsKey(groupKey)) { + BeanModel item = itemsMap.get(groupKey); + addLabel(item, groupName); + } else { + throw new RuntimeException(""); + } + } + } + + @Override + public void addChildController(GroupController controller) { + childControllers.put(keys.get(keys.size()-1), controller); + } + + @Override + public GroupController getChildController(String key) { + return childControllers.get(key); + } + + @Override + public JComponent getComponent() { + return this; + } + +// @Override +// public void setSelectedItem(String groupName) { +// super.setSelectedItem(groupName); +// } + + @Override + public void setSelectedKey(String key) { + super.setSelectedIndex(keys.indexOf(key)); + } + + @Override + public String getSelectedKey() { + int index = getSelectedIndex(); + return index < 0 ? null : keys.get(index); + } + + public boolean containsKey(String key) { + return keys.contains(key); + } + + public List getKeys() { + return keys; + } +} diff --git a/src/eu/engys/util/bean/BeanModel.java b/src/eu/engys/util/bean/BeanModel.java new file mode 100644 index 0000000..b438eb9 --- /dev/null +++ b/src/eu/engys/util/bean/BeanModel.java @@ -0,0 +1,404 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.util.bean; + +import static eu.engys.util.ui.ComponentsFactory.checkField; +import static eu.engys.util.ui.ComponentsFactory.doubleArrayField; +import static eu.engys.util.ui.ComponentsFactory.doubleField; +import static eu.engys.util.ui.ComponentsFactory.doublePointField; +import static eu.engys.util.ui.ComponentsFactory.intArrayField; +import static eu.engys.util.ui.ComponentsFactory.intField; +import static eu.engys.util.ui.ComponentsFactory.radioField; +import static eu.engys.util.ui.ComponentsFactory.stringField; +import static eu.engys.util.ui.RadioFieldPanel.PROPERTY_NAME; + +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.swing.JCheckBox; +import javax.swing.JComboBox; +import javax.swing.JComponent; +import javax.swing.ListModel; + +import com.jgoodies.binding.PresentationModel; +import com.jgoodies.binding.adapter.Bindings; +import com.jgoodies.binding.binder.Binders; +import com.jgoodies.binding.value.AbstractWrappedValueModel; +import com.jgoodies.binding.value.BindingConverter; +import com.jgoodies.binding.value.ValueModel; + +import eu.engys.util.ui.ComponentsFactory; +import eu.engys.util.ui.ListBuilder; +import eu.engys.util.ui.ListFieldPanel; +import eu.engys.util.ui.RadioFieldPanel; +import eu.engys.util.ui.builder.JCheckBoxController; +import eu.engys.util.ui.textfields.DoubleField; +import eu.engys.util.ui.textfields.IntegerField; +import eu.engys.util.ui.textfields.StringField; + +public class BeanModel extends PresentationModel implements BeanModelListener { + + private static final String VALUE_PROPERTY = "value"; + private Map> listeners = new HashMap<>(); + + public BeanModel() { + super(); + addListener(); + } + + public BeanModel(T t) { + super(t); + addListener(); + } + + @Override + public void setBean(T newBean) { +// System.out.println("BeanModel.setBean() " + newBean); + super.setBean(newBean); + } + + private void addListener() { + addPropertyChangeListener("afterBean", new PropertyChangeListener() { + @Override + public void propertyChange(PropertyChangeEvent evt) { + Object obj = evt.getNewValue(); + for (String propertyName : listeners.keySet()) { + for (BeanModelListener listener : listeners.get(propertyName)) { + + Object value = getValue(propertyName); + if (value != null) { + listener.beanModelChanged(value); + } + // try { + // PropertyDescriptor pd = new PropertyDescriptor(propertyName, obj.getClass()); + // Object value = pd.getReadMethod().invoke(obj, (Object[]) null); + // } catch (Exception e) { + // e.printStackTrace(); + // } + } + } + + } + }); + } + + public BeanModelListener getListener(String propertyName, Object bean) { + for (BeanModelListener listener : listeners.get(propertyName)) { + if (listener.getBeanObject().getClass() == bean.getClass()) { + return listener; + } + } + return null; + } + + @SuppressWarnings("unchecked") + @Override + public void beanModelChanged(Object value) { + if (value != null && value.getClass() == getBean().getClass()) { + setBean((T) value); + } + } + + @Override + public T getBeanObject() { + return getBean(); + } + + @Override + public BeanModel getBeanModel() { + return this; + } + + public void addBeanModelListener(String propertyName, BeanModelListener listener) { + if (!listeners.containsKey(propertyName)) { + listeners.put(propertyName, new ArrayList()); + } + listeners.get(propertyName).add(listener); + } + + /* + * BINDING + */ + public StringField bindLabel(String key) { + StringField field = stringField(); + Binders.binderFor(this).bindBeanProperty(key).to(field); + return field; + } + + public JCheckBox bindBoolean(String key) { + JCheckBox field = checkField(); + Binders.binderFor(this).bindBeanProperty(key).to(field); + return field; + } + + public IntegerField bindInteger(String key) { + IntegerField field = intField(-Integer.MAX_VALUE, Integer.MAX_VALUE); + Binders.binderFor(this).bindBeanProperty(key).to(field); + return field; + } + + public IntegerField bindInteger(String key, Integer lb, Integer ub) { + IntegerField field = intField(lb, ub); + Binders.binderFor(this).bindBeanProperty(key).to(field); + return field; + } + + public IntegerField bindIntegerPositive(String key) { + IntegerField field = intField(0, Integer.MAX_VALUE); + Binders.binderFor(this).bindBeanProperty(key).to(field); + return field; + } + + public DoubleField bindDouble(String key) { + DoubleField field = doubleField(); + Binders.binderFor(this).bindBeanProperty(key).to(field); + return field; + } + + public DoubleField bindDouble(String key, Integer places) { + DoubleField field = doubleField(places); + Binders.binderFor(this).bindBeanProperty(key).to(field); + return field; + } + + public DoubleField bindDouble(String key, Double def) { + DoubleField field = doubleField(def); + Binders.binderFor(this).bindBeanProperty(key).to(field); + return field; + } + + public DoubleField bindDouble(String key, double lb, double ub) { + DoubleField field = doubleField(lb, ub); + Binders.binderFor(this).bindBeanProperty(key).to(field); + return field; + } + + public DoubleField bindDoublePositive(String key) { + DoubleField field = doubleField(0.0, Double.MAX_VALUE); + Binders.binderFor(this).bindBeanProperty(key).to(field); + return field; + } + + public DoubleField bindDoubleNegative(String key) { + DoubleField field = doubleField(-Double.MAX_VALUE, 0.0); + Binders.binderFor(this).bindBeanProperty(key).to(field); + return field; + } + + public JComponent bindChoice(String key, String[] keys, String[] labels) { + RadioFieldPanel field = radioField(keys, labels); + JComponent c = new RadioWrapper(field); + ValueModel valueModel = getComponentModel(key); + Bindings.bind(c, VALUE_PROPERTY, valueModel); + return field; + } + + public ListFieldPanel bindList(String key, ListBuilder listBuilder) { + ListFieldPanel field = new ListFieldPanel(listBuilder); + AbstractWrappedValueModel m = getComponentModel(key); + Bindings.bind(field, ListFieldPanel.VALUES, m); + return field; + } + + public JCheckBoxController bindCheckBoxController(String key, String label) { + JCheckBoxController check = ComponentsFactory.checkBoxControllerField(label); + Binders.binderFor(this).bindBeanProperty(key).to(check); + return check; + } + + public JComboBox bindSelection(String key, ListModel listModel) { + JComboBox field = ComponentsFactory.selectField(listModel); + Binders.binderFor(this).bindBeanProperty(key).asSelectionIn(listModel).to(field); + return field; + } + + @SuppressWarnings("unchecked") + public JComboBox bindSelection(String key, E... items) { + JComboBox field = ComponentsFactory.selectField(items); + Binders.binderFor(this).bindBeanProperty(key).asSelectionIn(items).to(field); + return field; + } + + public IntegerField[] bindIntegerArray(String key, int dimensions) { + IntegerField[] fields = intArrayField(dimensions); + for (int i = 0; i < fields.length; i++) { + IntegerField f = fields[i]; + f.setColumns(1); + } + + JComponent c = new IntegerWrapper(fields); + ValueModel valueModel = getComponentModel(key); + Bindings.bind(c, VALUE_PROPERTY, valueModel); + + return fields; + } + + public DoubleField[] bindDoubleArray(String key, int dimensions) { + DoubleField[] fields = doubleArrayField(dimensions); + for (int i = 0; i < fields.length; i++) { + DoubleField f = fields[i]; + f.setColumns(1); + } + + JComponent c = new DoubleWrapper(fields); + ValueModel valueModel = getComponentModel(key); + Bindings.bind(c, VALUE_PROPERTY, valueModel); + + return fields; + } + + @SuppressWarnings("unchecked") + public BeanComboBoxController bindComboController(final String key, BeanModel... models) { + for (BeanModel model : models) { + addBeanModelListener(key, model); + } + BeanComboBoxController combo = new BeanComboBoxController<>(models); + BindingConverter> converter = new BindingConverter>() { + @Override + public BeanModel targetValue(E sourceValue) { + BeanModelListener listener = getListener(key, sourceValue); + return listener != null ? (BeanModel) listener.getBeanModel() : null; + } + + @Override + public E sourceValue(BeanModel targetValue) { + return targetValue == null ? null : targetValue.getBean(); + } + }; + Binders.binderFor(this).bindBeanProperty(key).converted(converter).asSelectionIn(models).to(combo); + + return combo; + } + + public DoubleField[] bindPoint(String key) { + return bindPoint(key, DoubleField.DEFAULT_PLACES); + } + + public DoubleField[] bindPoint(String key, Integer places) { + DoubleField[] field = doublePointField(places); + JComponent c = new DoubleWrapper(field); + ValueModel valueModel = getComponentModel(key); + Bindings.bind(c, "value", valueModel); + + return field; + } + + public static class RadioWrapper extends JComponent { + + private RadioFieldPanel panel; + + public RadioWrapper(RadioFieldPanel panel) { + this.panel = panel; + panel.addPropertyChangeListener(PROPERTY_NAME, new PropertyChangeListener() { + @Override + public void propertyChange(PropertyChangeEvent evt) { + firePropertyChange(VALUE_PROPERTY, null, evt.getNewValue()); + } + }); + } + + public String getValue() { + return panel.getSelectedKey(); + } + + public void setValue(String value) { + String oldValue = getValue(); + panel.select(value); + firePropertyChange(VALUE_PROPERTY, oldValue, value); + } + } + + public static class DoubleWrapper extends JComponent { + private DoubleField[] fields; + + public DoubleWrapper(DoubleField[] fields) { + this.fields = fields; + for (DoubleField df : fields) { + df.addPropertyChangeListener(VALUE_PROPERTY, new PropertyChangeListener() { + @Override + public void propertyChange(PropertyChangeEvent evt) { + firePropertyChange(VALUE_PROPERTY, getValue(), getValue()); + } + }); + } + } + + public double[] getValue() { + double[] value = new double[fields.length]; + for (int i = 0; i < value.length; i++) { + value[i] = fields[i].getDoubleValue(); + } + return value; + } + + public void setValue(double[] value) { + double[] oldValue = getValue(); + if (value != null) { + for (int i = 0; i < value.length; i++) { + fields[i].setDoubleValue(value[i]); + } + } + firePropertyChange(VALUE_PROPERTY, oldValue, value); + } + } + + public static class IntegerWrapper extends JComponent { + private IntegerField[] fields; + + public IntegerWrapper(IntegerField[] fields) { + this.fields = fields; + for (IntegerField df : fields) { + df.addPropertyChangeListener(VALUE_PROPERTY, new PropertyChangeListener() { + @Override + public void propertyChange(PropertyChangeEvent evt) { + firePropertyChange(VALUE_PROPERTY, getValue(), getValue()); + } + }); + } + } + + public int[] getValue() { + int[] value = new int[fields.length]; + for (int i = 0; i < value.length; i++) { + value[i] = fields[i].getIntValue(); + } + return value; + } + + public void setValue(int[] value) { + int[] oldValue = getValue(); + if (value != null) { + for (int i = 0; i < value.length; i++) { + fields[i].setIntValue(value[i]); + } + } + firePropertyChange(VALUE_PROPERTY, oldValue, value); + } + } +} diff --git a/src/eu/engys/util/bean/BeanModelListener.java b/src/eu/engys/util/bean/BeanModelListener.java new file mode 100644 index 0000000..463f05e --- /dev/null +++ b/src/eu/engys/util/bean/BeanModelListener.java @@ -0,0 +1,34 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.util.bean; + +public interface BeanModelListener { + + public void beanModelChanged(Object value); + + public Object getBeanObject(); + + public BeanModel getBeanModel(); +} \ No newline at end of file diff --git a/src/eu/engys/util/bean/BeanPanelBuilder.java b/src/eu/engys/util/bean/BeanPanelBuilder.java new file mode 100644 index 0000000..884878c --- /dev/null +++ b/src/eu/engys/util/bean/BeanPanelBuilder.java @@ -0,0 +1,139 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.util.bean; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Stack; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import eu.engys.util.ui.builder.GroupController; +import eu.engys.util.ui.builder.PanelBuilder; + +public class BeanPanelBuilder extends PanelBuilder { + + private static final Logger logger = LoggerFactory.getLogger(BeanPanelBuilder.class); + + private BeanModel selectedModel; + private Map modelsByKey = new HashMap<>(); + private Map beanSelectors = new HashMap(); + + private boolean selectModelAfterSelection = true; + + public BeanPanelBuilder() { + super(); + } + + public BeanPanelBuilder(String name) { + super(name); + } + + public void startBean(String groupName, BeanModel model) { + String groupKey = model.getBean().getClass().getCanonicalName(); + + startGroup(groupKey, groupName); + + modelsByKey.put(groupKey, model); + beanSelectors.put(groupKey, new BeanSelector(controllers, groups)); + + checkForParent(); + } + + public void endBean() { + endGroup(); + } + + public BeanModel getSelectedModel() { + return selectedModel; + } + + private void setSelectedModel(BeanModel selectedModel) { + if (selectedModel != null) { + this.selectedModel = selectedModel; + } + } + + @SuppressWarnings("unchecked") + public void selectBean(Object newBean) { + if (newBean != null) { + Class newType = newBean.getClass(); + //ut.println("DictionaryPanelBuilder.selectDictionary() NEW TYPE: "+newType); + for (String key : modelsByKey.keySet()) { + BeanModel model = modelsByKey.get(key); + Object oldBean = model.getBean(); + Class oldType = oldBean.getClass(); + //System.out.println("DictionaryPanelBuilder.selectDictionary() OLD TYPE: "+oldType); + if (newType.equals(oldType)) { + //System.out.println("DictionaryPanelBuilder.selectDictionary() FOUND"); + beanSelectors.get(key).select(); + setSelectedModel(model); + selectedModel.setBean(newBean); + return; + } + } + logger.warn("NOT FOUND: if the model you are trying to select has a companion, use the metod 'selectDictionaries(dictionary,companion) ' instead"); + } else { + logger.warn("NULL DICTIONARY"); + } + } + + @Override + protected void afterSelection(String selectedKey) { + super.afterSelection(selectedKey); + BeanModel model = modelsByKey.get(selectedKey); + // System.out.println("DictionaryPanelBuilder.afterSelection() "+selectedKey); + if (model != null && selectModelAfterSelection) { + setSelectedModel(model); + } else { + // System.err.println("setSelectedModel -> -> -> -> -> -> Model is NULLLL"); + } + } + + class BeanSelector { + + private List controllersStack = new ArrayList(); + private List groupsStack = new ArrayList(); + + public BeanSelector(Stack controllers, Stack groups) { + this.controllersStack.addAll(controllers); + this.groupsStack.addAll(groups); + } + + public void select() { + for (int i = 0; i < controllersStack.size(); i++) { + GroupController controller = controllersStack.get(i); + KeydRowGroup group = groupsStack.get(i); + // System.out.println("DictionaryPanelBuilder.DictionarySelector.select() ["+i+"] "+group.groupKey); + controller.setSelectedKey(group.groupKey); + } + } + + } + +} diff --git a/src/eu/engys/util/bean/Bindings.java b/src/eu/engys/util/bean/Bindings.java index 244a3e4..601f791 100644 --- a/src/eu/engys/util/bean/Bindings.java +++ b/src/eu/engys/util/bean/Bindings.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.bean; import java.beans.PropertyChangeEvent; diff --git a/src/eu/engys/util/connection/LogPumper.java b/src/eu/engys/util/connection/LogPumper.java new file mode 100644 index 0000000..94bb521 --- /dev/null +++ b/src/eu/engys/util/connection/LogPumper.java @@ -0,0 +1,93 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.util.connection; + +import java.io.IOException; +import java.io.OutputStream; +import java.io.PrintWriter; +import java.net.Socket; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class LogPumper { + + private static final Logger logger = LoggerFactory.getLogger(LogPumper.class); + + private StringBuffer buffer = new StringBuffer(); + + private PrintWriter out; + private Socket socket; + + public void connect(Socket socket) { + this.socket = socket; + try { + this.out = new PrintWriter(socket.getOutputStream(), true); + } catch (IOException e) { + } + pump(""); + } + + public void connect(OutputStream os) { + this.socket = null; + this.out = new PrintWriter(os, true); + } + + public void pump(String lines) { + if (out == null) { + logger.debug("[LOG PUMPER] Buffering ... "); + buffer.append(lines); + } else { + if (isBuffering()) { + logger.debug("[LOG PUMPER] Flush buffer"); + out.print(buffer.toString()); + buffer.setLength(0); + } + out.print(lines); + out.flush(); + } + } + + public void pump(Exception e) { + logger.error("[LOG PUMPER] ERROR: {}", e.getMessage()); + } + + public void close() throws IOException { + if (out != null) { + out.flush(); + out.close(); + } + + if (socket != null) { + this.socket.close(); + this.socket = null; + } + + } + + public boolean isBuffering() { + return buffer.length() > 0; + } +} diff --git a/src/eu/engys/util/connection/QueueParameters.java b/src/eu/engys/util/connection/QueueParameters.java index e3550a5..6d541e3 100644 --- a/src/eu/engys/util/connection/QueueParameters.java +++ b/src/eu/engys/util/connection/QueueParameters.java @@ -1,31 +1,32 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.connection; -public class QueueParameters { +import java.io.Serializable; + +public class QueueParameters implements Serializable{ public static final String QUEUE_NODES = "numberOfNodes"; public static final String QUEUE_CPUS = "cpuPerNode"; @@ -36,9 +37,14 @@ public class QueueParameters { private int numberOfNodes = 1; private String nodeNames = ""; private int cpuPerNode = 1; - private int timeout = 12; + private int timeout = 500; private String feature = ""; + private String submit = "qsub"; + private String delete = "qdel"; + private String statistic = "qstat"; + private String nodes = "qnodes"; + public int getNumberOfNodes() { return numberOfNodes; } @@ -76,4 +82,4 @@ public class QueueParameters { } -} +} \ No newline at end of file diff --git a/src/eu/engys/util/connection/SshParameters.java b/src/eu/engys/util/connection/SshParameters.java index c18cbfc..e0d1b08 100644 --- a/src/eu/engys/util/connection/SshParameters.java +++ b/src/eu/engys/util/connection/SshParameters.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.connection; import java.io.Serializable; diff --git a/src/eu/engys/util/connection/SshUtils.java b/src/eu/engys/util/connection/SshUtils.java index a204b74..6aa4450 100644 --- a/src/eu/engys/util/connection/SshUtils.java +++ b/src/eu/engys/util/connection/SshUtils.java @@ -1,48 +1,47 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.connection; import java.awt.Container; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.Insets; -import java.io.BufferedWriter; import java.io.File; import java.io.FileInputStream; -import java.io.FileWriter; import java.io.IOException; import java.io.InputStream; import java.net.InetAddress; -import java.net.URL; import java.net.UnknownHostException; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; +import java.util.HashMap; import java.util.Map; import java.util.Vector; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import javax.swing.JLabel; import javax.swing.JOptionPane; @@ -74,12 +73,14 @@ import eu.engys.util.ui.UiUtil; public class SshUtils { - public static final int TIMEOUT = 21000; + private static final String SOURCE_DOT_BASH_PROFILE = "[[ -e ~/.bash_profile ]] && source ~/.bash_profile; "; + + private static final String SOURCE_DOT_PROFILE = "[[ -e ~/.profile ]] && source ~/.profile; "; + + public static final int TIMEOUT = 21000; private static final Logger logger = LoggerFactory.getLogger(SshUtils.class); - private static final URL PLINK_URL = SshUtils.class.getClassLoader().getResource("eu/engys/gui/vtk/depot/ssh/plink.exe"); - public enum Terminal { XTERM, GNOMETERMINAL, KONSOLE } @@ -176,7 +177,7 @@ public class SshUtils { channel.cd(remoteDestination.toString()); String remoteFile = remoteDestination + getFilePathSeparator(remoteDestination) + localFile.getFileName(); if (remoteFileAlreadyExists(remoteFile, channel)) { - int res = JOptionPane.showConfirmDialog(UiUtil.getActiveWindow(), "File " + remoteFile + " already exists. Override?"); + int res = JOptionPane.showConfirmDialog(UiUtil.getActiveWindow(), "File " + remoteFile + " already exists. Overwrite?"); if (res == JOptionPane.OK_OPTION) { if (localFile.toFile().isDirectory()) { // channel.rmdir gives an error @@ -203,7 +204,8 @@ public class SshUtils { monitor.info("New folder: " + localFile.getFileName().toString()); } for (File file : localFile.toFile().listFiles()) { - uploadFileOrFolder(Paths.get(file.toURI()), remoteDestination + getFilePathSeparator(remoteDestination) + localFile.getFileName(), channel, monitor); + String newRemoteFolder = remoteDestination + getFilePathSeparator(remoteDestination) + localFile.getFileName(); + uploadFileOrFolder(Paths.get(file.toURI()), newRemoteFolder, channel, monitor); } } else { if (monitor != null) { @@ -254,6 +256,7 @@ public class SshUtils { } } + public static class UploadProgressMonitor implements SftpProgressMonitor { private ProgressMonitor monitor; @@ -266,8 +269,9 @@ public class SshUtils { @Override public void init(int op, String src, String dest, long max) { + monitor.setIndeterminate(false); monitor.setTotal(total); - monitor.setCurrent(null, 0); + monitor.setCurrent(null, 1); } @Override @@ -316,42 +320,44 @@ public class SshUtils { channel.get(remoteFile, localDestination.toString()); } - public static void exexRemoteScriptInLocalShell(String user, String host, String privateKeyPath, String scriptFile) throws IOException, InterruptedException { - String nameOS = System.getProperty("os.name"); - String command = null; - if (nameOS.startsWith("Windows")) { - String openTerminalcommand = "cmd /C start cmd.exe /K"; - String plinkPath = PLINK_URL.getFile().substring(1); - String sshCommand = "-ssh " + host + " -l " + user + " -i " + privateKeyPath + " -m"; - File scriptLauncher = createScriptLauncher(scriptFile); - String scriptLauncherPath = scriptLauncher.getAbsolutePath(); - command = openTerminalcommand + " " + plinkPath + " " + sshCommand + " " + scriptLauncherPath; - } else if (nameOS.startsWith("Linux")) { - Terminal terminal = getConsoleType(); - String openTerminalcommand = null; - switch (terminal) { - case GNOMETERMINAL: - openTerminalcommand = "gnome-terminal -x"; - break; - case KONSOLE: - openTerminalcommand = "konsole -e"; - break; - case XTERM: - openTerminalcommand = "xterm -x"; - break; - default: - break; - } - - String sshCommand = "ssh " + user + "@" + host + " -i " + privateKeyPath.toString() + " " + scriptFile; - command = openTerminalcommand + " " + sshCommand; - - } else { - System.out.println("OS NOT SUPPORTED!"); - } - Process p = Runtime.getRuntime().exec(command); - p.waitFor(); - } +// public static void exexRemoteScriptInLocalShell(String user, String host, String privateKeyPath, String scriptFile) throws IOException, InterruptedException { +// String nameOS = System.getProperty("os.name"); +// String command = null; +// if (nameOS.startsWith("Windows")) { +// String openTerminalcommand = "cmd /C start cmd.exe /K"; +// String plinkPath = PLINK_URL.getFile().substring(1); +// String sshCommand = "-ssh " + host + " -l " + user + " -i " + privateKeyPath + " -m"; +// File scriptLauncher = createScriptLauncher(scriptFile); +// String scriptLauncherPath = scriptLauncher.getAbsolutePath(); +// command = openTerminalcommand + " " + plinkPath + " " + sshCommand + " " + scriptLauncherPath; +// } else if (nameOS.startsWith("Linux")) { +// Terminal terminal = getConsoleType(); +// String openTerminalcommand = null; +// switch (terminal) { +// case GNOMETERMINAL: +// openTerminalcommand = "gnome-terminal -x"; +// break; +// case KONSOLE: +// openTerminalcommand = "konsole -e"; +// break; +// case XTERM: +// openTerminalcommand = "xterm -x"; +// break; +// default: +// break; +// } +// +// String sshCommand = "ssh " + user + "@" + host + " -i " + privateKeyPath.toString() + " " + scriptFile; +// command = openTerminalcommand + " " + sshCommand; +// +// } else { +// System.out.println("OS NOT SUPPORTED!"); +// } +// if(command != null){ +// Process p = Runtime.getRuntime().exec(command); +// p.waitFor(); +// } +// } public static void execSSHCommand(String command, Session session) throws JSchException, IOException { execSSHCommand(command, session, null); @@ -382,6 +388,17 @@ public class SshUtils { } } + public static Map getEnvFromCommand(String command) { + Map env = new HashMap<>(); + Pattern pattern = Pattern.compile("export\\s(.*?)=(.*)\\s&&"); + Matcher m = pattern.matcher(command); + while (m.find()) { + env.put(m.group(1), m.group(2)); + } + + return env; + } + public static String addEnvToCommand(String command, Map env) { StringBuilder sb = new StringBuilder(); if (env != null) { @@ -396,12 +413,22 @@ public class SshUtils { public static String addProfileLoaderToCommand(String command) { StringBuilder sb = new StringBuilder(); - sb.append("[[ -e ~/.profile ]] && source ~/.profile; "); - sb.append("[[ -e ~/.bash_profile ]] && source ~/.bash_profile; "); + sb.append(SOURCE_DOT_PROFILE); + sb.append(SOURCE_DOT_BASH_PROFILE); sb.append(command); return sb.toString(); } + public static String removeProfileLoaderToCommand(String command) { + if (command.contains(SOURCE_DOT_PROFILE)) { + command = command.replace(SOURCE_DOT_PROFILE, ""); + } + if (command.contains(SOURCE_DOT_BASH_PROFILE)) { + command = command.replace(SOURCE_DOT_BASH_PROFILE, ""); + } + return command; + } + private static void waitForChannelClosed(ChannelExec channel) { while (channel.getExitStatus() == -1 && !channel.isClosed()) { try { @@ -415,32 +442,32 @@ public class SshUtils { try { execSSHCommand("chmod +x " + filePath, session); } catch (JSchException | IOException e) { - e.printStackTrace(); + logger.warn("{}", e.getMessage()); } } - private static Terminal getConsoleType() throws IOException, InterruptedException { - Process p = Runtime.getRuntime().exec("which gnome-terminal"); - p.waitFor(); - if (p.exitValue() == 0) { - return Terminal.GNOMETERMINAL; - } - Process p1 = Runtime.getRuntime().exec("which konsole"); - p1.waitFor(); - if (p1.exitValue() == 0) { - return Terminal.KONSOLE; - } - return Terminal.XTERM; - } - - private static File createScriptLauncher(String string) throws IOException { - File file = File.createTempFile("xxx", null); - FileWriter fstream = new FileWriter(file); - BufferedWriter out = new BufferedWriter(fstream); - out.write(string); - out.close(); - return file; - } +// private static Terminal getConsoleType() throws IOException, InterruptedException { +// Process p = Runtime.getRuntime().exec("which gnome-terminal"); +// p.waitFor(); +// if (p.exitValue() == 0) { +// return Terminal.GNOMETERMINAL; +// } +// Process p1 = Runtime.getRuntime().exec("which konsole"); +// p1.waitFor(); +// if (p1.exitValue() == 0) { +// return Terminal.KONSOLE; +// } +// return Terminal.XTERM; +// } +// +// private static File createScriptLauncher(String string) throws IOException { +// File file = File.createTempFile("xxx", null); +// FileWriter fstream = new FileWriter(file); +// BufferedWriter out = new BufferedWriter(fstream); +// out.write(string); +// out.close(); +// return file; +// } public static boolean testConnection(SshParameters sshParameters) { return testConnection(sshParameters, null, false, false); diff --git a/src/eu/engys/util/filechooser/AbstractFileChooser.java b/src/eu/engys/util/filechooser/AbstractFileChooser.java index 71cfa87..6beb333 100644 --- a/src/eu/engys/util/filechooser/AbstractFileChooser.java +++ b/src/eu/engys/util/filechooser/AbstractFileChooser.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.filechooser; import java.awt.Dimension; diff --git a/src/eu/engys/util/filechooser/FileChooserEventListener.java b/src/eu/engys/util/filechooser/FileChooserEventListener.java index ffc4165..072660c 100644 --- a/src/eu/engys/util/filechooser/FileChooserEventListener.java +++ b/src/eu/engys/util/filechooser/FileChooserEventListener.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.filechooser; public interface FileChooserEventListener { diff --git a/src/eu/engys/util/filechooser/HelyxFileChooser.java b/src/eu/engys/util/filechooser/HelyxFileChooser.java index 04a687e..e464688 100644 --- a/src/eu/engys/util/filechooser/HelyxFileChooser.java +++ b/src/eu/engys/util/filechooser/HelyxFileChooser.java @@ -1,43 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - -/* - * Copyright 2012 Krzysztof Otrebski (krzysztof.otrebski@gmail.com) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.filechooser; diff --git a/src/eu/engys/util/filechooser/LinkFileObject.java b/src/eu/engys/util/filechooser/LinkFileObject.java index 0bb94d2..e317df2 100644 --- a/src/eu/engys/util/filechooser/LinkFileObject.java +++ b/src/eu/engys/util/filechooser/LinkFileObject.java @@ -1,43 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - -/* - * Copyright 2012 Krzysztof Otrebski (krzysztof.otrebski@gmail.com) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.filechooser; diff --git a/src/eu/engys/util/filechooser/ParentFileObject.java b/src/eu/engys/util/filechooser/ParentFileObject.java index f294759..5371ed5 100644 --- a/src/eu/engys/util/filechooser/ParentFileObject.java +++ b/src/eu/engys/util/filechooser/ParentFileObject.java @@ -1,43 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - -/* - * Copyright 2012 Krzysztof Otrebski (krzysztof.otrebski@gmail.com) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.filechooser; diff --git a/src/eu/engys/util/filechooser/RemoteFileChooser.java b/src/eu/engys/util/filechooser/RemoteFileChooser.java index 68c70ab..da614d3 100644 --- a/src/eu/engys/util/filechooser/RemoteFileChooser.java +++ b/src/eu/engys/util/filechooser/RemoteFileChooser.java @@ -1,43 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - -/* - * Copyright 2012 Krzysztof Otrebski (krzysztof.otrebski@gmail.com) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.filechooser; diff --git a/src/eu/engys/util/filechooser/actions/CloneFileAction.java b/src/eu/engys/util/filechooser/actions/CloneFileAction.java new file mode 100644 index 0000000..bf234a4 --- /dev/null +++ b/src/eu/engys/util/filechooser/actions/CloneFileAction.java @@ -0,0 +1,155 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.util.filechooser.actions; + +import static javax.swing.JOptionPane.ERROR_MESSAGE; +import static javax.swing.JOptionPane.YES_OPTION; +import static javax.swing.JOptionPane.showMessageDialog; +import static javax.swing.JOptionPane.showOptionDialog; + +import java.awt.Component; +import java.awt.event.ActionEvent; +import java.io.File; + +import javax.swing.AbstractAction; +import javax.swing.Icon; +import javax.swing.JOptionPane; +import javax.swing.JTable; +import javax.swing.SwingUtilities; + +import org.apache.commons.vfs2.AllFileSelector; +import org.apache.commons.vfs2.FileObject; +import org.apache.commons.vfs2.FileSystemException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import eu.engys.util.filechooser.gui.FileChooserController; +import eu.engys.util.filechooser.table.FileSystemTableModel; +import eu.engys.util.filechooser.util.VFSUtils; +import eu.engys.util.ui.ResourcesUtil; +import eu.engys.util.ui.textfields.StringField; + +public class CloneFileAction extends AbstractAction { + + private static final Logger logger = LoggerFactory.getLogger(CloneFileAction.class); + + private static final String TITLE = "Clone file"; + private static final String PROMPT = "File name"; + public static final String TEXTFIELD_NAME = "fileobject.name"; + public static final String CANCEL_LABEL = "Cancel"; + public static final String CREATE_LABEL = "Create"; + private static final String FILE_ALREADY_EXISTS = "File already exist"; + private static final String EMPTY_NAME_MESSAGE = "Cannot create file or folder with empty name!"; + + private FileChooserController controller; + private JTable table; + + public CloneFileAction(FileChooserController controller, JTable table) { + super(LABEL, ICON); + putValue(SHORT_DESCRIPTION, TOOLTIP); + this.table = table; + this.controller = controller; + setEnabled(!controller.isRemote()); + } + + @Override + public void actionPerformed(ActionEvent actionEvent) { + if (table.getSelectedRows().length == 1) { + FileSystemTableModel model = (FileSystemTableModel) table.getModel(); + FileObject fileObject = model.get(table.getSelectedRow()); + if (fileObject != null) { + cloneFile(fileObject); + } + } + } + + private void cloneFile(FileObject fileObject) { + String currentName = fileObject.getName().getBaseName(); + String newName = promptName(currentName); + if (newName == null) { + return; + } else if (newName.isEmpty()) { + showMessageDialog(SwingUtilities.getRoot(controller.getUriPanel()), EMPTY_NAME_MESSAGE, TITLE, ERROR_MESSAGE); + cloneFile(fileObject); + } else { + try { + clone(fileObject, newName); + } catch (FileSystemException e) { + logger.error("Rename error: {}", e.getMessage()); + } + } + } + + private void clone(FileObject fileObject, String newName) throws FileSystemException { + FileObject parentFileObject = fileObject.getParent(); + String parentFile = VFSUtils.decode(parentFileObject.getName().getURI(), controller.getSshParameters()); + File newFile = new File(parentFile, newName); + if (newFile.exists()) { + showMessageDialog(SwingUtilities.getRoot(controller.getUriPanel()), FILE_ALREADY_EXISTS, TITLE, ERROR_MESSAGE); + cloneFile(fileObject); + } else { + cloneInAThread(fileObject, newName, parentFileObject); + } + } + + private void cloneInAThread(final FileObject fileObject, final String newName, final FileObject parentFileObject) { + controller.showLoading(); + new Thread(new Runnable() { + @Override + public void run() { + try { + FileObject newFO = parentFileObject.resolveFile(newName); + newFO.copyFrom(fileObject, new AllFileSelector()); + controller.refreshLocation(parentFileObject); + controller.showTable(); + } catch (FileSystemException e) { + logger.error("Rename error: {}", e.getMessage()); + } + } + }).start(); + } + + private String promptName(String initialValue) { + StringField nameField = new StringField(initialValue); + nameField.setName(TEXTFIELD_NAME); + nameField.setPrompt(PROMPT); + + Object[] options = { CREATE_LABEL, CANCEL_LABEL }; + Component parent = SwingUtilities.getRoot(controller.getUriPanel()); + int response = showOptionDialog(parent, nameField, TITLE, JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]); + if (response == YES_OPTION) { + return nameField.getText(); + } + return null; + } + + /** + * Resources + */ + + private static final String LABEL = ResourcesUtil.getString("clone.file.label"); + private static final String TOOLTIP = ResourcesUtil.getString("clone.file.tooltip"); + private static final Icon ICON = ResourcesUtil.getIcon("clone.file.icon"); +} diff --git a/src/eu/engys/util/filechooser/actions/DeleteFileAction.java b/src/eu/engys/util/filechooser/actions/DeleteFileAction.java index 8f8d0ba..57a8e53 100644 --- a/src/eu/engys/util/filechooser/actions/DeleteFileAction.java +++ b/src/eu/engys/util/filechooser/actions/DeleteFileAction.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.filechooser.actions; import java.awt.event.ActionEvent; @@ -33,9 +32,6 @@ import javax.swing.Icon; import org.apache.commons.io.FileUtils; import org.apache.commons.vfs2.FileObject; -import org.apache.commons.vfs2.FileSystemException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import eu.engys.util.filechooser.gui.FileChooserController; import eu.engys.util.filechooser.util.VFSUtils; @@ -43,40 +39,42 @@ import eu.engys.util.ui.ResourcesUtil; public final class DeleteFileAction extends AbstractAction { - private static final Logger logger = LoggerFactory.getLogger(DeleteFileAction.class); private FileChooserController controller; public DeleteFileAction(FileChooserController controller) { - super("Delete"); + super(LABEL, ICON); + putValue(SHORT_DESCRIPTION, TOOLTIP); this.controller = controller; - putValue(SMALL_ICON, DELETE_FOLDER_ICON); - putValue(SHORT_DESCRIPTION, DELETE_FOLDER_TEXT); setEnabled(!controller.isRemote()); } @Override public void actionPerformed(ActionEvent e) { + controller.showLoading(); + new Thread(new Runnable() { + @Override + public void run() { + delete(); + controller.refreshLocation(controller.getUriPanel().getFileObject()); + controller.showTable(); + } + }).start(); + + } + + private void delete() { FileObject[] fileObjects = controller.getFileSystemPanel().getSelectedFileObjects(); for (FileObject fo : fileObjects) { File file = new File(VFSUtils.decode(fo.getName().getURI(), controller.getSshParameters())); FileUtils.deleteQuietly(file); } - refresh(controller.getUriPanel().getFileObject()); - } - - private void refresh(FileObject fileObject) { - try { - fileObject.refresh(); - controller.goToURL(fileObject); - } catch (FileSystemException e) { - logger.error("Can't refresh location", e.getMessage()); - } } /** * Resources */ - private static final String DELETE_FOLDER_TEXT = ResourcesUtil.getString("delete.file.label"); - private static final Icon DELETE_FOLDER_ICON = ResourcesUtil.getIcon("delete.file.icon"); + private static final String LABEL = ResourcesUtil.getString("delete.file.label"); + private static final Icon ICON = ResourcesUtil.getIcon("delete.file.icon"); + private static final String TOOLTIP = ResourcesUtil.getString("delete.file.tooltip"); } diff --git a/src/eu/engys/util/filechooser/actions/ExtractArchiveAction.java b/src/eu/engys/util/filechooser/actions/ExtractArchiveAction.java index 0353943..bf95dc3 100644 --- a/src/eu/engys/util/filechooser/actions/ExtractArchiveAction.java +++ b/src/eu/engys/util/filechooser/actions/ExtractArchiveAction.java @@ -1,41 +1,41 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.filechooser.actions; +import static javax.swing.JOptionPane.ERROR_MESSAGE; +import static javax.swing.JOptionPane.showMessageDialog; + import java.awt.event.ActionEvent; import java.io.File; import javax.swing.AbstractAction; import javax.swing.Icon; -import javax.swing.JOptionPane; import javax.swing.SwingUtilities; import org.apache.commons.io.FilenameUtils; import org.apache.commons.vfs2.FileObject; -import org.apache.commons.vfs2.FileSystemException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -45,15 +45,18 @@ import eu.engys.util.filechooser.util.VFSUtils; import eu.engys.util.ui.ResourcesUtil; public final class ExtractArchiveAction extends AbstractAction { + + private static final Logger logger = LoggerFactory.getLogger(ExtractArchiveAction.class); - private static final Logger logger = LoggerFactory.getLogger(ExtractArchiveAction.class); - private FileChooserController controller; + private static final String TITLE = "Archive Error"; + private static final String NOT_AN_ARCHIVE_MESSAGE = "The selected file is not a known archive file"; + + private FileChooserController controller; public ExtractArchiveAction(FileChooserController controller) { - super("Extract"); + super(LABEL, ICON); + putValue(SHORT_DESCRIPTION, TOOLTIP); this.controller = controller; - putValue(SMALL_ICON, EXTRACT_ARCHIVE_ICON); - putValue(SHORT_DESCRIPTION, EXTRACT_ARCHIVE_TEXT); setEnabled(!controller.isRemote()); } @@ -61,14 +64,12 @@ public final class ExtractArchiveAction extends AbstractAction { public void actionPerformed(ActionEvent e) { controller.showLoading(); new Thread(new Runnable() { - @Override public void run() { extractArchives(); controller.showTable(); } }).start(); - } private void extractArchives() { @@ -80,21 +81,20 @@ public final class ExtractArchiveAction extends AbstractAction { private void extractFileObject(FileObject archivedFileObject) { try { - final File selectedFile = new File(VFSUtils.decode(archivedFileObject.getName().getURI(), controller.getSshParameters())); + File selectedFile = new File(VFSUtils.decode(archivedFileObject.getName().getURI(), controller.getSshParameters())); if (ArchiveUtils.isArchive(selectedFile)) { File parentFile = new File(VFSUtils.decode(archivedFileObject.getParent().getName().getURI(), controller.getSshParameters())); ArchiveUtils.unarchive(selectedFile, parentFile); controller.resetFileFilter(); - refresh(archivedFileObject.getParent()); - + controller.refreshLocation(archivedFileObject.getParent()); controller.getFileSystemPanel().selectFileByName(removeExtension(selectedFile.getAbsolutePath())); } else { - JOptionPane.showMessageDialog(SwingUtilities.getRoot(controller.getFileSystemPanel()), "The selected file is not a known archive file", "Archive Error", JOptionPane.ERROR_MESSAGE); + showMessageDialog(SwingUtilities.getRoot(controller.getFileSystemPanel()), NOT_AN_ARCHIVE_MESSAGE, TITLE, ERROR_MESSAGE); } } catch (Exception e) { - logger.error("Can't extract file", e); + logger.error(TITLE, e); } } @@ -104,19 +104,11 @@ public final class ExtractArchiveAction extends AbstractAction { return noEventualSecondExtension; } - private void refresh(FileObject fileObject) { - try { - fileObject.refresh(); - controller.goToURL(fileObject); - } catch (FileSystemException e) { - logger.error("Can't refresh location", e); - } - } - /** * Resources */ - private static final String EXTRACT_ARCHIVE_TEXT = ResourcesUtil.getString("extract.archive.label"); - private static final Icon EXTRACT_ARCHIVE_ICON = ResourcesUtil.getIcon("extract.archive.icon"); + private static final String LABEL = ResourcesUtil.getString("extract.archive.label"); + private static final String TOOLTIP = ResourcesUtil.getString("extract.archive.tooltip"); + private static final Icon ICON = ResourcesUtil.getIcon("extract.archive.icon"); } diff --git a/src/eu/engys/util/filechooser/actions/NewFolderAction.java b/src/eu/engys/util/filechooser/actions/NewFolderAction.java index 7adbfe5..40bb926 100644 --- a/src/eu/engys/util/filechooser/actions/NewFolderAction.java +++ b/src/eu/engys/util/filechooser/actions/NewFolderAction.java @@ -1,112 +1,121 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.filechooser.actions; +import static javax.swing.JOptionPane.ERROR_MESSAGE; +import static javax.swing.JOptionPane.QUESTION_MESSAGE; +import static javax.swing.JOptionPane.YES_NO_OPTION; +import static javax.swing.JOptionPane.YES_OPTION; +import static javax.swing.JOptionPane.showMessageDialog; +import static javax.swing.JOptionPane.showOptionDialog; + import java.awt.Component; import java.awt.event.ActionEvent; import java.io.File; import javax.swing.AbstractAction; import javax.swing.Icon; -import javax.swing.JOptionPane; import javax.swing.SwingUtilities; import org.apache.commons.vfs2.FileObject; -import org.apache.commons.vfs2.FileSystemException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import eu.engys.util.filechooser.gui.FileChooserController; import eu.engys.util.filechooser.util.VFSUtils; import eu.engys.util.ui.ResourcesUtil; -import eu.engys.util.ui.textfields.PromptTextField; +import eu.engys.util.ui.textfields.StringField; public final class NewFolderAction extends AbstractAction { + private static final String TITLE = "New Folder"; + private static final String PROMPT = "Folder name"; + public static final String TEXTFIELD_NAME = "newFolder.name"; + public static final String CANCEL_LABEL = "Cancel"; + public static final String CREATE_LABEL = "Create"; private static final String FOLDER_ALREADY_EXISTS = "Folder already exists"; - private static final String EMPTY_NAME_MESSAGE = "Cannot create folder with emptyName!"; - private static final String NEW_FOLDER_NAME = "New Folder Name"; - private static final Logger logger = LoggerFactory.getLogger(NewFolderAction.class); + private static final String EMPTY_NAME_MESSAGE = "Cannot create folder with empty name"; + private FileChooserController controller; public NewFolderAction(FileChooserController controller) { - super("New"); + super(LABEL, ICON); + putValue(SHORT_DESCRIPTION, TOOLTIP); this.controller = controller; - putValue(SMALL_ICON, NEW_FOLDER_ICON); - putValue(SHORT_DESCRIPTION, NEW_FOLDER_TEXT); setEnabled(!controller.isRemote()); } @Override public void actionPerformed(ActionEvent e) { - FileObject fileObject = controller.getUriPanel().getFileObject(); - String newFolderName = askNewFolderName(); + FileObject parentFO = controller.getUriPanel().getFileObject(); + if (parentFO != null) { + createNewFolder(parentFO); + } + } + + private void createNewFolder(FileObject parentFO) { + String newFolderName = promptName(); if (newFolderName == null) { return; } else if (newFolderName.isEmpty()) { - JOptionPane.showMessageDialog(SwingUtilities.getRoot(controller.getUriPanel()), EMPTY_NAME_MESSAGE, NEW_FOLDER_NAME, JOptionPane.ERROR_MESSAGE); + showMessageDialog(SwingUtilities.getRoot(controller.getUriPanel()), EMPTY_NAME_MESSAGE, TITLE, ERROR_MESSAGE); + createNewFolder(parentFO); } else { - String parentFile = VFSUtils.decode(fileObject.getName().getURI(), controller.getSshParameters()); - File newFile = new File(parentFile, newFolderName); - if (newFile.exists()) { - JOptionPane.showMessageDialog(SwingUtilities.getRoot(controller.getUriPanel()), FOLDER_ALREADY_EXISTS, NEW_FOLDER_NAME, JOptionPane.ERROR_MESSAGE); - } else { - newFile.mkdirs(); - refresh(fileObject); - } + create(parentFO, newFolderName); } } - private void refresh(FileObject fileObject) { - try { - fileObject.refresh(); - controller.goToURL(fileObject); - } catch (FileSystemException e) { - logger.error("Can't refresh location", e.getMessage()); - } - } + private String promptName() { + StringField nameField = new StringField(); + nameField.setName(TEXTFIELD_NAME); + nameField.setPrompt(PROMPT); - private String askNewFolderName() { - final PromptTextField textFieldName = new PromptTextField(); - textFieldName.setName("newFolder.name"); - textFieldName.setPrompt("newFolder"); - - Object[] options = { "Create", "Cancel" }; + Object[] options = { CREATE_LABEL, CANCEL_LABEL }; Component parent = SwingUtilities.getRoot(controller.getUriPanel()); - int response = JOptionPane.showOptionDialog(parent, textFieldName, NEW_FOLDER_NAME, JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]); - if (response == JOptionPane.YES_OPTION) { - return textFieldName.getText(); + int response = showOptionDialog(parent, nameField, TITLE, YES_NO_OPTION, QUESTION_MESSAGE, null, options, options[0]); + if (response == YES_OPTION) { + return nameField.getText(); } return null; } + private void create(FileObject parentFO, String newFolderName) { + String parentFile = VFSUtils.decode(parentFO.getName().getURI(), controller.getSshParameters()); + File newFile = new File(parentFile, newFolderName); + if (newFile.exists()) { + showMessageDialog(SwingUtilities.getRoot(controller.getUriPanel()), FOLDER_ALREADY_EXISTS, TITLE, ERROR_MESSAGE); + createNewFolder(parentFO); + } else { + newFile.mkdirs(); + controller.refreshLocation(parentFO); + } + } + /** * Resources */ - private static final String NEW_FOLDER_TEXT = ResourcesUtil.getString("new.folder.label"); - private static final Icon NEW_FOLDER_ICON = ResourcesUtil.getIcon("new.folder.icon"); + private static final String LABEL = ResourcesUtil.getString("new.folder.label"); + private static final String TOOLTIP = ResourcesUtil.getString("new.folder.tooltip"); + private static final Icon ICON = ResourcesUtil.getIcon("new.folder.icon"); } diff --git a/src/eu/engys/util/filechooser/actions/RenameFileAction.java b/src/eu/engys/util/filechooser/actions/RenameFileAction.java new file mode 100644 index 0000000..3321f93 --- /dev/null +++ b/src/eu/engys/util/filechooser/actions/RenameFileAction.java @@ -0,0 +1,139 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.util.filechooser.actions; + +import static javax.swing.JOptionPane.ERROR_MESSAGE; +import static javax.swing.JOptionPane.YES_OPTION; +import static javax.swing.JOptionPane.showMessageDialog; +import static javax.swing.JOptionPane.showOptionDialog; + +import java.awt.Component; +import java.awt.event.ActionEvent; +import java.io.File; + +import javax.swing.AbstractAction; +import javax.swing.Icon; +import javax.swing.JOptionPane; +import javax.swing.JTable; +import javax.swing.SwingUtilities; + +import org.apache.commons.vfs2.FileObject; +import org.apache.commons.vfs2.FileSystemException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import eu.engys.util.filechooser.gui.FileChooserController; +import eu.engys.util.filechooser.table.FileSystemTableModel; +import eu.engys.util.filechooser.util.VFSUtils; +import eu.engys.util.ui.ResourcesUtil; +import eu.engys.util.ui.textfields.StringField; + +public class RenameFileAction extends AbstractAction { + + private static final Logger logger = LoggerFactory.getLogger(RenameFileAction.class); + + private static final String TITLE = "Rename file"; + private static final String PROMPT = "File name"; + public static final String TEXTFIELD_NAME = "fileobject.name"; + public static final String CANCEL_LABEL = "Cancel"; + public static final String RENAME_LABEL = "Rename"; + private static final String FILE_ALREADY_EXISTS = "File already exist"; + private static final String EMPTY_NAME_MESSAGE = "Cannot create file or folder with empty name!"; + + private FileChooserController controller; + private JTable table; + + public RenameFileAction(FileChooserController controller, JTable table) { + super(LABEL, ICON); + putValue(SHORT_DESCRIPTION, TOOLTIP); + this.table = table; + this.controller = controller; + setEnabled(!controller.isRemote()); + } + + @Override + public void actionPerformed(ActionEvent actionEvent) { + if (table.getSelectedRows().length == 1) { + FileSystemTableModel model = (FileSystemTableModel) table.getModel(); + FileObject fileObject = model.get(table.getSelectedRow()); + if (fileObject != null) { + renameFile(fileObject); + } + } + } + + private void renameFile(FileObject fileObject) { + String currentName = fileObject.getName().getBaseName(); + String newName = promptName(currentName); + if (newName == null) { + return; + } else if (newName.isEmpty()) { + showMessageDialog(SwingUtilities.getRoot(controller.getUriPanel()), EMPTY_NAME_MESSAGE, TITLE, ERROR_MESSAGE); + renameFile(fileObject); + } else { + try { + rename(fileObject, newName); + } catch (FileSystemException e) { + logger.error("Rename error: {}", e.getMessage()); + } + } + } + + private void rename(FileObject fileObject, String newName) throws FileSystemException { + FileObject parentFileObject = fileObject.getParent(); + String parentFile = VFSUtils.decode(parentFileObject.getName().getURI(), controller.getSshParameters()); + File newFile = new File(parentFile, newName); + if (newFile.exists()) { + showMessageDialog(SwingUtilities.getRoot(controller.getUriPanel()), FILE_ALREADY_EXISTS, TITLE, ERROR_MESSAGE); + renameFile(fileObject); + } else { + FileObject newFO = parentFileObject.resolveFile(newName); + fileObject.moveTo(newFO); + controller.refreshLocation(parentFileObject); + } + } + + private String promptName(String initialValue) { + StringField nameField = new StringField(initialValue); + nameField.setName(TEXTFIELD_NAME); + nameField.setPrompt(PROMPT); + + Object[] options = { RENAME_LABEL, CANCEL_LABEL }; + Component parent = SwingUtilities.getRoot(controller.getUriPanel()); + int response = showOptionDialog(parent, nameField, TITLE, JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]); + if (response == YES_OPTION) { + return nameField.getText(); + } + return null; + } + + /** + * Resources + */ + + private static final String LABEL = ResourcesUtil.getString("rename.file.label"); + private static final String TOOLTIP = ResourcesUtil.getString("rename.file.tooltip"); + private static final Icon ICON = ResourcesUtil.getIcon("rename.file.icon"); +} diff --git a/src/eu/engys/util/filechooser/actions/favorite/AddFavorite.java b/src/eu/engys/util/filechooser/actions/favorite/AddFavorite.java deleted file mode 100644 index 17af0d1..0000000 --- a/src/eu/engys/util/filechooser/actions/favorite/AddFavorite.java +++ /dev/null @@ -1,91 +0,0 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - -/* - * Copyright 2012 Krzysztof Otrebski (krzysztof.otrebski@gmail.com) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package eu.engys.util.filechooser.actions.favorite; - -import java.awt.event.ActionEvent; - -import javax.swing.AbstractAction; -import javax.swing.Icon; - -import org.apache.commons.vfs2.FileObject; -import org.apache.commons.vfs2.FileSystemException; - -import eu.engys.util.filechooser.favorites.Favorite; -import eu.engys.util.filechooser.gui.FileChooserController; -import eu.engys.util.filechooser.util.VFSUtils; -import eu.engys.util.ui.ResourcesUtil; - -/** - */ -public class AddFavorite extends AbstractAction { - - private FileChooserController controller; - - public AddFavorite(FileChooserController controller) { - this.controller = controller; - putValue(NAME, NAV_ADDTOFAVORITES); - putValue(SHORT_DESCRIPTION, NAV_ADDTOFAVORITES); - putValue(SMALL_ICON, STAR_PLUS); - - } - - @Override - public void actionPerformed(ActionEvent e) { - FileObject currentLocation = controller.getUriPanel().getFileObject(); - if (currentLocation != null) { - try { - String url = currentLocation.getURL().toString(); - String name = VFSUtils.decode(url, controller.getSshParameters()); - Favorite favorite = new Favorite(name, url, Favorite.Type.USER); - controller.addFavorite(favorite); - } catch (FileSystemException e1) { - e1.printStackTrace(); - } - } - } - - /** - * Resources - */ - private static final String NAV_ADDTOFAVORITES = ResourcesUtil.getString("nav.AddToFavorites"); - private static final Icon STAR_PLUS = ResourcesUtil.getIcon("starPlus"); -} diff --git a/src/eu/engys/util/filechooser/actions/favorite/AddFavoriteAction.java b/src/eu/engys/util/filechooser/actions/favorite/AddFavoriteAction.java new file mode 100644 index 0000000..99fdc31 --- /dev/null +++ b/src/eu/engys/util/filechooser/actions/favorite/AddFavoriteAction.java @@ -0,0 +1,80 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.util.filechooser.actions.favorite; + +import java.awt.event.ActionEvent; + +import javax.swing.AbstractAction; +import javax.swing.Icon; + +import org.apache.commons.vfs2.FileObject; +import org.apache.commons.vfs2.FileSystemException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import eu.engys.util.filechooser.favorites.Favorite; +import eu.engys.util.filechooser.gui.FileChooserController; +import eu.engys.util.filechooser.util.VFSUtils; +import eu.engys.util.ui.ResourcesUtil; + +public class AddFavoriteAction extends AbstractAction { + + private static final Logger logger = LoggerFactory.getLogger(AddFavoriteAction.class); + + private FileChooserController controller; + + public AddFavoriteAction(FileChooserController controller) { + super(LABEL, ICON); + putValue(SHORT_DESCRIPTION, TOOLTIP); + this.controller = controller; + + } + + @Override + public void actionPerformed(ActionEvent e) { + FileObject currentLocation = controller.getUriPanel().getFileObject(); + if (currentLocation != null) { + try { + addFavorite(currentLocation); + } catch (FileSystemException ex) { + logger.error("Filesystem error: {}", ex.getMessage()); + } + } + } + + private void addFavorite(FileObject currentLocation) throws FileSystemException { + String url = currentLocation.getURL().toString(); + String name = VFSUtils.decode(url, controller.getSshParameters()); + Favorite favorite = new Favorite(name, url, Favorite.Type.USER); + controller.addFavorite(favorite); + } + + /** + * Resources + */ + private static final String LABEL = ResourcesUtil.getString("add.favorite.label"); + private static final String TOOLTIP = ResourcesUtil.getString("add.favorite.tooltip"); + private static final Icon ICON = ResourcesUtil.getIcon("add.favorite.icon"); +} diff --git a/src/eu/engys/util/filechooser/actions/favorite/EditFavorite.java b/src/eu/engys/util/filechooser/actions/favorite/EditFavorite.java deleted file mode 100644 index 223b0d4..0000000 --- a/src/eu/engys/util/filechooser/actions/favorite/EditFavorite.java +++ /dev/null @@ -1,167 +0,0 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - -/* - * Copyright 2012 Krzysztof Otrebski (krzysztof.otrebski@gmail.com) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package eu.engys.util.filechooser.actions.favorite; - -import java.awt.GridLayout; -import java.awt.event.ActionEvent; -import java.awt.event.FocusAdapter; -import java.awt.event.FocusEvent; - -import javax.swing.AbstractAction; -import javax.swing.Icon; -import javax.swing.JLabel; -import javax.swing.JList; -import javax.swing.JOptionPane; -import javax.swing.JPanel; -import javax.swing.JTextField; -import javax.swing.SwingUtilities; -import javax.swing.event.AncestorEvent; -import javax.swing.event.AncestorListener; - -import eu.engys.util.filechooser.favorites.Favorite; -import eu.engys.util.filechooser.favorites.list.MutableListModel; -import eu.engys.util.filechooser.gui.FileChooserController; -import eu.engys.util.filechooser.util.VFSUtils; -import eu.engys.util.ui.ResourcesUtil; - -/** - */ -public class EditFavorite extends AbstractAction { - - private JList favoriteList; - private MutableListModel listModel; - private FileChooserController controller; - - public EditFavorite(FileChooserController controller, JList favoriteList, MutableListModel listModel) { - super(EDITFAVORITES_ACTIONNAME, EDITSIGNATURE); - super.putValue(SHORT_DESCRIPTION, EDITFAVORITES_TOOLTIP); - this.controller = controller; - this.favoriteList = favoriteList; - this.listModel = listModel; - } - - @Override - public void actionPerformed(ActionEvent actionEvent) { - if (favoriteList.getSelectedValue() != null) { - Favorite favorite = favoriteList.getSelectedValue(); - JPanel panel = new JPanel(new GridLayout(4, 1)); - - JTextField nameField = new JTextField(favorite.getName()); - addNameListeners(nameField); - nameField.setName("favorite.name"); - panel.add(new JLabel(EDITFAVORITES_NAME)); - panel.add(nameField); - - JTextField urlField = new JTextField(decodedURL(favorite), 20); - urlField.setName("favorite.url"); - panel.add(new JLabel(EDITFAVORITES_URL)); - panel.add(urlField); - - int response = JOptionPane.showConfirmDialog(SwingUtilities.getRoot(favoriteList), panel, EDITFAVORITES_TITLE, JOptionPane.YES_NO_OPTION); - if (response == JOptionPane.YES_OPTION) { - favorite.setName(nameField.getText()); - favorite.setUrl(encodedURL(urlField)); - listModel.change(favoriteList.getSelectedIndex(), favorite); - } - } - } - - private String encodedURL(JTextField urlField) { - return VFSUtils.encode(urlField.getText(), controller.getSshParameters()); - } - - private String decodedURL(Favorite favorite) { - return VFSUtils.decode(favorite.getUrl(), controller.getSshParameters()); - } - - private void addNameListeners(final JTextField text) { - text.addFocusListener(new FocusAdapter() { - public void focusGained(FocusEvent evt) { - SwingUtilities.invokeLater(new Runnable() { - @Override - public void run() { - text.selectAll(); - } - }); - } - - @Override - public void focusLost(FocusEvent e) { - SwingUtilities.invokeLater(new Runnable() { - @Override - public void run() { - text.select(0, 0); - } - }); - } - }); - text.addAncestorListener(new AncestorListener() { - - @Override - public void ancestorRemoved(AncestorEvent event) { - } - - @Override - public void ancestorMoved(AncestorEvent event) { - } - - @Override - public void ancestorAdded(AncestorEvent event) { - // doesn't work because the "yes" button grabs the focus - text.requestFocusInWindow(); - } - }); - text.setFocusable(true); - } - - /** - * Resources - */ - - private static final String EDITFAVORITES_ACTIONNAME = ResourcesUtil.getString("favorites.action"); - private static final String EDITFAVORITES_TOOLTIP = ResourcesUtil.getString("favorites.tooltip"); - private static final String EDITFAVORITES_NAME = ResourcesUtil.getString("favorites.name"); - private static final String EDITFAVORITES_URL = ResourcesUtil.getString("favorites.url"); - private static final String EDITFAVORITES_TITLE = ResourcesUtil.getString("favorites.title"); - - private static final Icon EDITSIGNATURE = ResourcesUtil.getIcon("favorites.edit"); -} diff --git a/src/eu/engys/util/filechooser/actions/favorite/OpenFavorite.java b/src/eu/engys/util/filechooser/actions/favorite/OpenFavorite.java deleted file mode 100644 index 6ba2812..0000000 --- a/src/eu/engys/util/filechooser/actions/favorite/OpenFavorite.java +++ /dev/null @@ -1,87 +0,0 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - -/* - * Copyright 2012 Krzysztof Otrebski (krzysztof.otrebski@gmail.com) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package eu.engys.util.filechooser.actions.favorite; - -import javax.swing.Icon; -import javax.swing.JList; - -import eu.engys.util.filechooser.actions.pathnavigation.BaseNavigateAction; -import eu.engys.util.filechooser.favorites.Favorite; -import eu.engys.util.filechooser.gui.FileChooserController; -import eu.engys.util.ui.ResourcesUtil; - -/** - */ -public class OpenFavorite extends BaseNavigateAction { - - private JList favoriteList; - - public OpenFavorite(FileChooserController controller, JList favoriteList) { - super(controller, "Open", FOLDEROPEN); - this.favoriteList = favoriteList; - } - - @Override - protected void performLongOperation(CheckBeforeActionResult checkBeforeActionResult) { - if (favoriteList.getSelectedValue() != null) { - Favorite favorite = favoriteList.getSelectedValue(); - controller.goToURL(favorite.getUrl(), true); - controller.updateOkButton(); - } - } - - @Override - protected boolean canGoUrl() { - return favoriteList.getSelectedValue() != null; - } - - @Override - protected boolean canExecuteDefaultAction() { - return true; - } - - /** - * Resources - */ - - private static final Icon FOLDEROPEN = ResourcesUtil.getIcon("folderOpen"); -} diff --git a/src/eu/engys/util/filechooser/actions/favorite/OpenFavoriteAction.java b/src/eu/engys/util/filechooser/actions/favorite/OpenFavoriteAction.java new file mode 100644 index 0000000..5d75dce --- /dev/null +++ b/src/eu/engys/util/filechooser/actions/favorite/OpenFavoriteAction.java @@ -0,0 +1,69 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.util.filechooser.actions.favorite; + +import javax.swing.JList; + +import eu.engys.util.filechooser.actions.navigation.BaseNavigateAction; +import eu.engys.util.filechooser.favorites.Favorite; +import eu.engys.util.filechooser.gui.FileChooserController; +import eu.engys.util.ui.ResourcesUtil; + +public class OpenFavoriteAction extends BaseNavigateAction { + + private JList favoriteList; + + public OpenFavoriteAction(FileChooserController controller, JList favoriteList) { + super(controller, LABEL); + putValue(SHORT_DESCRIPTION, TOOLTIP); + this.favoriteList = favoriteList; + } + + @Override + protected void performLongOperation(CheckBeforeActionResult checkBeforeActionResult) { + if (favoriteList.getSelectedValue() != null) { + Favorite favorite = favoriteList.getSelectedValue(); + controller.goToURL(favorite.getUrl(), true); + controller.updateOkButton(); + } + } + + @Override + protected boolean canGoUrl() { + return favoriteList.getSelectedValue() != null; + } + + @Override + protected boolean canExecuteDefaultAction() { + return true; + } + + /** + * Resources + */ + private static final String LABEL = ResourcesUtil.getString("open.favorite.label"); + private static final String TOOLTIP = ResourcesUtil.getString("open.favorite.tooltip"); + +} diff --git a/src/eu/engys/util/filechooser/actions/favorite/RenameFavoriteAction.java b/src/eu/engys/util/filechooser/actions/favorite/RenameFavoriteAction.java new file mode 100644 index 0000000..af4c5cb --- /dev/null +++ b/src/eu/engys/util/filechooser/actions/favorite/RenameFavoriteAction.java @@ -0,0 +1,104 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.util.filechooser.actions.favorite; + +import java.awt.GridLayout; +import java.awt.event.ActionEvent; + +import javax.swing.AbstractAction; +import javax.swing.Icon; +import javax.swing.JLabel; +import javax.swing.JList; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.JTextField; +import javax.swing.SwingUtilities; + +import eu.engys.util.filechooser.favorites.Favorite; +import eu.engys.util.filechooser.favorites.list.MutableListModel; +import eu.engys.util.filechooser.gui.FileChooserController; +import eu.engys.util.filechooser.util.VFSUtils; +import eu.engys.util.ui.ResourcesUtil; +import eu.engys.util.ui.textfields.StringField; + +public class RenameFavoriteAction extends AbstractAction { + + private static final String TITLE = "Rename favorite"; + private static final String NAME_LABEL = "Name:"; + private static final String URL_LABEL = "URL:"; + + private JList favoriteList; + private MutableListModel listModel; + private FileChooserController controller; + + public RenameFavoriteAction(FileChooserController controller, JList favoriteList, MutableListModel listModel) { + super(LABEL, ICON); + putValue(SHORT_DESCRIPTION, TOOLTIP); + this.controller = controller; + this.favoriteList = favoriteList; + this.listModel = listModel; + } + + @Override + public void actionPerformed(ActionEvent actionEvent) { + if (favoriteList.getSelectedValue() != null) { + Favorite favorite = favoriteList.getSelectedValue(); + JPanel panel = new JPanel(new GridLayout(4, 1)); + + StringField nameField = new StringField(favorite.getName(), true, false); + nameField.setName("favorite.name"); + panel.add(new JLabel(NAME_LABEL)); + panel.add(nameField); + + StringField urlField = new StringField(decodedURL(favorite), true, false); + urlField.setName("favorite.url"); + panel.add(new JLabel(URL_LABEL)); + panel.add(urlField); + + int response = JOptionPane.showConfirmDialog(SwingUtilities.getRoot(favoriteList), panel, TITLE, JOptionPane.YES_NO_OPTION); + if (response == JOptionPane.YES_OPTION) { + favorite.setName(nameField.getText()); + favorite.setUrl(encodedURL(urlField)); + listModel.change(favoriteList.getSelectedIndex(), favorite); + } + } + } + + private String encodedURL(JTextField urlField) { + return VFSUtils.encode(urlField.getText(), controller.getSshParameters()); + } + + private String decodedURL(Favorite favorite) { + return VFSUtils.decode(favorite.getUrl(), controller.getSshParameters()); + } + + /** + * Resources + */ + + private static final String LABEL = ResourcesUtil.getString("rename.favorite.label"); + private static final String TOOLTIP = ResourcesUtil.getString("rename.favorite.name"); + private static final Icon ICON = ResourcesUtil.getIcon("rename.favorite.icon"); +} diff --git a/src/eu/engys/util/filechooser/actions/navigation/BaseNavigateAction.java b/src/eu/engys/util/filechooser/actions/navigation/BaseNavigateAction.java new file mode 100644 index 0000000..4854389 --- /dev/null +++ b/src/eu/engys/util/filechooser/actions/navigation/BaseNavigateAction.java @@ -0,0 +1,157 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.util.filechooser.actions.navigation; + +import java.awt.Component; +import java.awt.KeyboardFocusManager; +import java.awt.event.ActionEvent; +import java.util.concurrent.Executor; +import java.util.concurrent.Executors; + +import javax.swing.AbstractAction; +import javax.swing.Icon; +import javax.swing.JOptionPane; +import javax.swing.SwingWorker; + +import eu.engys.util.filechooser.gui.FileChooserController; +import eu.engys.util.ui.UiUtil; + +public abstract class BaseNavigateAction extends AbstractAction { + + private static final int SWITCH_TO_LOADING_TIME = 120; + + public FileChooserController controller; + private static Executor executor = Executors.newSingleThreadExecutor(); + private volatile SwingWorker showLoadingAfterDelayWorker; + private Component focusOwner; + + public BaseNavigateAction(FileChooserController controller) { + super(); + this.controller = controller; + } + + public BaseNavigateAction(FileChooserController controller, String name) { + this(controller); + putValue(NAME, name); + } + + public BaseNavigateAction(FileChooserController controller, String name, Icon icon) { + this(controller, name); + putValue(SMALL_ICON, icon); + } + + protected abstract void performLongOperation(CheckBeforeActionResult checkBeforeActionResult); + + @Override + public final void actionPerformed(ActionEvent e) { + final CheckBeforeActionResult checkBeforeActionResult = doInUiThreadBefore(); + if (CheckBeforeActionResult.CANT_GO.equals(checkBeforeActionResult)) { + if (showLoadingAfterDelayWorker != null) { + showLoadingAfterDelayWorker.cancel(false); + } + return; + } + + SwingWorker worker = new SwingWorker() { + + @Override + protected void done() { + doInUiThreadAfter(); + } + + @Override + protected Void doInBackground() throws Exception { + try { + performLongOperation(checkBeforeActionResult); + } catch (Exception e) { + JOptionPane.showMessageDialog(UiUtil.getActiveWindow(), e.getMessage(), "File Chooser Error", JOptionPane.ERROR_MESSAGE); + e.printStackTrace(); + } + return null; + } + }; + executor.execute(worker); + + } + + protected final void doInUiThreadAfter() { + if (showLoadingAfterDelayWorker != null) { + showLoadingAfterDelayWorker.cancel(false); + } + controller.showTable(); + if (focusOwner != null) { + focusOwner.requestFocus(); + } + } + + protected final CheckBeforeActionResult doInUiThreadBefore() { + CheckBeforeActionResult result = CheckBeforeActionResult.CAN_GO; + if (!canGoUrl()) { + if (canExecuteDefaultAction()) { + result = CheckBeforeActionResult.CANT_GO_USE_DEFAULT_ACTION; + } else { + result = CheckBeforeActionResult.CANT_GO; + } + } else { + if (canExecuteDefaultAction()) { + result = CheckBeforeActionResult.CAN_GO_OR_USE_DEFAULT_ACTION; + } else { + result = CheckBeforeActionResult.CAN_GO; + } + } + + focusOwner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner(); + showLoadingAfterDelayWorker = new SwingWorker() { + + @Override + protected void done() { + boolean cancelled = isCancelled(); + if (!cancelled) { + controller.showLoading(); + } + } + + @Override + protected Void doInBackground() throws Exception { + Thread.sleep(SWITCH_TO_LOADING_TIME); + return null; + } + }; + executor.execute(showLoadingAfterDelayWorker); + return result; + } + + protected abstract boolean canExecuteDefaultAction(); + + protected abstract boolean canGoUrl(); + + protected void updateGuiBefore() { + + } + + public enum CheckBeforeActionResult { + CAN_GO_OR_USE_DEFAULT_ACTION, CANT_GO, CANT_GO_USE_DEFAULT_ACTION, CAN_GO; + } +} diff --git a/src/eu/engys/util/filechooser/actions/navigation/BaseNavigateActionGoUp.java b/src/eu/engys/util/filechooser/actions/navigation/BaseNavigateActionGoUp.java new file mode 100644 index 0000000..5837474 --- /dev/null +++ b/src/eu/engys/util/filechooser/actions/navigation/BaseNavigateActionGoUp.java @@ -0,0 +1,81 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.util.filechooser.actions.navigation; + +import javax.swing.Icon; + +import org.apache.commons.vfs2.FileObject; +import org.apache.commons.vfs2.FileSystemException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import eu.engys.util.filechooser.gui.FileChooserController; +import eu.engys.util.filechooser.util.VFSUtils; +import eu.engys.util.ui.ResourcesUtil; + +public final class BaseNavigateActionGoUp extends BaseNavigateAction { + + private static final Logger logger = LoggerFactory.getLogger(BaseNavigateActionGoUp.class); + + public BaseNavigateActionGoUp(FileChooserController controller) { + super(controller, LABEL, ICON); + putValue(SHORT_DESCRIPTION, TOOLTIP); + } + + @Override + public void performLongOperation(CheckBeforeActionResult actionResult) { + logger.debug("Executing going up"); + try { + FileObject parent = controller.getUriPanel().getFileObject().getParent(); + controller.goToURL(parent); + } catch (FileSystemException e) { + logger.error("Error go UP", e.getMessage()); + } + } + + @Override + protected boolean canGoUrl() { + try { + FileObject parent = controller.getUriPanel().getFileObject().getParent(); + return parent != null && VFSUtils.canGoUrl(parent); + } catch (FileSystemException e) { + logger.error("Can't get parent of current location", e.getMessage()); + } + return false; + } + + @Override + protected boolean canExecuteDefaultAction() { + return false; + } + + /* + * Resources + */ + + private static final String LABEL = ResourcesUtil.getString("path.move.up.label"); + private static final String TOOLTIP = ResourcesUtil.getString("path.move.up.tooltip"); + private static final Icon ICON = ResourcesUtil.getIcon("path.move.up.icon"); +} diff --git a/src/eu/engys/util/filechooser/actions/navigation/BaseNavigateActionOpen.java b/src/eu/engys/util/filechooser/actions/navigation/BaseNavigateActionOpen.java new file mode 100644 index 0000000..209959d --- /dev/null +++ b/src/eu/engys/util/filechooser/actions/navigation/BaseNavigateActionOpen.java @@ -0,0 +1,88 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.util.filechooser.actions.navigation; + +import org.apache.commons.vfs2.FileObject; +import org.apache.commons.vfs2.FileSystemException; +import org.apache.commons.vfs2.FileType; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import eu.engys.util.filechooser.AbstractFileChooser.ReturnValue; +import eu.engys.util.filechooser.gui.FileChooserController; +import eu.engys.util.filechooser.util.SelectionMode; +import eu.engys.util.filechooser.util.VFSUtils; + +public final class BaseNavigateActionOpen extends BaseNavigateAction { + + private static final Logger logger = LoggerFactory.getLogger(BaseNavigateActionOpen.class); + private final FileChooserController controller; + + public BaseNavigateActionOpen(FileChooserController controller) { + super(controller); + this.controller = controller; + } + + @Override + public void performLongOperation(CheckBeforeActionResult checkBeforeActionResult) { + // When double click a file on the table + FileObject fileObject = controller.getSelectedFileObject(); + if (canExecuteDefaultAction()) { + controller.closeAndReturn(ReturnValue.Approve); + } else { + controller.goToURL(fileObject); + } + } + + @Override + protected boolean canGoUrl() { + FileObject fileObject = controller.getSelectedFileObject(); + if (fileObject != null) { + try { + return VFSUtils.canGoUrl(fileObject); + } catch (FileSystemException e) { + logger.error("Can't open location", e.getMessage()); + } + } + return false; + } + + @Override + protected boolean canExecuteDefaultAction() { + SelectionMode selectionMode = controller.getSelectionMode(); + if (selectionMode.isFilesOnly() || selectionMode.isDirsAndFiles()) { + FileObject fileObject = controller.getSelectedFileObject(); + if (fileObject != null) { + try { + return FileType.FILE == fileObject.getType() || FileType.FILE_OR_FOLDER == fileObject.getType(); + } catch (FileSystemException e) { + logger.warn("Cant' get file type", e); + } + } + } + return false; + } + +} diff --git a/src/eu/engys/util/filechooser/actions/navigation/BaseNavigateActionRefresh.java b/src/eu/engys/util/filechooser/actions/navigation/BaseNavigateActionRefresh.java new file mode 100644 index 0000000..e9f53bc --- /dev/null +++ b/src/eu/engys/util/filechooser/actions/navigation/BaseNavigateActionRefresh.java @@ -0,0 +1,65 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.util.filechooser.actions.navigation; + +import javax.swing.Icon; + +import org.apache.commons.vfs2.FileObject; + +import eu.engys.util.filechooser.gui.FileChooserController; +import eu.engys.util.ui.ResourcesUtil; + +public final class BaseNavigateActionRefresh extends BaseNavigateAction { + + public BaseNavigateActionRefresh(FileChooserController controller) { + super(controller, LABEL, ICON); + putValue(SHORT_DESCRIPTION, TOOLTIP); + } + + @Override + public void performLongOperation(CheckBeforeActionResult checkBeforeActionResult) { + FileObject fileObject = controller.getUriPanel().getFileObject(); + controller.refreshLocation(fileObject); + } + + @Override + protected boolean canGoUrl() { + return true; + } + + @Override + protected boolean canExecuteDefaultAction() { + return false; + } + + /** + * Resources + */ + + private static final String LABEL = ResourcesUtil.getString("path.refresh.label"); + private static final String TOOLTIP = ResourcesUtil.getString("path.refresh.tooltip"); + private static final Icon ICON = ResourcesUtil.getIcon("path.refresh.icon"); + +} diff --git a/src/eu/engys/util/filechooser/actions/pathnavigation/BaseNavigateAction.java b/src/eu/engys/util/filechooser/actions/pathnavigation/BaseNavigateAction.java deleted file mode 100644 index 8c11956..0000000 --- a/src/eu/engys/util/filechooser/actions/pathnavigation/BaseNavigateAction.java +++ /dev/null @@ -1,175 +0,0 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - -/* - * Copyright 2012 Krzysztof Otrebski (krzysztof.otrebski@gmail.com) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package eu.engys.util.filechooser.actions.pathnavigation; - -import java.awt.Component; -import java.awt.KeyboardFocusManager; -import java.awt.event.ActionEvent; -import java.util.concurrent.Executor; -import java.util.concurrent.Executors; - -import javax.swing.AbstractAction; -import javax.swing.Icon; -import javax.swing.JOptionPane; -import javax.swing.SwingWorker; - -import eu.engys.util.filechooser.gui.FileChooserController; -import eu.engys.util.ui.UiUtil; - -public abstract class BaseNavigateAction extends AbstractAction { - - private static final int SWITCH_TO_LOADING_TIME = 120; - - public FileChooserController controller; - private static Executor executor = Executors.newSingleThreadExecutor(); - private volatile SwingWorker showLoadingAfterDelayWorker; - private Component focusOwner; - - public BaseNavigateAction(FileChooserController controller) { - super(); - this.controller = controller; - } - - public BaseNavigateAction(FileChooserController controller, String name) { - this(controller); - putValue(NAME, name); - } - - public BaseNavigateAction(FileChooserController controller, String name, Icon icon) { - this(controller, name); - putValue(SMALL_ICON, icon); - } - - protected abstract void performLongOperation(CheckBeforeActionResult checkBeforeActionResult); - - @Override - public final void actionPerformed(ActionEvent e) { - final CheckBeforeActionResult checkBeforeActionResult = doInUiThreadBefore(); - if (CheckBeforeActionResult.CANT_GO.equals(checkBeforeActionResult)) { - return; - } - - SwingWorker worker = new SwingWorker() { - - @Override - protected void done() { - doInUiThreadAfter(); - } - - @Override - protected Void doInBackground() throws Exception { - try { - performLongOperation(checkBeforeActionResult); - } catch (Exception e) { - JOptionPane.showMessageDialog(UiUtil.getActiveWindow(), e.getMessage(), "File Chooser Error", JOptionPane.ERROR_MESSAGE); - e.printStackTrace(); - } - return null; - } - }; - executor.execute(worker); - - } - - protected final void doInUiThreadAfter() { - if (showLoadingAfterDelayWorker != null) { - showLoadingAfterDelayWorker.cancel(false); - } - updateGuiAfter(); - controller.showTable(); - if (focusOwner != null) { - focusOwner.requestFocus(); - } - } - - protected void updateGuiAfter() { - } - - protected final CheckBeforeActionResult doInUiThreadBefore() { - CheckBeforeActionResult result = CheckBeforeActionResult.CAN_GO; - if (!canGoUrl()) { - if (canExecuteDefaultAction()) { - result = CheckBeforeActionResult.CANT_GO_USE_DEFAULT_ACTION; - } else { - result = CheckBeforeActionResult.CANT_GO; - } - } else { - if (canExecuteDefaultAction()) { - result = CheckBeforeActionResult.CAN_GO_OR_USE_DEFAULT_ACTION; - } else { - result = CheckBeforeActionResult.CAN_GO; - } - } - - focusOwner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner(); - showLoadingAfterDelayWorker = new SwingWorker() { - - @Override - protected void done() { - boolean cancelled = isCancelled(); - if (!cancelled) { - controller.showLoading(); - } - } - - @Override - protected Void doInBackground() throws Exception { - Thread.sleep(SWITCH_TO_LOADING_TIME); - return null; - } - }; - executor.execute(showLoadingAfterDelayWorker); - return result; - } - - protected abstract boolean canExecuteDefaultAction(); - - protected abstract boolean canGoUrl(); - - protected void updateGuiBefore() { - - } - - public enum CheckBeforeActionResult { - CAN_GO_OR_USE_DEFAULT_ACTION, CANT_GO, CANT_GO_USE_DEFAULT_ACTION, CAN_GO; - } -} diff --git a/src/eu/engys/util/filechooser/actions/pathnavigation/BaseNavigateActionGoUp.java b/src/eu/engys/util/filechooser/actions/pathnavigation/BaseNavigateActionGoUp.java deleted file mode 100644 index 20f22d7..0000000 --- a/src/eu/engys/util/filechooser/actions/pathnavigation/BaseNavigateActionGoUp.java +++ /dev/null @@ -1,82 +0,0 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - -package eu.engys.util.filechooser.actions.pathnavigation; - -import javax.swing.Icon; - -import org.apache.commons.vfs2.FileObject; -import org.apache.commons.vfs2.FileSystemException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import eu.engys.util.filechooser.gui.FileChooserController; -import eu.engys.util.filechooser.util.VFSUtils; -import eu.engys.util.ui.ResourcesUtil; - -public final class BaseNavigateActionGoUp extends BaseNavigateAction { - - private static final Logger LOGGER = LoggerFactory.getLogger(BaseNavigateActionGoUp.class); - - public BaseNavigateActionGoUp(FileChooserController controller) { - super(controller); - putValue(SMALL_ICON, ARROWTURN90); - putValue(SHORT_DESCRIPTION, NAV_GOFOLDERUP); - } - - @Override - public void performLongOperation(CheckBeforeActionResult actionResult) { - LOGGER.debug("Executing going up"); - try { - FileObject parent = controller.getUriPanel().getFileObject().getParent(); - controller.goToURL(parent); - } catch (FileSystemException e) { - LOGGER.error("Error go UP", e); - } - } - - @Override - protected boolean canGoUrl() { - try { - FileObject parent = controller.getUriPanel().getFileObject().getParent(); - return parent != null && VFSUtils.canGoUrl(parent); - } catch (FileSystemException e) { - LOGGER.error("Can't get parent of current location", e); - } - return false; - } - - @Override - protected boolean canExecuteDefaultAction() { - return false; - } - - /** - * Resources - */ - - private static final String NAV_GOFOLDERUP = ResourcesUtil.getString("nav.goFolderUp"); - private static final Icon ARROWTURN90 = ResourcesUtil.getIcon("arrowTurn90"); -} diff --git a/src/eu/engys/util/filechooser/actions/pathnavigation/BaseNavigateActionOpen.java b/src/eu/engys/util/filechooser/actions/pathnavigation/BaseNavigateActionOpen.java deleted file mode 100644 index 77b1414..0000000 --- a/src/eu/engys/util/filechooser/actions/pathnavigation/BaseNavigateActionOpen.java +++ /dev/null @@ -1,89 +0,0 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - -package eu.engys.util.filechooser.actions.pathnavigation; - -import org.apache.commons.vfs2.FileObject; -import org.apache.commons.vfs2.FileSystemException; -import org.apache.commons.vfs2.FileType; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import eu.engys.util.filechooser.AbstractFileChooser.ReturnValue; -import eu.engys.util.filechooser.gui.FileChooserController; -import eu.engys.util.filechooser.util.SelectionMode; -import eu.engys.util.filechooser.util.VFSUtils; - -public final class BaseNavigateActionOpen extends BaseNavigateAction { - - private static final Logger LOGGER = LoggerFactory.getLogger(BaseNavigateActionOpen.class); - private final FileChooserController controller; - - public BaseNavigateActionOpen(FileChooserController controller) { - super(controller); - this.controller = controller; - } - - @Override - public void performLongOperation(CheckBeforeActionResult checkBeforeActionResult) { - // When double click a file on the table - FileObject fileObject = controller.getSelectedFileObject(); - if (canExecuteDefaultAction()) { - controller.closeAndReturn(ReturnValue.Approve); - } else { - controller.goToURL(fileObject); - } - } - - @Override - protected boolean canGoUrl() { - FileObject fileObject = controller.getSelectedFileObject(); - if (fileObject != null) { - try { - return VFSUtils.canGoUrl(fileObject); - } catch (FileSystemException e) { - LOGGER.error("Can't open location", e.getMessage()); - } - } - return false; - } - - @Override - protected boolean canExecuteDefaultAction() { - SelectionMode selectionMode = controller.getSelectionMode(); - if (selectionMode.isFilesOnly() || selectionMode.isDirsAndFiles()) { - FileObject fileObject = controller.getSelectedFileObject(); - if (fileObject != null) { - try { - return FileType.FILE.equals(fileObject.getType()) || FileType.FILE_OR_FOLDER.equals(fileObject.getType()); - } catch (FileSystemException e) { - LOGGER.warn("Cant' get file type", e); - } - } - } - return false; - } - -} diff --git a/src/eu/engys/util/filechooser/actions/pathnavigation/BaseNavigateActionRefresh.java b/src/eu/engys/util/filechooser/actions/pathnavigation/BaseNavigateActionRefresh.java deleted file mode 100644 index 2843edb..0000000 --- a/src/eu/engys/util/filechooser/actions/pathnavigation/BaseNavigateActionRefresh.java +++ /dev/null @@ -1,76 +0,0 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - -package eu.engys.util.filechooser.actions.pathnavigation; - -import javax.swing.Icon; - -import org.apache.commons.vfs2.FileObject; -import org.apache.commons.vfs2.FileSystemException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import eu.engys.util.filechooser.gui.FileChooserController; -import eu.engys.util.ui.ResourcesUtil; - -public final class BaseNavigateActionRefresh extends BaseNavigateAction { - - private static final Logger LOGGER = LoggerFactory.getLogger(BaseNavigateActionRefresh.class); - - public BaseNavigateActionRefresh(FileChooserController controller) { - super(controller); - putValue(SMALL_ICON, ARROWCIRCLEDOUBLE); - putValue(SHORT_DESCRIPTION, NAV_REFRESHACTIONLABELTEXT); - } - - @Override - public void performLongOperation(CheckBeforeActionResult checkBeforeActionResult) { - try { - FileObject fileObject = controller.getUriPanel().getFileObject(); - fileObject.refresh(); - controller.goToURL(fileObject); - } catch (FileSystemException e) { - LOGGER.error("Can't refresh location", e.getMessage()); - } - } - - @Override - protected boolean canGoUrl() { - return true; - } - - @Override - protected boolean canExecuteDefaultAction() { - return false; - } - - /** - * Resources - */ - - private static final String NAV_REFRESHACTIONLABELTEXT = ResourcesUtil.getString("nav.refreshActionLabelText"); - private static final Icon ARROWCIRCLEDOUBLE = ResourcesUtil.getIcon("arrowCircleDouble"); - -} diff --git a/src/eu/engys/util/filechooser/authentication/AuthStore.java b/src/eu/engys/util/filechooser/authentication/AuthStore.java index 45b5d09..e6f5f5d 100644 --- a/src/eu/engys/util/filechooser/authentication/AuthStore.java +++ b/src/eu/engys/util/filechooser/authentication/AuthStore.java @@ -1,43 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - -/* - * Copyright 2012 Krzysztof Otrebski (krzysztof.otrebski@gmail.com) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.filechooser.authentication; diff --git a/src/eu/engys/util/filechooser/authentication/AuthStoreUtils.java b/src/eu/engys/util/filechooser/authentication/AuthStoreUtils.java index 5dde411..0099e55 100644 --- a/src/eu/engys/util/filechooser/authentication/AuthStoreUtils.java +++ b/src/eu/engys/util/filechooser/authentication/AuthStoreUtils.java @@ -1,43 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - -/* - * Copyright 2012 Krzysztof Otrebski (krzysztof.otrebski@gmail.com) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.filechooser.authentication; @@ -75,9 +59,9 @@ import org.xml.sax.XMLReader; import org.xml.sax.helpers.DefaultHandler; import org.xml.sax.helpers.XMLReaderFactory; -public class AuthStoreUtils { +import eu.engys.util.Util; - private static final java.util.logging.Logger LOGGER = java.util.logging.Logger.getLogger(AuthStoreUtils.class.getName()); +public class AuthStoreUtils { public static final String USER = "user"; public static final String HOST = "host"; @@ -274,7 +258,7 @@ public class AuthStoreUtils { Cipher cipher = Cipher.getInstance(ALGORITHM_BLOW_FISH); cipher.init(Cipher.ENCRYPT_MODE, secretKeySpec); - byte[] encrypted = cipher.doFinal(new String(bytes).getBytes("UTF-8")); + byte[] encrypted = cipher.doFinal(new String(bytes).getBytes(Util.UTF_8)); return encrypted; } @@ -288,11 +272,11 @@ public class AuthStoreUtils { } protected byte[] charsToBytes(char[] chars) throws UnsupportedEncodingException { - return new String(chars).getBytes("UTF-8"); + return new String(chars).getBytes(Util.UTF_8); } protected char[] bytesToChars(byte[] bytes) { - return new String(bytes, Charset.forName("UTF-8")).toCharArray(); + return new String(bytes, Charset.forName(Util.UTF_8)).toCharArray(); } public PasswordProvider getPasswordProvider() { diff --git a/src/eu/engys/util/filechooser/authentication/AuthorisationCancelledException.java b/src/eu/engys/util/filechooser/authentication/AuthorisationCancelledException.java index 34e022d..7bc4735 100644 --- a/src/eu/engys/util/filechooser/authentication/AuthorisationCancelledException.java +++ b/src/eu/engys/util/filechooser/authentication/AuthorisationCancelledException.java @@ -1,43 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - -/* - * Copyright 2012 Krzysztof Otrebski (krzysztof.otrebski@gmail.com) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.filechooser.authentication; diff --git a/src/eu/engys/util/filechooser/authentication/CompositeAuthStore.java b/src/eu/engys/util/filechooser/authentication/CompositeAuthStore.java index 1db3e11..ee11f44 100644 --- a/src/eu/engys/util/filechooser/authentication/CompositeAuthStore.java +++ b/src/eu/engys/util/filechooser/authentication/CompositeAuthStore.java @@ -1,43 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - -/* - * Copyright 2012 Krzysztof Otrebski (krzysztof.otrebski@gmail.com) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.filechooser.authentication; diff --git a/src/eu/engys/util/filechooser/authentication/DialogPasswordProvider.java b/src/eu/engys/util/filechooser/authentication/DialogPasswordProvider.java index 44909a6..7f63db6 100644 --- a/src/eu/engys/util/filechooser/authentication/DialogPasswordProvider.java +++ b/src/eu/engys/util/filechooser/authentication/DialogPasswordProvider.java @@ -1,43 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - -/* - * Copyright 2012 Krzysztof Otrebski (krzysztof.otrebski@gmail.com) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.filechooser.authentication; diff --git a/src/eu/engys/util/filechooser/authentication/MemoryAuthStore.java b/src/eu/engys/util/filechooser/authentication/MemoryAuthStore.java index 2410c95..214ea9f 100644 --- a/src/eu/engys/util/filechooser/authentication/MemoryAuthStore.java +++ b/src/eu/engys/util/filechooser/authentication/MemoryAuthStore.java @@ -1,43 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - -/* - * Copyright 2012 Krzysztof Otrebski (krzysztof.otrebski@gmail.com) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.filechooser.authentication; diff --git a/src/eu/engys/util/filechooser/authentication/PasswordProvider.java b/src/eu/engys/util/filechooser/authentication/PasswordProvider.java index 0abae91..2f5b7fc 100644 --- a/src/eu/engys/util/filechooser/authentication/PasswordProvider.java +++ b/src/eu/engys/util/filechooser/authentication/PasswordProvider.java @@ -1,43 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - -/* - * Copyright 2012 Krzysztof Otrebski (krzysztof.otrebski@gmail.com) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.filechooser.authentication; diff --git a/src/eu/engys/util/filechooser/authentication/StaticPasswordProvider.java b/src/eu/engys/util/filechooser/authentication/StaticPasswordProvider.java index f856d75..1c6a809 100644 --- a/src/eu/engys/util/filechooser/authentication/StaticPasswordProvider.java +++ b/src/eu/engys/util/filechooser/authentication/StaticPasswordProvider.java @@ -1,43 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - -/* - * Copyright 2012 Krzysztof Otrebski (krzysztof.otrebski@gmail.com) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.filechooser.authentication; diff --git a/src/eu/engys/util/filechooser/authentication/UserAuthenticationDataWrapper.java b/src/eu/engys/util/filechooser/authentication/UserAuthenticationDataWrapper.java index e3add8b..0ef7954 100644 --- a/src/eu/engys/util/filechooser/authentication/UserAuthenticationDataWrapper.java +++ b/src/eu/engys/util/filechooser/authentication/UserAuthenticationDataWrapper.java @@ -1,43 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - -/* - * Copyright 2012 Krzysztof Otrebski (krzysztof.otrebski@gmail.com) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.filechooser.authentication; diff --git a/src/eu/engys/util/filechooser/authentication/UserAuthenticationInfo.java b/src/eu/engys/util/filechooser/authentication/UserAuthenticationInfo.java index aa6607a..e497826 100644 --- a/src/eu/engys/util/filechooser/authentication/UserAuthenticationInfo.java +++ b/src/eu/engys/util/filechooser/authentication/UserAuthenticationInfo.java @@ -1,43 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - -/* - * Copyright 2012 Krzysztof Otrebski (krzysztof.otrebski@gmail.com) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.filechooser.authentication; @@ -106,4 +90,4 @@ public class UserAuthenticationInfo { return "UserAuthenticationInfo [ user: " +user + " - host: " + host + " - protocol: " + protocol + " ]" ; } -} +} \ No newline at end of file diff --git a/src/eu/engys/util/filechooser/authentication/UserAuthenticatorFactory.java b/src/eu/engys/util/filechooser/authentication/UserAuthenticatorFactory.java index 5133a72..6b82e37 100644 --- a/src/eu/engys/util/filechooser/authentication/UserAuthenticatorFactory.java +++ b/src/eu/engys/util/filechooser/authentication/UserAuthenticatorFactory.java @@ -1,43 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - -/* - * Copyright 2012 Krzysztof Otrebski (krzysztof.otrebski@gmail.com) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.filechooser.authentication; diff --git a/src/eu/engys/util/filechooser/authentication/authenticator/AbstractUiUserAuthenticator.java b/src/eu/engys/util/filechooser/authentication/authenticator/AbstractUiUserAuthenticator.java index be68ba6..c5604a6 100644 --- a/src/eu/engys/util/filechooser/authentication/authenticator/AbstractUiUserAuthenticator.java +++ b/src/eu/engys/util/filechooser/authentication/authenticator/AbstractUiUserAuthenticator.java @@ -1,43 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - -/* - * Copyright 2012 Krzysztof Otrebski (krzysztof.otrebski@gmail.com) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.filechooser.authentication.authenticator; @@ -54,7 +38,6 @@ import org.apache.commons.vfs2.UserAuthenticationData.Type; import eu.engys.util.filechooser.authentication.UserAuthenticationDataWrapper; import eu.engys.util.filechooser.uri.VFSURIParser; import eu.engys.util.ui.ExecUtil; -import eu.engys.util.ui.ResourcesUtil; import eu.engys.util.ui.UiUtil; import eu.engys.util.ui.builder.PanelBuilder; @@ -68,7 +51,7 @@ public abstract class AbstractUiUserAuthenticator implements OtrosUserAuthentica public AbstractUiUserAuthenticator(String url, FileSystemOptions fileSystemOptions) { this.url = url; - this.title = MessageFormat.format(AUTHENTICATOR_ENTERCREDENTIALSFORURL, url); + this.title = MessageFormat.format("Enter credentials for URL {0}", url); this.fileSystemOptions = fileSystemOptions; this.vfsUriParser = new VFSURIParser(url); } @@ -121,11 +104,4 @@ public abstract class AbstractUiUserAuthenticator implements OtrosUserAuthentica return fileSystemOptions; } - /** - * Resources - */ - - private static final String AUTHENTICATOR_SAVEPASSWORD = ResourcesUtil.getString("authenticator.savePassword"); - private static final String AUTHENTICATOR_ENTERCREDENTIALSFORURL = ResourcesUtil.getString("authenticator.enterCredentialsForUrl"); - } diff --git a/src/eu/engys/util/filechooser/authentication/authenticator/OtrosStaticUserAuthenticator.java b/src/eu/engys/util/filechooser/authentication/authenticator/OtrosStaticUserAuthenticator.java index 75ba395..e16023f 100644 --- a/src/eu/engys/util/filechooser/authentication/authenticator/OtrosStaticUserAuthenticator.java +++ b/src/eu/engys/util/filechooser/authentication/authenticator/OtrosStaticUserAuthenticator.java @@ -1,43 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - -/* - * Copyright 2012 Krzysztof Otrebski (krzysztof.otrebski@gmail.com) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.filechooser.authentication.authenticator; diff --git a/src/eu/engys/util/filechooser/authentication/authenticator/OtrosUserAuthenticator.java b/src/eu/engys/util/filechooser/authentication/authenticator/OtrosUserAuthenticator.java index ebf26ec..a473a8a 100644 --- a/src/eu/engys/util/filechooser/authentication/authenticator/OtrosUserAuthenticator.java +++ b/src/eu/engys/util/filechooser/authentication/authenticator/OtrosUserAuthenticator.java @@ -1,43 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - -/* - * Copyright 2012 Krzysztof Otrebski (krzysztof.otrebski@gmail.com) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.filechooser.authentication.authenticator; diff --git a/src/eu/engys/util/filechooser/authentication/authenticator/UseCentralsFromSessionUserAuthenticator.java b/src/eu/engys/util/filechooser/authentication/authenticator/UseCentralsFromSessionUserAuthenticator.java index 7789ec5..72fa7d3 100644 --- a/src/eu/engys/util/filechooser/authentication/authenticator/UseCentralsFromSessionUserAuthenticator.java +++ b/src/eu/engys/util/filechooser/authentication/authenticator/UseCentralsFromSessionUserAuthenticator.java @@ -1,32 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - -/* - * Copyright (c) 2012. Krzysztof Otrebski - * All right reserved - */ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.filechooser.authentication.authenticator; diff --git a/src/eu/engys/util/filechooser/depot/FTPUserAuthenticator.java b/src/eu/engys/util/filechooser/depot/FTPUserAuthenticator.java index 0b0ab6b..3a1a39b 100644 --- a/src/eu/engys/util/filechooser/depot/FTPUserAuthenticator.java +++ b/src/eu/engys/util/filechooser/depot/FTPUserAuthenticator.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.filechooser.depot; ///* // * Copyright 2012 Krzysztof Otrebski (krzysztof.otrebski@gmail.com) diff --git a/src/eu/engys/util/filechooser/depot/OriginalVfsBrowser.java b/src/eu/engys/util/filechooser/depot/OriginalVfsBrowser.java index 1dbaeb0..7484b4f 100644 --- a/src/eu/engys/util/filechooser/depot/OriginalVfsBrowser.java +++ b/src/eu/engys/util/filechooser/depot/OriginalVfsBrowser.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.filechooser.depot; ///* // * Copyright 2012 Krzysztof Otrebski (krzysztof.otrebski@gmail.com) diff --git a/src/eu/engys/util/filechooser/depot/SftpUserAuthenticator.java b/src/eu/engys/util/filechooser/depot/SftpUserAuthenticator.java index f81f133..72f7e65 100644 --- a/src/eu/engys/util/filechooser/depot/SftpUserAuthenticator.java +++ b/src/eu/engys/util/filechooser/depot/SftpUserAuthenticator.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.filechooser.depot; ///* // * Copyright 2012 Krzysztof Otrebski (krzysztof.otrebski@gmail.com) diff --git a/src/eu/engys/util/filechooser/depot/SmbUserAuthenticator.java b/src/eu/engys/util/filechooser/depot/SmbUserAuthenticator.java index 9f8bfdf..0ed5b3c 100644 --- a/src/eu/engys/util/filechooser/depot/SmbUserAuthenticator.java +++ b/src/eu/engys/util/filechooser/depot/SmbUserAuthenticator.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.filechooser.depot; ///* // * Copyright 2012 Krzysztof Otrebski (krzysztof.otrebski@gmail.com) diff --git a/src/eu/engys/util/filechooser/favorites/Favorite.java b/src/eu/engys/util/filechooser/favorites/Favorite.java index 4d208af..4c5deb5 100644 --- a/src/eu/engys/util/filechooser/favorites/Favorite.java +++ b/src/eu/engys/util/filechooser/favorites/Favorite.java @@ -1,43 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - -/* - * Copyright 2012 Krzysztof Otrebski (krzysztof.otrebski@gmail.com) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.filechooser.favorites; diff --git a/src/eu/engys/util/filechooser/favorites/FavoritesUtils.java b/src/eu/engys/util/filechooser/favorites/FavoritesUtils.java index ff15206..4659f67 100644 --- a/src/eu/engys/util/filechooser/favorites/FavoritesUtils.java +++ b/src/eu/engys/util/filechooser/favorites/FavoritesUtils.java @@ -1,43 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - -/* - * Copyright 2012 Krzysztof Otrebski (krzysztof.otrebski@gmail.com) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.filechooser.favorites; diff --git a/src/eu/engys/util/filechooser/favorites/PopupListener.java b/src/eu/engys/util/filechooser/favorites/PopupListener.java index 945a4e8..727078b 100644 --- a/src/eu/engys/util/filechooser/favorites/PopupListener.java +++ b/src/eu/engys/util/filechooser/favorites/PopupListener.java @@ -1,43 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - -/* - * Copyright 2012 Krzysztof Otrebski (krzysztof.otrebski@gmail.com) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.filechooser.favorites; @@ -113,4 +97,4 @@ public class PopupListener extends MouseAdapter implements KeyListener { public void keyReleased(KeyEvent e) { } -} +} \ No newline at end of file diff --git a/src/eu/engys/util/filechooser/favorites/list/MutableListDragListener.java b/src/eu/engys/util/filechooser/favorites/list/MutableListDragListener.java index 6ee854d..d8c135e 100644 --- a/src/eu/engys/util/filechooser/favorites/list/MutableListDragListener.java +++ b/src/eu/engys/util/filechooser/favorites/list/MutableListDragListener.java @@ -1,43 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - -/* - * Copyright 2012 Krzysztof Otrebski (krzysztof.otrebski@gmail.com) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.filechooser.favorites.list; @@ -84,4 +68,4 @@ public class MutableListDragListener implements DragSourceListener, DragGestureL public void dropActionChanged(final DragSourceDragEvent dsde) { } -} +} \ No newline at end of file diff --git a/src/eu/engys/util/filechooser/favorites/list/MutableListDropHandler.java b/src/eu/engys/util/filechooser/favorites/list/MutableListDropHandler.java index da82ed3..962ae71 100644 --- a/src/eu/engys/util/filechooser/favorites/list/MutableListDropHandler.java +++ b/src/eu/engys/util/filechooser/favorites/list/MutableListDropHandler.java @@ -1,43 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - -/* - * Copyright 2012 Krzysztof Otrebski (krzysztof.otrebski@gmail.com) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.filechooser.favorites.list; @@ -92,4 +76,4 @@ public class MutableListDropHandler extends TransferHandler { model.move(index, dropTargetIndex); return true; } -} +} \ No newline at end of file diff --git a/src/eu/engys/util/filechooser/favorites/list/MutableListModel.java b/src/eu/engys/util/filechooser/favorites/list/MutableListModel.java index 6887c21..997ca02 100644 --- a/src/eu/engys/util/filechooser/favorites/list/MutableListModel.java +++ b/src/eu/engys/util/filechooser/favorites/list/MutableListModel.java @@ -1,43 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - -/* - * Copyright 2012 Krzysztof Otrebski (krzysztof.otrebski@gmail.com) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.filechooser.favorites.list; diff --git a/src/eu/engys/util/filechooser/favorites/list/SelectFirstElementFocusAdapter.java b/src/eu/engys/util/filechooser/favorites/list/SelectFirstElementFocusAdapter.java index a61ecdb..b5f786e 100644 --- a/src/eu/engys/util/filechooser/favorites/list/SelectFirstElementFocusAdapter.java +++ b/src/eu/engys/util/filechooser/favorites/list/SelectFirstElementFocusAdapter.java @@ -1,43 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - -/* - * Copyright 2012 Krzysztof Otrebski (krzysztof.otrebski@gmail.com) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.filechooser.favorites.list; diff --git a/src/eu/engys/util/filechooser/favorites/renderer/FavoriteListCellRenderer.java b/src/eu/engys/util/filechooser/favorites/renderer/FavoriteListCellRenderer.java index 76d1074..12468ee 100644 --- a/src/eu/engys/util/filechooser/favorites/renderer/FavoriteListCellRenderer.java +++ b/src/eu/engys/util/filechooser/favorites/renderer/FavoriteListCellRenderer.java @@ -1,43 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - -/* - * Copyright 2012 Krzysztof Otrebski (krzysztof.otrebski@gmail.com) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.filechooser.favorites.renderer; @@ -87,7 +71,7 @@ public class FavoriteListCellRenderer extends DefaultListCellRenderer { /* * RESOURCES */ - private static final Icon HOME_ICON = ResourcesUtil.getIcon("home"); - private static final Icon DESKTOP_ICON = ResourcesUtil.getIcon("desktop"); - private static final Icon DOCUMENTS_ICON = ResourcesUtil.getIcon("documents"); + private static final Icon HOME_ICON = ResourcesUtil.getIcon("folder.user"); + private static final Icon DESKTOP_ICON = ResourcesUtil.getIcon("folder.desktop"); + private static final Icon DOCUMENTS_ICON = ResourcesUtil.getIcon("folder.documents"); } diff --git a/src/eu/engys/util/filechooser/gui/Accessory.java b/src/eu/engys/util/filechooser/gui/Accessory.java index 976bb31..af9190c 100644 --- a/src/eu/engys/util/filechooser/gui/Accessory.java +++ b/src/eu/engys/util/filechooser/gui/Accessory.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.filechooser.gui; import javax.swing.JPanel; diff --git a/src/eu/engys/util/filechooser/gui/BreadCrumbsPanel.java b/src/eu/engys/util/filechooser/gui/BreadCrumbsPanel.java index 1416717..695f35e 100644 --- a/src/eu/engys/util/filechooser/gui/BreadCrumbsPanel.java +++ b/src/eu/engys/util/filechooser/gui/BreadCrumbsPanel.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.filechooser.gui; import java.awt.BorderLayout; diff --git a/src/eu/engys/util/filechooser/gui/BrowserFactory.java b/src/eu/engys/util/filechooser/gui/BrowserFactory.java index 16a21d0..a306a81 100644 --- a/src/eu/engys/util/filechooser/gui/BrowserFactory.java +++ b/src/eu/engys/util/filechooser/gui/BrowserFactory.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.filechooser.gui; import eu.engys.util.connection.SshParameters; diff --git a/src/eu/engys/util/filechooser/gui/ButtonsPanel.java b/src/eu/engys/util/filechooser/gui/ButtonsPanel.java index a4e93de..8f506fd 100644 --- a/src/eu/engys/util/filechooser/gui/ButtonsPanel.java +++ b/src/eu/engys/util/filechooser/gui/ButtonsPanel.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.filechooser.gui; import java.awt.BorderLayout; @@ -39,8 +38,6 @@ import javax.swing.JList; import javax.swing.JPanel; import javax.swing.ListCellRenderer; -import net.java.dev.designgridlayout.Componentizer; - import org.apache.commons.vfs2.FileObject; import org.apache.commons.vfs2.FileSystemException; import org.apache.commons.vfs2.FileType; @@ -49,6 +46,7 @@ import eu.engys.util.filechooser.AbstractFileChooser.ReturnValue; import eu.engys.util.filechooser.util.HelyxFileFilter; import eu.engys.util.ui.ExecUtil; import eu.engys.util.ui.builder.PanelBuilder; +import net.java.dev.designgridlayout.Componentizer; public class ButtonsPanel extends JPanel { @@ -86,7 +84,6 @@ public class ButtonsPanel extends JPanel { public void updateOkButton() { ExecUtil.invokeAndWait(new Runnable() { - @Override public void run() { _updateOkButton_OnEDT(); diff --git a/src/eu/engys/util/filechooser/gui/FavoritesPanel.java b/src/eu/engys/util/filechooser/gui/FavoritesPanel.java index ff8eeee..d00c8fa 100644 --- a/src/eu/engys/util/filechooser/gui/FavoritesPanel.java +++ b/src/eu/engys/util/filechooser/gui/FavoritesPanel.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.filechooser.gui; import java.awt.BorderLayout; @@ -52,8 +51,8 @@ import javax.swing.border.CompoundBorder; import javax.swing.event.ListDataEvent; import javax.swing.event.ListDataListener; -import eu.engys.util.filechooser.actions.favorite.EditFavorite; -import eu.engys.util.filechooser.actions.favorite.OpenFavorite; +import eu.engys.util.filechooser.actions.favorite.OpenFavoriteAction; +import eu.engys.util.filechooser.actions.favorite.RenameFavoriteAction; import eu.engys.util.filechooser.favorites.Favorite; import eu.engys.util.filechooser.favorites.FavoritesUtils; import eu.engys.util.filechooser.favorites.PopupListener; @@ -119,7 +118,7 @@ public class FavoritesPanel extends JPanel { addOpenActionToList(favoriteSystemList); addPopupMenu(favoriteSystemList, ACTION_OPEN); - JLabel systemLocationLabel = createLabelWithIcon(FAVORITES_SYSTEMLOCATIONS, COMPUTER_ICON); + JLabel systemLocationLabel = createLabelWithIcon(SYSTEM_LABEL, SYSTEM_ICON); if (!controller.isRemote()) { JPanel systemPanel = new JPanel(new BorderLayout()); @@ -141,9 +140,9 @@ public class FavoritesPanel extends JPanel { addOpenActionToList(favoritesUserList); addEditActionToList(favoritesUserList, userListModel); - addPopupMenu(favoritesUserList, ACTION_OPEN, ACTION_EDIT, ACTION_DELETE); + addPopupMenu(favoritesUserList, ACTION_EDIT, ACTION_DELETE); - JLabel userFavouritesLabel = createLabelWithIcon(FAVORITES_FAVORITES, STAR); + JLabel userFavouritesLabel = createLabelWithIcon(USER_LABEL, USER_ICON); JPanel favoritesPanel = new JPanel(new BorderLayout()); favoritesPanel.setName(FAVORITES_PANEL); @@ -194,7 +193,7 @@ public class FavoritesPanel extends JPanel { final JList favoritesUserList = new JList(userListModel); favoritesUserList.setTransferHandler(new MutableListDropHandler(favoritesUserList)); new MutableListDragListener(favoritesUserList); - favoritesUserList.getActionMap().put(ACTION_DELETE, new AbstractAction("Delete", MINUSBUTTON) { + favoritesUserList.getActionMap().put(ACTION_DELETE, new AbstractAction(DELETE_LABEL, DELETE_ICON) { @Override public void actionPerformed(ActionEvent e) { @@ -260,12 +259,12 @@ public class FavoritesPanel extends JPanel { } private void addOpenActionToList(final JList favoritesList) { - favoritesList.getActionMap().put(ACTION_OPEN, new OpenFavorite(controller, favoritesList)); + favoritesList.getActionMap().put(ACTION_OPEN, new OpenFavoriteAction(controller, favoritesList)); favoritesList.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { boolean isLeftButton = e.getButton() == MouseEvent.BUTTON1; - boolean isSingleClick = e.getClickCount() == 1; - if (isSingleClick && isLeftButton) { + boolean isDoubleClick = e.getClickCount() == 2; + if (isDoubleClick && isLeftButton) { favoritesList.getActionMap().get(ACTION_OPEN).actionPerformed(null); } } @@ -275,7 +274,7 @@ public class FavoritesPanel extends JPanel { } private void addEditActionToList(JList favoritesList, MutableListModel listModel) { - favoritesList.getActionMap().put(ACTION_EDIT, new EditFavorite(controller, favoritesList, listModel)); + favoritesList.getActionMap().put(ACTION_EDIT, new RenameFavoriteAction(controller, favoritesList, listModel)); InputMap favoritesListInputMap = favoritesList.getInputMap(JComponent.WHEN_FOCUSED); favoritesListInputMap.put(KeyStroke.getKeyStroke("F2"), ACTION_EDIT); @@ -285,10 +284,13 @@ public class FavoritesPanel extends JPanel { * Resources */ - private static final String FAVORITES_SYSTEMLOCATIONS = ResourcesUtil.getString("favorites.systemLocations"); - private static final String FAVORITES_FAVORITES = ResourcesUtil.getString("favorites.favorites"); + private static final String SYSTEM_LABEL = ResourcesUtil.getString("favorites.system.label"); + private static final Icon SYSTEM_ICON = ResourcesUtil.getIcon("favorites.system.icon"); - private static final Icon COMPUTER_ICON = ResourcesUtil.getIcon("computer"); - private static final Icon STAR = ResourcesUtil.getIcon("star"); - private static final Icon MINUSBUTTON = ResourcesUtil.getIcon("minusButton"); -} + private static final String USER_LABEL = ResourcesUtil.getString("favorites.user.label"); + private static final Icon USER_ICON = ResourcesUtil.getIcon("favorites.user.icon"); + + private static final String DELETE_LABEL = ResourcesUtil.getString("favorites.delete.label"); + private static final Icon DELETE_ICON = ResourcesUtil.getIcon("favorites.delete.icon"); + +} \ No newline at end of file diff --git a/src/eu/engys/util/filechooser/gui/FileChooserController.java b/src/eu/engys/util/filechooser/gui/FileChooserController.java index 1dc5158..624b3f6 100644 --- a/src/eu/engys/util/filechooser/gui/FileChooserController.java +++ b/src/eu/engys/util/filechooser/gui/FileChooserController.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.filechooser.gui; import org.apache.commons.vfs2.FileObject; @@ -71,6 +70,15 @@ public class FileChooserController { // this.breadCrumbsPanel = chooserPanel.getBreadCrumbsPanel(); } + public void refreshLocation(FileObject fileObject) { + try { + fileObject.refresh(); + goToURL(fileObject); + } catch (FileSystemException e) { + logger.error("Can't refresh location", e.getMessage()); + } + } + public void goToURL(final String url, boolean encoded) { String encodedURL = encoded ? url : VFSUtils.encode(url, sshParameters); try { @@ -101,15 +109,9 @@ public class FileChooserController { @Override public void run() { FileObject[] fileObjectsWithParent = files; - if (fileSystemPanel != null) { - fileSystemPanel.setContent(fileObjectsWithParent); - } - if (uriPanel != null) { - uriPanel.setFileObject(fileObject); - } - if (fileSystemPanel != null) { - fileSystemPanel.resetFilter(); - } + fileSystemPanel.setContent(fileObjectsWithParent); + uriPanel.setFileObject(fileObject); + fileSystemPanel.resetFilter(); } }); updateOkButton(); @@ -137,7 +139,9 @@ public class FileChooserController { } public void resetFileFilter() { - buttonsPanel.resetFileFilter(); + if (buttonsPanel != null) { + buttonsPanel.resetFileFilter(); + } } public URIPanel getUriPanel() { @@ -179,11 +183,15 @@ public class FileChooserController { } public void updateNewFileName() { - uriPanel.updateFileName(); + if (uriPanel != null) { + uriPanel.updateFileName(); + } } public void updateOkButton() { - buttonsPanel.updateOkButton(); + if (buttonsPanel != null) { + buttonsPanel.updateOkButton(); + } } public void closeAndReturn(ReturnValue retVal) { @@ -217,10 +225,18 @@ public class FileChooserController { /* * For tests purposes only */ + public FavoritesPanel getFavoritesPanel() { + return favoritesPanel; + } + public void setFavoritesPanel(FavoritesPanel favoritesPanel) { this.favoritesPanel = favoritesPanel; } + public void setFileSystemPanel(FileSystemPanel fileSystemPanel) { + this.fileSystemPanel = fileSystemPanel; + } + public void setUriPanel(URIPanel uriPanel) { this.uriPanel = uriPanel; } diff --git a/src/eu/engys/util/filechooser/gui/FileChooserPanel.java b/src/eu/engys/util/filechooser/gui/FileChooserPanel.java index eda5b10..11c5ff9 100644 --- a/src/eu/engys/util/filechooser/gui/FileChooserPanel.java +++ b/src/eu/engys/util/filechooser/gui/FileChooserPanel.java @@ -1,43 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - -/* - * Copyright 2012 Krzysztof Otrebski (krzysztof.otrebski@gmail.com) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.filechooser.gui; diff --git a/src/eu/engys/util/filechooser/gui/FileSystemPanel.java b/src/eu/engys/util/filechooser/gui/FileSystemPanel.java index 3d72b65..9a6bff7 100644 --- a/src/eu/engys/util/filechooser/gui/FileSystemPanel.java +++ b/src/eu/engys/util/filechooser/gui/FileSystemPanel.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.filechooser.gui; import java.awt.BorderLayout; @@ -37,12 +36,13 @@ import java.util.Date; import java.util.List; import javax.swing.ActionMap; -import javax.swing.BorderFactory; import javax.swing.InputMap; import javax.swing.JButton; import javax.swing.JComponent; +import javax.swing.JMenuItem; import javax.swing.JOptionPane; import javax.swing.JPanel; +import javax.swing.JPopupMenu; import javax.swing.JScrollPane; import javax.swing.JTable; import javax.swing.JTextField; @@ -65,12 +65,15 @@ import org.apache.commons.vfs2.FileSystemException; import org.apache.commons.vfs2.FileType; import eu.engys.util.ArchiveUtils; +import eu.engys.util.filechooser.actions.CloneFileAction; import eu.engys.util.filechooser.actions.DeleteFileAction; import eu.engys.util.filechooser.actions.ExtractArchiveAction; import eu.engys.util.filechooser.actions.NewFolderAction; -import eu.engys.util.filechooser.actions.pathnavigation.BaseNavigateActionGoUp; -import eu.engys.util.filechooser.actions.pathnavigation.BaseNavigateActionOpen; -import eu.engys.util.filechooser.actions.pathnavigation.BaseNavigateActionRefresh; +import eu.engys.util.filechooser.actions.RenameFileAction; +import eu.engys.util.filechooser.actions.navigation.BaseNavigateActionGoUp; +import eu.engys.util.filechooser.actions.navigation.BaseNavigateActionOpen; +import eu.engys.util.filechooser.actions.navigation.BaseNavigateActionRefresh; +import eu.engys.util.filechooser.favorites.PopupListener; import eu.engys.util.filechooser.table.FileNameWithType; import eu.engys.util.filechooser.table.FileNameWithTypeComparator; import eu.engys.util.filechooser.table.FileSize; @@ -88,11 +91,13 @@ import eu.engys.util.ui.treetable.TableFilter; public class FileSystemPanel extends JPanel { - private static final String ACTION_OPEN = "OPEN"; - private static final String ACTION_GO_UP = "GO_UP"; - private static final String ACTION_REFRESH = "REFRESH"; - private static final String ACTION_DELETE = "DELETE"; - private static final String ACTION_APPROVE = "ACTION APPROVE"; + public static final String ACTION_OPEN = "OPEN"; + public static final String ACTION_GO_UP = "GO_UP"; + public static final String ACTION_REFRESH = "REFRESH"; + public static final String ACTION_RENAME = "RENAME"; + public static final String ACTION_CLONE = "CLONE"; + public static final String ACTION_DELETE = "DELETE"; + public static final String ACTION_APPROVE = "ACTION APPROVE"; public static final String NAME = "chooser.filesystempanel"; public static final String CREATE_FOLDER = "create.folder"; @@ -129,6 +134,7 @@ public class FileSystemPanel extends JPanel { FileSystemTableModel model = new FileSystemTableModel(); this.table = new JTable(model); populateActionMap(); + addPopupMenu(table, ACTION_RENAME, ACTION_CLONE, ACTION_DELETE); populateInputMap(); setColumnSize(); @@ -136,7 +142,6 @@ public class FileSystemPanel extends JPanel { table.setRowSorter(sorter); tableFilter = new TableFilter(""); - tableFilter.setColumnsWhereToSearch(0); sorter.setRowFilter(tableFilter); table.setFillsViewportHeight(true); @@ -162,9 +167,6 @@ public class FileSystemPanel extends JPanel { bar.add(createFolderButton); bar.add(deleteFileButton); bar.add(extractArchiveButton); - - bar.setBorder(BorderFactory.createEmptyBorder()); - return bar; } @@ -193,7 +195,7 @@ public class FileSystemPanel extends JPanel { } private void filter() { - tableFilter.setFilterText(searchField.getText()); + tableFilter.setFilterText(0, searchField.getText()); sorter.sort(); } @@ -279,6 +281,8 @@ public class FileSystemPanel extends JPanel { inputMap.put(KeyStroke.getKeyStroke("DELETE"), ACTION_DELETE); inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_CANCEL, 0), ACTION_DELETE); + inputMap.put(KeyStroke.getKeyStroke("F2"), ACTION_RENAME); + inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_F2, 0), ACTION_REFRESH); } private void populateActionMap() { @@ -287,6 +291,19 @@ public class FileSystemPanel extends JPanel { actionMap.put(ACTION_GO_UP, new BaseNavigateActionGoUp(controller)); actionMap.put(ACTION_REFRESH, new BaseNavigateActionRefresh(controller)); actionMap.put(ACTION_DELETE, new DeleteFileAction(controller)); + actionMap.put(ACTION_RENAME, new RenameFileAction(controller, table)); + actionMap.put(ACTION_CLONE, new CloneFileAction(controller, table)); + } + + private JPopupMenu addPopupMenu(JTable table, String... actions) { + JPopupMenu favoritesPopupMenu = new JPopupMenu(); + for (String action : actions) { + JMenuItem item = favoritesPopupMenu.add(table.getActionMap().get(action)); + item.setName(action); + } + table.addKeyListener(new PopupListener(favoritesPopupMenu)); + table.addMouseListener(new PopupListener(favoritesPopupMenu)); + return favoritesPopupMenu; } public FileObject getSelectedFileObject() { diff --git a/src/eu/engys/util/filechooser/gui/LoadingPanel.java b/src/eu/engys/util/filechooser/gui/LoadingPanel.java index e74547a..fc8c9b5 100644 --- a/src/eu/engys/util/filechooser/gui/LoadingPanel.java +++ b/src/eu/engys/util/filechooser/gui/LoadingPanel.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.filechooser.gui; import java.awt.BorderLayout; diff --git a/src/eu/engys/util/filechooser/gui/Options.java b/src/eu/engys/util/filechooser/gui/Options.java index fd69107..a7673f7 100644 --- a/src/eu/engys/util/filechooser/gui/Options.java +++ b/src/eu/engys/util/filechooser/gui/Options.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.filechooser.gui; import javax.swing.JPanel; diff --git a/src/eu/engys/util/filechooser/gui/URIPanel.java b/src/eu/engys/util/filechooser/gui/URIPanel.java index d53fc7f..c71dd2a 100644 --- a/src/eu/engys/util/filechooser/gui/URIPanel.java +++ b/src/eu/engys/util/filechooser/gui/URIPanel.java @@ -1,32 +1,33 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.filechooser.gui; import java.awt.BorderLayout; import java.awt.event.ActionEvent; +import java.awt.event.FocusAdapter; +import java.awt.event.FocusEvent; import java.awt.event.KeyEvent; import javax.swing.AbstractAction; @@ -40,180 +41,196 @@ import javax.swing.KeyStroke; import javax.swing.event.DocumentEvent; import javax.swing.event.DocumentListener; -import net.java.dev.designgridlayout.Componentizer; - import org.apache.commons.vfs2.FileObject; import org.apache.commons.vfs2.FileSystemException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import eu.engys.util.filechooser.actions.favorite.AddFavorite; -import eu.engys.util.filechooser.actions.pathnavigation.BaseNavigateAction; -import eu.engys.util.filechooser.actions.pathnavigation.BaseNavigateActionGoUp; -import eu.engys.util.filechooser.actions.pathnavigation.BaseNavigateActionRefresh; +import eu.engys.util.filechooser.actions.favorite.AddFavoriteAction; +import eu.engys.util.filechooser.actions.navigation.BaseNavigateAction; +import eu.engys.util.filechooser.actions.navigation.BaseNavigateActionGoUp; +import eu.engys.util.filechooser.actions.navigation.BaseNavigateActionRefresh; import eu.engys.util.filechooser.util.VFSUtils; import eu.engys.util.ui.ResourcesUtil; import eu.engys.util.ui.UiUtil; import eu.engys.util.ui.builder.PanelBuilder; +import net.java.dev.designgridlayout.Componentizer; public class URIPanel extends JPanel { - private static final Logger LOGGER = LoggerFactory.getLogger(URIPanel.class); + private static final String OPEN_PATH = "OPEN_PATH"; - public static final String NAME = "chooser.uripanel"; - public static final String NAME_LABEL = "Name:"; - public static final String LOOK_IN = "Look in:"; - public static final String SAVE_IN = "Save in:"; - private static final String ACTION_FOCUS_ON_TABLE = "FOCUS ON TABLE"; + private static final Logger logger = LoggerFactory.getLogger(URIPanel.class); - public static final String ADD_FAVORITE = "add.favorite"; - public static final String UP_FOLDER = "up.folder"; - public static final String REFRESH = "refresh"; + public static final String NAME = "chooser.uripanel"; + public static final String NAME_LABEL = "Name:"; + public static final String LOOK_IN = "Look in:"; + public static final String SAVE_IN = "Save in:"; + private static final String ACTION_FOCUS_ON_TABLE = "FOCUS ON TABLE"; - private JTextField pathField; + public static final String ADD_FAVORITE = "add.favorite"; + public static final String UP_FOLDER = "up.folder"; + public static final String REFRESH = "refresh"; - private FileChooserController controller; - private FileObject fileObject; - private JTextField newFileNameField; - private BreadCrumbsPanel breadCrumbs; + private JTextField pathField; - public URIPanel(FileChooserController controller) { - super(new BorderLayout()); - setName(NAME); - this.controller = controller; - layoutComponents(); - } + private FileChooserController controller; + private FileObject fileObject; + private JTextField newFileNameField; + private BreadCrumbsPanel breadCrumbs; - private void layoutComponents() { - pathField = createPathField(); - breadCrumbs = new BreadCrumbsPanel(controller); + public URIPanel(FileChooserController controller) { + super(new BorderLayout()); + setName(NAME); + this.controller = controller; + layoutComponents(); + } - PanelBuilder pb = new PanelBuilder(); + private void layoutComponents() { + pathField = createPathField(); + breadCrumbs = new BreadCrumbsPanel(controller); - String pathLabel = controller.isSaveAs() ? SAVE_IN : LOOK_IN; - pb.addComponent(pathLabel, Componentizer.create().prefAndMore(pathField).minToPref(createURIActionsBar()).component()); - pathField.setName(pathLabel); + PanelBuilder pb = new PanelBuilder(); - if (controller.isSaveAs()) { - newFileNameField = new JTextField(15); - newFileNameField.getDocument().addDocumentListener(new NotEmptyListener()); - newFileNameField.setText(""); - pb.addComponent(NAME_LABEL, newFileNameField); - } + String pathLabel = controller.isSaveAs() ? SAVE_IN : LOOK_IN; + pb.addComponent(pathLabel, Componentizer.create().prefAndMore(pathField).minToPref(createURIActionsBar()).component()); + pathField.setName(pathLabel); - JPanel panel = new JPanel(new BorderLayout()); - panel.add(pb.removeMargins().getPanel(), BorderLayout.NORTH); - panel.add(breadCrumbs, BorderLayout.CENTER); + if (controller.isSaveAs()) { + newFileNameField = new JTextField(15); + newFileNameField.getDocument().addDocumentListener(new NotEmptyListener()); + newFileNameField.setText(""); + pb.addComponent(NAME_LABEL, newFileNameField); + } - add(panel, BorderLayout.CENTER); - } + JPanel panel = new JPanel(new BorderLayout()); + panel.add(pb.removeMargins().getPanel(), BorderLayout.NORTH); + panel.add(breadCrumbs, BorderLayout.CENTER); - public String getNewFileName() { - return newFileNameField == null ? null : newFileNameField.getText(); - } + add(panel, BorderLayout.CENTER); + } - private JTextField createPathField() { - final JTextField field = new JTextField(30); - field.setToolTipText(NAV_PATHTOOLTIP); + public String getNewFileName() { + return newFileNameField == null ? null : newFileNameField.getText(); + } - InputMap inputMapPath = field.getInputMap(JComponent.WHEN_FOCUSED); - inputMapPath.put(KeyStroke.getKeyStroke("ENTER"), "OPEN_PATH"); - inputMapPath.put(KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, 0), ACTION_FOCUS_ON_TABLE); + private JTextField createPathField() { + final JTextField field = new JTextField(30); + field.setToolTipText(NAV_PATHTOOLTIP); + + field.addFocusListener(new FocusAdapter() { + @Override + public void focusLost(FocusEvent e) { + if(fileObject != null){ + /* + * This will fix the path displayed if no ENTER is pressed + */ + try { + pathField.setText(VFSUtils.decode(fileObject.getURL().toString(), controller.getSshParameters())); + } catch (FileSystemException e1) { + logger.error("Can't get URL", e); + } + } + } + }); - field.getActionMap().put("OPEN_PATH", new BaseNavigateAction(controller) { + InputMap inputMapPath = field.getInputMap(JComponent.WHEN_FOCUSED); + inputMapPath.put(KeyStroke.getKeyStroke("ENTER"), OPEN_PATH); + inputMapPath.put(KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, 0), ACTION_FOCUS_ON_TABLE); - @Override - protected void performLongOperation(CheckBeforeActionResult actionResult) { - controller.goToURL(field.getText().trim(), false); - controller.updateOkButton(); - } + field.getActionMap().put(OPEN_PATH, new BaseNavigateAction(controller) { - @Override - protected boolean canGoUrl() { - return true; - } + @Override + protected void performLongOperation(CheckBeforeActionResult actionResult) { + controller.goToURL(field.getText().trim(), false); + controller.updateOkButton(); + } - @Override - protected boolean canExecuteDefaultAction() { - return false; - } + @Override + protected boolean canGoUrl() { + return true; + } - }); + @Override + protected boolean canExecuteDefaultAction() { + return false; + } - field.getActionMap().put(ACTION_FOCUS_ON_TABLE, new AbstractAction() { - @Override - public void actionPerformed(ActionEvent e) { - controller.fixSelection(); - } - }); - return field; - } + }); - private JComponent createURIActionsBar() { - JButton goUpButton = new JButton(new BaseNavigateActionGoUp(controller)); - goUpButton.setName(UP_FOLDER); + field.getActionMap().put(ACTION_FOCUS_ON_TABLE, new AbstractAction() { + @Override + public void actionPerformed(ActionEvent e) { + controller.fixSelection(); + } + }); + return field; + } - JButton refreshButton = new JButton(new BaseNavigateActionRefresh(controller)); - refreshButton.setName(REFRESH); + private JComponent createURIActionsBar() { + JButton goUpButton = new JButton(new BaseNavigateActionGoUp(controller)); + goUpButton.setName(UP_FOLDER); - JButton addCurrentLocationToFavoriteButton = new JButton(new AddFavorite(controller)); - addCurrentLocationToFavoriteButton.setName(ADD_FAVORITE); - addCurrentLocationToFavoriteButton.setText(""); + JButton refreshButton = new JButton(new BaseNavigateActionRefresh(controller)); + refreshButton.setName(REFRESH); - JToolBar bar = UiUtil.getToolbar("uri.panel.toolbar"); + JButton addCurrentLocationToFavoriteButton = new JButton(new AddFavoriteAction(controller)); + addCurrentLocationToFavoriteButton.setName(ADD_FAVORITE); + addCurrentLocationToFavoriteButton.setText(""); - bar.add(goUpButton); - bar.add(refreshButton); - bar.add(addCurrentLocationToFavoriteButton); + JToolBar bar = UiUtil.getToolbar("uri.panel.toolbar"); + bar.add(goUpButton); + bar.add(refreshButton); + bar.add(addCurrentLocationToFavoriteButton); - return bar; - } + return bar; + } - public void setFileObject(FileObject fileObject) { - try { - this.fileObject = fileObject; - pathField.setText(VFSUtils.decode(fileObject.getURL().toString(), controller.getSshParameters())); - breadCrumbs.updatePanel(fileObject); - } catch (FileSystemException e) { - LOGGER.error("Can't get URL", e); - } - } + public void setFileObject(FileObject fileObject) { + try { + this.fileObject = fileObject; + pathField.setText(VFSUtils.decode(fileObject.getURL().toString(), controller.getSshParameters())); + breadCrumbs.updatePanel(fileObject); + } catch (FileSystemException e) { + logger.error("Can't get URL", e); + } + } - public void updateFileName() { - FileObject fo = controller.getSelectedFileObject(); - if (controller.isSaveAs() && fo != null) { - newFileNameField.setText(fo.getName().getBaseName()); - } - } + public void updateFileName() { + FileObject fo = controller.getSelectedFileObject(); + if (controller.isSaveAs() && fo != null) { + newFileNameField.setText(fo.getName().getBaseName()); + } + } - public FileObject getFileObject() { - return fileObject; - } + public FileObject getFileObject() { + return fileObject; + } - private class NotEmptyListener implements DocumentListener { - @Override - public void removeUpdate(DocumentEvent e) { - checkNotEmpty(); - } + private class NotEmptyListener implements DocumentListener { + @Override + public void removeUpdate(DocumentEvent e) { + checkNotEmpty(); + } - @Override - public void insertUpdate(DocumentEvent e) { - checkNotEmpty(); - } + @Override + public void insertUpdate(DocumentEvent e) { + checkNotEmpty(); + } - @Override - public void changedUpdate(DocumentEvent e) { - checkNotEmpty(); - } + @Override + public void changedUpdate(DocumentEvent e) { + checkNotEmpty(); + } - private void checkNotEmpty() { - controller.updateOkButton(); - } - } + private void checkNotEmpty() { + controller.updateOkButton(); + } + } - /** - * Resources - */ + /** + * Resources + */ - private static final String NAV_PATHTOOLTIP = ResourcesUtil.getString("nav.pathTooltip"); + private static final String NAV_PATHTOOLTIP = ResourcesUtil.getString("nav.pathTooltip"); } diff --git a/src/eu/engys/util/filechooser/table/FileNameWithType.java b/src/eu/engys/util/filechooser/table/FileNameWithType.java index 7ccc1f9..20bac42 100644 --- a/src/eu/engys/util/filechooser/table/FileNameWithType.java +++ b/src/eu/engys/util/filechooser/table/FileNameWithType.java @@ -1,43 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - -/* - * Copyright 2012 Krzysztof Otrebski (krzysztof.otrebski@gmail.com) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.filechooser.table; diff --git a/src/eu/engys/util/filechooser/table/FileNameWithTypeComparator.java b/src/eu/engys/util/filechooser/table/FileNameWithTypeComparator.java index ec78b8b..d816513 100644 --- a/src/eu/engys/util/filechooser/table/FileNameWithTypeComparator.java +++ b/src/eu/engys/util/filechooser/table/FileNameWithTypeComparator.java @@ -1,43 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - -/* - * Copyright 2012 Krzysztof Otrebski (krzysztof.otrebski@gmail.com) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.filechooser.table; diff --git a/src/eu/engys/util/filechooser/table/FileObjectComparator.java b/src/eu/engys/util/filechooser/table/FileObjectComparator.java index bb59ed0..0024ab9 100644 --- a/src/eu/engys/util/filechooser/table/FileObjectComparator.java +++ b/src/eu/engys/util/filechooser/table/FileObjectComparator.java @@ -1,43 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - -/* - * Copyright 2012 Krzysztof Otrebski (krzysztof.otrebski@gmail.com) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.filechooser.table; diff --git a/src/eu/engys/util/filechooser/table/FileSize.java b/src/eu/engys/util/filechooser/table/FileSize.java index cd80ac7..feb79b7 100644 --- a/src/eu/engys/util/filechooser/table/FileSize.java +++ b/src/eu/engys/util/filechooser/table/FileSize.java @@ -1,43 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - -/* - * Copyright 2012 Krzysztof Otrebski (krzysztof.otrebski@gmail.com) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.filechooser.table; diff --git a/src/eu/engys/util/filechooser/table/FileSystemTableModel.java b/src/eu/engys/util/filechooser/table/FileSystemTableModel.java index d7d9e64..f722523 100644 --- a/src/eu/engys/util/filechooser/table/FileSystemTableModel.java +++ b/src/eu/engys/util/filechooser/table/FileSystemTableModel.java @@ -1,43 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - -/* - * Copyright 2012 Krzysztof Otrebski (krzysztof.otrebski@gmail.com) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.filechooser.table; diff --git a/src/eu/engys/util/filechooser/table/QuickSearchKeyAdapter.java b/src/eu/engys/util/filechooser/table/QuickSearchKeyAdapter.java index 0a6c91e..3077871 100644 --- a/src/eu/engys/util/filechooser/table/QuickSearchKeyAdapter.java +++ b/src/eu/engys/util/filechooser/table/QuickSearchKeyAdapter.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.filechooser.table; import java.awt.Rectangle; diff --git a/src/eu/engys/util/filechooser/table/renderer/DateTableCellRenderer.java b/src/eu/engys/util/filechooser/table/renderer/DateTableCellRenderer.java index 8e764f0..ee88949 100644 --- a/src/eu/engys/util/filechooser/table/renderer/DateTableCellRenderer.java +++ b/src/eu/engys/util/filechooser/table/renderer/DateTableCellRenderer.java @@ -1,43 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - -/* - * Copyright 2012 Krzysztof Otrebski (krzysztof.otrebski@gmail.com) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.filechooser.table.renderer; diff --git a/src/eu/engys/util/filechooser/table/renderer/FileNameWithTypeTableCellRenderer.java b/src/eu/engys/util/filechooser/table/renderer/FileNameWithTypeTableCellRenderer.java index 5d1a94c..22d9daa 100644 --- a/src/eu/engys/util/filechooser/table/renderer/FileNameWithTypeTableCellRenderer.java +++ b/src/eu/engys/util/filechooser/table/renderer/FileNameWithTypeTableCellRenderer.java @@ -1,43 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - -/* - * Copyright 2012 Krzysztof Otrebski (krzysztof.otrebski@gmail.com) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.filechooser.table.renderer; @@ -47,12 +31,15 @@ import static eu.engys.util.ui.FileChooserUtils.PDF_EXTENSION; import java.awt.Component; import java.io.File; +import java.util.Collection; import javax.swing.Icon; import javax.swing.JLabel; import javax.swing.JTable; import javax.swing.table.DefaultTableCellRenderer; +import org.apache.commons.io.FileUtils; +import org.apache.commons.io.filefilter.FileFilterUtils; import org.apache.commons.vfs2.FileName; import org.apache.commons.vfs2.FileType; @@ -63,72 +50,89 @@ import eu.engys.util.ui.ResourcesUtil; public class FileNameWithTypeTableCellRenderer extends DefaultTableCellRenderer { - @Override - public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { - JLabel label = (JLabel) super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); - FileNameWithType fileNameWithType = (FileNameWithType) value; - FileName fileName = fileNameWithType.getFileName(); - label.setText(fileName.getBaseName()); - label.setToolTipText(fileName.getPath()); + @Override + public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { + JLabel label = (JLabel) super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); - FileType fileType = fileNameWithType.getFileType(); - Icon icon = null; - if (FileType.FOLDER.equals(fileType)) { - String decodePath = VFSUtils.decode(fileName.getURI(), null); - File file = decodePath == null ? null : new File(decodePath); - if (isSuitable(file)) { - label.setText(label.getText()); - if (ApplicationInfo.getVendor() != null) { - icon = ResourcesUtil.getIcon(ApplicationInfo.getVendor().toLowerCase() + ".case"); - } - } else { - icon = FOLDEROPEN; - } - } else if (VFSUtils.isArchive(fileName)) { - if ("jar".equalsIgnoreCase(fileName.getExtension())) { - icon = JARICON; - } else { - icon = FOLDERZIPPER; - } - } else if (FileType.FILE.equals(fileType)) { - if (PDF_EXTENSION.equalsIgnoreCase(fileName.getExtension())) { - icon = PDF_ICON; - } else if (EXCEL_EXTENSION_OLD.equalsIgnoreCase(fileName.getExtension()) || EXCEL_EXTENSION_NEW.equalsIgnoreCase(fileName.getExtension())) { - icon = EXCEL_ICON; - } else { - icon = FILE; - } - } else if (FileType.IMAGINARY.equals(fileType)) { - icon = SHORTCUT; - } - label.setIcon(icon); - return label; - } + if (value != null) { + FileNameWithType fileNameWithType = (FileNameWithType) value; + FileName fileName = fileNameWithType.getFileName(); + label.setText(fileName.getBaseName()); + label.setToolTipText(fileName.getPath()); - private boolean isSuitable(File file) { - if (file != null && file.exists() && file.isDirectory()) { - File constant = new File(file, "constant"); - File system = new File(file, "system"); - if (constant.exists() && constant.isDirectory() && system.exists() && system.isDirectory()) { - File controlDict = new File(system, "controlDict"); - return controlDict.exists(); - } - return false; - } - return false; - } + FileType fileType = fileNameWithType.getFileType(); + Icon icon = null; + if (FileType.FOLDER.equals(fileType)) { + String decodePath = VFSUtils.decode(fileName.getURI(), null); + File file = decodePath == null ? null : new File(decodePath); + if (isSuitableCase(file)) { + label.setText(label.getText()); + if (ApplicationInfo.getVendor() != null) { + icon = ResourcesUtil.getIcon(ApplicationInfo.getVendor().toLowerCase() + ".case"); + } + } else if (isSuitableStudy(file)) { + label.setText(label.getText()); + if (ApplicationInfo.getVendor() != null) { + icon = ResourcesUtil.getIcon(ApplicationInfo.getVendor().toLowerCase() + ".study"); + } + } else { + icon = FOLDEROPEN; + } + } else if (VFSUtils.isArchive(fileName)) { + if ("jar".equalsIgnoreCase(fileName.getExtension())) { + icon = JARICON; + } else { + icon = FOLDERZIPPER; + } + } else if (FileType.FILE.equals(fileType)) { + if (PDF_EXTENSION.equalsIgnoreCase(fileName.getExtension())) { + icon = PDF_ICON; + } else if (EXCEL_EXTENSION_OLD.equalsIgnoreCase(fileName.getExtension()) || EXCEL_EXTENSION_NEW.equalsIgnoreCase(fileName.getExtension())) { + icon = EXCEL_ICON; + } else { + icon = FILE; + } + } else if (FileType.IMAGINARY.equals(fileType)) { + icon = SHORTCUT; + } + label.setIcon(icon); + } - /** - * Resources - */ + return label; + } - private static final Icon FILE = ResourcesUtil.getIcon("file"); - private static final Icon JARICON = ResourcesUtil.getIcon("jarIcon"); - private static final Icon SHORTCUT = ResourcesUtil.getIcon("shortCut"); - private static final Icon FOLDEROPEN = ResourcesUtil.getIcon("folderOpen"); - private static final Icon FOLDERZIPPER = ResourcesUtil.getIcon("folderZipper"); + private boolean isSuitableCase(File file) { + if (file != null && file.exists() && file.isDirectory()) { + File constant = new File(file, "constant"); + File system = new File(file, "system"); + if (constant.exists() && constant.isDirectory() && system.exists() && system.isDirectory()) { + File controlDict = new File(system, "controlDict"); + return controlDict.exists(); + } + return false; + } + return false; + } - private static final Icon PDF_ICON = ResourcesUtil.getIcon("file.pdf"); - private static final Icon EXCEL_ICON = ResourcesUtil.getIcon("file.excel"); + private boolean isSuitableStudy(File file) { + if (file != null && file.exists() && file.isDirectory()) { + Collection listFiles = FileUtils.listFiles(file, FileFilterUtils.suffixFileFilter(".std"), null); + return listFiles.size() == 1; + } + return false; + } + + /** + * Resources + */ + + private static final Icon FILE = ResourcesUtil.getIcon("file.icon"); + private static final Icon JARICON = ResourcesUtil.getIcon("jar.icon"); + private static final Icon SHORTCUT = ResourcesUtil.getIcon("shortcut.icon"); + private static final Icon FOLDEROPEN = ResourcesUtil.getIcon("folder.icon"); + private static final Icon FOLDERZIPPER = ResourcesUtil.getIcon("archive.icon"); + + private static final Icon PDF_ICON = ResourcesUtil.getIcon("file.pdf"); + private static final Icon EXCEL_ICON = ResourcesUtil.getIcon("file.excel"); } diff --git a/src/eu/engys/util/filechooser/table/renderer/FileSizeTableCellRenderer.java b/src/eu/engys/util/filechooser/table/renderer/FileSizeTableCellRenderer.java index a5e0ecf..df1a428 100644 --- a/src/eu/engys/util/filechooser/table/renderer/FileSizeTableCellRenderer.java +++ b/src/eu/engys/util/filechooser/table/renderer/FileSizeTableCellRenderer.java @@ -1,43 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - -/* - * Copyright 2012 Krzysztof Otrebski (krzysztof.otrebski@gmail.com) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.filechooser.table.renderer; diff --git a/src/eu/engys/util/filechooser/table/renderer/FileTypeTableCellRenderer.java b/src/eu/engys/util/filechooser/table/renderer/FileTypeTableCellRenderer.java index 74b243d..34a2248 100644 --- a/src/eu/engys/util/filechooser/table/renderer/FileTypeTableCellRenderer.java +++ b/src/eu/engys/util/filechooser/table/renderer/FileTypeTableCellRenderer.java @@ -1,43 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - -/* - * Copyright 2012 Krzysztof Otrebski (krzysztof.otrebski@gmail.com) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.filechooser.table.renderer; diff --git a/src/eu/engys/util/filechooser/table/renderer/MixedDateTableCellRenderer.java b/src/eu/engys/util/filechooser/table/renderer/MixedDateTableCellRenderer.java index 5359902..c5df51f 100644 --- a/src/eu/engys/util/filechooser/table/renderer/MixedDateTableCellRenderer.java +++ b/src/eu/engys/util/filechooser/table/renderer/MixedDateTableCellRenderer.java @@ -1,43 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - -/* - * Copyright 2012 Krzysztof Otrebski (krzysztof.otrebski@gmail.com) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.filechooser.table.renderer; diff --git a/src/eu/engys/util/filechooser/table/renderer/RelativeDateTableCellRenderer.java b/src/eu/engys/util/filechooser/table/renderer/RelativeDateTableCellRenderer.java index 1e6e916..ea0687d 100644 --- a/src/eu/engys/util/filechooser/table/renderer/RelativeDateTableCellRenderer.java +++ b/src/eu/engys/util/filechooser/table/renderer/RelativeDateTableCellRenderer.java @@ -1,43 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - -/* - * Copyright 2012 Krzysztof Otrebski (krzysztof.otrebski@gmail.com) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.filechooser.table.renderer; diff --git a/src/eu/engys/util/filechooser/uri/Protocol.java b/src/eu/engys/util/filechooser/uri/Protocol.java index 3d4f31e..88979f9 100644 --- a/src/eu/engys/util/filechooser/uri/Protocol.java +++ b/src/eu/engys/util/filechooser/uri/Protocol.java @@ -1,43 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - -/* - * Copyright 2012 Krzysztof Otrebski (krzysztof.otrebski@gmail.com) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.filechooser.uri; /** diff --git a/src/eu/engys/util/filechooser/uri/VFSURIParser.java b/src/eu/engys/util/filechooser/uri/VFSURIParser.java index 847d83a..f54a753 100644 --- a/src/eu/engys/util/filechooser/uri/VFSURIParser.java +++ b/src/eu/engys/util/filechooser/uri/VFSURIParser.java @@ -1,43 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - -/* - * Copyright 2012 Krzysztof Otrebski (krzysztof.otrebski@gmail.com) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.filechooser.uri; diff --git a/src/eu/engys/util/filechooser/uri/VFSURIValidator.java b/src/eu/engys/util/filechooser/uri/VFSURIValidator.java index 25d32c9..171d361 100644 --- a/src/eu/engys/util/filechooser/uri/VFSURIValidator.java +++ b/src/eu/engys/util/filechooser/uri/VFSURIValidator.java @@ -1,43 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - -/* - * Copyright 2012 Krzysztof Otrebski (krzysztof.otrebski@gmail.com) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.filechooser.uri; import java.util.regex.Matcher; diff --git a/src/eu/engys/util/filechooser/util/CompositeTaskContext.java b/src/eu/engys/util/filechooser/util/CompositeTaskContext.java index 0307794..51dbbb2 100644 --- a/src/eu/engys/util/filechooser/util/CompositeTaskContext.java +++ b/src/eu/engys/util/filechooser/util/CompositeTaskContext.java @@ -1,43 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - -/* - * Copyright 2012 Krzysztof Otrebski (krzysztof.otrebski@gmail.com) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.filechooser.util; diff --git a/src/eu/engys/util/filechooser/util/EngysFileSystemManager.java b/src/eu/engys/util/filechooser/util/EngysFileSystemManager.java index c5b4c0f..dc90653 100644 --- a/src/eu/engys/util/filechooser/util/EngysFileSystemManager.java +++ b/src/eu/engys/util/filechooser/util/EngysFileSystemManager.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.filechooser.util; import org.apache.commons.lang.StringUtils; diff --git a/src/eu/engys/util/filechooser/util/FileNameWrapper.java b/src/eu/engys/util/filechooser/util/FileNameWrapper.java index f0e1cef..ed9dfbe 100644 --- a/src/eu/engys/util/filechooser/util/FileNameWrapper.java +++ b/src/eu/engys/util/filechooser/util/FileNameWrapper.java @@ -1,43 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - -/* - * Copyright 2012 Krzysztof Otrebski (krzysztof.otrebski@gmail.com) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.filechooser.util; diff --git a/src/eu/engys/util/filechooser/util/FileObjectWrapper.java b/src/eu/engys/util/filechooser/util/FileObjectWrapper.java index a773e91..e814009 100644 --- a/src/eu/engys/util/filechooser/util/FileObjectWrapper.java +++ b/src/eu/engys/util/filechooser/util/FileObjectWrapper.java @@ -1,43 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - -/* - * Copyright 2012 Krzysztof Otrebski (krzysztof.otrebski@gmail.com) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.filechooser.util; diff --git a/src/eu/engys/util/filechooser/util/HelyxFileFilter.java b/src/eu/engys/util/filechooser/util/HelyxFileFilter.java index 19d4d4f..353accc 100644 --- a/src/eu/engys/util/filechooser/util/HelyxFileFilter.java +++ b/src/eu/engys/util/filechooser/util/HelyxFileFilter.java @@ -1,31 +1,31 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.filechooser.util; import java.io.File; +import java.util.Arrays; import org.apache.commons.io.FilenameUtils; @@ -50,7 +50,7 @@ public class HelyxFileFilter { } public boolean isAllFilesFilter() { - return ALL_FILES_FILTER_DESCRIPTION.equals(description) && ALL_FILES_FILTER_EXTENSIONS.equals(extensions); + return ALL_FILES_FILTER_DESCRIPTION.equals(description) && Arrays.equals(ALL_FILES_FILTER_EXTENSIONS, extensions); } public String getDescription() { diff --git a/src/eu/engys/util/filechooser/util/InvalidFileName.java b/src/eu/engys/util/filechooser/util/InvalidFileName.java index e8495fa..dccae99 100644 --- a/src/eu/engys/util/filechooser/util/InvalidFileName.java +++ b/src/eu/engys/util/filechooser/util/InvalidFileName.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.filechooser.util; import org.apache.commons.vfs2.FileName; diff --git a/src/eu/engys/util/filechooser/util/SelectionMode.java b/src/eu/engys/util/filechooser/util/SelectionMode.java index 45f459a..6385c36 100644 --- a/src/eu/engys/util/filechooser/util/SelectionMode.java +++ b/src/eu/engys/util/filechooser/util/SelectionMode.java @@ -1,43 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - -/* - * Copyright 2012 Krzysztof Otrebski (krzysztof.otrebski@gmail.com) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.filechooser.util; diff --git a/src/eu/engys/util/filechooser/util/TaskContext.java b/src/eu/engys/util/filechooser/util/TaskContext.java index 39e3d57..2ff6bbd 100644 --- a/src/eu/engys/util/filechooser/util/TaskContext.java +++ b/src/eu/engys/util/filechooser/util/TaskContext.java @@ -1,43 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - -/* - * Copyright 2012 Krzysztof Otrebski (krzysztof.otrebski@gmail.com) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.filechooser.util; diff --git a/src/eu/engys/util/filechooser/util/VFSUtils.java b/src/eu/engys/util/filechooser/util/VFSUtils.java index b022dba..47d3c4a 100644 --- a/src/eu/engys/util/filechooser/util/VFSUtils.java +++ b/src/eu/engys/util/filechooser/util/VFSUtils.java @@ -1,43 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - -/* - * Copyright 2012 Krzysztof Otrebski (krzysztof.otrebski@gmail.com) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.filechooser.util; import static eu.engys.util.ui.FileChooserUtils.DEFAULT_SSH_PORT; @@ -99,449 +83,444 @@ import eu.engys.util.ui.ResourcesUtil; */ public final class VFSUtils { - private static final Logger logger = LoggerFactory.getLogger(VFSUtils.class); - - public enum LocationType { - file, sftp; - - public String toString() { - if (Util.isWindows() && equals(file)) { - return super.toString() + WIN_PROTOCOL_PREFIX; - } - return super.toString() + UNIX_PROTOCOL_PREFIX; - }; - - public static String[] toStringArray() { - return new String[] { file.toString(), sftp.toString() }; - }; - } - - private static final int SYMBOLIC_LINK_MAX_SIZE = 128; - - private static FileSystemManager fileSystemManager; - private static FileSystemOptions fileSystemOptions = new FileSystemOptions(); - public static final String UNIX_PROTOCOL_PREFIX = "://"; - public static final String WIN_PROTOCOL_PREFIX = ":///"; - private static final File HOME_DIRECTORY = new File(System.getProperty("user.home")); - - public static final File CONFIG_DIRECTORY = new File(HOME_DIRECTORY, ".otrosvfsbrowser"); - public static final File USER_AUTH_FILE = new File(CONFIG_DIRECTORY, "auth.xml"); - public static final File USER_AUTH_FILE_BAK = new File(CONFIG_DIRECTORY, "auth.xml.bak"); - private static ReadWriteLock aLock = new ReentrantReadWriteLock(true); - - // File size localized strings - - private static final Map schemeIconMap = new HashMap(); - private static final Set archivesSuffixes = new HashSet(); - - static { - schemeIconMap.put("file", ResourcesUtil.getIcon("drive")); - schemeIconMap.put("sftp", ResourcesUtil.getIcon("networkCloud")); - schemeIconMap.put("ftp", ResourcesUtil.getIcon("networkCloud")); - schemeIconMap.put("smb", ResourcesUtil.getIcon("sambaShare")); - schemeIconMap.put("http", ResourcesUtil.getIcon("networkCloud")); - schemeIconMap.put("https", ResourcesUtil.getIcon("networkCloud")); - schemeIconMap.put("zip", ResourcesUtil.getIcon("folderZipper")); - schemeIconMap.put("tar", ResourcesUtil.getIcon("folderZipper")); - schemeIconMap.put("jar", ResourcesUtil.getIcon("jarIcon")); - schemeIconMap.put("tgz", ResourcesUtil.getIcon("folderZipper")); - schemeIconMap.put("tbz", ResourcesUtil.getIcon("folderZipper")); - - archivesSuffixes.add("zip"); - archivesSuffixes.add("tar"); - archivesSuffixes.add("jar"); - archivesSuffixes.add("tgz"); - archivesSuffixes.add("gz"); - archivesSuffixes.add("bz2"); - archivesSuffixes.add("tar"); - archivesSuffixes.add("tbz"); - archivesSuffixes.add("tgz"); - - } - - public static FileSystemManager getFileSystemManager() { - aLock.readLock().lock(); - - try { - if (fileSystemManager == null) { - try { - EngysFileSystemManager fm = new EngysFileSystemManager(); - // fm.setClassLoader(StandardFileSystemManager.class.getClassLoader()); - fm.setConfiguration(StandardFileSystemManager.class.getResource("providers.xml")); - fm.setCacheStrategy(CacheStrategy.MANUAL); - fm.init(); - logger.trace("Supported schemes: {} ", Joiner.on(", ").join(fm.getSchemes())); - fileSystemManager = fm; - } catch (Exception exc) { - throw new RuntimeException(exc); - } - } - - return fileSystemManager; - } finally { - aLock.readLock().unlock(); - } - } - - public static String getFriendlyName(String fileName) { - return getFriendlyName(fileName, true); - } - - public static String getFriendlyName(String fileName, boolean excludeLocalFilePrefix) { - if (fileName == null) { - return ""; - } - StringBuilder filePath = new StringBuilder(); - - int pos = fileName.lastIndexOf('@'); - - if (pos == -1) { - filePath.append(fileName); - } else { - int pos2 = fileName.indexOf(UNIX_PROTOCOL_PREFIX); - - if (pos2 == -1) { - filePath.append(fileName); - } else { - String protocol = fileName.substring(0, pos2); - - filePath.append(protocol).append(UNIX_PROTOCOL_PREFIX).append(fileName.substring(pos + 1, fileName.length())); - } - } - - String returnedString = filePath.toString(); - - if (excludeLocalFilePrefix && returnedString.startsWith(LocationType.file.toString())) { - return filePath.substring(LocationType.file.toString().length()); - } - - return returnedString; - } - - public static FileObject createFileSystemRoot(FileObject fileObject) { - try { - return fileObject.getFileSystem().getRoot(); - } catch (FileSystemException ex) { - return null; - } - } - - public static FileObject[] getFiles(Component parent, FileObject folder) { - try { - return getChildren(folder); - } catch (FileSystemException ex) { - String url = folder == null ? "non existing file" : folder.getName().getPath(); - VFSUtils.showErrorMessage(parent, url, ex); - return new FileObject[0]; - } - } - - public static FileObject getRootFileSystem(FileObject fileObject) { - try { - if ((fileObject == null) || !fileObject.exists()) { - return null; - } - - return fileObject.getFileSystem().getRoot(); - } catch (FileSystemException ex) { - return null; - } - } - - public static boolean isHiddenFile(FileObject fileObject) { - try { - return fileObject.getName().getBaseName().charAt(0) == '.'; - } catch (Exception ex) { - return false; - } - } - - public static boolean isRoot(FileObject fileObject) { - try { - return fileObject.getParent() == null; - } catch (FileSystemException ex) { - return false; - } - } - - public static FileObject resolveFileObject(String filePath) throws FileSystemException { - return resolveFileObject(filePath, null); - } - - public static FileObject resolveFileObject(String filePath, SshParameters sshParameters) throws FileSystemException { - logger.trace("Resolving file: {}", filePath); - if (filePath.startsWith(LocationType.sftp.toString())) { - SftpFileSystemConfigBuilder builder = SftpFileSystemConfigBuilder.getInstance(); - builder.setStrictHostKeyChecking(fileSystemOptions, "no"); - builder.setUserDirIsRoot(fileSystemOptions, false); - builder.setCompression(fileSystemOptions, "zlib,none"); - } - - AuthStore sessionAuthStore = new MemoryAuthStore(); - if (sshParameters != null) { - String host = sshParameters.getHost(); - String user = sshParameters.getUser(); - String pwd = sshParameters.getSshpwd(); - String key = sshParameters.getSshkey(); - int port = sshParameters.getPort(); - if (host != null && user != null && pwd != null && key != null) { - setAuthenticationFromSSHParameters(sessionAuthStore, host, user, pwd, key); - } - } - return resolveFileObject(sessionAuthStore, filePath); - } - - private static void setAuthenticationFromSSHParameters(AuthStore sessionAuthStore, String host, String user, String pwd, String key) { - UserAuthenticationInfo auInfo = new UserAuthenticationInfo(Protocol.SFTP.getName(), host, user); - UserAuthenticationDataWrapper authenticationData = new UserAuthenticationDataWrapper(); - authenticationData.setData(UserAuthenticationData.USERNAME, user.toCharArray()); - authenticationData.setData(UserAuthenticationData.PASSWORD, pwd.toCharArray()); - authenticationData.setData(UserAuthenticationDataWrapper.SSH_KEY, key.toCharArray()); - sessionAuthStore.add(auInfo, authenticationData); - } - - private static FileObject resolveFileObject(AuthStore sessionAuthStore, String filePath) throws FileSystemException { - UserAuthenticatorFactory factory = new UserAuthenticatorFactory(); - OtrosUserAuthenticator authenticator = factory.getUiUserAuthenticator(sessionAuthStore, filePath, fileSystemOptions); - if (filePath.startsWith(LocationType.sftp.toString())) { - SftpFileSystemConfigBuilder builder = SftpFileSystemConfigBuilder.getInstance(); - builder.setStrictHostKeyChecking(fileSystemOptions, "no"); - builder.setUserDirIsRoot(fileSystemOptions, false); - builder.setCompression(fileSystemOptions, "zlib,none"); - - } - - DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator(fileSystemOptions, authenticator); - FileObject resolveFile; - try { - resolveFile = getFileSystemManager().resolveFile(filePath, fileSystemOptions);// SLOW ACTION (circa 120ms) - resolveFile.getType(); - } catch (FileSystemException e) { - logger.error("Error resolving file " + filePath, e.getMessage()); - e.printStackTrace(); - throw e; - } - return resolveFile; - } - - public static boolean exists(FileObject fileObject) { - if (fileObject == null) { - return false; - } - - try { - return fileObject.exists(); - } catch (FileSystemException ex) { - return false; - } - } - - public static boolean isDirectory(FileObject fileObject) { - try { - return fileObject.getType().equals(FileType.FOLDER); - } catch (FileSystemException ex) { - logger.info("Exception when checking if fileobject is folder", ex); - return false; - } - } - - public static boolean isLocalFile(FileObject fileObject) { - try { - return fileObject.getURL().getProtocol().equalsIgnoreCase("file") && FileType.FILE.equals(fileObject.getType()); - } catch (FileSystemException e) { - logger.info("Exception when checking if fileobject is local file", e); - return false; - } - } - - public static boolean isFileSystemRoot(FileObject folder) { - return isRoot(folder); - } - - public static boolean isParent(FileObject folder, FileObject file) { - try { - FileObject parent = file.getParent(); - - return parent != null && parent.equals(folder); - - } catch (FileSystemException ex) { - return false; - } - } - - public static String getRemoteUserHome(SshParameters sshParameters) throws FileSystemException { - return "/home/" + sshParameters.getUser(); - } - - public static FileObject getUserHome() throws FileSystemException { - return resolveFileObject(Util.isUnix() ? PrefUtil.USER_DIR : PrefUtil.USER_HOME); - } - - public static void checkForSftpLinks(FileObject[] files, TaskContext taskContext) { - logger.trace("Checking for SFTP links"); - taskContext.setMax(files.length); - long ts = System.currentTimeMillis(); - for (int i = 0; i < files.length && !taskContext.isStop(); i++) { - FileObject fileObject = files[i]; - try { - if (fileObject instanceof SftpFileObject) { - SftpFileObject sftpFileObject = (SftpFileObject) fileObject; - long size = sftpFileObject.getContent().getSize(); - if (sftpFileObject.getType() == FileType.FILE && size < SYMBOLIC_LINK_MAX_SIZE && size != 0) { - if (!pointToItself(sftpFileObject)) { - files[i] = new LinkFileObject(sftpFileObject); - } - } - - } - taskContext.setCurrentProgress(i); - } catch (Exception e) { - - } - - } - long checkDuration = System.currentTimeMillis() - ts; - logger.trace("Checking SFTP links took {} ms [{}ms/file]", checkDuration, (float) checkDuration / files.length); - } - - public static boolean pointToItself(FileObject fileObject) throws FileSystemException { - if (!fileObject.getURL().getProtocol().equalsIgnoreCase("file") && FileType.FILE.equals(fileObject.getType())) { - logger.trace("Checking if {} is pointing to itself", fileObject.getName().getFriendlyURI()); - FileObject[] children = VFSUtils.getChildren(fileObject); - logger.trace("Children number of {} is {}", fileObject.getName().getFriendlyURI(), children.length); - if (children.length == 1) { - FileObject child = children[0]; - if (child.getContent().getSize() != child.getContent().getSize()) { - return false; - } - if (child.getName().getBaseName().equals(fileObject.getName().getBaseName())) { - return true; - } - } - } - return false; - } - - public static FileObject[] getChildren(FileObject fileObject) throws FileSystemException { - FileObject[] result; - if (isLocalFileSystem(fileObject) && isArchive(fileObject)) { - String extension = fileObject.getName().getExtension(); - result = VFSUtils.resolveFileObject(extension + ":" + fileObject.getURL().toString() + "!/").getChildren(); - } else { - result = fileObject.getChildren(); - } - return filterInvalidFiles(result); - } - - private static FileObject[] filterInvalidFiles(FileObject[] result) { - List validFileObjects = new ArrayList<>(); - for (FileObject fo : result) { - if (fo.getName() instanceof InvalidFileName) { - logger.warn("Invalid filename filtered: {}", ((InvalidFileName) fo.getName()).getOriginalName()); - } else { - if (isLocalFileSystem(fo) && isInvalidFolder(fo)) { - logger.warn("Invalid folder filtered: {}", fo.getName()); - } else { - validFileObjects.add(fo); - } - } - } - return validFileObjects.toArray(new FileObject[0]); - } - - private static boolean isInvalidFolder(FileObject folder) { - try { - if (folder.getType() != FileType.FOLDER) { - return false; - } - - File file = new File(decode(folder.getName().getURI(), null)); - String[] files = UriParser.encode(file.list()); - - return files == null; - } catch (Exception e) { - return true; - } - } - - public static boolean isArchive(FileObject fileObject) { - return isArchive(fileObject.getName()); - } - - public static boolean isArchive(FileName fileName) { - String extension = fileName.getExtension(); - return archivesSuffixes.contains(extension.toLowerCase()); - } - - private static boolean isLocalFileSystem(FileObject fileObject) { - return fileObject.getName().getScheme().equalsIgnoreCase("file"); - } - - public static Icon getIconForFileSystem(String url) { - String schema = "file"; - if (null != url) { - int indexOf = url.indexOf(UNIX_PROTOCOL_PREFIX); - if (indexOf > 0) { - schema = url.substring(0, indexOf); - } - } - return schemeIconMap.get(schema); - } - - public static boolean canGoUrl(FileObject fileObject) throws FileSystemException { - if (VFSUtils.pointToItself(fileObject)) { - return false; - } - if (VFSUtils.isLocalFile(fileObject)) { - return false; - } - return true; - - } - - public static String encode(String url, SshParameters sshParameters) { - String fixedUrl = url.replace("\\", "/"); - if (sshParameters != null) { - String host = sshParameters.getHost(); - String port = String.valueOf(sshParameters.getPort()); - String typePrefix = LocationType.sftp.toString(); - if (port.equals(DEFAULT_SSH_PORT)) { - return typePrefix + host + fixedUrl; - } else { - return typePrefix + host + ":" + port + fixedUrl; - } - } else { - String typePrefix = LocationType.file.toString(); - return typePrefix + fixedUrl; - } - } - - public static String decode(String path, SshParameters sshParameters) { - if (path.startsWith(LocationType.file.toString())) { - return StringUtils.removeStart(path, LocationType.file.toString()); - } else if (path.startsWith(LocationType.sftp.toString()) && sshParameters != null) { - String noType = StringUtils.removeStart(path, LocationType.sftp.toString()); - String noHost = StringUtils.removeStart(noType, sshParameters.getHost()); - String noPort = StringUtils.removeStart(noHost, ":" + sshParameters.getPort()); - return noPort; - } - return null; - } - - public static void showErrorMessage(final Component parent, final String url, final Exception e) { - ExecUtil.invokeLater(new Runnable() { - @Override - public void run() { - String message = "Error opening " + url; - if (e != null) { - message += "\n" + e.getMessage(); - if (message.contains("descendent")) { - message = message.replace("descendent", ""); - } - } - logger.error(message); - JOptionPane.showMessageDialog(parent, message, "File System Error", JOptionPane.ERROR_MESSAGE); - } - }); - } + private static final Logger logger = LoggerFactory.getLogger(VFSUtils.class); + + public enum LocationType { + file, sftp; + + public String toString() { + if (Util.isWindows() && equals(file)) { + return super.toString() + WIN_PROTOCOL_PREFIX; + } + return super.toString() + UNIX_PROTOCOL_PREFIX; + }; + + public static String[] toStringArray() { + return new String[] { file.toString(), sftp.toString() }; + }; + } + + private static final int SYMBOLIC_LINK_MAX_SIZE = 128; + + private static FileSystemManager fileSystemManager; + private static FileSystemOptions fileSystemOptions = new FileSystemOptions(); + public static final String UNIX_PROTOCOL_PREFIX = "://"; + public static final String WIN_PROTOCOL_PREFIX = ":///"; + + private static ReadWriteLock aLock = new ReentrantReadWriteLock(true); + + // File size localized strings + + private static final Map schemeIconMap = new HashMap(); + private static final Set archivesSuffixes = new HashSet(); + + static { + schemeIconMap.put("file", ResourcesUtil.getIcon("drive.icon")); + schemeIconMap.put("jar", ResourcesUtil.getIcon("jar.icon")); + schemeIconMap.put("smb", ResourcesUtil.getIcon("samba.icon")); + schemeIconMap.put("sftp", ResourcesUtil.getIcon("network.icon")); + schemeIconMap.put("ftp", ResourcesUtil.getIcon("network.icon")); + schemeIconMap.put("http", ResourcesUtil.getIcon("network.icon")); + schemeIconMap.put("https", ResourcesUtil.getIcon("network.icon")); + schemeIconMap.put("zip", ResourcesUtil.getIcon("archive.icon")); + schemeIconMap.put("tar", ResourcesUtil.getIcon("archive.icon")); + schemeIconMap.put("tgz", ResourcesUtil.getIcon("archive.icon")); + schemeIconMap.put("tbz", ResourcesUtil.getIcon("archive.icon")); + + archivesSuffixes.add("zip"); + archivesSuffixes.add("tar"); + archivesSuffixes.add("jar"); + archivesSuffixes.add("tgz"); + archivesSuffixes.add("gz"); + archivesSuffixes.add("bz2"); + archivesSuffixes.add("tar"); + archivesSuffixes.add("tbz"); + archivesSuffixes.add("tgz"); + + } + + public static FileSystemManager getFileSystemManager() { + aLock.readLock().lock(); + + try { + if (fileSystemManager == null) { + try { + EngysFileSystemManager fm = new EngysFileSystemManager(); + // fm.setClassLoader(StandardFileSystemManager.class.getClassLoader()); + fm.setConfiguration(StandardFileSystemManager.class.getResource("providers.xml")); + fm.setCacheStrategy(CacheStrategy.MANUAL); + fm.init(); + logger.trace("Supported schemes: {} ", Joiner.on(", ").join(fm.getSchemes())); + fileSystemManager = fm; + } catch (Exception exc) { + throw new RuntimeException(exc); + } + } + + return fileSystemManager; + } finally { + aLock.readLock().unlock(); + } + } + + public static String getFriendlyName(String fileName) { + return getFriendlyName(fileName, true); + } + + public static String getFriendlyName(String fileName, boolean excludeLocalFilePrefix) { + if (fileName == null) { + return ""; + } + StringBuilder filePath = new StringBuilder(); + + int pos = fileName.lastIndexOf('@'); + + if (pos == -1) { + filePath.append(fileName); + } else { + int pos2 = fileName.indexOf(UNIX_PROTOCOL_PREFIX); + + if (pos2 == -1) { + filePath.append(fileName); + } else { + String protocol = fileName.substring(0, pos2); + + filePath.append(protocol).append(UNIX_PROTOCOL_PREFIX).append(fileName.substring(pos + 1, fileName.length())); + } + } + + String returnedString = filePath.toString(); + + if (excludeLocalFilePrefix && returnedString.startsWith(LocationType.file.toString())) { + return filePath.substring(LocationType.file.toString().length()); + } + + return returnedString; + } + + public static FileObject createFileSystemRoot(FileObject fileObject) { + try { + return fileObject.getFileSystem().getRoot(); + } catch (FileSystemException ex) { + return null; + } + } + + public static FileObject[] getFiles(Component parent, FileObject folder) { + try { + return getChildren(folder); + } catch (FileSystemException ex) { + String url = folder == null ? "non existing file" : folder.getName().getPath(); + VFSUtils.showErrorMessage(parent, url, ex); + return new FileObject[0]; + } + } + + public static FileObject getRootFileSystem(FileObject fileObject) { + try { + if ((fileObject == null) || !fileObject.exists()) { + return null; + } + + return fileObject.getFileSystem().getRoot(); + } catch (FileSystemException ex) { + return null; + } + } + + public static boolean isHiddenFile(FileObject fileObject) { + try { + return fileObject.getName().getBaseName().charAt(0) == '.'; + } catch (Exception ex) { + return false; + } + } + + public static boolean isRoot(FileObject fileObject) { + try { + return fileObject.getParent() == null; + } catch (FileSystemException ex) { + return false; + } + } + + public static FileObject resolveFileObject(String filePath) throws FileSystemException { + return resolveFileObject(filePath, null); + } + + public static FileObject resolveFileObject(String filePath, SshParameters sshParameters) throws FileSystemException { + logger.trace("Resolving file: {}", filePath); + if (filePath.startsWith(LocationType.sftp.toString())) { + SftpFileSystemConfigBuilder builder = SftpFileSystemConfigBuilder.getInstance(); + builder.setStrictHostKeyChecking(fileSystemOptions, "no"); + builder.setUserDirIsRoot(fileSystemOptions, false); + builder.setCompression(fileSystemOptions, "zlib,none"); + } + + AuthStore sessionAuthStore = new MemoryAuthStore(); + if (sshParameters != null) { + String host = sshParameters.getHost(); + String user = sshParameters.getUser(); + String pwd = sshParameters.getSshpwd(); + String key = sshParameters.getSshkey(); + if (host != null && user != null && pwd != null && key != null) { + setAuthenticationFromSSHParameters(sessionAuthStore, host, user, pwd, key); + } + } + return resolveFileObject(sessionAuthStore, filePath); + } + + private static void setAuthenticationFromSSHParameters(AuthStore sessionAuthStore, String host, String user, String pwd, String key) { + UserAuthenticationInfo auInfo = new UserAuthenticationInfo(Protocol.SFTP.getName(), host, user); + UserAuthenticationDataWrapper authenticationData = new UserAuthenticationDataWrapper(); + authenticationData.setData(UserAuthenticationData.USERNAME, user.toCharArray()); + authenticationData.setData(UserAuthenticationData.PASSWORD, pwd.toCharArray()); + authenticationData.setData(UserAuthenticationDataWrapper.SSH_KEY, key.toCharArray()); + sessionAuthStore.add(auInfo, authenticationData); + } + + private static FileObject resolveFileObject(AuthStore sessionAuthStore, String filePath) throws FileSystemException { + UserAuthenticatorFactory factory = new UserAuthenticatorFactory(); + OtrosUserAuthenticator authenticator = factory.getUiUserAuthenticator(sessionAuthStore, filePath, fileSystemOptions); + if (filePath.startsWith(LocationType.sftp.toString())) { + SftpFileSystemConfigBuilder builder = SftpFileSystemConfigBuilder.getInstance(); + builder.setStrictHostKeyChecking(fileSystemOptions, "no"); + builder.setUserDirIsRoot(fileSystemOptions, false); + builder.setCompression(fileSystemOptions, "zlib,none"); + + } + + DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator(fileSystemOptions, authenticator); + FileObject resolveFile; + try { + resolveFile = getFileSystemManager().resolveFile(filePath, fileSystemOptions);// SLOW ACTION (circa 120ms) + resolveFile.getType(); + } catch (FileSystemException e) { + logger.error("Error resolving file " + filePath, e.getMessage()); + e.printStackTrace(); + throw e; + } + return resolveFile; + } + + public static boolean exists(FileObject fileObject) { + if (fileObject == null) { + return false; + } + + try { + return fileObject.exists(); + } catch (FileSystemException ex) { + return false; + } + } + + public static boolean isDirectory(FileObject fileObject) { + try { + return fileObject.getType().equals(FileType.FOLDER); + } catch (FileSystemException ex) { + logger.info("Exception when checking if fileobject is folder", ex); + return false; + } + } + + public static boolean isLocalFile(FileObject fileObject) { + try { + return fileObject.getURL().getProtocol().equalsIgnoreCase("file") && FileType.FILE.equals(fileObject.getType()); + } catch (FileSystemException e) { + logger.info("Exception when checking if fileobject is local file", e); + return false; + } + } + + public static boolean isFileSystemRoot(FileObject folder) { + return isRoot(folder); + } + + public static boolean isParent(FileObject folder, FileObject file) { + try { + FileObject parent = file.getParent(); + + return parent != null && parent.equals(folder); + + } catch (FileSystemException ex) { + return false; + } + } + + public static String getRemoteUserHome(SshParameters sshParameters) throws FileSystemException { + return "/home/" + sshParameters.getUser(); + } + + public static FileObject getUserHome() throws FileSystemException { + return resolveFileObject(Util.isUnix() ? PrefUtil.USER_DIR : PrefUtil.USER_HOME); + } + + public static void checkForSftpLinks(FileObject[] files, TaskContext taskContext) { + logger.trace("Checking for SFTP links"); + taskContext.setMax(files.length); + long ts = System.currentTimeMillis(); + for (int i = 0; i < files.length && !taskContext.isStop(); i++) { + FileObject fileObject = files[i]; + try { + if (fileObject instanceof SftpFileObject) { + SftpFileObject sftpFileObject = (SftpFileObject) fileObject; + long size = sftpFileObject.getContent().getSize(); + if (sftpFileObject.getType() == FileType.FILE && size < SYMBOLIC_LINK_MAX_SIZE && size != 0) { + if (!pointToItself(sftpFileObject)) { + files[i] = new LinkFileObject(sftpFileObject); + } + } + + } + taskContext.setCurrentProgress(i); + } catch (Exception e) { + + } + + } + long checkDuration = System.currentTimeMillis() - ts; + logger.trace("Checking SFTP links took {} ms [{}ms/file]", checkDuration, (float) checkDuration / files.length); + } + + public static boolean pointToItself(FileObject fileObject) throws FileSystemException { + if (!fileObject.getURL().getProtocol().equalsIgnoreCase("file") && FileType.FILE.equals(fileObject.getType())) { + logger.trace("Checking if {} is pointing to itself", fileObject.getName().getFriendlyURI()); + FileObject[] children = VFSUtils.getChildren(fileObject); + logger.trace("Children number of {} is {}", fileObject.getName().getFriendlyURI(), children.length); + if (children.length == 1) { + FileObject child = children[0]; + if (child.getContent().getSize() != child.getContent().getSize()) { + return false; + } + if (child.getName().getBaseName().equals(fileObject.getName().getBaseName())) { + return true; + } + } + } + return false; + } + + public static FileObject[] getChildren(FileObject fileObject) throws FileSystemException { + FileObject[] result; + if (isLocalFileSystem(fileObject) && isArchive(fileObject)) { + String extension = fileObject.getName().getExtension(); + result = VFSUtils.resolveFileObject(extension + ":" + fileObject.getURL().toString() + "!/").getChildren(); + } else { + result = fileObject.getChildren(); + } + return filterInvalidFiles(result); + } + + private static FileObject[] filterInvalidFiles(FileObject[] result) { + List validFileObjects = new ArrayList<>(); + for (FileObject fo : result) { + if (fo.getName() instanceof InvalidFileName) { + logger.warn("Invalid filename filtered: {}", ((InvalidFileName) fo.getName()).getOriginalName()); + } else { + if (isLocalFileSystem(fo) && isInvalidFolder(fo)) { + logger.warn("Invalid folder filtered: {}", fo.getName()); + } else { + validFileObjects.add(fo); + } + } + } + return validFileObjects.toArray(new FileObject[0]); + } + + private static boolean isInvalidFolder(FileObject folder) { + try { + if (folder.getType() != FileType.FOLDER) { + return false; + } + + File file = new File(decode(folder.getName().getURI(), null)); + String[] files = UriParser.encode(file.list()); + + return files == null; + } catch (Exception e) { + return true; + } + } + + public static boolean isArchive(FileObject fileObject) { + return isArchive(fileObject.getName()); + } + + public static boolean isArchive(FileName fileName) { + String extension = fileName.getExtension(); + return archivesSuffixes.contains(extension.toLowerCase()); + } + + private static boolean isLocalFileSystem(FileObject fileObject) { + return fileObject.getName().getScheme().equalsIgnoreCase("file"); + } + + public static Icon getIconForFileSystem(String url) { + String schema = "file"; + if (null != url) { + int indexOf = url.indexOf(UNIX_PROTOCOL_PREFIX); + if (indexOf > 0) { + schema = url.substring(0, indexOf); + } + } + return schemeIconMap.get(schema); + } + + public static boolean canGoUrl(FileObject fileObject) throws FileSystemException { + if (VFSUtils.pointToItself(fileObject)) { + return false; + } + if (VFSUtils.isLocalFile(fileObject)) { + return false; + } + return true; + + } + + public static String encode(String url, SshParameters sshParameters) { + String fixedUrl = url.replace("\\", "/"); + if (sshParameters != null) { + String host = sshParameters.getHost(); + String port = String.valueOf(sshParameters.getPort()); + String typePrefix = LocationType.sftp.toString(); + if (port.equals(DEFAULT_SSH_PORT)) { + return typePrefix + host + fixedUrl; + } else { + return typePrefix + host + ":" + port + fixedUrl; + } + } else { + String typePrefix = LocationType.file.toString(); + return typePrefix + fixedUrl; + } + } + + public static String decode(String path, SshParameters sshParameters) { + if (path.startsWith(LocationType.file.toString())) { + return StringUtils.removeStart(path, LocationType.file.toString()); + } else if (path.startsWith(LocationType.sftp.toString()) && sshParameters != null) { + String noType = StringUtils.removeStart(path, LocationType.sftp.toString()); + String noHost = StringUtils.removeStart(noType, sshParameters.getHost()); + String noPort = StringUtils.removeStart(noHost, ":" + sshParameters.getPort()); + return noPort; + } + return null; + } + + public static void showErrorMessage(final Component parent, final String url, final Exception e) { + ExecUtil.invokeLater(new Runnable() { + @Override + public void run() { + String message = "Error opening " + url; + if (e != null) { + message += "\n" + e.getMessage(); + if (message.contains("descendent")) { + message = message.replace("descendent", ""); + } + } + logger.error(message); + JOptionPane.showMessageDialog(parent, message, "File System Error", JOptionPane.ERROR_MESSAGE); + } + }); + } } diff --git a/src/eu/engys/util/plaf/HelyxOSLookAndFeel.java b/src/eu/engys/util/plaf/HelyxOSLookAndFeel.java index 5b1b433..218d790 100644 --- a/src/eu/engys/util/plaf/HelyxOSLookAndFeel.java +++ b/src/eu/engys/util/plaf/HelyxOSLookAndFeel.java @@ -1,29 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.plaf; import javax.swing.UIManager; diff --git a/src/eu/engys/util/plaf/ILookAndFeel.java b/src/eu/engys/util/plaf/ILookAndFeel.java index 32dbe88..840808d 100644 --- a/src/eu/engys/util/plaf/ILookAndFeel.java +++ b/src/eu/engys/util/plaf/ILookAndFeel.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.plaf; diff --git a/src/eu/engys/util/plaf/LAFUtils.java b/src/eu/engys/util/plaf/LAFUtils.java new file mode 100644 index 0000000..acd2371 --- /dev/null +++ b/src/eu/engys/util/plaf/LAFUtils.java @@ -0,0 +1,57 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.util.plaf; + +import java.awt.Toolkit; +import java.util.StringTokenizer; + +import eu.engys.util.Util; + +public class LAFUtils { + + public static final String CHARS_DIGITS = "0123456789"; + private static final int DEFAULT_FONT_SIZE = 11; + + public static int getSystemFontSize() { + int size = DEFAULT_FONT_SIZE; + if (Util.isUnix()) { + String fontName = (String) Toolkit.getDefaultToolkit().getDesktopProperty("gnome.Gtk/FontName"); + if (fontName != null) { + StringTokenizer tok = new StringTokenizer(fontName); + while (tok.hasMoreTokens()) { + String word = tok.nextToken(); + if (CHARS_DIGITS.indexOf(word.charAt(0)) != -1) { + try { + size = Integer.parseInt(word); + } catch (NumberFormatException ex) { + } + } + } + } + } + return size; + } + +} diff --git a/src/eu/engys/util/plaf/TestLookAndFeel.java b/src/eu/engys/util/plaf/TestLookAndFeel.java index a3e7d23..3b115c1 100644 --- a/src/eu/engys/util/plaf/TestLookAndFeel.java +++ b/src/eu/engys/util/plaf/TestLookAndFeel.java @@ -1,66 +1,62 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.plaf; - public class TestLookAndFeel implements ILookAndFeel { - - private static final double[] BG_COLOR = {0.3, 0.6, 0.9}; - private static final double[] BG2_COLOR = {0.1, 0.2, 0.4}; - private static final double[] SELECT_COLOR = {1.0, 1.0, 1.0}; - - @Override - public double[] get3DColor1() { - return BG_COLOR; - } - - @Override - public double[] get3DColor2() { - return BG2_COLOR; - } - - @Override - public double[] get3DSelectionColor() { - return SELECT_COLOR; - } - - @Override - public int getMainWidth() { - return 550; - } - - @Override - public int getSecondaryWidth() { - return 180; - } - - @Override + + private static final double[] BG_COLOR = { 0.3, 0.6, 0.9 }; + private static final double[] BG2_COLOR = { 0.1, 0.2, 0.4 }; + private static final double[] SELECT_COLOR = { 1.0, 1.0, 1.0 }; + + @Override + public double[] get3DColor1() { + return BG_COLOR; + } + + @Override + public double[] get3DColor2() { + return BG2_COLOR; + } + + @Override + public double[] get3DSelectionColor() { + return SELECT_COLOR; + } + + @Override + public int getMainWidth() { + return 550; + } + + @Override + public int getSecondaryWidth() { + return 180; + } + + @Override public void init() { } - -} +} diff --git a/src/eu/engys/util/progress/ConsoleMonitor.java b/src/eu/engys/util/progress/ConsoleMonitor.java index 0ea2e2d..53a5e20 100644 --- a/src/eu/engys/util/progress/ConsoleMonitor.java +++ b/src/eu/engys/util/progress/ConsoleMonitor.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.progress; diff --git a/src/eu/engys/util/progress/ProgressBar.java b/src/eu/engys/util/progress/ProgressBar.java index 18800b8..f779fcd 100644 --- a/src/eu/engys/util/progress/ProgressBar.java +++ b/src/eu/engys/util/progress/ProgressBar.java @@ -1,27 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.progress; import javax.swing.JProgressBar; diff --git a/src/eu/engys/util/progress/ProgressDialog.java b/src/eu/engys/util/progress/ProgressDialog.java index 7512df6..9286441 100644 --- a/src/eu/engys/util/progress/ProgressDialog.java +++ b/src/eu/engys/util/progress/ProgressDialog.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.progress; @@ -32,7 +31,6 @@ import java.awt.Window; import java.awt.event.ActionEvent; import java.awt.event.AdjustmentEvent; import java.awt.event.AdjustmentListener; -import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; import java.util.List; @@ -46,7 +44,6 @@ import javax.swing.JDialog; import javax.swing.JEditorPane; import javax.swing.JPanel; import javax.swing.JScrollPane; -import javax.swing.SwingUtilities; import eu.engys.util.ui.ExecUtil; import eu.engys.util.ui.UiUtil; @@ -56,7 +53,7 @@ public class ProgressDialog extends JDialog { private final Action CLOSE_ACTION = new AbstractAction("Close") { @Override public void actionPerformed(ActionEvent e) { - dispose(); + setVisible(false); } }; @@ -155,7 +152,7 @@ public class ProgressDialog extends JDialog { } private void _start() { - _update(); + _update("START"); stopButton.setVisible(monitor.canStop()); @@ -198,15 +195,16 @@ public class ProgressDialog extends JDialog { } } - public void update() { + public void update(final String label) { ExecUtil.invokeLater(new Runnable() { public void run() { - _update(); + _update(label); } }); } - private void _update() { + private void _update(String label) { +// System.out.println("ProgressDialog '"+label+"' current: " + monitor.getCurrent() + ", total: " + monitor.getTotal() + ", indet: " + monitor.isIndeterminate()); if (monitor.getCurrent() != monitor.getTotal()) { String messages = monitor.getMessages(); statusArea.setText(messages); @@ -217,8 +215,9 @@ public class ProgressDialog extends JDialog { } if (!monitor.isIndeterminate()) { - if (monitor.getTotal() != progressBar.getMaximum()) - progressBar.setMaximum(monitor.getTotal()); + if (monitor.getTotal() != progressBar.getMaximum()) { + progressBar.setMaximum(monitor.getTotal()); + } if (monitor.getTotal() > 0) { progressBar.setStringPainted(true); @@ -227,7 +226,6 @@ public class ProgressDialog extends JDialog { progressBar.setStringPainted(false); } } - } else { progressBar.setStringPainted(true); progressBar.setValue(progressBar.getMaximum()); @@ -235,27 +233,4 @@ public class ProgressDialog extends JDialog { } } - public static void runOnEDT(final Runnable runnable) { - if (SwingUtilities.isEventDispatchThread()) { - // System.out.println("ProgressDialog.runOnEDT() is EDT"); - // Thread.dumpStack(); - runnable.run(); - } else { - SwingUtilities.invokeLater(runnable); - } - } - - public static void waitOnEDT(final Runnable runnable) { - if (SwingUtilities.isEventDispatchThread()) { - // System.out.println("ProgressDialog.runOnEDT() is EDT"); - // Thread.dumpStack(); - runnable.run(); - } else { - try { - SwingUtilities.invokeAndWait(runnable); - } catch (InvocationTargetException | InterruptedException e) { - e.printStackTrace(); - } - } - } } diff --git a/src/eu/engys/util/progress/ProgressMonitor.java b/src/eu/engys/util/progress/ProgressMonitor.java index 78ddbd1..4d4aca3 100644 --- a/src/eu/engys/util/progress/ProgressMonitor.java +++ b/src/eu/engys/util/progress/ProgressMonitor.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.progress; diff --git a/src/eu/engys/util/progress/ProgressMonitorImpl.java b/src/eu/engys/util/progress/ProgressMonitorImpl.java index 45c1c43..ea2b50b 100644 --- a/src/eu/engys/util/progress/ProgressMonitorImpl.java +++ b/src/eu/engys/util/progress/ProgressMonitorImpl.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.progress; @@ -118,7 +117,7 @@ public class ProgressMonitorImpl implements ProgressMonitor { @Override public void setTotal(int total) { this.total = total; - dialog().update(); + dialog().update("setTotal"); } private Future currentTask = null; @@ -213,7 +212,7 @@ public class ProgressMonitorImpl implements ProgressMonitor { @Override public void setIndeterminate(boolean indeterminate) { this.indeterminate = indeterminate; - dialog().update(); + dialog().update("setIndeterminate"); } @Override @@ -223,7 +222,7 @@ public class ProgressMonitorImpl implements ProgressMonitor { this.current = current; if (msg != null) info(msg); - dialog().update(); + dialog().update("setCurrent"); } @Override @@ -233,7 +232,7 @@ public class ProgressMonitorImpl implements ProgressMonitor { this.current = current; if (msg != null) info(msg, indentLevel); - dialog().update(); + dialog().update("setCurrent"); } @Override @@ -247,7 +246,7 @@ public class ProgressMonitorImpl implements ProgressMonitor { sb.append(addIndentation(msg, indentLevel)); sb.append(END_INFO); } - dialog().update(); + dialog().update("setCurrent"); } @Override @@ -270,7 +269,7 @@ public class ProgressMonitorImpl implements ProgressMonitor { sb.append(START_INFO); sb.append(message); sb.append(END_INFO); - dialog().update(); + dialog().update("info: " + message); } @Override @@ -278,7 +277,7 @@ public class ProgressMonitorImpl implements ProgressMonitor { sb.append(START_INFO); sb.append(message); sb.append(END_INFO_N); - dialog().update(); + dialog().update("infoN: " + message); } @Override @@ -301,7 +300,7 @@ public class ProgressMonitorImpl implements ProgressMonitor { // sb.append(START_INFO); sb.append(message); // sb.append(END_INFO); - dialog().update(); + dialog().update("debug"); } @Override @@ -310,7 +309,7 @@ public class ProgressMonitorImpl implements ProgressMonitor { sb.append(START_WARING); sb.append(message); sb.append(END_WARNING); - dialog().update(); + dialog().update("warning"); } @Override @@ -336,7 +335,7 @@ public class ProgressMonitorImpl implements ProgressMonitor { sb.append(START_ERROR); sb.append(message); sb.append(END_ERROR); - dialog().update(); + dialog().update("error"); } private void error(Throwable t) { diff --git a/src/eu/engys/util/progress/SilentMonitor.java b/src/eu/engys/util/progress/SilentMonitor.java index 532c028..d07252a 100644 --- a/src/eu/engys/util/progress/SilentMonitor.java +++ b/src/eu/engys/util/progress/SilentMonitor.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.progress; diff --git a/src/eu/engys/util/progress/VTKProgressConsoleWrapper.java b/src/eu/engys/util/progress/VTKProgressConsoleWrapper.java deleted file mode 100644 index ccc62dc..0000000 --- a/src/eu/engys/util/progress/VTKProgressConsoleWrapper.java +++ /dev/null @@ -1,52 +0,0 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - -package eu.engys.util.progress; - -import vtk.vtkAlgorithm; - -public class VTKProgressConsoleWrapper { - - private vtkAlgorithm algo; - private String title; - - public VTKProgressConsoleWrapper(String title, vtkAlgorithm algo, ProgressMonitor monitor) { - this.title = title; - this.algo = algo; - } - - public void onProgress() { - System.err.println( (int) (algo.GetProgress() * 100)); - } - - public void onStart() { - System.err.println("Loading " + title + "... "); - } - - public void onEnd() { - System.out.println("done"); - } - -} diff --git a/src/eu/engys/util/progress/VTKProgressMonitorWrapper.java b/src/eu/engys/util/progress/VTKProgressMonitorWrapper.java deleted file mode 100644 index 2fcf39a..0000000 --- a/src/eu/engys/util/progress/VTKProgressMonitorWrapper.java +++ /dev/null @@ -1,54 +0,0 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - -package eu.engys.util.progress; - -import vtk.vtkAlgorithm; - -public class VTKProgressMonitorWrapper { - - private vtkAlgorithm algo; - private ProgressMonitor monitor; - private String title; - - public VTKProgressMonitorWrapper(String title, vtkAlgorithm algo, ProgressMonitor monitor) { - this.title = title; - this.algo = algo; - this.monitor = monitor; - } - - public void onProgress() { - monitor.setCurrent(null, (int) (algo.GetProgress() * 100)); - } - - public void onStart() { - monitor.infoN("Loading " + title + "... ", 1); - } - - public void onEnd() { - monitor.info("done"); - } - -} diff --git a/src/eu/engys/util/ui/ASCIIArt.java b/src/eu/engys/util/ui/ASCIIArt.java index 8ddee27..029861d 100644 --- a/src/eu/engys/util/ui/ASCIIArt.java +++ b/src/eu/engys/util/ui/ASCIIArt.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.ui; import java.awt.Font; diff --git a/src/eu/engys/util/ui/BigButton.java b/src/eu/engys/util/ui/BigButton.java index 171ff25..16dafd5 100644 --- a/src/eu/engys/util/ui/BigButton.java +++ b/src/eu/engys/util/ui/BigButton.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.ui; diff --git a/src/eu/engys/util/ui/ButtonBar.java b/src/eu/engys/util/ui/ButtonBar.java index 4fc0816..2c0f04d 100644 --- a/src/eu/engys/util/ui/ButtonBar.java +++ b/src/eu/engys/util/ui/ButtonBar.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.ui; diff --git a/src/eu/engys/util/ui/CheckBoxPanel.java b/src/eu/engys/util/ui/CheckBoxPanel.java index ef03fb1..00fd7bc 100644 --- a/src/eu/engys/util/ui/CheckBoxPanel.java +++ b/src/eu/engys/util/ui/CheckBoxPanel.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.ui; @@ -80,7 +79,6 @@ public class CheckBoxPanel extends JPanel { titleComponent.setFont(font); titleComponent.setForeground(color); - titleComponent.setFocusable(false); titleComponent.setContentAreaFilled(false); titleComponent.addActionListener(new CheckBoxPanel.EnableDisableAction()); @@ -92,4 +90,5 @@ public class CheckBoxPanel extends JPanel { } } + } diff --git a/src/eu/engys/util/ui/ChooseFileAction.java b/src/eu/engys/util/ui/ChooseFileAction.java index 2491123..549c066 100644 --- a/src/eu/engys/util/ui/ChooseFileAction.java +++ b/src/eu/engys/util/ui/ChooseFileAction.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.ui; import java.awt.event.ActionEvent; diff --git a/src/eu/engys/util/ui/ChooserPanel.java b/src/eu/engys/util/ui/ChooserPanel.java index d93b898..9f8f50d 100644 --- a/src/eu/engys/util/ui/ChooserPanel.java +++ b/src/eu/engys/util/ui/ChooserPanel.java @@ -1,30 +1,31 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.ui; +import static eu.engys.util.ui.UiUtil.NONE_LABEL; + import java.awt.Dimension; import java.awt.FlowLayout; import java.awt.GridLayout; @@ -42,7 +43,7 @@ import javax.swing.JRadioButton; public class ChooserPanel extends JPanel implements ActionListener { - public static final String NONE = "NONE"; + public static final String SELECTION_PROPERTY = "selection"; private ButtonGroup buttonGroup = new ButtonGroup(); private Map buttons = new HashMap(); @@ -73,7 +74,7 @@ public class ChooserPanel extends JPanel implements ActionListener { if (buttonGroup.getSelection() != null) return buttonGroup.getSelection().getActionCommand(); else - return NONE; + return NONE_LABEL; } public boolean hasSelection() { @@ -123,15 +124,16 @@ public class ChooserPanel extends JPanel implements ActionListener { return radio; } - public void addChoice(String choice, int offset) { + public JRadioButton addChoice(String choice, int offset) { JRadioButton radio = createChoice(choice, offset); add(radio); buttonGroup.add(radio); buttons.put(choice, radio); + return radio; } - public void addChoice(String choice) { - addChoice(choice, UiUtil.ONE_SPACE); + public JRadioButton addChoice(String choice) { + return addChoice(choice, UiUtil.ONE_SPACE); } public void addChoices(int offset, String... choices) { @@ -152,7 +154,7 @@ public class ChooserPanel extends JPanel implements ActionListener { @Override public void actionPerformed(ActionEvent e) { if (e.getSource() instanceof AbstractButton) { - firePropertyChange("selection", false, true); + firePropertyChange(SELECTION_PROPERTY, false, true); } } diff --git a/src/eu/engys/util/ui/ComponentTitledBorder.java b/src/eu/engys/util/ui/ComponentTitledBorder.java index 9f8b7ab..ef02db7 100644 --- a/src/eu/engys/util/ui/ComponentTitledBorder.java +++ b/src/eu/engys/util/ui/ComponentTitledBorder.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.ui; import java.awt.Color; @@ -199,4 +198,4 @@ public class ComponentTitledBorder extends TitledBorder { } return compR; } -} +} \ No newline at end of file diff --git a/src/eu/engys/util/ui/ComponentsFactory.java b/src/eu/engys/util/ui/ComponentsFactory.java index 095b0d4..24fb122 100644 --- a/src/eu/engys/util/ui/ComponentsFactory.java +++ b/src/eu/engys/util/ui/ComponentsFactory.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.ui; import java.awt.Color; @@ -39,6 +38,7 @@ import javax.swing.JList; import javax.swing.JPasswordField; import javax.swing.JTextArea; import javax.swing.ListCellRenderer; +import javax.swing.ListModel; import javax.swing.SwingConstants; import javax.swing.UIManager; import javax.swing.event.ListDataListener; @@ -99,6 +99,7 @@ public class ComponentsFactory { JCheckBox checkBox = new JCheckBox(string); checkBox.setSelected(def); checkBox.setOpaque(false); + checkBox.setForeground(color.darker()); checkBox.putClientProperty("Synthetica.background", color); checkBox.putClientProperty("Synthetica.background.alpha", UIManager.get("Synthetica.checkbox.background.alpha")); return checkBox; @@ -120,6 +121,10 @@ public class ComponentsFactory { return new StringField(text); } + public static StringField stringField(String text, boolean checkEmptyStrings, boolean checkForbidden) { + return new StringField(text, checkEmptyStrings, checkForbidden); + } + public static JPasswordField passwordField() { return new JPasswordField(20); } @@ -128,6 +133,10 @@ public class ComponentsFactory { return new SpinnerField(0, Integer.MAX_VALUE, 0); } + public static SpinnerField spinnerField(Integer def) { + return new SpinnerField(0, Integer.MAX_VALUE, def); + } + public static SpinnerField spinnerField(Integer lb, Integer ub) { return new SpinnerField(lb, ub, Math.max(0, lb)); } @@ -140,6 +149,10 @@ public class ComponentsFactory { return new IntegerField(lb, ub, Math.max(0, lb)); } + public static IntegerField intField(Integer lb, Integer ub, Integer value, boolean checkEmptyValue) { + return new IntegerField(lb, ub, value, checkEmptyValue); + } + public static IntegerField intField(Integer def) { return new IntegerField(0, Integer.MAX_VALUE, def); } @@ -164,8 +177,8 @@ public class ComponentsFactory { return new DoubleField(-Double.MAX_VALUE, Double.MAX_VALUE, 0.0, places); } - public static DoubleField doubleField(Integer places, Double d) { - return new DoubleField(-Double.MAX_VALUE, Double.MAX_VALUE, d, places); + public static DoubleField doubleField(Integer places, Double def) { + return new DoubleField(-Double.MAX_VALUE, Double.MAX_VALUE, def, places); } public static DoubleField doubleField(Double lb, Double ub) { @@ -347,22 +360,72 @@ public class ComponentsFactory { return combo; } + @SuppressWarnings({ "rawtypes", "unchecked" }) + public static JComboBox selectField(final ListModel listModel) { + final JComboBox combo = selectField(); + combo.setModel(new ComboBoxModel() { + + private Object selected; + + @Override + public void removeListDataListener(ListDataListener l) { + } + + @Override + public int getSize() { + return listModel.getSize(); + } + + @Override + public Object getElementAt(int index) { + return listModel.getElementAt(index); + } + + @Override + public void addListDataListener(ListDataListener l) { + } + + @Override + public void setSelectedItem(Object anItem) { + this.selected = anItem; + combo.revalidate(); + combo.repaint(); + } + + @Override + public Object getSelectedItem() { + return selected; + } + }); + return combo; + } + + @SuppressWarnings("unchecked") + public static JComboBox selectField(T... items) { + JComboBox combo = new SelectField<>(items); + return combo; + } + public static JComboBox selectField(String... items) { JComboBox combo = new SelectField<>(items); return combo; } + public static JComboBox selectField(final E[] keys, final String[] labels) { + return selectField(keys, labels, new Icon[keys.length]); + } + public static JComboBox selectField(final String[] keys, final String[] labels) { return selectField(keys, labels, new Icon[keys.length]); } - public static SelectField selectField(final String[] keys, final String[] labels, final Icon[] icons) { - SelectField combo = new SelectField<>(keys, labels, icons); + public static SelectField selectField(final E[] keys, final String[] labels, final Icon[] icons) { + SelectField combo = new SelectField<>(keys, labels, icons); return combo; } - private static JComboBoxWithItemsSupport selectFieldWithItemSupport() { - JComboBoxWithItemsSupport combo = new JComboBoxWithItemsSupport() { + private static JComboBoxWithItemsSupport selectFieldWithItemSupport() { + JComboBoxWithItemsSupport combo = new JComboBoxWithItemsSupport() { @Override protected void fireActionEvent() { super.fireActionEvent(); @@ -372,17 +435,19 @@ public class ComponentsFactory { return combo; } - public static JComboBoxWithItemsSupport selectFieldWithItemSupport(final String[] items) { - JComboBoxWithItemsSupport combo = selectFieldWithItemSupport(); - for (String string : items) { + public static JComboBoxWithItemsSupport selectFieldWithItemSupport(final String[] keys) { + JComboBoxWithItemsSupport combo = selectFieldWithItemSupport(); + for (String string : keys) { combo.addItem(string); } return combo; } - public static JComboBoxWithItemsSupport selectFieldWithItemSupport(final String[] keys, final String[] items) { - JComboBoxWithItemsSupport combo = selectFieldWithItemSupport(keys); - combo.setLabels(items); + public static JComboBoxWithItemsSupport selectFieldWithItemSupport(final String[] keys, final String[] labels) { + JComboBoxWithItemsSupport combo = selectFieldWithItemSupport(); + for (int i = 0; i < keys.length; i++) { + combo.addItem(keys[i], labels[i]); + } return combo; } diff --git a/src/eu/engys/util/ui/CopyPasteSupport.java b/src/eu/engys/util/ui/CopyPasteSupport.java index a6cd33f..208cac8 100644 --- a/src/eu/engys/util/ui/CopyPasteSupport.java +++ b/src/eu/engys/util/ui/CopyPasteSupport.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.ui; @@ -33,15 +32,23 @@ import java.awt.datatransfer.StringSelection; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.KeyEvent; +import java.util.EnumSet; +import java.util.List; import java.util.StringTokenizer; import javax.swing.JComponent; import javax.swing.JOptionPane; import javax.swing.JTable; import javax.swing.KeyStroke; +import javax.swing.RowSorter; +import javax.swing.RowSorter.SortKey; +import javax.swing.table.TableModel; public class CopyPasteSupport { + private static final String PASTE_ACTION = "Paste"; + private static final String COPY_ACTION = "Copy"; + public static void addSupportTo(JTable table) { KeyStroke copy = KeyStroke.getKeyStroke(KeyEvent.VK_C, ActionEvent.CTRL_MASK, false); // Identifying the copy KeyStroke user can modify this @@ -52,8 +59,8 @@ public class CopyPasteSupport { CopyPasteListener cpl = new CopyPasteListener(table); - table.registerKeyboardAction(cpl, "Copy", copy, JComponent.WHEN_FOCUSED); - table.registerKeyboardAction(cpl, "Paste", paste, JComponent.WHEN_FOCUSED); + table.registerKeyboardAction(cpl, COPY_ACTION, copy, JComponent.WHEN_FOCUSED); + table.registerKeyboardAction(cpl, PASTE_ACTION, paste, JComponent.WHEN_FOCUSED); table.setColumnSelectionAllowed(true); table.setRowSelectionAllowed(true); @@ -69,140 +76,173 @@ public class CopyPasteSupport { @Override public void actionPerformed(ActionEvent e) { - Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); - - if (e.getActionCommand().equals("Copy")) { - StringBuffer sbf = new StringBuffer(); - // Check to ensure we have selected only a contiguous block of - // cells - int numcols = table.getSelectedColumnCount(); - int numrows = table.getSelectedRowCount(); - - int[] rowsselected = table.getSelectedRows(); - int[] colsselected = table.getSelectedColumns(); - if (!((numrows - 1 == rowsselected[rowsselected.length - 1] - rowsselected[0] && numrows == rowsselected.length) && (numcols - 1 == colsselected[colsselected.length - 1] - - colsselected[0] && numcols == colsselected.length))) { - JOptionPane.showMessageDialog(UiUtil.getActiveWindow(), "Invalid Copy Selection", "Invalid Copy Selection", JOptionPane.ERROR_MESSAGE); - return; - } - for (int i = 0; i < numrows; i++) { - for (int j = 0; j < numcols; j++) { - sbf.append(table.getValueAt(rowsselected[i], colsselected[j])); - if (j < numcols - 1) - sbf.append("\t"); - } - sbf.append("\n"); - } - StringSelection stsel = new StringSelection(sbf.toString()); - - clipboard.setContents(stsel, stsel); + if (e.getActionCommand().equals(COPY_ACTION)) { + copy(); } - if (e.getActionCommand().equals("Paste")) { - System.out.println("Trying to Paste"); - int[] selRows = table.getSelectedRows(); - int[] selCols = table.getSelectedColumns(); + if (e.getActionCommand().equals(PASTE_ACTION)) { + RowSorter sorter = table.getRowSorter(); + List sortKeys = null; + if (sorter != null ) { + sortKeys = sorter.getSortKeys(); + sorter.setSortKeys(null); + } + paste(); + if (sorter != null && sortKeys != null ) { + sorter.setSortKeys(sortKeys); + } + } + } - int startRow = selRows[0]; - int startCol = selCols[0]; + private void copy() { + Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); + StringBuffer sbf = new StringBuffer(); + // Check to ensure we have selected only a contiguous block of cells + int numcols = table.getSelectedColumnCount(); + int numrows = table.getSelectedRowCount(); - try { - String copiedString = (String) clipboard.getContents(this).getTransferData(DataFlavor.stringFlavor); - System.out.println("String is:" + copiedString); + int[] rowsselected = table.getSelectedRows(); + int[] colsselected = table.getSelectedColumns(); + if (!((numrows - 1 == rowsselected[rowsselected.length - 1] - rowsselected[0] && numrows == rowsselected.length) && (numcols - 1 == colsselected[colsselected.length - 1] + - colsselected[0] && numcols == colsselected.length))) { + JOptionPane.showMessageDialog(UiUtil.getActiveWindow(), "Invalid Copy Selection", "Invalid Copy Selection", JOptionPane.ERROR_MESSAGE); + return; + } + for (int i = 0; i < numrows; i++) { + for (int j = 0; j < numcols; j++) { + sbf.append(table.getValueAt(rowsselected[i], colsselected[j])); + if (j < numcols - 1) + sbf.append("\t"); + } + sbf.append("\n"); + } + StringSelection stsel = new StringSelection(sbf.toString()); - String[][] data = stringToArray(copiedString); - TypeOfCopy type = decodeTypeOfCopy(data, selRows, selCols); + clipboard.setContents(stsel, stsel); + } - if (type == TypeOfCopy.ERROR) { - JOptionPane.showMessageDialog(UiUtil.getActiveWindow(), "Invalid Paste Selection", "Invalid Paste Selection", JOptionPane.ERROR_MESSAGE); - } else { - System.out.println(String.format("Paste %d x %d -> %d x %d", data.length, data[0].length, selRows.length, selCols.length)); - switch (type) { - case CELL: - for (int i = 0; i < selRows.length; i++) { - for (int j = 0; j < selCols.length; j++) { - table.setValueAt(getEditedValue(data[0][0]), selRows[i], selCols[j]); - } + private void paste() { + Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); + + int[] selRows = table.getSelectedRows(); + int[] selCols = table.getSelectedColumns(); + + int nRows = selRows.length; + int nCols = selCols.length; + + try { + String copiedString = (String) clipboard.getContents(this).getTransferData(DataFlavor.stringFlavor); +// System.out.println("String is:" + copiedString); + + String[][] data = stringToArray(copiedString); + Structure copyStructure = decodeStructureOfData(data); + Structure pasteStructure = decodeStructureOfData(new String[nRows][nCols]); + + if (copyStructure == Structure.ERROR) { + JOptionPane.showMessageDialog(UiUtil.getActiveWindow(), "Invalid Paste Selection", "Invalid Paste Selection", JOptionPane.ERROR_MESSAGE); + } else { +// System.out.println(String.format("Paste %s -> %s (%d x %d -> %d x %d)", copyStructure, pasteStructure, data.length, data[0].length, selRows.length, selCols.length)); + switch (copyStructure) { + case CELL: + for (int i = 0; i < selRows.length; i++) { + for (int j = 0; j < selCols.length; j++) { + table.setValueAt(getEditedValue(data[0][0]), selRows[i], selCols[j]); } - break; + } + break; - case ROW: + case ROW: + if (EnumSet.range(Structure.CELL,Structure.CELL).contains(pasteStructure)) { + // int retVal = JOptionPane.showConfirmDialog(null, "The content of the clipboard is bigger than the range selected.\nDo you want to insert anyway?", "Warning", JOptionPane.YES_NO_OPTION); + // if (retVal == JOptionPane.YES_OPTION) { + int rows = Math.max(selRows.length, data.length); + int cols = Math.max(selCols.length, data[0].length); + + for (int i = 0; i < rows; i++) { + for (int j = 0; j < cols; j++) { + int r = selRows[0] + i; + int c = selCols[0] + j; + if (inRange(r, c)) { + Object v = getEditedValue(data[0][j]); + System.out.println("[" + r + ", " + c +"] < " + v); + table.setValueAt(v, r, c); + } + } + // } + } + } else { for (int i = 0; i < selRows.length; i++) { for (int j = 0; j < selCols.length; j++) { table.setValueAt(getEditedValue(data[0][j]), selRows[i], selCols[j]); } } - break; - - case COLUMN: - for (int i = 0; i < selRows.length; i++) { - for (int j = 0; j < selCols.length; j++) { - table.setValueAt(getEditedValue(data[j][0]), selRows[i], selCols[j]); - } - } - break; - - case MATRIX: - for (int i = 0; i < selRows.length; i++) { - for (int j = 0; j < selCols.length; j++) { - table.setValueAt(getEditedValue(data[i][j]), selRows[i], selCols[j]); - } - } - break; - - default: - break; } + break; + + case COLUMN: + //TODO estendere funzionamento come per la riga + for (int i = 0; i < selRows.length; i++) { + for (int j = 0; j < selCols.length; j++) { + table.setValueAt(getEditedValue(data[j][0]), selRows[i], selCols[j]); + } + } + break; + + case MATRIX: + //TODO estendere funzionamento come per la riga + for (int i = 0; i < selRows.length; i++) { + for (int j = 0; j < selCols.length; j++) { + table.setValueAt(getEditedValue(data[i][j]), selRows[i], selCols[j]); + } + } + break; + + default: + break; } - } catch (Exception ex) { - ex.printStackTrace(); + table.repaint(); } + } catch (Exception ex) { + ex.printStackTrace(); } } + + public boolean inRange(int r, int c) { + return r < table.getRowCount() && c < table.getColumnCount(); + } private Object getEditedValue(String string) { - // Class klass = table.getModel().getColumnClass(col); - // System.out.println("CopyPasteSupport.CopyPasteListener.getEditedValue() "+klass); try { return Double.valueOf(string); } catch (NumberFormatException e) { - return 0; + return 0D; } - // Object value; - - // if (klass.isInstance(Double.class)) { - // value = Double.valueOf(string); - // } else { - // value = string; - // } } - enum TypeOfCopy { + enum Structure { CELL, ROW, COLUMN, MATRIX, ERROR } - private TypeOfCopy decodeTypeOfCopy(String[][] data, int[] selRows, int[] selCols) { + private Structure decodeStructureOfData(String[][] data) { if (data != null) { if (data.length == 1) { if (data[0].length == 1) { - return TypeOfCopy.CELL; - } else if (data[0].length == selCols.length) { - return TypeOfCopy.ROW; + return Structure.CELL; } else { - return TypeOfCopy.ERROR; + return Structure.ROW; } - } else if (data.length == selRows.length) { + } else if (data.length > 1) { if (data[0].length == 1) { - return TypeOfCopy.COLUMN; - } else if (data[0].length == selCols.length) { - return TypeOfCopy.MATRIX; + return Structure.COLUMN; + } else if (data[0].length > 1) { + return Structure.MATRIX; } else { - return TypeOfCopy.ERROR; + return Structure.ERROR; } } else { - return TypeOfCopy.ERROR; + return Structure.ERROR; } } else { - return TypeOfCopy.ERROR; + return Structure.ERROR; } } @@ -211,14 +251,20 @@ public class CopyPasteSupport { String[][] data = new String[rowTokenizer.countTokens()][]; for (int i = 0; rowTokenizer.hasMoreTokens(); i++) { String rowstring = rowTokenizer.nextToken(); - StringTokenizer colTokenizer = new StringTokenizer(rowstring, "\t"); + StringTokenizer colTokenizer; + if (copiedString.contains(",")) { + colTokenizer = new StringTokenizer(rowstring, ","); + } else { + colTokenizer = new StringTokenizer(rowstring, "\t"); + } data[i] = new String[colTokenizer.countTokens()]; for (int j = 0; colTokenizer.hasMoreTokens(); j++) { String value = (String) colTokenizer.nextToken(); - data[i][j] = value; + data[i][j] = value.trim(); } } return data; + } } } diff --git a/src/eu/engys/util/ui/DoubleListAction.java b/src/eu/engys/util/ui/DoubleListAction.java index 3189e17..a812a35 100644 --- a/src/eu/engys/util/ui/DoubleListAction.java +++ b/src/eu/engys/util/ui/DoubleListAction.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.ui; import java.awt.BorderLayout; @@ -100,15 +99,16 @@ public class DoubleListAction extends AbstractAction { String[] destination = listField.getValues(); String[] source = listBuilder.getSourceElements(); - String[] sourceMinusAlreadyPresent = new String[source.length - destination.length]; - int j = 0; List destinationList = Arrays.asList(destination); - for (int i = 0; i < source.length; i++) { - if (!destinationList.contains(source[i])) { - sourceMinusAlreadyPresent[j++] = source[i]; + List sourceList = new ArrayList<>(); + + for (String el : source) { + if (!destinationList.contains(el)) { + sourceList.add(el); } } - dual.setSourceElements(sourceMinusAlreadyPresent); + + dual.setSourceElements(sourceList.toArray()); dual.setDestinationElements(destination); dialog.setVisible(true); diff --git a/src/eu/engys/util/ui/DualList.java b/src/eu/engys/util/ui/DualList.java index 63dfe22..614de0c 100644 --- a/src/eu/engys/util/ui/DualList.java +++ b/src/eu/engys/util/ui/DualList.java @@ -1,29 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.ui; import java.awt.BorderLayout; @@ -49,7 +47,6 @@ import javax.swing.JLabel; import javax.swing.JList; import javax.swing.JPanel; import javax.swing.JScrollPane; -import javax.swing.ListModel; public class DualList extends JPanel { private JList sourceList; @@ -111,14 +108,6 @@ public class DualList extends JPanel { sourceListModel.addAll(newValue); } - private void addSourceElements(ListModel newValue) { - int size = newValue.getSize(); - for (int i = 0; i < size; i++) { - System.out.println("DualList.addSourceElements(): " + newValue.getElementAt(i)); - sourceListModel.add(newValue.getElementAt(i)); - } - } - @SuppressWarnings("deprecation") private void clearSourceSelected() { Object selected[] = sourceList.getSelectedValues(); diff --git a/src/eu/engys/util/ui/ExecUtil.java b/src/eu/engys/util/ui/ExecUtil.java index bbecce6..30e7efa 100644 --- a/src/eu/engys/util/ui/ExecUtil.java +++ b/src/eu/engys/util/ui/ExecUtil.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.ui; import java.lang.reflect.InvocationTargetException; diff --git a/src/eu/engys/util/ui/FieldChangeListener.java b/src/eu/engys/util/ui/FieldChangeListener.java new file mode 100644 index 0000000..2742fc7 --- /dev/null +++ b/src/eu/engys/util/ui/FieldChangeListener.java @@ -0,0 +1,59 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ + +package eu.engys.util.ui; + +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; + +public abstract class FieldChangeListener implements PropertyChangeListener, ActionListener { + + private boolean adjusting = false; + + public abstract void fieldChanged(Object source); + + public boolean isAdjusting() { + return adjusting; + } + + public void setAdjusting(boolean b) { + this.adjusting = b; + } + + @Override + public void propertyChange(PropertyChangeEvent e) { + if (! isAdjusting() && e.getPropertyName().equals("value")) { + fieldChanged(e.getSource()); + } + } + @Override + public void actionPerformed(ActionEvent e) { + if (! isAdjusting() ) { + fieldChanged(e.getSource()); + } + } +} diff --git a/src/eu/engys/util/ui/FileChooserUtils.java b/src/eu/engys/util/ui/FileChooserUtils.java index 2817a9e..965023b 100644 --- a/src/eu/engys/util/ui/FileChooserUtils.java +++ b/src/eu/engys/util/ui/FileChooserUtils.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.ui; import java.io.File; @@ -38,97 +37,101 @@ import eu.engys.util.filechooser.util.HelyxFileFilter; import eu.engys.util.filechooser.util.SelectionMode; public class FileChooserUtils { - + + public static final String STL_EXTENSION = "stl"; public static final String PDF_EXTENSION = "pdf"; - public static final String PNG_EXTENSION = "png"; - public static final String CSV_EXTENSION = "csv"; - public static final String EXCEL_EXTENSION_OLD = "xls"; - public static final String EXCEL_EXTENSION_NEW = "xlsx"; - - public static final String DEFAULT_SSH_PORT = "22"; - - public static File getPNGFile() { - File lastDir = PrefUtil.getWorkDir(PrefUtil.LAST_OPEN_EXPORT_DIR); + public static final String PNG_EXTENSION = "png"; + public static final String CSV_EXTENSION = "csv"; + public static final String EXCEL_EXTENSION_OLD = "xls"; + public static final String EXCEL_EXTENSION_NEW = "xlsx"; - HelyxFileChooser fc = new HelyxFileChooser(lastDir.getAbsolutePath()); - fc.setSelectionMode(SelectionMode.FILES_ONLY); - HelyxFileFilter filter = new HelyxFileFilter("PNG File (*.png)", PNG_EXTENSION); - File file = null; - ReturnValue retVal = fc.showSaveAsDialog(filter); + public static final HelyxFileFilter STL_FILTER = new HelyxFileFilter("STL File (*.stl)", STL_EXTENSION); + public static final HelyxFileFilter CSV_FILTER = new HelyxFileFilter("CSV File (*.csv)", CSV_EXTENSION); + public static final HelyxFileFilter XLS_FILTER = new HelyxFileFilter("Excel File (*.xls, *.xlsx)", EXCEL_EXTENSION_OLD, EXCEL_EXTENSION_NEW); - if (retVal.isApprove()) { - file = fc.getSelectedFile(); - String extension = FilenameUtils.getExtension(file.getAbsolutePath()); - - if (!extension.equalsIgnoreCase(PNG_EXTENSION)) { - file = new File(file.getParent(), file.getName() + "." + PNG_EXTENSION); - } + public static final String DEFAULT_SSH_PORT = "22"; - if (file.exists()) { - int confirm = JOptionPane.showConfirmDialog(UiUtil.getActiveWindow(), "File already exists. Overwrite?", "Warning", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE); - if (confirm == JOptionPane.NO_OPTION) { - return getPNGFile(); - } - } - PrefUtil.putFile(PrefUtil.LAST_OPEN_EXPORT_DIR, file.getParentFile()); - } - return file; - } + public static File getPNGFile() { + File lastDir = PrefUtil.getWorkDir(PrefUtil.LAST_OPEN_EXPORT_DIR); - public static File getExcelFile() { - File lastDir = PrefUtil.getWorkDir(PrefUtil.LAST_OPEN_EXPORT_DIR); - - HelyxFileChooser fc = new HelyxFileChooser(lastDir.getAbsolutePath()); - fc.setSelectionMode(SelectionMode.FILES_ONLY); - HelyxFileFilter filter = new HelyxFileFilter("Excel File (*.xls, *.xlsx)", EXCEL_EXTENSION_OLD, EXCEL_EXTENSION_NEW); - File file = null; - ReturnValue retVal = fc.showSaveAsDialog(filter); - - if (retVal.isApprove()) { - file = fc.getSelectedFile(); - String extension = FilenameUtils.getExtension(file.getAbsolutePath()); - - if (!extension.equalsIgnoreCase(EXCEL_EXTENSION_OLD) && !extension.equalsIgnoreCase(EXCEL_EXTENSION_NEW)) { - file = new File(file.getParent(), file.getName() + "." + EXCEL_EXTENSION_OLD); - } - - if (file.exists()) { - int confirm = JOptionPane.showConfirmDialog(UiUtil.getActiveWindow(), "File already exists. Overwrite?", "Warning", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE); - if (confirm == JOptionPane.NO_OPTION) { - return getPNGFile(); - } - } - PrefUtil.putFile(PrefUtil.LAST_OPEN_EXPORT_DIR, file.getParentFile()); - } - return file; - } + HelyxFileChooser fc = new HelyxFileChooser(lastDir.getAbsolutePath()); + fc.setSelectionMode(SelectionMode.FILES_ONLY); + HelyxFileFilter filter = new HelyxFileFilter("PNG File (*.png)", PNG_EXTENSION); + File file = null; + ReturnValue retVal = fc.showSaveAsDialog(filter); - public static File getCSVFile() { - File lastDir = PrefUtil.getWorkDir(PrefUtil.LAST_OPEN_EXPORT_DIR); - - HelyxFileChooser fc = new HelyxFileChooser(lastDir.getAbsolutePath()); - fc.setSelectionMode(SelectionMode.FILES_ONLY); - HelyxFileFilter filter = new HelyxFileFilter("CSV File (*.csv)", CSV_EXTENSION); - File file = null; - ReturnValue retVal = fc.showSaveAsDialog(filter); - - if (retVal.isApprove()) { - file = fc.getSelectedFile(); - String extension = FilenameUtils.getExtension(file.getAbsolutePath()); - - if (!extension.equalsIgnoreCase(CSV_EXTENSION)) { - file = new File(file.getParent(), file.getName() + "." + CSV_EXTENSION); - } - - if (file.exists()) { - int confirm = JOptionPane.showConfirmDialog(UiUtil.getActiveWindow(), "File already exists. Overwrite?", "Warning", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE); - if (confirm == JOptionPane.NO_OPTION) { - return getPNGFile(); - } - } - PrefUtil.putFile(PrefUtil.LAST_OPEN_EXPORT_DIR, file.getParentFile()); - } - return file; - } + if (retVal.isApprove()) { + file = fc.getSelectedFile(); + String extension = FilenameUtils.getExtension(file.getAbsolutePath()); + + if (!extension.equalsIgnoreCase(PNG_EXTENSION)) { + file = new File(file.getParent(), file.getName() + "." + PNG_EXTENSION); + } + + if (file.exists()) { + int confirm = JOptionPane.showConfirmDialog(UiUtil.getActiveWindow(), "File already exists. Overwrite?", "Warning", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE); + if (confirm == JOptionPane.NO_OPTION) { + return getPNGFile(); + } + } + PrefUtil.putFile(PrefUtil.LAST_OPEN_EXPORT_DIR, file.getParentFile()); + } + return file; + } + + public static File getExcelFile() { + File lastDir = PrefUtil.getWorkDir(PrefUtil.LAST_OPEN_EXPORT_DIR); + + HelyxFileChooser fc = new HelyxFileChooser(lastDir.getAbsolutePath()); + fc.setSelectionMode(SelectionMode.FILES_ONLY); + + File file = null; + ReturnValue retVal = fc.showSaveAsDialog(XLS_FILTER); + + if (retVal.isApprove()) { + file = fc.getSelectedFile(); + String extension = FilenameUtils.getExtension(file.getAbsolutePath()); + + if (!extension.equalsIgnoreCase(EXCEL_EXTENSION_OLD) && !extension.equalsIgnoreCase(EXCEL_EXTENSION_NEW)) { + file = new File(file.getParent(), file.getName() + "." + EXCEL_EXTENSION_OLD); + } + + if (file.exists()) { + int confirm = JOptionPane.showConfirmDialog(UiUtil.getActiveWindow(), "File already exists. Overwrite?", "Warning", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE); + if (confirm == JOptionPane.NO_OPTION) { + return getPNGFile(); + } + } + PrefUtil.putFile(PrefUtil.LAST_OPEN_EXPORT_DIR, file.getParentFile()); + } + return file; + } + + public static File getCSVFile() { + File lastDir = PrefUtil.getWorkDir(PrefUtil.LAST_OPEN_EXPORT_DIR); + + HelyxFileChooser fc = new HelyxFileChooser(lastDir.getAbsolutePath()); + fc.setSelectionMode(SelectionMode.FILES_ONLY); + File file = null; + ReturnValue retVal = fc.showSaveAsDialog(CSV_FILTER); + + if (retVal.isApprove()) { + file = fc.getSelectedFile(); + String extension = FilenameUtils.getExtension(file.getAbsolutePath()); + + if (!extension.equalsIgnoreCase(CSV_EXTENSION)) { + file = new File(file.getParent(), file.getName() + "." + CSV_EXTENSION); + } + + if (file.exists()) { + int confirm = JOptionPane.showConfirmDialog(UiUtil.getActiveWindow(), "File already exists. Overwrite?", "Warning", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE); + if (confirm == JOptionPane.NO_OPTION) { + return getPNGFile(); + } + } + PrefUtil.putFile(PrefUtil.LAST_OPEN_EXPORT_DIR, file.getParentFile()); + } + return file; + } } diff --git a/src/eu/engys/util/ui/FileFieldPanel.java b/src/eu/engys/util/ui/FileFieldPanel.java index 0bc2d08..bd07caa 100644 --- a/src/eu/engys/util/ui/FileFieldPanel.java +++ b/src/eu/engys/util/ui/FileFieldPanel.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.ui; import java.awt.BorderLayout; @@ -46,7 +45,6 @@ public class FileFieldPanel extends JPanel { textField = new FileTextField(); textField.setEditable(false); - textField.setFocusable(false); textField.setToolTipText(tooltip); textField.setPrompt(prompt); diff --git a/src/eu/engys/util/ui/JComboBoxWithItemsSupport.java b/src/eu/engys/util/ui/JComboBoxWithItemsSupport.java index 8609844..b81097a 100644 --- a/src/eu/engys/util/ui/JComboBoxWithItemsSupport.java +++ b/src/eu/engys/util/ui/JComboBoxWithItemsSupport.java @@ -1,62 +1,59 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.ui; import java.awt.Component; -import java.awt.event.ItemEvent; -import java.awt.event.ItemListener; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; -import javax.swing.DefaultComboBoxModel; import javax.swing.JComboBox; import javax.swing.JLabel; import javax.swing.JList; import javax.swing.ListCellRenderer; -public class JComboBoxWithItemsSupport extends JComboBox implements ItemListener { +public class JComboBoxWithItemsSupport extends JComboBox { - private Map itemFromKey = new HashMap(); + private Map itemFromKey = new HashMap<>(); private List disabledIndexes = new ArrayList(); + private boolean isDisabledIndex; public JComboBoxWithItemsSupport() { super(); - final ListCellRenderer renderer = getRenderer(); - setRenderer(new ListCellRenderer() { + final ListCellRenderer renderer = getRenderer(); + setRenderer(new ListCellRenderer() { @Override - public Component getListCellRendererComponent(JList list, String value, int index, boolean isSelected, boolean cellHasFocus) { + public Component getListCellRendererComponent(JList list, T value, int index, boolean isSelected, boolean cellHasFocus) { Component c = renderer.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); if (c instanceof JLabel) { JLabel label = (JLabel) c; - String key = value; - label.setText(itemFromKey.containsKey(key) ? itemFromKey.get(key) : key); + T key = value; + label.setText(key != null ? (itemFromKey.containsKey(key) ? itemFromKey.get(key) : key.toString()) : ""); if (disabledIndexes.contains(index)) { label.setFocusable(false); @@ -72,50 +69,81 @@ public class JComboBoxWithItemsSupport extends JComboBox implements Item return c; } }); - addItemListener(this); } - + @Override - public void itemStateChanged(ItemEvent e) { - if (e.getSource() instanceof JComboBox && e.getStateChange() == ItemEvent.SELECTED) { - JComboBox combo = (JComboBox) e.getSource(); - int index = combo.getSelectedIndex(); - if (disabledIndexes.contains(index)) { - combo.setSelectedIndex(-1); - } - } - } + public void setPopupVisible(boolean visible) { + if(!visible && isDisabledIndex){ + isDisabledIndex = false; + } else { + super.setPopupVisible(visible); + } + } @Override public void setSelectedIndex(int index) { if (disabledIndexes.contains(index)) { - super.setSelectedIndex(-1); + isDisabledIndex = true; + if(getSelectedIndex() == index){ + super.setSelectedIndex(-1); + } } else { super.setSelectedIndex(index); } } - public boolean isDisabledAt(int index){ - return disabledIndexes.contains(index); - } + @SuppressWarnings("unchecked") + @Override + public void setSelectedItem(Object item) { + if (disabledIndexes.contains(getIndexOf((T)item))) { + isDisabledIndex = true; + if(getSelectedItem() == item){ + super.setSelectedIndex(-1); + } + } else { + super.setSelectedItem(item); + } + } -// private void addDisabledIndex(int index) { -// disabledIndexes.add(index); -// } + public void addDisabledItem(T item) { + int itemIndex = getIndexOf(item); + disabledIndexes.add(itemIndex); + } - public void addDisabledItem(String item) { - int itemIndex = ((DefaultComboBoxModel) getModel()).getIndexOf(item); + public void addDisabledItem(int itemIndex) { disabledIndexes.add(itemIndex); } + private int getIndexOf(T item) { + for (int i = 0; i < getModel().getSize(); i++) { + if (getModel().getElementAt(i).equals(item)) { + return i; + } + } + return -1; + } + public void clearDisabledIndexes() { disabledIndexes.clear(); } + + public boolean isDisabled(T item){ + int itemIndex = getIndexOf(item); + return disabledIndexes.contains(itemIndex); + } - public void setLabels(String[] labels) { - for (int i = 0; i < getItemCount(); i++) { - itemFromKey.put(getItemAt(i), labels[i]); - } - } + @Override + public void addItem(T item) { + super.addItem(item); + } + + public void addItem(T item, String label) { + super.addItem(item); + itemFromKey.put(item, label); + } + + public void addLabel(T item, String label) { + itemFromKey.put(item, label); + } } diff --git a/src/eu/engys/util/ui/ListBuilder.java b/src/eu/engys/util/ui/ListBuilder.java index c357c40..4289ce7 100644 --- a/src/eu/engys/util/ui/ListBuilder.java +++ b/src/eu/engys/util/ui/ListBuilder.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.ui; public interface ListBuilder { diff --git a/src/eu/engys/util/ui/ListFieldPanel.java b/src/eu/engys/util/ui/ListFieldPanel.java index a84f701..7a27f29 100644 --- a/src/eu/engys/util/ui/ListFieldPanel.java +++ b/src/eu/engys/util/ui/ListFieldPanel.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.ui; import java.awt.BorderLayout; @@ -35,20 +34,30 @@ import javax.swing.JPanel; import eu.engys.util.ui.textfields.StringField; public class ListFieldPanel extends JPanel { + + private static final String NAME = "list.field.panel"; + + public static final String VALUES = "values"; + + public static final String FIELD = "field"; + public static final String BUTTON = "button"; + + private StringField textField; private JButton button; public ListFieldPanel(ListBuilder listBuilder) { super(new BorderLayout(4, 4)); - setName("list.field.panel"); + setName(NAME); + setOpaque(false); textField = new StringField(); - textField.setName("field"); + textField.setName(FIELD); textField.setColumns(20); textField.setEnabled(false); button = createButtonDoubleList(listBuilder); - button.setName("button"); + button.setName(BUTTON); add(textField, BorderLayout.CENTER); add(button, BorderLayout.EAST); } @@ -62,6 +71,7 @@ public class ListFieldPanel extends JPanel { @Override public void addPropertyChangeListener(PropertyChangeListener listener) { + super.addPropertyChangeListener(listener); if (textField != null) textField.addPropertyChangeListener(listener); } @@ -87,6 +97,7 @@ public class ListFieldPanel extends JPanel { sb.append(string + " "); } textField.setValue(sb.toString()); + firePropertyChange(VALUES, new String[0], values); } @Override diff --git a/src/eu/engys/util/ui/NoneSelectedButtonGroup.java b/src/eu/engys/util/ui/NoneSelectedButtonGroup.java index 17da3a7..72202d0 100644 --- a/src/eu/engys/util/ui/NoneSelectedButtonGroup.java +++ b/src/eu/engys/util/ui/NoneSelectedButtonGroup.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.ui; import javax.swing.ButtonGroup; @@ -37,4 +36,4 @@ public class NoneSelectedButtonGroup extends ButtonGroup { clearSelection(); } } - } + } \ No newline at end of file diff --git a/src/eu/engys/util/ui/RadioFieldPanel.java b/src/eu/engys/util/ui/RadioFieldPanel.java index 0634bbb..8456f0c 100644 --- a/src/eu/engys/util/ui/RadioFieldPanel.java +++ b/src/eu/engys/util/ui/RadioFieldPanel.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.ui; import java.awt.GridLayout; @@ -39,6 +38,7 @@ import javax.swing.JRadioButton; public class RadioFieldPanel extends JPanel implements ActionListener { public static final String PROPERTY_NAME = "value"; + private ButtonGroup bg = new ButtonGroup(); public RadioFieldPanel() { diff --git a/src/eu/engys/util/ui/ResourcesUtil.java b/src/eu/engys/util/ui/ResourcesUtil.java index c055067..2b5ff9a 100644 --- a/src/eu/engys/util/ui/ResourcesUtil.java +++ b/src/eu/engys/util/ui/ResourcesUtil.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.ui; diff --git a/src/eu/engys/util/ui/ScriptEditor.java b/src/eu/engys/util/ui/ScriptEditor.java index 44097c7..a23b96e 100644 --- a/src/eu/engys/util/ui/ScriptEditor.java +++ b/src/eu/engys/util/ui/ScriptEditor.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.ui; import java.awt.BorderLayout; @@ -65,303 +64,354 @@ import eu.engys.util.filechooser.util.SelectionMode; public class ScriptEditor { - public enum Syntax { - BASH, BATCH, PYTHON, JAVA, C - }; + public enum Syntax { + BASH, BATCH, PYTHON, JAVA, C + }; - public static final String BAT_COMMENT = "rem "; - public static final String SHELL_COMMENT = "# "; + public static final String BAT_COMMENT = "rem "; + public static final String SHELL_COMMENT = "# "; - private static ScriptEditor instance; + private static ScriptEditor instance; - private JDialog dialog; - private RSyntaxTextArea editor; - private DocumentListener documentListener; + private JDialog dialog; + private RSyntaxTextArea editor; + private DocumentListener documentListener; - private File file; - private List defaultScript; - private boolean modified; - private JButton okButton; + private File file; + private List defaultScript; + private boolean modified; + private JButton okButton; - public static ScriptEditor getInstance() { - if (instance == null) - instance = new ScriptEditor(); - return instance; - } + public static ScriptEditor getInstance() { + if (instance == null) + instance = new ScriptEditor(); + return instance; + } - private ScriptEditor() { - initEditor(); - initListeners(); - } + private ScriptEditor() { + initEditor(); + initListeners(); + } - private void initEditor() { - this.editor = new RSyntaxTextArea(); - // End of line is changed in save method - // This is used to split text in lines - editor.getDocument().putProperty(DefaultEditorKit.EndOfLineStringProperty, IOUtils.EOL); - editor.setCodeFoldingEnabled(true); - editor.setAntiAliasingEnabled(true); - editor.setBackground(new Color(240, 240, 240)); - editor.setName("codeEditor"); - } + private void initEditor() { + this.editor = new RSyntaxTextArea(); + // End of line is changed in save method + // This is used to split text in lines + editor.getDocument().putProperty(DefaultEditorKit.EndOfLineStringProperty, IOUtils.LNX_EOL); + editor.setCodeFoldingEnabled(true); + editor.setAntiAliasingEnabled(true); + editor.setBackground(new Color(240, 240, 240)); + editor.setName("codeEditor"); + } - private void initListeners() { - documentListener = new DocumentListener() { + private void initListeners() { + documentListener = new DocumentListener() { - @Override - public void removeUpdate(DocumentEvent e) { - documentModified(); - } + @Override + public void removeUpdate(DocumentEvent e) { + documentModified(); + } - @Override - public void insertUpdate(DocumentEvent e) { - documentModified(); - } + @Override + public void insertUpdate(DocumentEvent e) { + documentModified(); + } - @Override - public void changedUpdate(DocumentEvent e) { - documentModified(); - } - }; - } + @Override + public void changedUpdate(DocumentEvent e) { + documentModified(); + } + }; + } - private void documentModified() { - if (!modified) { - if (dialog != null) { - dialog.setTitle("*" + dialog.getTitle()); - this.modified = true; - } - } - } + private void documentModified() { + if (!modified) { + if (dialog != null) { + dialog.setTitle("*" + dialog.getTitle()); + this.modified = true; + } + } + } - public void show(Syntax syntax, Path scriptPath, List defaultScript) { - String style = ""; - switch (syntax) { - case BASH: - style = SyntaxConstants.SYNTAX_STYLE_UNIX_SHELL; - break; - case BATCH: - style = SyntaxConstants.SYNTAX_STYLE_WINDOWS_BATCH; - break; - case PYTHON: - style = SyntaxConstants.SYNTAX_STYLE_PYTHON; - break; - case C: - style = SyntaxConstants.SYNTAX_STYLE_C; - break; - case JAVA: - style = SyntaxConstants.SYNTAX_STYLE_JAVA; - break; + public void show(Syntax syntax, Path scriptPath, List defaultScript) { + String style = ""; + switch (syntax) { + case BASH: + style = SyntaxConstants.SYNTAX_STYLE_UNIX_SHELL; + break; + case BATCH: + style = SyntaxConstants.SYNTAX_STYLE_WINDOWS_BATCH; + break; + case PYTHON: + style = SyntaxConstants.SYNTAX_STYLE_PYTHON; + break; + case C: + style = SyntaxConstants.SYNTAX_STYLE_C; + break; + case JAVA: + style = SyntaxConstants.SYNTAX_STYLE_JAVA; + break; - default: - break; - } - editor.setSyntaxEditingStyle(style); - show(scriptPath, defaultScript); - } + default: + break; + } + editor.setSyntaxEditingStyle(style); + show(scriptPath, defaultScript); + } - public void show(Path scriptPath, List defaultScript) { - this.defaultScript = defaultScript; - this.file = scriptPath != null ? scriptPath.toFile() : null; - this.editor.setSyntaxEditingStyle(Util.isWindowsScriptStyle() ? SyntaxConstants.SYNTAX_STYLE_WINDOWS_BATCH : SyntaxConstants.SYNTAX_STYLE_UNIX_SHELL); - ExecUtil.invokeAndWait(new Runnable() { + public void show(Path scriptPath, List defaultScript) { + this.defaultScript = defaultScript; + this.file = scriptPath != null ? scriptPath.toFile() : null; + this.editor.setSyntaxEditingStyle(Util.isWindowsScriptStyle() ? SyntaxConstants.SYNTAX_STYLE_WINDOWS_BATCH : SyntaxConstants.SYNTAX_STYLE_UNIX_SHELL); + ExecUtil.invokeAndWait(new Runnable() { - @Override - public void run() { - initDialog(); - load(); - dialog.setVisible(true); - } - }); - } + @Override + public void run() { + initDialog(); + load(); + dialog.setVisible(true); + } + }); + } - private void initDialog() { - dialog = new JDialog(UiUtil.getActiveWindow(), ModalityType.MODELESS); - dialog.setName("script.editor.dialog"); - dialog.getContentPane().setLayout(new BorderLayout()); - dialog.getContentPane().add(createMainPanel(), BorderLayout.CENTER); - dialog.getContentPane().add(createButtonsPanel(), BorderLayout.SOUTH); - dialog.getContentPane().doLayout(); - dialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE); - dialog.addWindowListener(new WindowAdapter() { - @Override - public void windowClosing(WindowEvent e) { - closeDialog(); - } - }); + private void initDialog() { + dialog = new JDialog(UiUtil.getActiveWindow(), ModalityType.MODELESS); + dialog.setName("script.editor.dialog"); + dialog.getContentPane().setLayout(new BorderLayout()); + dialog.getContentPane().add(createMainPanel(), BorderLayout.CENTER); + dialog.getContentPane().add(createButtonsPanel(), BorderLayout.SOUTH); + dialog.getContentPane().doLayout(); + dialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE); + dialog.addWindowListener(new WindowAdapter() { + @Override + public void windowClosing(WindowEvent e) { + closeDialog(); + } + }); - dialog.setSize(800, 600); - dialog.setLocationRelativeTo(null); - dialog.getRootPane().setDefaultButton(okButton); - } + dialog.setSize(800, 600); + dialog.setLocationRelativeTo(null); + dialog.getRootPane().setDefaultButton(okButton); + } - private JPanel createMainPanel() { - RTextScrollPane sp = new RTextScrollPane(editor); - sp.setFoldIndicatorEnabled(true); - sp.setBorder(BorderFactory.createEmptyBorder()); - JPanel mainPanel = new JPanel(new BorderLayout()); - mainPanel.add(sp); - return mainPanel; - } + private JPanel createMainPanel() { + RTextScrollPane sp = new RTextScrollPane(editor); + sp.setFoldIndicatorEnabled(true); + sp.setBorder(BorderFactory.createEmptyBorder()); + JPanel mainPanel = new JPanel(new BorderLayout()); + mainPanel.add(sp); + return mainPanel; + } - private JPanel createButtonsPanel() { - JPanel panel = new JPanel(new GridLayout(1, 2)); - JPanel leftPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); - JButton resetButton = new JButton(new ResetAction()); - resetButton.setName("reset"); - leftPanel.add(resetButton); - JPanel rightPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); - - okButton = new JButton(new OKAction()); - okButton.setName("OK"); - rightPanel.add(okButton); - - JButton cancelButton = new JButton(new CancelAction()); - cancelButton.setName("cancel"); - rightPanel.add(cancelButton); + private JPanel createButtonsPanel() { + JButton importButton = new JButton(new ImportAction()); + importButton.setName("import"); - panel.add(leftPanel); - panel.add(rightPanel); + JButton resetButton = new JButton(new ResetAction()); + resetButton.setName("reset"); - JPanel buttonsPanel = new JPanel(new BorderLayout()); - buttonsPanel.add(new JSeparator(SwingConstants.HORIZONTAL), BorderLayout.NORTH); - buttonsPanel.add(panel, BorderLayout.CENTER); + JPanel leftPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); + leftPanel.add(importButton); + leftPanel.add(resetButton); - return buttonsPanel; - } + okButton = new JButton(new OKAction()); + okButton.setName("OK"); - private void closeDialog() { - dialog.setVisible(false); - dialog.dispose(); - dialog = null; - } + JButton cancelButton = new JButton(new CancelAction()); + cancelButton.setName("cancel"); - private void load() { - editor.getDocument().removeDocumentListener(documentListener); - if (file != null && file.exists()) { - try { - // IOUtils.loadFromFile(editor, file, null, Charset.defaultCharset()); - editor.setText(IOUtils.readStringFromFile(file)); - editor.setCaretPosition(0); - } catch (Exception e) { - e.printStackTrace(); - } - dialog.setTitle(file.getAbsolutePath()); - } else { - editor.setText(""); - dialog.setTitle("newScript"); - } - editor.getDocument().addDocumentListener(documentListener); - this.modified = false; - } + JPanel rightPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); + rightPanel.add(okButton); + rightPanel.add(cancelButton); - private void save() { - if (file != null && file.exists()) { - try { - IOUtils.writeStringToFile(file, editor.getText()); - } catch (Exception e) { - e.printStackTrace(); - } - dialog.setTitle(file.getAbsolutePath()); - } else { - saveAs(); - } - } + JPanel panel = new JPanel(new GridLayout(1, 2)); + panel.add(leftPanel); + panel.add(rightPanel); - private void saveAs() { - File lastDir = PrefUtil.getWorkDir(PrefUtil.WORK_DIR); - HelyxFileChooser fc = new HelyxFileChooser(lastDir.getAbsolutePath()); - fc.setParent(dialog); - fc.setSelectionMode(SelectionMode.FILES_ONLY); - ReturnValue retVal = fc.showSaveAsDialog(); - if (retVal.isApprove()) { - File file = fc.getSelectedFile(); - if (file != null) { - if (file.exists()) { - int answer = JOptionPane.showConfirmDialog(UiUtil.getActiveWindow(), "File already exists. Overwrite?", "File Overwrite", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE); - if (answer == JOptionPane.YES_OPTION) { - setFile(file); - save(); - } - } else { - try { - file.createNewFile(); - setFile(file); - save(); - } catch (IOException e) { - e.printStackTrace(); - } - } - PrefUtil.putFile(PrefUtil.WORK_DIR, file.getParentFile()); - } - } - } + JPanel buttonsPanel = new JPanel(new BorderLayout()); + buttonsPanel.add(new JSeparator(SwingConstants.HORIZONTAL), BorderLayout.NORTH); + buttonsPanel.add(panel, BorderLayout.CENTER); - private void setFile(File file) { - this.file = file; - } + return buttonsPanel; + } - private class OKAction extends AbstractAction { - public OKAction() { - super("OK"); - } + private void closeDialog() { + dialog.setVisible(false); + dialog.dispose(); + dialog = null; + } - @Override - public void actionPerformed(ActionEvent e) { - save(); - closeDialog(); - } - } + private void load() { + editor.getDocument().removeDocumentListener(documentListener); + if (file != null && file.exists()) { + try { + // IOUtils.loadFromFile(editor, file, null, Charset.defaultCharset()); + editor.setText(IOUtils.readStringFromFile(file)); + editor.setCaretPosition(0); + } catch (Exception e) { + e.printStackTrace(); + } + dialog.setTitle(file.getAbsolutePath()); + } else { + editor.setText(""); + dialog.setTitle("newScript"); + } + editor.getDocument().addDocumentListener(documentListener); + this.modified = false; + } - private class CancelAction extends AbstractAction { - public CancelAction() { - super("Cancel"); - } + private void save() { + if (file != null && file.exists()) { + try { + IOUtils.writeStringToFile(file, editor.getText()); + } catch (Exception e) { + e.printStackTrace(); + } + dialog.setTitle(file.getAbsolutePath()); + } else { + saveAs(); + } + } - @Override - public void actionPerformed(ActionEvent e) { - closeDialog(); - } + private void saveAs() { + File lastDir = PrefUtil.getWorkDir(PrefUtil.WORK_DIR); + HelyxFileChooser fc = new HelyxFileChooser(lastDir.getAbsolutePath()); + fc.setParent(dialog); + fc.setSelectionMode(SelectionMode.FILES_ONLY); + ReturnValue retVal = fc.showSaveAsDialog(); + if (retVal.isApprove()) { + File file = fc.getSelectedFile(); + if (file != null) { + if (file.exists()) { + int answer = JOptionPane.showConfirmDialog(UiUtil.getActiveWindow(), "File already exists. Overwrite?", "File Overwrite", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE); + if (answer == JOptionPane.YES_OPTION) { + setFile(file); + save(); + } + } else { + try { + file.createNewFile(); + setFile(file); + save(); + } catch (IOException e) { + e.printStackTrace(); + } + } + PrefUtil.putFile(PrefUtil.WORK_DIR, file.getParentFile()); + } + } + } - } + private void setFile(File file) { + this.file = file; + } - private class ResetAction extends AbstractAction { - public ResetAction() { - super("Reset"); - } + private class OKAction extends AbstractAction { + public OKAction() { + super("OK"); + } - @Override - public void actionPerformed(ActionEvent e) { - if (file != null) { - try { - File defaultFile = File.createTempFile("xxx", null); - IOUtils.writeLinesToFile(defaultFile, getDefaultFileLinesAndOldOnesCommented()); - editor.setText(IOUtils.readStringFromFile(defaultFile)); - editor.setCaretPosition(0); - FileUtils.deleteQuietly(defaultFile); - } catch (Exception ex) { - ex.printStackTrace(); - } - } - } + @Override + public void actionPerformed(ActionEvent e) { + save(); + closeDialog(); + } + } - private List getDefaultFileLinesAndOldOnesCommented() throws IOException { - List commentedLines = getCurrentFileCommentedLines(); + private class CancelAction extends AbstractAction { + public CancelAction() { + super("Cancel"); + } - List newLines = new ArrayList<>(); - newLines.addAll(defaultScript); - newLines.add(""); - newLines.addAll(commentedLines); - return newLines; - } + @Override + public void actionPerformed(ActionEvent e) { + closeDialog(); + } - private List getCurrentFileCommentedLines() throws IOException { - String comment = Util.isWindowsScriptStyle() ? BAT_COMMENT : SHELL_COMMENT; - List commentedLines = new ArrayList<>(); - for (String line : FileUtils.readLines(file)) { - commentedLines.add(new StringBuilder(comment).append(line).toString()); - } - return commentedLines; - } - } + } + + private class ImportAction extends AbstractAction { + public ImportAction() { + super("Import"); + } + + @Override + public void actionPerformed(ActionEvent e) { + HelyxFileChooser chooser = new HelyxFileChooser(); + chooser.setParent(dialog); + chooser.setSelectionMode(SelectionMode.FILES_ONLY); + + ReturnValue retVal = chooser.showOpenDialog(); + if (retVal.isApprove()) { + File defaultFile = null; + try { + defaultFile = File.createTempFile("xxx", null); + IOUtils.writeLinesToFile(defaultFile, getFileLinesAndOldOnesCommented(chooser.getSelectedFile())); + editor.setText(IOUtils.readStringFromFile(defaultFile)); + editor.setCaretPosition(0); + } catch (Exception ex) { + ex.printStackTrace(); + } finally { + if (defaultFile != null) { + FileUtils.deleteQuietly(defaultFile); + } + } + } + } + + private List getFileLinesAndOldOnesCommented(File file) throws IOException { + List commentedLines = getCurrentFileCommentedLines(); + + List newLines = new ArrayList<>(); + newLines.addAll(FileUtils.readLines(file)); + newLines.add(""); + newLines.addAll(commentedLines); + return newLines; + } + } + + private class ResetAction extends AbstractAction { + public ResetAction() { + super("Reset"); + } + + @Override + public void actionPerformed(ActionEvent e) { + if (file != null) { + File defaultFile = null; + try { + defaultFile = File.createTempFile("xxx", null); + IOUtils.writeLinesToFile(defaultFile, getDefaultFileLinesAndOldOnesCommented()); + editor.setText(IOUtils.readStringFromFile(defaultFile)); + editor.setCaretPosition(0); + } catch (Exception ex) { + ex.printStackTrace(); + } finally { + if (defaultFile != null) { + FileUtils.deleteQuietly(defaultFile); + } + } + } + } + + private List getDefaultFileLinesAndOldOnesCommented() throws IOException { + List commentedLines = getCurrentFileCommentedLines(); + + List newLines = new ArrayList<>(); + newLines.addAll(defaultScript); + newLines.add(""); + newLines.addAll(commentedLines); + return newLines; + } + + } + + private List getCurrentFileCommentedLines() throws IOException { + String comment = Util.isWindowsScriptStyle() ? BAT_COMMENT : SHELL_COMMENT; + List commentedLines = new ArrayList<>(); + for (String line : FileUtils.readLines(file)) { + commentedLines.add(new StringBuilder(comment).append(line).toString()); + } + return commentedLines; + } } diff --git a/src/eu/engys/util/ui/SelectionValueConfigurator.java b/src/eu/engys/util/ui/SelectionValueConfigurator.java index 3018f4b..f1f32c3 100644 --- a/src/eu/engys/util/ui/SelectionValueConfigurator.java +++ b/src/eu/engys/util/ui/SelectionValueConfigurator.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.ui; public interface SelectionValueConfigurator { diff --git a/src/eu/engys/util/ui/TableUtil.java b/src/eu/engys/util/ui/TableUtil.java index 885e16c..e567d2c 100644 --- a/src/eu/engys/util/ui/TableUtil.java +++ b/src/eu/engys/util/ui/TableUtil.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.ui; import javax.swing.JTable; diff --git a/src/eu/engys/util/ui/TitledBorderWithAction.java b/src/eu/engys/util/ui/TitledBorderWithAction.java new file mode 100644 index 0000000..db01e71 --- /dev/null +++ b/src/eu/engys/util/ui/TitledBorderWithAction.java @@ -0,0 +1,181 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.util.ui; + +import java.awt.Component; +import java.awt.Dimension; +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.Insets; +import java.awt.event.MouseEvent; +import java.awt.event.MouseListener; +import java.awt.event.MouseMotionListener; +import java.awt.geom.Rectangle2D; + +import javax.swing.ImageIcon; +import javax.swing.JComponent; +import javax.swing.JLabel; +import javax.swing.border.AbstractBorder; +import javax.swing.border.Border; +import javax.swing.border.TitledBorder; + +public class TitledBorderWithAction extends TitledBorder implements MouseListener, MouseMotionListener { + + public static final String EMPTY_TITLE = " "; + private static final ImageIcon ICON_BLACK = (ImageIcon) ResourcesUtil.getIcon("delete.icon"); + private static final ImageIcon ICON_RED = (ImageIcon) ResourcesUtil.getIcon("uncheck.icon"); + // private static final ImageIcon ICON = (ImageIcon) ResourcesUtil.getIcon("table.delete.row.icon"); + + private Runnable action; + private JComponent parent; + private int labelY; + private int labelH; + private int labelX; + private int labelW; + private CrossButton label; + + public TitledBorderWithAction(String text, JComponent parent, Runnable action) { + super(text); + this.parent = parent; + this.action = action; + parent.addMouseListener(this); + parent.addMouseMotionListener(this); + this.label = new CrossButton(); + } + + public TitledBorderWithAction(JComponent parent, Runnable action) { + this(EMPTY_TITLE, parent, action); + } + + @Override + public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) { + super.paintBorder(c, g, x, y, width, height); + + Border border = getBorder(); + String title = getTitle(); + if ((title != null) && !title.isEmpty()) { + int edge = (border instanceof TitledBorder) ? 0 : EDGE_SPACING; + Dimension size = label.getPreferredSize(); + Insets insets = getBorderInsets(border, c, new Insets(0, 0, 0, 0)); + + labelY = y; + labelH = size.height; + + insets.left = 0; + insets.right = 0; + insets.left += edge + TEXT_INSET_H; + insets.right += edge + TEXT_INSET_H; + + labelX = x; + labelW = width - insets.left - insets.right; + if (labelW > size.width) { + labelW = size.width; + } + + labelX += width - insets.right - labelW; + // labelY -= labelH - insets.top; + + g.translate(labelX, labelY); + label.setSize(labelW, labelH); + label.paint(g); + g.translate(-labelX, -labelY); + } + } + + private static Insets getBorderInsets(Border border, Component c, Insets insets) { + if (border == null) { + insets.set(0, 0, 0, 0); + } else if (border instanceof AbstractBorder) { + AbstractBorder ab = (AbstractBorder) border; + insets = ab.getBorderInsets(c, insets); + } else { + Insets i = border.getBorderInsets(c); + insets.set(i.top, i.left, i.bottom, i.right); + } + return insets; + } + + class CrossButton extends JLabel { + private boolean rollover; + + public CrossButton() { + super("M"); + } + + protected void paintComponent(Graphics g) { + Graphics2D g2 = (Graphics2D) g; + g2.drawImage(rollover ? ICON_RED.getImage() : ICON_BLACK.getImage(), 0, 0, null); + } + + public void setRollover(boolean rollover) { + this.rollover = rollover; + } + } + + @Override + public void mouseClicked(MouseEvent e) { + Rectangle2D rect = new Rectangle2D.Double(labelX, labelY, labelW, labelH); + if (rect.contains(e.getX(), e.getY())) { + action.run(); + } + } + + @Override + public void mousePressed(MouseEvent e) { + } + + @Override + public void mouseReleased(MouseEvent e) { + } + + @Override + public void mouseEntered(MouseEvent e) { + } + + @Override + public void mouseExited(MouseEvent e) { + checkCross(e); + } + + @Override + public void mouseDragged(MouseEvent e) { + } + + @Override + public void mouseMoved(MouseEvent e) { + checkCross(e); + } + + private void checkCross(MouseEvent e) { + Rectangle2D rect = new Rectangle2D.Double(labelX, labelY, labelW, labelH); + if (rect.contains(e.getX(), e.getY())) { + label.setRollover(true); + } else { + label.setRollover(false); + } + parent.repaint(); + } + +} diff --git a/src/eu/engys/util/ui/TreeUtil.java b/src/eu/engys/util/ui/TreeUtil.java index be8cc6f..3858a12 100644 --- a/src/eu/engys/util/ui/TreeUtil.java +++ b/src/eu/engys/util/ui/TreeUtil.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.ui; diff --git a/src/eu/engys/util/ui/UiUtil.java b/src/eu/engys/util/ui/UiUtil.java index 73acd63..adf1834 100644 --- a/src/eu/engys/util/ui/UiUtil.java +++ b/src/eu/engys/util/ui/UiUtil.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.ui; import java.awt.BorderLayout; @@ -30,12 +29,15 @@ import java.awt.Component; import java.awt.Container; import java.awt.Dimension; import java.awt.FlowLayout; +import java.awt.Font; import java.awt.FontMetrics; import java.awt.GraphicsConfiguration; import java.awt.GraphicsDevice; import java.awt.GraphicsEnvironment; import java.awt.Insets; import java.awt.LayoutManager; +import java.awt.MouseInfo; +import java.awt.Point; import java.awt.Rectangle; import java.awt.Toolkit; import java.awt.Window; @@ -43,6 +45,7 @@ import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.ItemEvent; import java.awt.event.ItemListener; +import java.awt.font.TextAttribute; import java.io.File; import java.lang.Thread.UncaughtExceptionHandler; import java.nio.file.Paths; @@ -75,6 +78,7 @@ import javax.swing.JMenuItem; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JPopupMenu; +import javax.swing.JSplitPane; import javax.swing.JTabbedPane; import javax.swing.JToggleButton; import javax.swing.JToolBar; @@ -102,14 +106,44 @@ import eu.engys.util.connection.SshParameters; import eu.engys.util.connection.SshUtils; import eu.engys.util.progress.ProgressMonitor; -/** Static convenience methods for GUIs which eliminate code duplication. */ public final class UiUtil { + public static String DIALOG_OK_LABEL = "OK"; + public static String DIALOG_CANCEL_LABEL = "Cancel"; + public static String RESET_BUTTON_LABEL = "Reset"; + public static String ADD_BUTTON_LABEL = "Add"; + public static String REMOVE_BUTTON_LABEL = "Remove"; + public static String EDIT_BUTTON_LABEL = "Edit"; + public static final String NONE_LABEL = "None"; + + public static final String ADD_ROW_BUTTON_NAME = "add.row.button"; + public static final String REM_ROW_BUTTON_NAME = "rem.row.button"; + + public static final Dimension LABEL_DIMENSION = new JLabel("M").getPreferredSize(); + + /* + * So tests can run on low resolution monitors too + */ + public static final Dimension TEST_FRAME_SIZE = new Dimension(1000, 800); + + /** + * First we check for an active window + * (scenario: the progress monitor is up, and I want to get it instead of the main application frame) + * + * If no active windows are found we return the first showing window + * (scenario: the application frame is up but it is not active because Im working on another software, + * if an optionpane is shown I assign the first showing window as a parent instead) + */ public static Window getActiveWindow() { - for (Window window : Window.getWindows()) { + Window[] windows = Window.getWindows(); + for (Window window : windows) { if (window.isShowing() && window.isActive()) return (Window) window; } + for (Window window : windows) { + if (window.isShowing()) + return (Window) window; + } return null; } @@ -140,6 +174,59 @@ public final class UiUtil { } } + /** + * This method collapses the bottom component of a splitpane + */ + public static void collapseSplitPane(JSplitPane splitPane) { + splitPane.setBottomComponent(new JLabel()); + splitPane.setDividerLocation(Integer.MAX_VALUE); + splitPane.setResizeWeight(1); + splitPane.setDividerSize(0); + } + + /** + * This method shows the bottom if it was previosly hidden + */ + public static void expandSplitPane(JSplitPane splitPane, JComponent bottomComponent, double splitLocationRatio, int bottomComponentHeight) { + if (splitPane.getBottomComponent() instanceof JLabel) { + splitPane.setBottomComponent(bottomComponent); + } + if (splitPane.getResizeWeight() == 1) { + splitPane.setDividerLocation(splitPane.getHeight() - bottomComponentHeight); + splitPane.setResizeWeight(splitLocationRatio); + splitPane.setDividerSize(new JSplitPane().getDividerSize()); + } + } + + public static boolean isCollapsed(JSplitPane splitPane) { + boolean check1 = splitPane.getBottomComponent() instanceof JLabel; + boolean check2 = splitPane.getDividerSize() == 0; + boolean check3 = splitPane.getResizeWeight() == 1; + return check1 && check2 && check3; + } + + public static void showInfoPopup(Component parent, String text) { + try { + JPopupMenu popup = new JPopupMenu(); + popup.add(new JMenuItem(text)); + Point location = MouseInfo.getPointerInfo().getLocation(); + SwingUtilities.convertPointFromScreen(location, parent); + popup.show(parent, location.x, (location.y / 2)); + } catch (Exception ee) { + // convertPointFromScreen can throw a Nullpointer exception + // no need to do anything + } + } + + public static JLabel getLabelSeparator() { + return new JLabel() { + @Override + public Dimension getPreferredSize() { + return ComponentsFactory.intField().getPreferredSize(); + } + }; + } + public static void showDocumentationNotLoadedWarning(boolean emptyDocumentation) { if (emptyDocumentation) { JOptionPane.showMessageDialog(UiUtil.getActiveWindow(), "Missing file.", ApplicationInfo.getName() + " Documentation error", JOptionPane.ERROR_MESSAGE); @@ -147,7 +234,7 @@ public final class UiUtil { JOptionPane.showMessageDialog(UiUtil.getActiveWindow(), "Ambiguous file name.", ApplicationInfo.getName() + " Documentation error", JOptionPane.ERROR_MESSAGE); } } - + public static void showEnvironmentNotLoadedWarning(String application) { String message = String.format("%s cannot be launched because:\n\t1) %s is not installed on your system.\n\t2) The path to the executable does not exists.\n\t3) The path to the executable is broken.\nPlease, enter %s executable path under: Edit > Preferences.", application, application, application); JOptionPane.showMessageDialog(UiUtil.getActiveWindow(), message, application + " executable error", JOptionPane.WARNING_MESSAGE); @@ -168,31 +255,11 @@ public final class UiUtil { JOptionPane.showMessageDialog(UiUtil.getActiveWindow(), message, "Demo", JOptionPane.INFORMATION_MESSAGE); } - public static void show(String title, Component panel, int w, int h) { - UiUtil.centerAndShow(defaultTestFrame(title, panel, w, h)); - } - - public static void show(String title, Component panel) { - UiUtil.centerAndShow(defaultTestFrame(title, panel)); - } - - public static JFrame defaultTestFrame(String title, Component panel, int w, int h) { - JFrame frame = defaultTestFrame(title, panel); - frame.setSize(w, h); - frame.setPreferredSize(new Dimension(w, h)); - return frame; - } - public static JFrame defaultTestFrame(String title, Component panel) { - JFrame frame = defaultEmptyTestFrame(title); - frame.getContentPane().add(panel, BorderLayout.CENTER); - return frame; - } - - public static JFrame defaultEmptyTestFrame(String title) { JFrame frame = new JFrame(title); frame.getContentPane().setLayout(new BorderLayout()); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + frame.getContentPane().add(panel, BorderLayout.CENTER); return frame; } @@ -213,19 +280,12 @@ public final class UiUtil { public static void centerAndShow(Window aWindow) { aWindow.pack(); - /* - * If called from outside the event dispatch thread (as is the case upon startup, in the launch thread), - * then in principle this code is not thread-safe: once pack has been called, the component is realized, - * and (most) further work on the component should take place in the event-dispatch thread. - * - * In practice, it is exceedingly unlikely that this will lead to an error, since invisible components cannot receive events. - */ center(aWindow); aWindow.setVisible(true); } public static Border getStandardBorder() { - return BorderFactory.createEmptyBorder(UiUtil.STANDARD_BORDER, UiUtil.STANDARD_BORDER, UiUtil.STANDARD_BORDER, UiUtil.STANDARD_BORDER); + return BorderFactory.createEmptyBorder(STANDARD_BORDER, STANDARD_BORDER, STANDARD_BORDER, STANDARD_BORDER); } public static JComponent getCommandRow(JComponent... aButtons) { @@ -270,28 +330,26 @@ public final class UiUtil { return panel; } - public static JComponent getCommandColumnToolbar(java.util.List aButtons) { - equalizeSizes(aButtons); - JToolBar panel = getToolbar("command.column.toolbar"); - LayoutManager layout = new BoxLayout(panel, BoxLayout.Y_AXIS); - panel.setLayout(layout); - panel.setOpaque(false); - panel.setFloatable(false); - panel.setBorder(BorderFactory.createEmptyBorder(0, UiUtil.TWO_SPACES, 0, 0)); + public static JComponent getCommandColumnToolbar(List buttons) { + equalizeSizes(buttons); + JToolBar toolbar = getToolbarWrapped("command.column.toolbar"); + LayoutManager layout = new BoxLayout(toolbar, BoxLayout.Y_AXIS); + toolbar.setLayout(layout); + toolbar.setBorder(BorderFactory.createEmptyBorder(0, UiUtil.TWO_SPACES, 0, 0)); // (no for-each is used here, because of the 'not-yet-last' check) - Iterator buttonsIter = aButtons.iterator(); + Iterator buttonsIter = buttons.iterator(); while (buttonsIter.hasNext()) { AbstractButton next = (AbstractButton) buttonsIter.next(); next.setAlignmentX(Component.LEFT_ALIGNMENT); next.setHorizontalAlignment(SwingConstants.LEFT); - panel.add(next); + toolbar.add(next); if (buttonsIter.hasNext()) { - panel.add(Box.createVerticalStrut(UiUtil.ONE_SPACE)); + toolbar.add(Box.createVerticalStrut(UiUtil.ONE_SPACE)); } } - panel.add(Box.createVerticalGlue()); - return panel; + toolbar.add(Box.createVerticalGlue()); + return toolbar; } public static JMenuItem createMenuItem(Action a) { @@ -318,10 +376,10 @@ public final class UiUtil { b.setText(((text != null && text.equals("MISSING")) ? null : text)); b.setIcon(icon); b.setToolTipText(desc); - + return b; } - + public static AbstractButton createToolBarIconButton(Action a) { return _createToolBarButton(a, false); } @@ -343,12 +401,11 @@ public final class UiUtil { return null; } }; - b.setName(text != null ? text : desc); + b.setName((text == null || text.isEmpty()) ? desc : text); b.setText(showLabel ? ((text != null && text.equals("MISSING")) ? null : text) : null); b.setIcon(icon); b.setToolTipText(desc); // b.setEnabled(a.isEnabled()); - b.setFocusable(false); return b; } @@ -363,7 +420,6 @@ public final class UiUtil { }; button.setName(name); button.setToolTipText(tooltip); - button.setFocusable(false); final JPopupMenu popup = new JPopupMenu(); for (Action action : actions) { @@ -394,16 +450,6 @@ public final class UiUtil { return bar; } - public static void clearToolbar(JToolBar toolbar) { - for (Component c : toolbar.getComponents()) { - if (c instanceof AbstractButton) { - ((AbstractButton) c).setSelected(false); - } else if (c instanceof JComboBox) { - ((JComboBox) c).setSelectedIndex(-1); - } - } - } - public static ButtonBar createToolBarToggleButtonBar(Action... actions) { ButtonGroup viewGroup = new ButtonGroup(); ButtonBar bar = new ButtonBar(); @@ -445,7 +491,6 @@ public final class UiUtil { b.setRolloverSelectedIcon(sel_icon); b.setSelectedIcon(sel_icon); b.setEnabled(a.isEnabled()); - b.setFocusable(false); return b; } @@ -461,7 +506,6 @@ public final class UiUtil { b.setHorizontalTextPosition(SwingConstants.RIGHT); // b.setVerticalTextPosition(3); b.setName((String) a.getValue(Action.NAME)); - b.setFocusable(false); return b; } @@ -482,7 +526,6 @@ public final class UiUtil { b.setText(""); b.setIcon(icon); b.setToolTipText(text); - b.setFocusable(false); group.add(b); return b; } @@ -565,6 +608,7 @@ public final class UiUtil { private static Action getPrototype(String actionName) { return new AbstractAction(actionName) { + @Override public void actionPerformed(ActionEvent arg0) { } @@ -597,7 +641,7 @@ public final class UiUtil { } - public static void equalizeSizes(java.util.List aComponents) { + public static void equalizeSizes(List aComponents) { Dimension targetSize = new Dimension(0, 0); for (JComponent comp : aComponents) { Dimension compSize = comp.getPreferredSize(); @@ -655,7 +699,7 @@ public final class UiUtil { containers.remove(container); } } - + public static void disable(Container container) { List components = getDescendantsOfType(JComponent.class, container, true); List enabledComponents = new ArrayList(); @@ -678,7 +722,6 @@ public final class UiUtil { } } } - public static void expandAll(JTree tree, boolean expand) { TreeNode root = (TreeNode) tree.getModel().getRoot(); @@ -736,16 +779,39 @@ public final class UiUtil { } public static JToolBar getToolbar(String name) { - JToolBar toolbar = new JToolBar(); - toolbar.setLayout(new WrappedFlowLayout(FlowLayout.LEFT, 0, 0)); + return getToolbar(name, JToolBar.HORIZONTAL); + } + + public static JToolBar getToolbar(String name, int orientation) { + JToolBar toolbar = new JToolBar(orientation); + toolbar.setName(name); toolbar.putClientProperty("Synthetica.toolBar.buttons.paintBorder", Boolean.TRUE); toolbar.putClientProperty("Synthetica.opaque", Boolean.FALSE); - toolbar.setName(name); toolbar.setFloatable(false); - toolbar.setRollover(false); toolbar.setOpaque(false); toolbar.setBorder(BorderFactory.createEmptyBorder()); + return toolbar; + } + public static JToolBar getToolbarWrapped() { + return getToolbarWrapped("", JToolBar.HORIZONTAL); + } + + public static JToolBar getToolbarWrapped(String name) { + return getToolbarWrapped(name, JToolBar.HORIZONTAL); + } + + public static JToolBar getToolbarWrapped(String name, int orientation) { + JToolBar toolbar = getToolbar(name, orientation); + toolbar.setLayout(new WrappedFlowLayout(FlowLayout.LEFT, 0, 0)); + return toolbar; + } + + public static JToolBar createButtonToolbarStyle(AbstractButton button) { + JToolBar toolbar = UiUtil.getToolbar(""); + toolbar.setBorder(BorderFactory.createEmptyBorder()); + toolbar.add(button); + // toolbar.add(Box.createGlue()); return toolbar; } @@ -811,11 +877,6 @@ public final class UiUtil { if (GraphicsEnvironment.isHeadless()) { } else { e.printStackTrace(); -// StringOutputStream stream = new StringOutputStream(); -// e.printStackTrace(new PrintStream(stream)); -// String msg = stream.toString(); -// System.err.println(msg); -// JOptionPane.showMessageDialog(UiUtil.getActiveWindow(), msg, "An error occurred", JOptionPane.ERROR_MESSAGE); } } }); @@ -880,7 +941,17 @@ public final class UiUtil { } catch (Exception e) { } - + } + + @SuppressWarnings("unchecked") + public static JButton createURLOpenerButton(AbstractAction action){ + JButton aButton = new JButton(action); + Font origFont = aButton.getFont(); + Map attributes = origFont.getAttributes(); + attributes.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON); + aButton.setFont(aButton.getFont().deriveFont(attributes)); + aButton.setOpaque(false); + return aButton; } public static final int ONE_SPACE = 5; diff --git a/src/eu/engys/util/ui/ViewAction.java b/src/eu/engys/util/ui/ViewAction.java index 65362ce..a19aa86 100644 --- a/src/eu/engys/util/ui/ViewAction.java +++ b/src/eu/engys/util/ui/ViewAction.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.ui; diff --git a/src/eu/engys/util/ui/WrappedFlowLayout.java b/src/eu/engys/util/ui/WrappedFlowLayout.java index 2350477..d5c9b79 100644 --- a/src/eu/engys/util/ui/WrappedFlowLayout.java +++ b/src/eu/engys/util/ui/WrappedFlowLayout.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.ui; import java.awt.Component; @@ -128,4 +127,4 @@ public class WrappedFlowLayout extends FlowLayout { } } -} +} \ No newline at end of file diff --git a/src/eu/engys/util/ui/builder/GroupController.java b/src/eu/engys/util/ui/builder/GroupController.java index 682020d..9dbc2bc 100644 --- a/src/eu/engys/util/ui/builder/GroupController.java +++ b/src/eu/engys/util/ui/builder/GroupController.java @@ -1,51 +1,53 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.ui.builder; import java.awt.event.ActionListener; +import java.awt.event.ItemListener; +import java.util.List; import javax.swing.JComponent; public interface GroupController { - void addActionListener(ActionListener pop); + + void addActionListener(ActionListener pop); + + void addItemListener(ItemListener pop); String getSelectedKey(); - void setSelectedIndex(int i); - - void setSelectedItem(String groupName); - void setSelectedKey(String key); void addGroup(String groupKey, String groupName); void addChildController(GroupController controller); - GroupController getChildController(String selectedKey); + GroupController getChildController(String seleTctedKey); JComponent getComponent(); + + List getKeys(); } diff --git a/src/eu/engys/util/ui/builder/HideController.java b/src/eu/engys/util/ui/builder/HideController.java index a5fbcb9..d7ef58d 100644 --- a/src/eu/engys/util/ui/builder/HideController.java +++ b/src/eu/engys/util/ui/builder/HideController.java @@ -1,33 +1,33 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.ui.builder; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.awt.event.ItemListener; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -36,27 +36,29 @@ import java.util.Map; import javax.swing.JComponent; import javax.swing.JLabel; - public class HideController implements GroupController { private ActionListener action; private JLabel label = new JLabel(); - private List groups = new ArrayList(); - private List keys = new ArrayList(); - private Map childControllers = new HashMap(); + private List groups = new ArrayList<>(); + private List keys = new ArrayList<>(); + private Map childControllers = new HashMap<>(); private String selectedKey = null; - @Override public void setSelectedIndex(int i) { setSelectedItem(groups.get(i)); } - @Override +// @Override public void setSelectedItem(String item) { selectedKey = item != null ? keys.get(groups.indexOf(item)) : null; action.actionPerformed(new ActionEvent(this, ActionEvent.ACTION_PERFORMED, selectedKey)); label.setText(item); } + + @Override + public void addItemListener(ItemListener pop) { + } @Override public void setSelectedKey(String key) { @@ -98,4 +100,8 @@ public class HideController implements GroupController { this.action = showHideAction; } + @Override + public List getKeys() { + return keys; + } } diff --git a/src/eu/engys/util/ui/builder/JCheckBoxController.java b/src/eu/engys/util/ui/builder/JCheckBoxController.java index 214789f..e50beb1 100644 --- a/src/eu/engys/util/ui/builder/JCheckBoxController.java +++ b/src/eu/engys/util/ui/builder/JCheckBoxController.java @@ -1,39 +1,39 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.ui.builder; import java.awt.Color; import java.awt.Font; import java.awt.event.ActionListener; +import java.awt.event.ItemListener; +import java.util.Arrays; +import java.util.List; import javax.swing.JCheckBox; import javax.swing.JComponent; - public class JCheckBoxController extends JCheckBox implements GroupController { private String selectedKey; @@ -42,7 +42,6 @@ public class JCheckBoxController extends JCheckBox implements GroupController { super(name); setName(name); setOpaque(false); - setFocusable(false); } @Override @@ -50,6 +49,11 @@ public class JCheckBoxController extends JCheckBox implements GroupController { super.addActionListener(action); } + @Override + public void addItemListener(ItemListener l) { + super.addItemListener(l); + } + @Override public void addGroup(String groupKey, String groupName) { this.selectedKey = groupKey; @@ -60,16 +64,6 @@ public class JCheckBoxController extends JCheckBox implements GroupController { return this; } - @Override - public void setSelectedIndex(int i) { - super.doClick(); - } - - @Override - public void setSelectedItem(String groupName) { - super.doClick(); - } - @Override public void setSelectedKey(String key) { super.doClick(); @@ -100,4 +94,9 @@ public class JCheckBoxController extends JCheckBox implements GroupController { // if (isEnabled()) return Color.BLUE; return super.getForeground(); } + + @Override + public List getKeys() { + return Arrays.asList("key"); + } } diff --git a/src/eu/engys/util/ui/builder/JComboBoxController.java b/src/eu/engys/util/ui/builder/JComboBoxController.java index be9608e..f71d43d 100644 --- a/src/eu/engys/util/ui/builder/JComboBoxController.java +++ b/src/eu/engys/util/ui/builder/JComboBoxController.java @@ -1,32 +1,32 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.ui.builder; import java.awt.event.ActionListener; +import java.awt.event.ItemListener; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -36,7 +36,7 @@ import javax.swing.JComponent; import eu.engys.util.ui.JComboBoxWithItemsSupport; -public class JComboBoxController extends JComboBoxWithItemsSupport implements GroupController { +public class JComboBoxController extends JComboBoxWithItemsSupport implements GroupController { private List keys = new ArrayList(); private Map childControllers = new HashMap(); @@ -49,6 +49,11 @@ public class JComboBoxController extends JComboBoxWithItemsSupport implements Gr public void addActionListener(ActionListener action) { super.addActionListener(action); } + + @Override + public void addItemListener(ItemListener aListener) { + super.addItemListener(aListener); + } @Override public void addGroup(String groupKey, String groupName) { @@ -73,10 +78,10 @@ public class JComboBoxController extends JComboBoxWithItemsSupport implements Gr return this; } - @Override - public void setSelectedItem(String groupName) { - super.setSelectedItem(groupName); - } +// @Override +// public void setSelectedItem(String groupName) { +// super.setSelectedItem(groupName); +// } @Override public void setSelectedKey(String key) { @@ -92,4 +97,9 @@ public class JComboBoxController extends JComboBoxWithItemsSupport implements Gr public boolean containsKey(String key) { return keys.contains(key); } + + @Override + public List getKeys() { + return keys; + } } diff --git a/src/eu/engys/util/ui/builder/PanelBuilder.java b/src/eu/engys/util/ui/builder/PanelBuilder.java index e707729..158e049 100644 --- a/src/eu/engys/util/ui/builder/PanelBuilder.java +++ b/src/eu/engys/util/ui/builder/PanelBuilder.java @@ -1,54 +1,52 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.ui.builder; import java.awt.Font; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Stack; +import javax.swing.BorderFactory; import javax.swing.JComponent; import javax.swing.JLabel; import javax.swing.JPanel; +import eu.engys.util.TooltipUtils; +import eu.engys.util.ui.UiUtil; import net.java.dev.designgridlayout.DesignGridLayout; import net.java.dev.designgridlayout.INonGridRow; import net.java.dev.designgridlayout.IRowCreator; import net.java.dev.designgridlayout.ISpannableGridRow; import net.java.dev.designgridlayout.RowGroup; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import eu.engys.util.TooltipUtils; -import eu.engys.util.ui.UiUtil; - /** *
  * startChoice("Autore");
@@ -105,22 +103,17 @@ import eu.engys.util.ui.UiUtil;
  * endGroup();//marvel
  * endChoice();//autore
  * 
- * */ public class PanelBuilder { - private static final Logger logger = LoggerFactory.getLogger(PanelBuilder.class); - - private DesignGridLayout layout; private final JPanel parent; + protected Stack groups = new Stack<>(); + protected Stack controllers = new Stack<>(); + protected Stack actions = new Stack<>(); + private DesignGridLayout layout; private int level = 0; private int indent = 0; - - protected Stack groups = new Stack(); - protected Stack controllers = new Stack(); - protected Stack actions = new Stack(); - - private HashMap hideables = new HashMap(); + private HashMap hideables = new HashMap<>(); private String prefix = ""; @@ -139,8 +132,13 @@ public class PanelBuilder { this.parent.setName(name); } + public void update() { + parent.revalidate(); + parent.repaint(); + } + public JPanel getPanel() { - return (JPanel) parent; + return parent; } public PanelBuilder removeMargins() { @@ -148,6 +146,21 @@ public class PanelBuilder { return this; } + public PanelBuilder withTitle(String title) { + parent.setBorder(BorderFactory.createTitledBorder(title)); + return this; + } + + public PanelBuilder withName(String name) { + parent.setName(name); + return this; + } + + public PanelBuilder nonOpaque() { + parent.setOpaque(false); + return this; + } + public PanelBuilder margins(double top, double left, double bottom, double right) { layout.margins(top, left, bottom, right); return this; @@ -195,6 +208,10 @@ public class PanelBuilder { newLeftRow().add(c).fill(); } + public void emptyRow() { + newLeftRow().add(new JLabel(" ")).fill(); + } + public void addSeparator(String string) { addSeparator(boldlabel(string)); } @@ -240,11 +257,15 @@ public class PanelBuilder { public JComponent addComponent(String label, JComponent c) { newGridRow(label, null).add(c); - c.setName(prefix + label); + if (prefix.isEmpty() && label.isEmpty() && c.getName() != null) { + // if a name already in place do nothing + } else { + c.setName(prefix + label); + } return c; } - public JComponent addComponent(String label, JComponent c, String tooltip) { + public JComponent addComponent(String label, String tooltip, JComponent c) { newGridRow(label, tooltip).add(c); c.setName(prefix + label); c.setToolTipText(TooltipUtils.format(tooltip)); @@ -258,7 +279,7 @@ public class PanelBuilder { } public JComponent addComponentAndSpan(String label, JComponent c, int span) { - newGridRow(label, null).add(c,span).spanRow(); + newGridRow(label, null).add(c, span).spanRow(); c.setName(prefix + label); return c; } @@ -284,9 +305,24 @@ public class PanelBuilder { return c; } - public JComponent[] addComponent(JLabel label, JComponent... c) { - newGridRow(label, null).add(c); - setNames(prefix + label.getName()); + public JComponent[] addComponent2Columns(String l1, JComponent c1, String l2, JComponent c2) { + newGridRow(l1, null).add(c1).grid(label(l2)).add(c2); + c1.setName(l1); + c2.setName(l2); + return new JComponent[] { c1, c2 }; + } + + public JComponent[] addComponent3Columns(String l1, JComponent c1, String l2, JComponent c2, String l3, JComponent c3) { + newGridRow(l1, null).add(c1).grid(label(l2)).add(c2).grid(label(l3)).add(c3); + c1.setName(l1); + c2.setName(l2); + c3.setName(l3); + return new JComponent[] { c1, c2, c3 }; + } + + public JComponent[] addComponent(String label, String tooltip, JComponent... c) { + newGridRow(label, tooltip).add(c); + setNames(label, c); return c; } @@ -320,10 +356,14 @@ public class PanelBuilder { private void setNames(String label, JComponent... c) { if (c.length == 1) { - c[0].setName(prefix + label); + if (c[0].getName() == null) { + c[0].setName(prefix + label); + } } else { for (int i = 0; i < c.length; i++) { - c[i].setName(prefix + label + "." + i); + if (c[i].getName() == null) { + c[i].setName(prefix + label + "." + i); + } } } } @@ -353,37 +393,44 @@ public class PanelBuilder { layout.emptyRow(); } - public GroupController startChoice(String choiceName, GroupController groupController) { - - ShowHideAction action = new ShowHideAction(); - - actions.push(action); - controllers.push(groupController); - - addComponent(choiceName, controllers.peek().getComponent()); - - level++; - - return groupController; - } - public GroupController startChoice(String choiceName) { return startChoice(choiceName, (String) null); } public GroupController startChoice(String choiceName, String tooltip) { - ShowHideAction action = new ShowHideAction(); + return startChoice(choiceName, new JComboBoxController(), tooltip); + } - GroupController comboBox = comboBox(); + public GroupController startChoice(String choiceName, GroupController comboBox) { + return startChoice(choiceName, comboBox, (String) null); + } + + public GroupController startChoiceNoLabel(String name, GroupController comboBox) { + ShowHideAction action = new ShowHideAction(); actions.push(action); controllers.push(comboBox); - addComponent(choiceName, controllers.peek().getComponent()); + JComponent c = controllers.peek().getComponent(); + c.setName(name); + addFill(c); level++; - ((JComboBoxController) comboBox).setToolTipText(TooltipUtils.format(tooltip)); + return comboBox; + } + + public GroupController startChoice(String choiceName, GroupController comboBox, String tooltip) { + ShowHideAction action = new ShowHideAction(); + + actions.push(action); + controllers.push(comboBox); + + addComponent(choiceName, tooltip, controllers.peek().getComponent()); + + level++; + + ((JComponent) comboBox).setToolTipText(TooltipUtils.format(tooltip)); return comboBox; } @@ -392,7 +439,7 @@ public class PanelBuilder { level--; GroupController combo = controllers.pop(); combo.addActionListener(actions.pop()); - combo.setSelectedIndex(0); + combo.setSelectedKey(combo.getKeys().get(0)); } public void startHidable(String key) { @@ -411,7 +458,7 @@ public class PanelBuilder { // indent--; GroupController check = controllers.pop(); check.addActionListener(actions.pop()); - check.setSelectedIndex(0); + check.setSelectedKey(check.getKeys().get(0)); } public void setShowing(String hideable, String group) { @@ -466,6 +513,23 @@ public class PanelBuilder { return checkBox; } + public GroupController startCheck2(String checkName, JCheckBoxController checkBox, String tooltip) { + ShowHideAction action = new ShowHideAction(); + + actions.push(action); + controllers.push(checkBox); + + addSeparator(controllers.peek().getComponent()); + + level++; + indent(); + startGroup(checkName); + + checkBox.setToolTipText(TooltipUtils.format(tooltip)); + + return checkBox; + } + public void endCheck() { endCheck(true); } @@ -476,11 +540,24 @@ public class PanelBuilder { outdent(); GroupController check = controllers.pop(); check.addActionListener(actions.pop()); - check.setSelectedIndex(0); + check.setSelectedKey(check.getKeys().get(0)); if (enable) return; // questo significa che se voglio inizialmente deselezionato - // devo fare click due volte - check.setSelectedIndex(0); + // devo fare click due volte + check.setSelectedKey(check.getKeys().get(0)); + } + + public void endCheck2(boolean enable) { + endGroup(); + level--; + outdent(); + GroupController check = controllers.pop(); + check.addItemListener(actions.pop()); + check.setSelectedKey(check.getKeys().get(0)); + if (enable) + return; // questo significa che se voglio inizialmente deselezionato + // devo fare click due volte + check.setSelectedKey(check.getKeys().get(0)); } public RowGroup startGroup(String groupName) { @@ -490,7 +567,7 @@ public class PanelBuilder { public RowGroup startGroup(String groupKey, String groupName) { RowGroup group = new RowGroup(); actions.peek().addItem(groupKey, group); // prima questo altrimenti - // scassa + // scassa controllers.peek().addGroup(groupKey, groupName); groups.push(new KeydRowGroup(groupKey, group)); @@ -546,15 +623,24 @@ public class PanelBuilder { return new JCheckBoxController(name); } - private GroupController comboBox() { - return new JComboBoxController(); - } - private GroupController hider() { return new HideController(); } - class ShowHideAction implements ActionListener { + protected void beforeSelection(String selectedKey) { + + } + + protected void afterSelection(String selectedKey) { + + } + + /* set a prefix for naming component */ + public void prefix(String name) { + this.prefix = name; + } + + class ShowHideAction implements ActionListener, ItemListener { Map groups = new HashMap(); String previousKey = null; @@ -562,6 +648,30 @@ public class PanelBuilder { groups.put(groupKey, group); } + @Override + public void itemStateChanged(ItemEvent e) { + Object source = e.getSource(); + if (source instanceof GroupController) { + GroupController controller = (GroupController) e.getSource(); + String selectedKey = controller.getSelectedKey(); + handleSelection(selectedKey); + GroupController childController = controller.getChildController(selectedKey); + if (childController != null) { + String childSelectedKey = childController.getSelectedKey(); + childController.setSelectedKey(childSelectedKey); + } + } else { + if (previousKey != null) { + groups.get(previousKey).hide(); + previousKey = null; + } else { + String selectedKey = groups.keySet().iterator().next(); + groups.get(selectedKey).show(); + previousKey = selectedKey; + } + } + } + @Override public void actionPerformed(ActionEvent e) { Object source = e.getSource(); @@ -573,11 +683,6 @@ public class PanelBuilder { if (childController != null) { String childSelectedKey = childController.getSelectedKey(); childController.setSelectedKey(childSelectedKey); - // GroupController grandChildController = childController.getChildController(childSelectedKey); - // if (grandChildController != null) { - // String grandChildSelectedKey = childController.getSelectedKey(); - // grandChildController.setSelectedKey(grandChildSelectedKey); - // } } } else { if (previousKey != null) { @@ -601,13 +706,6 @@ public class PanelBuilder { previousKey = selectedKey; afterSelection(selectedKey); } - } - - protected void beforeSelection(String selectedKey) { - - } - - protected void afterSelection(String selectedKey) { } @@ -620,9 +718,4 @@ public class PanelBuilder { this.groupKey = groupKey; } } - - /* set a prefix for naming component */ - public void prefix(String name) { - this.prefix = name; - } } diff --git a/src/eu/engys/util/ui/checkboxtree/AddCheckBoxToTree.java b/src/eu/engys/util/ui/checkboxtree/AddCheckBoxToTree.java index 3d2d757..5b2304a 100644 --- a/src/eu/engys/util/ui/checkboxtree/AddCheckBoxToTree.java +++ b/src/eu/engys/util/ui/checkboxtree/AddCheckBoxToTree.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.ui.checkboxtree; import java.awt.BorderLayout; diff --git a/src/eu/engys/util/ui/checkboxtree/FileTreeViewer.java b/src/eu/engys/util/ui/checkboxtree/FileTreeViewer.java index 4c1192f..7a4a465 100644 --- a/src/eu/engys/util/ui/checkboxtree/FileTreeViewer.java +++ b/src/eu/engys/util/ui/checkboxtree/FileTreeViewer.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.ui.checkboxtree; @@ -55,6 +54,7 @@ import javax.swing.tree.TreeCellRenderer; import javax.swing.tree.TreePath; import javax.swing.tree.TreeSelectionModel; +import de.javasoft.plaf.synthetica.SyntheticaAluOxideLookAndFeel; import eu.engys.util.ui.UiUtil; public class FileTreeViewer extends JFrame { @@ -174,6 +174,13 @@ public class FileTreeViewer extends JFrame { } } + public static void main(String argv[]) { + try { + UIManager.setLookAndFeel(new SyntheticaAluOxideLookAndFeel());// "com.sun.java.swing.plaf.windows.WindowsLookAndFeel"); + } catch (Exception evt) { + } + new FileTreeViewer(); + } } class IconCellRenderer extends JLabel implements TreeCellRenderer { diff --git a/src/eu/engys/util/ui/checkboxtree/LoadableItem.java b/src/eu/engys/util/ui/checkboxtree/LoadableItem.java index 6d2d88f..09c5107 100644 --- a/src/eu/engys/util/ui/checkboxtree/LoadableItem.java +++ b/src/eu/engys/util/ui/checkboxtree/LoadableItem.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.ui.checkboxtree; diff --git a/src/eu/engys/util/ui/checkboxtree/RootVisibleItem.java b/src/eu/engys/util/ui/checkboxtree/RootVisibleItem.java index 505f40f..cd52f1b 100644 --- a/src/eu/engys/util/ui/checkboxtree/RootVisibleItem.java +++ b/src/eu/engys/util/ui/checkboxtree/RootVisibleItem.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.ui.checkboxtree; diff --git a/src/eu/engys/util/ui/checkboxtree/RootVisibleLoadableItem.java b/src/eu/engys/util/ui/checkboxtree/RootVisibleLoadableItem.java index 5e185fd..c9c1290 100644 --- a/src/eu/engys/util/ui/checkboxtree/RootVisibleLoadableItem.java +++ b/src/eu/engys/util/ui/checkboxtree/RootVisibleLoadableItem.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.ui.checkboxtree; diff --git a/src/eu/engys/util/ui/checkboxtree/RootVisibleLoadableTreeNode.java b/src/eu/engys/util/ui/checkboxtree/RootVisibleLoadableTreeNode.java index f902785..cffec1c 100644 --- a/src/eu/engys/util/ui/checkboxtree/RootVisibleLoadableTreeNode.java +++ b/src/eu/engys/util/ui/checkboxtree/RootVisibleLoadableTreeNode.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.ui.checkboxtree; diff --git a/src/eu/engys/util/ui/checkboxtree/TristateCheckBox.java b/src/eu/engys/util/ui/checkboxtree/TristateCheckBox.java index db1197a..defcbcd 100644 --- a/src/eu/engys/util/ui/checkboxtree/TristateCheckBox.java +++ b/src/eu/engys/util/ui/checkboxtree/TristateCheckBox.java @@ -1,29 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.ui.checkboxtree; import java.awt.event.ActionEvent; @@ -38,258 +36,246 @@ import javax.swing.ActionMap; import javax.swing.ButtonGroup; import javax.swing.ButtonModel; import javax.swing.Icon; -import javax.swing.ImageIcon; import javax.swing.JCheckBox; import javax.swing.SwingUtilities; import javax.swing.event.ChangeListener; import javax.swing.plaf.ActionMapUIResource; public class TristateCheckBox extends JCheckBox { - static final long serialVersionUID = 0; + static final long serialVersionUID = 0; - private static final Icon EYE_ICON = new ImageIcon(TristateCheckBox.class.getClassLoader().getResource("eu/engys/resources/images/eye16.png")); - private static final Icon EYE_NO_ICON = new ImageIcon(TristateCheckBox.class.getClassLoader().getResource("eu/engys/resources/images/eye_no16.png")); - - public enum State { NOT_SELECTED, SELECTED, DONT_CARE }; + public enum State { + NOT_SELECTED, SELECTED, DONT_CARE + }; - private final TristateDecorator model; + private final TristateDecorator model; - public TristateCheckBox(String text, Icon icon, State initial) { - super(text, icon); -// setIcon(EYE_NO_ICON); -// setSelectedIcon(EYE_ICON); -// setPressedIcon(EYE_ICON); -// setRolloverIcon(EYE_ICON); -// setRolloverSelectedIcon(EYE_NO_ICON); - - // Add a listener for when the mouse is pressed - super.addMouseListener(new MouseAdapter() { - public void mousePressed(MouseEvent e) { - grabFocus(); - model.nextState(); - } - }); + public TristateCheckBox(String text, Icon icon, State initial) { + super(text, icon); + // setIcon(EYE_NO_ICON); + // setSelectedIcon(EYE_ICON); + // setPressedIcon(EYE_ICON); + // setRolloverIcon(EYE_ICON); + // setRolloverSelectedIcon(EYE_NO_ICON); - // Reset the keyboard action map - ActionMap map = new ActionMapUIResource(); - map.put("pressed", new AbstractAction() { + // Add a listener for when the mouse is pressed + super.addMouseListener(new MouseAdapter() { + public void mousePressed(MouseEvent e) { + grabFocus(); + model.nextState(); + } + }); - private static final long serialVersionUID = 1L; + // Reset the keyboard action map + ActionMap map = new ActionMapUIResource(); + map.put("pressed", new AbstractAction() { - public void actionPerformed(ActionEvent e) { - grabFocus(); - model.nextState(); - } - }); + private static final long serialVersionUID = 1L; - map.put("released", null); + public void actionPerformed(ActionEvent e) { + grabFocus(); + model.nextState(); + } + }); - SwingUtilities.replaceUIActionMap(this, map); + map.put("released", null); - // set the model to the adapted model - model = new TristateDecorator(getModel()); - setModel(model); - setState(initial); - } + SwingUtilities.replaceUIActionMap(this, map); - // Constractor types: - public TristateCheckBox(String text, State initial) { - this(text, null, initial); - } + // set the model to the adapted model + model = new TristateDecorator(getModel()); + setModel(model); + setState(initial); + } - public TristateCheckBox(String text) { - this(text, State.DONT_CARE); - } + // Constractor types: + public TristateCheckBox(String text, State initial) { + this(text, null, initial); + } - public TristateCheckBox() { - this(null); - } + public TristateCheckBox(String text) { + this(text, State.DONT_CARE); + } - /** No one may add mouse listeners, not even Swing! */ - public void addMouseListener(MouseListener l) { - } + public TristateCheckBox() { + this(null); + } - /** - * Set the new state to either SELECTED, NOT_SELECTED or DONT_CARE. If state - * == null, it is treated as DONT_CARE. - */ - public void setState(State state) { - model.setState(state); - } + /** No one may add mouse listeners, not even Swing! */ + public void addMouseListener(MouseListener l) { + } - /** - * Return the current state, which is determined by the selection status of - * the model. - */ - public State getState() { - return model.getState(); - } + /** + * Set the new state to either SELECTED, NOT_SELECTED or DONT_CARE. If state == null, it is treated as DONT_CARE. + */ + public void setState(State state) { + model.setState(state); + } - public void setSelected(boolean b) { - if (b) { - setState(State.SELECTED); - } else { - setState(State.NOT_SELECTED); - } - } + /** + * Return the current state, which is determined by the selection status of the model. + */ + public State getState() { + return model.getState(); + } - /** - * Exactly which Design Pattern is this? Is it an Adapter, a Proxy or a - * Decorator? In this case, my vote lies with the Decorator, because we are - * extending functionality and "decorating" the original model with a more - * powerful model. - */ - private class TristateDecorator implements ButtonModel { - private final ButtonModel other; + public void setSelected(boolean b) { + if (b) { + setState(State.SELECTED); + } else { + setState(State.NOT_SELECTED); + } + } - private TristateDecorator(ButtonModel other) { - this.other = other; - } + /** + * Exactly which Design Pattern is this? Is it an Adapter, a Proxy or a Decorator? In this case, my vote lies with the Decorator, because we are extending functionality and "decorating" the original model with a more powerful model. + */ + private class TristateDecorator implements ButtonModel { + private final ButtonModel other; - private void setState(State state) { - if (state == State.NOT_SELECTED) { - other.setArmed(false); - setPressed(false); - setSelected(false); - } else if (state == State.SELECTED) { - other.setArmed(false); - setPressed(false); - setSelected(true); - } else { // either "null" or DONT_CARE - other.setArmed(true); - setPressed(true); - setSelected(false); - } - } + private TristateDecorator(ButtonModel other) { + this.other = other; + } - /** - * The current state is embedded in the selection / armed state of the - * model. - * - * We return the SELECTED state when the checkbox is selected but not - * armed, DONT_CARE state when the checkbox is selected and armed (grey) - * and NOT_SELECTED when the checkbox is deselected. - */ - private State getState() { - if (isSelected() && !isArmed()) { - // normal black tick - return State.SELECTED; - } else if (isSelected() && isArmed()) { - // don't care grey tick - return State.DONT_CARE; - } else { - // normal deselected - return State.NOT_SELECTED; - } - } + private void setState(State state) { + if (state == State.NOT_SELECTED) { + other.setArmed(false); + setPressed(false); + setSelected(false); + } else if (state == State.SELECTED) { + other.setArmed(false); + setPressed(false); + setSelected(true); + } else { // either "null" or DONT_CARE + other.setArmed(true); + setPressed(true); + setSelected(false); + } + } - /** We rotate between NOT_SELECTED, SELECTED and DONT_CARE. */ - private void nextState() { - State current = getState(); - if (current == State.NOT_SELECTED) { - setState(State.SELECTED); - } else if (current == State.SELECTED) { - setState(State.DONT_CARE); - } else if (current == State.DONT_CARE) { - setState(State.NOT_SELECTED); - } - } + /** + * The current state is embedded in the selection / armed state of the model. + * + * We return the SELECTED state when the checkbox is selected but not armed, DONT_CARE state when the checkbox is selected and armed (grey) and NOT_SELECTED when the checkbox is deselected. + */ + private State getState() { + if (isSelected() && !isArmed()) { + // normal black tick + return State.SELECTED; + } else if (isSelected() && isArmed()) { + // don't care grey tick + return State.DONT_CARE; + } else { + // normal deselected + return State.NOT_SELECTED; + } + } - /** Filter: No one may change the armed status except us. */ - public void setArmed(boolean b) { - } + /** We rotate between NOT_SELECTED, SELECTED and DONT_CARE. */ + private void nextState() { + State current = getState(); + if (current == State.NOT_SELECTED) { + setState(State.SELECTED); + } else if (current == State.SELECTED) { + setState(State.DONT_CARE); + } else if (current == State.DONT_CARE) { + setState(State.NOT_SELECTED); + } + } - /** - * We disable focusing on the component when it is not enabled. - */ - public void setEnabled(boolean b) { - setFocusable(b); - other.setEnabled(b); - } + /** Filter: No one may change the armed status except us. */ + public void setArmed(boolean b) { + } - /** - * All these methods simply delegate to the "other" model that is being - * decorated. - */ - public boolean isArmed() { - return other.isArmed(); - } + /** + * We disable focusing on the component when it is not enabled. + */ + public void setEnabled(boolean b) { + other.setEnabled(b); + } - public boolean isSelected() { - return other.isSelected(); - } + /** + * All these methods simply delegate to the "other" model that is being decorated. + */ + public boolean isArmed() { + return other.isArmed(); + } - public boolean isEnabled() { - return other.isEnabled(); - } + public boolean isSelected() { + return other.isSelected(); + } - public boolean isPressed() { - return other.isPressed(); - } + public boolean isEnabled() { + return other.isEnabled(); + } - public boolean isRollover() { - return other.isRollover(); - } + public boolean isPressed() { + return other.isPressed(); + } - public int getMnemonic() { - return other.getMnemonic(); - } + public boolean isRollover() { + return other.isRollover(); + } - public String getActionCommand() { - return other.getActionCommand(); - } + public int getMnemonic() { + return other.getMnemonic(); + } - public Object[] getSelectedObjects() { - return other.getSelectedObjects(); - } + public String getActionCommand() { + return other.getActionCommand(); + } - public void setSelected(boolean b) { - other.setSelected(b); - } + public Object[] getSelectedObjects() { + return other.getSelectedObjects(); + } - public void setPressed(boolean b) { - other.setPressed(b); - } + public void setSelected(boolean b) { + other.setSelected(b); + } - public void setRollover(boolean b) { - other.setRollover(b); - } + public void setPressed(boolean b) { + other.setPressed(b); + } - public void setMnemonic(int key) { - other.setMnemonic(key); - } + public void setRollover(boolean b) { + other.setRollover(b); + } - public void setActionCommand(String s) { - other.setActionCommand(s); - } + public void setMnemonic(int key) { + other.setMnemonic(key); + } - public void setGroup(ButtonGroup group) { - other.setGroup(group); - } + public void setActionCommand(String s) { + other.setActionCommand(s); + } - public void addActionListener(ActionListener l) { - other.addActionListener(l); - } + public void setGroup(ButtonGroup group) { + other.setGroup(group); + } - public void removeActionListener(ActionListener l) { - other.removeActionListener(l); - } + public void addActionListener(ActionListener l) { + other.addActionListener(l); + } - public void addItemListener(ItemListener l) { - other.addItemListener(l); - } + public void removeActionListener(ActionListener l) { + other.removeActionListener(l); + } - public void removeItemListener(ItemListener l) { - other.removeItemListener(l); - } + public void addItemListener(ItemListener l) { + other.addItemListener(l); + } - public void addChangeListener(ChangeListener l) { - other.addChangeListener(l); - } + public void removeItemListener(ItemListener l) { + other.removeItemListener(l); + } - public void removeChangeListener(ChangeListener l) { - other.removeChangeListener(l); - } + public void addChangeListener(ChangeListener l) { + other.addChangeListener(l); + } - } + public void removeChangeListener(ChangeListener l) { + other.removeChangeListener(l); + } + + } } diff --git a/src/eu/engys/util/ui/checkboxtree/VisibleItem.java b/src/eu/engys/util/ui/checkboxtree/VisibleItem.java index 346de42..1422819 100644 --- a/src/eu/engys/util/ui/checkboxtree/VisibleItem.java +++ b/src/eu/engys/util/ui/checkboxtree/VisibleItem.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.ui.checkboxtree; public interface VisibleItem { diff --git a/src/eu/engys/util/ui/groupcolumnheader/ColumnGroup.java b/src/eu/engys/util/ui/groupcolumnheader/ColumnGroup.java index a593645..d9d5d88 100644 --- a/src/eu/engys/util/ui/groupcolumnheader/ColumnGroup.java +++ b/src/eu/engys/util/ui/groupcolumnheader/ColumnGroup.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.ui.groupcolumnheader; diff --git a/src/eu/engys/util/ui/groupcolumnheader/GroupableTableColumnModel.java b/src/eu/engys/util/ui/groupcolumnheader/GroupableTableColumnModel.java index 4ce29b7..4a225f9 100644 --- a/src/eu/engys/util/ui/groupcolumnheader/GroupableTableColumnModel.java +++ b/src/eu/engys/util/ui/groupcolumnheader/GroupableTableColumnModel.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.ui.groupcolumnheader; diff --git a/src/eu/engys/util/ui/groupcolumnheader/GroupableTableHeader.java b/src/eu/engys/util/ui/groupcolumnheader/GroupableTableHeader.java index 3c2a2ee..49bf656 100644 --- a/src/eu/engys/util/ui/groupcolumnheader/GroupableTableHeader.java +++ b/src/eu/engys/util/ui/groupcolumnheader/GroupableTableHeader.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.ui.groupcolumnheader; diff --git a/src/eu/engys/util/ui/groupcolumnheader/GroupableTableHeaderUI.java b/src/eu/engys/util/ui/groupcolumnheader/GroupableTableHeaderUI.java index a835efc..8d98299 100644 --- a/src/eu/engys/util/ui/groupcolumnheader/GroupableTableHeaderUI.java +++ b/src/eu/engys/util/ui/groupcolumnheader/GroupableTableHeaderUI.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.ui.groupcolumnheader; diff --git a/src/eu/engys/util/ui/stepcomponent/FlatButtonUI.java b/src/eu/engys/util/ui/stepcomponent/FlatButtonUI.java index 3b8a311..82c9710 100644 --- a/src/eu/engys/util/ui/stepcomponent/FlatButtonUI.java +++ b/src/eu/engys/util/ui/stepcomponent/FlatButtonUI.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.ui.stepcomponent; diff --git a/src/eu/engys/util/ui/stepcomponent/MultiLineLabel.java b/src/eu/engys/util/ui/stepcomponent/MultiLineLabel.java index de74b08..9187868 100644 --- a/src/eu/engys/util/ui/stepcomponent/MultiLineLabel.java +++ b/src/eu/engys/util/ui/stepcomponent/MultiLineLabel.java @@ -1,51 +1,31 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.ui.stepcomponent; -/* - * IzPack - Copyright 2001-2008 Julien Ponge, All Rights Reserved. - * - * http://izpack.org/ - * http://izpack.codehaus.org/ - * - * Copyright 1997,2002 Elmar Grom - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ + import java.awt.Color; import java.awt.Dimension; diff --git a/src/eu/engys/util/ui/stepcomponent/RichJLabel.java b/src/eu/engys/util/ui/stepcomponent/RichJLabel.java deleted file mode 100644 index c357d1d..0000000 --- a/src/eu/engys/util/ui/stepcomponent/RichJLabel.java +++ /dev/null @@ -1,142 +0,0 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - - -package eu.engys.util.ui.stepcomponent; - -/* -Swing Hacks Tips and Tools for Killer GUIs -By Joshua Marinacci, Chris Adamson -First Edition June 2005 -Series: Hacks -ISBN: 0-596-00907-0 -Pages: 542 -website: http://www.oreilly.com/catalog/swinghks/ - */ -import java.awt.Color; -import java.awt.Dimension; -import java.awt.FontMetrics; -import java.awt.Graphics; -import java.awt.Graphics2D; -import java.awt.RenderingHints; -import java.awt.font.LineMetrics; - -import javax.swing.JFrame; -import javax.swing.JLabel; - -public class RichJLabel extends JLabel { - - private int tracking; - - public RichJLabel(String text, int tracking) { - super(text); - this.tracking = tracking; - } - - private int left_x, left_y, right_x, right_y; - - private Color left_color, right_color; - - public void setLeftShadow(int x, int y, Color color) { - left_x = x; - left_y = y; - left_color = color; - } - - public void setRightShadow(int x, int y, Color color) { - right_x = x; - right_y = y; - right_color = color; - } - - public Dimension getPreferredSize() { - String text = getText(); - FontMetrics fm = this.getFontMetrics(getFont()); - - int w = fm.stringWidth(text); - w += (text.length() - 1) * tracking; - w += left_x + right_x; - - int h = fm.getHeight(); - h += left_y + right_y; - - return new Dimension(w, h); - } - - public void paintComponent(Graphics g) { - ((Graphics2D) g).setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); - - char[] chars = getText().toCharArray(); - - FontMetrics fm = this.getFontMetrics(getFont()); - int h = fm.getAscent(); - LineMetrics lm = fm.getLineMetrics(getText(), g); - g.setFont(getFont()); - - int x = 0; - - for (int i = 0; i < chars.length; i++) { - char ch = chars[i]; - int w = fm.charWidth(ch) + tracking; - - g.setColor(getLeft_color()); - g.drawString("" + chars[i], x - left_x, h - left_y); - - g.setColor(getRight_color()); - g.drawString("" + chars[i], x + right_x, h + right_y); - - g.setColor(getForeground()); - g.drawString("" + chars[i], x, h); - - x += w; - } - - } - - public Color getLeft_color() { - return left_color; - } - - public Color getRight_color() { - return right_color; - } - - public static void main(String[] args) { - RichJLabel label = new RichJLabel("www.java2s.com", 0); - label.setLeftShadow(1, 1, Color.white); - label.setRightShadow(1, 1, Color.white); - label.setForeground(Color.blue); - label.setFont(label.getFont().deriveFont(140f)); - - JFrame frame = new JFrame("RichJLabel hack"); - frame.getContentPane().add(label); - frame.pack(); - frame.setVisible(true); - } - - public static void p(String str) { - System.out.println(str); - } -} diff --git a/src/eu/engys/util/ui/stepcomponent/StepButton.java b/src/eu/engys/util/ui/stepcomponent/StepButton.java index 216e742..9ca70cc 100644 --- a/src/eu/engys/util/ui/stepcomponent/StepButton.java +++ b/src/eu/engys/util/ui/stepcomponent/StepButton.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.ui.stepcomponent; @@ -93,33 +92,11 @@ class StepButton extends JToggleButton { } private void configureTitle(String text) { -// title = new RichJLabel(text, 0) { -// public Color getForeground() { -// return changeForeground()? Color.WHITE : Color.BLACK; -// }; -// -// @Override -// public Color getLeft_color() { -// return changeForeground()? Color.DARK_GRAY : super.getLeft_color(); -// } -// -// @Override -// public Color getRight_color() { -// return changeForeground()? Color.BLACK : super.getRight_color(); -// } -// }; -// title.setLeftShadow(1, 1, Color.white); -// title.setRightShadow(1, 1, Color.lightGray); -// -// title.setForeground(Color.blue); -// title.setFont(title.getFont().deriveFont(20f)); title = new MultiLineLabel(text, MultiLineLabel.CENTER) { public Color getForeground() { return changeForeground()? Color.WHITE : Color.BLACK; } }; - //title.setFont(getFont().deriveFont(getFont().getSize2D()+4)); - //title.setBorder(BorderFactory.createLineBorder(Color.RED)); } public void updateUI() { diff --git a/src/eu/engys/util/ui/stepcomponent/StepButtonUI.java b/src/eu/engys/util/ui/stepcomponent/StepButtonUI.java index a0d8764..b9228d6 100644 --- a/src/eu/engys/util/ui/stepcomponent/StepButtonUI.java +++ b/src/eu/engys/util/ui/stepcomponent/StepButtonUI.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.ui.stepcomponent; diff --git a/src/eu/engys/util/ui/stepcomponent/StepComponent.java b/src/eu/engys/util/ui/stepcomponent/StepComponent.java index 5784243..7338a44 100644 --- a/src/eu/engys/util/ui/stepcomponent/StepComponent.java +++ b/src/eu/engys/util/ui/stepcomponent/StepComponent.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.ui.stepcomponent; diff --git a/src/eu/engys/util/ui/stepcomponent/StepComponentLayout.java b/src/eu/engys/util/ui/stepcomponent/StepComponentLayout.java index be46ee5..0fd1917 100644 --- a/src/eu/engys/util/ui/stepcomponent/StepComponentLayout.java +++ b/src/eu/engys/util/ui/stepcomponent/StepComponentLayout.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.ui.stepcomponent; diff --git a/src/eu/engys/util/ui/textfields/AdaptativeFormat.java b/src/eu/engys/util/ui/textfields/AdaptativeFormat.java index 85fdc27..e6e1d05 100644 --- a/src/eu/engys/util/ui/textfields/AdaptativeFormat.java +++ b/src/eu/engys/util/ui/textfields/AdaptativeFormat.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.ui.textfields; diff --git a/src/eu/engys/util/ui/textfields/DoubleField.java b/src/eu/engys/util/ui/textfields/DoubleField.java index 2f44638..2bd3598 100644 --- a/src/eu/engys/util/ui/textfields/DoubleField.java +++ b/src/eu/engys/util/ui/textfields/DoubleField.java @@ -1,34 +1,33 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.ui.textfields; import java.awt.Font; import java.awt.Insets; import java.beans.Transient; +import java.io.Serializable; import java.text.DecimalFormat; import java.text.DecimalFormatSymbols; import java.util.Locale; @@ -48,7 +47,7 @@ import eu.engys.util.ui.textfields.verifiers.DoubleVerifier; * http://www.javalobby.org/java/forums/t20551.html * */ -public class DoubleField extends PromptTextField { +public class DoubleField extends PromptTextField implements Serializable { private static final DecimalFormatSymbols decimalFormatSymbols = new DecimalFormatSymbols(Locale.US); @@ -242,4 +241,8 @@ public class DoubleField extends PromptTextField { setGroupingUsed(false); } } + +// public static void main(String[] args) { +// System.err.println(new AdaptativeFormat(new DoubleEditFormat(10), new DoubleScientificFormat(10), 10).format(1e-14)); +// } } diff --git a/src/eu/engys/util/ui/textfields/FileTextField.java b/src/eu/engys/util/ui/textfields/FileTextField.java index 4ddba9f..2c44fb3 100644 --- a/src/eu/engys/util/ui/textfields/FileTextField.java +++ b/src/eu/engys/util/ui/textfields/FileTextField.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.ui.textfields; diff --git a/src/eu/engys/util/ui/textfields/IntegerField.java b/src/eu/engys/util/ui/textfields/IntegerField.java index 21e0e2c..f51ea30 100644 --- a/src/eu/engys/util/ui/textfields/IntegerField.java +++ b/src/eu/engys/util/ui/textfields/IntegerField.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.ui.textfields; @@ -41,6 +40,8 @@ import eu.engys.util.ui.textfields.verifiers.IntegerVerifier; * See also * https://docs.oracle.com/javase/tutorial/uiswing/components/formattedtextfield.html * http://stackoverflow.com/a/12978182 + * http://www.javalobby.org/java/forums/t20551.html + * * */ public class IntegerField extends PromptTextField implements Serializable { @@ -137,7 +138,7 @@ public class IntegerField extends PromptTextField implements Serializable { } } - + public static class IntegerEditFormat extends DecimalFormat { public IntegerEditFormat() { super(); diff --git a/src/eu/engys/util/ui/textfields/NullableNumberFormatter.java b/src/eu/engys/util/ui/textfields/NullableNumberFormatter.java index 8533f5f..a75b8b1 100644 --- a/src/eu/engys/util/ui/textfields/NullableNumberFormatter.java +++ b/src/eu/engys/util/ui/textfields/NullableNumberFormatter.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.ui.textfields; diff --git a/src/eu/engys/util/ui/textfields/PromptTextField.java b/src/eu/engys/util/ui/textfields/PromptTextField.java index 6cbeca1..36513a0 100644 --- a/src/eu/engys/util/ui/textfields/PromptTextField.java +++ b/src/eu/engys/util/ui/textfields/PromptTextField.java @@ -1,27 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.ui.textfields; import java.awt.Color; @@ -60,6 +60,7 @@ public class PromptTextField extends JFormattedTextField { public static final int STRING_FIELD_COLUMNS = 10; private String prompt = ""; + private boolean highlighted; public PromptTextField() { super(); @@ -74,9 +75,25 @@ public class PromptTextField extends JFormattedTextField { this.prompt = prompt; } + public void setHighlighted(boolean b) { + this.highlighted = b; + if (b) { + setBackground(HIGHLIGHT_BG); + setForeground(HIGHLIGHT_FG); + } else { + setBackground(DEFAULT_BG); + setForeground(DEFAULT_FG); + } + } + public void setValidColors() { - setBackground(DEFAULT_BG); - setForeground(DEFAULT_FG); + if (highlighted) { + setBackground(HIGHLIGHT_BG); + setForeground(HIGHLIGHT_FG); + } else { + setBackground(DEFAULT_BG); + setForeground(DEFAULT_FG); + } } public void setInvalidColors() { diff --git a/src/eu/engys/util/ui/textfields/SpinnerField.java b/src/eu/engys/util/ui/textfields/SpinnerField.java index 33c21ff..1dd9282 100644 --- a/src/eu/engys/util/ui/textfields/SpinnerField.java +++ b/src/eu/engys/util/ui/textfields/SpinnerField.java @@ -1,42 +1,44 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.ui.textfields; +import java.awt.event.FocusEvent; +import java.awt.event.FocusListener; import java.io.Serializable; import javax.swing.JFormattedTextField; import javax.swing.JSpinner; +import javax.swing.JTextField; import javax.swing.SpinnerNumberModel; import javax.swing.text.DefaultFormatterFactory; import javax.swing.text.NumberFormatter; +import eu.engys.util.ui.ExecUtil; + public class SpinnerField extends JSpinner implements Serializable { - public SpinnerField() { this(-Integer.MAX_VALUE, Integer.MAX_VALUE, 0); } @@ -48,7 +50,8 @@ public class SpinnerField extends JSpinner implements Serializable { public SpinnerField(int min, int max, int value) throws IllegalArgumentException { super(new SpinnerNumberModel(value, min, max, 1)); - JFormattedTextField textField = ((JSpinner.DefaultEditor)getEditor()).getTextField(); + final JFormattedTextField textField = getTextField(); + textField.setHorizontalAlignment(JTextField.LEFT); NumberFormatter def = new NullableNumberFormatter(); def.setValueClass(Integer.class); @@ -67,8 +70,13 @@ public class SpinnerField extends JSpinner implements Serializable { DefaultFormatterFactory dff = new DefaultFormatterFactory(def, disp, ed); textField.setFormatterFactory(dff); + textField.setColumns(4); + + textField.addFocusListener(new SpinnerFocusListener()); + } - textField.setColumns(4); + public JFormattedTextField getTextField() { + return ((JSpinner.DefaultEditor) getEditor()).getTextField(); } public void setIntValue(int value) { @@ -83,4 +91,33 @@ public class SpinnerField extends JSpinner implements Serializable { return 0; } + private class SpinnerFocusListener implements FocusListener { + + @Override + public void focusGained(final FocusEvent e) { + new Thread(new Runnable() { + @Override + public void run() { + ExecUtil.invokeLater(new Runnable() { + @Override + public void run() { + ((JTextField) e.getSource()).selectAll(); + } + }); + } + }).start(); + } + + @Override + public void focusLost(final FocusEvent e) { + ExecUtil.invokeLater(new Runnable() { + @Override + public void run() { + ((JTextField) e.getSource()).getCaret().setDot(((JTextField) e.getSource()).getCaretPosition()); + } + }); + } + + } + } diff --git a/src/eu/engys/util/ui/textfields/StringField.java b/src/eu/engys/util/ui/textfields/StringField.java index 25b3ce9..d9be4be 100644 --- a/src/eu/engys/util/ui/textfields/StringField.java +++ b/src/eu/engys/util/ui/textfields/StringField.java @@ -1,31 +1,30 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.ui.textfields; +import java.awt.Insets; import java.text.ParseException; import javax.swing.text.DefaultFormatterFactory; @@ -53,42 +52,45 @@ public class StringField extends PromptTextField { } public StringField(int columns) { - this("", columns, true, true); + this("", columns, true, true); } public StringField(String text, int columns, boolean checkEmptyStrings, boolean checkForbidden) { super(); setFormatterFactory(new DefaultFormatterFactory(new StringFormatter())); setText(text); - setInputVerifier(new StringVerifier(this)); - setColumns(columns != -1 ? columns : STRING_FIELD_COLUMNS); - setToVerifier(checkEmptyStrings, checkForbidden); + setInputVerifier(new StringVerifier(this)); + setColumns(columns != -1 ? columns : STRING_FIELD_COLUMNS); + setToVerifier(checkEmptyStrings, checkForbidden); + } + + public StringField(Insets insets) { + super(insets); } public void setStringValue(String value) { - super.setValue(value); + super.setValue(value); } - - public String getStringValue() { - return (String) super.getValue(); - } - - public void setToVerifier(boolean checkEmptyStrings, boolean checkForbidden) { - ((StringVerifier) getInputVerifier()).setCheckEmptyStrings(checkEmptyStrings); - ((StringVerifier) getInputVerifier()).setCheckForbidden(checkForbidden); - } - - class StringFormatter extends AbstractFormatter { - @Override - public Object stringToValue(String text) throws ParseException { - return text; - } - - @Override - public String valueToString(Object value) throws ParseException { - return value != null ? value.toString() : ""; - } - } - -} + public String getStringValue() { + return (String) super.getValue(); + } + + public void setToVerifier(boolean checkEmptyStrings, boolean checkForbidden) { + ((StringVerifier) getInputVerifier()).setCheckEmptyStrings(checkEmptyStrings); + ((StringVerifier) getInputVerifier()).setCheckForbidden(checkForbidden); + } + + class StringFormatter extends AbstractFormatter { + @Override + public Object stringToValue(String text) throws ParseException { + return text; + } + + @Override + public String valueToString(Object value) throws ParseException { + return value != null ? value.toString() : ""; + } + } + +} diff --git a/src/eu/engys/util/ui/textfields/verifiers/AbstractVerifier.java b/src/eu/engys/util/ui/textfields/verifiers/AbstractVerifier.java index 9a2909b..89f2823 100644 --- a/src/eu/engys/util/ui/textfields/verifiers/AbstractVerifier.java +++ b/src/eu/engys/util/ui/textfields/verifiers/AbstractVerifier.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.ui.textfields.verifiers; @@ -45,8 +44,9 @@ import javax.swing.JTextField; import eu.engys.util.ui.textfields.PromptTextField; /** - * See Building a Swing Validation Package with InputVerifier - * http://www.javalobby.org/java/forums/t20551.html + * See + * http://stackoverflow.com/questions/4238749/revert-jtextfield-to-last-good-value + * http://stackoverflow.com/questions/10266889/jformattedtextfield-only-validate-when-pressed-enter * */ public abstract class AbstractVerifier extends InputVerifier implements KeyListener { diff --git a/src/eu/engys/util/ui/textfields/verifiers/DoubleVerifier.java b/src/eu/engys/util/ui/textfields/verifiers/DoubleVerifier.java index a38cf7c..db5ba8b 100644 --- a/src/eu/engys/util/ui/textfields/verifiers/DoubleVerifier.java +++ b/src/eu/engys/util/ui/textfields/verifiers/DoubleVerifier.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.ui.textfields.verifiers; diff --git a/src/eu/engys/util/ui/textfields/verifiers/FileVerifier.java b/src/eu/engys/util/ui/textfields/verifiers/FileVerifier.java index 8994f85..9d06e47 100644 --- a/src/eu/engys/util/ui/textfields/verifiers/FileVerifier.java +++ b/src/eu/engys/util/ui/textfields/verifiers/FileVerifier.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.ui.textfields.verifiers; @@ -31,11 +30,11 @@ import java.io.File; import javax.swing.JComponent; import javax.swing.JTextField; -import eu.engys.util.ui.textfields.PromptTextField; +import eu.engys.util.ui.textfields.FileTextField; public class FileVerifier extends AbstractVerifier { - public FileVerifier(PromptTextField c) { + public FileVerifier(FileTextField c) { super(c); } diff --git a/src/eu/engys/util/ui/textfields/verifiers/IntegerVerifier.java b/src/eu/engys/util/ui/textfields/verifiers/IntegerVerifier.java index 37a24a6..2fb128e 100644 --- a/src/eu/engys/util/ui/textfields/verifiers/IntegerVerifier.java +++ b/src/eu/engys/util/ui/textfields/verifiers/IntegerVerifier.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.ui.textfields.verifiers; diff --git a/src/eu/engys/util/ui/textfields/verifiers/StringVerifier.java b/src/eu/engys/util/ui/textfields/verifiers/StringVerifier.java index 8a7f849..b3fb9d6 100644 --- a/src/eu/engys/util/ui/textfields/verifiers/StringVerifier.java +++ b/src/eu/engys/util/ui/textfields/verifiers/StringVerifier.java @@ -1,76 +1,80 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.ui.textfields.verifiers; import javax.swing.JComponent; import javax.swing.JTextField; import eu.engys.util.Util; -import eu.engys.util.ui.textfields.PromptTextField; +import eu.engys.util.ui.textfields.StringField; public class StringVerifier extends AbstractVerifier { - private boolean checkEmptyStrings = true; + private boolean checkEmptyStrings = true; private boolean checkForbidden = true; - public StringVerifier(PromptTextField c) { - super(c); - } - - @Override - protected boolean validationCriteria(JComponent jc) { - try { - String text = ((JTextField) jc).getText(); - - if ( checkEmptyStrings && (text == null || text.isEmpty())){ - setMessage("Empty name"); - return false; - } + public StringVerifier(StringField c) { + super(c); + } - if (checkForbidden) { - for (char ch : text.toCharArray()) { - if (Util.isForbidden(ch)) { - setMessage("Illegal charachter: " + ch); - return false; - } - } - } - } catch (Exception e) { - setMessage("Error parsing string"); - return false; - } - return true; - } + @Override + protected boolean validationCriteria(JComponent jc) { + try { + String text = ((JTextField) jc).getText(); - public void setCheckEmptyStrings(boolean b) { - this.checkEmptyStrings = b; - } + if (checkEmptyStrings && (text == null || text.isEmpty())) { + setMessage(getErrorMessage()); + return false; + } + + if (checkForbidden) { + for (char ch : text.toCharArray()) { + if (Util.isForbidden(ch)) { + setMessage("Illegal charachter: " + ch); + return false; + } + } + } + } catch (Exception e) { + setMessage("Error parsing string"); + return false; + } + return true; + } + + protected String getErrorMessage() { + return "Empty name"; + } + + public void setCheckEmptyStrings(boolean b) { + this.checkEmptyStrings = b; + } public void setCheckForbidden(boolean checkForbidden) { this.checkForbidden = checkForbidden; } + } + diff --git a/src/eu/engys/util/ui/treetable/AbstractTreeTableModel.java b/src/eu/engys/util/ui/treetable/AbstractTreeTableModel.java index 1ae1680..dbeb52a 100644 --- a/src/eu/engys/util/ui/treetable/AbstractTreeTableModel.java +++ b/src/eu/engys/util/ui/treetable/AbstractTreeTableModel.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.ui.treetable; diff --git a/src/eu/engys/util/ui/treetable/JTreeTable.java b/src/eu/engys/util/ui/treetable/JTreeTable.java index 3f52545..dbb3204 100644 --- a/src/eu/engys/util/ui/treetable/JTreeTable.java +++ b/src/eu/engys/util/ui/treetable/JTreeTable.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.ui.treetable; @@ -33,6 +32,8 @@ import java.util.EventObject; import javax.swing.JTable; import javax.swing.JTree; +import javax.swing.RowSorter; +import javax.swing.table.TableModel; import javax.swing.table.TableRowSorter; import eu.engys.util.ui.TableUtil; @@ -80,15 +81,23 @@ public class JTreeTable extends JTable { if (tree.getRowHeight() < 1) { setRowHeight(20); } - } - public void setSearchableColumns(int... searchableColumns) { - filter.setColumnsWhereToSearch(searchableColumns); + public void filterOn() { + setRowSorter(sorter); + } + + public void filterOff() { + setRowSorter(null); } - public void filter(final String filterText) { - filter.setFilterText(filterText); + public void filter(int i, String filterText) { + filter.setFilterText(i, filterText); + sorter.sort(); + } + + public void resetFilter() { + filter.reset(); sorter.sort(); } @@ -105,7 +114,17 @@ public class JTreeTable extends JTable { } public Object getNode(int index) { - return ((TreeTableModelAdapter) getModel()).nodeForRow(index); + RowSorter rowSorter = getRowSorter(); + int cIndex = rowSorter != null ? rowSorter.convertRowIndexToModel(index) : index; + return ((TreeTableModelAdapter) getModel()).nodeForRow(cIndex); + } + + public boolean isExpanded(int row) { + return tree.isExpanded(row); + } + + public boolean isCollapsed(int row) { + return tree.isCollapsed(row); } public void updateUI() { @@ -166,14 +185,13 @@ public class JTreeTable extends JTable { tree.collapsePath(tree.getPathForRow(0)); } + public void setTreeEditable(boolean treeEditable) { + this.treeEditable = treeEditable; + } public boolean getTreeEditable() { return treeEditable; } - public void setTreeEditable(boolean editable) { - this.treeEditable = editable; - } - public boolean getShowsIcons() { return showsIcons; } diff --git a/src/eu/engys/util/ui/treetable/TableFilter.java b/src/eu/engys/util/ui/treetable/TableFilter.java index e106f6d..88b01ba 100644 --- a/src/eu/engys/util/ui/treetable/TableFilter.java +++ b/src/eu/engys/util/ui/treetable/TableFilter.java @@ -1,70 +1,71 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.ui.treetable; +import java.util.HashMap; +import java.util.Map; + import javax.swing.RowFilter; import javax.swing.table.TableModel; -import org.apache.commons.lang.ArrayUtils; - public class TableFilter extends RowFilter { - private String filterText; - private int[] columnsWhereToSearch; + private Map filterStrings = new HashMap<>(); public TableFilter(String initialFilter) { - this.filterText = initialFilter; + setFilterText(0, ""); } - public void setFilterText(String filterText) { - this.filterText = filterText; - } - - public void setColumnsWhereToSearch(int... columnsWhereToSearch) { - this.columnsWhereToSearch = columnsWhereToSearch; + public void setFilterText(int i, String filterText) { + filterStrings.put(i, filterText); } @Override public boolean include(RowFilter.Entry entry) { - if (columnsWhereToSearch == null || columnsWhereToSearch.length == 0) { + if (filterStrings == null || filterStrings.isEmpty()) { return true; } - String regexpFilter = filterText.replace(".", "\\.").replace("*", ".*").replace("?", ".?").replace("+", ".+").concat(".*"); - int numberOfTableColumns = entry.getValueCount(); for (int i = 0; i < numberOfTableColumns; i++) { - if (ArrayUtils.contains(columnsWhereToSearch, i)) { - if (entry.getStringValue(i).matches(regexpFilter)) { - return true; + if (filterStrings.containsKey(i)) { + String filterText = filterStrings.get(i); + String regexpFilter = filterText.replace(".", "\\.").replace("*", ".*").replace("?", ".?").replace("+", ".+").concat(".*"); + if (regexpFilter.isEmpty() || entry.getStringValue(i).matches(regexpFilter)) { + continue; + } else { + return false; } } } - return false; - + return true; } -} + public void reset() { + filterStrings.clear(); + setFilterText(0, ""); + } + +} \ No newline at end of file diff --git a/src/eu/engys/util/ui/treetable/TreeTableCellEditor.java b/src/eu/engys/util/ui/treetable/TreeTableCellEditor.java index 078485c..20f386a 100644 --- a/src/eu/engys/util/ui/treetable/TreeTableCellEditor.java +++ b/src/eu/engys/util/ui/treetable/TreeTableCellEditor.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.ui.treetable; import java.awt.Component; diff --git a/src/eu/engys/util/ui/treetable/TreeTableModel.java b/src/eu/engys/util/ui/treetable/TreeTableModel.java index 483f9a6..ad8fe3c 100644 --- a/src/eu/engys/util/ui/treetable/TreeTableModel.java +++ b/src/eu/engys/util/ui/treetable/TreeTableModel.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.ui.treetable; diff --git a/src/eu/engys/util/ui/treetable/TreeTableModelAdapter.java b/src/eu/engys/util/ui/treetable/TreeTableModelAdapter.java index e227730..626a096 100644 --- a/src/eu/engys/util/ui/treetable/TreeTableModelAdapter.java +++ b/src/eu/engys/util/ui/treetable/TreeTableModelAdapter.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.ui.treetable; diff --git a/src/eu/engys/util/ui/treetable/tree/JTreeTableCellRenderer.java b/src/eu/engys/util/ui/treetable/tree/JTreeTableCellRenderer.java index 7f6024e..838496e 100644 --- a/src/eu/engys/util/ui/treetable/tree/JTreeTableCellRenderer.java +++ b/src/eu/engys/util/ui/treetable/tree/JTreeTableCellRenderer.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.ui.treetable.tree; import java.awt.Component; diff --git a/src/eu/engys/util/ui/treetable/tree/ListToTreeSelectionModelWrapper.java b/src/eu/engys/util/ui/treetable/tree/ListToTreeSelectionModelWrapper.java index 6ba9c8b..470411f 100644 --- a/src/eu/engys/util/ui/treetable/tree/ListToTreeSelectionModelWrapper.java +++ b/src/eu/engys/util/ui/treetable/tree/ListToTreeSelectionModelWrapper.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.ui.treetable.tree; import javax.swing.JTree; diff --git a/src/eu/engys/util/ui/treetable/tree/TreeTableCellRenderer.java b/src/eu/engys/util/ui/treetable/tree/TreeTableCellRenderer.java index ee5b26f..9565c68 100644 --- a/src/eu/engys/util/ui/treetable/tree/TreeTableCellRenderer.java +++ b/src/eu/engys/util/ui/treetable/tree/TreeTableCellRenderer.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.ui.treetable.tree; import java.awt.Color; @@ -49,6 +48,7 @@ public class TreeTableCellRenderer extends JTree implements TableCellRenderer { public TreeTableCellRenderer(JTreeTable jTreeTable, TreeModel model) { super(model); + setLargeModel(true); this.jTreeTable = jTreeTable; this.tableDefaultRenderer = jTreeTable.getDefaultRenderer(Object.class); setCellRenderer(new JTreeTableCellRenderer(jTreeTable)); diff --git a/src/eu/engys/util/ui/treetable/tree/TreeTableTreeModel.java b/src/eu/engys/util/ui/treetable/tree/TreeTableTreeModel.java index d6bd14f..c37da0a 100644 --- a/src/eu/engys/util/ui/treetable/tree/TreeTableTreeModel.java +++ b/src/eu/engys/util/ui/treetable/tree/TreeTableTreeModel.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.ui.treetable.tree; diff --git a/src/eu/engys/util/ui/treetable/tree/TreeTableTreeNode.java b/src/eu/engys/util/ui/treetable/tree/TreeTableTreeNode.java index c0dad7c..b542980 100644 --- a/src/eu/engys/util/ui/treetable/tree/TreeTableTreeNode.java +++ b/src/eu/engys/util/ui/treetable/tree/TreeTableTreeNode.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.util.ui.treetable.tree; diff --git a/src/eu/engys/vtk/AbstractMeshReader.java b/src/eu/engys/vtk/AbstractMeshReader.java new file mode 100644 index 0000000..2122588 --- /dev/null +++ b/src/eu/engys/vtk/AbstractMeshReader.java @@ -0,0 +1,50 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.vtk; + +import java.io.File; + +import eu.engys.core.project.mesh.FieldItems; +import eu.engys.util.progress.ProgressMonitor; + +public class AbstractMeshReader { + + protected final File baseDir; + protected final boolean parallel; + protected final ProgressMonitor monitor; + + protected FieldItems fieldItems = new FieldItems(); + + protected AbstractMeshReader(File baseDir, boolean parallel, ProgressMonitor monitor) { + this.baseDir = baseDir; + this.parallel = parallel; + this.monitor = monitor; + } + + public FieldItems getFieldItems() { + return fieldItems; + } + +} diff --git a/src/eu/engys/vtk/ActorsMap.java b/src/eu/engys/vtk/ActorsMap.java index ee0138a..ddd839e 100644 --- a/src/eu/engys/vtk/ActorsMap.java +++ b/src/eu/engys/vtk/ActorsMap.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.vtk; import java.util.Collection; diff --git a/src/eu/engys/vtk/CellZoneActor.java b/src/eu/engys/vtk/CellZoneActor.java index 198b057..03edbbd 100644 --- a/src/eu/engys/vtk/CellZoneActor.java +++ b/src/eu/engys/vtk/CellZoneActor.java @@ -1,36 +1,33 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.vtk; -import vtk.vtkPolyData; -import vtk.vtkUnstructuredGrid; import eu.engys.core.project.zero.cellzones.CellZone; -import eu.engys.core.project.zero.facezones.FaceZone; import eu.engys.util.ui.checkboxtree.VisibleItem; import eu.engys.vtk.actors.DefaultActor; +import vtk.vtkUnstructuredGrid; public class CellZoneActor extends DefaultActor { @@ -42,14 +39,8 @@ public class CellZoneActor extends DefaultActor { newActor(dataset, true); } - public CellZoneActor(FaceZone zone, vtkPolyData dataset) { - super(zone.getName()); - this.zone = zone; - newActor(dataset, true); - } - @Override public VisibleItem getVisibleItem() { return zone; } -} +} \ No newline at end of file diff --git a/src/eu/engys/vtk/ExternalMeshReader.java b/src/eu/engys/vtk/ExternalMeshReader.java new file mode 100644 index 0000000..bd00775 --- /dev/null +++ b/src/eu/engys/vtk/ExternalMeshReader.java @@ -0,0 +1,326 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.vtk; + +import static eu.engys.core.project.mesh.FieldItem.MAGNITUDE; +import static eu.engys.core.project.mesh.FieldItem.X; +import static eu.engys.core.project.mesh.FieldItem.Y; +import static eu.engys.core.project.mesh.FieldItem.Z; +import static eu.engys.core.project.zero.fields.Fields.U; +import static eu.engys.vtk.VTKUtil.logBlockNames; + +import java.io.File; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import eu.engys.core.project.geometry.BoundingBox; +import eu.engys.core.project.mesh.FieldItem; +import eu.engys.core.project.mesh.FieldItem.DataType; +import eu.engys.util.progress.ProgressMonitor; +import vtk.vtkCompositeDataPipeline; +import vtk.vtkCompositeDataSet; +import vtk.vtkDataObject; +import vtk.vtkDataSet; +import vtk.vtkExecutive; +import vtk.vtkInformation; +import vtk.vtkInformationDoubleVectorKey; +import vtk.vtkMultiBlockDataSet; +import vtk.vtkPolyData; +import vtk.vtkUnstructuredGrid; + +public class ExternalMeshReader extends AbstractMeshReader { + + private static final Logger logger = LoggerFactory.getLogger(ExternalMeshReader.class); + + private static final String FACE_ZONES = "faceZones"; + private static final String CELL_ZONES = "cellZones"; + static final String PATCHES = "Patches"; + static final String ZONES = "Zones"; + + private static final boolean readFaceZones = false; + private static final boolean readCellZones = true; + + private Map patchesDataset; + private List faceZonesDataset; + private List cellZonesDataset; + + private BoundingBox bounds; + private List timesteps; + + public ExternalMeshReader(File baseDir, boolean parallel, ProgressMonitor monitor) { + super(baseDir, parallel, monitor); + + this.patchesDataset = new HashMap<>(); + this.faceZonesDataset = new ArrayList<>(); + this.cellZonesDataset = new ArrayList<>(); + } + + public void read(double timeStep) { + VTKOpenFOAMReader reader = new VTKOpenFOAMReader(baseDir, parallel, monitor);//"External"); + reader.UpdateInformation(); + reader.ReadPatchesOn(); + reader.ReadInternalMeshOff(); + reader.ReadZonesOn(); + reader.setTimeStep(timeStep); + reader.Update(); + + vtkMultiBlockDataSet dataset = reader.GetOutput(); + try { + if (VTKUtil.isSingleRegion(dataset)) { + readSingleRegion(dataset); + } else { + readMultiRegion(dataset); + } + + readFieldItems(reader); + readTimeSteps(reader); + readBounds(reader); + } catch (Exception e) { + logger.error(e.getMessage(), e); + } finally { + dataset.Delete(); + reader.Delete(); + } + } + + private void readMultiRegion(vtkMultiBlockDataSet dataset) { + int numberOfBlocks = dataset.GetNumberOfBlocks(); + if (numberOfBlocks > 0) { + logger.debug("READ [MULTI] [EXTERNAL] blocks are: {}", logBlockNames(dataset)); + + vtkDataObject defaultRegion = VTKUtil.getBlock(VTKUtil.DEFAULT_REGION, dataset); + if (defaultRegion != null) { + readSingleRegion((vtkMultiBlockDataSet) defaultRegion); + } else { + logger.warn("READ [MULTI] [EXTERNAL]: {} NOT LOADED", VTKUtil.DEFAULT_REGION); + } + } else { + logger.warn("READ [MULTI] [EXTERNAL]: EMPTY!"); + } + } + + private void readSingleRegion(vtkMultiBlockDataSet dataset) { + int numberOfBlocks = dataset.GetNumberOfBlocks(); + if (numberOfBlocks > 0) { + logger.debug("READ [SINGLE] [EXTERNAL] blocks are: {}", logBlockNames(dataset)); + + vtkDataObject patches = VTKUtil.getBlock(PATCHES, dataset); + if (patches != null) { + extractPatchesDataset(patches); + } else { + logger.warn("READ [SINGLE] [PATCHES]: {} NOT FOUND", PATCHES); + } + + vtkDataObject zones = VTKUtil.getBlock(ZONES, dataset); + if (zones != null) { + extractZonesDataset(zones); + } else { + logger.warn("READ [SINGLE] [ZONES]: {} NOT FOUND", ZONES); + } + } + } + + private void extractPatchesDataset(vtkDataObject block) { + if (block != null && block instanceof vtkMultiBlockDataSet) { + vtkMultiBlockDataSet dataset = (vtkMultiBlockDataSet) block; + int subblockNumbers = dataset.GetNumberOfBlocks(); + for (int i = 0; i < subblockNumbers; i++) { + vtkDataObject subBlock = dataset.GetBlock(i); + if (subBlock instanceof vtkPolyData) { + String name = dataset.GetMetaData(i).Get(new vtkCompositeDataSet().NAME()); + this.patchesDataset.put(name, VTKUtil.shallowCopy((vtkPolyData) subBlock)); + } + } + } + } + + private void extractZonesDataset(vtkDataObject block) { + if (block != null && block instanceof vtkMultiBlockDataSet) { + + vtkMultiBlockDataSet zones = (vtkMultiBlockDataSet) block; + + if (readFaceZones) { + vtkDataObject faceZones = VTKUtil.getBlock(FACE_ZONES, zones); + if (faceZones != null) { + extractFaceZonesDataset(faceZones); + } else { + logger.warn("READ [SINGLE] [FACE ZONES]: {} NOT FOUND", FACE_ZONES); + } + } else { + logger.debug("READ [SINGLE] [FACE ZONES]: programmatically DISABLED"); + } + + if (readCellZones) { + vtkDataObject cellZones = VTKUtil.getBlock(CELL_ZONES, zones); + if (cellZones != null) { + extractCellZonesDataset(cellZones); + } else { + logger.warn("READ [SINGLE] [ZONES]: {} NOT FOUND", ZONES); + } + } else { + logger.debug("READ [SINGLE] [ZONES]: programmatically DISABLED"); + } + zones.Delete(); + } + } + + private void extractCellZonesDataset(vtkDataObject block) { + if (block != null && block instanceof vtkMultiBlockDataSet) { + vtkMultiBlockDataSet cellZones = (vtkMultiBlockDataSet) block; + int cellZonesNumber = cellZones.GetNumberOfBlocks(); + for (int i = 0; i < cellZonesNumber; i++) { + vtkDataObject cellZone = cellZones.GetBlock(i); + if (cellZone instanceof vtkUnstructuredGrid) { + this.cellZonesDataset.add(VTKUtil.shallowCopy((vtkUnstructuredGrid) cellZone)); + } + } + } + } + + private void extractFaceZonesDataset(vtkDataObject block) { + if (block != null && block instanceof vtkMultiBlockDataSet) { + vtkMultiBlockDataSet dataset = (vtkMultiBlockDataSet) block; + int subblockNumbers = dataset.GetNumberOfBlocks(); + for (int i = 0; i < subblockNumbers; i++) { + vtkDataObject subBlock = dataset.GetBlock(i); + if (subBlock instanceof vtkPolyData) { + this.faceZonesDataset.add(VTKUtil.shallowCopy((vtkPolyData) subBlock)); + } + } + } + } + + private void readFieldItems(VTKOpenFOAMReader reader) { + readCellFieldItems(reader); + readPointFieldItems(reader); + } + + private void readCellFieldItems(VTKOpenFOAMReader reader) { + List allDataSets = new ArrayList<>(); + allDataSets.addAll(patchesDataset.values()); + allDataSets.addAll(faceZonesDataset); + allDataSets.addAll(cellZonesDataset); + + Map cellRanges = VTKUtil.getCellFieldsRanges(allDataSets); + for (String newField : reader.getCellArrayNames()) { + if (cellRanges.containsKey(newField)) { + if (newField.startsWith(U)) { + fieldItems.addCellFieldItem(new FieldItem(newField + " - " + MAGNITUDE, newField, DataType.CELL, 0, cellRanges.get(newField)[0])); + fieldItems.addCellFieldItem(new FieldItem(newField + " - " + X, newField, DataType.CELL, 1, cellRanges.get(newField)[1])); + fieldItems.addCellFieldItem(new FieldItem(newField + " - " + Y, newField, DataType.CELL, 2, cellRanges.get(newField)[2])); + fieldItems.addCellFieldItem(new FieldItem(newField + " - " + Z, newField, DataType.CELL, 3, cellRanges.get(newField)[3])); + } else { + fieldItems.addCellFieldItem(new FieldItem(newField, newField, DataType.CELL, -1, cellRanges.get(newField)[0])); + } + } else { + logger.warn("No cell range for {}", newField); + } + } + } + + private void readPointFieldItems(VTKOpenFOAMReader reader) { + List allDataSets = new ArrayList<>(); + allDataSets.addAll(patchesDataset.values()); + allDataSets.addAll(faceZonesDataset); + allDataSets.addAll(cellZonesDataset); + + Map pointRanges = VTKUtil.getPointFieldsRanges(allDataSets); + for (String newField : reader.getPointArrayNames()) { + if (pointRanges.containsKey(newField)) { + if (newField.startsWith(U)) { + fieldItems.addPointFieldItem(new FieldItem(newField + " - " + MAGNITUDE, newField, DataType.POINT, 0, pointRanges.get(newField)[0])); + fieldItems.addPointFieldItem(new FieldItem(newField + " - " + X, newField, DataType.POINT, 1, pointRanges.get(newField)[1])); + fieldItems.addPointFieldItem(new FieldItem(newField + " - " + Y, newField, DataType.POINT, 2, pointRanges.get(newField)[2])); + fieldItems.addPointFieldItem(new FieldItem(newField + " - " + Z, newField, DataType.POINT, 3, pointRanges.get(newField)[3])); + } else { + fieldItems.addPointFieldItem(new FieldItem(newField, newField, DataType.POINT, -1, pointRanges.get(newField)[0])); + } + } else { + logger.warn("No point range for {}", newField); + } + } + } + + private void readTimeSteps(VTKOpenFOAMReader reader) { + vtkExecutive exe = reader.GetExecutive(); + vtkCompositeDataPipeline pipeline = (vtkCompositeDataPipeline) exe; + vtkInformation outInfo = exe.GetOutputInformation(0); + + vtkInformationDoubleVectorKey timeStepsKey = pipeline.TIME_STEPS(); + int nTimeSteps = outInfo.Length(timeStepsKey); // Get the number of time steps + List ts = new ArrayList<>(); + for (int i = 0; i < nTimeSteps; i++) { + double timeValue = outInfo.Get(timeStepsKey, i); + ts.add(Double.valueOf(timeValue)); + } + this.timesteps = ts; + } + + private void readBounds(VTKOpenFOAMReader reader) { + List allDataSets = new ArrayList<>(); + allDataSets.addAll(patchesDataset.values()); + allDataSets.addAll(faceZonesDataset); + allDataSets.addAll(cellZonesDataset); + this.bounds = VTKUtil.calculateBounds(allDataSets); + } + + public BoundingBox getBounds() { + return bounds; + } + + public List getTimesteps() { + return timesteps; + } + + public List getCellZonesDataset() { + return cellZonesDataset; + } + + public Map getPatchesDataset() { + return patchesDataset; + } + + public List getFaceZonesDataset() { + return faceZonesDataset; + } + + public void clear() { + for (vtkDataObject obj : patchesDataset.values()) { + obj.Delete(); + } + for (vtkDataObject obj : faceZonesDataset) { + obj.Delete(); + } + for (vtkDataObject obj : cellZonesDataset) { + obj.Delete(); + } + } + +} diff --git a/src/eu/engys/vtk/FaceZoneActor.java b/src/eu/engys/vtk/FaceZoneActor.java new file mode 100644 index 0000000..4ffd869 --- /dev/null +++ b/src/eu/engys/vtk/FaceZoneActor.java @@ -0,0 +1,46 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.vtk; + +import eu.engys.core.project.zero.facezones.FaceZone; +import eu.engys.util.ui.checkboxtree.VisibleItem; +import eu.engys.vtk.actors.DefaultActor; +import vtk.vtkPolyData; + +public class FaceZoneActor extends DefaultActor { + + private VisibleItem zone; + + public FaceZoneActor(FaceZone zone, vtkPolyData dataset) { + super(zone.getName()); + this.zone = zone; + newActor(dataset, true); + } + + @Override + public VisibleItem getVisibleItem() { + return zone; + } +} \ No newline at end of file diff --git a/src/eu/engys/vtk/GeometryContext.java b/src/eu/engys/vtk/GeometryContext.java index 997a3ed..673cdb2 100644 --- a/src/eu/engys/vtk/GeometryContext.java +++ b/src/eu/engys/vtk/GeometryContext.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.vtk; import java.util.LinkedHashMap; @@ -31,22 +30,12 @@ import java.util.Map; import eu.engys.core.project.geometry.Surface; import eu.engys.gui.view3D.Actor; import eu.engys.gui.view3D.Context; -import eu.engys.gui.view3D.Representation; public class GeometryContext extends Context { private ActorsMap actorsMap; private Map actorsVisibility; - // private Map actorsProperty; - - public GeometryContext(Representation representation, Map actorsMap) { - super(representation); - this.actorsMap = new ActorsMap(actorsMap); - this.actorsVisibility = initActorsVisibility(actorsMap); - // this.actorsProperty = initActorsProperty(actorsMap); - } - @Override public boolean isEmpty() { return actorsMap.isEmpty(); @@ -57,6 +46,13 @@ public class GeometryContext extends Context { actorsVisibility.clear(); } + public ActorsMap getActorsMap() { + return actorsMap; + } + public void setActorsMap(Map actorsMap) { + this.actorsMap = new ActorsMap(actorsMap); + this.actorsVisibility = initActorsVisibility(actorsMap); + } private Map initActorsVisibility(Map actorsMap) { Map map = new LinkedHashMap<>(); for (Surface surface : actorsMap.keySet()) { @@ -65,11 +61,6 @@ public class GeometryContext extends Context { } return map; } - - public ActorsMap getActorsMap() { - return actorsMap; - } - public Map getActorsVisibility() { return actorsVisibility; } diff --git a/src/eu/engys/vtk/HelyxView3DEventListener.java b/src/eu/engys/vtk/HelyxView3DEventListener.java index 471ece6..5c254db 100644 --- a/src/eu/engys/vtk/HelyxView3DEventListener.java +++ b/src/eu/engys/vtk/HelyxView3DEventListener.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.vtk; @@ -40,15 +39,16 @@ import eu.engys.gui.events.view3D.LayersCoverageEvent; import eu.engys.gui.events.view3D.MeshQualityEvent; import eu.engys.gui.events.view3D.PlaneEvent; import eu.engys.gui.events.view3D.PointEvent; +import eu.engys.gui.events.view3D.RotatedBoxEvent; import eu.engys.gui.events.view3D.SelectionEvent; import eu.engys.gui.events.view3D.VolumeReportEvent; import eu.engys.gui.events.view3D.VolumeReportVisibilityEvent; import eu.engys.gui.events.view3D.VolumeReportVisibilityEvent.Kind; import eu.engys.gui.view3D.CanvasPanel; import eu.engys.gui.view3D.LayerInfo; -import eu.engys.gui.view3D.QualityInfo; import eu.engys.gui.view3D.Selection; import eu.engys.gui.view3D.View3DEventListener; +import eu.engys.gui.view3D.quality.QualityInfo; import eu.engys.util.ui.textfields.DoubleField; public class HelyxView3DEventListener implements View3DEventListener { @@ -69,28 +69,43 @@ public class HelyxView3DEventListener implements View3DEventListener { String key = ((PointEvent) event).getKey(); EventActionType action = ((PointEvent) event).getAction(); Color color = ((PointEvent) event).getColor(); - view3D.showPoint(point, key, action, color); + view3D.showPoint(key, point, action, color); } else if (event instanceof AxisEvent) { AxisEvent e = (AxisEvent) event; DoubleField[] origin = e.getAxisInfo().getCenter(); DoubleField[] normal = e.getAxisInfo().getAxis(); + DoubleField angle1 = e.getAxisInfo().getCamber(); + DoubleField angle2 = e.getAxisInfo().getToe(); + double magnitude = e.getAxisInfo().getMagnitude(); + int sign = e.getAxisInfo().getSign(); EventActionType action = e.getAxisInfo().getAction(); - view3D.showAxis(origin, normal, action); + if (normal != null) { + view3D.showAxis(origin, normal, magnitude, action); + } else { + view3D.showAxis(origin, angle1, angle2, magnitude, sign, action); + } } else if (event instanceof PlaneEvent) { + String key = ((PlaneEvent) event).getKey(); DoubleField[] origin = ((PlaneEvent) event).getOrigin(); DoubleField[] normal = ((PlaneEvent) event).getNormal(); EventActionType action = ((PlaneEvent) event).getAction(); boolean interactive = ((PlaneEvent) event).isInteractive(); if (interactive) { - view3D.showPlane(origin, normal, action); + view3D.showPlane(key, origin, normal, action); } else { - view3D.showPlaneDisplay(origin, normal, action); + view3D.showPlaneDisplay(key, origin, normal, action); } } else if (event instanceof BoxEvent) { DoubleField[] min = ((BoxEvent) event).getMin(); DoubleField[] max = ((BoxEvent) event).getMax(); EventActionType action = ((BoxEvent) event).getAction(); view3D.showBox(min, max, action); + } else if (event instanceof RotatedBoxEvent) { + DoubleField[] center = ((RotatedBoxEvent) event).getCenter(); + DoubleField[] delta = ((RotatedBoxEvent) event).getDelta(); + DoubleField[] rotation = ((RotatedBoxEvent) event).getRotation(); + EventActionType action = ((RotatedBoxEvent) event).getAction(); + view3D.showRotatedBox(center, delta, rotation, action); } else if (event instanceof SelectionEvent) { Selection selection = ((SelectionEvent) event).getSelection(); EventActionType action = ((SelectionEvent) event).getAction(); diff --git a/src/eu/engys/vtk/InteractorStyle.java b/src/eu/engys/vtk/InteractorStyle.java deleted file mode 100644 index f5dbea6..0000000 --- a/src/eu/engys/vtk/InteractorStyle.java +++ /dev/null @@ -1,105 +0,0 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - -package eu.engys.vtk; - -import vtk.vtkInteractorStyleTrackballCamera; - -public class InteractorStyle extends vtkInteractorStyleTrackballCamera { - - public InteractorStyle() { - super(); - AddObserver("MouseMoveEvent", this, "OnMouseMove"); - AddObserver("LeftButtonPressEvent", this, "leftButtonPressed"); - AddObserver("MiddleButtonPressEvent", this, "middleButtonPressed"); - AddObserver("RightButtonPressEvent", this, "rightButtonPressed"); - AddObserver("LeftButtonReleaseEvent", this, "leftButtonReleased"); - AddObserver("MiddleButtonReleaseEvent", this, "middleButtonReleased"); - AddObserver("RightButtonReleaseEvent", this, "rightButtonReleased"); - } - - public void leftButtonPressed() { - System.out.println("InteractorStyle.leftButtonPressed()"); -// buttonDown(getLastPos(), 0); - } - - public void middleButtonPressed() { - System.out.println("InteractorStyle.middleButtonPressed()"); -// buttonDown(getLastPos(), 1); - } - - public void rightButtonPressed() { - System.out.println("InteractorStyle.rightButtonPressed()"); -// buttonDown(getLastPos(), 2); - } - - public void leftButtonReleased() { - System.out.println("InteractorStyle.leftButtonReleased()"); -// buttonUp(getLastPos(), 0); - } - - public void middleButtonReleased() { - System.out.println("InteractorStyle.middleButtonReleased()"); -// buttonUp(getLastPos(), 1); - } - - public void rightButtonReleased() { - System.out.println("InteractorStyle.rightButtonReleased()"); -// buttonUp(getLastPos(), 2); - } - - public void OnMouseMove() { - System.out.println("InteractorStyle.OnMouseMove() " + GetState()); -// int x = GetInteractor().GetEventPosition()[0]; -// int y = GetInteractor().GetEventPosition()[1]; -// switch(GetState()) -// { -// case 1: // '\001' -// postText(INTERACTOR_ACTION_ROTATE); -// Rotate(); -// InvokeEvent("InteractionEvent"); -// break; -// -// case 2: // '\002' -// postText(INTERACTOR_ACTION_PAN); -// Pan(); -// InvokeEvent("InteractionEvent"); -// break; -// -// case 4: // '\004' -// postText(INTERACTOR_ACTION_ZOOM); -// Dolly(); -// InvokeEvent("InteractionEvent"); -// break; -// -// case 3: // '\003' -// postText(INTERACTOR_ACTION_ROLL); -// Spin(); -// InvokeEvent("InteractionEvent"); -// break; -// } - } - -} diff --git a/src/eu/engys/vtk/InternalMeshReader.java b/src/eu/engys/vtk/InternalMeshReader.java new file mode 100644 index 0000000..d6be22a --- /dev/null +++ b/src/eu/engys/vtk/InternalMeshReader.java @@ -0,0 +1,166 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.vtk; + +import static eu.engys.core.project.mesh.FieldItem.MAGNITUDE; +import static eu.engys.core.project.mesh.FieldItem.X; +import static eu.engys.core.project.mesh.FieldItem.Y; +import static eu.engys.core.project.mesh.FieldItem.Z; +import static eu.engys.core.project.zero.fields.Fields.U; + +import java.io.File; +import java.util.Map; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import eu.engys.core.project.mesh.FieldItem; +import eu.engys.core.project.mesh.FieldItem.DataType; +import eu.engys.util.progress.ProgressMonitor; +import vtk.vtkDataObject; +import vtk.vtkMultiBlockDataSet; +import vtk.vtkUnstructuredGrid; + +public class InternalMeshReader extends AbstractMeshReader { + + static final String INTERNAL_MESH = "internalMesh"; + + private static final Logger logger = LoggerFactory.getLogger(InternalMeshReader.class); + + private vtkUnstructuredGrid internalMeshDataset = null; + + public InternalMeshReader(File baseDir, boolean parallel, ProgressMonitor monitor) { + super(baseDir, parallel, monitor); + } + + public void read(double timeStep) { + VTKOpenFOAMReader reader = new VTKOpenFOAMReader(baseDir, parallel, monitor);//, "Internal"); + reader.UpdateInformation(); + reader.ReadPatchesOff(); + reader.ReadInternalMeshOn(); + reader.ReadZonesOff(); + reader.setTimeStep(timeStep); + reader.Update(); + + vtkMultiBlockDataSet dataset = reader.GetOutput(); + try { + + if (VTKUtil.isSingleRegion(dataset)) { + readSingleRegionInternalMesh(dataset); + } else { + readMultiRegionInternalMesh(dataset); + } + + readFieldItems(reader); + + } catch (Exception e) { + logger.error(e.getMessage(), e); + } finally { + dataset.Delete(); + reader.Delete(); + } + } + + private void readMultiRegionInternalMesh(vtkMultiBlockDataSet dataset) { + int numberOfBlocks = dataset.GetNumberOfBlocks(); + if (numberOfBlocks > 0) { + logger.debug("READ [MULTI] [INTERNAL] blocks are: {}", VTKUtil.logBlockNames(dataset)); + + vtkDataObject defaultRegion = VTKUtil.getBlock(VTKUtil.DEFAULT_REGION, dataset); + if (defaultRegion != null) { + readSingleRegionInternalMesh((vtkMultiBlockDataSet) defaultRegion); + } else { + logger.warn("READ [MULTI] [INTERNAL]: {} NOT FOUND", VTKUtil.DEFAULT_REGION); + } + } else { + logger.warn("READ [MULTI] [INTERNAL]: EMPTY"); + } + } + + private void readSingleRegionInternalMesh(vtkMultiBlockDataSet dataset) { + int numberOfBlocks = dataset.GetNumberOfBlocks(); + if (numberOfBlocks > 0) { + logger.debug("READ [SINGLE] [INTERNAL] blocks are: {}", VTKUtil.logBlockNames(dataset)); + + vtkDataObject internalMesh = VTKUtil.getBlock(INTERNAL_MESH, dataset); + if (internalMesh != null) { + extractInternalDataset(internalMesh); + } else { + logger.warn("READ [SINGLE] [INTERNAL]: {} NOT FOUND", INTERNAL_MESH); + } + } else { + logger.warn("READ [SINGLE] [INTERNAL]: EMPTY!"); + } + } + + private void extractInternalDataset(vtkDataObject block) { + this.internalMeshDataset = VTKUtil.shallowCopy((vtkUnstructuredGrid) block); + } + + private void readFieldItems(VTKOpenFOAMReader reader) { + readCellFieldItems(reader); + readPointFieldItems(reader); + } + + private void readCellFieldItems(VTKOpenFOAMReader reader) { + Map cellRanges = VTKUtil.getCellFieldsRanges(internalMeshDataset); + for (String newField : reader.getCellArrayNames()) { + if (newField.startsWith(U)) { + fieldItems.addCellFieldItem(new FieldItem(newField + " - " + MAGNITUDE, newField, DataType.CELL, 0, cellRanges.get(newField)[0])); + fieldItems.addCellFieldItem(new FieldItem(newField + " - " + X, newField, DataType.CELL, 1, cellRanges.get(newField)[1])); + fieldItems.addCellFieldItem(new FieldItem(newField + " - " + Y, newField, DataType.CELL, 2, cellRanges.get(newField)[2])); + fieldItems.addCellFieldItem(new FieldItem(newField + " - " + Z, newField, DataType.CELL, 3, cellRanges.get(newField)[3])); + } else { + fieldItems.addCellFieldItem(new FieldItem(newField, newField, DataType.CELL, -1, cellRanges.get(newField)[0])); + } + } + } + + private void readPointFieldItems(VTKOpenFOAMReader reader) { + Map pointRanges = VTKUtil.getPointFieldsRanges(internalMeshDataset); + for (String newField : reader.getPointArrayNames()) { + if (newField.startsWith(U)) { + fieldItems.addPointFieldItem(new FieldItem(newField + " - " + MAGNITUDE, newField, DataType.POINT, 0, pointRanges.get(newField)[0])); + fieldItems.addPointFieldItem(new FieldItem(newField + " - " + X, newField, DataType.POINT, 1, pointRanges.get(newField)[1])); + fieldItems.addPointFieldItem(new FieldItem(newField + " - " + Y, newField, DataType.POINT, 2, pointRanges.get(newField)[2])); + fieldItems.addPointFieldItem(new FieldItem(newField + " - " + Z, newField, DataType.POINT, 3, pointRanges.get(newField)[3])); + } else { + fieldItems.addPointFieldItem(new FieldItem(newField, newField, DataType.POINT, -1, pointRanges.get(newField)[0])); + } + } + } + + public vtkUnstructuredGrid getInternalMeshDataset() { + return internalMeshDataset; + } + + public void clear() { + if (internalMeshDataset != null) { + internalMeshDataset.Delete(); + internalMeshDataset = null; + } + } + +} diff --git a/src/eu/engys/vtk/MeshContext.java b/src/eu/engys/vtk/MeshContext.java index 6188b68..7452e59 100644 --- a/src/eu/engys/vtk/MeshContext.java +++ b/src/eu/engys/vtk/MeshContext.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.vtk; import java.util.LinkedHashMap; @@ -30,82 +29,100 @@ import java.util.Map; import eu.engys.gui.view3D.Actor; import eu.engys.gui.view3D.Context; -import eu.engys.gui.view3D.Representation; public class MeshContext extends Context { - + private boolean allowSelection; private Map patches; private Map patchesVisibility; - private Map cellzones; - private Map zonesVisibility; + private Map faceZones; + private Map faceZonesVisibility; - public MeshContext(Representation representation, boolean allowSelection, Map cellzones, Map patches) { - super(representation); - this.allowSelection = allowSelection; - - this.patches = new LinkedHashMap<>(patches); - this.patchesVisibility = initPatchesVisibility(patches); - - this.cellzones = new LinkedHashMap<>(cellzones); - this.zonesVisibility = initZonesVisibility(cellzones); - } + private Map cellZones; + private Map cellZonesVisibility; + + private Map internalMesh; + private Map internalMeshVisibility; public void clear() { patches.clear(); patchesVisibility.clear(); - zonesVisibility.clear(); - cellzones.clear(); + cellZones.clear(); + cellZonesVisibility.clear(); + faceZones.clear(); + faceZonesVisibility.clear(); } - private Map initPatchesVisibility(Map patches) { - Map map = new LinkedHashMap<>(); - for (String name : patches.keySet()) { - Actor actor = patches.get(name); - map.put(name, actor.getVisibility()); - } - return map; - } - - private Map initZonesVisibility(Map cellzones) { - Map map = new LinkedHashMap<>(); - for (String name : cellzones.keySet()) { - Actor actor = cellzones.get(name); - map.put(name, actor.getVisibility()); - } - return map; - } - @Override public boolean isEmpty() { return patches.isEmpty(); } - - public boolean isAllowSelection(){ + + public boolean isAllowSelection() { return allowSelection; } - + public void setAllowSelection(boolean allowSelection) { + this.allowSelection = allowSelection; + } + public Map getPatches() { return patches; } - + public void setPatches(Map patches) { + this.patches = new LinkedHashMap<>(patches); + this.patchesVisibility = initVisibility(patches); + } public Map getPatchesVisibility() { return patchesVisibility; } - - public Map getCellzones() { - return cellzones; + + public Map getFaceZones() { + return faceZones; } - - public Map getZonesVisibility() { - return zonesVisibility; + public void setFaceZones(Map faceZones) { + this.faceZones = new LinkedHashMap<>(faceZones); + this.faceZonesVisibility = initVisibility(faceZones); + } + public Map getFaceZonesVisibility() { + return faceZonesVisibility; } + public Map getCellZones() { + return cellZones; + } + public void setCellZones(Map cellZones) { + this.cellZones = new LinkedHashMap<>(cellZones); + this.cellZonesVisibility = initVisibility(cellZones); + } + public Map getCellZonesVisibility() { + return cellZonesVisibility; + } + + public Map getInternalMesh() { + return internalMesh; + } + public void setInternalMesh(Map internalMesh) { + this.internalMesh = new LinkedHashMap<>(internalMesh); + this.internalMeshVisibility = initVisibility(internalMesh); + } + public Map getInternalMeshVisibility() { + return internalMeshVisibility; + } + + private Map initVisibility(Map actors) { + Map map = new LinkedHashMap<>(); + for (String name : actors.keySet()) { + Actor actor = actors.get(name); + map.put(name, actor.getVisibility()); + } + return map; + } + @Override public String toString() { - return "MeshContext [ repres = " + representation + ", zones are " + cellzones.keySet().size() + ", patches are " + patches.keySet().size() + "]"; + return "MeshContext [ rep = " + representation + ", CellZones = " + cellZones.keySet().size() + ", FaceZones = " + faceZones.keySet().size() + ", Patches = " + patches.keySet().size() + "]"; } } diff --git a/src/eu/engys/vtk/PatchActor.java b/src/eu/engys/vtk/PatchActor.java index 39fc430..9034790 100644 --- a/src/eu/engys/vtk/PatchActor.java +++ b/src/eu/engys/vtk/PatchActor.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.vtk; import eu.engys.core.project.zero.patches.Patch; @@ -42,4 +41,4 @@ public class PatchActor extends DefaultActor { public VisibleItem getVisibleItem() { return patch; } -} +} \ No newline at end of file diff --git a/src/eu/engys/vtk/ReaderProgress.java b/src/eu/engys/vtk/ReaderProgress.java index 39961d5..a18b875 100644 --- a/src/eu/engys/vtk/ReaderProgress.java +++ b/src/eu/engys/vtk/ReaderProgress.java @@ -1,33 +1,32 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.vtk; -import vtk.vtkAlgorithm; import eu.engys.util.progress.ProgressMonitor; +import vtk.vtkAlgorithm; public class ReaderProgress { private vtkAlgorithm reader; diff --git a/src/eu/engys/vtk/RenderPanelAdapter.java b/src/eu/engys/vtk/RenderPanelAdapter.java index 8ad8fce..e9b47ad 100644 --- a/src/eu/engys/vtk/RenderPanelAdapter.java +++ b/src/eu/engys/vtk/RenderPanelAdapter.java @@ -1,40 +1,40 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.vtk; import java.awt.Color; import java.awt.event.KeyListener; -import vtk.vtkAssembly; -import vtk.vtkImageData; import eu.engys.gui.view3D.Actor; +import eu.engys.gui.view3D.CameraManager; import eu.engys.gui.view3D.CameraManager.Position; import eu.engys.gui.view3D.Interactor; import eu.engys.gui.view3D.RenderPanel; import eu.engys.gui.view3D.Representation; +import vtk.vtkAssembly; +import vtk.vtkImageData; public class RenderPanelAdapter implements RenderPanel { @@ -110,6 +110,10 @@ public class RenderPanelAdapter implements RenderPanel { @Override public void addActor(vtkAssembly cor) { } + + @Override + public void removeActor(vtkAssembly cor) { + } @Override public void addActor(Actor actor) { @@ -122,16 +126,23 @@ public class RenderPanelAdapter implements RenderPanel { @Override public void selectActors(boolean keep, Actor... pickedActor) { } - + + @Override + public void filterActors(Actor... actors) { + } + @Override public void setLowRendering() { - } @Override public void setHighRendering() { } + @Override + public void DestroyTimer() { + } + @Override public void setActorColor(Color c, Actor... actor) { } @@ -161,6 +172,11 @@ public class RenderPanelAdapter implements RenderPanel { return null; } + @Override + public CameraManager getCameraManager() { + return null; + } + @Override public Interactor getInteractor() { return null; diff --git a/src/eu/engys/vtk/TimeStepsReader.java b/src/eu/engys/vtk/TimeStepsReader.java new file mode 100644 index 0000000..7f36331 --- /dev/null +++ b/src/eu/engys/vtk/TimeStepsReader.java @@ -0,0 +1,82 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.vtk; + +import java.util.ArrayList; +import java.util.List; + +import eu.engys.core.project.Model; +import eu.engys.util.progress.ProgressMonitor; +import vtk.vtkCompositeDataPipeline; +import vtk.vtkExecutive; +import vtk.vtkInformation; +import vtk.vtkInformationDoubleVectorKey; + +public class TimeStepsReader { + + private Model model; + private ProgressMonitor monitor; + + private List timesteps; + + public TimeStepsReader(Model model, ProgressMonitor monitor) { + this.model = model; + this.monitor = monitor; + } + + public void read(double timeStep) { + VTKOpenFOAMReader reader = new VTKOpenFOAMReader(model.getProject().getBaseDir(), model.getProject().isParallel(), monitor);//, "Time Steps"); + reader.UpdateInformation(); + reader.ReadInternalMeshOff(); + reader.ReadPatchesOff(); + reader.ReadZonesOff(); + reader.setTimeStep(timeStep); + reader.Update(); + + readTimeSteps(reader); + reader.Delete(); + } + + private void readTimeSteps(VTKOpenFOAMReader reader) { + vtkExecutive exe = reader.GetExecutive(); + vtkCompositeDataPipeline pipeline = (vtkCompositeDataPipeline) exe; + vtkInformation outInfo = exe.GetOutputInformation(0); + + vtkInformationDoubleVectorKey timeStepsKey = pipeline.TIME_STEPS(); + int nTimeSteps = outInfo.Length(timeStepsKey); // Get the number of time + // steps + List ts = new ArrayList<>(); + for (int i = 0; i < nTimeSteps; i++) { + double timeValue = outInfo.Get(timeStepsKey, i); + ts.add(Double.valueOf(timeValue)); + } + this.timesteps = ts; + } + + public List getTimesteps() { + return timesteps; + } + +} diff --git a/src/eu/engys/vtk/VTK3DActionsToolBar.java b/src/eu/engys/vtk/VTK3DActionsToolBar.java index 28e5e80..db9fd08 100644 --- a/src/eu/engys/vtk/VTK3DActionsToolBar.java +++ b/src/eu/engys/vtk/VTK3DActionsToolBar.java @@ -1,29 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.vtk; import static eu.engys.util.ui.UiUtil.createButtonBarToggleButton; @@ -40,66 +38,71 @@ import eu.engys.core.project.Model; import eu.engys.gui.view3D.Context; import eu.engys.gui.view3D.Controller3D; import eu.engys.util.plaf.ILookAndFeel; +import eu.engys.util.ui.UiUtil; -public class VTK3DActionsToolBar extends JToolBar { +public class VTK3DActionsToolBar { + + private static final String ACTIONS_TOOLBAR_NAME = "3d.actions.toolbar"; static final String _3D_LOAD_MESH = "3d.load.mesh"; - + static final String _3D_AXIS_XPOS = "3d.axis.xpos"; static final String _3D_AXIS_XNEG = "3d.axis.xneg"; static final String _3D_AXIS_YPOS = "3d.axis.ypos"; static final String _3D_AXIS_YNEG = "3d.axis.yneg"; static final String _3D_AXIS_ZPOS = "3d.axis.zpos"; static final String _3D_AXIS_ZNEG = "3d.axis.zneg"; - + static final String _3D_ZOOM_RESET = "3d.zoom.reset"; static final String _3D_ZOOM_TOBOX = "3d.zoom.tobox"; static final String _3D_ZOOM_OUT = "3d.zoom.out"; static final String _3D_ZOOM_IN = "3d.zoom.in"; - + static final String _3D_VIEW_PROJECTIONS = "3d.view.projections"; static final String _3D_VIEW_OUTLINE = "3d.view.outline"; static final String _3D_VIEW_PROFILE = "3d.view.profile"; static final String _3D_VIEW_EDGES = "3d.view.edges"; static final String _3D_VIEW_SURFACE = "3d.view.surface"; static final String _3D_VIEW_WIREFRAME = "3d.view.wireframe"; + + // static final String _3D_LOCATION = "3d.view.location"; + // static final String _3D_COR = "3d.view.cor"; + private Model model; + private JToolBar toolbar; + public VTK3DActionsToolBar(Model model, ILookAndFeel laf) { - super(JToolBar.VERTICAL); + super(); this.model = model; - putClientProperty("Synthetica.toolBar.buttons.paintBorder", Boolean.TRUE); - putClientProperty("Synthetica.opaque", Boolean.FALSE); - setFloatable(false); - setRollover(true); - setOpaque(false); + this.toolbar = UiUtil.getToolbar(ACTIONS_TOOLBAR_NAME, JToolBar.VERTICAL); layoutComponents(); } private void layoutComponents() { - add(createToolBarButton(ActionManager.getInstance().get(_3D_ZOOM_IN))); - add(createToolBarButton(ActionManager.getInstance().get(_3D_ZOOM_OUT))); - add(createToolBarButton(ActionManager.getInstance().get(_3D_ZOOM_TOBOX))); - add(createToolBarButton(ActionManager.getInstance().get(_3D_ZOOM_RESET))); - addSeparator(); - add(createToolBarButton(ActionManager.getInstance().get(_3D_AXIS_XPOS))); - add(createToolBarButton(ActionManager.getInstance().get(_3D_AXIS_XNEG))); - add(createToolBarButton(ActionManager.getInstance().get(_3D_AXIS_YPOS))); - add(createToolBarButton(ActionManager.getInstance().get(_3D_AXIS_YNEG))); - add(createToolBarButton(ActionManager.getInstance().get(_3D_AXIS_ZPOS))); - add(createToolBarButton(ActionManager.getInstance().get(_3D_AXIS_ZNEG))); - addSeparator(); + toolbar.add(createToolBarButton(ActionManager.getInstance().get(_3D_ZOOM_IN))); + toolbar.add(createToolBarButton(ActionManager.getInstance().get(_3D_ZOOM_OUT))); + toolbar.add(createToolBarButton(ActionManager.getInstance().get(_3D_ZOOM_TOBOX))); + toolbar.add(createToolBarButton(ActionManager.getInstance().get(_3D_ZOOM_RESET))); + toolbar.addSeparator(); + toolbar.add(createToolBarButton(ActionManager.getInstance().get(_3D_AXIS_XPOS))); + toolbar.add(createToolBarButton(ActionManager.getInstance().get(_3D_AXIS_XNEG))); + toolbar.add(createToolBarButton(ActionManager.getInstance().get(_3D_AXIS_YPOS))); + toolbar.add(createToolBarButton(ActionManager.getInstance().get(_3D_AXIS_YNEG))); + toolbar.add(createToolBarButton(ActionManager.getInstance().get(_3D_AXIS_ZPOS))); + toolbar.add(createToolBarButton(ActionManager.getInstance().get(_3D_AXIS_ZNEG))); + toolbar.addSeparator(); ButtonGroup viewGroup = new ButtonGroup(); - add(createButtonBarToggleButton(ActionManager.getInstance().get(_3D_VIEW_WIREFRAME), viewGroup)); - add(createButtonBarToggleButton(ActionManager.getInstance().get(_3D_VIEW_SURFACE), viewGroup)); - add(createButtonBarToggleButton(ActionManager.getInstance().get(_3D_VIEW_EDGES), viewGroup)); - add(createButtonBarToggleButton(ActionManager.getInstance().get(_3D_VIEW_PROFILE), viewGroup)); - add(createButtonBarToggleButton(ActionManager.getInstance().get(_3D_VIEW_OUTLINE), viewGroup)); - add(createToolBarToggleButton(ActionManager.getInstance().get(_3D_VIEW_PROJECTIONS))); + toolbar.add(createButtonBarToggleButton(ActionManager.getInstance().get(_3D_VIEW_WIREFRAME), viewGroup)); + toolbar.add(createButtonBarToggleButton(ActionManager.getInstance().get(_3D_VIEW_SURFACE), viewGroup)); + toolbar.add(createButtonBarToggleButton(ActionManager.getInstance().get(_3D_VIEW_EDGES), viewGroup)); + toolbar.add(createButtonBarToggleButton(ActionManager.getInstance().get(_3D_VIEW_PROFILE), viewGroup)); + toolbar.add(createButtonBarToggleButton(ActionManager.getInstance().get(_3D_VIEW_OUTLINE), viewGroup)); + toolbar.add(createToolBarToggleButton(ActionManager.getInstance().get(_3D_VIEW_PROJECTIONS))); } public void update(List controllers) { - Context context = getaContext(controllers); + Context context = getaContext(controllers); if (context != null) { ActionManager.getInstance().get(_3D_VIEW_PROJECTIONS).setEnabled(true); ActionManager.getInstance().get(_3D_VIEW_WIREFRAME).setEnabled(true); @@ -109,64 +112,64 @@ public class VTK3DActionsToolBar extends JToolBar { ActionManager.getInstance().get(_3D_VIEW_OUTLINE).setEnabled(true); switch (context.getRepresentation()) { - case WIREFRAME: - ActionManager.getInstance().get(_3D_VIEW_WIREFRAME).setSelected(true); - break; - case SURFACE: - ActionManager.getInstance().get(_3D_VIEW_SURFACE).setSelected(true); - break; - case SURFACE_WITH_EDGES: - ActionManager.getInstance().get(_3D_VIEW_EDGES).setSelected(true); - break; - case OUTLINE: - ActionManager.getInstance().get(_3D_VIEW_OUTLINE).setSelected(true); - break; - case PROFILE: - ActionManager.getInstance().get(_3D_VIEW_PROFILE).setSelected(true); - break; + case WIREFRAME: + ActionManager.getInstance().get(_3D_VIEW_WIREFRAME).setSelected(true); + break; + case SURFACE: + ActionManager.getInstance().get(_3D_VIEW_SURFACE).setSelected(true); + break; + case SURFACE_WITH_EDGES: + ActionManager.getInstance().get(_3D_VIEW_EDGES).setSelected(true); + break; + case OUTLINE: + ActionManager.getInstance().get(_3D_VIEW_OUTLINE).setSelected(true); + break; + case PROFILE: + ActionManager.getInstance().get(_3D_VIEW_PROFILE).setSelected(true); + break; } -// if (context instanceof MeshContext) { -// MeshContext mc = (MeshContext) context; -// ActionManager.getInstance().get(_3D_LOAD_MESH).setEnabled(!model.getPatches().isEmpty() && mc.isEmpty()); -// } + // if (context instanceof MeshContext) { + // MeshContext mc = (MeshContext) context; + // ActionManager.getInstance().get(_3D_LOAD_MESH).setEnabled(!model.getPatches().isEmpty() && mc.isEmpty()); + // } } else { - ActionManager.getInstance().get(_3D_VIEW_WIREFRAME).setEnabled(false); + ActionManager.getInstance().get(_3D_VIEW_WIREFRAME).setEnabled(false); ActionManager.getInstance().get(_3D_VIEW_SURFACE).setEnabled(false); ActionManager.getInstance().get(_3D_VIEW_EDGES).setEnabled(false); ActionManager.getInstance().get(_3D_VIEW_PROFILE).setEnabled(false); ActionManager.getInstance().get(_3D_VIEW_OUTLINE).setEnabled(false); ActionManager.getInstance().get(_3D_VIEW_PROJECTIONS).setEnabled(false); } - + MeshContext mContext = (MeshContext) getMeshContext(controllers); - if(mContext != null){ + if (mContext != null) { ActionManager.getInstance().get(_3D_LOAD_MESH).setEnabled(!model.getPatches().isEmpty() && mContext.isEmpty()); } } - private Context getaContext(List controllers) { - for (Controller3D c : controllers) { - Context context = c.getCurrentContext(); - if (context != null) { - return context; - } - } - return null; - } + private Context getaContext(List controllers) { + for (Controller3D c : controllers) { + Context context = c.getCurrentContext(); + if (context != null) { + return context; + } + } + return null; + } - private Context getMeshContext(List controllers) { - for (Controller3D c : controllers) { - Context context = c.getCurrentContext(); - if (context != null && context instanceof MeshContext) { - return context; - } - } - return null; - } + private Context getMeshContext(List controllers) { + for (Controller3D c : controllers) { + Context context = c.getCurrentContext(); + if (context != null && context instanceof MeshContext) { + return context; + } + } + return null; + } - public void clear() { - ActionManager.getInstance().get(_3D_VIEW_WIREFRAME).setSelected(false); - ActionManager.getInstance().get(_3D_VIEW_SURFACE).setSelected(false); + public void clear() { + ActionManager.getInstance().get(_3D_VIEW_WIREFRAME).setSelected(false); + ActionManager.getInstance().get(_3D_VIEW_SURFACE).setSelected(false); ActionManager.getInstance().get(_3D_VIEW_EDGES).setSelected(false); ActionManager.getInstance().get(_3D_VIEW_PROFILE).setSelected(false); ActionManager.getInstance().get(_3D_VIEW_OUTLINE).setSelected(false); @@ -178,5 +181,9 @@ public class VTK3DActionsToolBar extends JToolBar { ActionManager.getInstance().get(_3D_VIEW_PROFILE).setEnabled(false); ActionManager.getInstance().get(_3D_VIEW_OUTLINE).setEnabled(false); ActionManager.getInstance().get(_3D_VIEW_PROJECTIONS).setEnabled(false); - } + } + + public JToolBar getToolbar() { + return toolbar; + } } diff --git a/src/eu/engys/vtk/VTKActors.java b/src/eu/engys/vtk/VTKActors.java index 981d1fa..dd6ad88 100644 --- a/src/eu/engys/vtk/VTKActors.java +++ b/src/eu/engys/vtk/VTKActors.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.vtk; import java.util.Collection; @@ -38,6 +37,7 @@ public interface VTKActors { public abstract boolean containsActor(Actor pickedActor); public abstract Map getActorsMap(); + public abstract void addActorsMap(Map map, Map visibility); void setRenderPanel(RenderPanel renderPanel); } diff --git a/src/eu/engys/vtk/VTKCameraManager.java b/src/eu/engys/vtk/VTKCameraManager.java index d13bd21..57e286d 100644 --- a/src/eu/engys/vtk/VTKCameraManager.java +++ b/src/eu/engys/vtk/VTKCameraManager.java @@ -1,32 +1,31 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.vtk; -import vtk.vtkRenderer; import eu.engys.gui.view3D.CameraManager; +import vtk.vtkRenderer; public class VTKCameraManager implements CameraManager { @@ -36,7 +35,18 @@ public class VTKCameraManager implements CameraManager { this.vtkRenderPanel = vtkRenderPanel; } - + @Override + public double[] getCameraDirection() { + vtkRenderer renderer = vtkRenderPanel.GetRenderer(); + return renderer.GetActiveCamera().GetDirectionOfProjection(); + } + + @Override + public double[] getFocusPoint() { + vtkRenderer renderer = vtkRenderPanel.GetRenderer(); + return renderer.GetActiveCamera().GetFocalPoint(); + } + public void setCameraPosition(Position pos) { vtkRenderer renderer = vtkRenderPanel.GetRenderer(); double[] fp = renderer.GetActiveCamera().GetFocalPoint(); diff --git a/src/eu/engys/vtk/VTKCellZones.java b/src/eu/engys/vtk/VTKCellZones.java index 9c83de5..e694849 100644 --- a/src/eu/engys/vtk/VTKCellZones.java +++ b/src/eu/engys/vtk/VTKCellZones.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.vtk; import java.util.ArrayList; @@ -35,16 +34,13 @@ import java.util.Map; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import vtk.vtkDataObject; -import vtk.vtkPolyData; -import vtk.vtkUnstructuredGrid; import eu.engys.core.project.Model; import eu.engys.core.project.zero.cellzones.CellZone; -import eu.engys.core.project.zero.facezones.FaceZone; import eu.engys.gui.view3D.Actor; +import eu.engys.gui.view3D.PickInfo; import eu.engys.gui.view3D.Picker; import eu.engys.gui.view3D.RenderPanel; -import eu.engys.util.progress.ProgressMonitor; +import vtk.vtkUnstructuredGrid; public class VTKCellZones implements VTKActors, Picker { @@ -52,36 +48,29 @@ public class VTKCellZones implements VTKActors, Picker { private Map actors = new LinkedHashMap<>(); private Map names = new LinkedHashMap<>(); + private RenderPanel renderPanel; private Model model; - private ProgressMonitor monitor; - public VTKCellZones(Model model, ProgressMonitor monitor) { + public VTKCellZones(Model model) { this.model = model; - this.monitor = monitor; } @Override public void setRenderPanel(RenderPanel renderPanel) { this.renderPanel = renderPanel; } - - public void load(List cellZonesDataset) { + + public void load(List cellZonesDataset) { for (int i = 0; i < cellZonesDataset.size(); i++) { - vtkDataObject dataset = cellZonesDataset.get(i); - - if (dataset instanceof vtkPolyData) { - FaceZone zone = model.getFaceZones().get(i); - zone.setLoaded(true); - addActorToZones(new CellZoneActor(zone, (vtkPolyData) dataset)); - } else if (dataset instanceof vtkUnstructuredGrid) { - CellZone zone = model.getCellZones().get(i); - zone.setLoaded(true); - addActorToZones(new CellZoneActor(zone, (vtkUnstructuredGrid) dataset)); - } + vtkUnstructuredGrid dataset = cellZonesDataset.get(i); + + CellZone zone = model.getCellZones().get(i); + zone.setLoaded(true); + addActorToZones(new CellZoneActor(zone, dataset)); } } - + void addActorToZones(Actor actor) { logger.debug("[ADD ACTOR] {} ({})", actor.getName(), actor.getVisibility() ? "visible" : "hidden"); actors.put(actor.getName(), actor); @@ -95,15 +84,6 @@ public class VTKCellZones implements VTKActors, Picker { } } - public void addCellZonesMap(Map map, Map visibility) { - for (String name : map.keySet()) { - Actor actor = map.get(name); - actor.setVisibility(visibility.get(name)); - addActorToZones(actor); - renderPanel.addActor(actor); - } - } - public void deleteActors() { for (Actor actor : actors.values()) { renderPanel.removeActor(actor); @@ -126,6 +106,12 @@ public class VTKCellZones implements VTKActors, Picker { actor.setVisibility(false); } } + + public void VisibilityOn() { + for (Actor actor : actors.values()) { + actor.setVisibility(true); + } + } public Collection getActors() { return actors.values(); @@ -135,16 +121,6 @@ public class VTKCellZones implements VTKActors, Picker { return names.containsKey(pickedActor); } -// @Override -// public String getActorName(Actor pickedActor) { -// return names.get(pickedActor); -// } - - @Override - public boolean canPickCells(Actor pickedActor) { - return false; - } - @Override public boolean canPickMesh() { return true; @@ -152,7 +128,7 @@ public class VTKCellZones implements VTKActors, Picker { public void selectActors(CellZone[] zones) { logger.debug("updateSurfaceVisibility: {} zones selected {}", zones.length, zones.length == 1 ? ", selection is: " + zones[0] : ""); - + List selection = new ArrayList(); for (CellZone zone : zones) { String name = zone.getName(); @@ -172,19 +148,15 @@ public class VTKCellZones implements VTKActors, Picker { } renderPanel.renderLater(); } - - public void update(List cellZonesDataset) { + + public void update(List cellZonesDataset) { List actorsList = new ArrayList<>(getActors()); for (int i = 0; i < cellZonesDataset.size(); i++) { - vtkDataObject obj = cellZonesDataset.get(i); + vtkUnstructuredGrid obj = cellZonesDataset.get(i); Actor actor = actorsList.get(i); - if (obj instanceof vtkPolyData) { - logger.debug("Update polydata {}", names.get(actor)); - VTKUtil.changeDataset(actor, (vtkPolyData) obj); - } else if (obj instanceof vtkUnstructuredGrid) { - logger.debug("Update unstructured_grid {}", names.get(actor)); - VTKUtil.changeDataset(actor, (vtkUnstructuredGrid) obj); - } + logger.debug("Update unstructured_grid {}", names.get(actor)); +// VTKUtil.changeDataset(actor, obj); + actor.setInput(obj); } } @@ -193,8 +165,22 @@ public class VTKCellZones implements VTKActors, Picker { return Collections.unmodifiableMap(actors); } + @Override + public void addActorsMap(Map map, Map visibility) { + for (String name : map.keySet()) { + Actor actor = map.get(name); + actor.setVisibility(visibility.get(name)); + addActorToZones(actor); + renderPanel.addActor(actor); + } + } + public boolean isLoaded() { return !actors.isEmpty(); } + @Override + public void pickActor(PickInfo pi) { + } + } diff --git a/src/eu/engys/vtk/VTKColors.java b/src/eu/engys/vtk/VTKColors.java index b205a93..6e33333 100644 --- a/src/eu/engys/vtk/VTKColors.java +++ b/src/eu/engys/vtk/VTKColors.java @@ -1,38 +1,37 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.vtk; import java.awt.Color; import java.util.ArrayList; import java.util.List; -import vtk.vtkLookupTable; import eu.engys.core.project.mesh.FieldItem; import eu.engys.core.project.mesh.ScalarBarType; import eu.engys.gui.view3D.Actor; +import vtk.vtkLookupTable; public class VTKColors { @@ -71,13 +70,6 @@ public class VTKColors { public ScalarsColor to(VTKActors actors) { this.actors.addAll(actors.getActors()); - - if (field.isAutomaticRange()) { - new VTKRangeCalculator(field).calculateRange_Automatically_For(actors); - } else { - // use existing range - } - return this; } @@ -92,35 +84,30 @@ public class VTKColors { } public static void applyTypeToLookupTable(FieldItem fieldItem, vtkLookupTable table) { - // Vector Mode - if (fieldItem.getComponent() <= 0) { - table.SetVectorModeToMagnitude(); - } else { + if (fieldItem.getComponentIndex() > 0) { + // Ux Uy Uz table.SetVectorModeToComponent(); - table.SetVectorComponent(fieldItem.getComponent() - 1); + table.SetVectorComponent(fieldItem.getComponentIndex() - 1); + } else { + table.SetVectorModeToMagnitude(); } - // Range - table.SetRange(fieldItem.getRange()); + if (fieldItem.isScalar()) { + table.SetRange(fieldItem.range()); + } // Colors ScalarBarType scalarBarType = fieldItem.getScalarBarType(); - List colors = scalarBarType.getColors(fieldItem.getResolution()); - if (scalarBarType.equals(ScalarBarType.RED_TO_BLUE_RAINBOW) || scalarBarType.equals(ScalarBarType.BLUE_TO_RED_RAINBOW)) { - table.SetNumberOfTableValues(fieldItem.getResolution()); - table.SetHueRange(scalarBarType.getColors(-1).get(0)); - table.ForceBuild(); - } else { - table.SetNumberOfTableValues(colors.size()); - for (int i = 0; i < colors.size(); i++) { - double[] values = colors.get(i); - double red = values[0]; - double green = values[1]; - double blue = values[2]; - table.SetTableValue(i, red, green, blue, 1); - } - table.Build(); + List colors = scalarBarType.getColors(fieldItem); + table.SetNumberOfTableValues(colors.size()); + for (int i = 0; i < colors.size(); i++) { + double[] values = colors.get(i); + double red = values[0]; + double green = values[1]; + double blue = values[2]; + table.SetTableValue(i, red, green, blue, 1); } + table.Build(); } static class IndexedColor { diff --git a/src/eu/engys/vtk/VTKEmptyView3D.java b/src/eu/engys/vtk/VTKEmptyView3D.java index 194c594..0b5dfb1 100644 --- a/src/eu/engys/vtk/VTKEmptyView3D.java +++ b/src/eu/engys/vtk/VTKEmptyView3D.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.vtk; import java.awt.AlphaComposite; @@ -56,9 +55,9 @@ import eu.engys.gui.view3D.Controller3D; import eu.engys.gui.view3D.Geometry3DController; import eu.engys.gui.view3D.LayerInfo; import eu.engys.gui.view3D.Mesh3DController; -import eu.engys.gui.view3D.QualityInfo; import eu.engys.gui.view3D.RenderPanel; import eu.engys.gui.view3D.Selection; +import eu.engys.gui.view3D.quality.QualityInfo; import eu.engys.gui.view3D.widget.Widget; import eu.engys.util.ApplicationInfo; import eu.engys.util.progress.ProgressMonitor; @@ -158,9 +157,12 @@ public class VTKEmptyView3D extends JPanel implements CanvasPanel { } @Override - public void load() { + public void load(boolean loadMesh) { for (Controller3D context : controllers) { - logger.info("[LOAD] {}", context.getClass().getSimpleName()); + logger.info("[LOAD 3D] {}", context.getClass().getSimpleName()); + if (context instanceof Mesh3DController && !loadMesh) { + continue; + } context.loadActors(); } } @@ -189,21 +191,37 @@ public class VTKEmptyView3D extends JPanel implements CanvasPanel { } @Override - public void showPoint(DoubleField[] point, String key, EventActionType action, Color color) { + public void showRotatedBox(DoubleField[] center, DoubleField[] delta, DoubleField[] rotation, EventActionType actions) { } @Override - public void showPlane(DoubleField[] origin, DoubleField[] normal, EventActionType actions) { + public void showPoint(String key, DoubleField[] point, EventActionType action, Color color) { } @Override - public void showPlaneDisplay(DoubleField[] origin, DoubleField[] normal, EventActionType actions) { + public void showPlane(String key, DoubleField[] origin, DoubleField[] normal, EventActionType actions) { } @Override - public void showAxis(DoubleField[] origin, DoubleField[] normal, EventActionType actions) { + public void showPlaneDisplay(String key, DoubleField[] origin, DoubleField[] normal, EventActionType actions) { } + @Override + public void showAxis(DoubleField[] origin, DoubleField[] normal, double magnitude, EventActionType actions) { + } + + @Override + public void showAxis(DoubleField[] origin, DoubleField angle1, DoubleField angle2, double magnitude, int sign, EventActionType actions) { + } + + // @Override + // public void activateCOR(EventActionType action) { + // } + // + // @Override + // public void activateLocation(EventActionType action) { + // } + @Override public void activateSelection(Selection selection, EventActionType action) { } diff --git a/src/eu/engys/vtk/VTKFaceZones.java b/src/eu/engys/vtk/VTKFaceZones.java new file mode 100644 index 0000000..f2c88b4 --- /dev/null +++ b/src/eu/engys/vtk/VTKFaceZones.java @@ -0,0 +1,186 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.vtk; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import eu.engys.core.project.Model; +import eu.engys.core.project.zero.facezones.FaceZone; +import eu.engys.gui.view3D.Actor; +import eu.engys.gui.view3D.PickInfo; +import eu.engys.gui.view3D.Picker; +import eu.engys.gui.view3D.RenderPanel; +import vtk.vtkPolyData; + +public class VTKFaceZones implements VTKActors, Picker { + + private static final Logger logger = LoggerFactory.getLogger(VTKFaceZones.class); + + private Map actors = new LinkedHashMap<>(); + private Map names = new LinkedHashMap<>(); + + private RenderPanel renderPanel; + private Model model; + + public VTKFaceZones(Model model) { + this.model = model; + } + + @Override + public void setRenderPanel(RenderPanel renderPanel) { + this.renderPanel = renderPanel; + } + + public void load(List faceZonesDataset) { + for (int i = 0; i < faceZonesDataset.size(); i++) { + vtkPolyData dataset = faceZonesDataset.get(i); + + FaceZone zone = model.getFaceZones().get(i); + zone.setLoaded(true); + addActorToZones(new FaceZoneActor(zone, dataset)); + } + } + + void addActorToZones(Actor actor) { + logger.debug("[ADD ACTOR] {} ({})", actor.getName(), actor.getVisibility() ? "visible" : "hidden"); + actors.put(actor.getName(), actor); + names.put(actor, actor.getName()); + } + + void addActorsToRenderer() { + for (String name : actors.keySet()) { + Actor actor = actors.get(name); + renderPanel.addActor(actor); + } + } + + public void deleteActors() { + for (Actor actor : actors.values()) { + renderPanel.removeActor(actor); + actor.deleteActor(); + } + actors.clear(); + names.clear(); + } + + public void removeActorsFromRenderer() { + for (Actor actor : actors.values()) { + renderPanel.removeActor(actor); + } + actors.clear(); + names.clear(); + } + + public void VisibilityOff() { + for (Actor actor : actors.values()) { + actor.setVisibility(false); + } + } + + public void VisibilityOn() { + for (Actor actor : actors.values()) { + actor.setVisibility(true); + } + } + + public Collection getActors() { + return actors.values(); + } + + public boolean containsActor(Actor pickedActor) { + return names.containsKey(pickedActor); + } + + @Override + public boolean canPickMesh() { + return true; + } + + public void selectActors(FaceZone[] zones) { + logger.debug("updateSurfaceVisibility: {} zones selected {}", zones.length, zones.length == 1 ? ", selection is: " + zones[0] : ""); + + List selection = new ArrayList(); + for (FaceZone zone : zones) { + String name = zone.getName(); + if (zone.isVisible() && actors.containsKey(name)) { + selection.add(actors.get(name)); + } + } + renderPanel.setLowRendering(); + renderPanel.selectActors(false, selection.toArray(new Actor[0])); + renderPanel.setHighRendering(); + } + + public void updateVisibility(FaceZone[] selection) { + for (FaceZone cellZone : selection) { + Actor actor = actors.get(cellZone.getName()); + actor.setVisibility(cellZone.isVisible()); + } + renderPanel.renderLater(); + } + + public void update(List cellZonesDataset) { + List actorsList = new ArrayList<>(getActors()); + for (int i = 0; i < cellZonesDataset.size(); i++) { + vtkPolyData obj = cellZonesDataset.get(i); + Actor actor = actorsList.get(i); + logger.debug("Update polydata {}", names.get(actor)); +// VTKUtil.changeDataset(actor, obj); + actor.setInput(obj); + } + } + + @Override + public Map getActorsMap() { + return Collections.unmodifiableMap(actors); + } + + @Override + public void addActorsMap(Map map, Map visibility) { + for (String name : map.keySet()) { + Actor actor = map.get(name); + actor.setVisibility(visibility.get(name)); + addActorToZones(actor); + renderPanel.addActor(actor); + } + } + + public boolean isLoaded() { + return !actors.isEmpty(); + } + + @Override + public void pickActor(PickInfo pi) { + } + +} diff --git a/src/eu/engys/vtk/VTKGeometry3DController.java b/src/eu/engys/vtk/VTKGeometry3DController.java index b9b1a36..9a558ee 100644 --- a/src/eu/engys/vtk/VTKGeometry3DController.java +++ b/src/eu/engys/vtk/VTKGeometry3DController.java @@ -1,34 +1,32 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.vtk; import java.awt.Color; import java.util.ArrayList; import java.util.Collection; -import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -38,7 +36,6 @@ import javax.inject.Inject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import eu.engys.core.Arguments; import eu.engys.core.controller.GeometryToMesh; import eu.engys.core.project.Model; import eu.engys.core.project.geometry.BoundingBox; @@ -48,9 +45,7 @@ import eu.engys.core.project.geometry.Type; import eu.engys.core.project.geometry.stl.AffineTransform; import eu.engys.core.project.geometry.surface.Plane; import eu.engys.core.project.geometry.surface.Region; -import eu.engys.core.project.geometry.surface.Solid; import eu.engys.core.project.geometry.surface.Stl; -import eu.engys.core.project.mesh.FieldItem; import eu.engys.gui.events.EventManager; import eu.engys.gui.events.view3D.View3DEvent; import eu.engys.gui.view.View3DElement; @@ -58,11 +53,11 @@ import eu.engys.gui.view3D.Actor; import eu.engys.gui.view3D.Context; import eu.engys.gui.view3D.Geometry3DController; import eu.engys.gui.view3D.Geometry3DEventListener; +import eu.engys.gui.view3D.PickInfo; import eu.engys.gui.view3D.Picker; import eu.engys.gui.view3D.RenderPanel; import eu.engys.gui.view3D.Representation; import eu.engys.util.progress.ProgressMonitor; -import eu.engys.util.ui.checkboxtree.VisibleItem; import eu.engys.vtk.actors.SurfaceToActor; import eu.engys.vtk.actors.SurfaceToActor.ActorMode; @@ -71,7 +66,7 @@ public class VTKGeometry3DController implements Geometry3DController, Picker { private static final Logger logger = LoggerFactory.getLogger(VTKGeometry3DController.class); protected RenderPanel renderPanel; - private final Model model; + protected final Model model; private final ProgressMonitor monitor; private final ActorsMap actorsMap = new ActorsMap(); @@ -95,21 +90,19 @@ public class VTKGeometry3DController implements Geometry3DController, Picker { @Override public void loadActors() { - if (Arguments.load3Dgeometry) { - isLoading = true; + isLoading = true; - Geometry geometry = model.getGeometry(); + Geometry geometry = model.getGeometry(); - monitor.info("-> Actors"); - _addSurfaces(geometry.getSurfaces()); - _addSurfaces(geometry.getLines().toArray()); + monitor.info("-> Actors"); + _addSurfaces(geometry.getSurfaces()); + _addSurfaces(geometry.getLines().toArray()); - if (geometry.hasBlock()) { - _addSurfaces(geometry.getBlock()); - } - - isLoading = false; + if (geometry.hasBlock()) { + _addSurfaces(geometry.getBlock()); } + + isLoading = false; } @Override @@ -241,7 +234,38 @@ public class VTKGeometry3DController implements Geometry3DController, Picker { } } } + + @Override + public void updateSurfacesFilter(Surface... surfaces) { + logger.debug("[FILTER] {} surfaces filtered {}", surfaces.length, surfaces.length == 1 ? ", selection is: " + surfaces[0].getName() : ""); + List selection = new ArrayList(); + + _updateSurfacesFilter(surfaces, selection); + + // if (selection.isEmpty()) { + // logger.debug("updateSurfacesSelection: NONE selected!"); + // } else { + if (!actorsMap.isEmpty()) { + renderPanel.filterActors(selection.toArray(new Actor[0])); + } + // } + + } + + private void _updateSurfacesFilter(Surface[] surfaces, List selection) { + for (Surface surface : surfaces) { + if (surface.hasRegions() && surface.isSingleton()) { + _updateSurfacesFilter(surface.getRegions(), selection); + continue; + } + if (surface.isVisible() && actorsMap.contains(surface)) { + selection.add(actorsMap.get(surface)); + } + } + } + + @Override public void updateSurfacesSelection(Surface... surfaces) { logger.debug("[SELECTION] {} surfaces selected {}", surfaces.length, surfaces.length == 1 ? ", selection is: " + surfaces[0].getName() : ""); @@ -390,7 +414,7 @@ public class VTKGeometry3DController implements Geometry3DController, Picker { return VTKUtil.computeBoundingBox(actors); } - private Collection getListOfSurfaceActors(Surface[] surfaces) { + protected Collection getListOfSurfaceActors(Surface[] surfaces) { Collection list = new ArrayList<>(); for (Surface surface : surfaces) { if (surface.getType().isStl()) { @@ -427,10 +451,6 @@ public class VTKGeometry3DController implements Geometry3DController, Picker { } } - @Override - public void showField(FieldItem fieldItem) { - } - private Map, GeometryContext> contextMap = new HashMap<>(); private GeometryContext context; @@ -475,14 +495,20 @@ public class VTKGeometry3DController implements Geometry3DController, Picker { @Override public void newContext(Class klass) { - GeometryContext context = new GeometryContext(Representation.SURFACE, getActorsMap()); + GeometryContext context = new GeometryContext(); + context.setRepresentation(Representation.SURFACE); + context.setActorsMap(getActorsMap()); + contextMap.put(klass, context); logger.info("[NEW CONTEXT] for {} is {}", klass.getSimpleName(), context); } @Override public void newEmptyContext(Class klass) { - GeometryContext context = new GeometryContext(Representation.SURFACE, Collections. emptyMap()); + GeometryContext context = new GeometryContext(); + context.setRepresentation(Representation.SURFACE); + context.setActorsMap(getActorsMap()); + contextMap.put(klass, context); logger.info("[EMPTY CONTEXT] for {} is {}", klass.getSimpleName(), context); } @@ -492,7 +518,11 @@ public class VTKGeometry3DController implements Geometry3DController, Picker { if (contextMap.containsKey(klass)) { contextMap.remove(klass).clear(); } - GeometryContext context = new GeometryContext(renderPanel.getRepresentation(), actorsMap.getDelegate()); + + GeometryContext context = new GeometryContext(); + context.setRepresentation(renderPanel.getRepresentation()); + context.setActorsMap(getActorsMap()); + logger.info("[DUMP CONTEXT] for {} is {}", klass.getSimpleName(), context); contextMap.put(klass, context); } @@ -521,15 +551,13 @@ public class VTKGeometry3DController implements Geometry3DController, Picker { return actorsMap.getDelegate(); } - @Override - public boolean canPickCells(Actor pickedActor) { - VisibleItem surface = pickedActor.getVisibleItem(); - return (surface instanceof Stl || surface instanceof Solid); - } - @Override public boolean canPickMesh() { return false; } + @Override + public void pickActor(PickInfo pi) { + } + } diff --git a/src/eu/engys/vtk/VTKInteractor.java b/src/eu/engys/vtk/VTKInteractor.java index bac3035..8d9517f 100644 --- a/src/eu/engys/vtk/VTKInteractor.java +++ b/src/eu/engys/vtk/VTKInteractor.java @@ -1,64 +1,84 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.vtk; +import java.util.ArrayList; +import java.util.List; + +import eu.engys.gui.view3D.Interactor; import vtk.vtkGenericRenderWindowInteractor; import vtk.vtkInteractorObserver; -import vtk.vtkInteractorStyle; +import vtk.vtkInteractorStyleHelyx; import vtk.vtkInteractorStyleRubberBand3D; import vtk.vtkInteractorStyleRubberBandZoom; -import vtk.vtkInteractorStyleTrackballCamera; import vtk.vtkRenderWindow; -import eu.engys.gui.view3D.Interactor; public class VTKInteractor extends vtkGenericRenderWindowInteractor implements Interactor { + private List listeners = new ArrayList<>(); + public VTKInteractor(vtkRenderWindow rw) { - vtkInteractorStyle style = new vtkInteractorStyleTrackballCamera(); SetRenderWindow(rw); - SetInteractorStyle(style); + setStyleToDefault(); -// iren.AddObserver("TimerEvent", this, "TimerEvent"); -// iren.AddObserver("CreateTimerEvent", this, "StartTimer"); -// iren.AddObserver("DestroyTimerEvent", this, "DestroyTimer"); +// AddObserver("TimerEvent", this, "TimerEvent"); +// AddObserver("CreateTimerEvent", this, "StartTimer"); +// AddObserver("DestroyTimerEvent", this, "DestroyTimer"); // -// iren.SetDesiredUpdateRate(HIGHEST_RATE); -// iren.SetStillUpdateRate(LOW_RATE); +// SetDesiredUpdateRate(HIGHEST_RATE); +// SetStillUpdateRate(LOW_RATE); +// VTKUtil.observe(this, "INTER"); +// style.AddObserver("InteractionEvent", this, "InteractionEvent"); } +// public void InteractionEvent() { +// vtkInteractorObserver style = GetInteractorStyle(); +// if (style instanceof vtkInteractorStyleTrackballCamera) { +// int state = ((vtkInteractorStyleTrackballCamera) style).GetState(); +// for (InteractorListener l : listeners) { +// switch (state) { +// case 1: l.rotate(); break; +// case 2: l.pan(); break; +// case 3: l.spin(); break; +// case 4: l.zoom(); break; +// +// default: break; +// } +// } +// } +// } + @Override public void setStyleToDefault() { - System.out.println("VTKInteractor.setStyleToDefault()<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"); - SetInteractorStyle(new vtkInteractorStyleTrackballCamera()); +// SetInteractorStyle(new vtkInteractorStyleTrackballCamera()); + SetInteractorStyle(new vtkInteractorStyleHelyx()); } @Override public void setStyleToArea() { - System.out.println("VTKInteractor.setStyleToArea() >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"); SetInteractorStyle(new vtkInteractorStyleRubberBand3D()); } @@ -80,7 +100,6 @@ public class VTKInteractor extends vtkGenericRenderWindowInteractor implements I @Override public void updateSize(int w, int h) { SetSize(w, h); - // rw.SetSize(w, h); ConfigureEvent(); } @@ -98,4 +117,31 @@ public class VTKInteractor extends vtkGenericRenderWindowInteractor implements I public void addObserver(vtkInteractorObserver widget) { widget.SetInteractor(this); } + + @Override + public void addListener(InteractorListener l) { + listeners.add(l); + } + + @Override + public void removeListener(InteractorListener l) { + listeners.remove(l); + } + + @Override + public double[] getCenter() { + if (GetInteractorStyle() instanceof vtkInteractorStyleHelyx) { + vtkInteractorStyleHelyx hs = (vtkInteractorStyleHelyx) GetInteractorStyle(); + return hs.GetCenter(); + } + return new double[3]; + } + + @Override + public void setCenter(double[] center) { + if (GetInteractorStyle() instanceof vtkInteractorStyleHelyx) { + vtkInteractorStyleHelyx hs = (vtkInteractorStyleHelyx) GetInteractorStyle(); + hs.SetCenter(center); + } + } } diff --git a/src/eu/engys/vtk/VTKInternalMesh.java b/src/eu/engys/vtk/VTKInternalMesh.java index cc452f8..cf164a9 100644 --- a/src/eu/engys/vtk/VTKInternalMesh.java +++ b/src/eu/engys/vtk/VTKInternalMesh.java @@ -1,104 +1,261 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.vtk; +import java.io.File; import java.util.Arrays; import java.util.Collection; import java.util.Collections; +import java.util.HashMap; +import java.util.List; import java.util.Map; -import vtk.vtkCutter; -import vtk.vtkDataObject; -import vtk.vtkExtractGeometry; -import vtk.vtkPlane; -import vtk.vtkTableBasedClipDataSet; -import vtk.vtkUnstructuredGrid; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import eu.engys.gui.view3D.Actor; import eu.engys.gui.view3D.RenderPanel; import eu.engys.util.progress.ProgressMonitor; import eu.engys.vtk.actors.InternalMeshActor; +import vtk.vtkAlgorithm; +import vtk.vtkContourFilter; +import vtk.vtkCutter; +import vtk.vtkExtractGeometry; +import vtk.vtkPlane; +import vtk.vtkPolyData; +import vtk.vtkSTLWriter; +import vtk.vtkSmoothPolyDataFilter; +import vtk.vtkTableBasedClipDataSet; +import vtk.vtkUnstructuredGrid; public class VTKInternalMesh implements VTKActors { - private Actor actor; + class Clip { + + private vtkPlane plane; + private boolean insideOut; + + public Clip(vtkPlane plane, boolean insideOut) { + this.plane = plane; + this.insideOut = insideOut; + } + + public void update(vtkUnstructuredGrid internalMeshDataset) { + vtkTableBasedClipDataSet clipper = new vtkTableBasedClipDataSet(); + clipper.SetInputData(internalMeshDataset); + clipper.SetClipFunction(plane); + if (insideOut) { + clipper.InsideOutOn(); + } else { + clipper.InsideOutOff(); + } + + updateInAThread(UPDATING_CLIPPER, clipper); + + vtkUnstructuredGrid output = clipper.GetOutput(); + VTKUtil.printTotalMemory(output); + +// deleteActor(); +// VTKUtil.gc(false); + +// VTKInternalMeshNew.this.actor = new InternalMeshActor(output); + + actor.interactiveOff(); + actor.setInput(output); + + output.Delete(); + clipper.Delete(); + } + + public void delete() { +// clipper.RemoveAllInputs(); +// clipper.Delete(); + } + } + + class Slice { + + private vtkPlane plane; + private List values; + + public Slice(vtkPlane plane, List values) { + this.plane = plane; + this.values = values; + } + + public void update(vtkUnstructuredGrid internalMeshDataset) { + vtkCutter slicer = new vtkCutter(); + slicer.SetInputData(internalMeshDataset); + slicer.GenerateTrianglesOff(); + slicer.SetCutFunction(plane); + +// slicer.SetNumberOfContours(values.size()); +// for (int i = 0; i < values.size(); i++) { +// slicer.SetValue(i, values.get(i)); +// } + + updateInAThread(UPDATING_SLICER, slicer); + + vtkPolyData output = slicer.GetOutput(); + VTKUtil.printTotalMemory(output); + + actor.interactiveOff(); + actor.setInput(slicer.GetOutput()); + + output.Delete(); + slicer.Delete(); + } + + public void delete() { +// +// slicer.RemoveAllInputs(); +// slicer.Delete(); + } + + } + class Crinkle { + + private vtkPlane plane; + + public Crinkle(vtkPlane plane) { + this.plane = plane; + } + + public void update(vtkUnstructuredGrid internalMeshDataset) { + vtkExtractGeometry crinkle = new vtkExtractGeometry(); + crinkle.SetInputData(internalMeshDataset); + crinkle.ExtractInsideOn(); + crinkle.ExtractOnlyBoundaryCellsOn(); + crinkle.ExtractBoundaryCellsOn(); + crinkle.SetImplicitFunction(plane); + + updateInAThread(UPDATING_CRINKLE, crinkle); + + vtkUnstructuredGrid output = crinkle.GetOutput(); + VTKUtil.printTotalMemory(output); + + actor.interactiveOff(); + actor.setInput(output); + + output.Delete(); + crinkle.Delete(); + } + + public void delete() { +// crinkle.RemoveAllInputs(); +// crinkle.Delete(); + } + } + + private static final Logger logger = LoggerFactory.getLogger(VTKInternalMesh.class); + + private static final String UPDATING_CONTOUR_AND_SMOOTH = "Updating contour and smooth"; + private static final String UPDATING_CRINKLE = "Updating crinkle"; + private static final String UPDATING_CLIPPER = "Updating clipper"; + private static final String UPDATING_SLICER = "Updating slicer"; + private InternalMeshActor actor; private RenderPanel renderPanel; - private vtkCutter slicer; - private vtkExtractGeometry crinkle; - private vtkTableBasedClipDataSet clipper; + private Clip clipper; + private Slice slicer; + private Crinkle crinkle; + +// private vtkCutter slicer; +// private vtkExtractGeometry crinkle; + private vtkContourFilter contour; + private vtkSmoothPolyDataFilter smooth; private vtkUnstructuredGrid internalMeshDataset; + private ProgressMonitor monitor; public VTKInternalMesh(ProgressMonitor monitor) { + this.monitor = monitor; } @Override public void setRenderPanel(RenderPanel renderPanel) { this.renderPanel = renderPanel; } - - public void update(vtkDataObject dataset) { + + public void update(final vtkUnstructuredGrid dataSet) { + VTKUtil.printTotalMemory(dataSet); if (actor != null) { - renderPanel.removeActor(actor); - - load(dataset); - - VisibilityOn(); - +// hide(); + +// deleteActor(); + deleteDataSet(); + + VTKUtil.gc(false); + + this.internalMeshDataset = VTKUtil.shallowCopy(dataSet); +// this.actor = new InternalMeshActor(new vtkUnstructuredGrid()); + if (slicer != null) { - slicer.SetInputData(internalMeshDataset); - slicer.Update(); - connectActorToSlicer(); + slicer.update(internalMeshDataset); } else if (clipper != null) { - clipper.SetInputData(internalMeshDataset); - clipper.Update(); - connectActorToClipper(); + clipper.update(internalMeshDataset); } else if (crinkle != null) { - crinkle.SetInputData(internalMeshDataset); - crinkle.Update(); - connectActorToCrinkler(); + crinkle.update(internalMeshDataset); + } else if (contour != null && smooth != null) { + contour.SetInputData(internalMeshDataset); + updateInAThread(UPDATING_CONTOUR_AND_SMOOTH, contour, smooth); + connectActorToSmoothedContour(); + } else { + actor.setInput(internalMeshDataset); } - - renderPanel.addActor(actor); + +// show(); + + logger.debug("Update internalMesh"); } } - - public void load(vtkDataObject internalMeshDataset) { + public void load(vtkUnstructuredGrid dataSet) { + VTKUtil.printTotalMemory(dataSet); + + deleteActor(); + deleteDataSet(); + + VTKUtil.gc(false); + + this.internalMeshDataset = VTKUtil.shallowCopy(dataSet); + this.actor = new InternalMeshActor(internalMeshDataset); + } + + private void deleteDataSet() { if (this.internalMeshDataset != null) { - VTKUtil.deleteDataset(this.internalMeshDataset); + VTKUtil.deleteDataset(internalMeshDataset); + this.internalMeshDataset = null; } + } + private void deleteActor() { if (this.actor != null) { this.actor.deleteActor(); + this.actor = null; } - - this.internalMeshDataset = new vtkUnstructuredGrid(); - this.internalMeshDataset.ShallowCopy((vtkUnstructuredGrid) internalMeshDataset); - this.actor = new InternalMeshActor(this.internalMeshDataset); } public void deleteActors() { @@ -109,6 +266,8 @@ public class VTKInternalMesh implements VTKActors { deleteClipper(); deleteSlicer(); + deleteCrinkle(); + deleteContourAndSmooth(); } } @@ -116,39 +275,52 @@ public class VTKInternalMesh implements VTKActors { if (actor != null) { renderPanel.removeActor(actor); } - actor = null; } private void deleteSlicer() { if (slicer != null) { - slicer.RemoveAllInputs(); - slicer.Delete(); + slicer.delete(); slicer = null; } } private void deleteClipper() { if (clipper != null) { - clipper.RemoveAllInputs(); - clipper.Delete(); + clipper.delete(); clipper = null; } } private void deleteCrinkle() { if (crinkle != null) { - crinkle.RemoveAllInputs(); - crinkle.Delete(); + crinkle.delete(); crinkle = null; } } + private void deleteContourAndSmooth() { + if (contour != null) { + contour.RemoveAllInputs(); + contour.Delete(); + contour = null; + } + if (smooth != null) { + smooth.RemoveAllInputs(); + smooth.Delete(); + smooth = null; + } + } + public void VisibilityOff() { if (actor != null) { actor.setVisibility(false); } } + public boolean isVisible() { + return actor != null && actor.getVisibility(); + } + public void VisibilityOn() { if (actor != null) { actor.setVisibility(true); @@ -156,24 +328,32 @@ public class VTKInternalMesh implements VTKActors { } public void disconnectFilters() { - actor.setInput(internalMeshDataset); - deleteClipper(); deleteSlicer(); deleteCrinkle(); + deleteContourAndSmooth(); + + if (actor != null) { + actor.setInput(internalMeshDataset); + } } public boolean isLoaded() { return actor != null; } + public void hide() { + renderPanel.removeActor(actor); + } + public void show() { + actor.VisibilityOn(); renderPanel.addActor(actor); } @Override public Collection getActors() { - return actor != null ? Arrays.asList(actor) : Collections. emptyList(); + return actor != null ? Arrays.asList(actor) : Collections. emptyList(); } @Override @@ -181,27 +361,29 @@ public class VTKInternalMesh implements VTKActors { return false; } - public void clip(vtkPlane plane) { + public void clip(vtkPlane plane, boolean insideOut) { +// hide(); + deleteClipper(); deleteSlicer(); deleteCrinkle(); - clipper = new vtkTableBasedClipDataSet(); - clipper.SetInputData(internalMeshDataset); - clipper.SetClipFunction(plane); - clipper.InsideOutOff(); - clipper.Update(); - - connectActorToClipper(); - + clipper = new Clip(plane, insideOut); + clipper.update(internalMeshDataset); + +// show(); renderPanel.renderLater(); - - VTKUtil.gc(false); } - private void connectActorToClipper() { - actor.interactiveOff(); - actor.setInput(clipper.GetOutput()); + public void slice(vtkPlane plane, List values) { + deleteClipper(); + deleteSlicer(); + deleteCrinkle(); + + slicer = new Slice(plane, values); + slicer.update(internalMeshDataset); + + renderPanel.renderLater(); } void crinkle(vtkPlane plane) { @@ -209,60 +391,116 @@ public class VTKInternalMesh implements VTKActors { deleteSlicer(); deleteCrinkle(); - crinkle = new vtkExtractGeometry(); - crinkle.SetInputData(internalMeshDataset); - crinkle.ExtractInsideOn(); - crinkle.ExtractOnlyBoundaryCellsOn(); - crinkle.ExtractBoundaryCellsOn(); - crinkle.SetImplicitFunction(plane); - crinkle.Update(); - - connectActorToCrinkler(); - + crinkle = new Crinkle(plane); + crinkle.update(internalMeshDataset); + renderPanel.renderLater(); } - private void connectActorToCrinkler() { - actor.interactiveOff(); - actor.setInput(crinkle.GetOutput()); - } + void smoothedContour(final String field, final List values, final int smoothingIterations, final double smoothingConvergence) { + deleteContourAndSmooth(); - void slice(vtkPlane plane) { - deleteClipper(); - deleteSlicer(); - deleteCrinkle(); - - slicer = new vtkCutter(); - slicer.SetInputData(internalMeshDataset); - slicer.GenerateTrianglesOff(); - slicer.SetCutFunction(plane); - slicer.Update(); - // slicerSetNumberOfContours(nbContours); - - connectActorToSlicer(); - - renderPanel.renderLater(); - } - - private void connectActorToSlicer() { - actor.interactiveOff(); - actor.setInput(slicer.GetOutput()); - } - - void insideOut(boolean selected) { - if (selected) { - clipper.InsideOutOn(); - } else { - clipper.InsideOutOff(); + contour = new vtkContourFilter(); + contour.SetInputData(internalMeshDataset); + contour.ComputeScalarsOff(); + contour.ComputeNormalsOff(); + contour.GenerateTrianglesOn(); + contour.SetInputArrayToProcess(0, 0, 0, "vtkDataObject::FIELD_ASSOCIATION_POINTS", field); + contour.SetNumberOfContours(values.size()); + for (int i = 0; i < values.size(); i++) { + contour.SetValue(i, values.get(i)); } - clipper.Update(); - connectActorToClipper(); + smooth = new vtkSmoothPolyDataFilter(); + smooth.SetInputData(contour.GetOutput()); + smooth.SetNumberOfIterations(smoothingIterations); + smooth.SetConvergence(smoothingConvergence); + + updateInAThread(UPDATING_CONTOUR_AND_SMOOTH, contour, smooth); + + connectActorToSmoothedContour(); renderPanel.renderLater(); + + VTKUtil.gc(false); } + void exportSmoothedContourAsSTL(final File stlFile) { + vtkSTLWriter writer = new vtkSTLWriter(); + writer.SetFileName(stlFile.getAbsolutePath()); + writer.SetInputData(smooth.GetOutput()); + + writeSTLInAThread("Saving STL file " + stlFile.getAbsolutePath(), writer); + writer.Delete(); + } + + private void writeSTLInAThread(String log, final vtkSTLWriter writer) { + writer.RemoveAllObservers(); + VTKProgressMonitorWrapper progressWrapper = new VTKProgressMonitorWrapper("", writer, monitor); + writer.AddObserver("StartEvent", progressWrapper, "onStart"); + writer.AddObserver("EndEvent", progressWrapper, "onEnd"); + writer.AddObserver("ProgressEvent", progressWrapper, "onProgress"); + + monitor.setIndeterminate(false); + monitor.setTotal(100); + monitor.start(log, false, new Runnable() { + @Override + public void run() { + writer.Write(); + monitor.end(); + } + }); + } + + private void connectActorToSmoothedContour() { + actor.interactiveOff(); + actor.setInput(smooth.GetOutput()); + } + + private void updateInAThread(String log, final vtkAlgorithm... algo) { + for (vtkAlgorithm a : algo) { + a.RemoveAllObservers(); + + VTKProgressMonitorWrapper progressWrapper = new VTKProgressMonitorWrapper("", a, monitor); + a.AddObserver("StartEvent", progressWrapper, "onStart"); + a.AddObserver("EndEvent", progressWrapper, "onEnd"); + a.AddObserver("ProgressEvent", progressWrapper, "onProgress"); + } + + if (monitor.isFinished()) { + monitor.setIndeterminate(false); + monitor.setTotal(100); + monitor.start(log, false, new Runnable() { + @Override + public void run() { + for (vtkAlgorithm a : algo) { + a.Update(); + } + monitor.end(); + } + }); + } else { + for (vtkAlgorithm a : algo) { + a.Update(); + } + } + } + + @Override public Map getActorsMap() { - return null; + Map map = new HashMap<>(); + if (isLoaded()) { + map.put("internalMesh", actor); + } + return map; + } + + @Override + public void addActorsMap(Map map, Map visibility) { + if (map.size() > 0) { + this.actor = (InternalMeshActor) map.get("internalMesh"); + actor.setVisibility(visibility.get("internalMesh")); + renderPanel.addActor(actor); + } } } diff --git a/src/eu/engys/vtk/VTKInternalMeshOld.java b/src/eu/engys/vtk/VTKInternalMeshOld.java new file mode 100644 index 0000000..665381b --- /dev/null +++ b/src/eu/engys/vtk/VTKInternalMeshOld.java @@ -0,0 +1,396 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.vtk; +//package eu.engys.vtk; +// +//import java.io.File; +//import java.util.Arrays; +//import java.util.Collection; +//import java.util.Collections; +//import java.util.List; +//import java.util.Map; +// +//import vtk.vtkAlgorithm; +//import vtk.vtkContourFilter; +//import vtk.vtkCutter; +//import vtk.vtkDataObject; +//import vtk.vtkExtractGeometry; +//import vtk.vtkPlane; +//import vtk.vtkSTLWriter; +//import vtk.vtkSmoothPolyDataFilter; +//import vtk.vtkTableBasedClipDataSet; +//import vtk.vtkUnstructuredGrid; +//import eu.engys.gui.view3D.Actor; +//import eu.engys.gui.view3D.RenderPanel; +//import eu.engys.util.progress.ProgressMonitor; +//import eu.engys.vtk.actors.InternalMeshActor; +// +//public class VTKInternalMesh implements VTKActors { +// +// private static final String UPDATING_CONTOUR_AND_SMOOTH = "Updating contour and smooth"; +// private static final String UPDATING_CRINKLE = "Updating crinkle"; +// private static final String UPDATING_CLIPPER = "Updating clipper"; +// private static final String UPDATING_SLICER = "Updating slicer"; +// private Actor actor; +// private RenderPanel renderPanel; +// +// private vtkCutter slicer; +// private vtkExtractGeometry crinkle; +// private vtkTableBasedClipDataSet clipper; +// +// private vtkContourFilter contour; +// private vtkSmoothPolyDataFilter smooth; +// +// private vtkUnstructuredGrid internalMeshDataset; +// private ProgressMonitor monitor; +// +// public VTKInternalMesh(ProgressMonitor monitor) { +// this.monitor = monitor; +// } +// +// @Override +// public void setRenderPanel(RenderPanel renderPanel) { +// this.renderPanel = renderPanel; +// } +// +// public void update(final vtkDataObject dataset) { +// if (actor != null) { +// if (this.internalMeshDataset != null) { +// VTKUtil.deleteDataset(this.internalMeshDataset); +// } +// +// this.internalMeshDataset = new vtkUnstructuredGrid(); +// this.internalMeshDataset.ShallowCopy((vtkUnstructuredGrid) dataset); +// if (slicer != null) { +// slicer.SetInputData(internalMeshDataset); +// updateInAThread(UPDATING_SLICER, slicer); +// connectActorToSlicer(); +// } else if (clipper != null) { +// clipper.SetInputData(internalMeshDataset); +// updateInAThread(UPDATING_CLIPPER, clipper); +// connectActorToClipper(); +// } else if (crinkle != null) { +// crinkle.SetInputData(internalMeshDataset); +// updateInAThread(UPDATING_CRINKLE, crinkle); +// connectActorToCrinkler(); +// } else if (contour != null && smooth != null) { +// contour.SetInputData(internalMeshDataset); +// updateInAThread(UPDATING_CONTOUR_AND_SMOOTH, contour, smooth); +// connectActorToSmoothedContour(); +// } +// } +// } +// +// public void load(vtkDataObject internalMeshDataset) { +// if (this.internalMeshDataset != null) { +// VTKUtil.deleteDataset(this.internalMeshDataset); +// } +// +// if (this.actor != null) { +// this.actor.deleteActor(); +// } +// +// this.internalMeshDataset = new vtkUnstructuredGrid(); +// this.internalMeshDataset.ShallowCopy((vtkUnstructuredGrid) internalMeshDataset); +// this.actor = new InternalMeshActor(this.internalMeshDataset); +// } +// +// public void deleteActors() { +// if (actor != null) { +// renderPanel.removeActor(actor); +// actor.deleteActor(); +// actor = null; +// +// deleteClipper(); +// deleteSlicer(); +// deleteCrinkle(); +// deleteContourAndSmooth(); +// } +// } +// +// public void removeActorsFromRenderer() { +// if (actor != null) { +// renderPanel.removeActor(actor); +// } +// actor = null; +// } +// +// private void deleteSlicer() { +// if (slicer != null) { +// slicer.RemoveAllInputs(); +// slicer.Delete(); +// slicer = null; +// } +// } +// +// private void deleteClipper() { +// if (clipper != null) { +// clipper.RemoveAllInputs(); +// clipper.Delete(); +// clipper = null; +// } +// } +// +// private void deleteCrinkle() { +// if (crinkle != null) { +// crinkle.RemoveAllInputs(); +// crinkle.Delete(); +// crinkle = null; +// } +// } +// +// private void deleteContourAndSmooth() { +// if (contour != null) { +// contour.RemoveAllInputs(); +// contour.Delete(); +// contour = null; +// } +// if (smooth != null) { +// smooth.RemoveAllInputs(); +// smooth.Delete(); +// smooth = null; +// } +// } +// +// public void VisibilityOff() { +// if (actor != null) { +// actor.setVisibility(false); +// } +// } +// +// public boolean isVisible() { +// return actor != null && actor.getVisibility(); +// } +// +// public void VisibilityOn() { +// if (actor != null) { +// actor.setVisibility(true); +// } +// } +// +// public void disconnectFilters() { +// actor.setInput(internalMeshDataset); +// +// deleteClipper(); +// deleteSlicer(); +// deleteCrinkle(); +// deleteContourAndSmooth(); +// } +// +// public boolean isLoaded() { +// return actor != null; +// } +// +// public void show() { +// renderPanel.addActor(actor); +// } +// +// @Override +// public Collection getActors() { +// return actor != null ? Arrays.asList(actor) : Collections. emptyList(); +// } +// +// @Override +// public boolean containsActor(Actor pickedActor) { +// return false; +// } +// +// public void clip(vtkPlane plane) { +// deleteClipper(); +// deleteSlicer(); +// deleteCrinkle(); +// +// clipper = new vtkTableBasedClipDataSet(); +// clipper.SetInputData(internalMeshDataset); +// clipper.SetClipFunction(plane); +// clipper.InsideOutOff(); +// +// updateInAThread(UPDATING_CLIPPER, clipper); +// +// connectActorToClipper(); +// +// renderPanel.renderLater(); +// +// VTKUtil.gc(false); +// } +// +// private void connectActorToClipper() { +// actor.interactiveOff(); +// actor.setInput(clipper.GetOutput()); +// } +// +// void smoothedContour(final String field, final List values, final int smoothingIterations, final double smoothingConvergence) { +// deleteContourAndSmooth(); +// +// contour = new vtkContourFilter(); +// contour.SetInputData(internalMeshDataset); +// contour.ComputeScalarsOff(); +// contour.ComputeNormalsOff(); +// contour.GenerateTrianglesOn(); +// contour.SetInputArrayToProcess(0, 0, 0, "vtkDataObject::FIELD_ASSOCIATION_POINTS", field); +// contour.SetNumberOfContours(values.size()); +// for (int i = 0; i < values.size(); i++) { +// contour.SetValue(i, values.get(i)); +// } +// +// smooth = new vtkSmoothPolyDataFilter(); +// smooth.SetInputData(contour.GetOutput()); +// smooth.SetNumberOfIterations(smoothingIterations); +// smooth.SetConvergence(smoothingConvergence); +// +// updateInAThread(UPDATING_CONTOUR_AND_SMOOTH, contour, smooth); +// +// connectActorToSmoothedContour(); +// +// renderPanel.renderLater(); +// +// VTKUtil.gc(false); +// } +// +// void exportSmoothedContourAsSTL(final File stlFile) { +// vtkSTLWriter writer = new vtkSTLWriter(); +// writer.SetFileName(stlFile.getAbsolutePath()); +// writer.SetInputData(smooth.GetOutput()); +// +// writeSTLInAThread("Saving STL file " + stlFile.getAbsolutePath(), writer); +// writer.Delete(); +// } +// +// private void writeSTLInAThread(String log, final vtkSTLWriter writer) { +// writer.RemoveAllObservers(); +// VTKProgressMonitorWrapper progressWrapper = new VTKProgressMonitorWrapper("", writer, monitor); +// writer.AddObserver("StartEvent", progressWrapper, "onStart"); +// writer.AddObserver("EndEvent", progressWrapper, "onEnd"); +// writer.AddObserver("ProgressEvent", progressWrapper, "onProgress"); +// +// monitor.setIndeterminate(false); +// monitor.setTotal(100); +// monitor.start(log, false, new Runnable() { +// @Override +// public void run() { +// writer.Write(); +// monitor.end(); +// } +// }); +// } +// +// private void connectActorToSmoothedContour() { +// actor.interactiveOff(); +// actor.setInput(smooth.GetOutput()); +// } +// +// void crinkle(vtkPlane plane) { +// deleteClipper(); +// deleteSlicer(); +// deleteCrinkle(); +// +// crinkle = new vtkExtractGeometry(); +// +// crinkle.SetInputData(internalMeshDataset); +// crinkle.ExtractInsideOn(); +// crinkle.ExtractOnlyBoundaryCellsOn(); +// crinkle.ExtractBoundaryCellsOn(); +// crinkle.SetImplicitFunction(plane); +// +// updateInAThread(UPDATING_CRINKLE, crinkle); +// +// connectActorToCrinkler(); +// +// renderPanel.renderLater(); +// } +// +// private void connectActorToCrinkler() { +// actor.interactiveOff(); +// actor.setInput(crinkle.GetOutput()); +// } +// +// void slice(vtkPlane plane, List values) { +// deleteClipper(); +// deleteSlicer(); +// deleteCrinkle(); +// +// slicer = new vtkCutter(); +// slicer.SetInputData(internalMeshDataset); +// slicer.GenerateTrianglesOff(); +// slicer.SetCutFunction(plane); +// +//// slicer.SetNumberOfContours(values.size()); +//// for (int i = 0; i < values.size(); i++) { +//// slicer.SetValue(i, values.get(i)); +//// } +// +// updateInAThread(UPDATING_SLICER, slicer); +// +// connectActorToSlicer(); +// +// renderPanel.renderLater(); +// } +// +// private void connectActorToSlicer() { +// actor.interactiveOff(); +// actor.setInput(slicer.GetOutput()); +// } +// +// void insideOut(boolean selected) { +// if (selected) { +// clipper.InsideOutOn(); +// } else { +// clipper.InsideOutOff(); +// } +// updateInAThread(UPDATING_CLIPPER, clipper); +// +// connectActorToClipper(); +// +// renderPanel.renderLater(); +// } +// +// private void updateInAThread(String log, final vtkAlgorithm... algo) { +// for (vtkAlgorithm a : algo) { +// a.RemoveAllObservers(); +// +// VTKProgressMonitorWrapper progressWrapper = new VTKProgressMonitorWrapper("", a, monitor); +// a.AddObserver("StartEvent", progressWrapper, "onStart"); +// a.AddObserver("EndEvent", progressWrapper, "onEnd"); +// a.AddObserver("ProgressEvent", progressWrapper, "onProgress"); +// } +// +// monitor.setIndeterminate(false); +// monitor.setTotal(100); +// monitor.start(log, false, new Runnable() { +// @Override +// public void run() { +// for (vtkAlgorithm a : algo) { +// a.Update(); +// } +// monitor.end(); +// } +// }); +// } +// +// @Override +// public Map getActorsMap() { +// return null; +// } +//} diff --git a/src/eu/engys/vtk/VTKMesh3DController.java b/src/eu/engys/vtk/VTKMesh3DController.java index a1efa7f..dc6232b 100644 --- a/src/eu/engys/vtk/VTKMesh3DController.java +++ b/src/eu/engys/vtk/VTKMesh3DController.java @@ -1,36 +1,36 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.vtk; -import static eu.engys.core.project.mesh.ScalarBarType.BLUE_TO_RED_RAINBOW; import static eu.engys.vtk.VTKColors.WHITE; +import java.io.File; import java.util.Collection; import java.util.Collections; import java.util.HashMap; +import java.util.List; import javax.inject.Inject; import javax.swing.JOptionPane; @@ -39,15 +39,16 @@ import org.apache.commons.collections.CollectionUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import vtk.vtkPlane; -import eu.engys.core.Arguments; +import com.google.common.collect.Lists; + import eu.engys.core.controller.GeometryToMesh; import eu.engys.core.project.Model; import eu.engys.core.project.geometry.BoundingBox; import eu.engys.core.project.geometry.Surface; import eu.engys.core.project.mesh.FieldItem; -import eu.engys.core.project.mesh.ScalarBarType; +import eu.engys.core.project.mesh.FieldItems; import eu.engys.core.project.zero.cellzones.CellZone; +import eu.engys.core.project.zero.facezones.FaceZone; import eu.engys.core.project.zero.patches.Patch; import eu.engys.gui.events.EventManager; import eu.engys.gui.events.view3D.ActorVisibilityEvent; @@ -60,10 +61,10 @@ import eu.engys.gui.view3D.Mesh3DEventListener; import eu.engys.gui.view3D.RenderPanel; import eu.engys.gui.view3D.Representation; import eu.engys.util.progress.ProgressMonitor; -import eu.engys.util.ui.ExecUtil; import eu.engys.util.ui.UiUtil; import eu.engys.vtk.actors.SurfaceToActor; import eu.engys.vtk.actors.SurfaceToActor.ActorMode; +import vtk.vtkPlane; public class VTKMesh3DController implements Mesh3DController { @@ -73,9 +74,13 @@ public class VTKMesh3DController implements Mesh3DController { private final ProgressMonitor monitor; private final VTKPatches patchActors; private final VTKCellZones cellZonesActors; + private final VTKFaceZones faceZonesActors; private final VTKInternalMesh internalMeshActor; +// private final VTKInternalMesh internalMeshActor; - private FieldItem currentField = null; + + + private FieldItem currentField; private double currentTimeStep = 0; private RenderPanel renderPanel; @@ -85,9 +90,13 @@ public class VTKMesh3DController implements Mesh3DController { this.monitor = monitor; this.patchActors = new VTKPatches(model); - this.cellZonesActors = new VTKCellZones(model, monitor); + this.cellZonesActors = new VTKCellZones(model); + this.faceZonesActors = new VTKFaceZones(model); +// this.internalMeshActor = new VTKInternalMesh(monitor); this.internalMeshActor = new VTKInternalMesh(monitor); + this.currentField = FieldItem.indexItem(); + EventManager.registerEventListener(new Mesh3DEventListener(this), View3DEvent.class); } @@ -97,11 +106,13 @@ public class VTKMesh3DController implements Mesh3DController { patchActors.setRenderPanel(renderPanel); cellZonesActors.setRenderPanel(renderPanel); + faceZonesActors.setRenderPanel(renderPanel); internalMeshActor.setRenderPanel(renderPanel); if (renderPanel.getPickManager() != null) { renderPanel.getPickManager().registerPickerForActors(patchActors); renderPanel.getPickManager().registerPickerForActors(cellZonesActors); + renderPanel.getPickManager().registerPickerForActors(faceZonesActors); } } @@ -118,6 +129,7 @@ public class VTKMesh3DController implements Mesh3DController { for (Actor a : actors) { String actorName = g2m.getPatchName(surface); a.rename(actorName); + a.setVisibility(true); patchActors.addActorToPatches(a); } } @@ -126,22 +138,35 @@ public class VTKMesh3DController implements Mesh3DController { if (actors.length == 1) { String zoneName = g2m.getCellZoneName(surface); actors[0].rename(zoneName); + actors[0].setVisibility(true); cellZonesActors.addActorToZones(actors[0]); } else { for (Actor a : actors) { + a.setVisibility(true); cellZonesActors.addActorToZones(a); } } } - - VTKColors.indexedColor().to(patchActors).to(cellZonesActors).apply(); + for (Surface surface : g2m.getWillBeFaceZones()) { + Actor[] actors = surfaceToActor.toActor(surface); + if (actors.length == 1) { + String zoneName = g2m.getFaceZoneName(surface); + actors[0].rename(zoneName); + actors[0].setVisibility(true); + faceZonesActors.addActorToZones(actors[0]); + } else { + for (Actor a : actors) { + a.setVisibility(true); + faceZonesActors.addActorToZones(a); + } + } + } + VTKColors.indexedColor().to(patchActors).to(cellZonesActors).to(faceZonesActors).apply(); } @Override public void loadActors() { - if (Arguments.load3Dmesh) { - _loadExternalMesh(); - } + _loadExternalMesh(); } @Override @@ -154,22 +179,29 @@ public class VTKMesh3DController implements Mesh3DController { return internalMeshActor.isLoaded(); } + @Override + public boolean isInternalMeshVisible() { + return internalMeshActor.isVisible(); + } + @Override public void clear() { deleteActors(); - this.currentField = null; + this.currentField = FieldItem.indexItem(); this.currentTimeStep = 0; } private void deleteActors() { patchActors.deleteActors(); cellZonesActors.deleteActors(); + faceZonesActors.deleteActors(); internalMeshActor.deleteActors(); } private void removeActorsFromRenderer() { patchActors.removeActorsFromRenderer(); cellZonesActors.removeActorsFromRenderer(); + faceZonesActors.removeActorsFromRenderer(); internalMeshActor.removeActorsFromRenderer(); } @@ -193,25 +225,44 @@ public class VTKMesh3DController implements Mesh3DController { cellZonesActors.updateVisibility(selection); } + @Override + public void updateFaceZonesSelection(FaceZone[] selection) { + faceZonesActors.selectActors(selection); + } + + @Override + public void updateFaceZonesVisibility(FaceZone... selection) { + faceZonesActors.updateVisibility(selection); + } + @Override @SuppressWarnings("unchecked") public Collection getActorsList() { - return CollectionUtils.union(patchActors.getActors(), CollectionUtils.union(cellZonesActors.getActors(), internalMeshActor.getActors())); + Collection pActors = patchActors.getActors(); + Collection cActors = cellZonesActors.getActors(); + Collection fActors = faceZonesActors.getActors(); + Collection iActors = internalMeshActor.getActors(); + return CollectionUtils.union(pActors, CollectionUtils.union(cActors, CollectionUtils.union(fActors, iActors))); } @Override public void readTimeSteps() { - VTKOpenFOAMDataset dataset = new VTKOpenFOAMDataset(model, null); - dataset.loadInformations(currentTimeStep); - dataset.clear(); + TimeStepsReader reader = new TimeStepsReader(model, monitor); + reader.read(currentTimeStep); + model.getMesh().setTimeSteps(reader.getTimesteps()); } @Override public void showField(FieldItem fieldItem) { this.currentField = fieldItem; - if (FieldItem.SOLID.equals(fieldItem.getName())) { + updateActorsColors(); + } + + @Override + public void updateActorsColors() { + if (FieldItem.SOLID.equals(currentField.getName())) { setColorsToSolid(); - } else if (FieldItem.INDEXED.equals(fieldItem.getName())) { + } else if (FieldItem.INDEXED.equals(currentField.getName())) { setColorsToIndexed(); } else { setColorsToScalar(); @@ -219,93 +270,68 @@ public class VTKMesh3DController implements Mesh3DController { } private void setColorsToSolid() { - VTKColors.solidColor(WHITE).to(patchActors).to(cellZonesActors).to(internalMeshActor).apply(); + VTKColors.solidColor(WHITE).to(patchActors).to(cellZonesActors).to(faceZonesActors).to(internalMeshActor).apply(); renderPanel.renderLater(); } private void setColorsToIndexed() { - VTKColors.indexedColor().to(patchActors).to(cellZonesActors).apply(); + VTKColors.indexedColor().to(patchActors).to(cellZonesActors).to(faceZonesActors).to(internalMeshActor).apply(); VTKColors.solidColor(WHITE).to(internalMeshActor).apply(); renderPanel.renderLater(); } private void setColorsToScalar() { - VTKColors.scalarsColor(currentField).to(patchActors).to(cellZonesActors).to(internalMeshActor).apply(); + VTKColors.scalarsColor(currentField).to(patchActors).to(cellZonesActors).to(faceZonesActors).to(internalMeshActor).apply(); renderPanel.renderLater(); } @Override - public void showTimeStep(final double currentTimeStep) { + public void changeTimeStep(final double currentTimeStep) { this.currentTimeStep = currentTimeStep; monitor.start("Loading values for timestep " + currentTimeStep, false, new Runnable() { @Override public void run() { - final VTKOpenFOAMDataset dataset = new VTKOpenFOAMDataset(model, monitor); - dataset.loadTimeStep(currentTimeStep); - - ExecUtil.invokeLater(new Runnable() { - @Override - public void run() { - patchActors.update(dataset.getPatchesDataset()); - cellZonesActors.update(dataset.getCellZonesDataset()); - internalMeshActor.update(dataset.getInternalMeshDataset()); - dataset.clear(); - } - }); + _changeTimeStep(currentTimeStep); + fixFieldItemSelection(); monitor.end(); } }); + } - if (currentField != null && currentField.isScalar()) { - setColorsToScalar(); + private void _changeTimeStep(double currentTimeStep) { + renderPanel.DestroyTimer(); + + File baseDir = model.getProject().getBaseDir(); + boolean parallel = model.getProject().isParallel(); + + ExternalMeshReader eReader = new ExternalMeshReader(baseDir, parallel, monitor); + eReader.read(currentTimeStep); + + renderPanel.lock(); + patchActors.update(Lists.newArrayList(eReader.getPatchesDataset().values())); + cellZonesActors.update(eReader.getCellZonesDataset()); +// faceZonesActors.update(eReader.getFaceZonesDataset()); + renderPanel.unlock(); + + model.getMesh().getExternalMesh().setBounds(eReader.getBounds()); + model.getMesh().setTimeSteps(eReader.getTimesteps()); + + model.getMesh().getExternalMesh().getFieldItems().addFieldItems(eReader.getFieldItems()); + + eReader.clear(); + + if (internalMeshActor.isLoaded()) { + InternalMeshReader iReader = new InternalMeshReader(baseDir, parallel, monitor); + iReader.read(currentTimeStep); + + renderPanel.lock(); + internalMeshActor.update(iReader.getInternalMeshDataset()); + renderPanel.unlock(); + model.getMesh().getInternalMesh().getFieldItems().addFieldItems(iReader.getFieldItems()); + iReader.clear(); } - } - - @Override - public FieldItem getCurrentFieldItem() { - return currentField; - } - - @Override - public double getCurrentTimeStep() { - return currentTimeStep; - } - - // RESOLUTION - @Override - public void setScalarsActorsResolution(int resolution) { - currentField.setResolution(resolution); - setColorsToScalar(); - } - - // SCALARBAR TYPE - @Override - public void setScalarsBarType(ScalarBarType scalarBarType) { - currentField.setScalarBarType(scalarBarType); - setColorsToScalar(); - } - - // RANGE - @Override - public void setAutomaticRangeCalculation(boolean autoRange) { - currentField.setAutomaticRange(autoRange); - setColorsToScalar(); - } - - @Override - public void setManualRangeCalculation(double[] range) { - currentField.setRange(range); - setColorsToScalar(); - } - - // RESET - @Override - public void resetScalarsActorsRangeAndResolutionAndHue() { - currentField.setAutomaticRange(true); - currentField.setResolution(FieldItem.DEFAULT_RESOLUTION); - currentField.setScalarBarType(BLUE_TO_RED_RAINBOW); - - setColorsToScalar(); + + VTKUtil.gc(true); } @Override @@ -320,27 +346,40 @@ public class VTKMesh3DController implements Mesh3DController { monitor.start("Loading mesh", false, new Runnable() { @Override public void run() { - _loadExternalMesh(); - monitor.end(); + if (!patchActors.isLoaded()) { + _loadExternalMesh(); + monitor.end(); + } } }); } private void _loadExternalMesh() { - if (!patchActors.isLoaded()) { - VTKOpenFOAMDataset dataset = new VTKOpenFOAMDataset(model, monitor); - dataset.loadExternalMesh(0); + File baseDir = model.getProject().getBaseDir(); + boolean parallel = model.getProject().isParallel(); + + ExternalMeshReader reader = new ExternalMeshReader(baseDir, parallel, monitor); + reader.read(0); - monitor.info("-> Patches"); - patchActors.load(dataset.getPatchesDataset()); + monitor.info("-> Patches"); + patchActors.load(reader.getPatchesDataset()); - monitor.info("-> Cell Zones"); - cellZonesActors.load(dataset.getCellZonesDataset()); + monitor.info("-> Cell Zones"); + cellZonesActors.load(reader.getCellZonesDataset()); - VTKColors.indexedColor().to(patchActors).to(cellZonesActors).apply(); +// monitor.info("-> Face Zones"); +// faceZonesActors.load(reader.getFaceZonesDataset()); + + cellZonesActors.VisibilityOff(); + faceZonesActors.VisibilityOff(); - dataset.clear(); - } + model.getMesh().getExternalMesh().setBounds(reader.getBounds()); + model.getMesh().setTimeSteps(reader.getTimesteps()); + model.getMesh().getExternalMesh().getFieldItems().addFieldItems(reader.getFieldItems()); + + VTKColors.indexedColor().to(patchActors).to(cellZonesActors).to(faceZonesActors).apply(); + + reader.clear(); } @Override @@ -353,11 +392,8 @@ public class VTKMesh3DController implements Mesh3DController { if (internalMeshActor.isLoaded()) { hideAllActorsShowInternalMesh(); internalMeshActor.show(); - if (currentField != null) { - showField(currentField); - } else { - VTKColors.solidColor(WHITE).to(internalMeshActor).apply(); - } + + fixFieldItemSelection(); } } @@ -366,22 +402,33 @@ public class VTKMesh3DController implements Mesh3DController { monitor.start("Loading internal mesh", false, new Runnable() { @Override public void run() { - VTKOpenFOAMDataset dataset = new VTKOpenFOAMDataset(model, monitor); - dataset.loadInternalMesh(currentTimeStep); - - monitor.info("-> Internal Mesh Actor"); - internalMeshActor.load(dataset.getInternalMeshDataset()); - - dataset.clear(); + _loadInternalMesh(); monitor.end(); } }); } } + private void _loadInternalMesh() { + File baseDir = model.getProject().getBaseDir(); + boolean parallel = model.getProject().isParallel(); + + InternalMeshReader reader = new InternalMeshReader(baseDir, parallel, monitor); + reader.read(currentTimeStep); + + monitor.info("-> Internal Mesh Actor"); + internalMeshActor.load(reader.getInternalMeshDataset()); + model.getMesh().getInternalMesh().getFieldItems().addFieldItems(reader.getFieldItems()); + + reader.clear(); + + VTKUtil.gc(true); + } + private void hideAllActorsShowInternalMesh() { - cellZonesActors.VisibilityOff(); patchActors.VisibilityOff(); + cellZonesActors.VisibilityOff(); + faceZonesActors.VisibilityOff(); internalMeshActor.VisibilityOn(); EventManager.triggerEvent(this, new ActorVisibilityEvent(false)); @@ -392,21 +439,57 @@ public class VTKMesh3DController implements Mesh3DController { if (internalMeshActor.isLoaded()) { internalMeshActor.disconnectFilters(); showAllActorsHideInternalMesh(); + + fixFieldItemSelection(); } } private void showAllActorsHideInternalMesh() { - cellZonesActors.VisibilityOff(); patchActors.VisibilityOn(); +// faceZonesActors.VisibilityOn(); +// cellZonesActors.VisibilityOn(); + faceZonesActors.VisibilityOff(); + cellZonesActors.VisibilityOff(); internalMeshActor.VisibilityOff(); EventManager.triggerEvent(this, new ActorVisibilityEvent(true)); } + private void fixFieldItemSelection() { + if (currentField != null) { + if (isInternalMeshVisible()) { + FieldItems items = model.getMesh().getInternalMesh().getFieldItems(); + showField(items.getEquivalentFieldItemOf(currentField)); + } else { + FieldItems items = model.getMesh().getExternalMesh().getFieldItems(); + showField(items.getEquivalentFieldItemOf(currentField)); + } + } else { + setColorsToSolid(); + } + } + @Override - public void clip(vtkPlane plane) { + public void disconnectFiltersFromInternalMesh() { if (internalMeshActor.isLoaded()) { - internalMeshActor.clip(plane); + internalMeshActor.disconnectFilters(); + } + } + + @Override + public FieldItem getCurrentFieldItem() { + return currentField; + } + + @Override + public double getCurrentTimeStep() { + return currentTimeStep; + } + + @Override + public void clip(vtkPlane plane, boolean insideOut) { + if (internalMeshActor.isLoaded()) { + internalMeshActor.clip(plane, insideOut); } } @@ -418,24 +501,23 @@ public class VTKMesh3DController implements Mesh3DController { } @Override - public void slice(vtkPlane plane) { + public void slice(vtkPlane plane, List values) { if (internalMeshActor.isLoaded()) { - internalMeshActor.slice(plane); + internalMeshActor.slice(plane, values); } } @Override - public void insideOut(boolean selected) { + public void contour(String field, List values, int smoothingIterations, double smoothingConvergence) { if (internalMeshActor.isLoaded()) { - internalMeshActor.insideOut(selected); + internalMeshActor.smoothedContour(field, values, smoothingIterations, smoothingConvergence); } } @Override - public void disconnectFiltersFromInternalMesh() { + public void exportContourAsSTL(File stlFile) { if (internalMeshActor.isLoaded()) { - internalMeshActor.disconnectFilters(); - render(); + internalMeshActor.exportSmoothedContourAsSTL(stlFile); } } @@ -470,8 +552,10 @@ public class VTKMesh3DController implements Mesh3DController { logger.info("[APPLY CONTEXT] for {} is {}", klass.getSimpleName(), context); renderPanel.setRepresentation(context.getRepresentation()); this.allowSelection = context.isAllowSelection(); - cellZonesActors.addCellZonesMap(context.getCellzones(), context.getZonesVisibility()); - patchActors.addPatchMap(context.getPatches(), context.getPatchesVisibility()); + patchActors.addActorsMap(context.getPatches(), context.getPatchesVisibility()); + faceZonesActors.addActorsMap(context.getFaceZones(), context.getFaceZonesVisibility()); + cellZonesActors.addActorsMap(context.getCellZones(), context.getCellZonesVisibility()); + internalMeshActor.addActorsMap(context.getInternalMesh(), context.getInternalMeshVisibility()); } else { logger.info("[APPLY CONTEXT] for {} is NOT FOUND", klass.getSimpleName()); } @@ -479,14 +563,27 @@ public class VTKMesh3DController implements Mesh3DController { @Override public void newContext(Class klass) { - MeshContext context = new MeshContext(Representation.SURFACE, true, cellZonesActors.getActorsMap(), patchActors.getActorsMap()); + MeshContext context = new MeshContext(); + context.setRepresentation(Representation.SURFACE); + context.setAllowSelection(true); + context.setPatches(patchActors.getActorsMap()); + context.setCellZones(cellZonesActors.getActorsMap()); + context.setFaceZones(faceZonesActors.getActorsMap()); + context.setInternalMesh(internalMeshActor.getActorsMap()); + contextMap.put(klass, context); logger.info("[NEW CONTEXT] for {} is {}", klass.getSimpleName(), context); } @Override public void newEmptyContext(Class klass) { - MeshContext context = new MeshContext(Representation.SURFACE, true, Collections. emptyMap(), Collections. emptyMap()); + MeshContext context = new MeshContext(); + context.setRepresentation(Representation.SURFACE); + context.setAllowSelection(true); + context.setPatches(Collections. emptyMap()); + context.setCellZones(Collections. emptyMap()); + context.setFaceZones(Collections. emptyMap()); + context.setInternalMesh(Collections. emptyMap()); contextMap.put(klass, context); logger.info("[EMPTY CONTEXT] for {} is {}", klass.getSimpleName(), context); } @@ -496,7 +593,13 @@ public class VTKMesh3DController implements Mesh3DController { if (contextMap.containsKey(klass)) { contextMap.remove(klass).clear(); } - MeshContext context = new MeshContext(renderPanel.getRepresentation(), allowSelection, cellZonesActors.getActorsMap(), patchActors.getActorsMap()); + MeshContext context = new MeshContext(); + context.setRepresentation(renderPanel.getRepresentation()); + context.setAllowSelection(allowSelection); + context.setPatches(patchActors.getActorsMap()); + context.setCellZones(cellZonesActors.getActorsMap()); + context.setFaceZones(faceZonesActors.getActorsMap()); + context.setInternalMesh(internalMeshActor.getActorsMap()); contextMap.put(klass, context); logger.info("[DUMP CONTEXT] for {} is {}", klass.getSimpleName(), context); } @@ -513,6 +616,7 @@ public class VTKMesh3DController implements Mesh3DController { public void showAllActors() { patchActors.addActorsToRenderer(); cellZonesActors.addActorsToRenderer(); + faceZonesActors.addActorsToRenderer(); } } diff --git a/src/eu/engys/vtk/VTKMouseHandler.java b/src/eu/engys/vtk/VTKMouseHandler.java index 20ea04e..0dcd128 100644 --- a/src/eu/engys/vtk/VTKMouseHandler.java +++ b/src/eu/engys/vtk/VTKMouseHandler.java @@ -1,29 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.vtk; import java.awt.event.InputEvent; @@ -37,8 +35,11 @@ import java.awt.event.MouseWheelListener; import javax.swing.SwingUtilities; +import eu.engys.gui.view3D.Interactor; +import eu.engys.gui.view3D.Representation; import vtk.vtkGenericRenderWindowInteractor; import vtk.vtkInteractorObserver; +import vtk.vtkInteractorStyleHelyx; import vtk.vtkInteractorStyleRubberBand3D; import vtk.vtkInteractorStyleRubberBandZoom; import vtk.vtkInteractorStyleTrackballCamera; @@ -64,7 +65,8 @@ public class VTKMouseHandler implements MouseListener, MouseMotionListener, Mous public void mouseClicked(MouseEvent e) { // System.out.println("MOUSE CLICKED"); VTKPickManager pickManager = vtkRenderPanel.getPickManager(); - vtkGenericRenderWindowInteractor iren = (vtkGenericRenderWindowInteractor) vtkRenderPanel.getInteractor(); + Interactor interactor = vtkRenderPanel.getInteractor(); + vtkGenericRenderWindowInteractor iren = (vtkGenericRenderWindowInteractor) interactor; if (SwingUtilities.isLeftMouseButton(e)) { if (!isDragging) { @@ -72,6 +74,8 @@ public class VTKMouseHandler implements MouseListener, MouseMotionListener, Mous if (iren.GetInteractorStyle() instanceof vtkInteractorStyleTrackballCamera) { pickManager.pick(pos[0], pos[1], e.isControlDown(), e.isShiftDown()); + } else if (iren.GetInteractorStyle() instanceof vtkInteractorStyleHelyx) { + pickManager.pick(pos[0], pos[1], e.isControlDown(), e.isShiftDown()); } } else if(iren.GetInteractorStyle() instanceof vtkInteractorStyleRubberBand3D) { vtkInteractorStyleRubberBand3D style = (vtkInteractorStyleRubberBand3D) iren.GetInteractorStyle(); @@ -79,7 +83,7 @@ public class VTKMouseHandler implements MouseListener, MouseMotionListener, Mous int[] endPosition = style.GetEndPosition(); pickManager.pickArea(startPosition, endPosition, e.isControlDown(), e.isShiftDown()); } else if(iren.GetInteractorStyle() instanceof vtkInteractorStyleRubberBandZoom) { - iren.SetInteractorStyle(new vtkInteractorStyleTrackballCamera()); + interactor.setStyleToDefault(); } } else if (SwingUtilities.isRightMouseButton(e)) { if (!isDragging) { @@ -87,7 +91,9 @@ public class VTKMouseHandler implements MouseListener, MouseMotionListener, Mous if (iren.GetInteractorStyle() instanceof vtkInteractorStyleTrackballCamera) { pickManager.popup(pos[0], pos[1], e); - } + } else if (iren.GetInteractorStyle() instanceof vtkInteractorStyleHelyx) { + pickManager.popup(pos[0], pos[1], e); + } } } } @@ -110,6 +116,8 @@ public class VTKMouseHandler implements MouseListener, MouseMotionListener, Mous iren.SetEventInformationFlipY(e.getX(), e.getY(), ctrlPressed(e), shiftPressed(e), '0', 0, "0"); } else if (style instanceof vtkInteractorStyleTrackballCamera) { iren.SetEventInformation(e.getX(), e.getY(), ctrlPressed(e), shiftPressed(e), '0', 0, "0"); + } else if (style instanceof vtkInteractorStyleHelyx) { + iren.SetEventInformation(e.getX(), e.getY(), ctrlPressed(e), shiftPressed(e), '0', 0, "0"); } iren.RightButtonPressEvent(); } @@ -123,7 +131,8 @@ public class VTKMouseHandler implements MouseListener, MouseMotionListener, Mous public void mouseReleased(MouseEvent e) { // System.out.println("MOUSE RELEASED"); VTKPickManager pickManager = vtkRenderPanel.getPickManager(); - vtkGenericRenderWindowInteractor iren = (vtkGenericRenderWindowInteractor) vtkRenderPanel.getInteractor(); + Interactor interactor = vtkRenderPanel.getInteractor(); + vtkGenericRenderWindowInteractor iren = (vtkGenericRenderWindowInteractor) interactor; iren.SetEventInformationFlipY(e.getX(), e.getY(), ctrlPressed(e), shiftPressed(e), '0', 0, "0"); vtkRenderPanel.lock(); @@ -131,7 +140,7 @@ public class VTKMouseHandler implements MouseListener, MouseMotionListener, Mous if (SwingUtilities.isLeftMouseButton(e)) { iren.LeftButtonReleaseEvent(); if(iren.GetInteractorStyle() instanceof vtkInteractorStyleRubberBandZoom) { - iren.SetInteractorStyle(new vtkInteractorStyleTrackballCamera()); + interactor.setStyleToDefault(); } else if(iren.GetInteractorStyle() instanceof vtkInteractorStyleRubberBand3D) { vtkInteractorStyleRubberBand3D style = (vtkInteractorStyleRubberBand3D) iren.GetInteractorStyle(); int[] startPosition = style.GetStartPosition(); @@ -205,7 +214,13 @@ public class VTKMouseHandler implements MouseListener, MouseMotionListener, Mous } else { iren.SetEventInformationFlipY(e.getX(), e.getY(), ctrlPressed(e), shiftPressed(e), '0', 0, "0"); } - } + } else if (style instanceof vtkInteractorStyleHelyx) { + if (SwingUtilities.isRightMouseButton(e)) { + iren.SetEventInformation(e.getX(), e.getY(), ctrlPressed(e), shiftPressed(e), '0', 0, "0"); + } else { + iren.SetEventInformationFlipY(e.getX(), e.getY(), ctrlPressed(e), shiftPressed(e), '0', 0, "0"); + } + } vtkRenderPanel.lock(); iren.MouseMoveEvent(); @@ -236,6 +251,27 @@ public class VTKMouseHandler implements MouseListener, MouseMotionListener, Mous @Override public void keyPressed(KeyEvent e) { + int key = e.getKeyCode(); + switch (key) { + case KeyEvent.VK_W: + vtkRenderPanel.changeRepresentation(Representation.WIREFRAME); + break; + case KeyEvent.VK_O: + vtkRenderPanel.changeRepresentation(Representation.OUTLINE); + break; + case KeyEvent.VK_E: + vtkRenderPanel.changeRepresentation(Representation.SURFACE_WITH_EDGES); + break; + case KeyEvent.VK_S: + vtkRenderPanel.changeRepresentation(Representation.SURFACE); + break; + case KeyEvent.VK_R: + vtkRenderPanel.resetZoomLater(); + break; + + default: + break; + } } @Override diff --git a/src/eu/engys/vtk/VTKOpenFOAMDataset.java b/src/eu/engys/vtk/VTKOpenFOAMDataset.java deleted file mode 100644 index 6e8f6c9..0000000 --- a/src/eu/engys/vtk/VTKOpenFOAMDataset.java +++ /dev/null @@ -1,436 +0,0 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - - -package eu.engys.vtk; - -import static eu.engys.core.project.zero.fields.Fields.U; -import static eu.engys.vtk.VTKUtil.logBlockNames; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import vtk.vtkCompositeDataPipeline; -import vtk.vtkCompositeDataSet; -import vtk.vtkDataObject; -import vtk.vtkExecutive; -import vtk.vtkInformation; -import vtk.vtkInformationDoubleVectorKey; -import vtk.vtkMultiBlockDataSet; -import vtk.vtkPolyData; -import vtk.vtkUnstructuredGrid; -import eu.engys.core.project.Model; -import eu.engys.core.project.mesh.FieldItem; -import eu.engys.core.project.mesh.FieldItem.DataType; -import eu.engys.core.project.mesh.Mesh; -import eu.engys.util.progress.ProgressMonitor; -import eu.engys.vtk.info.VTKDataInformation; - -public class VTKOpenFOAMDataset { - - private static final Logger logger = LoggerFactory.getLogger(VTKOpenFOAMDataset.class); - - private static final String DEFAULT_REGION = "defaultRegion"; - private static final String INTERNAL_MESH = "internalMesh"; - private static final String ZONES = "Zones"; - private static final String FACE_ZONES = "faceZones"; - private static final String CELL_ZONES = "cellZones"; - private static final String PATCHES = "Patches"; - - private Model model; - private ProgressMonitor monitor; - - private vtkUnstructuredGrid internalMeshDataset = null; - private List patchesDataset = new ArrayList<>(); - private List cellZonesDataset = new ArrayList<>(); - - public VTKOpenFOAMDataset(Model model, ProgressMonitor monitor) { - this.model = model; - this.monitor = monitor; - } - - public void loadInformations(double timeStep) { - logger.info("Load mesh informations for timestep {}", timeStep); - VTKOpenFOAMReader reader = new VTKOpenFOAMReader(model, monitor, "Informations of"); - reader.UpdateInformation(); - reader.ReadInternalMeshOff(); - reader.ReadPatchesOff(); - reader.ReadZonesOff(); - reader.setTimeStep(timeStep); - reader.Update(); - - extractInformations(reader, timeStep); - - reader.Delete(); - } - - public List getCellZonesDataset() { - return cellZonesDataset; - } - - public List getPatchesDataset() { - return patchesDataset; - } - - public vtkUnstructuredGrid getInternalMeshDataset() { - return internalMeshDataset; - } - - public void loadInternalMesh(double timeStep) { - VTKOpenFOAMReader reader = new VTKOpenFOAMReader(model, monitor, "Internal"); - reader.UpdateInformation(); - reader.ReadInternalMeshOn(); - reader.ReadPatchesOff(); - reader.ReadZonesOff(); - reader.setTimeStep(timeStep); - reader.Update(); - - vtkMultiBlockDataSet dataset = reader.GetOutput(); - try { - - if (isSingleRegion(dataset)) { - readSingleRegionInternalMesh(dataset); - } else { - readMultiRegionInternalMesh(dataset); - } - } catch (Exception e) { - logger.error(e.getMessage(), e); - } finally { - dataset.Delete(); - reader.Delete(); - } - } - - private void readSingleRegionInternalMesh(vtkMultiBlockDataSet dataset) { - int numberOfBlocks = dataset.GetNumberOfBlocks(); - if (numberOfBlocks > 0) { - logger.debug("READ [SINGLE] [INTERNAL] blocks are: {}", VTKUtil.logBlockNames(dataset)); - - vtkDataObject internalMesh = getBlock(INTERNAL_MESH, dataset); - if (internalMesh != null) { - extractInternalDataset(internalMesh); - } else { - logger.warn("READ [SINGLE] [INTERNAL]: {} NOT FOUND", INTERNAL_MESH); - } - } else { - logger.warn("READ [SINGLE] [INTERNAL]: EMPTY!"); - } - } - - private void readMultiRegionInternalMesh(vtkMultiBlockDataSet dataset) { - int numberOfBlocks = dataset.GetNumberOfBlocks(); - if (numberOfBlocks > 0) { - logger.debug("READ [MULTI] [INTERNAL] blocks are: {}", VTKUtil.logBlockNames(dataset)); - - vtkDataObject defaultRegion = getBlock(DEFAULT_REGION, dataset); - if (defaultRegion != null) { - readSingleRegionInternalMesh((vtkMultiBlockDataSet) defaultRegion); - } else { - logger.warn("READ [MULTI] [INTERNAL]: {} NOT FOUND", DEFAULT_REGION); - } - } else { - logger.warn("READ [MULTI] [INTERNAL]: EMPTY"); - } - } - - public void loadExternalMesh(double timeStep) { - VTKOpenFOAMReader reader = new VTKOpenFOAMReader(model, monitor, "External"); - reader.ReadInternalMeshOff(); - reader.ReadPatchesOn(); - reader.ReadZonesOn(); - reader.setTimeStep(timeStep); - reader.Update(); - - vtkMultiBlockDataSet dataset = reader.GetOutput(); - - try { - if (isSingleRegion(dataset)) { - readSingleRegion(dataset); - } else { - readMultiRegion(dataset); - } - - extractInformations(reader, timeStep); - - } catch (Exception e) { - logger.error(e.getMessage(), e); - } finally { - dataset.Delete(); - reader.Delete(); - } - } - - private boolean isSingleRegion(vtkMultiBlockDataSet dataset) { - int numberOfBlocks = dataset.GetNumberOfBlocks(); - if (numberOfBlocks > 0) { - String blockName = dataset.GetMetaData(0).Get(new vtkCompositeDataSet().NAME()); - return blockName.equals(PATCHES) || blockName.equals(ZONES) || blockName.equals(INTERNAL_MESH) ; - } - return false; - } - - private void readSingleRegion(vtkMultiBlockDataSet dataset) { - int numberOfBlocks = dataset.GetNumberOfBlocks(); - if (numberOfBlocks > 0) { - logger.debug("READ [SINGLE] [EXTERNAL] blocks are: {}", logBlockNames(dataset)); - - vtkDataObject patches = getBlock(PATCHES, dataset); - if (patches != null) { - extractPatchesDataset(patches); - } else { - logger.warn("READ [SINGLE] [PATCHES]: {} NOT FOUND", PATCHES); - } - - vtkDataObject zones = getBlock(ZONES, dataset); - if (zones != null) { - extractZonesDataset(zones); - } else { - logger.warn("READ [SINGLE] [ZONES]: {} NOT FOUND", ZONES); - } - } - } - - private void readMultiRegion(vtkMultiBlockDataSet dataset) { - int numberOfBlocks = dataset.GetNumberOfBlocks(); - if (numberOfBlocks > 0) { - logger.debug("READ [MULTI] [EXTERNAL] blocks are: {}", logBlockNames(dataset)); - - vtkDataObject defaultRegion = getBlock(DEFAULT_REGION, dataset); - if (defaultRegion != null) { - readSingleRegion((vtkMultiBlockDataSet) defaultRegion); - } else { - logger.warn("READ [MULTI] [EXTERNAL]: {} NOT LOADED", DEFAULT_REGION); - } - } else { - logger.warn("READ [MULTI] [EXTERNAL]: EMPTY!"); - } - } - - private vtkDataObject getBlock(String blockName, vtkMultiBlockDataSet dataset) { - int numberOfBlocks = dataset.GetNumberOfBlocks(); - for (int i = 0; i < numberOfBlocks; i++) { - String name = dataset.GetMetaData(i).Get(new vtkCompositeDataSet().NAME()); - if (blockName.equals(name)) { - return dataset.GetBlock(i); - } - } - return null; - } - - private void extractPatchesDataset(vtkDataObject block) { - if (block != null && block instanceof vtkMultiBlockDataSet) { - vtkMultiBlockDataSet dataset = (vtkMultiBlockDataSet) block; - int subblockNumbers = dataset.GetNumberOfBlocks(); - for (int i = 0; i < subblockNumbers; i++) { - vtkDataObject subBlock = dataset.GetBlock(i); - if (subBlock instanceof vtkPolyData) { - this.patchesDataset.add(shallowCopy((vtkPolyData) subBlock)); - } - } - } - } - - public static vtkDataObject shallowCopy(vtkPolyData data) { - vtkPolyData copy = new vtkPolyData(); - copy.ShallowCopy(data); - return copy; - } - - public static vtkUnstructuredGrid shallowCopy(vtkUnstructuredGrid data) { - vtkUnstructuredGrid copy = new vtkUnstructuredGrid(); - copy.ShallowCopy(data); - return copy; - } - - private void extractZonesDataset(vtkDataObject block) { - if (block != null && block instanceof vtkMultiBlockDataSet) { - - vtkMultiBlockDataSet zones = (vtkMultiBlockDataSet) block; - - - vtkDataObject faceZones = getBlock(FACE_ZONES, zones); - if (faceZones != null) { -// extractFaceZonesDataset(zones); - } else { - logger.warn("READ [SINGLE] [FACE ZONES]: {} NOT FOUND", FACE_ZONES); - } - - vtkDataObject cellZones = getBlock(CELL_ZONES, zones); - if (cellZones != null) { - extractCellZonesDataset(cellZones); - } else { - logger.warn("READ [SINGLE] [ZONES]: {} NOT FOUND", ZONES); - } - - - - zones.Delete(); - } - } - - private void extractCellZonesDataset(vtkDataObject block) { - if (block != null && block instanceof vtkMultiBlockDataSet) { - vtkMultiBlockDataSet cellZones = (vtkMultiBlockDataSet) block; - int cellZonesNumber = cellZones.GetNumberOfBlocks(); - for (int i = 0; i < cellZonesNumber; i++) { - vtkDataObject cellZone = cellZones.GetBlock(i); - if (cellZone instanceof vtkUnstructuredGrid) { - logger.warn("Load as a Cell Zone"); - cellZonesDataset.add(shallowCopy((vtkUnstructuredGrid) cellZone)); - } - } - } - } - - private void extractInternalDataset(vtkDataObject block) { - this.internalMeshDataset = shallowCopy((vtkUnstructuredGrid) block); - } - - public void loadTimeStep(double timeStep) { - VTKOpenFOAMReader reader = new VTKOpenFOAMReader(model, monitor, "Time steps of"); - reader.UpdateInformation(); - reader.ReadInternalMeshOn(); - reader.ReadPatchesOn(); - reader.ReadZonesOn(); - reader.setTimeStep(timeStep); - reader.Update(); - - vtkMultiBlockDataSet dataset = reader.GetOutput(); - try { - if (isSingleRegion(dataset)) { - readSingleRegionInternalMesh(dataset); - readSingleRegion(dataset); - } else { - readMultiRegionInternalMesh(dataset); - readMultiRegion(dataset); - } - - extractInformations(reader, timeStep); - - } catch (Exception e) { - logger.error(e.getMessage(), e); - } finally { - dataset.Delete(); - reader.Delete(); - } - } - - private void extractInformations(VTKOpenFOAMReader reader, double timeStep) { - VTKDataInformation info = new VTKDataInformation(); - info.AddFromMultiBlockDataSet(reader.GetOutput()); - - Mesh mesh = model.getMesh(); - mesh.readStatistics(model); - mesh.setBounds(info.getBounds()); - mesh.setMemorySize(info.getMemorySize()); - - mesh.setTimeSteps(getTimeSteps(reader)); - - readFieldItems(reader, mesh); - - mesh.getTimeStepPointFieldsMap().put(Double.valueOf(timeStep), reader.getPointArrayNames()); - mesh.getTimeStepCellFieldsMap().put(Double.valueOf(timeStep), reader.getCellArrayNames()); - - logger.info("Timesteps = {}", mesh.getTimeSteps()); - logger.info("CellFieldsItems = {}", mesh.getCellFieldMap().keySet()); - logger.info("PointFieldsItems = {}", mesh.getPointFieldMap().keySet()); - - mesh.setRegions(getRegions(reader)); - } - - private List getRegions(VTKOpenFOAMReader reader) { - return null; - } - - private void readFieldItems(VTKOpenFOAMReader reader, Mesh mesh) { - for (String newField : reader.getCellArrayNames()) { - Map cellFieldMap = mesh.getCellFieldMap(); - if (newField.startsWith(U)) { - for (int i = 0; i < FieldItem.COMPONENTS.length; i++) { - FieldItem fieldItem = new FieldItem(newField, DataType.CELL, i); - if (!cellFieldMap.containsKey(newField + "_" + i)) { - cellFieldMap.put(newField + "_" + i, fieldItem); - } - } - } else { - FieldItem fieldItem = new FieldItem(newField, DataType.CELL, -1); - if (!cellFieldMap.containsKey(newField)) { - cellFieldMap.put(newField, fieldItem); - } - } - } - for (String newField : reader.getPointArrayNames()) { - Map pointFieldMap = mesh.getPointFieldMap(); - if (newField.startsWith(U)) { - for (int i = 0; i < FieldItem.COMPONENTS.length; i++) { - FieldItem fieldItem = new FieldItem(newField, DataType.POINT, i); - if (!pointFieldMap.containsKey(newField + "_" + i)) { - pointFieldMap.put(newField + "_" + i, fieldItem); - } - } - } else { - FieldItem fieldItem = new FieldItem(newField, DataType.POINT, -1); - if (!pointFieldMap.containsKey(newField)) { - pointFieldMap.put(newField, fieldItem); - } - } - } - } - - private List getTimeSteps(VTKOpenFOAMReader reader) { - vtkExecutive exe = reader.GetExecutive(); - vtkCompositeDataPipeline pipeline = (vtkCompositeDataPipeline) exe; - vtkInformation outInfo = exe.GetOutputInformation(0); - - vtkInformationDoubleVectorKey timeStepsKey = pipeline.TIME_STEPS(); - int nTimeSteps = outInfo.Length(timeStepsKey); // Get the number of time - // steps - List timesteps = new ArrayList<>(); - for (int i = 0; i < nTimeSteps; i++) { - double timeValue = outInfo.Get(timeStepsKey, i); - timesteps.add(Double.valueOf(timeValue)); - } - return timesteps; - } - - public void clear() { - for (vtkDataObject obj : patchesDataset) { - obj.Delete(); - } - for (vtkDataObject obj : cellZonesDataset) { - obj.Delete(); - } - if (internalMeshDataset != null) { - internalMeshDataset.Delete(); - internalMeshDataset = null; - } - patchesDataset.clear(); - cellZonesDataset.clear(); - } -} diff --git a/src/eu/engys/vtk/VTKOpenFOAMReader.java b/src/eu/engys/vtk/VTKOpenFOAMReader.java index 3f76902..d4cb290 100644 --- a/src/eu/engys/vtk/VTKOpenFOAMReader.java +++ b/src/eu/engys/vtk/VTKOpenFOAMReader.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.vtk; import java.io.File; @@ -32,225 +31,214 @@ import java.util.Collections; import java.util.LinkedList; import java.util.List; -import org.apache.log4j.Level; - +import eu.engys.core.project.zero.fields.Fields; +import eu.engys.util.progress.ProgressMonitor; import vtk.vtkCompositeDataPipeline; import vtk.vtkDataObject; import vtk.vtkDataSet; import vtk.vtkExecutive; import vtk.vtkMultiBlockDataSet; import vtk.vtkPOpenFOAMReader; -import eu.engys.core.LoggerUtil; -import eu.engys.core.project.Model; -import eu.engys.core.project.openFOAMProject; -import eu.engys.core.project.zero.fields.Fields; -import eu.engys.core.project.zero.patches.Patches; -import eu.engys.util.VTKSettings; -import eu.engys.util.progress.ProgressMonitor; -import eu.engys.util.progress.SilentMonitor; -import eu.engys.util.progress.VTKProgressMonitorWrapper; public class VTKOpenFOAMReader { - public static void main(String[] args) { - LoggerUtil.initTestLogger(Level.DEBUG); - VTKSettings.LoadAllNativeLibraries(); - Model model = new Model(); - model.init(); -// model.setProject(openFOAMProject.newParallelProject(new File("/home/stefano/ENGYS/examples/HELYX3/singleChannelPump_static_run"))); - model.setProject(openFOAMProject.newParallelProject(new File("/home/stefano/ENGYS/examples/HELYX3/ECOMARINE/testKCS_01_parallel_01"))); - - VTKOpenFOAMReader reader = new VTKOpenFOAMReader(model, new SilentMonitor(), ""); - reader.ReadInternalMeshOff(); - reader.ReadPatchesOff(); - reader.ReadZonesOff(); - reader.setTimeStep(0.0); -// reader.UpdateInformation(); - reader.Update(); -// reader.UpdateExtent(); - - } - - public static boolean decomposePolyhedra; - + public static boolean debug = false; + + // public static void main(String[] args) { + // LoggerUtil.initTestLogger(Level.DEBUG); + // VTKSettings.LoadAllNativeLibraries(); + // Model model = new Model(); + // model.init(); + // // model.setProject(openFOAMProject.newParallelProject(new File("/home/stefano/ENGYS/examples/HELYX3/singleChannelPump_static_run"))); + // model.setProject(openFOAMProject.newParallelProject(new File("/home/stefano/ENGYS/examples/HELYX3/ECOMARINE/testKCS_01_parallel_01"))); + // + // VTKOpenFOAMReader reader = new VTKOpenFOAMReader(model, new SilentMonitor(), ""); + // reader.ReadInternalMeshOff(); + // reader.ReadPatchesOff(); + // reader.ReadZonesOff(); + // reader.setTimeStep(0.0); + // // reader.UpdateInformation(); + // reader.Update(); + // // reader.UpdateExtent(); + // + // } + + public static boolean decomposePolyhedra = true; + private vtkPOpenFOAMReader reader; - private Model model; - public VTKOpenFOAMReader(Model model, ProgressMonitor monitor, String meshType) { - this.model = model; + public VTKOpenFOAMReader(File baseDir, boolean parallel, ProgressMonitor monitor/*, String meshType*/) { + File foamFile = new File(baseDir, " "); + reader = new vtkPOpenFOAMReader(); + if (parallel) { + reader.SetCaseType(0); + } else { + reader.SetCaseType(1); + } + reader.SetFileName(foamFile.getAbsolutePath()); + reader.CreateCellToPointOn(); - File baseDir = model.getProject().getBaseDir(); - File foamFile = new File(baseDir, " "); + reader.DisableAllCellArrays(); + reader.DisableAllLagrangianArrays(); + reader.DisableAllPointArrays(); + reader.DisableAllPatchArrays(); - boolean parallel = model.getProject().isParallel(); + reader.CacheMeshOff(); - reader = new vtkPOpenFOAMReader(); - if (parallel) { - reader.SetCaseType(0); - } else { - reader.SetCaseType(1); - } - reader.SetFileName(foamFile.getAbsolutePath()); - reader.CreateCellToPointOn(); + reader.DecomposePolyhedraOn(); // se qui si mette OFF viene giu' tutto - reader.DisableAllCellArrays(); - reader.DisableAllLagrangianArrays(); - reader.DisableAllPointArrays(); - reader.DisableAllPatchArrays(); + reader.ReleaseDataFlagOn(); - reader.CacheMeshOff(); + if (monitor != null) { + VTKProgressMonitorWrapper progressWrapper = new VTKProgressMonitorWrapper("", reader, monitor); + reader.AddObserver("StartEvent", progressWrapper, "onStart"); + reader.AddObserver("EndEvent", progressWrapper, "onEnd"); + reader.AddObserver("ProgressEvent", progressWrapper, "onProgress"); - reader.DecomposePolyhedraOn(); // se qui si mette OFF viene giu' tutto + monitor.setIndeterminate(false); + monitor.setTotal(100); +// monitor.info("-> " + meshType + " Mesh"); + } + } - reader.ReleaseDataFlagOn(); - - if (monitor != null) { - VTKProgressMonitorWrapper progressWrapper = new VTKProgressMonitorWrapper("", reader, monitor); - reader.AddObserver("StartEvent", progressWrapper, "onStart"); - reader.AddObserver("EndEvent", progressWrapper, "onEnd"); - reader.AddObserver("ProgressEvent", progressWrapper, "onProgress"); - - monitor.setIndeterminate(false); - monitor.setTotal(100); - monitor.info("-> " + meshType + " Mesh"); - } - } + public void ReadInternalMeshOff() { + reader.SetPatchArrayStatus("internalMesh", 0); + if (decomposePolyhedra) { + reader.DecomposePolyhedraOn(); + } else { + reader.DecomposePolyhedraOff(); + } + } - public void ReadInternalMeshOff() { - reader.SetPatchArrayStatus("internalMesh", 0); - if (decomposePolyhedra) { - reader.DecomposePolyhedraOn(); - } else { - reader.DecomposePolyhedraOff(); - } - } + public void ReadInternalMeshOn() { + reader.SetPatchArrayStatus("internalMesh", 1); + if (decomposePolyhedra) { + reader.DecomposePolyhedraOn(); + } else { + reader.DecomposePolyhedraOff(); + } + } - public void ReadInternalMeshOn() { - reader.SetPatchArrayStatus("internalMesh", 1); - if (decomposePolyhedra) { - reader.DecomposePolyhedraOn(); - } else { - reader.DecomposePolyhedraOff(); - } - } + public void ReadPatchesOff() { +// Patches patches = model.getPatches().patchesToDisplay(); +// for (String patch : patches.toMap().keySet()) { +// reader.SetPatchArrayStatus(patch, 0); +// } + reader.DisableAllPatchArrays(); + } - public void ReadPatchesOff() { - Patches patches = model.getPatches().patchesToDisplay(); - for (String patch : patches.toMap().keySet()) { - reader.SetPatchArrayStatus(patch, 0); - } - } + public void ReadPatchesOn() { +// Patches patches = model.getPatches().patchesToDisplay(); +// for (String patch : patches.toMap().keySet()) { +// reader.SetPatchArrayStatus(patch, 1); +// } + reader.EnableAllPatchArrays(); + } - public void ReadPatchesOn() { - Patches patches = model.getPatches().patchesToDisplay(); - for (String patch : patches.toMap().keySet()) { - reader.SetPatchArrayStatus(patch, 1); - } - } + public void ReadZonesOn() { + reader.ReadZonesOn(); + } - public void ReadZonesOn() { - reader.ReadZonesOn(); - } + public void ReadZonesOff() { + reader.ReadZonesOff(); + } - public void ReadZonesOff() { - reader.ReadZonesOff(); - } + public void setTimeStep(double timeValue) { + vtkExecutive exe = reader.GetExecutive(); + vtkCompositeDataPipeline pipeline = (vtkCompositeDataPipeline) exe; + pipeline.SetUpdateTimeStep(0, timeValue); + } - public void setTimeStep(double timeValue) { - vtkExecutive exe = reader.GetExecutive(); - vtkCompositeDataPipeline pipeline = (vtkCompositeDataPipeline) exe; - pipeline.SetUpdateTimeStep(0, timeValue); - } + public void Delete() { + reader.Delete(); + reader = null; + } - public void Delete() { - reader.Delete(); - reader = null; - } + public void Update() { + reader.Update(); + if (debug) { + VTKUtil.printDatasetData(reader); + } + } - public void Update() { - reader.Update(); - VTKUtil.printDatasetData(reader); - } + public void UpdateExtent() { + reader.UpdateWholeExtent(); + } - public void UpdateExtent() { - reader.UpdateWholeExtent(); - } + public void UpdateInformation() { + reader.UpdateInformation(); + } - public void UpdateInformation() { - reader.UpdateInformation(); - } + public vtkExecutive GetExecutive() { + return reader.GetExecutive(); + } - public vtkExecutive GetExecutive() { - return reader.GetExecutive(); - } + public vtkMultiBlockDataSet GetOutput() { + return reader.GetOutput(); + } - public vtkMultiBlockDataSet GetOutput() { - return reader.GetOutput(); - } + public List getCellArrayNames() { + vtkDataSet dataSet = getAValidDataSet(reader.GetOutput()); + if (dataSet != null) { + return reorderNames(VTKUtil.getCellFields(dataSet)); + } else if (reader.GetNumberOfCellArrays() > 0) { + List list = new ArrayList<>(); + int cellArraysNumber = reader.GetNumberOfCellArrays(); + for (int i = 0; i < cellArraysNumber; i++) { + list.add(reader.GetCellArrayName(i)); + } + return list; + } else { + return Collections.emptyList(); + } + } - public List getCellArrayNames() { - vtkDataSet dataSet = getAValidDataSet(reader.GetOutput()); - if (dataSet != null) { - return reorderNames(VTKUtil.getCellFields(dataSet)); - } else if (reader.GetNumberOfCellArrays() > 0) { - List list = new ArrayList<>(); - int cellArraysNumber = reader.GetNumberOfCellArrays(); - for (int i = 0; i < cellArraysNumber; i++) { - list.add(reader.GetCellArrayName(i)); - } - return list; - } else { - return Collections.emptyList(); - } - } + public List getPointArrayNames() { + vtkDataSet dataSet = getAValidDataSet(reader.GetOutput()); + if (dataSet != null) { + return reorderNames(VTKUtil.getPointFields(dataSet)); + } else if (reader.GetNumberOfPointArrays() > 0) { + List list = new ArrayList<>(); + int pointArraysNumber = reader.GetNumberOfPointArrays(); + for (int i = 0; i < pointArraysNumber; i++) { + list.add(reader.GetPointArrayName(i)); + } + return list; + } else { + return Collections.emptyList(); + } + } - public List getPointArrayNames() { - vtkDataSet dataSet = getAValidDataSet(reader.GetOutput()); - if (dataSet != null) { - return reorderNames(VTKUtil.getPointFields(dataSet)); - } else if (reader.GetNumberOfPointArrays() > 0) { - List list = new ArrayList<>(); - int pointArraysNumber = reader.GetNumberOfPointArrays(); - for (int i = 0; i < pointArraysNumber; i++) { - list.add(reader.GetPointArrayName(i)); - } - return list; - } else { - return Collections.emptyList(); - } - } + public static List reorderNames(String[] names) { + List list = new ArrayList<>(); + for (String string : names) { + list.add(string); + } + List fields = Arrays.asList(Fields.EDITABLE_FIELDS); + List ordered = new LinkedList(); + for (String field : fields) { + int index = list.indexOf(field); + if (index >= 0) { + ordered.add(list.remove(index)); + } + } + ordered.addAll(list); - public static List reorderNames(String[] names) { - List list = new ArrayList<>(); - for (String string : names) { - list.add(string); - } - List fields = Arrays.asList(Fields.EDITABLE_FIELDS); - List ordered = new LinkedList(); - for (String field : fields) { - int index = list.indexOf(field); - if (index >= 0) { - ordered.add(list.remove(index)); - } - } - ordered.addAll(list); + return ordered; + } - return ordered; - } + private vtkDataSet getAValidDataSet(vtkMultiBlockDataSet dataSet) { + if (dataSet != null) { + if (dataSet.GetNumberOfBlocks() > 0) { + vtkDataObject block = dataSet.GetBlock(0); + if (block instanceof vtkMultiBlockDataSet) { + return getAValidDataSet((vtkMultiBlockDataSet) block); + } else if (block instanceof vtkDataSet) { + return (vtkDataSet) block; + } + } + } + return null; + } - private vtkDataSet getAValidDataSet(vtkMultiBlockDataSet dataSet) { - if (dataSet != null) { - if (dataSet.GetNumberOfBlocks() > 0) { - vtkDataObject block = dataSet.GetBlock(0); - if (block instanceof vtkMultiBlockDataSet) { - return getAValidDataSet((vtkMultiBlockDataSet) block); - } else if (block instanceof vtkDataSet) { - return (vtkDataSet) block; - } - } - } - return null; - } - - } diff --git a/src/eu/engys/vtk/VTKPatches.java b/src/eu/engys/vtk/VTKPatches.java index 685f133..0c69a7e 100644 --- a/src/eu/engys/vtk/VTKPatches.java +++ b/src/eu/engys/vtk/VTKPatches.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.vtk; import java.util.ArrayList; @@ -35,139 +34,118 @@ import java.util.Map; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import vtk.vtkDataObject; -import vtk.vtkPolyData; import eu.engys.core.project.Model; import eu.engys.core.project.zero.patches.Patch; import eu.engys.gui.view3D.Actor; +import eu.engys.gui.view3D.PickInfo; import eu.engys.gui.view3D.Picker; import eu.engys.gui.view3D.RenderPanel; +import vtk.vtkDataSet; +import vtk.vtkPolyData; public class VTKPatches implements VTKActors, Picker { - private static final Logger logger = LoggerFactory.getLogger(VTKPatches.class); - - private Map actors = new LinkedHashMap<>(); - private Map names = new LinkedHashMap<>(); - - private RenderPanel renderPanel; - private Model model; + private static final Logger logger = LoggerFactory.getLogger(VTKPatches.class); - public VTKPatches(Model model) { - this.model = model; - } - - @Override - public void setRenderPanel(RenderPanel renderPanel) { - this.renderPanel = renderPanel; - } - - public void load(List patchesDataset) { - for (int i = 0; i < patchesDataset.size(); i++) { - vtkDataObject obj = patchesDataset.get(i); - if (obj instanceof vtkPolyData) { - Patch patch = model.getPatches().patchesToDisplay().get(i); - patch.setLoaded(true); - patch.setDataSet((vtkPolyData) obj); - addActorToPatches(new PatchActor(patch)); - } - } - } - - void addActorToPatches(Actor actor) { - logger.debug("[ADD ACTOR] {} ({})", actor.getName(), actor.getVisibility() ? "visible" : "hidden"); + private Map actors = new LinkedHashMap<>(); + private Map names = new LinkedHashMap<>(); + + private RenderPanel renderPanel; + private Model model; + + public VTKPatches(Model model) { + this.model = model; + } + + @Override + public void setRenderPanel(RenderPanel renderPanel) { + this.renderPanel = renderPanel; + } + + public void load(Map patchesDataset) { + Map patchMap = model.getPatches().patchesToDisplay().toMap(); + for (String patchName : patchMap.keySet()) { + Patch patch = patchMap.get(patchName); + patch.setLoaded(true); + patch.setDataSet(patchesDataset.get(patchName)); + addActorToPatches(new PatchActor(patch)); + } + } + + void addActorToPatches(Actor actor) { + logger.debug("[ADD ACTOR] {} ({})", actor.getName(), actor.getVisibility() ? "visible" : "hidden"); actors.put(actor.getName(), actor); names.put(actor, actor.getName()); } void addActorsToRenderer() { - for (String name : actors.keySet()) { - Actor actor = actors.get(name); - renderPanel.addActor(actor); - } - } - - public void addPatchMap(Map map, Map visibility) { - for (String name : map.keySet()) { - Actor actor = map.get(name); - actor.setVisibility(visibility.get(name)); - addActorToPatches(actor); + for (String name : actors.keySet()) { + Actor actor = actors.get(name); renderPanel.addActor(actor); - } } - - public void deleteActors() { - for (Actor actor : actors.values()) { + + public void deleteActors() { + for (Actor actor : actors.values()) { renderPanel.removeActor(actor); actor.deleteActor(); } - actors.clear(); - names.clear(); - } + actors.clear(); + names.clear(); + } - public void removeActorsFromRenderer() { - for (Actor actor : actors.values()) { + public void removeActorsFromRenderer() { + for (Actor actor : actors.values()) { renderPanel.removeActor(actor); } - actors.clear(); - names.clear(); - } + actors.clear(); + names.clear(); + } - public void VisibilityOn() { - for (Actor actor : actors.values()) { + public void VisibilityOn() { + for (Actor actor : actors.values()) { actor.setVisibility(true); } - } - - public void VisibilityOff() { - for (Actor actor : actors.values()) { - actor.setVisibility(false); - } - } + } - @Override - public Collection getActors() { - return actors.values(); - } + public void VisibilityOff() { + for (Actor actor : actors.values()) { + actor.setVisibility(false); + } + } - @Override - public boolean containsActor(Actor actor) { - return names.containsKey(actor); - } + @Override + public Collection getActors() { + return actors.values(); + } -// @Override -// public String getActorName(Actor pickedActor) { -// return names.get(pickedActor); -// } - - @Override - public boolean canPickCells(Actor pickedActor) { - return false; - } - - @Override - public boolean canPickMesh() { - return true; - } + @Override + public boolean containsActor(Actor actor) { + return names.containsKey(actor); + } - public void updateSelection(Patch[] patches) { - logger.debug("updateSurfaceVisibility: {} patches selected {}", patches.length, patches.length == 1 ? ", selection is: " + patches[0] : ""); - - List selection = new ArrayList(); + @Override + public boolean canPickMesh() { + return true; + } - for (Patch patch : patches) { - String name = patch.getName(); - if (patch.isVisible() && actors.containsKey(name)) { - selection.add(actors.get(name)); - } - } - renderPanel.setLowRendering(); - renderPanel.selectActors(false, selection.toArray(new Actor[0])); - renderPanel.setHighRendering(); - } + public void updateSelection(Patch[] patches) { + logger.debug("updateSurfaceVisibility: {} patches selected {}", patches.length, patches.length == 1 ? ", selection is: " + patches[0] : ""); - public void updateVisibility(Patch[] selection) { + List selection = new ArrayList(); + + for (Patch patch : patches) { + String name = patch.getName(); + if (patch.isVisible() && actors.containsKey(name)) { + selection.add(actors.get(name)); + } + } + renderPanel.setLowRendering(); + renderPanel.selectActors(false, selection.toArray(new Actor[0])); + renderPanel.setHighRendering(); + } + + public void updateVisibility(Patch[] selection) { for (Patch patch : selection) { String name = patch.getName(); if (actors.containsKey(name)) { @@ -178,25 +156,38 @@ public class VTKPatches implements VTKActors, Picker { renderPanel.renderLater(); } - public void update(List patchesDataset) { - List actorsList = new ArrayList<>(getActors()); - for (int i = 0; i < patchesDataset.size(); i++) { - vtkDataObject subset = patchesDataset.get(i); - Actor actor = actorsList.get(i); - if (subset instanceof vtkPolyData) { - logger.debug("Update polydata {}", names.get(actor)); - VTKUtil.changeDataset(actor, (vtkPolyData) subset); - } - } - } + public void update(List patchesDataset) { + VTKUtil.printTotalMemory(patchesDataset.toArray(new vtkDataSet[0])); - @Override - public Map getActorsMap() { - return Collections.unmodifiableMap(actors); - } + List actorsList = new ArrayList<>(getActors()); + for (int i = 0; i < patchesDataset.size(); i++) { + vtkPolyData subset = patchesDataset.get(i); + Actor actor = actorsList.get(i); + logger.debug("Update actor input {}", names.get(actor)); + actor.setInput(subset); + } + } + + @Override + public Map getActorsMap() { + return Collections.unmodifiableMap(actors); + } + + @Override + public void addActorsMap(Map map, Map visibility) { + for (String name : map.keySet()) { + Actor actor = map.get(name); + actor.setVisibility(visibility.get(name)); + addActorToPatches(actor); + } + addActorsToRenderer(); + } public boolean isLoaded() { return !actors.isEmpty(); } + @Override + public void pickActor(PickInfo pi) { + } } diff --git a/src/eu/engys/vtk/VTKPickManager.java b/src/eu/engys/vtk/VTKPickManager.java index b0a0522..c6c56eb 100644 --- a/src/eu/engys/vtk/VTKPickManager.java +++ b/src/eu/engys/vtk/VTKPickManager.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.vtk; @@ -30,10 +29,6 @@ import java.awt.event.MouseEvent; import java.util.ArrayList; import java.util.List; -import vtk.vtkAreaPicker; -import vtk.vtkCellPicker; -import vtk.vtkGenericRenderWindowInteractor; -import vtk.vtkWorldPointPicker; import eu.engys.gui.events.EventManager; import eu.engys.gui.events.EventManager.Event; import eu.engys.gui.events.view3D.ActorPopUpEvent; @@ -44,10 +39,14 @@ import eu.engys.gui.view3D.PickInfo; import eu.engys.gui.view3D.PickManager; import eu.engys.gui.view3D.Picker; import eu.engys.gui.view3D.RenderPanel; +import vtk.vtkAreaPicker; +import vtk.vtkCellPicker; +import vtk.vtkGenericRenderWindowInteractor; +import vtk.vtkPointPicker; public class VTKPickManager implements PickManager { - enum PickFor {ACTOR, CELL}; + enum PickFor {ACTOR, CELL, POINT}; private final RenderPanel renderPanel; private PickFor pickFor; @@ -57,15 +56,20 @@ public class VTKPickManager implements PickManager { } public void pick(int x, int y, boolean control, boolean shift) { - PickInfo pi = pickCell(x, y); - pi.shift = shift; - pi.control = control; - - if (pickFor == PickFor.ACTOR) { - pickActor(pi); - } else { - pickCell(pi); - } + if (pickFor == PickFor.POINT) { + PickInfo pi = pickPoint(x, y); + pickPoint(pi); + } else { + PickInfo pi = pickCell(x, y); + pi.shift = shift; + pi.control = control; + + if (pickFor == PickFor.ACTOR) { + pickActor(pi); + } else { + pickCell(pi); + } + } } public void pickArea(int[] startPosition, int[] endPosition, boolean control, boolean shift) { @@ -81,6 +85,9 @@ public class VTKPickManager implements PickManager { } void pickActor(PickInfo pi) { + for (final Picker picker : pickersForActors) { + picker.pickActor(pi); + } if (pi != null && pi.actor != null) { renderPanel.selectActors(pi.control, pi.actor); EventManager.triggerEvent(this, getSelectionEvent(pi.control, pi.actor)); @@ -98,55 +105,97 @@ public class VTKPickManager implements PickManager { } return new ActorSelectionEvent(null, null, false); } - - private void pickCell(final PickInfo pi) { - for (final CellPicker picker : pickersForCells) { - picker.pick(pi); -// ExecUtil.invokeLater(new Runnable() { -// @Override -// public void run() { -// } -// }); - } - } + + private void pickCell(final PickInfo pi) { + for (final CellPicker picker : pickersForCells) { + picker.pick(pi); + } + } + + private void pickPoint(final PickInfo pi) { + for (final CellPicker picker : pickersForPoints) { + picker.pick(pi); + } + } private List pickersForActors = new ArrayList<>(); private List pickersForCells = new ArrayList<>(); + private List pickersForPoints = new ArrayList<>(); + @Override public void registerPickerForActors(Picker picker) { pickersForActors.add(picker); } - public void registerPickerForCells(CellPicker picker) { - pickersForCells.add(picker); + @Override + public void unregisterPickerForActors(Picker picker) { + pickersForActors.remove(picker); } - public void unregisterPickerForCells(CellPicker picker) { - pickersForCells.remove(picker); - } + @Override + public void registerPickerForCells(CellPicker picker) { + pickersForCells.add(picker); + } + + @Override + public void unregisterPickerForCells(CellPicker picker) { + pickersForCells.remove(picker); + } + + @Override + public void registerPickerForPoints(CellPicker picker) { + pickersForPoints.add(picker); + } + + @Override + public void unregisterPickerForPoints(CellPicker picker) { + pickersForPoints.remove(picker); + } + @Override public void pickForActors() { pickFor = PickFor.ACTOR; } + @Override public void pickForCells() { pickActor(null); pickFor = PickFor.CELL; } - - public double[] pickPoint() { - int[] position = ((vtkGenericRenderWindowInteractor)((VTKRenderPanel)renderPanel).getInteractor()).GetLastEventPosition(); - return pickPoint(position); + + @Override + public void pickForPoints() { + pickActor(null); + pickFor = PickFor.POINT; } - public double[] pickPoint(int[] eventPosition) { + @Override + public PickInfo pickPoint() { + int[] position = ((vtkGenericRenderWindowInteractor)((VTKRenderPanel)renderPanel).getInteractor()).GetLastEventPosition(); + return pickPoint(position[0], position[1]); + } + + private PickInfo pickPoint(int x, int y) { renderPanel.lock(); - vtkWorldPointPicker pick = new vtkWorldPointPicker(); +// vtkWorldPointPicker picker = new vtkWorldPointPicker(); + vtkPointPicker picker = new vtkPointPicker(); + picker.SetTolerance(0.005); if (renderPanel instanceof VTKRenderPanel) { - pick.Pick(eventPosition[0], eventPosition[1], 0, ((VTKRenderPanel)renderPanel).GetRenderer()); + picker.Pick(x, y, 0, ((VTKRenderPanel)renderPanel).GetRenderer()); } + renderPanel.unlock(); - return pick.GetPickPosition(); + + PickInfo pi = new PickInfo(); + pi.actor = (Actor) picker.GetActor(); + pi.dataSet = picker.GetDataSet(); + pi.cellId = -1; + pi.pointId = picker.GetPointId(); + pi.cellIJK = null; + pi.normal = null; + pi.position = picker.GetPickPosition(); + + return pi; } private PickInfo pickCell(int x, int y) { @@ -162,6 +211,7 @@ public class VTKPickManager implements PickManager { pi.actor = (Actor) picker.GetActor(); pi.dataSet = picker.GetDataSet(); pi.cellId = picker.GetCellId(); + pi.pointId = -1; pi.cellIJK = picker.GetCellIJK(); pi.normal = picker.GetPickNormal(); pi.position = picker.GetPickPosition(); @@ -185,6 +235,7 @@ public class VTKPickManager implements PickManager { pi.actor = (Actor) picker.GetActor();//centerPicker.GetActor(); pi.dataSet = picker.GetDataSet();//centerPicker.GetDataSet(); pi.cellId = centerPicker.GetCellId(); + pi.pointId = -1; pi.cellIJK = null; pi.normal = null; pi.position = picker.GetPickPosition(); diff --git a/src/eu/engys/vtk/VTKProgressMonitorWrapper.java b/src/eu/engys/vtk/VTKProgressMonitorWrapper.java new file mode 100644 index 0000000..c63695c --- /dev/null +++ b/src/eu/engys/vtk/VTKProgressMonitorWrapper.java @@ -0,0 +1,54 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.vtk; + +import eu.engys.util.progress.ProgressMonitor; +import vtk.vtkAlgorithm; + +public class VTKProgressMonitorWrapper { + + private vtkAlgorithm algo; + private ProgressMonitor monitor; + private String title; + + public VTKProgressMonitorWrapper(String title, vtkAlgorithm algo, ProgressMonitor monitor) { + this.title = title; + this.algo = algo; + this.monitor = monitor; + } + + public void onProgress() { + monitor.setCurrent(null, (int) (algo.GetProgress() * 100)); + } + + public void onStart() { + monitor.infoN("Loading " + title + "... ", 1); + } + + public void onEnd() { + monitor.info("done"); + } + +} diff --git a/src/eu/engys/vtk/VTKRangeCalculator.java b/src/eu/engys/vtk/VTKRangeCalculator.java deleted file mode 100644 index b83ea52..0000000 --- a/src/eu/engys/vtk/VTKRangeCalculator.java +++ /dev/null @@ -1,96 +0,0 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - -package eu.engys.vtk; - -import vtk.vtkDataArray; -import vtk.vtkMapper; -import eu.engys.core.project.mesh.FieldItem; -import eu.engys.core.project.mesh.FieldItem.DataType; -import eu.engys.gui.view3D.Actor; - -public class VTKRangeCalculator { - - private FieldItem fieldItem; - - public VTKRangeCalculator(FieldItem fieldItem) { - this.fieldItem = fieldItem; - } - - public void calculateRange_Automatically_For(VTKActors actors) { - if (!actors.getActors().isEmpty()) { - double[] range = new double[] { Double.MAX_VALUE, -Double.MAX_VALUE }; - for (Actor actor : actors.getActors()) { - if (actor.getVisibility()) { - double[] drange = calculateRangeFor(actor); - if (drange != null) { -// System.out.println("VTKRangeCalculator.calculateRange_Automatically_For() " + Arrays.toString(drange)); - range[0] = Math.min(range[0], drange[0]); - range[1] = Math.max(range[1], drange[1]); - } - } - } - if (range[0] <= range[1] ) { -// System.out.println("VTKRangeCalculator.calculateRange_Automatically_For() " + actors.getClass() + " => " + Arrays.toString(range)); - fieldItem.setRange(range); - } - } - } - - public void calculateRange_Automatically_For(Actor actor) { - double[] range = fieldItem.getRange(); - if (actor.getVisibility()) { - double[] drange = calculateRangeFor(actor); - if (drange != null) { - range[0] = drange[0]; - range[1] = drange[1]; - } - - } - fieldItem.setRange(range); - } - - private double[] calculateRangeFor(Actor actor) { - vtkMapper mapper = actor.getMapper(); - mapper.Update(); - - vtkDataArray pScalars = null; - DataType dataType = fieldItem.getDataType(); - String fieldName = fieldItem.getName(); - - if (dataType.isCell()) { - pScalars = mapper.GetInputAsDataSet().GetCellData().GetScalars(fieldName); - } else if (dataType.isPoint()) { - pScalars = mapper.GetInputAsDataSet().GetPointData().GetScalars(fieldName); - } - - if (pScalars != null) { - return fieldItem.getComponent() >= 0 ? pScalars.GetRange(fieldItem.getComponent() - 1) : pScalars.GetRange(); - } - - return null; - } - -} diff --git a/src/eu/engys/vtk/VTKRenderPanel.java b/src/eu/engys/vtk/VTKRenderPanel.java index 4d68bed..e133051 100644 --- a/src/eu/engys/vtk/VTKRenderPanel.java +++ b/src/eu/engys/vtk/VTKRenderPanel.java @@ -1,29 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.vtk; import java.awt.Color; @@ -42,13 +40,6 @@ import javax.swing.Timer; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import vtk.vtkActorCollection; -import vtk.vtkAssembly; -import vtk.vtkImageData; -import vtk.vtkLight; -import vtk.vtkObject; -import vtk.vtkPanel; -import vtk.vtkWindowToImageFilter; import eu.engys.gui.view3D.Actor; import eu.engys.gui.view3D.CameraManager; import eu.engys.gui.view3D.CameraManager.Position; @@ -58,11 +49,21 @@ import eu.engys.gui.view3D.Representation; import eu.engys.util.PrefUtil; import eu.engys.util.plaf.ILookAndFeel; import eu.engys.util.ui.ExecUtil; +import vtk.vtkActorCollection; +import vtk.vtkAssembly; +import vtk.vtkImageData; +import vtk.vtkLight; +import vtk.vtkObject; +import vtk.vtkPanel; +import vtk.vtkRenderer; +import vtk.vtkWindowToImageFilter; public class VTKRenderPanel extends vtkPanel implements RenderPanel { - private enum LowRendering {ON, OFF} - + private enum LowRendering { + ON, OFF + } + private static final Logger logger = LoggerFactory.getLogger(VTKRenderPanel.class); public class DelayTimer extends Timer implements ActionListener { @@ -75,7 +76,7 @@ public class VTKRenderPanel extends vtkPanel implements RenderPanel { InteractiveOff(); } } - + public class CountdownTimer extends Timer implements ActionListener { private int delay = PrefUtil.getInt(PrefUtil._3D_LOCK_INTRACTIVE_TIME, 2000); @@ -130,65 +131,65 @@ public class VTKRenderPanel extends vtkPanel implements RenderPanel { private void Initialize() { iren = new VTKInteractor(rw); - double[] color1 = laf.get3DColor1(); - double[] color2 = laf.get3DColor2(); - double[] colorSelection = laf.get3DSelectionColor(); + double[] color1 = laf != null ? laf.get3DColor1() : VTKColors.BLUE; + double[] color2 = laf != null ? laf.get3DColor2() : VTKColors.WHITE; + double[] colorSelection = laf != null ? laf.get3DSelectionColor() : VTKColors.PINK; handler = new VTKMouseHandler(this); addMouseListener(handler); addMouseMotionListener(handler); addMouseWheelListener(handler); addKeyListener(handler); - + pickManager = new VTKPickManager(this); - pickManager .pickForActors(); - + pickManager.pickForActors(); + cameraManager = new VTKCameraManager(this); - + ren.GradientBackgroundOn(); ren.SetBackground(color1); ren.SetBackground2(color2); ren.SetGradientBackground(true); - // ren.RemoveAllLights(); + // ren.RemoveAllLights(); ren.AutomaticLightCreationOff(); ren.LightFollowCameraOn(); - - ren.AddLight(createLight( 45, 45)); + + ren.AddLight(createLight(45, 45)); ren.AddLight(createLight(-45, 45)); - ren.AddLight(createLight( 45,-45)); - ren.AddLight(createLight(-45,-45)); + ren.AddLight(createLight(45, -45)); + ren.AddLight(createLight(-45, -45)); sren.AutomaticLightCreationOn(); sren.GradientBackgroundOff(); - //iren.start(); + // iren.start(); addComponentListener(new ComponentAdapter() { public void componentResized(ComponentEvent event) { updateSize(getWidth(), getHeight()); } }); - -// VTKUtil.observe(rw, ""); - -// rw.AddObserver("AbortCheckEvent", this, "AbortCheckEvent"); - } - -// public void AbortCheckEvent() { -// if (rw.GetEventPending() != 0) { -// System.out.println("VTKRenderPanel.AbortCheckEvent() >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> "); -// rw.SetAbortRender(1); -// } -// } - + + // VTKUtil.observe(rw, ""); + + // rw.AddObserver("AbortCheckEvent", this, "AbortCheckEvent"); + } + + // public void AbortCheckEvent() { + // if (rw.GetEventPending() != 0) { + // System.out.println("VTKRenderPanel.AbortCheckEvent() >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> "); + // rw.SetAbortRender(1); + // } + // } + private vtkLight createLight(double elevation, double azimuth) { vtkLight light = new vtkLight(); light.SetIntensity(0.5); - light.SetColor(1,1,1); + light.SetColor(1, 1, 1); light.SetLightTypeToCameraLight(); light.SetDirectionAngle(elevation, azimuth); light.SwitchOn(); - + return light; } @@ -222,7 +223,7 @@ public class VTKRenderPanel extends vtkPanel implements RenderPanel { private void updateSize(int w, int h) { if (windowset == 1) { lock(); - iren.updateSize(w,h); + iren.updateSize(w, h); unlock(); } } @@ -265,53 +266,53 @@ public class VTKRenderPanel extends vtkPanel implements RenderPanel { @Override public void setHighRendering() { -// System.out.println("VTKRenderPanel.setHighRendering()"); + // System.out.println("VTKRenderPanel.setHighRendering()"); if (iren == null) { return; } - + if (lowRendering == LowRendering.OFF) { return; } - + StartTimer(); } @Override public void setLowRendering() { -// System.out.println("VTKRenderPanel.setLowRendering()"); + // System.out.println("VTKRenderPanel.setLowRendering()"); if (iren == null) { return; } - + if (lowRendering == LowRendering.OFF) { return; } - + DestroyTimer(); - + InteractiveOn(); } private void InteractiveOn() { -// System.err.println("VTKRenderPanel.InteractiveOn()"); + // System.err.println("VTKRenderPanel.InteractiveOn()"); lock(); for (Actor actor : getAllActors()) { actor.interactiveOn(); } - + unlock(); } private void InteractiveOff() { -// System.err.println("VTKRenderPanel.InteractiveOff()"); + // System.err.println("VTKRenderPanel.InteractiveOff()"); lock(); for (Actor actor : getAllActors()) { actor.interactiveOff(); } - + unlock(); renderLater(); } @@ -361,6 +362,7 @@ public class VTKRenderPanel extends vtkPanel implements RenderPanel { return; lock(); GetRenderer().ResetCamera(); + getInteractor().setCenter(getCameraManager().getFocusPoint()); unlock(); renderLater(); } @@ -377,6 +379,13 @@ public class VTKRenderPanel extends vtkPanel implements RenderPanel { unlock(); } + @Override + public void removeActor(vtkAssembly actor) { + lock(); + GetRenderer().RemoveActor(actor); + unlock(); + } + @Override public void addActor(Actor actor) { lock(); @@ -392,9 +401,9 @@ public class VTKRenderPanel extends vtkPanel implements RenderPanel { for (Actor actor : getAllActors()) { size += actor.getMemorySize(); } - - logger.debug("Total Memory Size: {}", size); - + + logger.trace("Total Memory Size: {}", size); + for (Actor actor : getAllActors()) { if (size > memory_limit) { actor.deselectedStateOff(); @@ -412,7 +421,7 @@ public class VTKRenderPanel extends vtkPanel implements RenderPanel { correctSelectionVisualization(); unlock(); } - + @Override public void clearSelection() { lock(); @@ -422,14 +431,36 @@ public class VTKRenderPanel extends vtkPanel implements RenderPanel { unlock(); } + @Override + public void filterActors(Actor... actors) { + lock(); + List toKeep = Arrays.asList(actors); + List allActors = getAllActors(); + for (Actor actor : allActors) { + if (toKeep.size() > 0) { + if (toKeep.contains(actor)) { + actor.unfilterActor(); + } else { + actor.filterActor(); + } + } else { + actor.unfilterActor(); + } + } + + unlock(); + Render(); + } + + @Override public void selectActors(boolean keepSelected, Actor... actors) { setLowRendering(); lock(); - + if (!keepSelected) { selection.clear(); } - + List toSelect = new ArrayList<>(); if (keepSelected) { for (Actor actor : actors) { @@ -442,11 +473,11 @@ public class VTKRenderPanel extends vtkPanel implements RenderPanel { } else { toSelect.addAll(Arrays.asList(actors)); } - + selection.addAll(toSelect); - + for (Actor actor : getAllActors()) { -// actor.interactiveOn(); + // actor.interactiveOn(); if (selection.size() > 0) { if (selection.contains(actor)) { actor.selectActor(); @@ -461,12 +492,17 @@ public class VTKRenderPanel extends vtkPanel implements RenderPanel { } } unlock(); -// renderLater(); + // renderLater(); Render(); -// renderAndWait(); + // renderAndWait(); setHighRendering(); } + @Override + public vtkRenderer GetSelectionRenderer() { + return super.GetSelectionRenderer(); + } + private List getAllActors() { List list = new ArrayList<>(); vtkActorCollection actors = ren.GetActors(); @@ -476,7 +512,7 @@ public class VTKRenderPanel extends vtkPanel implements RenderPanel { list.add((Actor) item); } } - + return list; } @@ -485,12 +521,11 @@ public class VTKRenderPanel extends vtkPanel implements RenderPanel { vtkActorCollection actors = sren.GetActors(); for (int a = 0; a < actors.GetNumberOfItems(); a++) { vtkObject item = actors.GetItemAsObject(a); - System.out.println("VTKRenderPanel.getSelectionActors() " +item); + System.out.println("VTKRenderPanel.getSelectionActors() " + item); } - + return list; } - @Override public void setActorColor(Color c, Actor... actors) { @@ -505,7 +540,7 @@ public class VTKRenderPanel extends vtkPanel implements RenderPanel { if (actor == null) continue; actor.setSolidColor(color, opacity); - + } unlock(); } @@ -515,7 +550,7 @@ public class VTKRenderPanel extends vtkPanel implements RenderPanel { selection.clear(); } - Representation representation = Representation.WIREFRAME; + Representation representation = Representation.SURFACE; public void setRepresentation(Representation representation) { this.representation = representation; @@ -535,7 +570,7 @@ public class VTKRenderPanel extends vtkPanel implements RenderPanel { unlock(); Render(); } - + @Override public void ParallelProjectionOn() { lock(); @@ -552,16 +587,16 @@ public class VTKRenderPanel extends vtkPanel implements RenderPanel { Render(); } -// @Override -// public vtkRenderer GetRenderer() { -// return super.GetRenderer(); -// } -// -// @Override -// public vtkRenderWindow GetRenderWindow() { -// return super.GetRenderWindow(); -// } - + // @Override + // public vtkRenderer GetRenderer() { + // return super.GetRenderer(); + // } + // + // @Override + // public vtkRenderWindow GetRenderWindow() { + // return super.GetRenderWindow(); + // } + @Override public Interactor getInteractor() { return this.iren; @@ -571,7 +606,12 @@ public class VTKRenderPanel extends vtkPanel implements RenderPanel { public VTKPickManager getPickManager() { return pickManager; } - + + @Override + public CameraManager getCameraManager() { + return cameraManager; + } + @Override public vtkImageData toImageData() { vtkWindowToImageFilter w2i = new vtkWindowToImageFilter(); @@ -582,12 +622,12 @@ public class VTKRenderPanel extends vtkPanel implements RenderPanel { return w2i.GetOutput(); } - + @Override public void lowRenderingOn() { this.lowRendering = LowRendering.ON; } - + @Override public void lowRenderingOff() { this.lowRendering = LowRendering.OFF; diff --git a/src/eu/engys/vtk/VTKUtil.java b/src/eu/engys/vtk/VTKUtil.java index de34be4..d67491b 100644 --- a/src/eu/engys/vtk/VTKUtil.java +++ b/src/eu/engys/vtk/VTKUtil.java @@ -1,386 +1,626 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.vtk; import java.util.ArrayList; import java.util.Collection; +import java.util.HashMap; import java.util.List; +import java.util.Map; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import vtk.vtkAlgorithm; -import vtk.vtkAlgorithmOutput; +import eu.engys.core.project.geometry.BoundingBox; +import eu.engys.core.project.geometry.Surface; +import eu.engys.core.project.geometry.surface.Solid; +import eu.engys.gui.view3D.Actor; +import eu.engys.gui.view3D.Controller3D; +import eu.engys.util.FormatUtil; +import eu.engys.util.Util; +import eu.engys.util.VTKSettings; +import vtk.vtkActor; +import vtk.vtkAppendPolyData; +import vtk.vtkCellArray; import vtk.vtkCellData; import vtk.vtkCleanPolyData; import vtk.vtkCompositeDataPipeline; import vtk.vtkCompositeDataSet; +import vtk.vtkConeSource; import vtk.vtkDataArray; import vtk.vtkDataObject; import vtk.vtkDataSet; import vtk.vtkDataSetSurfaceFilter; import vtk.vtkDoubleArray; import vtk.vtkExecutive; +import vtk.vtkFieldData; +import vtk.vtkIdList; import vtk.vtkInformation; import vtk.vtkInformationDoubleKey; import vtk.vtkInformationDoubleVectorKey; +import vtk.vtkInteractorStyleTrackballCamera; +import vtk.vtkIntersectionPolyDataFilter; +import vtk.vtkLineSource; import vtk.vtkMapper; import vtk.vtkMultiBlockDataSet; import vtk.vtkObject; import vtk.vtkOpenFOAMReader; +import vtk.vtkPlaneSource; import vtk.vtkPointData; import vtk.vtkPolyData; -import vtk.vtkPolyDataAlgorithm; import vtk.vtkPolyDataMapper; +import vtk.vtkPolyDataNormals; import vtk.vtkReferenceInformation; +import vtk.vtkRenderWindow; +import vtk.vtkRenderWindowInteractor; +import vtk.vtkRenderer; import vtk.vtkStreamingDemandDrivenPipeline; -import vtk.vtkTrivialProducer; +import vtk.vtkTriangleFilter; +import vtk.vtkTubeFilter; import vtk.vtkUnstructuredGrid; -import eu.engys.core.project.geometry.BoundingBox; -import eu.engys.gui.view3D.Actor; -import eu.engys.gui.view3D.Controller3D; -import eu.engys.util.Util; -import eu.engys.util.VTKSettings; public class VTKUtil { - private static final Logger logger = LoggerFactory.getLogger(VTKUtil.class); + private static final Logger logger = LoggerFactory.getLogger(VTKUtil.class); - public static BoundingBox computeBoundingBox(List controllers, boolean visibleOnly) { + public static BoundingBox computeBoundingBox(List controllers, boolean visibleOnly) { - List allVisibleActors = new ArrayList<>(); + List allVisibleActors = new ArrayList<>(); - for (Controller3D controller : controllers) { - Collection actors = controller.getActorsList(); - for (Actor vtkActor : actors) { - if (!visibleOnly || (visibleOnly && vtkActor.getVisibility())) { - allVisibleActors.add(vtkActor); - } - } - } + for (Controller3D controller : controllers) { + Collection actors = controller.getActorsList(); + for (Actor vtkActor : actors) { + if (!visibleOnly || (visibleOnly && vtkActor.getVisibility())) { + allVisibleActors.add(vtkActor); + } + } + } - return computeBoundingBox(allVisibleActors); - } + return computeBoundingBox(allVisibleActors); + } - public static BoundingBox computeBoundingBox(Collection actors) { - if(Util.isVarArgsNotNull(actors.toArray(new Actor[0]))){ - double xmin = Double.MAX_VALUE; - double xmax = -Double.MAX_VALUE; - double ymin = Double.MAX_VALUE; - double ymax = -Double.MAX_VALUE; - double zmin = Double.MAX_VALUE; - double zmax = -Double.MAX_VALUE; - - for (Actor actor : actors) { - if (actor != null) { - double[] bounds = actor.getBounds(); - xmin = Math.min(xmin, bounds[0]); - xmax = Math.max(xmax, bounds[1]); - ymin = Math.min(ymin, bounds[2]); - ymax = Math.max(ymax, bounds[3]); - zmin = Math.min(zmin, bounds[4]); - zmax = Math.max(zmax, bounds[5]); - } - } - - return new BoundingBox(xmin, xmax, ymin, ymax, zmin, zmax); - } else { - return new BoundingBox(0, 0, 0, 0, 0, 0); - } - - } + public static BoundingBox computeBoundingBox(Surface... surfaces) { + if (Util.isVarArgsNotNull(surfaces)) { + double xmin = Double.MAX_VALUE; + double xmax = -Double.MAX_VALUE; + double ymin = Double.MAX_VALUE; + double ymax = -Double.MAX_VALUE; + double zmin = Double.MAX_VALUE; + double zmax = -Double.MAX_VALUE; - public static void printDatasetData(vtkOpenFOAMReader reader) { - logger.debug("[reader] ---------------" + reader.GetFileName() + "----------------"); - int patchesNumber = reader.GetNumberOfPatchArrays(); - logger.debug("[reader] Patches Number: " + patchesNumber); - logger.debug("[reader] Patches List: "); - for (int i = 0; i < patchesNumber; i++) { - String patchName = reader.GetPatchArrayName(i); - int status = reader.GetPatchArrayStatus(patchName); - logger.debug("[reader] (" + i + ") " + patchName + ", status: " + (status == 0 ? "disabled" : "enabled")); - } + for (Surface surface : surfaces) { + if (surface != null) { + if (surface.getType().isSolid()) { + Solid solid = (Solid) surface; - int cellArraysNumber = reader.GetNumberOfCellArrays(); - logger.debug("[reader] Cell Arrays Number: " + cellArraysNumber); - logger.debug("[reader] Cell Arrays List: "); - for (int i = 0; i < cellArraysNumber; i++) { - String cellArrayName = reader.GetCellArrayName(i); - int status = reader.GetCellArrayStatus(cellArrayName); - logger.debug("[reader] (" + i + ") " + cellArrayName + ", status: " + (status == 0 ? "disabled" : "enabled")); - } + if (solid.getTransformedDataSet() != null) { + double[] bounds = solid.getTransformedDataSet().GetBounds(); + xmin = Math.min(xmin, bounds[0]); + xmax = Math.max(xmax, bounds[1]); + ymin = Math.min(ymin, bounds[2]); + ymax = Math.max(ymax, bounds[3]); + zmin = Math.min(zmin, bounds[4]); + zmax = Math.max(zmax, bounds[5]); + } + } + } + } - int pointArraysNumber = reader.GetNumberOfPointArrays(); - logger.debug("[reader] Point Arrays Number: " + pointArraysNumber); - logger.debug("[reader] Point Arrays List: "); - for (int i = 0; i < pointArraysNumber; i++) { - String pointArrayName = reader.GetPointArrayName(i); - int status = reader.GetPointArrayStatus(pointArrayName); - logger.debug("[reader] (" + i + ") " + pointArrayName + ", status: " + (status == 0 ? "disabled" : "enabled")); - } + return new BoundingBox(xmin, xmax, ymin, ymax, zmin, zmax); + } else { + return new BoundingBox(0, 0, 0, 0, 0, 0); + } + } - logger.debug("[reader] Decompose Polyhedra: " + reader.GetDecomposePolyhedra()); + public static BoundingBox computeBoundingBox(Collection actors) { + if (Util.isVarArgsNotNull(actors.toArray(new Actor[0]))) { + double xmin = Double.MAX_VALUE; + double xmax = -Double.MAX_VALUE; + double ymin = Double.MAX_VALUE; + double ymax = -Double.MAX_VALUE; + double zmin = Double.MAX_VALUE; + double zmax = -Double.MAX_VALUE; - int lagrangianArraysNumber = reader.GetNumberOfLagrangianArrays(); - logger.debug("[reader] Lagrangian Arrays Number: " + lagrangianArraysNumber); - logger.debug("[reader] Lagrangian Arrays List: "); - for (int i = 0; i < lagrangianArraysNumber; i++) { - String lagrangianArrayName = reader.GetLagrangianArrayName(i); - int status = reader.GetLagrangianArrayStatus(lagrangianArrayName); - logger.debug("[reader] (" + i + ") " + lagrangianArrayName + ", status: " + (status == 0 ? "disabled" : "enabled")); - } + for (Actor actor : actors) { + if (actor != null) { + double[] bounds = actor.getBounds(); + xmin = Math.min(xmin, bounds[0]); + xmax = Math.max(xmax, bounds[1]); + ymin = Math.min(ymin, bounds[2]); + ymax = Math.max(ymax, bounds[3]); + zmin = Math.min(zmin, bounds[4]); + zmax = Math.max(zmax, bounds[5]); + } + } - logger.debug("[reader] Read Zones: " + reader.GetReadZones()); + return new BoundingBox(xmin, xmax, ymin, ymax, zmin, zmax); + } else { + return new BoundingBox(0, 0, 0, 0, 0, 0); + } - vtkDoubleArray times = reader.GetTimeValues(); - if (times != null) { - logger.debug("[reader] Time Values: ["); - for (int i = 0; i < times.GetSize(); i++) { - logger.debug("[Time]" + times.GetValue(i) + ", "); - } - logger.debug("]"); - } else { - // reader.UpdateInformation(); // Scan time steps and create - // metadata - vtkExecutive exe = reader.GetExecutive(); - vtkInformation outInfo = exe.GetOutputInformation(0); - vtkInformationDoubleVectorKey timeStepsKey = new vtkStreamingDemandDrivenPipeline().TIME_STEPS(); - int nTimeSteps = outInfo.Length(timeStepsKey); // Get the number of - // time steps - logger.debug("[reader] Time Values: " + nTimeSteps); - for (int i = 0; i < nTimeSteps; i++) { - double timeValue = outInfo.Get(timeStepsKey, i); // Get the i-th + } + + public static void printDatasetData(vtkOpenFOAMReader reader) { + logger.debug("[reader] ---------------" + reader.GetFileName() + "----------------"); + int patchesNumber = reader.GetNumberOfPatchArrays(); + logger.debug("[reader] Patches Number: " + patchesNumber); + logger.debug("[reader] Patches List: "); + for (int i = 0; i < patchesNumber; i++) { + String patchName = reader.GetPatchArrayName(i); + int status = reader.GetPatchArrayStatus(patchName); + logger.debug("[reader] (" + i + ") " + patchName + ", status: " + (status == 0 ? "disabled" : "enabled")); + } + + int cellArraysNumber = reader.GetNumberOfCellArrays(); + logger.debug("[reader] Cell Arrays Number: " + cellArraysNumber); + logger.debug("[reader] Cell Arrays List: "); + for (int i = 0; i < cellArraysNumber; i++) { + String cellArrayName = reader.GetCellArrayName(i); + int status = reader.GetCellArrayStatus(cellArrayName); + logger.debug("[reader] (" + i + ") " + cellArrayName + ", status: " + (status == 0 ? "disabled" : "enabled")); + } + + int pointArraysNumber = reader.GetNumberOfPointArrays(); + logger.debug("[reader] Point Arrays Number: " + pointArraysNumber); + logger.debug("[reader] Point Arrays List: "); + for (int i = 0; i < pointArraysNumber; i++) { + String pointArrayName = reader.GetPointArrayName(i); + int status = reader.GetPointArrayStatus(pointArrayName); + logger.debug("[reader] (" + i + ") " + pointArrayName + ", status: " + (status == 0 ? "disabled" : "enabled")); + } + + logger.debug("[reader] Decompose Polyhedra: " + reader.GetDecomposePolyhedra()); + + int lagrangianArraysNumber = reader.GetNumberOfLagrangianArrays(); + logger.debug("[reader] Lagrangian Arrays Number: " + lagrangianArraysNumber); + logger.debug("[reader] Lagrangian Arrays List: "); + for (int i = 0; i < lagrangianArraysNumber; i++) { + String lagrangianArrayName = reader.GetLagrangianArrayName(i); + int status = reader.GetLagrangianArrayStatus(lagrangianArrayName); + logger.debug("[reader] (" + i + ") " + lagrangianArrayName + ", status: " + (status == 0 ? "disabled" : "enabled")); + } + + logger.debug("[reader] Read Zones: " + reader.GetReadZones()); + + vtkDoubleArray times = reader.GetTimeValues(); + if (times != null) { + logger.debug("[reader] Time Values: ["); + for (int i = 0; i < times.GetSize(); i++) { + logger.debug("[Time]" + times.GetValue(i) + ", "); + } + logger.debug("]"); + } else { + // reader.UpdateInformation(); // Scan time steps and create + // metadata + vtkExecutive exe = reader.GetExecutive(); + vtkInformation outInfo = exe.GetOutputInformation(0); + vtkInformationDoubleVectorKey timeStepsKey = new vtkStreamingDemandDrivenPipeline().TIME_STEPS(); + int nTimeSteps = outInfo.Length(timeStepsKey); // Get the number of + // time steps + logger.debug("[reader] Time Values: " + nTimeSteps); + for (int i = 0; i < nTimeSteps; i++) { + double timeValue = outInfo.Get(timeStepsKey, i); // Get the i-th // time value - logger.debug("[reader] Step: " + i + ", Value: " + timeValue); - } - } + logger.debug("[reader] Step: " + i + ", Value: " + timeValue); + } + } - vtkExecutive exe = reader.GetExecutive(); - vtkCompositeDataPipeline pipeline = (vtkCompositeDataPipeline) exe; - vtkInformation outInfo = exe.GetOutputInformation(0); - vtkInformationDoubleVectorKey TIME_STEPS = pipeline.TIME_STEPS(); - vtkInformationDoubleKey UPDATE_TIME_STEP = pipeline.UPDATE_TIME_STEP(); + vtkExecutive exe = reader.GetExecutive(); + vtkCompositeDataPipeline pipeline = (vtkCompositeDataPipeline) exe; + vtkInformation outInfo = exe.GetOutputInformation(0); + vtkInformationDoubleVectorKey TIME_STEPS = pipeline.TIME_STEPS(); + vtkInformationDoubleKey UPDATE_TIME_STEP = pipeline.UPDATE_TIME_STEP(); int nTimeSteps = outInfo.Length(TIME_STEPS); // Get the number of time steps - logger.debug("[pipeline] Time Values: " + nTimeSteps); - logger.debug("[pipeline] Time Values: current is " + outInfo.Get(UPDATE_TIME_STEP)); - for (int i = 0; i < nTimeSteps; i++) { + logger.debug("[pipeline] Time Values: " + nTimeSteps); + logger.debug("[pipeline] Time Values: current is " + outInfo.Get(UPDATE_TIME_STEP)); + for (int i = 0; i < nTimeSteps; i++) { double timeValue = outInfo.Get(TIME_STEPS, i); // Get the i-th time value - logger.debug("[pipeline] Step: " + i + ", Value: " + timeValue); + logger.debug("[pipeline] Step: " + i + ", Value: " + timeValue); - } + } - vtkMultiBlockDataSet dataset = reader.GetOutput(); - int blocksNumber = dataset.GetNumberOfBlocks(); - logger.debug("[dataset]\tBlocks Number: " + blocksNumber); - for (int i = 0; i < blocksNumber; i++) { - vtkDataObject block = dataset.GetBlock(i); - String name = dataset.GetMetaData(i).Get(new vtkCompositeDataSet().NAME()); - readBlock(block, name, i, "\t"); - } - logger.debug("[reader] ---------------" + reader.GetFileName() + "----------------"); - } + vtkMultiBlockDataSet dataset = reader.GetOutput(); + int blocksNumber = dataset.GetNumberOfBlocks(); + logger.debug("[dataset]\tBlocks Number: " + blocksNumber); + for (int i = 0; i < blocksNumber; i++) { + vtkDataObject block = dataset.GetBlock(i); + String name = dataset.GetMetaData(i).Get(new vtkCompositeDataSet().NAME()); + readBlock(block, name, i, "\t"); + } + logger.debug("[reader] ---------------" + reader.GetFileName() + "----------------"); + } - private static void readBlock(vtkDataObject block, String name, int i, String indent) { - if (block instanceof vtkMultiBlockDataSet) { - vtkMultiBlockDataSet multiBlockDataSet = (vtkMultiBlockDataSet) block; + private static void readBlock(vtkDataObject block, String name, int i, String indent) { + if (block instanceof vtkMultiBlockDataSet) { + vtkMultiBlockDataSet multiBlockDataSet = (vtkMultiBlockDataSet) block; int nBlocks = multiBlockDataSet.GetNumberOfBlocks(); logger.debug("[dataset]" + indent + "Block {} '{}': MultiBlockDataset, {} Sub Blocks", i, name, nBlocks); - for (int j = 0; j < nBlocks; j++) { - vtkDataObject subBlock = multiBlockDataSet.GetBlock(j); - String subName = multiBlockDataSet.GetMetaData(j).Get(new vtkCompositeDataSet().NAME()); - readBlock(subBlock, subName, j, indent + indent); - } - } else if (block instanceof vtkUnstructuredGrid) { - logger.debug("[dataset]" + indent + "Block {} '{}': UnstructuredGrid", i, name); - readFields((vtkDataSet) block, indent); - } else if (block instanceof vtkPolyData) { - logger.debug("[dataset]" + indent + "Block {} '{}': PolyData", i, name); - readFields((vtkDataSet) block, indent); - } else { - logger.debug("[dataset]" + indent + "Block {} '{}': OTHER {}", i, name, block); - } - } + for (int j = 0; j < nBlocks; j++) { + vtkDataObject subBlock = multiBlockDataSet.GetBlock(j); + String subName = multiBlockDataSet.GetMetaData(j).Get(new vtkCompositeDataSet().NAME()); + readBlock(subBlock, subName, j, indent + indent); + } + } else if (block instanceof vtkUnstructuredGrid) { + logger.debug("[dataset]" + indent + "Block {} '{}': UnstructuredGrid", i, name); + readFields((vtkDataSet) block, indent); + } else if (block instanceof vtkPolyData) { + logger.debug("[dataset]" + indent + "Block {} '{}': PolyData", i, name); + readFields((vtkDataSet) block, indent); + } else { + logger.debug("[dataset]" + indent + "Block {} '{}': OTHER {}", i, name, block); + } + } - private static void readFields(vtkDataSet dataSet, String indent) { - String[] pointFields = getPointFields(dataSet); - logger.debug("[dataset]" + indent + "\tPointData Arrays Number: " + pointFields.length); - for (int i = 0; i < pointFields.length; i++) { - logger.debug("[dataset]" + indent + "\t\t array " + i + ": " + pointFields[i]); - } - String[] cellFields = getCellFields(dataSet); - logger.debug("[dataset]" + indent + "\tCellData Arrays Number: " + cellFields.length); - for (int i = 0; i < cellFields.length; i++) { - logger.debug("[dataset]" + indent + "\t\t array " + i + ": " + cellFields[i]); - } - } + private static void readFields(vtkDataSet dataSet, String indent) { + String[] pointFields = getPointFields(dataSet); + Map pointRange = getPointFieldsRanges(dataSet); + logger.debug("[dataset]" + indent + "\tPointData Arrays Number: " + pointFields.length); + for (int i = 0; i < pointFields.length; i++) { + String fieldName = pointFields[i]; + if (fieldName.equals("U")) { + logger.debug("[dataset]" + indent + "\t\t array " + i + ": " + fieldName + " [" + pointRange.get(fieldName)[0][0] + ", " + pointRange.get(fieldName)[0][1] + "]" + " [" + pointRange.get(fieldName)[1][0] + ", " + pointRange.get(fieldName)[1][1] + "]" + " [" + pointRange.get(fieldName)[2][0] + ", " + pointRange.get(fieldName)[2][1] + "]" + " [" + pointRange.get(fieldName)[3][0] + ", " + pointRange.get(fieldName)[3][1] + "]"); - public static String[] getPointFields(vtkDataSet dataSet) { - vtkPointData pointData = dataSet.GetPointData(); - String[] fields = new String[pointData.GetNumberOfArrays()]; - for (int i = 0; i < fields.length; i++) { - fields[i] = pointData.GetArrayName(i); - } - return fields; - } + } else { + logger.debug("[dataset]" + indent + "\t\t array " + i + ": " + fieldName + " [" + pointRange.get(fieldName)[0][0] + ", " + pointRange.get(fieldName)[0][1] + "]"); + } + } + String[] cellFields = getCellFields(dataSet); + Map cellRange = getCellFieldsRanges(dataSet); + logger.debug("[dataset]" + indent + "\tCellData Arrays Number: " + cellFields.length); + for (int i = 0; i < cellFields.length; i++) { + String fieldName = cellFields[i]; + if (fieldName.equals("U")) { + logger.debug("[dataset]" + indent + "\t\t array " + i + ": " + fieldName + " [" + cellRange.get(fieldName)[0][0] + ", " + cellRange.get(fieldName)[0][1] + "]" + " [" + cellRange.get(fieldName)[1][0] + ", " + cellRange.get(fieldName)[1][1] + "]" + " [" + cellRange.get(fieldName)[2][0] + ", " + cellRange.get(fieldName)[2][1] + "]" + " [" + cellRange.get(fieldName)[3][0] + ", " + cellRange.get(fieldName)[3][1] + "]"); + } else { + logger.debug("[dataset]" + indent + "\t\t array " + i + ": " + fieldName + " [" + cellRange.get(fieldName)[0][0] + ", " + cellRange.get(fieldName)[0][1] + "]"); + } + } - public static String[] getCellFields(vtkDataSet dataSet) { - vtkCellData cellData = dataSet.GetCellData(); - String[] fields = new String[cellData.GetNumberOfArrays()]; - for (int i = 0; i < fields.length; i++) { - fields[i] = cellData.GetArrayName(i); - } - return fields; - } + } - public static void gc(boolean debug) { - if (VTKSettings.librariesAreLoaded()) { - vtkReferenceInformation info = vtkObject.JAVA_OBJECT_MANAGER.gc(debug); - if (debug) { - logger.debug("K: " + info.listKeptReferenceToString()); - logger.debug("R: " + info.listRemovedReferenceToString()); - } - } - } + public static String[] getPointFields(vtkDataSet dataSet) { + vtkPointData pointData = dataSet.GetPointData(); + String[] fields = new String[pointData.GetNumberOfArrays()]; + for (int i = 0; i < fields.length; i++) { + fields[i] = pointData.GetArrayName(i); + } + return fields; + } + + public static Map getPointFieldsRanges(vtkDataSet dataSet) { + List ds = new ArrayList(); + ds.add(dataSet); + return getPointFieldsRanges(ds); + } + + public static Map getPointFieldsRanges(List dataSet) { + Map rMap = new HashMap<>(); + for (vtkDataSet ds : dataSet) { + vtkPointData pointData = ds.GetPointData(); + for (int i = 0; i < pointData.GetNumberOfArrays(); i++) { + String fieldName = pointData.GetArrayName(i); + + if (!rMap.containsKey(fieldName)) { + double[][] defaultRange = new double[4][2]; + defaultRange[0] = new double[] { Double.MAX_VALUE, -Double.MAX_VALUE }; + defaultRange[1] = new double[] { Double.MAX_VALUE, -Double.MAX_VALUE }; + defaultRange[2] = new double[] { Double.MAX_VALUE, -Double.MAX_VALUE }; + defaultRange[3] = new double[] { Double.MAX_VALUE, -Double.MAX_VALUE }; + rMap.put(fieldName, defaultRange); + } + + double[][] newRanges = new double[4][2]; + newRanges[0] = pointData.GetScalars(fieldName).GetRange(-1); + newRanges[1] = pointData.GetScalars(fieldName).GetRange(0); + newRanges[2] = pointData.GetScalars(fieldName).GetRange(1); + newRanges[3] = pointData.GetScalars(fieldName).GetRange(2); + + double[][] currentRanges = rMap.get(fieldName); + for (int j = 0; j < 4; j++) { + double curMin = currentRanges[j][0]; + double newMin = newRanges[j][0]; + if (newMin < curMin) { + currentRanges[j][0] = newMin; + } + + double curMax = currentRanges[j][1]; + double newMax = newRanges[j][1]; + if (newMax > curMax) { + currentRanges[j][1] = newMax; + } + } + } + } + return rMap; + } + + public static String[] getCellFields(vtkDataSet dataSet) { + vtkCellData cellData = dataSet.GetCellData(); + String[] fields = new String[cellData.GetNumberOfArrays()]; + for (int i = 0; i < fields.length; i++) { + fields[i] = cellData.GetArrayName(i); + } + return fields; + } + + public static Map getCellFieldsRanges(vtkDataSet dataSet) { + List ds = new ArrayList(); + ds.add(dataSet); + return getCellFieldsRanges(ds); + } + + public static Map getCellFieldsRanges(List dataSet) { + Map rMap = new HashMap<>(); + for (vtkDataSet ds : dataSet) { + vtkCellData cellData = ds.GetCellData(); + for (int i = 0; i < cellData.GetNumberOfArrays(); i++) { + String fieldName = cellData.GetArrayName(i); + + if (!rMap.containsKey(fieldName)) { + double[][] defaultRange = new double[4][2]; + defaultRange[0] = new double[] { Double.MAX_VALUE, -Double.MAX_VALUE }; + defaultRange[1] = new double[] { Double.MAX_VALUE, -Double.MAX_VALUE }; + defaultRange[2] = new double[] { Double.MAX_VALUE, -Double.MAX_VALUE }; + defaultRange[3] = new double[] { Double.MAX_VALUE, -Double.MAX_VALUE }; + rMap.put(fieldName, defaultRange); + } + + double[][] newRanges = new double[4][2]; + newRanges[0] = cellData.GetScalars(fieldName).GetRange(-1); + newRanges[1] = cellData.GetScalars(fieldName).GetRange(0); + newRanges[2] = cellData.GetScalars(fieldName).GetRange(1); + newRanges[3] = cellData.GetScalars(fieldName).GetRange(2); + + if (rMap.containsKey(fieldName)) { + double[][] currentRanges = rMap.get(fieldName); + for (int j = 0; j < 4; j++) { + double curMin = currentRanges[j][0]; + double newMin = newRanges[j][0]; + if (newMin < curMin) { + currentRanges[j][0] = newMin; + } + + double curMax = currentRanges[j][1]; + double newMax = newRanges[j][1]; + if (newMax > curMax) { + currentRanges[j][1] = newMax; + } + } + } + + } + } + return rMap; + } + + public static BoundingBox calculateBounds(List dataSet) { + BoundingBox bounds = new BoundingBox(Double.MAX_VALUE, -Double.MAX_VALUE, Double.MAX_VALUE, -Double.MAX_VALUE, Double.MAX_VALUE, -Double.MAX_VALUE); + for (vtkDataSet ds : dataSet) { + double[] dsBounds = ds.GetBounds(); + double dsXmin = dsBounds[0]; + double dsXmax = dsBounds[1]; + double dsYmin = dsBounds[2]; + double dsYmax = dsBounds[3]; + double dsZmin = dsBounds[4]; + double dsZmax = dsBounds[5]; + + if (dsXmin < bounds.getXmin()) { + bounds.setXmin(dsXmin); + } + if (dsXmax > bounds.getXmax()) { + bounds.setXmax(dsXmax); + } + if (dsYmin < bounds.getYmin()) { + bounds.setYmin(dsYmin); + } + if (dsYmax > bounds.getYmax()) { + bounds.setYmax(dsYmax); + } + if (dsZmin < bounds.getZmin()) { + bounds.setZmin(dsZmin); + } + if (dsZmax > bounds.getZmax()) { + bounds.setZmax(dsZmax); + } + } + return bounds; + } + + public static void gc(boolean debug) { + if (VTKSettings.librariesAreLoaded()) { + vtkReferenceInformation info = vtkObject.JAVA_OBJECT_MANAGER.gc(debug); + if (debug) { + logger.debug("K: " + info.listKeptReferenceToString()); + logger.debug("R: " + info.listRemovedReferenceToString()); + } + } + } + + public static vtkPolyData triangleFilter(vtkDataObject input) { + vtkTriangleFilter filter = new vtkTriangleFilter(); + filter.SetInputData(input); + // filter.PassVertsOff(); + // filter.PassLinesOff(); + filter.Update(); + + return filter.GetOutput(); + } + + public static vtkPolyData geometryFilter(vtkUnstructuredGrid dataset) { + vtkDataSetSurfaceFilter filter = new vtkDataSetSurfaceFilter(); + filter.SetInputData(dataset); + filter.PassThroughCellIdsOn(); + filter.PassThroughPointIdsOn(); + filter.Update(); + + vtkPolyData output = filter.GetOutput(); + filter.Delete(); - public static vtkPolyData geometryFilter(vtkUnstructuredGrid dataset) { - vtkUnstructuredGrid input = new vtkUnstructuredGrid(); - input.ShallowCopy(dataset); - - vtkDataSetSurfaceFilter filter = new vtkDataSetSurfaceFilter(); - filter.SetInputData(input); - filter.PassThroughCellIdsOn(); - filter.PassThroughPointIdsOn(); - filter.Update(); - input.Delete(); - - vtkPolyData output = filter.GetOutput(); - filter.Delete(); - return output; - } - - public static vtkPolyData repairDataSet(vtkPolyData dataset) { - vtkCleanPolyData clean = new vtkCleanPolyData(); - // clean.ConvertLinesToPointsOff(); //def: on - // clean.ConvertPolysToLinesOff(); //def: on - // clean.ConvertStripsToPolysOff(); //def: on - // clean.PieceInvariantOff(); //def: on - // clean.PointMergingOff(); //def: on - // clean.SetAbsoluteTolerance(0); //def: 1.0 - // clean.SetTolerance(0);//def: 0.0 - // clean.ToleranceIsAbsoluteOn(); //def: off - clean.SetInputData(dataset); - clean.Update(); + } - return clean.GetOutput(); - } + public static vtkPolyData repairDataSet(vtkPolyData dataset) { + vtkCleanPolyData clean = new vtkCleanPolyData(); + // clean.ConvertLinesToPointsOff(); //def: on + // clean.ConvertPolysToLinesOff(); //def: on + // clean.ConvertStripsToPolysOff(); //def: on + // clean.PieceInvariantOff(); //def: on + // clean.PointMergingOff(); //def: on + // clean.SetAbsoluteTolerance(0); //def: 1.0 + // clean.SetTolerance(0);//def: 0.0 + // clean.ToleranceIsAbsoluteOn(); //def: off + clean.SetInputData(dataset); + clean.Update(); - public static void exit() { - vtkObject.JAVA_OBJECT_MANAGER.deleteAll(); - } + return clean.GetOutput(); + } - public static void changeDataset(Actor actor, vtkPolyData subset) { - vtkMapper mapper = actor.getMapper(); - ((vtkPolyDataMapper) mapper).SetInputData((vtkPolyData) subset); - } + public static void exit() { + vtkObject.JAVA_OBJECT_MANAGER.deleteAll(); + } - public static void changeDataset(Actor actor, vtkUnstructuredGrid subset) { - vtkMapper mapper = actor.getMapper(); - vtkAlgorithmOutput filterOutput = mapper.GetInputConnection(0, 0); - - if (filterOutput.GetProducer() instanceof vtkPolyDataAlgorithm ) { - vtkPolyDataAlgorithm filter = (vtkPolyDataAlgorithm) filterOutput.GetProducer(); - - VTKUtil.deleteDataset(filter.GetInput()); - filter.SetInputData(subset); - mapper.Update(); - } else if (filterOutput.GetProducer() instanceof vtkTrivialProducer ) { - vtkAlgorithm filter = (vtkAlgorithm) filterOutput.GetProducer(); - filter.SetInputDataObject(subset); - mapper.Update(); - } else { - logger.warn("CANNOT CHANGE DATASET FOR: {}", "unstructured grid"); - } - } +// public static void changeDataset(Actor actor, vtkPolyData subset) { +// vtkMapper mapper = actor.getMapper(); +// ((vtkPolyDataMapper) mapper).SetInputData((vtkPolyData) subset); +// } +// +// public static void changeDataset(Actor actor, vtkUnstructuredGrid subset) { +// vtkMapper mapper = actor.getMapper(); +// vtkAlgorithmOutput filterOutput = mapper.GetInputConnection(0, 0); +// +// if (filterOutput.GetProducer() instanceof vtkPolyDataAlgorithm) { +// vtkPolyDataAlgorithm filter = (vtkPolyDataAlgorithm) filterOutput.GetProducer(); +// +// VTKUtil.deleteDataset(filter.GetInput()); +// filter.SetInputData(subset); +// mapper.Update(); +// } else if (filterOutput.GetProducer() instanceof vtkTrivialProducer) { +// vtkAlgorithm filter = (vtkAlgorithm) filterOutput.GetProducer(); +// filter.SetInputDataObject(subset); +// mapper.Update(); +// } else { +// logger.warn("CANNOT CHANGE DATASET FOR: {}", "unstructured grid"); +// } +// } - public static void deleteDataset(vtkDataObject dataObject) { - if (dataObject instanceof vtkDataSet) { - vtkDataSet dataSet = (vtkDataSet) dataObject; - vtkPointData pointData = dataSet.GetPointData(); - vtkDataArray pScalars = pointData.GetScalars(); - if (pScalars != null) - pScalars.Delete(); - pointData.Delete(); + public static void deleteDataset(vtkDataObject dataObject) { + if (dataObject instanceof vtkDataSet) { + vtkDataSet dataSet = (vtkDataSet) dataObject; + vtkPointData pointData = dataSet.GetPointData(); + if (pointData != null) { + vtkDataArray pScalars = pointData.GetScalars(); + if (pScalars != null) { + pScalars.Delete(); + } + pointData.Delete(); + } - vtkCellData cellData = dataSet.GetCellData(); - vtkDataArray cScalars = cellData.GetScalars(); - if (cScalars != null) - cScalars.Delete(); - cellData.Delete(); + vtkCellData cellData = dataSet.GetCellData(); + if (cellData != null) { + vtkDataArray cScalars = cellData.GetScalars(); + if (cScalars != null) { + cScalars.Delete(); + } + cellData.Delete(); + } - dataSet.Delete(); - } else { - System.err.println("NOT A DATASET"); - } - } + vtkFieldData fieldData = dataSet.GetFieldData(); + if (fieldData != null) { + fieldData.Delete(); + } + + dataSet.Delete(); + } else { + System.err.println("NOT A DATASET"); + } + } - public static void observe(vtkObject obj, String label) { - ConsoleObserver o = new ConsoleObserver(obj, label); - - obj.AddObserver("AbortCheckEvent", o, "AbortCheckEvent"); - obj.AddObserver("StartEvent", o, "StartEvent"); - obj.AddObserver("EndEvent", o, "EndEvent"); + public static void observe(vtkObject obj, String label) { + ConsoleObserver o = new ConsoleObserver(obj, label); + + obj.AddObserver("AbortCheckEvent", o, "AbortCheckEvent"); + obj.AddObserver("StartEvent", o, "StartEvent"); + obj.AddObserver("EndEvent", o, "EndEvent"); obj.AddObserver("ProgressEvent", o, "ProgressEvent"); obj.AddObserver("TimerEvent", o, "TimerEvent"); obj.AddObserver("ConfigureEvent", o, "ConfigureEvent"); obj.AddObserver("ErrorEvent", o, "ErrorEvent"); obj.AddObserver("WarningEvent", o, "WarningEvent"); - } - - static class ConsoleObserver { - private vtkObject obj; + obj.AddObserver("MouseMoveEvent", o, "MouseMoveEvent"); + } + + static class ConsoleObserver { + private vtkObject obj; private String label; private long time = 0L; + public ConsoleObserver(vtkObject obj, String label) { this.obj = obj; this.label = label; } - public void AbortCheckEvent() { System.err.println("+++ AbortCheckEvent +++" + obj.GetClassName() + " - " + label); } - public void StartEvent() { System.err.println("StartEvent " + obj.GetClassName() + " - " + label); this.time = System.currentTimeMillis();} - public void EndEvent() { System.err.println("EndEvent " + obj.GetClassName() + " - " + label + " - ET: " + (System.currentTimeMillis() - time)/1000D + " sec");} - public void ProgressEvent() { System.err.println("ProgressEvent " + obj.GetClassName() + " - " + label);} - public void ConfigureEvent() { System.err.println("ConfigureEvent " + obj.GetClassName() + " - " + label);} - public void TimerEvent() { System.err.println("TimerEvent " + obj.GetClassName() + " - " + label);} - public void ErrorEvent() { System.err.println("ErrorEvent " + obj.GetClassName() + " - " + label);} - public void WarningEvent() { System.err.println("WarningEvent " + obj.GetClassName() + " - " + label);} - } - public static String logBlockNames(vtkMultiBlockDataSet dataset) { + public void AbortCheckEvent() { + System.err.println("+++ AbortCheckEvent +++" + obj.GetClassName() + " - " + label); + } + + public void StartEvent() { + System.err.println("StartEvent " + obj.GetClassName() + " - " + label); + this.time = System.currentTimeMillis(); + } + + public void EndEvent() { + System.err.println("EndEvent " + obj.GetClassName() + " - " + label + " - ET: " + (System.currentTimeMillis() - time) / 1000D + " sec"); + } + + public void ProgressEvent() { + System.err.println("ProgressEvent " + obj.GetClassName() + " - " + label); + } + + public void ConfigureEvent() { + System.err.println("ConfigureEvent " + obj.GetClassName() + " - " + label); + } + + public void TimerEvent() { + System.err.println("TimerEvent " + obj.GetClassName() + " - " + label); + } + + public void ErrorEvent() { + System.err.println("ErrorEvent " + obj.GetClassName() + " - " + label); + } + + public void WarningEvent() { + System.err.println("WarningEvent " + obj.GetClassName() + " - " + label); + } + + public void MouseMoveEvent() { + System.err.println("MouseMoveEvent " + obj.GetClassName() + " - " + label); + } + } + + public static String logBlockNames(vtkMultiBlockDataSet dataset) { StringBuilder sb = new StringBuilder(); int numberOfBlocks = dataset.GetNumberOfBlocks(); for (int i = 0; i < numberOfBlocks; i++) { @@ -389,7 +629,260 @@ public class VTKUtil { sb.append(name); sb.append(" "); } - + return sb.toString(); } + + public static vtkPolyData intersect(vtkPolyData input1, vtkPolyData input2, boolean triangulateInput1, boolean triangulateInput2) { + vtkIntersectionPolyDataFilter intersect = new vtkIntersectionPolyDataFilter(); + + if (triangulateInput1) { + vtkTriangleFilter triangle = new vtkTriangleFilter(); + triangle.SetInputData(input1); + triangle.Update(); + + intersect.SetInputData(0, triangle.GetOutput()); + } else { + intersect.SetInputData(0, input1); + } + + if (triangulateInput2) { + vtkTriangleFilter triangle = new vtkTriangleFilter(); + triangle.SetInputData(input2); + triangle.Update(); + + intersect.SetInputData(1, triangle.GetOutput()); + } else { + intersect.SetInputData(1, input2); + } + + intersect.SplitFirstOutputOff(); + intersect.SplitSecondOutputOff(); + intersect.Update(); + + return intersect.GetOutput(); + } + + public static vtkPolyData getPlane(BoundingBox bb, double[] normal) { + vtkPlaneSource planeSource = new vtkPlaneSource(); + planeSource.SetOrigin(0, 0, 0); + planeSource.SetPoint1(bb.getDiagonal(), 0, 0); + planeSource.SetPoint2(0, bb.getDiagonal(), 0); + planeSource.SetCenter(bb.getCenter()); + planeSource.SetNormal(normal); + planeSource.Update(); + + return planeSource.GetOutput(); + } + + public static boolean areTouching(vtkPolyData dataSet1, vtkPolyData dataSet2) { + vtkIntersectionPolyDataFilter intersect = new vtkIntersectionPolyDataFilter(); + intersect.SetInputData(0, dataSet1); + intersect.SetInputData(1, dataSet2); + + intersect.SplitFirstOutputOff(); + intersect.SplitSecondOutputOff(); + intersect.Update(); + + vtkPolyData output = intersect.GetOutput(); + + return output.GetNumberOfPoints() != 0; + } + + public static vtkActor createTestActor(vtkPolyData input, double[] color, double[] lineColor) { + vtkMapper mapper = new vtkPolyDataMapper(); + mapper.SetInputDataObject(input); + mapper.ScalarVisibilityOff(); + + vtkActor actor = new vtkActor(); + actor.SetMapper(mapper); + actor.GetProperty().SetRepresentationToWireframe(); + actor.GetProperty().SetEdgeColor(lineColor); + actor.GetProperty().SetColor(color); + actor.GetProperty().EdgeVisibilityOn(); + actor.GetProperty().SetLineWidth(1); + + mapper.Update(); + + return actor; + } + + public static vtkRenderWindow showRenderPanel(vtkActor... actors) { + vtkRenderer ren = new vtkRenderer(); + ren.GradientBackgroundOn(); + ren.SetBackground(0.1D, 0.1D, 0.1D); + ren.SetBackground2(0.4D, 0.4D, 0.4D); + + vtkRenderWindow renWin = new vtkRenderWindow(); + renWin.AddRenderer(ren); + renWin.SetSize(1024, 768); + + for (vtkActor actor : actors) { + ren.AddActor(actor); + } + + vtkRenderWindowInteractor iren = new vtkRenderWindowInteractor(); + iren.SetInteractorStyle(new vtkInteractorStyleTrackballCamera()); + iren.SetRenderWindow(renWin); + + iren.Start(); + + return renWin; + } + + public static boolean isSingleRegion(vtkMultiBlockDataSet dataset) { + int numberOfBlocks = dataset.GetNumberOfBlocks(); + if (numberOfBlocks > 0) { + String blockName = dataset.GetMetaData(0).Get(new vtkCompositeDataSet().NAME()); + return blockName.equals(ExternalMeshReader.PATCHES) || blockName.equals(ExternalMeshReader.ZONES) || blockName.equals(InternalMeshReader.INTERNAL_MESH); + } + return false; + } + + public static vtkDataObject getBlock(String blockName, vtkMultiBlockDataSet dataset) { + int numberOfBlocks = dataset.GetNumberOfBlocks(); + for (int i = 0; i < numberOfBlocks; i++) { + String name = dataset.GetMetaData(i).Get(new vtkCompositeDataSet().NAME()); + if (blockName.equals(name)) { + return dataset.GetBlock(i); + } + } + return null; + } + + public static vtkUnstructuredGrid shallowCopy(vtkUnstructuredGrid data) { + vtkUnstructuredGrid copy = new vtkUnstructuredGrid(); + copy.ShallowCopy(data); + return copy; + } + + public static vtkPolyData shallowCopy(vtkPolyData data) { + vtkPolyData copy = new vtkPolyData(); + copy.ShallowCopy(data); + return copy; + } + + public static final String DEFAULT_REGION = "defaultRegion"; + + + public static vtkPolyData createSimplePointMarkDataset() { + double L = 0.2; + double Z = 3.9*L; + + vtkConeSource coneSource = new vtkConeSource(); + coneSource.SetHeight(2*L); + coneSource.SetRadius(L/2); + coneSource.CappingOn(); + coneSource.SetCenter(0, 0, L); + coneSource.SetDirection(0, 0, -1); + coneSource.SetResolution(30); + coneSource.Update(); + + vtkPolyData outputMesh = coneSource.GetOutput(); + + vtkPolyDataNormals normals = new vtkPolyDataNormals(); + normals.SetInputData(outputMesh); + normals.Update(); + + return normals.GetOutput(); + } + + public static vtkPolyData createPointMarkDataset() { + double L = 0.2; + double Z = 3.9*L; + + vtkLineSource lineSource = new vtkLineSource(); + lineSource.SetPoint1(-L/4,0,Z); + lineSource.SetPoint2(L/4,0,Z); + + vtkTubeFilter labelTubeFilter = new vtkTubeFilter(); + labelTubeFilter.SetInputConnection(lineSource.GetOutputPort()); + labelTubeFilter.CappingOn(); + labelTubeFilter.SetRadius(L); + labelTubeFilter.SetNumberOfSides(50); + labelTubeFilter.Update(); + + lineSource = new vtkLineSource(); + lineSource.SetPoint1(-L/2,0,Z); + lineSource.SetPoint2(L/2,0,Z); + + vtkTubeFilter internalTubeFilter = new vtkTubeFilter(); + internalTubeFilter.SetInputConnection(lineSource.GetOutputPort()); + internalTubeFilter.CappingOff(); + internalTubeFilter.SetRadius(L); + internalTubeFilter.SetNumberOfSides(50); + internalTubeFilter.Update(); + + vtkTubeFilter externalTubeFilter = new vtkTubeFilter(); + externalTubeFilter.SetInputConnection(lineSource.GetOutputPort()); + externalTubeFilter.CappingOff(); + externalTubeFilter.SetRadius(2*L); + externalTubeFilter.SetNumberOfSides(50); + externalTubeFilter.Update(); + + vtkConeSource coneSource = new vtkConeSource(); + coneSource.SetHeight(2*L); + coneSource.SetRadius(L/2); + coneSource.CappingOff(); + coneSource.SetCenter(0, 0, L); + coneSource.SetDirection(0, 0, -1); + coneSource.SetResolution(30); + coneSource.Update(); + + vtkAppendPolyData append = new vtkAppendPolyData(); + append.AddInputData(internalTubeFilter.GetOutput()); + append.AddInputData(externalTubeFilter.GetOutput()); + append.AddInputData(coneSource.GetOutput()); + append.AddInputData(labelTubeFilter.GetOutput()); + append.Update(); + + vtkPolyData outputMesh = new vtkPolyData(); + outputMesh.DeepCopy(append.GetOutput()); + vtkCellArray outputTriangles = outputMesh.GetPolys(); + + int length = internalTubeFilter.GetOutput().GetNumberOfPoints(); + for (int ptId = 0; ptId < 50; ptId++) { + // Triangle one extremity + vtkIdList triangle = new vtkIdList(); + triangle.InsertNextId(ptId); + triangle.InsertNextId(ptId + length); + triangle.InsertNextId((ptId + 1) % 50 + length); + outputTriangles.InsertNextCell(triangle); + + triangle = new vtkIdList(); + triangle.InsertNextId(ptId); + triangle.InsertNextId((ptId + 1) % 50 + length); + triangle.InsertNextId((ptId + 1) % 50); + outputTriangles.InsertNextCell(triangle); + + // Triangle the other extremity + int offset = length - 50; + triangle = new vtkIdList(); + triangle.InsertNextId(ptId + offset); + triangle.InsertNextId(ptId + +offset + length); + triangle.InsertNextId((ptId + 1) % 50 + offset + length); + outputTriangles.InsertNextCell(triangle); + + triangle = new vtkIdList(); + triangle.InsertNextId((ptId + 1) % 50 + length + offset); + triangle.InsertNextId((ptId + 1) % 50 + offset); + triangle.InsertNextId(ptId + offset); + outputTriangles.InsertNextCell(triangle); + } + + vtkPolyDataNormals normals = new vtkPolyDataNormals(); + normals.SetInputData(outputMesh); + normals.Update(); + + return normals.GetOutput(); + } + + public static void printTotalMemory(vtkDataSet... dataSets) { + int total = 0; + for (vtkDataSet dataSet : dataSets) { + total += dataSet.GetActualMemorySize(); + } + logger.debug("TOTAL 3D MEMORY: {}", FormatUtil.format(total/1024D).toCents() + " MB"); + } + } diff --git a/src/eu/engys/vtk/VTKView3D.java b/src/eu/engys/vtk/VTKView3D.java index 444ce12..2b24f3f 100644 --- a/src/eu/engys/vtk/VTKView3D.java +++ b/src/eu/engys/vtk/VTKView3D.java @@ -1,36 +1,38 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.vtk; +import static eu.engys.core.controller.AbstractController.SAVE_SCREENSHOT; +import static eu.engys.util.ui.FileChooserUtils.PNG_EXTENSION; + import java.awt.BorderLayout; import java.awt.Color; import java.awt.Dimension; import java.awt.event.ComponentAdapter; import java.awt.event.ComponentEvent; +import java.io.File; import java.util.ArrayList; import java.util.HashMap; import java.util.LinkedHashSet; @@ -49,6 +51,9 @@ import org.slf4j.LoggerFactory; import eu.engys.core.controller.GeometryToMesh; import eu.engys.core.dictionary.model.EventActionType; +import eu.engys.core.presentation.Action; +import eu.engys.core.presentation.ActionContainer; +import eu.engys.core.presentation.ActionManager; import eu.engys.core.project.Model; import eu.engys.core.project.geometry.BoundingBox; import eu.engys.gui.events.EventManager; @@ -61,8 +66,9 @@ import eu.engys.gui.view3D.Controller3D; import eu.engys.gui.view3D.Geometry3DController; import eu.engys.gui.view3D.LayerInfo; import eu.engys.gui.view3D.Mesh3DController; -import eu.engys.gui.view3D.QualityInfo; +import eu.engys.gui.view3D.RenderPanel; import eu.engys.gui.view3D.Selection; +import eu.engys.gui.view3D.quality.QualityInfo; import eu.engys.gui.view3D.widget.Widget; import eu.engys.util.plaf.ILookAndFeel; import eu.engys.util.progress.ProgressMonitor; @@ -75,14 +81,16 @@ import eu.engys.vtk.widgets.ExtractSelectionWidget; import eu.engys.vtk.widgets.LayersCoverageWidget; import eu.engys.vtk.widgets.LogoWidget; import eu.engys.vtk.widgets.MinMaxPointWidgetManager; -import eu.engys.vtk.widgets.PlaneDisplayWidget; -import eu.engys.vtk.widgets.PlaneWidget; +import eu.engys.vtk.widgets.PlaneWidgetManager; import eu.engys.vtk.widgets.PointWidgetManager; import eu.engys.vtk.widgets.QualityWidget; import eu.engys.vtk.widgets.panels.BoundingBoxBar; import eu.engys.vtk.widgets.shapes.BoxWidget; +import eu.engys.vtk.widgets.shapes.RotatedBoxWidget; +import vtk.vtkPNGWriter; +import vtk.vtkWindowToImageFilter; -public class VTKView3D extends JPanel implements CanvasPanel { +public class VTKView3D extends JPanel implements CanvasPanel, ActionContainer { private static Logger logger = LoggerFactory.getLogger(CanvasPanel.class); @@ -99,15 +107,14 @@ public class VTKView3D extends JPanel implements CanvasPanel { private final List controllers; private VTK3DActionsToolBar genericToolBar; - + private PointWidgetManager pointWidgetManager; private AxisWidgetManager axisWidgetManager; private MinMaxPointWidgetManager minMaxPointWidgetManager; private AxesWidget axesWidget; -// private CORWidget corWidget; private BoxWidget boxWidget; - private PlaneWidget planeWidget; - private PlaneDisplayWidget planeDisplayWidget; + private RotatedBoxWidget rotatedBoxWidget; + private PlaneWidgetManager planeWidgetManager; private ExtractSelectionWidget selectionWidget; private QualityWidget qualityWidget; private LayersCoverageWidget layersWidget; @@ -124,30 +131,27 @@ public class VTKView3D extends JPanel implements CanvasPanel { private ILookAndFeel laf; private ProgressMonitor monitor; + private View3DElement currentElement; + @Inject public VTKView3D(Model model, ILookAndFeel laf, Set viewElements, Set controllers, Set widgets, ProgressMonitor monitor) { - super(); - this.model = model; - this.laf = laf; + super(); + this.model = model; + this.laf = laf; this.viewElements = viewElements; this.view3DElements = new LinkedHashSet<>(); - this.widgets = widgets; - this.monitor = monitor; - this.renderPanel = new VTKRenderPanel(laf); - this.view3DController = new VTKView3DController(this); - this.controllers = new ArrayList<>(); - -// this.meshController = new VTKMesh3DController(model, monitor); -// this.geometryController = new VTKGeometry3DController(model, monitor); -// -// registerController(meshController); -// registerController(geometryController); + this.widgets = widgets; + this.monitor = monitor; + this.renderPanel = new VTKRenderPanel(laf); + this.view3DController = new VTKView3DController(this); + this.controllers = new ArrayList<>(); for (Controller3D c : controllers) { registerController(c); } EventManager.registerEventListener(new HelyxView3DEventListener(this), View3DEvent.class); + ActionManager.getInstance().parseActions(this); } @Override @@ -158,7 +162,7 @@ public class VTKView3D extends JPanel implements CanvasPanel { this.geometryController = (Geometry3DController) controller; } else if (this.meshController == null && controller instanceof Mesh3DController) { this.meshController = (Mesh3DController) controller; - } + } } @Override @@ -168,7 +172,7 @@ public class VTKView3D extends JPanel implements CanvasPanel { for (ViewElement element : viewElements) { layoutElements(element); } - + this.genericToolBar = new VTK3DActionsToolBar(model, laf); this.widgetToolBar = new WidgetToolBar(widgets); this.boundingBoxBar = new BoundingBoxBar(this, laf); @@ -176,9 +180,9 @@ public class VTKView3D extends JPanel implements CanvasPanel { this.southPanel = new JPanel(new BorderLayout()); this.southPanel.add(boundingBoxBar, BorderLayout.SOUTH); - add(genericToolBar, BorderLayout.EAST); + add(genericToolBar.getToolbar(), BorderLayout.EAST); if (widgetToolBar.hasWidgets()) { - add(widgetToolBar, BorderLayout.NORTH); + add(widgetToolBar.getToolbar(), BorderLayout.NORTH); } add(renderPanel, BorderLayout.CENTER); @@ -210,8 +214,9 @@ public class VTKView3D extends JPanel implements CanvasPanel { // double timeInSeconds = vtkRendererPanel.GetRenderer().GetLastRenderTimeInSeconds(); // double fps = 1.0 / timeInSeconds; // System.out.println("FPS " + fps); - BoundingBox bb = boundingBoxBar.update(); -// corWidget.update(bb); + // BoundingBox bb = + boundingBoxBar.update(); + // corWidget.update(bb); } }); } @@ -223,31 +228,28 @@ public class VTKView3D extends JPanel implements CanvasPanel { this.widgetPanel = new WidgetPanel(widgets); this.axesWidget = new AxesWidget(renderPanel); this.logoWidget = new LogoWidget(renderPanel); -// this.corWidget = new CORWidget(renderPanel); - this.planeWidget = new PlaneWidget(renderPanel); - this.planeDisplayWidget = new PlaneDisplayWidget(renderPanel); + this.planeWidgetManager = new PlaneWidgetManager(renderPanel); this.selectionWidget = new ExtractSelectionWidget(renderPanel, monitor); this.qualityWidget = new QualityWidget(model, renderPanel, monitor); this.layersWidget = new LayersCoverageWidget(model, renderPanel, monitor); this.boxWidget = new BoxWidget(renderPanel); + this.rotatedBoxWidget = new RotatedBoxWidget(renderPanel); this.pointWidgetManager = new PointWidgetManager(renderPanel); this.axisWidgetManager = new AxisWidgetManager(renderPanel); this.minMaxPointWidgetManager = new MinMaxPointWidgetManager(renderPanel); } -// @Override -// public void start() { -// widgetPanel.clear(); -// vtkRendererPanel.resetZoomLater(); -// } - @Override - public void load() { + public void load(boolean loadMesh) { for (Controller3D context : controllers) { logger.info("[LOAD 3D] {}", context.getClass().getSimpleName()); + + if (context instanceof Mesh3DController && !loadMesh) { + continue; + } context.loadActors(); } - + for (View3DElement element : view3DElements) { logger.info("[LOAD 3D] {}", element.getClass().getSimpleName()); _load3D(element); @@ -255,8 +257,9 @@ public class VTKView3D extends JPanel implements CanvasPanel { logger.info("[LOAD] 3D Widgets"); loadWidgets(); + VTKUtil.gc(true); } - + private void _load3D(final View3DElement view3DElement) { ExecUtil.invokeAndWait(new Runnable() { @Override @@ -268,37 +271,47 @@ public class VTKView3D extends JPanel implements CanvasPanel { @Override public void save() { -// if (view3DElement == currentElement) { -// view3DElement.save(this); -// } + // if (view3DElement == currentElement) { + // view3DElement.save(this); + // } } - + @Override public void stop(Class klass) { stopWidgets(); - if (elementsByClass.containsKey(klass)) { - final View3DElement view3DElement = elementsByClass.get(klass); - ExecUtil.invokeAndWait(new Runnable() { - @Override - public void run() { - view3DElement.stop(VTKView3D.this); - view3DElement.save(VTKView3D.this); - } - }); + if (klass == null) { + if (currentElement != null) { + _stop(currentElement); + } else { + _stop(viewElements.iterator().next().getView3D()); + } + } else if (elementsByClass.containsKey(klass)) { + _stop(elementsByClass.get(klass)); } } + private void _stop(final View3DElement view3DElement) { + ExecUtil.invokeAndWait(new Runnable() { + @Override + public void run() { + view3DElement.stop(VTKView3D.this); + view3DElement.save(VTKView3D.this); + } + }); + } + @Override public void start(Class klass) { - if (klass == null) { + if (klass == null) { _start(view3DElements.iterator().next()); resetZoom(); } else if (elementsByClass.containsKey(klass)) { - _start(elementsByClass.get(klass)); + _start(elementsByClass.get(klass)); } } private void _start(final View3DElement view3DElement) { + this.currentElement = view3DElement; ExecUtil.invokeAndWait(new Runnable() { @Override public void run() { @@ -333,8 +346,9 @@ public class VTKView3D extends JPanel implements CanvasPanel { } return null; } - - public VTKRenderPanel getVTKRendererPanel() { + + @Override + public RenderPanel getRenderPanel() { return renderPanel; } @@ -346,11 +360,11 @@ public class VTKView3D extends JPanel implements CanvasPanel { @Override public void geometryToMesh(GeometryToMesh g2m) { renderPanel.clearSelection(); - + for (Controller3D controller : controllers) { controller.geometryToMesh(g2m); } - + for (View3DElement element : view3DElements) { _load3D(element); } @@ -374,8 +388,9 @@ public class VTKView3D extends JPanel implements CanvasPanel { widgetPanel.clear(); widgetToolBar.clear(); - planeWidget.clear(); - planeDisplayWidget.clear(); + boxWidget.clear(); + rotatedBoxWidget.clear(); + planeWidgetManager.clear(); selectionWidget.clear(); qualityWidget.clear(); layersWidget.clear(); @@ -389,7 +404,6 @@ public class VTKView3D extends JPanel implements CanvasPanel { widget.clear(); } axesWidget.clear(); -// corWidget.clear(); for (Controller3D context : controllers) { context.clearContext(); @@ -416,29 +430,34 @@ public class VTKView3D extends JPanel implements CanvasPanel { } @Override - public void showPoint(DoubleField[] point, String key, EventActionType action, Color color) { - pointWidgetManager.showPoint(point, key, action, color); + public void showPoint(String key, DoubleField[] point, EventActionType action, Color color) { + pointWidgetManager.showPoint(key, point, action, color); } @Override - public void showAxis(DoubleField[] origin, DoubleField[] normal, EventActionType action) { - axisWidgetManager.showPoint(origin, normal, action); + public void showAxis(DoubleField[] origin, DoubleField[] normal, double magnitude, EventActionType action) { + axisWidgetManager.showPoint(origin, normal, magnitude, action); } @Override - public void showPlane(DoubleField[] origin, DoubleField[] normal, EventActionType action) { + public void showAxis(DoubleField[] origin, DoubleField angle1, DoubleField angle2, double magnitude, int sign, EventActionType action) { + axisWidgetManager.showPoint(origin, angle1, angle2, magnitude, sign, action); + } + + @Override + public void showPlane(String key, DoubleField[] origin, DoubleField[] normal, EventActionType action) { BoundingBox bb = computeBoundingBox(true); double diagonal = bb.getDiagonal() / 2; double value = Double.isInfinite(diagonal) ? 1 : diagonal > 0 ? diagonal : 1; - planeWidget.showPlane(origin, normal, action, value); + planeWidgetManager.showPlane(key, origin, normal, action, value); } @Override - public void showPlaneDisplay(DoubleField[] origin, DoubleField[] normal, EventActionType action) { + public void showPlaneDisplay(String key, DoubleField[] origin, DoubleField[] normal, EventActionType action) { BoundingBox bb = computeBoundingBox(true); double diagonal = bb.getDiagonal() / 2; double value = Double.isInfinite(diagonal) ? 1 : diagonal > 0 ? diagonal : 1; - planeDisplayWidget.showPlane(origin, normal, action, value); + planeWidgetManager.showPlaneDisplay(key, origin, normal, action, value); } @Override @@ -446,9 +465,24 @@ public class VTKView3D extends JPanel implements CanvasPanel { selectionWidget.activateSelection(selection, action); } + // @Override + // public void activateLocation(EventActionType action) { + // locationWidget.activateSelection(action); + // } + + // @Override + // public void activateCOR(EventActionType action) { + // corWidget.activateSelection(action); + // } + @Override public void showBox(DoubleField[] min, DoubleField[] max, EventActionType action) { - boxWidget.showBox(null, min, max, action); + boxWidget.showBox(min, max, action); + } + + @Override + public void showRotatedBox(DoubleField[] center, DoubleField[] delta, DoubleField[] rotation, EventActionType action) { + rotatedBoxWidget.showBox(center, delta, rotation, action); } @Override @@ -470,7 +504,7 @@ public class VTKView3D extends JPanel implements CanvasPanel { public void showLayersCoverage(LayerInfo layerInfo, JPanel colorBar, EventActionType action) { layersWidget.activateLayersCoverage(layerInfo, colorBar, action); } - + @Override public boolean showWidget(Widget widget) { if (widget.canShow()) { @@ -478,6 +512,9 @@ public class VTKView3D extends JPanel implements CanvasPanel { if (widget.getWidgetComponent() != null) { showWidgetPanel(widget); } + for (Widget w : widgets) { + w.handleWidgetShow(widget.getClass()); + } return true; } else { return false; @@ -500,6 +537,9 @@ public class VTKView3D extends JPanel implements CanvasPanel { if (widget.getWidgetComponent() != null) { hideWidgetPanel(widget); } + for (Widget w : widgets) { + w.handleWidgetHide(widget.getClass()); + } } @Override @@ -511,20 +551,32 @@ public class VTKView3D extends JPanel implements CanvasPanel { } southPanel.revalidate(); } - -// @Override -// public void handleInitializeFieldsStarted(){ -// for (Widget widget : widgets) { -// widget.handleInitializeFieldsStarted(); -// } -// } -// -// @Override -// public void handleInitializeFieldsFinished(){ -// for (Widget widget : widgets) { -// widget.handleInitializeFieldsFinished(); -// } -// } + + // @Override + // public void handleInitializeFieldsStarted(){ + // for (Widget widget : widgets) { + // widget.handleInitializeFieldsStarted(); + // } + // } + // + // @Override + // public void handleInitializeFieldsFinished(){ + // for (Widget widget : widgets) { + // widget.handleInitializeFieldsFinished(); + // } + // } + + public void showInternalMesh() { + geometryController.showInternalMesh(); + meshController.showInternalMesh(); + notifyWidgets_InternalMeshShow(); + } + + public void hideInternalMesh() { + geometryController.hideInternalMesh(); + meshController.hideInternalMesh(); + notifyWidgets_InternalMeshHide(); + } public void stopWidgets() { for (Widget widget : widgets) { @@ -533,27 +585,38 @@ public class VTKView3D extends JPanel implements CanvasPanel { } public void loadWidgets() { -// corWidget.on(); for (Widget widget : widgets) { widget.load(); } } - public void updateWidgets_fieldChanged() { + public void notifyWidgets_FieldChanged() { for (Widget widget : widgets) { widget.handleFieldChanged(); } } - public void updateWidgets_timeStepChanged() { + public void notifyWidgets_TimeStepChanged() { for (Widget widget : widgets) { widget.handleTimeStepChanged(); } } - - public void updateWidgets_newTimeStep() { + + private void notifyWidgets_InternalMeshShow() { for (Widget widget : widgets) { - widget.handleNewTimeStepsRead(); + widget.handleInternalMeshShow(); + } + } + + private void notifyWidgets_InternalMeshHide() { + for (Widget widget : widgets) { + widget.handleInternalMeshHide(); + } + } + + public void notifyWidgets_ZoomReset() { + for (Widget widget : widgets) { + widget.handleZoomReset(); } } @@ -581,4 +644,28 @@ public class VTKView3D extends JPanel implements CanvasPanel { } } + @Action(key = SAVE_SCREENSHOT) + public void saveScreenshot() { + vtkWindowToImageFilter filter = new vtkWindowToImageFilter(); + renderPanel.lock(); + filter.SetInput(((VTKRenderPanel) renderPanel).GetRenderer().GetVTKWindow()); + filter.Update(); + renderPanel.unlock(); + vtkPNGWriter writer = new vtkPNGWriter(); + + File file = new File(model.getProject().getBaseDir(), model.getProject().getBaseDir().getName() + "." + PNG_EXTENSION); + if (file != null) { + writer.SetFileName(file.getAbsolutePath()); + writer.SetInputConnection(filter.GetOutputPort()); + writer.Write(); + writer.Delete(); + filter.Delete(); + } + } + + @Override + public boolean isDemo() { + return false; + } + } diff --git a/src/eu/engys/vtk/VTKView3DController.java b/src/eu/engys/vtk/VTKView3DController.java index b26831b..39d995d 100644 --- a/src/eu/engys/vtk/VTKView3DController.java +++ b/src/eu/engys/vtk/VTKView3DController.java @@ -1,29 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.vtk; import static eu.engys.vtk.VTK3DActionsToolBar._3D_AXIS_XNEG; @@ -43,139 +41,143 @@ import static eu.engys.vtk.VTK3DActionsToolBar._3D_ZOOM_IN; import static eu.engys.vtk.VTK3DActionsToolBar._3D_ZOOM_OUT; import static eu.engys.vtk.VTK3DActionsToolBar._3D_ZOOM_RESET; import static eu.engys.vtk.VTK3DActionsToolBar._3D_ZOOM_TOBOX; + import eu.engys.core.presentation.Action; import eu.engys.core.presentation.ActionContainer; import eu.engys.core.presentation.ActionManager; import eu.engys.core.presentation.ActionToggle; -import eu.engys.core.project.mesh.FieldItem; import eu.engys.gui.view3D.CameraManager.Position; +import eu.engys.gui.view3D.RenderPanel; import eu.engys.gui.view3D.Representation; public class VTKView3DController implements ActionContainer { - private VTKRenderPanel vtkRendererPanel; - private VTKView3D view3D; + private RenderPanel renderPanel; + private VTKView3D view3D; - public VTKView3DController(VTKView3D vtkView3D) { - this.view3D = vtkView3D; - this.vtkRendererPanel = vtkView3D.getVTKRendererPanel(); - ActionManager.getInstance().parseActions(this); - } + public VTKView3DController(VTKView3D vtkView3D) { + this.view3D = vtkView3D; + this.renderPanel = vtkView3D.getRenderPanel(); + ActionManager.getInstance().parseActions(this); + } - @Override - public boolean isDemo() { - return false; - } - - @Action(key=_3D_LOAD_MESH) - public void loadMesh() { - view3D.getMeshController().showExternalMesh(); - view3D.load(); - view3D.start(null); - } + @Override + public boolean isDemo() { + return false; + } - @Action(key=_3D_AXIS_XPOS) - public void viewXPos() { - vtkRendererPanel.setCameraPosition(Position.X_POS); - } + @Action(key = _3D_LOAD_MESH) + public void loadMesh() { + view3D.getMeshController().showExternalMesh(); + // view3D.load(); + view3D.start(null); + } - @Action(key=_3D_AXIS_XNEG) - public void viewXNeg() { - vtkRendererPanel.setCameraPosition(Position.X_NEG); - } + @Action(key = _3D_AXIS_XPOS) + public void viewXPos() { + renderPanel.setCameraPosition(Position.X_POS); + } - @Action(key=_3D_AXIS_YPOS) - public void viewYPos() { - vtkRendererPanel.setCameraPosition(Position.Y_POS); - } + @Action(key = _3D_AXIS_XNEG) + public void viewXNeg() { + renderPanel.setCameraPosition(Position.X_NEG); + } - @Action(key=_3D_AXIS_YNEG) - public void viewYNeg() { - vtkRendererPanel.setCameraPosition(Position.Y_NEG); - } + @Action(key = _3D_AXIS_YPOS) + public void viewYPos() { + renderPanel.setCameraPosition(Position.Y_POS); + } - @Action(key=_3D_AXIS_ZPOS) - public void viewZPos() { - vtkRendererPanel.setCameraPosition(Position.Z_POS); - } + @Action(key = _3D_AXIS_YNEG) + public void viewYNeg() { + renderPanel.setCameraPosition(Position.Y_NEG); + } - @Action(key=_3D_AXIS_ZNEG) - public void viewZNeg() { - vtkRendererPanel.setCameraPosition(Position.Z_NEG); - } + @Action(key = _3D_AXIS_ZPOS) + public void viewZPos() { + renderPanel.setCameraPosition(Position.Z_POS); + } - @Action(key=_3D_ZOOM_IN) - public void zoomIn() { - vtkRendererPanel.wheelForward(); - } + @Action(key = _3D_AXIS_ZNEG) + public void viewZNeg() { + renderPanel.setCameraPosition(Position.Z_NEG); + } - @Action(key=_3D_ZOOM_OUT) - public void zoomOut() { - vtkRendererPanel.wheelBackward(); - } + @Action(key = _3D_ZOOM_IN) + public void zoomIn() { + renderPanel.wheelForward(); + } - @Action(key=_3D_ZOOM_TOBOX) - public void zoomToBox() { - vtkRendererPanel.getInteractor().setStyleToZoom(); - } + @Action(key = _3D_ZOOM_OUT) + public void zoomOut() { + renderPanel.wheelBackward(); + } - @Action(key=_3D_ZOOM_RESET) - public void zoomReset() { - vtkRendererPanel.zoomReset(); - } + @Action(key = _3D_ZOOM_TOBOX) + public void zoomToBox() { + renderPanel.getInteractor().setStyleToZoom(); + } - @Action(key=_3D_VIEW_EDGES) - public void setRepresentationToSurfaceWithEdges() { - vtkRendererPanel.clearSelection(); - vtkRendererPanel.changeRepresentation(Representation.SURFACE_WITH_EDGES); - } + @Action(key = _3D_ZOOM_RESET) + public void zoomReset() { + renderPanel.zoomReset(); + view3D.notifyWidgets_ZoomReset(); + } - @Action(key=_3D_VIEW_PROFILE) - public void setRepresentationToProfile() { - vtkRendererPanel.clearSelection(); - vtkRendererPanel.changeRepresentation(Representation.PROFILE); - } + @Action(key = _3D_VIEW_EDGES) + public void setRepresentationToSurfaceWithEdges() { + renderPanel.clearSelection(); + renderPanel.changeRepresentation(Representation.SURFACE_WITH_EDGES); + } - @Action(key=_3D_VIEW_SURFACE) - public void setRepresentationToSurface() { - vtkRendererPanel.clearSelection(); - vtkRendererPanel.changeRepresentation(Representation.SURFACE); - } + @Action(key = _3D_VIEW_PROFILE) + public void setRepresentationToProfile() { + renderPanel.clearSelection(); + renderPanel.changeRepresentation(Representation.PROFILE); + } - @Action(key=_3D_VIEW_WIREFRAME) - public void setRepresentationToWireframe() { - vtkRendererPanel.clearSelection(); - vtkRendererPanel.changeRepresentation(Representation.WIREFRAME); - } + @Action(key = _3D_VIEW_SURFACE) + public void setRepresentationToSurface() { + renderPanel.clearSelection(); + renderPanel.changeRepresentation(Representation.SURFACE); + } - @Action(key=_3D_VIEW_OUTLINE) - public void setRepresentationToOutline() { - vtkRendererPanel.clearSelection(); - vtkRendererPanel.changeRepresentation(Representation.OUTLINE); - } + @Action(key = _3D_VIEW_WIREFRAME) + public void setRepresentationToWireframe() { + renderPanel.clearSelection(); + renderPanel.changeRepresentation(Representation.WIREFRAME); + } - @ActionToggle(key=_3D_VIEW_PROJECTIONS, normal="perspective", selected="parallel") - public void setProjection(boolean parallel) { - if (parallel) { - vtkRendererPanel.ParallelProjectionOn(); - } else { - vtkRendererPanel.ParallelProjectionOff(); - } - } + @Action(key = _3D_VIEW_OUTLINE) + public void setRepresentationToOutline() { + renderPanel.clearSelection(); + renderPanel.changeRepresentation(Representation.OUTLINE); + } - public void showScalarsForField(FieldItem fieldItem) { - view3D.getMeshController().showField(fieldItem); - view3D.getGeometryController().showField(fieldItem); - view3D.updateWidgets_fieldChanged(); - } + @ActionToggle(key = _3D_VIEW_PROJECTIONS, normal = "perspective", selected = "parallel") + public void setProjection(boolean parallel) { + if (parallel) { + renderPanel.ParallelProjectionOn(); + } else { + renderPanel.ParallelProjectionOff(); + } + } - public void showTimeStep(double time) { - view3D.getMeshController().showTimeStep(time); - view3D.updateWidgets_timeStepChanged(); - } - - public void readTimeSteps() { - view3D.getMeshController().readTimeSteps(); - view3D.updateWidgets_newTimeStep(); - } +// @ActionToggle(key = _3D_LOCATION, normal = "off", selected = "on") +// public void showLocation(boolean on) { +// if (on) { +// view3D.activateLocation(EventActionType.SHOW); +// } else { +// view3D.activateLocation(EventActionType.HIDE); +// } +// } +// +// @ActionToggle(key = _3D_COR, normal = "off", selected = "on") +// public void showCOR(boolean on) { +// if (on) { +// view3D.activateCOR(EventActionType.SHOW); +// } else { +// view3D.activateCOR(EventActionType.HIDE); +// } +// } } diff --git a/src/eu/engys/vtk/VTKView3DProvider.java b/src/eu/engys/vtk/VTKView3DProvider.java index 0baca03..417fed4 100644 --- a/src/eu/engys/vtk/VTKView3DProvider.java +++ b/src/eu/engys/vtk/VTKView3DProvider.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.vtk; diff --git a/src/eu/engys/vtk/WidgetPanel.java b/src/eu/engys/vtk/WidgetPanel.java index 3afe9c8..0dbef1f 100644 --- a/src/eu/engys/vtk/WidgetPanel.java +++ b/src/eu/engys/vtk/WidgetPanel.java @@ -1,29 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.vtk; import java.awt.BorderLayout; @@ -32,7 +30,9 @@ import java.util.Map; import java.util.Set; import javax.inject.Inject; +import javax.swing.BorderFactory; import javax.swing.JPanel; +import javax.swing.JScrollPane; import javax.swing.JTabbedPane; import eu.engys.gui.view3D.widget.Widget; @@ -58,32 +58,37 @@ public class WidgetPanel extends JPanel { for (Widget widget : components) { WidgetComponent widgetComponent = widget.getWidgetComponent(); if (widgetComponent != null) { - componentsMap.put(widgetComponent.getKey(), widgetComponent); + componentsMap.put(widgetComponent.getKey(), widgetComponent); } } - add(tabbedPane, BorderLayout.CENTER); + + JScrollPane pane = new JScrollPane(tabbedPane, JScrollPane.VERTICAL_SCROLLBAR_NEVER, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); + pane.setBorder(BorderFactory.createEmptyBorder()); + add(pane, BorderLayout.CENTER); } public void showPanel(String key) { WidgetComponent c = componentsMap.get(key); c.handleShow(); - if(getTabIndex(key) == -1){ - tabbedPane.addTab(key, c.getPanel()); + if (getTabIndex(key) == -1) { + tabbedPane.addTab(key, c.getPanel()); } tabbedPane.setSelectedComponent(c.getPanel()); } - - private int getTabIndex(String tab){ - for (int i = 0; i < tabbedPane.getTabCount(); i++) { - if(tabbedPane.getTitleAt(i).equals(tab)){ - return i; - } - } - return -1; + + private int getTabIndex(String tab) { + for (int i = 0; i < tabbedPane.getTabCount(); i++) { + if (tabbedPane.getTitleAt(i).equals(tab)) { + return i; + } + } + return -1; } public void hidePanel(String key) { - tabbedPane.removeTabAt(getTabIndex(key)); + WidgetComponent c = componentsMap.get(key); + c.handleHide(); + tabbedPane.removeTabAt(getTabIndex(key)); } public boolean isEmpty() { @@ -93,7 +98,7 @@ public class WidgetPanel extends JPanel { public void setHidden(boolean hidden) { this.hidden = hidden; } - + public boolean isHidden() { return hidden; } diff --git a/src/eu/engys/vtk/WidgetToolBar.java b/src/eu/engys/vtk/WidgetToolBar.java index f0883ca..2394034 100644 --- a/src/eu/engys/vtk/WidgetToolBar.java +++ b/src/eu/engys/vtk/WidgetToolBar.java @@ -1,63 +1,61 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.vtk; import static eu.engys.vtk.VTK3DActionsToolBar._3D_LOAD_MESH; -import java.awt.FlowLayout; import java.util.Set; -import javax.swing.Box; import javax.swing.JToolBar; import eu.engys.core.presentation.ActionManager; import eu.engys.gui.view3D.widget.Widget; -import eu.engys.util.ui.WrappedFlowLayout; +import eu.engys.util.ui.UiUtil; -public class WidgetToolBar extends JToolBar { +public class WidgetToolBar { + + public static final String WIDGET_TOOLBAR_NAME = "widget.toolbar"; private Set widgets; + private JToolBar toolbar; + public WidgetToolBar(Set widgets) { - super(JToolBar.HORIZONTAL); - setLayout(new WrappedFlowLayout(FlowLayout.LEFT, 0, 0)); + this.toolbar = UiUtil.getToolbarWrapped(WIDGET_TOOLBAR_NAME); this.widgets = widgets; - putClientProperty("Synthetica.toolBar.buttons.paintBorder", Boolean.TRUE); - putClientProperty("Synthetica.opaque", Boolean.FALSE); - setFloatable(false); - setRollover(true); layoutComponents(); } private void layoutComponents() { - add(ActionManager.getInstance().get(_3D_LOAD_MESH)); + toolbar.add(ActionManager.getInstance().get(_3D_LOAD_MESH)); for (Widget widget : widgets) { - widget.populate(this); + widget.populate(toolbar); } - add(Box.createHorizontalGlue()); +// toolbar.add(Box.createHorizontalGlue()); +// add(createToolBarToggleButton(ActionManager.getInstance().get(VTK3DActionsToolBar._3D_LOCATION))); +// add(createToolBarToggleButton(ActionManager.getInstance().get(VTK3DActionsToolBar._3D_COR))); } public void clear() { @@ -66,5 +64,9 @@ public class WidgetToolBar extends JToolBar { public boolean hasWidgets() { return widgets.size() > 0; } + + public JToolBar getToolbar() { + return toolbar; + } } diff --git a/src/eu/engys/vtk/actions/ExtractLines.java b/src/eu/engys/vtk/actions/ExtractLines.java index 3373773..dece0b7 100644 --- a/src/eu/engys/vtk/actions/ExtractLines.java +++ b/src/eu/engys/vtk/actions/ExtractLines.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.vtk.actions; import org.slf4j.Logger; diff --git a/src/eu/engys/vtk/actions/ExtractSelection.java b/src/eu/engys/vtk/actions/ExtractSelection.java index 286a453..b9dda22 100644 --- a/src/eu/engys/vtk/actions/ExtractSelection.java +++ b/src/eu/engys/vtk/actions/ExtractSelection.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.vtk.actions; import java.util.HashSet; @@ -33,6 +32,9 @@ import javax.vecmath.Vector3d; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import eu.engys.gui.view3D.PickInfo; +import eu.engys.gui.view3D.Selection; +import eu.engys.gui.view3D.Selection.SelectionMode; import vtk.vtkCellData; import vtk.vtkDataArray; import vtk.vtkDataSet; @@ -47,9 +49,6 @@ import vtk.vtkPolyData; import vtk.vtkPolyDataNormals; import vtk.vtkSelection; import vtk.vtkSelectionNode; -import eu.engys.gui.view3D.PickInfo; -import eu.engys.gui.view3D.Selection; -import eu.engys.gui.view3D.Selection.SelectionMode; public class ExtractSelection { @@ -143,7 +142,6 @@ public class ExtractSelection { private void pickByArea(PickInfo pi) { if (pi.frustum != null && pi.dataSet != null) { - vtkDataSet input = selection.getDataSet();//pi.dataSet; vtkIdFilter idFilter = new vtkIdFilter(); idFilter.CellIdsOn(); @@ -188,12 +186,15 @@ public class ExtractSelection { private void pickByFeature(PickInfo pi) { double[] normal = pi.normal; - vtkDataSet input = pi.dataSet; - int cellId = pi.cellId; - + + vtkDataSet input = selection.getDataSet();//pi.dataSet; if (input == null) return; + int cellId = pi.cellId; + if (cellId < 0) + return; + vtkPolyData output = getNormalsDataSet(normal, input); Set cells = new HashSet<>(); @@ -206,7 +207,41 @@ public class ExtractSelection { performSelection(id); } } + output.Delete(); + } + private vtkPolyData getNormalsDataSet(double[] normal, vtkDataSet dataSet) { + vtkPolyDataNormals normalsFilter = new vtkPolyDataNormals(); + normalsFilter.SetInputData(dataSet); + normalsFilter.SplittingOff(); + normalsFilter.SetFeatureAngle(60); + normalsFilter.ComputeCellNormalsOn(); + normalsFilter.FlipNormalsOff(); + normalsFilter.AutoOrientNormalsOff(); + normalsFilter.ConsistencyOff(); + normalsFilter.Update(); + + vtkPolyData output = normalsFilter.GetOutput(); + vtkCellData outputData = output.GetCellData(); + vtkDataArray normals = outputData.GetVectors("Normals"); + + vtkFloatArray angles = new vtkFloatArray(); + angles.SetName("Angles"); + + if (normals != null) { + for (int i = 0; i < normals.GetNumberOfTuples(); i++) { + double[] t = normals.GetTuple3(i); + double a = computeAngle(t, normal); + angles.InsertNextValue(a); + } + } + outputData.AddArray(angles); + + normalsFilter.Delete(); + angles.Delete(); + normals.Delete(); + + return output; } private void analyseNeighbours(int cellId, vtkPolyData output, Set cells) { @@ -239,7 +274,7 @@ public class ExtractSelection { for (int j = 0; j < neighborCellIds.GetNumberOfIds(); j++) { int id = neighborCellIds.GetId(j); - double angle = angles.GetComponent(id, 0); + double angle = angles.GetComponent(id, 0)%180; if (angle < selection.getFeatureAngle()) { neighbors.add(id); } @@ -261,33 +296,6 @@ public class ExtractSelection { } } - private vtkPolyData getNormalsDataSet(double[] normal, vtkDataSet dataSet) { - vtkPolyDataNormals normalsFilter = new vtkPolyDataNormals(); - normalsFilter.SetInputData(dataSet); - normalsFilter.SplittingOff(); - normalsFilter.SetFeatureAngle(60); - normalsFilter.ComputeCellNormalsOn(); - // normalsFilter.AutoOrientNormalsOn(); - normalsFilter.Update(); - - vtkPolyData output = normalsFilter.GetOutput(); - vtkCellData outputData = output.GetCellData(); - vtkDataArray normals = outputData.GetVectors("Normals"); - - vtkFloatArray angles = new vtkFloatArray(); - angles.SetName("Angles"); - - if (normals != null) { - for (int i = 0; i < normals.GetNumberOfTuples(); i++) { - double[] t = normals.GetTuple3(i); - double a = computeAngle(t, normal); - angles.InsertNextValue(a); - } - } - outputData.AddArray(angles); - return output; - } - private double computeAngle(double[] t, double[] normal) { Vector3d v = new Vector3d(t); Vector3d n = new Vector3d(normal); diff --git a/src/eu/engys/vtk/actions/IntersectSurfaces.java b/src/eu/engys/vtk/actions/IntersectSurfaces.java index 1ff4c9c..701e1f3 100644 --- a/src/eu/engys/vtk/actions/IntersectSurfaces.java +++ b/src/eu/engys/vtk/actions/IntersectSurfaces.java @@ -1,36 +1,34 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.vtk.actions; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import vtk.vtkIntersectionPolyDataFilter; +import eu.engys.vtk.VTKUtil; import vtk.vtkPolyData; -import vtk.vtkTriangleFilter; public class IntersectSurfaces { @@ -65,34 +63,10 @@ public class IntersectSurfaces { public vtkPolyData execute() { if (input1 != null && input2 != null) { - vtkIntersectionPolyDataFilter intersect = new vtkIntersectionPolyDataFilter(); + vtkPolyData output = VTKUtil.intersect(input1, input2, triangulateInput1, triangulateInput2); - if (triangulateInput1) { - vtkTriangleFilter triangle = new vtkTriangleFilter(); - triangle.SetInputData(input1); - triangle.Update(); - - intersect.SetInputData(0, triangle.GetOutput()); - } else { - intersect.SetInputData(0, input1); - } - - if (triangulateInput2) { - vtkTriangleFilter triangle = new vtkTriangleFilter(); - triangle.SetInputData(input2); - triangle.Update(); - - intersect.SetInputData(1, triangle.GetOutput()); - } else { - intersect.SetInputData(1, input2); - } - - intersect.SplitFirstOutputOff(); - intersect.SplitSecondOutputOff(); - intersect.Update(); - - log("LINE", intersect.GetOutput()); - return intersect.GetOutput(); + log("LINE", output); + return output; } else { return null; } diff --git a/src/eu/engys/vtk/actors/BoxActor.java b/src/eu/engys/vtk/actors/BoxActor.java index 1a9eba8..9145836 100644 --- a/src/eu/engys/vtk/actors/BoxActor.java +++ b/src/eu/engys/vtk/actors/BoxActor.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.vtk.actors; import eu.engys.core.project.geometry.surface.Box; diff --git a/src/eu/engys/vtk/actors/CylinderActor.java b/src/eu/engys/vtk/actors/CylinderActor.java index 318f178..eb8764e 100644 --- a/src/eu/engys/vtk/actors/CylinderActor.java +++ b/src/eu/engys/vtk/actors/CylinderActor.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.vtk.actors; import eu.engys.core.project.geometry.surface.Cylinder; diff --git a/src/eu/engys/vtk/actors/DefaultActor.java b/src/eu/engys/vtk/actors/DefaultActor.java index ebbe0ef..66614f1 100644 --- a/src/eu/engys/vtk/actors/DefaultActor.java +++ b/src/eu/engys/vtk/actors/DefaultActor.java @@ -1,44 +1,29 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.vtk.actors; -import vtk.vtkActor; -import vtk.vtkDataSet; -import vtk.vtkDataSetSurfaceFilter; -import vtk.vtkFeatureEdges; -import vtk.vtkLookupTable; -import vtk.vtkMapper; -import vtk.vtkOutlineFilter; -import vtk.vtkPolyData; -import vtk.vtkPolyDataAlgorithm; -import vtk.vtkPolyDataMapper; -import vtk.vtkProperty; -import vtk.vtkQuadricClustering; -import vtk.vtkTransform; -import vtk.vtkUnstructuredGrid; import eu.engys.core.project.geometry.stl.AffineTransform; import eu.engys.core.project.mesh.FieldItem; import eu.engys.gui.view3D.Actor; @@ -46,43 +31,57 @@ import eu.engys.gui.view3D.Representation; import eu.engys.util.PrefUtil; import eu.engys.vtk.VTKColors; import eu.engys.vtk.VTKUtil; +import vtk.vtkActor; +import vtk.vtkDataSetSurfaceFilter; +import vtk.vtkFeatureEdges; +import vtk.vtkLookupTable; +import vtk.vtkMapper; +import vtk.vtkOutlineFilter; +import vtk.vtkPolyData; +import vtk.vtkPolyDataMapper; +import vtk.vtkProperty; +import vtk.vtkQuadricClustering; +import vtk.vtkTransform; +import vtk.vtkUnstructuredGrid; public abstract class DefaultActor extends vtkActor implements Actor { - private enum SelectionState {BASE, SELECTED, DESELECTED}; - + private enum SelectionState { + BASE, SELECTED, DESELECTED + }; + private static final double BASE_OPACITY = 1.0; private static final double DESELECTION_OPACITY = 0.2; - private static final double SELECTION_OPACITY = 0.6; + private static final double SELECTION_OPACITY = 0.8; + + private String name; private vtkPolyDataMapper mapper; private vtkPolyDataMapper LODMapper; - private String name; - private vtkQuadricClustering LODFilter; - private vtkTransform transform; private vtkPolyDataMapper outlineMapper; - private vtkPolyDataAlgorithm outlineFilter; - private vtkFeatureEdges edges; private vtkPolyDataMapper edgesMapper; + private vtkTransform transform; + private boolean outline; private boolean profile; private boolean scalar; private SelectionState selectionState = SelectionState.BASE; private boolean useDeselectedState = true; - + private vtkProperty DESELECTION_PROPERTY; private vtkProperty SELECTION_PROPERTY; private vtkProperty BASE_PROPERTY; - + private int memorySize; + private boolean useLOD; private vtkActor selectionActor; - + public DefaultActor(String name) { this.name = name; this.transform = new vtkTransform(); this.selectionActor = new vtkActor(); - + setUpBaseProperty(); setUpSelectionProperty(); setUpDeselectionProperty(); @@ -106,7 +105,7 @@ public abstract class DefaultActor extends vtkActor implements Actor { actor.GetProperty().SetSpecular(VTKColors.SPECULAR); actor.GetProperty().SetSpecularPower(VTKColors.SPECULAR_POWER); } - + private void applyBaseProperty(vtkActor actor) { if (selectionState != SelectionState.BASE) { actor.GetProperty().SetColor(BASE_PROPERTY.GetColor()); @@ -119,16 +118,16 @@ public abstract class DefaultActor extends vtkActor implements Actor { SELECTION_PROPERTY.SetColor(VTKColors.SELECTION_COLOR); SELECTION_PROPERTY.SetOpacity(SELECTION_OPACITY); } - + private void applySelectionProperty(vtkActor actor) { if (selectionState != SelectionState.SELECTED) { - actor.GetProperty().SetColor(BASE_PROPERTY.GetColor()); + actor.GetProperty().SetColor(DESELECTION_PROPERTY.GetColor()); actor.GetProperty().SetOpacity(DESELECTION_PROPERTY.GetOpacity()); } } - + private void setUpDeselectionProperty() { - DESELECTION_PROPERTY = new vtkProperty(); + DESELECTION_PROPERTY = new vtkProperty(); DESELECTION_PROPERTY.SetColor(VTKColors.DESELECTION_COLOR); DESELECTION_PROPERTY.SetOpacity(DESELECTION_OPACITY); } @@ -143,31 +142,33 @@ public abstract class DefaultActor extends vtkActor implements Actor { input.ShallowCopy(dataset); this.mapper = new vtkPolyDataMapper(); + this.mapper.ScalarVisibilityOff(); this.mapper.ImmediateModeRenderingOff(); -// this.mapper.StaticOn(); -// VTKUtil.observe(mapper, getName()); + // this.mapper.StaticOn(); + // VTKUtil.observe(mapper, getName()); + this.LODMapper = new vtkPolyDataMapper(); + this.LODMapper.ScalarVisibilityOff(); + this.LODMapper.ImmediateModeRenderingOff(); + //this.LODMapper.StaticOn(); + SetMapper(mapper); selectionActor.SetMapper(mapper); - + this.outlineMapper = new vtkPolyDataMapper(); - this.outlineFilter = new vtkOutlineFilter(); - + this.outlineMapper.ScalarVisibilityOff(); + this.outlineMapper.ImmediateModeRenderingOff(); + this.edgesMapper = new vtkPolyDataMapper(); - this.edges = new vtkFeatureEdges(); - this.edges.SetBoundaryEdges(1); - this.edges.SetFeatureEdges(1); - this.edges.SetNonManifoldEdges(0); - this.edges.SetManifoldEdges(0); - this.edges.SetFeatureAngle(30D); - this.edges.ColoringOff(); - + this.edgesMapper.ScalarVisibilityOff(); + this.edgesMapper.ImmediateModeRenderingOff(); + this.outline = false; this.profile = false; this.scalar = false; - + setInput(input); - + input.Delete(); SetVisibility(visible ? 1 : 0); @@ -178,7 +179,7 @@ public abstract class DefaultActor extends vtkActor implements Actor { selectionActor.GetProperty().SetColor(SELECTION_PROPERTY.GetColor()); selectionActor.GetProperty().SetOpacity(SELECTION_PROPERTY.GetOpacity()); } - + protected void newActor(vtkUnstructuredGrid dataset, boolean visible) { vtkUnstructuredGrid input = new vtkUnstructuredGrid(); input.ShallowCopy(dataset); @@ -190,102 +191,124 @@ public abstract class DefaultActor extends vtkActor implements Actor { filter.Update(); input.Delete(); - newActor(filter.GetOutput(), visible); + vtkPolyData output = filter.GetOutput(); + newActor(output, visible); + output.Delete(); filter.Delete(); } - void createLOD() - { - this.LODMapper.ImmediateModeRenderingOff(); - this.LODMapper.StaticOn(); -// VTKUtil.observe(LODMapper, "LOD_" + getName()); - + vtkQuadricClustering createLOD() { int dim = 30; + vtkQuadricClustering LODFilter = new vtkQuadricClustering(); + LODFilter.UseInputPointsOn(); + LODFilter.CopyCellDataOn(); + LODFilter.UseInternalTrianglesOff(); + LODFilter.SetNumberOfDivisions(dim, dim, dim); + LODFilter.AutoAdjustNumberOfDivisionsOff(); + + return LODFilter; + } - this.LODFilter.UseInputPointsOn(); - this.LODFilter.CopyCellDataOn(); - this.LODFilter.UseInternalTrianglesOff(); - this.LODFilter.SetNumberOfDivisions(dim, dim, dim); - this.LODFilter.AutoAdjustNumberOfDivisionsOff(); + vtkOutlineFilter createOutline() { + return new vtkOutlineFilter(); } + vtkFeatureEdges createEdges() { + vtkFeatureEdges edges = new vtkFeatureEdges(); + edges.SetBoundaryEdges(1); + edges.SetFeatureEdges(1); + edges.SetNonManifoldEdges(0); + edges.SetManifoldEdges(0); + edges.SetFeatureAngle(30D); + edges.ColoringOff(); + + return edges; + + } @Override public void setInput(vtkPolyData input) { -// System.out.println("DefaultActor.setInput() size: " + input.GetActualMemorySize() + " kB"); + // System.out.println("DefaultActor.setInput() size: " + input.GetActualMemorySize() + " kB"); + SetMapper(null); + mapper.RemoveAllInputs(); mapper.SetInputData(input); - + int memory_limit = PrefUtil.getInt(PrefUtil._3D_LOCK_INTRACTIVE_MEMORY, 512); - this.memorySize = input.GetActualMemorySize(); - if (memorySize > memory_limit) { - if (LODMapper == null) { - this.LODMapper = new vtkPolyDataMapper(); - this.LODFilter = new vtkQuadricClustering(); - - createLOD(); - } - } else { - this.LODMapper = null; - this.LODFilter = null; - } + this.memorySize = input.GetActualMemorySize(); + this.useLOD = memorySize > memory_limit; if (LODMapper != null) { - LODFilter.RemoveAllInputs(); + vtkQuadricClustering LODFilter = createLOD(); LODFilter.SetInputData(input); LODFilter.Update(); - + + vtkPolyData output = LODFilter.GetOutput(); LODMapper.RemoveAllInputs(); - LODMapper.SetInputData(LODFilter.GetOutput()); + LODMapper.SetInputData(output); LODMapper.Update(); + output.Delete(); + LODFilter.Delete(); } - - if (outlineFilter != null) { + + if (outlineMapper != null) { + vtkOutlineFilter outlineFilter = createOutline(); outlineFilter.RemoveAllInputs(); outlineFilter.SetInputData(input); outlineFilter.Update(); - + + vtkPolyData output = outlineFilter.GetOutput(); outlineMapper.RemoveAllInputs(); - outlineMapper.SetInputData(outlineFilter.GetOutput()); + outlineMapper.SetInputData(output); outlineMapper.Update(); + + output.Delete(); + outlineFilter.Delete(); } - if (edges != null) { - edges.RemoveAllInputs(); + if (edgesMapper != null) { + vtkFeatureEdges edges = createEdges(); edges.SetInputData(input); edges.Update(); - + vtkPolyData output = edges.GetOutput(); + edgesMapper.RemoveAllInputs(); - edgesMapper.SetInputData(edges.GetOutput()); + edgesMapper.SetInputData(output); edgesMapper.Update(); + + output.Delete(); + edges.Delete(); } + + SetMapper(mapper); } - + @Override public void setInput(vtkUnstructuredGrid input) { vtkPolyData filter = VTKUtil.geometryFilter(input); setInput(filter); + filter.Delete(); } - + @Override public void interactiveOn() { if (!outline && !profile) { - if (LODMapper != null) { + if (useLOD) { SetMapper(LODMapper); selectionActor.SetMapper(LODMapper); } - } + } } @Override public void interactiveOff() { if (!outline && !profile) { - if (LODMapper != null) { + if (useLOD) { SetMapper(mapper); selectionActor.SetMapper(mapper); } } } - + @Override public String getName() { return name; @@ -295,7 +318,7 @@ public abstract class DefaultActor extends vtkActor implements Actor { public void rename(String name) { this.name = name; } - + @Override public vtkMapper getMapper() { return GetMapper(); @@ -316,35 +339,58 @@ public abstract class DefaultActor extends vtkActor implements Actor { public double[] getBounds() { return GetBounds(); } - + @Override public vtkActor getActor() { return this; } - + @Override public vtkActor getSelectionActor() { return selectionActor; } - + @Override public void deleteActor() { - if (LODFilter != null) { +// if (LODFilter != null) { +// LODFilter.RemoveAllInputs(); +// LODFilter.Delete(); +// } + if (LODMapper != null) { LODMapper.RemoveAllInputs(); LODMapper.Delete(); - LODFilter.RemoveAllInputs(); - LODFilter.Delete(); } - vtkDataSet dataset = mapper.GetInputAsDataSet(); + + if (edgesMapper != null) { + edgesMapper.RemoveAllInputs(); + edgesMapper.Delete(); + } +// if (edges != null) { +// edges.RemoveAllInputs(); +// edges.Delete(); +// } - VTKUtil.deleteDataset(dataset); + if (outlineMapper != null) { + outlineMapper.RemoveAllInputs(); + outlineMapper.Delete(); + } + + if (mapper != null) { +// vtkDataSet dataset = mapper.GetInputAsDataSet(); +// VTKUtil.deleteDataset(dataset); + mapper.RemoveAllInputs(); + mapper.Delete(); + } - mapper.RemoveAllInputs(); - mapper.Delete(); + SELECTION_PROPERTY.Delete(); + DESELECTION_PROPERTY.Delete(); + BASE_PROPERTY.Delete(); selectionActor.SetMapper(null); selectionActor.Delete(); + transform.Delete(); + SetMapper(null); Delete(); } @@ -352,7 +398,7 @@ public abstract class DefaultActor extends vtkActor implements Actor { @Override public void transformActor(boolean save, AffineTransform t) { vtkTransform transform = t.toVTK(this.transform); - + SetUserTransform(transform); selectionActor.SetUserTransform(transform); @@ -360,12 +406,12 @@ public abstract class DefaultActor extends vtkActor implements Actor { this.transform = transform; } } - + @Override public vtkTransform getUserTransform() { return (vtkTransform) GetUserTransform(); } - + @Override public void setSolidColor(double[] color, double opacity) { this.scalar = false; @@ -373,7 +419,7 @@ public abstract class DefaultActor extends vtkActor implements Actor { scalarVisibilityOff(); } - + @Override public void setScalarColors(vtkLookupTable lut, FieldItem field) { this.scalar = true; @@ -382,29 +428,27 @@ public abstract class DefaultActor extends vtkActor implements Actor { if (mapper != null) { setScalarColor(mapper, lut, field); } - if (LODMapper != null) { setScalarColor(LODMapper, lut, field); } + if (edgesMapper != null) { + setScalarColor(edgesMapper, lut, field); + } +// if (outlineMapper != null) { +// setScalarColor(outlineMapper, lut, field); +// } } protected void setLineWidth(int width) { GetProperty().SetLineWidth(width); - -// BASE_PROPERTY.SetLineWidth(width); -// SELECTION_PROPERTY.SetLineWidth(width); -// DESELECTION_PROPERTY.SetLineWidth(width); } - + protected void setColor(double[] color, double opacity) { GetProperty().SetColor(color); GetProperty().SetOpacity(opacity); - + BASE_PROPERTY.SetColor(color); BASE_PROPERTY.SetOpacity(opacity); - -// SELECTION_PROPERTY.SetColor(color); -// DESELECTION_PROPERTY.SetColor(color); } private static void setScalarColor(vtkMapper mapper, vtkLookupTable lut, FieldItem field) { @@ -420,65 +464,48 @@ public abstract class DefaultActor extends vtkActor implements Actor { } mapper.SetScalarRange(lut.GetRange()); - mapper.SelectColorArray(field.getName()); + mapper.SelectColorArray(field.getFieldName()); + mapper.InterpolateScalarsBeforeMappingOn(); mapper.Update(); } - + @Override public void setRepresentation(Representation representation) { switch (representation) { - case SURFACE: - GetProperty().SetRepresentationToSurface(); - GetProperty().EdgeVisibilityOff(); - -// BASE_PROPERTY.SetRepresentationToSurface(); -// BASE_PROPERTY.EdgeVisibilityOff(); - setOutLine(false); - setProfile(false); - break; - case WIREFRAME: - GetProperty().SetRepresentationToWireframe(); - GetProperty().EdgeVisibilityOff(); - -// BASE_PROPERTY.SetRepresentationToWireframe(); -// BASE_PROPERTY.EdgeVisibilityOff(); - setOutLine(false); - setProfile(false); - break; - case SURFACE_WITH_EDGES: - GetProperty().SetRepresentationToSurface(); - GetProperty().EdgeVisibilityOn(); - -// BASE_PROPERTY.SetRepresentationToSurface(); -// BASE_PROPERTY.EdgeVisibilityOn(); - setOutLine(false); - setProfile(false); - break; - case OUTLINE: -// GetProperty().SetRepresentationToSurface(); -// GetProperty().EdgeVisibilityOff(); -// -// BASE_PROPERTY.SetRepresentationToSurface(); -// BASE_PROPERTY.EdgeVisibilityOff(); - setProfile(false); - setOutLine(true); - break; - - case PROFILE: -// GetProperty().SetRepresentationToSurface(); -// GetProperty().EdgeVisibilityOff(); -// -// BASE_PROPERTY.SetRepresentationToSurface(); -// BASE_PROPERTY.EdgeVisibilityOff(); - setOutLine(false); - setProfile(true); - break; + case SURFACE: + GetProperty().SetRepresentationToSurface(); + GetProperty().EdgeVisibilityOff(); + setOutLine(false); + setProfile(false); + break; + case WIREFRAME: + GetProperty().SetRepresentationToWireframe(); + GetProperty().EdgeVisibilityOff(); + setOutLine(false); + setProfile(false); + break; + case SURFACE_WITH_EDGES: + GetProperty().SetRepresentationToSurface(); + GetProperty().EdgeVisibilityOn(); + setOutLine(false); + setProfile(false); + break; + case OUTLINE: + GetProperty().EdgeVisibilityOff(); + setProfile(false); + setOutLine(true); + break; + case PROFILE: + GetProperty().EdgeVisibilityOff(); + setOutLine(false); + setProfile(true); + break; - default: - break; + default: + break; } } - + private void setOutLine(boolean outline) { if (outline) { if (!this.outline) { @@ -491,7 +518,7 @@ public abstract class DefaultActor extends vtkActor implements Actor { } this.outline = outline; } - + private void setProfile(boolean profile) { if (profile) { if (!this.profile) { @@ -504,7 +531,7 @@ public abstract class DefaultActor extends vtkActor implements Actor { } this.profile = profile; } - + private void outlineActor() { SetMapper(outlineMapper); } @@ -512,7 +539,7 @@ public abstract class DefaultActor extends vtkActor implements Actor { private void deoutlineActor() { SetMapper(mapper); } - + private void profileActor() { SetMapper(edgesMapper); } @@ -520,7 +547,7 @@ public abstract class DefaultActor extends vtkActor implements Actor { private void deprofileActor() { SetMapper(mapper); } - + @Override public void restoreFromSelection() { if (this.selectionState != SelectionState.BASE) { @@ -532,8 +559,8 @@ public abstract class DefaultActor extends vtkActor implements Actor { } } this.selectionState = SelectionState.BASE; - } - + } + @Override public void selectActor() { if (this.selectionState != SelectionState.SELECTED) { @@ -542,7 +569,7 @@ public abstract class DefaultActor extends vtkActor implements Actor { } this.selectionState = SelectionState.SELECTED; } - + @Override public void deselectActor() { if (useDeselectedState) { @@ -560,33 +587,54 @@ public abstract class DefaultActor extends vtkActor implements Actor { if (mapper != null) { mapper.ScalarVisibilityOff(); } - if (LODMapper != null) { LODMapper.ScalarVisibilityOff(); } + if (edgesMapper != null) { + edgesMapper.ScalarVisibilityOff(); + } +// if (outlineMapper != null) { +// outlineMapper.ScalarVisibilityOff(); +// } } private void scalarVisibilityOn() { if (mapper != null) { mapper.ScalarVisibilityOn(); } - if (LODMapper != null) { LODMapper.ScalarVisibilityOn(); } + if (edgesMapper != null) { + edgesMapper.ScalarVisibilityOn(); + } +// if (outlineMapper != null) { +// outlineMapper.ScalarVisibilityOn(); +// } } - + @Override public void deselectedStateOn() { this.useDeselectedState = true; } + @Override public void deselectedStateOff() { this.useDeselectedState = false; } - + @Override public int getMemorySize() { return memorySize; } + + @Override + public void filterActor() { + setVisibility(false); + } + + @Override + public void unfilterActor() { + setVisibility(true); + } } diff --git a/src/eu/engys/vtk/actors/HelyxActor.java b/src/eu/engys/vtk/actors/HelyxActor.java index 42a8f34..9649f73 100644 --- a/src/eu/engys/vtk/actors/HelyxActor.java +++ b/src/eu/engys/vtk/actors/HelyxActor.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ //package eu.engys.vtk.actors; // //import org.apache.commons.lang.ArrayUtils; @@ -513,4 +512,4 @@ //// } // } // -//} +//} \ No newline at end of file diff --git a/src/eu/engys/vtk/actors/InternalMeshActor.java b/src/eu/engys/vtk/actors/InternalMeshActor.java index 442c07b..e1170e7 100644 --- a/src/eu/engys/vtk/actors/InternalMeshActor.java +++ b/src/eu/engys/vtk/actors/InternalMeshActor.java @@ -1,40 +1,40 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.vtk.actors; -import vtk.vtkUnstructuredGrid; import eu.engys.util.ui.checkboxtree.VisibleItem; +import vtk.vtkUnstructuredGrid; public class InternalMeshActor extends DefaultActor { + public static final String INTERNAL_MESH = "internalMesh"; + public InternalMeshActor(vtkUnstructuredGrid internalMeshDataset) { - super("internalMesh"); + super(INTERNAL_MESH); newActor(internalMeshDataset, false); - GetMapper().ScalarVisibilityOff(); VisibilityOff(); GetProperty().SetOpacity(1); } diff --git a/src/eu/engys/vtk/actors/LineActor.java b/src/eu/engys/vtk/actors/LineActor.java index 9e52752..7603d92 100644 --- a/src/eu/engys/vtk/actors/LineActor.java +++ b/src/eu/engys/vtk/actors/LineActor.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.vtk.actors; import eu.engys.core.project.geometry.FeatureLine; @@ -37,6 +36,11 @@ public class LineActor extends SurfaceActor { setColor(VTKColors.toVTK(line.getColor()), 1.0); setLineWidth(2); newActor(line.getDataSet(), line.isVisible()); + getMapper().SetResolveCoincidentTopologyToShiftZBuffer(); + getMapper().SetResolveCoincidentTopologyZShift(0.0001); +// getMapper().SetResolveCoincidentTopologyToPolygonOffset(); +// getMapper().SetResolveCoincidentTopologyPolygonOffsetFaces(1); + getActor().GetProperty().SetLineWidth(1); } @Override @@ -44,4 +48,4 @@ public class LineActor extends SurfaceActor { // do nothing!!! } -} +} \ No newline at end of file diff --git a/src/eu/engys/vtk/actors/PlaneActor.java b/src/eu/engys/vtk/actors/PlaneActor.java index 9999976..af5ee53 100644 --- a/src/eu/engys/vtk/actors/PlaneActor.java +++ b/src/eu/engys/vtk/actors/PlaneActor.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.vtk.actors; import eu.engys.core.project.geometry.surface.Plane; diff --git a/src/eu/engys/vtk/actors/PlaneRegionActor.java b/src/eu/engys/vtk/actors/PlaneRegionActor.java index 0d86195..066277a 100644 --- a/src/eu/engys/vtk/actors/PlaneRegionActor.java +++ b/src/eu/engys/vtk/actors/PlaneRegionActor.java @@ -1,36 +1,35 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.vtk.actors; -import vtk.vtkLookupTable; import eu.engys.core.project.geometry.surface.PlaneRegion; import eu.engys.core.project.mesh.FieldItem; import eu.engys.gui.view3D.Representation; import eu.engys.vtk.VTKColors; import eu.engys.vtk.actors.SurfaceToActor.ActorMode; +import vtk.vtkLookupTable; public class PlaneRegionActor extends SurfaceActor { diff --git a/src/eu/engys/vtk/actors/RingActor.java b/src/eu/engys/vtk/actors/RingActor.java index f7458d2..02d7ddb 100644 --- a/src/eu/engys/vtk/actors/RingActor.java +++ b/src/eu/engys/vtk/actors/RingActor.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.vtk.actors; import eu.engys.core.project.geometry.surface.Ring; diff --git a/src/eu/engys/vtk/actors/RotatedBoxActor.java b/src/eu/engys/vtk/actors/RotatedBoxActor.java new file mode 100644 index 0000000..210d831 --- /dev/null +++ b/src/eu/engys/vtk/actors/RotatedBoxActor.java @@ -0,0 +1,35 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.vtk.actors; + +import eu.engys.core.project.geometry.surface.RotatedBox; + +public class RotatedBoxActor extends SurfaceActor { + + public RotatedBoxActor(RotatedBox rbox) { + super(rbox); + newActor(rbox.getDataSet(), rbox.isVisible()); + } +} diff --git a/src/eu/engys/vtk/actors/SolidActor.java b/src/eu/engys/vtk/actors/SolidActor.java index 419f2d1..a4a9fc2 100644 --- a/src/eu/engys/vtk/actors/SolidActor.java +++ b/src/eu/engys/vtk/actors/SolidActor.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.vtk.actors; import eu.engys.core.project.geometry.surface.Solid; @@ -32,7 +31,13 @@ public class SolidActor extends SurfaceActor { public SolidActor(Solid solid) { super(solid); +// vtkCleanPolyData clean = new vtkCleanPolyData(); +// clean.AddInputData(solid.getDataSet()); +// clean.Update(); +// +// newActor(clean.GetOutput(), solid.isVisible()); +// clean.Delete(); newActor(solid.getDataSet(), solid.isVisible()); transformActor(true, solid.getTransformation()); } -} +} \ No newline at end of file diff --git a/src/eu/engys/vtk/actors/SphereActor.java b/src/eu/engys/vtk/actors/SphereActor.java index 132bdd6..274d5f2 100644 --- a/src/eu/engys/vtk/actors/SphereActor.java +++ b/src/eu/engys/vtk/actors/SphereActor.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.vtk.actors; import eu.engys.core.project.geometry.surface.Sphere; diff --git a/src/eu/engys/vtk/actors/StlActor.java b/src/eu/engys/vtk/actors/StlActor.java index 6a71460..117d77a 100644 --- a/src/eu/engys/vtk/actors/StlActor.java +++ b/src/eu/engys/vtk/actors/StlActor.java @@ -1,34 +1,32 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.vtk.actors; -import vtk.vtkAppendPolyData; -import vtk.vtkCleanPolyData; import eu.engys.core.project.geometry.surface.Solid; import eu.engys.core.project.geometry.surface.Stl; +import vtk.vtkAppendPolyData; public class StlActor extends SurfaceActor { @@ -37,20 +35,20 @@ public class StlActor extends SurfaceActor { super(stl); vtkAppendPolyData append = new vtkAppendPolyData(); - for (Solid solid : stl.getSolids()) { - append.SetInputData(solid.getDataSet()); + append.AddInputData(solid.getDataSet()); } append.Update(); - vtkCleanPolyData clean = new vtkCleanPolyData(); - clean.AddInputData(append.GetOutput()); - clean.Update(); - - newActor(clean.GetOutput(), stl.isVisible()); + newActor(append.GetOutput(), stl.isVisible()); +// vtkCleanPolyData clean = new vtkCleanPolyData(); +// clean.AddInputData(append.GetOutput()); +// clean.Update(); +// +// newActor(clean.GetOutput(), stl.isVisible()); append.Delete(); - clean.Delete(); +// clean.Delete(); transformActor(true, stl.getTransformation()); } -} +} \ No newline at end of file diff --git a/src/eu/engys/vtk/actors/StlAreaActor.java b/src/eu/engys/vtk/actors/StlAreaActor.java new file mode 100644 index 0000000..7f1dce3 --- /dev/null +++ b/src/eu/engys/vtk/actors/StlAreaActor.java @@ -0,0 +1,40 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.vtk.actors; + +import eu.engys.core.project.geometry.surface.StlArea; +import vtk.vtkPolyData; + +public class StlAreaActor extends SurfaceActor { + + public StlAreaActor(StlArea stlArea) { + super(stlArea); + + vtkPolyData dataSet = stlArea.getDataSet() != null ? stlArea.getDataSet() : new vtkPolyData(); + newActor(dataSet, stlArea.isVisible()); + + transformActor(true, stlArea.getTransformation()); + } +} \ No newline at end of file diff --git a/src/eu/engys/vtk/actors/SurfaceActor.java b/src/eu/engys/vtk/actors/SurfaceActor.java index 16900d3..e944192 100644 --- a/src/eu/engys/vtk/actors/SurfaceActor.java +++ b/src/eu/engys/vtk/actors/SurfaceActor.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.vtk.actors; import eu.engys.core.project.geometry.Surface; @@ -40,4 +39,4 @@ abstract class SurfaceActor extends DefaultActor { public VisibleItem getVisibleItem() { return surface; } -} +} \ No newline at end of file diff --git a/src/eu/engys/vtk/actors/SurfaceToActor.java b/src/eu/engys/vtk/actors/SurfaceToActor.java index 809c01a..8637a3a 100644 --- a/src/eu/engys/vtk/actors/SurfaceToActor.java +++ b/src/eu/engys/vtk/actors/SurfaceToActor.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.vtk.actors; @@ -43,9 +42,11 @@ import eu.engys.core.project.geometry.surface.MultiPlane; import eu.engys.core.project.geometry.surface.Plane; import eu.engys.core.project.geometry.surface.PlaneRegion; import eu.engys.core.project.geometry.surface.Ring; +import eu.engys.core.project.geometry.surface.RotatedBox; import eu.engys.core.project.geometry.surface.Solid; import eu.engys.core.project.geometry.surface.Sphere; import eu.engys.core.project.geometry.surface.Stl; +import eu.engys.core.project.geometry.surface.StlArea; import eu.engys.gui.view3D.Actor; import eu.engys.util.progress.ProgressMonitor; @@ -73,6 +74,9 @@ public class SurfaceToActor { case BOX: Box box = (Box) surface; return getBoxActor(box); + case RBOX: + RotatedBox rbox = (RotatedBox) surface; + return getRotatedBoxActor(rbox); case CYLINDER: Cylinder cyl = (Cylinder) surface; return getCylinderActor(cyl); @@ -95,6 +99,9 @@ public class SurfaceToActor { case STL: Stl stl = (Stl) surface; return getSTLActor(stl); + case STL_AREA: + StlArea stlArea = (StlArea) surface; + return getSTLAreaActor(stlArea); case MULTI: MultiPlane multi = (MultiPlane) surface; return getMultiPlaneActor(multi); @@ -126,6 +133,11 @@ public class SurfaceToActor { return actors.toArray(new Actor[0]); } + private Actor[] getSTLAreaActor(StlArea stlArea) { + logger.info("[ADD STL AREA] name: {}", stlArea.getPatchName()); + return new Actor[] { new StlAreaActor(stlArea) }; + } + private Actor[] getSolidActor(Solid solid) { logger.info("[ADD SOLID] name: {}", solid.getPatchName()); return new Actor[] { new SolidActor(solid) }; @@ -141,13 +153,18 @@ public class SurfaceToActor { return new SurfaceActor[] { new BoxActor(box) }; } + private SurfaceActor[] getRotatedBoxActor(RotatedBox box) { + logger.info("[ADD BOX] origin: {}, i: {}, j: {}, k: {}", format(box.getOrigin()).toCents(), format(box.getI()).toCents(), format(box.getJ()).toCents(), format(box.getK()).toCents()); + return new SurfaceActor[] { new RotatedBoxActor(box) }; + } + private SurfaceActor[] getCylinderActor(Cylinder cylinder) { logger.info("[ADD CYLINDER] point1: {}, point2: {}, radius: {}", format(cylinder.getPoint1()).toCents(), format(cylinder.getPoint2()).toCents(), format(cylinder.getRadius()).toCents()); return new SurfaceActor[] { new CylinderActor(cylinder) }; } private SurfaceActor[] getSphereActor(Sphere sphere) { - logger.info("[ADD SPHERE] center: {}, radius: {}", format(sphere.getCenter()).toCents(), sphere.getRadius()); + logger.info("[ADD SPHERE] center: {}, radius: {}", format(sphere.getCentre()).toCents(), sphere.getRadius()); return new SurfaceActor[] { new SphereActor(sphere) }; } @@ -171,13 +188,13 @@ public class SurfaceToActor { } private SurfaceActor[] getPlaneActor(Plane plane) { - if (plane.getCenter() == null) { - plane.setCenter(boundingBox.getCenter()); + if (plane.getBasePoint() == null) { + plane.setBasePoint(boundingBox.getCenter()); } - if (plane.getNormal() == null) { - plane.setNormal(new double[] {0, 0, 1}); + if (plane.getNormalVector() == null) { + plane.setNormalVector(new double[] {0, 0, 1}); } - logger.info("[ADD PLANE] origin: {}, normal: {}", format(plane.getCenter()).toCents(), format(plane.getNormal()).toCents()); + logger.info("[ADD PLANE] origin: {}, normal: {}", format(plane.getBasePoint()).toCents(), format(plane.getNormalVector()).toCents()); return new SurfaceActor[] { new PlaneActor(plane) }; } } diff --git a/src/eu/engys/vtk/info/VTKArrayInformation.java b/src/eu/engys/vtk/info/VTKArrayInformation.java deleted file mode 100644 index 809a850..0000000 --- a/src/eu/engys/vtk/info/VTKArrayInformation.java +++ /dev/null @@ -1,647 +0,0 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - - -package eu.engys.vtk.info; - -import java.io.PrintStream; -import java.util.ArrayList; -import java.util.List; - -import vtk.vtkAbstractArray; -import vtk.vtkDataArray; -import vtk.vtkObject; - -public class VTKArrayInformation { - String Name; - double[][] Ranges; - List ComponentNames; - String DefaultComponentName; - List InformationKeys; - int DataType; - int NumberOfComponents; - int NumberOfTuples; - boolean IsPartial; - private Object NumberOfInformationKeys; - -// namespace -// { -// typedef std::vector vtkInternalComponentNameBase; -// -// struct vtkPVArrayInformationInformationKey -// { -// vtkStdString Location; -// vtkStdString Name; -// }; -// -// typedef std::vector vtkInternalInformationKeysBase; -// } -// -// class vtkPVArrayInformation::vtkInternalComponentNames: -// public vtkInternalComponentNameBase -// { -// }; -// -// class vtkPVArrayInformation::vtkInternalInformationKeys: -// public vtkInternalInformationKeysBase -// { -// }; - - //---------------------------------------------------------------------------- - public VTKArrayInformation() - { - this.Initialize(); - } - - //---------------------------------------------------------------------------- - void Initialize() - { - this.Name = null; - this.DataType = VTKConstants.VTK_VOID; - this.NumberOfComponents = 0; - this.NumberOfTuples = 0; - - this.ComponentNames = new ArrayList<>(); - this.DefaultComponentName = null; - - this.Ranges = null; - this.IsPartial = false; - - this.InformationKeys = new ArrayList<>(); - } - - //---------------------------------------------------------------------------- - void PrintSelf(PrintStream os, String indent) - { - if (this.Name != null) - { - os.println(indent+"Name: " + this.Name); - } - os.println(indent+"DataType: " + this.DataType); - os.println(indent+"NumberOfComponents: " + this.NumberOfComponents); - if (this.ComponentNames != null) - { - os.println(indent+"ComponentNames:"); - for (int i = 0; i < this.ComponentNames.size(); ++i) - { - os.println(indent+indent+this.ComponentNames.get(i)); - } - } - os.println(indent+"NumberOfTuples: " + this.NumberOfTuples); - os.println(indent+"IsPartial: " + this.IsPartial); - - os.println(indent+"Ranges :"); - int num = this.NumberOfComponents; - if (num > 1) - { - ++num; - } - for (int idx = 0; idx < num; ++idx) - { - os.println(indent+indent+this.Ranges[idx][0] + ", " + this.Ranges[idx][1]); - } - - os.println(indent+"InformationKeys :"); - if(this.InformationKeys != null) - { -// num = this.NumberOfInformationKeys; -// for (idx = 0; idx < num; ++idx) -// { -// os + i2 + this.GetInformationKeyLocation(idx) + "::" -// + this.GetInformationKeyName(idx)); -// } - } else - { - os.println(indent+indent+"None"); - } - } - - //---------------------------------------------------------------------------- -// void vtkPVArrayInformation::SetNumberOfComponents(int numComps) -// { -// if (this.NumberOfComponents == numComps) -// { -// return; -// } -// if (this.Ranges) -// { -// delete[] this.Ranges; -// this.Ranges = NULL; -// } -// this.NumberOfComponents = numComps; -// if (numComps <= 0) -// { -// this.NumberOfComponents = 0; -// return; -// } -// if (numComps > 1) -// { // Extra range for vector magnitude (first in array). -// numComps = numComps + 1; -// } -// -// int idx; -// this.Ranges = new double[numComps * 2]; -// for (idx = 0; idx < numComps; ++idx) -// { -// this.Ranges[2 * idx] = VTK_DOUBLE_MAX; -// this.Ranges[2 * idx + 1] = -VTK_DOUBLE_MAX; -// } -// } - - //---------------------------------------------------------------------------- -// void vtkPVArrayInformation::SetComponentName(vtkIdType component, -// const char *name) -// { -// if (component < 0 || name == NULL) -// { -// return; -// } -// -// unsigned int index = static_cast (component); -// if (this.ComponentNames == NULL) -// { -// //delayed allocate -// this.ComponentNames -// = new vtkPVArrayInformation::vtkInternalComponentNames(); -// } -// -// if (index == this.ComponentNames.size()) -// { -// //the array isn't large enough, so we will resize -// this.ComponentNames.push_back(new vtkStdString(name)); -// return; -// } -// else if (index > this.ComponentNames.size()) -// { -// this.ComponentNames.resize(index + 1, NULL); -// } -// -// //replace an exisiting element -// vtkStdString *compName = this.ComponentNames.at(index); -// if (!compName) -// { -// compName = new vtkStdString(name); -// this.ComponentNames.at(index) = compName; -// } -// else -// { -// compName.assign(name); -// } -// } - - //---------------------------------------------------------------------------- -// const char* vtkPVArrayInformation::GetComponentName(vtkIdType component) -// { -// unsigned int index = static_cast (component); -// //check signed component for less than zero -// if (this.ComponentNames && component >= 0 && index -// < this.ComponentNames.size()) -// { -// vtkStdString *compName = this.ComponentNames.at(index); -// if (compName) -// { -// return compName.c_str(); -// } -// } -// else if (this.ComponentNames && component == -1 -// && this.ComponentNames.size() >= 1) -// { -// //we have a scalar array, and we need the component name -// vtkStdString *compName = this.ComponentNames.at(0); -// if (compName) -// { -// return compName.c_str(); -// } -// } -// //we have failed to find a user set component name, use the default component name -// this.DetermineDefaultComponentName(component, this.GetNumberOfComponents()); -// return this.DefaultComponentName.c_str(); -// } - - //---------------------------------------------------------------------------- -// void vtkPVArrayInformation::SetComponentRange(int comp, double min, double max) -// { -// if (comp >= this.NumberOfComponents || this.NumberOfComponents <= 0) -// { -// vtkErrorMacro("Bad component"); -// } -// if (this.NumberOfComponents > 1) -// { // Shift over vector mag range. -// ++comp; -// } -// if (comp < 0) -// { // anything less than 0 just defaults to the vector mag. -// comp = 0; -// } -// this.Ranges[comp * 2] = min; -// this.Ranges[comp * 2 + 1] = max; -// } - - //---------------------------------------------------------------------------- -// double* vtkPVArrayInformation::GetComponentRange(int comp) -// { -// if (comp >= this.NumberOfComponents || this.NumberOfComponents <= 0) -// { -// vtkErrorMacro("Bad component"); -// return NULL; -// } -// if (this.NumberOfComponents > 1) -// { // Shift over vector mag range. -// ++comp; -// } -// if (comp < 0) -// { // anything less than 0 just defaults to the vector mag. -// comp = 0; -// } -// return this.Ranges + comp * 2; -// } - - //---------------------------------------------------------------------------- -// void vtkPVArrayInformation::GetComponentRange(int comp, double *range) -// { -// double *ptr; -// -// ptr = this.GetComponentRange(comp); -// -// if (ptr == NULL) -// { -// range[0] = VTK_DOUBLE_MAX; -// range[1] = -VTK_DOUBLE_MAX; -// return; -// } -// -// range[0] = ptr[0]; -// range[1] = ptr[1]; -// } - - //---------------------------------------------------------------------------- -// void vtkPVArrayInformation::GetDataTypeRange(double range[2]) -// { -// int dataType = this.GetDataType(); -// switch (dataType) -// { -// case VTK_BIT: -// range[0] = VTK_BIT_MAX; -// range[1] = VTK_BIT_MAX; -// break; -// case VTK_UNSIGNED_CHAR: -// range[0] = VTK_UNSIGNED_CHAR_MIN; -// range[1] = VTK_UNSIGNED_CHAR_MAX; -// break; -// case VTK_CHAR: -// range[0] = VTK_CHAR_MIN; -// range[1] = VTK_CHAR_MAX; -// break; -// case VTK_UNSIGNED_SHORT: -// range[0] = VTK_UNSIGNED_SHORT_MIN; -// range[1] = VTK_UNSIGNED_SHORT_MAX; -// break; -// case VTK_SHORT: -// range[0] = VTK_SHORT_MIN; -// range[1] = VTK_SHORT_MAX; -// break; -// case VTK_UNSIGNED_INT: -// range[0] = VTK_UNSIGNED_INT_MIN; -// range[1] = VTK_UNSIGNED_INT_MAX; -// break; -// case VTK_INT: -// range[0] = VTK_INT_MIN; -// range[1] = VTK_INT_MAX; -// break; -// case VTK_UNSIGNED_LONG: -// range[0] = VTK_UNSIGNED_LONG_MIN; -// range[1] = VTK_UNSIGNED_LONG_MAX; -// break; -// case VTK_LONG: -// range[0] = VTK_LONG_MIN; -// range[1] = VTK_LONG_MAX; -// break; -// case VTK_FLOAT: -// range[0] = VTK_FLOAT_MIN; -// range[1] = VTK_FLOAT_MAX; -// break; -// case VTK_DOUBLE: -// range[0] = VTK_DOUBLE_MIN; -// range[1] = VTK_DOUBLE_MAX; -// break; -// default: -// // Default value: -// range[0] = 0; -// range[1] = 1; -// break; -// } -// } - //---------------------------------------------------------------------------- - void AddRanges(VTKArrayInformation info) - { - if (this.NumberOfComponents != info.NumberOfComponents) - { - System.err.println("Component mismatch."); - } - - double[] range = info.Ranges[0]; - if (this.NumberOfComponents > 1) - { - if (range[0] < this.Ranges[0][0]) - { - Ranges[0][0] = range[0]; - } - if (range[1] > Ranges[0][1]) - { - Ranges[0][1] = range[1]; - } - for (int idx = 0; idx < this.NumberOfComponents; ++idx) - { - range = info.Ranges[idx]; - if (range[0] < Ranges[idx+1][0]) - { - Ranges[idx+1][0] = range[0]; - } - if (range[1] > Ranges[idx+1][1]) - { - Ranges[idx+1][1] = range[1]; - } - } - } else { - if (range[0] < this.Ranges[0][0]) - { - Ranges[0][0] = range[0]; - } - if (range[1] > Ranges[0][1]) - { - Ranges[0][1] = range[1]; - } - } - - - this.NumberOfTuples += info.NumberOfTuples; - } - - //---------------------------------------------------------------------------- - void DeepCopy(VTKArrayInformation info) - { - this.Name = info.Name; - this.DataType = info.DataType; - this.NumberOfComponents = info.NumberOfComponents; - this.NumberOfTuples = info.NumberOfTuples; - - if (this.NumberOfComponents > 1) - { - this.Ranges = new double[this.NumberOfComponents+1][2]; - for (int idx = 0; idx < this.NumberOfComponents+1; ++idx) - { - this.Ranges[idx] = info.Ranges[idx]; - } - } else { - this.Ranges = new double[this.NumberOfComponents][2]; - this.Ranges[0] = info.Ranges[0]; - } - - - //clear the vector of old data - if (this.ComponentNames != null) - { - this.ComponentNames = null; - } - - if (info.ComponentNames != null) - { -// this.ComponentNames -// = new vtkPVArrayInformation::vtkInternalComponentNames(); -// //copy the passed in components if they exist -// this.ComponentNames.reserve(info.ComponentNames.size()); -// const char *name; -// for (unsigned i = 0; i < info.ComponentNames.size(); ++i) -// { -// name = info.GetComponentName(i); -// if (name) -// { -// this.SetComponentName(i, name); -// } -// } - } - - if (this.InformationKeys == null) - { - this.InformationKeys = new ArrayList<>(); - } - - //clear the vector of old data - this.InformationKeys.clear(); - - if (info.InformationKeys != null) - { -// //copy the passed in components if they exist -// for (unsigned i = 0; i < info.InformationKeys.size(); ++i) -// { -// this.InformationKeys.push_back(info.InformationKeys.at(i)); -// } - } - } - - //---------------------------------------------------------------------------- - boolean Compare(VTKArrayInformation info) { - if (info == null) { - return false; - } - if (info.Name.equals(this.Name) && info.NumberOfComponents == this.NumberOfComponents && this.NumberOfInformationKeys == info.NumberOfInformationKeys) { - return true; - } - return false; - } - - //---------------------------------------------------------------------------- - void CopyFromObject(vtkObject obj) - { - this.Initialize(); - - vtkAbstractArray array = (vtkAbstractArray) obj; -// if (!array) -// { -// vtkErrorMacro("Cannot downcast to abstract array."); -// this.Initialize(); -// return; -// } - - this.Name = array.GetName(); - this.DataType = array.GetDataType(); - this.NumberOfComponents = array.GetNumberOfComponents(); - this.NumberOfTuples = array.GetNumberOfTuples(); - - if (array.HasAComponentName()) - { - //copy the component names over - for (int i = 0; i < this.NumberOfComponents; ++i) - { - String name = array.GetComponentName(i); - if (name != null) - { - //each component doesn't have to be named - this.ComponentNames.add(i, name); - } - } - } - - if (obj instanceof vtkDataArray) - { - vtkDataArray data_array = (vtkDataArray) obj; - - if (this.NumberOfComponents > 1) - { - this.Ranges = new double[this.NumberOfComponents+1][2]; - // First store range of vector magnitude. - data_array.GetRange(this.Ranges[0], -1); - for (int idx = 0; idx < this.NumberOfComponents; ++idx) - { - data_array.GetRange(this.Ranges[idx+1], idx); - } - } else { - this.Ranges = new double[this.NumberOfComponents][2]; - data_array.GetRange(this.Ranges[0], 0); - } - } - -// if(this.InformationKeys) -// { -// this.InformationKeys.clear(); -// delete this.InformationKeys; -// this.InformationKeys = 0; -// } - if (array.HasInformation()) - { -// vtkInformation info = array.GetInformation(); -// vtkInformationIterator it = new vtkInformationIterator(); -// it.SetInformationWeak(info); -// it.GoToFirstItem(); -// while (!it.IsDoneWithTraversal()) -// { -// vtkInformationKey key = it.GetCurrentKey(); -// this.AddInformationKey(key.GetLocation(), key.GetName()); -// it.GoToNextItem(); -// } -// it.Delete(); - } - } - - //---------------------------------------------------------------------------- - void AddInformation(VTKArrayInformation info) - { - if (info == null) { - return; - } - - if (info.NumberOfComponents > 0) - { - if (this.NumberOfComponents == 0) - { - // If this object is uninitialized, copy. - this.DeepCopy(info); - } - else - { - // Leave everything but ranges and unique values as original, add ranges and unique values. - this.AddRanges(info); - //this.AddInformationKeys(info); - } - } - } - - //----------------------------------------------------------------------------- -// void DetermineDefaultComponentName( -// const int &component_no, const int &num_components) -// { -// if (!this.DefaultComponentName) -// { -// this.DefaultComponentName = new vtkStdString(); -// } -// -// this.DefaultComponentName.assign(vtkPVPostFilter::DefaultComponentName(component_no, num_components)); -// } - -// void AddInformationKeys(VTKArrayInformation info) -// { -// for (int k = 0; k < info.NumberOfInformationKeys; k++) -// { -// this.AddUniqueInformationKey(info.GetInformationKeyLocation(k), -// info.GetInformationKeyName(k)); -// } -// } - -// void AddInformationKey(String location, String name) -// { -// if(this.InformationKeys == null) -// { -// this.InformationKeys = new vtkInternalInformationKeys(); -// } -// vtkPVArrayInformationInformationKey info = vtkPVArrayInformationInformationKey(); -// info.Location = location; -// info.Name = name; -// this.InformationKeys.push_back(info); -// } - -// void AddUniqueInformationKey(String location, String name) -// { -// if (!this.HasInformationKey(location, name)) -// { -// this.AddInformationKey(location, name); -// } -// } - -// int GetNumberOfInformationKeys() -// { -// return static_cast(this.InformationKeys ? this.InformationKeys.size() : 0); -// } - -// String GetInformationKeyLocation(int index) -// { -// if (index < 0 || index >= this.GetNumberOfInformationKeys()) -// return NULL; -// -// return this.InformationKeys.at(index).Location; -// } - -// String GetInformationKeyName(int index) -// { -// if (index < 0 || index >= this.GetNumberOfInformationKeys()) -// return NULL; -// -// return this.InformationKeys.at(index).Name; -// } - -// int HasInformationKey(String location, String name) -// { -// for (int k = 0; k < this.GetNumberOfInformationKeys(); k++) -// { -// String key_location = this.GetInformationKeyLocation(k); -// String key_name = this.GetInformationKeyName(k); -// if (strcmp(location, key_location) == 0 && strcmp(name, key_name) == 0) -// { -// return 1; -// } -// } -// return 0; -// } - -} diff --git a/src/eu/engys/vtk/info/VTKCompositeDataInformation.java b/src/eu/engys/vtk/info/VTKCompositeDataInformation.java deleted file mode 100644 index e04e62c..0000000 --- a/src/eu/engys/vtk/info/VTKCompositeDataInformation.java +++ /dev/null @@ -1,419 +0,0 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - - -package eu.engys.vtk.info; - -import java.io.PrintStream; -import java.util.ArrayList; -import java.util.List; - -import vtk.vtkCompositeDataSet; -import vtk.vtkDataObject; -import vtk.vtkInformation; -import vtk.vtkMultiBlockDataSet; -import vtk.vtkMultiPieceDataSet; -import vtk.vtkObject; - -public class VTKCompositeDataInformation { - - class DataInformation { - VTKDataInformation Info; - String Name; - } - - private boolean DataIsComposite; - private boolean DataIsMultiPiece; - private int NumberOfPieces; - private List ChildrenInformation; - - public VTKCompositeDataInformation() { - // this.Internal = new vtkPVCompositeDataInformationInternals; - this.DataIsComposite = false; - this.DataIsMultiPiece = false; - this.NumberOfPieces = 0; - // DON'T FORGET TO UPDATE Initialize(). - } - - boolean GetDataIsComposite() { - return DataIsComposite; - } - - boolean GetDataIsMultiPiece() { - return DataIsMultiPiece; - } - void PrintSelf(PrintStream os, String indent) - { - os.println(indent+"DataIsMultiPiece: " + this.DataIsMultiPiece); - os.println(indent+"DataIsComposite: " + this.DataIsComposite); - } - -// VTKDataInformation GetDataInformationForCompositeIndex(int index) -// { -// if (!this.DataIsComposite) -// { -// return null; -// } -// -// if (this.DataIsMultiPiece) -// { -// if (index < this.NumberOfPieces) { -// (*index)=-1; -// return null; -// } -// -// (*index) -= this.NumberOfPieces; -// } -// -// for ( DataInformation d : ChildrenInformation) -// { -// if (d.Info != null) -// { -// VTKDataInformation info = d.Info.GetDataInformationForCompositeIndex(index); -// if ( (*index) == -1) -// { -// return info; -// } -// } else { -// (*index)--; -// if ((*index) < 0) -// { -// return null; -// } -// } -// } -// return null; -// } - - void Initialize() { - this.DataIsMultiPiece = false; - this.NumberOfPieces = 0; - this.DataIsComposite = false; - this.ChildrenInformation = new ArrayList<>(); - } - - int GetNumberOfChildren() { - return this.DataIsMultiPiece ? this.NumberOfPieces : ChildrenInformation.size(); - } - - VTKDataInformation GetDataInformation(int idx) { - if (this.DataIsMultiPiece) { - return null; - } - - if (idx >= ChildrenInformation.size()) { - return null; - } - - return this.ChildrenInformation.get(idx).Info; - } - - String GetName(int idx) { - if (this.DataIsMultiPiece) { - return null; - } - - if (idx >= this.ChildrenInformation.size()) { - return null; - } - - return this.ChildrenInformation.get(idx).Name; - } - - void CopyFromObject(vtkObject object) { - this.Initialize(); - - if (!(object instanceof vtkCompositeDataSet)) { - return; - } - - vtkCompositeDataSet cds = (vtkCompositeDataSet) object; - this.DataIsComposite = true; - - if (object instanceof vtkMultiPieceDataSet) { - vtkMultiPieceDataSet mpDS = (vtkMultiPieceDataSet) object; - this.DataIsMultiPiece = true; - this.NumberOfPieces = mpDS.GetNumberOfPieces(); - return; - } - - if(object instanceof vtkMultiBlockDataSet){ - vtkMultiBlockDataSet mbds = (vtkMultiBlockDataSet) object; - for (int i = 0; i < mbds.GetNumberOfBlocks(); i++) { - VTKDataInformation childInfo = null; - vtkDataObject block = mbds.GetBlock(i); - if (block != null) { - if (block != null) { - childInfo = new VTKDataInformation(); - childInfo.CopyFromObject(block); - } - DataInformation d = new DataInformation(); - d.Info = childInfo; - - vtkInformation info = block.GetInformation(); - if (info.Has(cds.NAME()) != 0) { - d.Name = info.Get(cds.NAME()); - } - -// if (iter.HasCurrentMetaData() != 0) { -// vtkInformation info = iter.GetCurrentMetaData(); -// if (info.Has(cds.NAME()) != 0) { -// d.Name = info.Get(cds.NAME()); -// } -// } - - ChildrenInformation.add(d); - } - } - } - // vtkTimerLog::MarkEndEvent("Copying information from composite data"); - } - - - // void vtkPVCompositeDataInformation::CopyFromAMR(vtkUniformGridAMR* amr) - // { - // unsigned int num_levels = amr.GetNumberOfLevels(); - // if (num_levels == 0) - // { - // this.Internal.ChildrenInformation.clear(); - // } - // else - // { - // this.Internal.ChildrenInformation.resize(num_levels); - // } - // - // // we use this to "simulate" a composite tree from AMR - // vtkNew tempMultiPiece; - // vtkNew tempDSInfo; - // - // for (unsigned int level=0; level < num_levels; level++) - // { - // unsigned int num_datasets = amr.GetNumberOfDataSets(level); - // tempMultiPiece.SetNumberOfPieces(num_datasets); - // - // vtkNew levelInfo; - // levelInfo.CopyFromCompositeDataSetInitialize(tempMultiPiece.GetPointer()); - // - // // now fill up levelInfo with meta-data about arrays. - // for (unsigned int idx=0; idx < num_datasets; idx++) - // { - // vtkUniformGrid* dataset = amr.GetDataSet(level, idx); - // if (dataset) - // { - // tempDSInfo.CopyFromObject(dataset); - // levelInfo.AddInformation(tempDSInfo.GetPointer(), 1); - // } - // } - // levelInfo.CopyFromCompositeDataSetFinalize(tempMultiPiece.GetPointer()); - // this.Internal.ChildrenInformation[level].Info = levelInfo.GetPointer(); - // } - // } - - //Called to merge informations from two processess. - void AddInformation(VTKCompositeDataInformation info) - { - if (info == null) - { - System.err.println("Cound not cast object to data information."); - return; - } - - this.DataIsComposite = info.GetDataIsComposite(); - this.DataIsMultiPiece = info.GetDataIsMultiPiece(); - if (this.DataIsMultiPiece) - { - if (this.NumberOfPieces != info.NumberOfPieces) - { - // vtkWarningMacro("Mismatch in number of pieces among processes."); - } - if (info.NumberOfPieces > this.NumberOfPieces) - { - this.NumberOfPieces = info.NumberOfPieces; - } - return; - } - - int otherNumChildren = info.ChildrenInformation.size(); - int numChildren = this.ChildrenInformation.size(); - if ( otherNumChildren > numChildren) - { - numChildren = otherNumChildren; - //this.ChildrenInformation.resize(numChildren); - } - - for (int i=0; i < otherNumChildren; i++) - { - VTKDataInformation otherInfo = info.ChildrenInformation.get(i).Info; - VTKDataInformation localInfo = this.ChildrenInformation.get(i).Info; - if (otherInfo != null) - { - if (localInfo != null) - { - localInfo.AddInformation(otherInfo); - } - else - { - VTKDataInformation dinf = new VTKDataInformation(); - dinf.AddInformation(otherInfo); - this.ChildrenInformation.get(i).Info = dinf; - } - } - - String otherName = info.ChildrenInformation.get(i).Name; - String localName = this.ChildrenInformation.get(i).Name; - if (!otherName.isEmpty()) - { - if (!localName.isEmpty() && localName != otherName) - { - //vtkWarningMacro("Same block is named as \'" << localName.c_str() - // << "\' as well as \'" << otherName.c_str() << "\'"); - } - localName = otherName; - } - } - } - - // void vtkPVCompositeDataInformation::CopyToStream( - // vtkClientServerStream* css) - // { - // // vtkTimerLog::MarkStartEvent("Copying composite information to stream"); - // css.Reset(); - // *css << vtkClientServerStream::Reply - // << this.DataIsComposite - // << this.DataIsMultiPiece - // << this.NumberOfPieces; - // - // unsigned int numChildren = static_cast( - // this.Internal.ChildrenInformation.size()); - // *css << numChildren; - // - // for(unsigned i=0; i(length)); - // } - // } - // *css << numChildren; // DONE marker - // *css << vtkClientServerStream::End; - // // vtkTimerLog::MarkEndEvent("Copying composite information to stream"); - // } - // - // //---------------------------------------------------------------------------- - // void vtkPVCompositeDataInformation::CopyFromStream( - // const vtkClientServerStream* css) - // { - // this.Initialize(); - // - // if(!css.GetArgument(0, 0, &this.DataIsComposite)) - // { - // vtkErrorMacro("Error parsing data set type."); - // return; - // } - // - // if(!css.GetArgument(0, 1, &this.DataIsMultiPiece)) - // { - // vtkErrorMacro("Error parsing data set type."); - // return; - // } - // - // if(!css.GetArgument(0, 2, &this.NumberOfPieces)) - // { - // vtkErrorMacro("Error parsing number of pieces."); - // return; - // } - // - // unsigned int numChildren; - // if(!css.GetArgument(0, 3, &numChildren)) - // { - // vtkErrorMacro("Error parsing number of children."); - // return; - // } - // int msgIdx = 3; - // this.Internal.ChildrenInformation.resize(numChildren); - // - // while (1) - // { - // msgIdx++; - // unsigned int childIdx; - // if(!css.GetArgument(0, msgIdx, &childIdx)) - // { - // vtkErrorMacro("Error parsing data set type."); - // return; - // } - // if (childIdx >= numChildren) //receiver DONE marker. - // { - // break; - // } - // msgIdx++; - // - // const char* name = 0; - // if (!css.GetArgument(0, msgIdx, &name)) - // { - // vtkErrorMacro("Error parsing the name for the block."); - // return; - // } - // - // vtkTypeUInt32 length; - // std::vector data; - // vtkClientServerStream dcss; - // - // msgIdx++; - // // Data information. - // vtkPVDataInformation* dataInf = vtkPVDataInformation::New(); - // if(!css.GetArgumentLength(0, msgIdx, &length)) - // { - // vtkErrorMacro("Error parsing length of cell data information."); - // dataInf.Delete(); - // return; - // } - // data.resize(length); - // if(!css.GetArgument(0, msgIdx, &*data.begin(), length)) - // { - // vtkErrorMacro("Error parsing cell data information."); - // dataInf.Delete(); - // return; - // } - // dcss.SetData(&*data.begin(), length); - // dataInf.CopyFromStream(&dcss); - // this.Internal.ChildrenInformation[childIdx].Info = dataInf; - // this.Internal.ChildrenInformation[childIdx].Name = name; - // dataInf.Delete(); - // } - // - // } - -} diff --git a/src/eu/engys/vtk/info/VTKConstants.java b/src/eu/engys/vtk/info/VTKConstants.java deleted file mode 100644 index e87614c..0000000 --- a/src/eu/engys/vtk/info/VTKConstants.java +++ /dev/null @@ -1,68 +0,0 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - -package eu.engys.vtk.info; - -public class VTKConstants { - - public static final int VTK_VOID = -1; - public static final int VTK_POLY_DATA = 0; - public static final int VTK_STRUCTURED_POINTS = 1; - public static final int VTK_STRUCTURED_GRID = 2; - public static final int VTK_RECTILINEAR_GRID = 3; - public static final int VTK_UNSTRUCTURED_GRID = 4; - public static final int VTK_PIECEWISE_FUNCTION = 5; - public static final int VTK_IMAGE_DATA = 6; - public static final int VTK_DATA_OBJECT = 7; - public static final int VTK_DATA_SET = 8; - public static final int VTK_POINT_SET = 9; - public static final int VTK_UNIFORM_GRID = 10; - public static final int VTK_COMPOSITE_DATA_SET = 11; - public static final int VTK_MULTIGROUP_DATA_SET = 12; - public static final int VTK_MULTIBLOCK_DATA_SET = 13; - public static final int VTK_HIERARCHICAL_DATA_SET = 14; - public static final int VTK_HIERARCHICAL_BOX_DATA_SET = 15; - public static final int VTK_GENERIC_DATA_SET = 16; - public static final int VTK_HYPER_OCTREE = 17; - public static final int VTK_TEMPORAL_DATA_SET = 18; - public static final int VTK_TABLE = 19; - public static final int VTK_GRAPH = 20; - public static final int VTK_TREE = 21; - public static final int VTK_SELECTION = 22; - public static final int VTK_DIRECTED_GRAPH = 23; - public static final int VTK_UNDIRECTED_GRAPH = 24; - public static final int VTK_MULTIPIECE_DATA_SET = 25; - public static final int VTK_DIRECTED_ACYCLIC_GRAPH = 26; - public static final int VTK_ARRAY_DATA = 27; - public static final int VTK_REEB_GRAPH = 28; - public static final int VTK_UNIFORM_GRID_AMR = 29; - public static final int VTK_NON_OVERLAPPING_AMR = 30; - public static final int VTK_OVERLAPPING_AMR = 31; - public static final int VTK_HYPER_TREE_GRID = 32; - public static final int VTK_MOLECULE = 33; - public static final int VTK_PISTON_DATA_OBJECT = 34; - public static final int VTK_PATH = 35; - -} diff --git a/src/eu/engys/vtk/info/VTKDataInformation.java b/src/eu/engys/vtk/info/VTKDataInformation.java deleted file mode 100644 index 2baac66..0000000 --- a/src/eu/engys/vtk/info/VTKDataInformation.java +++ /dev/null @@ -1,1240 +0,0 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - - -package eu.engys.vtk.info; - -import java.io.PrintStream; - -import vtk.vtkAlgorithm; -import vtk.vtkAlgorithmOutput; -import vtk.vtkCompositeDataSet; -import vtk.vtkDataObject; -import vtk.vtkDataSet; -import vtk.vtkFieldData; -import vtk.vtkGenericDataSet; -import vtk.vtkImageData; -import vtk.vtkInformation; -import vtk.vtkMultiBlockDataSet; -import vtk.vtkObject; -import vtk.vtkPointSet; -import vtk.vtkRectilinearGrid; -import vtk.vtkStructuredGrid; -import vtk.vtkUniformGrid; -import eu.engys.util.Util; - -public class VTKDataInformation { - - private VTKCompositeDataInformation CompositeDataInformation = new VTKCompositeDataInformation(); - private VTKDataSetAttributesInformation PointDataInformation = new VTKDataSetAttributesInformation(); - private VTKDataSetAttributesInformation CellDataInformation = new VTKDataSetAttributesInformation(); - private VTKDataSetAttributesInformation VertexDataInformation = new VTKDataSetAttributesInformation(); - private VTKDataSetAttributesInformation EdgeDataInformation = new VTKDataSetAttributesInformation(); - private VTKDataSetAttributesInformation RowDataInformation = new VTKDataSetAttributesInformation(); - private VTKDataSetAttributesInformation FieldDataInformation = new VTKDataSetAttributesInformation(); - private VTKArrayInformation PointArrayInformation = new VTKArrayInformation(); - - private int CompositeDataSetType, DataSetType, NumberOfPoints, NumberOfCells, NumberOfRows, MemorySize, PolygonCount, NumberOfDataSets, HasTime, PortNumber; - private String DataClassName, TimeLabel, CompositeDataClassName; - private double[] Bounds; - private int[] Extent; - private double Time; - private boolean SortArrays; - - public VTKDataInformation() { - Initialize(); - } - - private void Initialize() { - this.DataSetType = -1; - this.CompositeDataSetType = -1; - this.NumberOfPoints = 0; - this.NumberOfCells = 0; - this.NumberOfRows = 0; - this.NumberOfDataSets = 0; - this.MemorySize = 0; - this.PolygonCount = 0; - this.Bounds = new double[6]; - this.Bounds[0] = this.Bounds[2] = this.Bounds[4] = Double.MAX_VALUE; - this.Bounds[1] = this.Bounds[3] = this.Bounds[5] = -Double.MAX_VALUE; - this.Extent = new int[6]; - this.Extent[0] = this.Extent[2] = this.Extent[4] = Integer.MAX_VALUE; - this.Extent[1] = this.Extent[3] = this.Extent[5] = -Integer.MAX_VALUE; - this.PointDataInformation.Initialize(); - this.CellDataInformation.Initialize(); - this.VertexDataInformation.Initialize(); - this.EdgeDataInformation.Initialize(); - this.RowDataInformation.Initialize(); - this.FieldDataInformation.Initialize(); - this.CompositeDataInformation.Initialize(); - this.PointArrayInformation.Initialize(); - this.DataClassName = ""; - this.CompositeDataClassName = ""; - // this.TimeSpan[0] = VTK_DOUBLE_MAX; - // this.TimeSpan[1] = -VTK_DOUBLE_MAX; - this.HasTime = 0; - this.Time = 0.0; - // this.SetTimeLabel(NULL); - } - - private void DeepCopy(VTKDataInformation dataInfo, boolean copyCompositeInformation) { - - this.DataSetType = dataInfo.DataSetType; - this.CompositeDataSetType = dataInfo.CompositeDataSetType; - this.DataClassName = dataInfo.DataClassName; - this.CompositeDataClassName = dataInfo.CompositeDataClassName; - - this.NumberOfDataSets = dataInfo.NumberOfDataSets; - - this.NumberOfPoints = dataInfo.NumberOfPoints; - this.NumberOfCells = dataInfo.NumberOfCells; - this.NumberOfRows = dataInfo.NumberOfRows; - this.MemorySize = dataInfo.MemorySize; - this.PolygonCount = dataInfo.PolygonCount; - - Util.deepCopy(dataInfo.Bounds, this.Bounds); - Util.deepCopy(dataInfo.Extent, this.Extent); - - // Copy attribute information. - this.PointDataInformation.DeepCopy(dataInfo.PointDataInformation); - this.CellDataInformation.DeepCopy(dataInfo.CellDataInformation); - this.VertexDataInformation.DeepCopy(dataInfo.VertexDataInformation); - this.EdgeDataInformation.DeepCopy(dataInfo.EdgeDataInformation); - this.RowDataInformation.DeepCopy(dataInfo.RowDataInformation); - this.FieldDataInformation.DeepCopy(dataInfo.FieldDataInformation); - if (copyCompositeInformation) { - this.CompositeDataInformation.AddInformation(dataInfo.CompositeDataInformation); - } - this.PointArrayInformation.AddInformation(dataInfo.PointArrayInformation); - - // double *timespan; - // timespan = dataInfo.GetTimeSpan(); - // this.TimeSpan[0] = timespan[0]; - // this.TimeSpan[1] = timespan[1]; - // this.SetTimeLabel(dataInfo.GetTimeLabel()); - } - - public void AddFromMultiBlockDataSet(vtkMultiBlockDataSet data) { - for (int i = 0; i < data.GetNumberOfBlocks(); i++) { - vtkDataObject block = data.GetBlock(i); - if (block != null) { - VTKDataInformation dinf = new VTKDataInformation(); - dinf.CopyFromObject(block); - dinf.DataClassName = block.GetClassName(); - dinf.DataSetType = block.GetDataObjectType(); - this.AddInformation(dinf, true); - block.Delete(); - } - } - - } - - public void CopyFromObject(vtkObject object) { - vtkDataObject dobj = null; - vtkInformation info = null; - // Handle the case where the a vtkAlgorithmOutput is passed instead of - // the data object. vtkSMPart uses vtkAlgorithmOutput. - if (!(object instanceof vtkDataObject)) { - if (object instanceof vtkAlgorithmOutput) { - vtkAlgorithmOutput algOutput = (vtkAlgorithmOutput) object; - vtkAlgorithm producer = algOutput.GetProducer(); - if (producer != null && producer.GetClassName().equals("vtkPVNullSource")) { - // Don't gather any data information from the hypothetical - // null source. - return; - } - - if (producer.IsA("vtkPVPostFilter") == 0) { - algOutput = producer.GetInputConnection(0, 0); - } - info = producer.GetOutputPortInformation(this.PortNumber); - dobj = producer.GetOutputDataObject(algOutput.GetIndex()); - - producer.Delete(); - algOutput.Delete(); - } else if (object instanceof vtkAlgorithm) { - vtkAlgorithm algo = (vtkAlgorithm) object; - // We don't use vtkAlgorithm::GetOutputDataObject() since that - // call a UpdateDataObject() pass, which may raise errors if the - // algo - // is not fully setup yet. - if (algo.GetClassName().equals("vtkPVNullSource")) { - // Don't gather any data information from the hypothetical - // null source. - return; - } - info = algo.GetExecutive().GetOutputInformation(this.PortNumber); - // if (!info || vtkDataObject::GetData(info) == NULL) - // { - // return; - // } - dobj = algo.GetOutputDataObject(this.PortNumber); - algo.Delete(); - } - } else { - dobj = (vtkDataObject) object; - } - - if (object instanceof vtkCompositeDataSet) { - vtkCompositeDataSet cds = (vtkCompositeDataSet) dobj; - this.CopyFromCompositeDataSet(cds); - this.CopyCommonMetaData(cds, info); - return; - } - - if (object instanceof vtkDataSet) { - vtkDataSet ds = (vtkDataSet) dobj; - this.CopyFromDataSet(ds); - this.CopyCommonMetaData(ds, info); - return; - } - - if (object instanceof vtkGenericDataSet) { - vtkGenericDataSet ads = (vtkGenericDataSet) dobj; - this.CopyFromGenericDataSet(ads); - this.CopyCommonMetaData(ads, info); - return; - } - - // vtkGraph* graph = vtkGraph::SafeDownCast(dobj); - // if( graph) - // { - // this.CopyFromGraph(graph); - // this.CopyCommonMetaData(dobj, info); - // return; - // } - // - // vtkTable* table = vtkTable::SafeDownCast(dobj); - // if (table) - // { - // this.CopyFromTable(table); - // this.CopyCommonMetaData(dobj, info); - // return; - // } - // - // vtkSelection* selection = vtkSelection::SafeDownCast(dobj); - // if (selection) - // { - // this.CopyFromSelection(selection); - // this.CopyCommonMetaData(dobj, info); - // return; - // } - // - // String cname = dobj.GetClassName(); - // vtkPVDataInformationHelper *dhelper = - // vtkPVDataInformation::FindHelper - // (cname); - // if (dhelper) - // { - // dhelper.CopyFromDataObject(this, dobj); - // this.CopyCommonMetaData(dobj, info); - // dhelper.Delete(); - // return; - // } - - // Because custom applications may implement their own data - // object types, this isn't an error condition - just - // display the name of the data object and return quietly. - this.DataClassName = dobj.GetClassName(); - this.CopyCommonMetaData(dobj, info); - } - - private void CopyFromCompositeDataSetInitialize(vtkCompositeDataSet data) { - this.Initialize(); - this.CompositeDataInformation.CopyFromObject(data); - } - - private void CopyFromCompositeDataSetFinalize(vtkCompositeDataSet data) { - this.CompositeDataClassName = data.GetClassName(); - this.CompositeDataSetType = data.GetDataObjectType(); - - if (this.DataSetType == -1) { - // This is a composite dataset with no non-empty leaf node. Set some - // data type (Look at BUG #7144). - this.DataClassName = "vtkDataSet"; - this.DataSetType = VTKConstants.VTK_DATA_SET; - } - } - - private void CopyFromCompositeDataSet(vtkCompositeDataSet data) { - this.CopyFromCompositeDataSetInitialize(data); - - int numDataSets = this.CompositeDataInformation.GetNumberOfChildren(); - if (this.CompositeDataInformation.GetDataIsMultiPiece()) { - } else { - for (int cc = 0; cc < numDataSets; cc++) { - VTKDataInformation childInfo = this.CompositeDataInformation.GetDataInformation(cc); - if (childInfo != null) { - this.AddInformation(childInfo, true); - } - } - } - - this.CopyFromCompositeDataSetFinalize(data); - - // AddInformation should have updated NumberOfDataSets correctly to - // count number of non-zero datasets. We don't need to fix it here. - // this.NumberOfDataSets = numDataSets; - } - - private void CopyCommonMetaData(vtkDataObject data, vtkInformation pinfo) { - // Gather some common stuff - // if (pinfo && - // pinfo.Has(vtkStreamingDemandDrivenPipeline::TIME_RANGE())) - // { - // double *times = - // pinfo.Get(vtkStreamingDemandDrivenPipeline::TIME_RANGE()); - // this.TimeSpan[0] = times[0]; - // this.TimeSpan[1] = times[1]; - // } - // - // this.SetTimeLabel( - // (pinfo && - // pinfo.Has(vtkStreamingDemandDrivenPipeline::TIME_LABEL_ANNOTATION())) - // ? - // pinfo.Get(vtkStreamingDemandDrivenPipeline::TIME_LABEL_ANNOTATION()) - // : NULL); - // - // vtkInformation *dinfo = data.GetInformation(); - // if (dinfo.Has(vtkDataObject::DATA_TIME_STEP())) - // { - // double time = dinfo.Get(vtkDataObject::DATA_TIME_STEP()); - // this.Time = time; - // this.HasTime = 1; - // } - } - - private void CopyFromDataSet(vtkDataSet data) { - int idx; - double[] bds = null; - int[] ext = null; - - this.DataClassName = data.GetClassName(); - this.DataSetType = data.GetDataObjectType(); - - this.NumberOfDataSets = 1; - - switch (this.DataSetType) { - case VTKConstants.VTK_IMAGE_DATA: - ext = ((vtkImageData) data).GetExtent(); - break; - case VTKConstants.VTK_STRUCTURED_GRID: - ext = ((vtkStructuredGrid) data).GetExtent(); - break; - case VTKConstants.VTK_RECTILINEAR_GRID: - ext = ((vtkRectilinearGrid) data).GetExtent(); - break; - case VTKConstants.VTK_UNIFORM_GRID: - ext = ((vtkUniformGrid) data).GetExtent(); - break; - case VTKConstants.VTK_UNSTRUCTURED_GRID: - case VTKConstants.VTK_POLY_DATA: - this.PolygonCount = data.GetNumberOfCells(); - break; - } - if (ext != null) { - for (idx = 0; idx < 6; ++idx) { - this.Extent[idx] = ext[idx]; - } - } - - this.NumberOfPoints = data.GetNumberOfPoints(); - if (this.NumberOfPoints == 0) { - return; - } - - // We do not want to get the number of dual cells from an octree - // because this triggers generation of connectivity arrays. - if (data.GetDataObjectType() != VTKConstants.VTK_HYPER_OCTREE) { - this.NumberOfCells = data.GetNumberOfCells(); - } - - bds = data.GetBounds(); - for (idx = 0; idx < 6; ++idx) { - this.Bounds[idx] = bds[idx]; - } - this.MemorySize = data.GetActualMemorySize(); - - if (data instanceof vtkPointSet) { - vtkPointSet ps = (vtkPointSet) data; - if (ps.GetPoints() != null) { - this.PointArrayInformation.CopyFromObject(ps.GetPoints().GetData()); - } - } - - // Copy Point Data information - this.PointDataInformation.CopyFromDataSetAttributes(data.GetPointData()); - - // Copy Cell Data information - this.CellDataInformation.CopyFromDataSetAttributes(data.GetCellData()); - - // Copy Field Data information, if any - vtkFieldData fd = data.GetFieldData(); - if (fd != null && fd.GetNumberOfArrays() > 0) { - this.FieldDataInformation.CopyFromFieldData(fd); - } - } - - private void CopyFromGenericDataSet(vtkGenericDataSet data) { - this.DataClassName = data.GetClassName(); - this.DataSetType = data.GetDataObjectType(); - - this.NumberOfDataSets = 1; - this.NumberOfPoints = data.GetNumberOfPoints(); - if (this.NumberOfPoints == 0) { - return; - } - // We do not want to get the number of dual cells from an octree - // because this triggers generation of connectivity arrays. - if (data.GetDataObjectType() != VTKConstants.VTK_HYPER_OCTREE) { - this.NumberOfCells = data.GetNumberOfCells(-1); - } - - data.GetBounds(this.Bounds); - - this.MemorySize = data.GetActualMemorySize(); - - switch (this.DataSetType) { - case VTKConstants.VTK_POLY_DATA: - this.PolygonCount = data.GetNumberOfCells(2); - break; - } - - // Copy Point Data information - this.PointDataInformation.CopyFromGenericAttributesOnPoints(data.GetAttributes()); - - // Copy Cell Data information - this.CellDataInformation.CopyFromGenericAttributesOnCells(data.GetAttributes()); - } - - public void AddInformation(VTKDataInformation info) { - this.AddInformation(info, false); - } - - private void AddInformation(VTKDataInformation info, boolean addingParts) { - if (info == null) { - System.err.println("Cound not cast object to data information."); - return; - } - - // if (!addingParts) { - // this.SetCompositeDataClassName(info.CompositeDataClassName); - // this.CompositeDataSetType = info.CompositeDataSetType; - // this.CompositeDataInformation.AddInformation(info.CompositeDataInformation); - // } - - if (info.NumberOfDataSets == 0) { - return; - } - - if (this.NumberOfPoints == 0 && this.NumberOfCells == 0 && this.NumberOfDataSets == 0) { - // Just copy the other array information. - this.DeepCopy(info, !addingParts); - return; - } - - // For data set, lets pick the common super class. - // This supports Heterogeneous collections. - // We need a new classification: Structured. - // This would allow extracting grid from mixed structured collections. - if (this.DataSetType != info.DataSetType) { // IsTypeOf method will not - // work here. Must be done - // manually. - if (this.DataSetType == VTKConstants.VTK_IMAGE_DATA || this.DataSetType == VTKConstants.VTK_RECTILINEAR_GRID || this.DataSetType == VTKConstants.VTK_DATA_SET || info.DataSetType == VTKConstants.VTK_IMAGE_DATA || info.DataSetType == VTKConstants.VTK_RECTILINEAR_GRID || info.DataSetType == VTKConstants.VTK_DATA_SET) { - this.DataSetType = VTKConstants.VTK_DATA_SET; - this.DataClassName = "vtkDataSet"; - } else { - if (this.DataSetType == VTKConstants.VTK_GENERIC_DATA_SET || info.DataSetType == VTKConstants.VTK_GENERIC_DATA_SET) { - this.DataSetType = VTKConstants.VTK_GENERIC_DATA_SET; - this.DataClassName = "vtkGenericDataSet"; - } else { - this.DataSetType = VTKConstants.VTK_POINT_SET; - this.DataClassName = "vtkPointSet"; - } - } - } - - // Empty data set? Ignore bounds, extent and array info. - if (info.NumberOfCells == 0 && info.NumberOfPoints == 0) { - return; - } - - // First the easy stuff. - this.NumberOfPoints += info.NumberOfPoints; - this.NumberOfCells += info.NumberOfCells; - this.MemorySize += info.MemorySize; - this.NumberOfRows += info.NumberOfRows; - - switch (this.DataSetType) { - case VTKConstants.VTK_POLY_DATA: - this.PolygonCount += info.NumberOfCells; - break; - } - if (addingParts) { - // Adding data information of parts - this.NumberOfDataSets += info.NumberOfDataSets; - } else { - // Adding data information of 1 part across processors - if (this.CompositeDataClassName != null) { - // Composite data blocks are not distributed across processors. - // Simply add their number. - this.NumberOfDataSets += info.NumberOfDataSets; - } else { - // Simple data blocks are distributed across processors, use - // the largest number (actually, NumberOfDataSets should always - // be 1 since the data information is for a part) - if (this.NumberOfDataSets < info.NumberOfDataSets) { - this.NumberOfDataSets = info.NumberOfDataSets; - } - } - } - - // Bounds are only a little harder. - double[] bds = info.Bounds; - for (int i = 0; i < 3; ++i) { - int j = i * 2; - if (bds[j] < this.Bounds[j]) { - this.Bounds[j] = bds[j]; - } - ++j; - if (bds[j] > this.Bounds[j]) { - this.Bounds[j] = bds[j]; - } - } - - // Extents are only a little harder. - int[] ext = info.Extent; - for (int i = 0; i < 3; ++i) { - int j = i * 2; - if (ext[j] < this.Extent[j]) { - this.Extent[j] = ext[j]; - } - ++j; - if (ext[j] > this.Extent[j]) { - this.Extent[j] = ext[j]; - } - } - - // Now for the messy part, all of the arrays. - this.PointArrayInformation.AddInformation(info.PointArrayInformation); - this.PointDataInformation.AddInformation(info.PointDataInformation); - this.CellDataInformation.AddInformation(info.CellDataInformation); - this.VertexDataInformation.AddInformation(info.VertexDataInformation); - this.EdgeDataInformation.AddInformation(info.EdgeDataInformation); - this.RowDataInformation.AddInformation(info.RowDataInformation); - this.FieldDataInformation.AddInformation(info.FieldDataInformation); - // this.GenericAttributesInformation.AddInformation(info.GetGenericAttributesInformation()); - - // double times = info.GetTimeSpan(); - // if (times[0] < this.TimeSpan[0]) { - // this.TimeSpan[0] = times[0]; - // } - // if (times[1] > this.TimeSpan[1]) { - // this.TimeSpan[1] = times[1]; - // } - // - // if (!this.HasTime && info.GetHasTime()) { - // this.Time = info.GetTime(); - // this.HasTime = 1; - // } - // - // this.SetTimeLabel(info.GetTimeLabel()); - } - - String GetPrettyDataTypeString() { - int dataType = this.DataSetType; - if (this.CompositeDataSetType >= 0) { - dataType = this.CompositeDataSetType; - } - - switch (dataType) { - case VTKConstants.VTK_POLY_DATA: - return "Polygonal Mesh"; - case VTKConstants.VTK_STRUCTURED_POINTS: - return "Image (Uniform Rectilinear Grid)"; - case VTKConstants.VTK_STRUCTURED_GRID: - return "Structured (Curvilinear) Grid"; - case VTKConstants.VTK_RECTILINEAR_GRID: - return "Rectilinear Grid"; - case VTKConstants.VTK_UNSTRUCTURED_GRID: - return "Unstructured Grid"; - case VTKConstants.VTK_PIECEWISE_FUNCTION: - return "Piecewise function"; - case VTKConstants.VTK_IMAGE_DATA: - return "Image (Uniform Rectilinear Grid)"; - case VTKConstants.VTK_DATA_OBJECT: - return "Data Object"; - case VTKConstants.VTK_DATA_SET: - return "Data Set"; - case VTKConstants.VTK_POINT_SET: - return "Point Set"; - case VTKConstants.VTK_UNIFORM_GRID: - return "Image (Uniform Rectilinear Grid) with blanking"; - case VTKConstants.VTK_COMPOSITE_DATA_SET: - return "Composite Dataset"; - case VTKConstants.VTK_MULTIGROUP_DATA_SET: - return "Multi-group Dataset"; - case VTKConstants.VTK_MULTIBLOCK_DATA_SET: - return "Multi-block Dataset"; - case VTKConstants.VTK_HIERARCHICAL_DATA_SET: - return "Hierarchical DataSet (Deprecated)"; - case VTKConstants.VTK_HIERARCHICAL_BOX_DATA_SET: - return "AMR Dataset (Deprecated)"; - case VTKConstants.VTK_NON_OVERLAPPING_AMR: - return "Non-Overlapping AMR Dataset"; - case VTKConstants.VTK_OVERLAPPING_AMR: - return "Overlapping AMR Dataset"; - case VTKConstants.VTK_GENERIC_DATA_SET: - return "Generic Dataset"; - case VTKConstants.VTK_HYPER_OCTREE: - return "Hyper-octree"; - case VTKConstants.VTK_HYPER_TREE_GRID: - return "Hyper-tree Grid"; - case VTKConstants.VTK_TEMPORAL_DATA_SET: - return "Temporal Dataset"; - case VTKConstants.VTK_TABLE: - return "Table"; - case VTKConstants.VTK_GRAPH: - return "Graph"; - case VTKConstants.VTK_TREE: - return "Tree"; - case VTKConstants.VTK_SELECTION: - return "Selection"; - case VTKConstants.VTK_DIRECTED_GRAPH: - return "Directed Graph"; - case VTKConstants.VTK_UNDIRECTED_GRAPH: - return "Undirected Graph"; - case VTKConstants.VTK_MULTIPIECE_DATA_SET: - return "Multi-piece Dataset"; - case VTKConstants.VTK_DIRECTED_ACYCLIC_GRAPH: - return "Directed Acyclic Graph"; - default: - // vtkPVDataInformationHelper *dhelper = - // vtkPVDataInformation::FindHelper - // (this.DataClassName); - // if (dhelper) - // { - // const char *namestr = dhelper.GetPrettyDataTypeString(); - // dhelper.Delete(); - // return namestr; - // } - } - - return "UnknownType"; - } - - int IsDataStructured() { - switch (this.DataSetType) { - case VTKConstants.VTK_IMAGE_DATA: - case VTKConstants.VTK_STRUCTURED_GRID: - case VTKConstants.VTK_RECTILINEAR_GRID: - case VTKConstants.VTK_UNIFORM_GRID: - case VTKConstants.VTK_GENERIC_DATA_SET: - return 1; - } - return 0; - } - - public void PrintSelf(PrintStream os) { - - os.println("PortNumber: " + this.PortNumber); - os.println("DataSetType: " + this.DataSetType); - os.println("CompositeDataSetType: " + this.CompositeDataSetType); - os.println("NumberOfPoints: " + this.NumberOfPoints); - os.println("NumberOfRows: " + this.NumberOfRows); - os.println("NumberOfCells: " + this.NumberOfCells); - os.println("NumberOfDataSets: " + this.NumberOfDataSets); - os.println("MemorySize: " + this.MemorySize); - os.println("PolygonCount: " + this.PolygonCount); - os.println("Bounds: " + this.Bounds[0] + ", " + this.Bounds[1] + ", " + this.Bounds[2] + ", " + this.Bounds[3] + ", " + this.Bounds[4] + ", " + this.Bounds[5]); - os.println("Extent: " + this.Extent[0] + ", " + this.Extent[1] + ", " + this.Extent[2] + ", " + this.Extent[3] + ", " + this.Extent[4] + ", " + this.Extent[5]); - - String indent = " "; - os.println("PointDataInformation "); - this.PointDataInformation.PrintSelf(os, indent); - os.println("CellDataInformation "); - this.CellDataInformation.PrintSelf(os, indent); - os.println("VertexDataInformation"); - this.VertexDataInformation.PrintSelf(os, indent); - os.println("EdgeDataInformation"); - this.EdgeDataInformation.PrintSelf(os, indent); - os.println("RowDataInformation"); - this.RowDataInformation.PrintSelf(os, indent); - os.println("FieldDataInformation "); - this.FieldDataInformation.PrintSelf(os, indent); - os.println("CompositeDataInformation "); - this.CompositeDataInformation.PrintSelf(os, indent); - os.println("PointArrayInformation "); - this.PointArrayInformation.PrintSelf(os, indent); - - os.println("DataClassName: " + (this.DataClassName != null ? this.DataClassName : "(none)")); - os.println("CompositeDataClassName: " + (this.CompositeDataClassName != null ? this.CompositeDataClassName : "(none)")); - - // os.println("TimeSpan: " + this.TimeSpan[0] + ", " + this.TimeSpan[1] - // ); - - if (this.TimeLabel != null) { - os.println("TimeLabel: " + this.TimeLabel); - } - } - - public int getCompositeDataSetType() { - return CompositeDataSetType; - } - - public int getDataSetType() { - return DataSetType; - } - - public int getNumberOfPoints() { - return NumberOfPoints; - } - - public int getNumberOfCells() { - return NumberOfCells; - } - - public int getNumberOfRows() { - return NumberOfRows; - } - - public int getMemorySize() { - return MemorySize; - } - - public int getPolygonCount() { - return PolygonCount; - } - - public double[] getBounds() { - return Bounds; - } - - public int[] getExtent() { - return Extent; - } - - public String getDataClassName() { - return DataClassName; - } - - public String getCompositeDataClassName() { - return CompositeDataClassName; - } - - public int getNumberOfDataSets() { - return NumberOfDataSets; - } - - // String GetDataSetTypeAsString() - // { - // if(this.DataSetType == -1) - // { - // return "UnknownType"; - // } - // else - // { - // return vtkDataObjectTypes::GetClassNameFromTypeId(this.DataSetType); - // } - // } - - // Need to do this manually. - // int DataSetTypeIsA(String type) { - // if (strcmp(type, "vtkDataObject") == 0) { // Every type is of type - // vtkDataObject. - // return 1; - // } - // if (strcmp(type, "vtkDataSet") == 0) { // Every type is of type - // vtkDataObject. - // if (this.DataSetType == VTK_POLY_DATA || this.DataSetType == - // VTK_STRUCTURED_GRID || this.DataSetType == VTK_UNSTRUCTURED_GRID || - // this.DataSetType == VTK_IMAGE_DATA || this.DataSetType == - // VTK_RECTILINEAR_GRID || this.DataSetType == VTK_UNSTRUCTURED_GRID || - // this.DataSetType == VTK_HYPER_TREE_GRID || this.DataSetType == - // VTK_STRUCTURED_POINTS) { - // return 1; - // } - // } - // if (strcmp(type, this.GetDataSetTypeAsString()) == 0) { // If class names - // are the same, then they are of the same type. - // return 1; - // } - // if (strcmp(type, "vtkPointSet") == 0) { - // if (this.DataSetType == VTK_POLY_DATA || this.DataSetType == - // VTK_STRUCTURED_GRID || this.DataSetType == VTK_UNSTRUCTURED_GRID) { - // return 1; - // } - // } - // if (strcmp(type, "vtkStructuredData") == 0) { - // if (this.DataSetType == VTK_IMAGE_DATA || this.DataSetType == - // VTK_STRUCTURED_GRID || this.DataSetType == VTK_RECTILINEAR_GRID) { - // return 1; - // } - // } - // - // return 0; - // } - - // VTKDataInformation GetDataInformationForCompositeIndex(int index) - // { - // if (index == 0) - // { - // (*index)--; - // return this; - // } - // - // (*index)--; - // return - // this.CompositeDataInformation.GetDataInformationForCompositeIndex(index); - // } - - // void CopyToStream(vtkClientServerStream* css) - // { - // css.Reset(); - // *css << vtkClientServerStream::Reply; - // *css << this.DataClassName - // << this.DataSetType - // << this.NumberOfDataSets - // << this.NumberOfPoints - // << this.NumberOfCells - // << this.NumberOfRows - // << this.MemorySize - // << this.PolygonCount - // << this.Time - // << this.HasTime - // << this.TimeLabel - // << vtkClientServerStream::InsertArray(this.Bounds, 6) - // << vtkClientServerStream::InsertArray(this.Extent, 6); - // - // size_t length; - // const unsigned char* data; - // vtkClientServerStream dcss; - // - // this.PointArrayInformation.CopyToStream(&dcss); - // dcss.GetData(&data, &length); - // *css << vtkClientServerStream::InsertArray(data, - // static_cast(length)); - // - // dcss.Reset(); - // - // this.PointDataInformation.CopyToStream(&dcss); - // dcss.GetData(&data, &length); - // *css << vtkClientServerStream::InsertArray(data, - // static_cast(length)); - // - // dcss.Reset(); - // - // this.CellDataInformation.CopyToStream(&dcss); - // dcss.GetData(&data, &length); - // *css << vtkClientServerStream::InsertArray(data, - // static_cast(length)); - // - // dcss.Reset(); - // - // this.VertexDataInformation.CopyToStream(&dcss); - // dcss.GetData(&data, &length); - // *css << vtkClientServerStream::InsertArray(data, - // static_cast(length)); - // - // dcss.Reset(); - // - // this.EdgeDataInformation.CopyToStream(&dcss); - // dcss.GetData(&data, &length); - // *css << vtkClientServerStream::InsertArray(data, - // static_cast(length)); - // - // dcss.Reset(); - // - // this.RowDataInformation.CopyToStream(&dcss); - // dcss.GetData(&data, &length); - // *css << vtkClientServerStream::InsertArray(data, - // static_cast(length)); - // - // *css << this.CompositeDataClassName; - // *css << this.CompositeDataSetType; - // - // dcss.Reset(); - // - // this.CompositeDataInformation.CopyToStream(&dcss); - // dcss.GetData(&data, &length); - // *css << vtkClientServerStream::InsertArray(data, - // static_cast(length)); - // - // dcss.Reset(); - // - // this.FieldDataInformation.CopyToStream(&dcss); - // dcss.GetData(&data, &length); - // *css << vtkClientServerStream::InsertArray(data, - // static_cast(length)); - // - // *css << vtkClientServerStream::InsertArray(this.TimeSpan, 2); - // - // *css << vtkClientServerStream::End; - // } - - // void CopyFromStream(const vtkClientServerStream* css) - // { - // CSS_ARGUMENT_BEGIN(); - // - // const char* dataclassname = 0; - // if (!CSS_GET_NEXT_ARGUMENT(css, 0, &dataclassname)) - // { - // vtkErrorMacro("Error parsing class name of data."); - // return; - // } - // this.SetDataClassName(dataclassname); - // - // if (!CSS_GET_NEXT_ARGUMENT(css, 0, &this.DataSetType)) - // { - // vtkErrorMacro("Error parsing data set type."); - // return; - // } - // if (!CSS_GET_NEXT_ARGUMENT(css, 0, &this.NumberOfDataSets)) - // { - // vtkErrorMacro("Error parsing number of datasets."); - // return; - // } - // if (!CSS_GET_NEXT_ARGUMENT(css, 0, &this.NumberOfPoints)) - // { - // vtkErrorMacro("Error parsing number of points."); - // return; - // } - // if (!CSS_GET_NEXT_ARGUMENT(css, 0, &this.NumberOfCells)) - // { - // vtkErrorMacro("Error parsing number of cells."); - // return; - // } - // if (!CSS_GET_NEXT_ARGUMENT(css, 0, &this.NumberOfRows)) - // { - // vtkErrorMacro("Error parsing number of cells."); - // return; - // } - // if(!CSS_GET_NEXT_ARGUMENT(css, 0, &this.MemorySize)) - // { - // vtkErrorMacro("Error parsing memory size."); - // return; - // } - // if(!CSS_GET_NEXT_ARGUMENT(css, 0, &this.PolygonCount)) - // { - // vtkErrorMacro("Error parsing memory size."); - // return; - // } - // if(!CSS_GET_NEXT_ARGUMENT(css, 0, &this.Time)) - // { - // vtkErrorMacro("Error parsing Time."); - // return; - // } - // if(!CSS_GET_NEXT_ARGUMENT(css, 0, &this.HasTime)) - // { - // vtkErrorMacro("Error parsing has-time."); - // return; - // } - // const char* timeLabel = 0; - // if (!CSS_GET_NEXT_ARGUMENT(css, 0, &timeLabel)) - // { - // vtkErrorMacro("Error parsing time label."); - // return; - // } - // this.SetTimeLabel(timeLabel); - // if(!CSS_GET_NEXT_ARGUMENT2(css, 0, this.Bounds, 6)) - // { - // vtkErrorMacro("Error parsing bounds."); - // return; - // } - // if(!CSS_GET_NEXT_ARGUMENT2(css, 0, this.Extent, 6)) - // { - // vtkErrorMacro("Error parsing extent."); - // return; - // } - // - // vtkTypeUInt32 length; - // std::vector data; - // vtkClientServerStream dcss; - // - // // Point array information. - // if(!css.GetArgumentLength(0, CSS_GET_CUR_INDEX(), &length)) - // { - // vtkErrorMacro("Error parsing length of point data information."); - // return; - // } - // data.resize(length); - // if(!css.GetArgument(0, CSS_GET_CUR_INDEX(), &*data.begin(), length)) - // { - // vtkErrorMacro("Error parsing point data information."); - // return; - // } - // dcss.SetData(&*data.begin(), length); - // this.PointArrayInformation.CopyFromStream(&dcss); - // CSS_GET_CUR_INDEX()++; - // - // // Point data array information. - // if(!css.GetArgumentLength(0, CSS_GET_CUR_INDEX(), &length)) - // { - // vtkErrorMacro("Error parsing length of point data information."); - // return; - // } - // data.resize(length); - // if(!css.GetArgument(0, CSS_GET_CUR_INDEX(), &*data.begin(), length)) - // { - // vtkErrorMacro("Error parsing point data information."); - // return; - // } - // dcss.SetData(&*data.begin(), length); - // this.PointDataInformation.CopyFromStream(&dcss); - // CSS_GET_CUR_INDEX()++; - // - // // Cell data array information. - // if(!css.GetArgumentLength(0, CSS_GET_CUR_INDEX(), &length)) - // { - // vtkErrorMacro("Error parsing length of cell data information."); - // return; - // } - // data.resize(length); - // if(!css.GetArgument(0, CSS_GET_CUR_INDEX(), &*data.begin(), length)) - // { - // vtkErrorMacro("Error parsing cell data information."); - // return; - // } - // dcss.SetData(&*data.begin(), length); - // this.CellDataInformation.CopyFromStream(&dcss); - // CSS_GET_CUR_INDEX()++; - // - // // Vertex data array information. - // if(!css.GetArgumentLength(0, CSS_GET_CUR_INDEX(), &length)) - // { - // vtkErrorMacro("Error parsing length of cell data information."); - // return; - // } - // data.resize(length); - // if(!css.GetArgument(0, CSS_GET_CUR_INDEX(), &*data.begin(), length)) - // { - // vtkErrorMacro("Error parsing cell data information."); - // return; - // } - // dcss.SetData(&*data.begin(), length); - // this.VertexDataInformation.CopyFromStream(&dcss); - // CSS_GET_CUR_INDEX()++; - // - // // Edge data array information. - // if(!css.GetArgumentLength(0, CSS_GET_CUR_INDEX(), &length)) - // { - // vtkErrorMacro("Error parsing length of cell data information."); - // return; - // } - // data.resize(length); - // if(!css.GetArgument(0, CSS_GET_CUR_INDEX(), &*data.begin(), length)) - // { - // vtkErrorMacro("Error parsing cell data information."); - // return; - // } - // dcss.SetData(&*data.begin(), length); - // this.EdgeDataInformation.CopyFromStream(&dcss); - // CSS_GET_CUR_INDEX()++; - // - // // Row data array information. - // if(!css.GetArgumentLength(0, CSS_GET_CUR_INDEX(), &length)) - // { - // vtkErrorMacro("Error parsing length of cell data information."); - // return; - // } - // data.resize(length); - // if(!css.GetArgument(0, CSS_GET_CUR_INDEX(), &*data.begin(), length)) - // { - // vtkErrorMacro("Error parsing cell data information."); - // return; - // } - // dcss.SetData(&*data.begin(), length); - // this.RowDataInformation.CopyFromStream(&dcss); - // CSS_GET_CUR_INDEX()++; - // - // const char* compositedataclassname = 0; - // if(!CSS_GET_NEXT_ARGUMENT(css, 0, &compositedataclassname)) - // { - // vtkErrorMacro("Error parsing class name of data."); - // return; - // } - // this.SetCompositeDataClassName(compositedataclassname); - // - // if(!CSS_GET_NEXT_ARGUMENT(css, 0, &this.CompositeDataSetType)) - // { - // vtkErrorMacro("Error parsing data set type."); - // return; - // } - // - // // Composite data information. - // if(!css.GetArgumentLength(0, CSS_GET_CUR_INDEX(), &length)) - // { - // vtkErrorMacro("Error parsing length of cell data information."); - // return; - // } - // data.resize(length); - // if(!css.GetArgument(0, CSS_GET_CUR_INDEX(), &*data.begin(), length)) - // { - // vtkErrorMacro("Error parsing cell data information."); - // return; - // } - // dcss.SetData(&*data.begin(), length); - // if (dcss.GetNumberOfMessages() > 0) - // { - // this.CompositeDataInformation.CopyFromStream(&dcss); - // } - // else - // { - // this.CompositeDataInformation.Initialize(); - // } - // CSS_GET_CUR_INDEX()++; - // - // // Field data array information. - // if(!css.GetArgumentLength(0, CSS_GET_CUR_INDEX(), &length)) - // { - // vtkErrorMacro("Error parsing length of field data information."); - // return; - // } - // - // data.resize(length); - // if(!css.GetArgument(0, CSS_GET_CUR_INDEX(), &*data.begin(), length)) - // { - // vtkErrorMacro("Error parsing field data information."); - // return; - // } - // dcss.SetData(&*data.begin(), length); - // this.FieldDataInformation.CopyFromStream(&dcss); - // CSS_GET_CUR_INDEX()++; - // - // if(!CSS_GET_NEXT_ARGUMENT2(css, 0, this.TimeSpan, 2)) - // { - // vtkErrorMacro("Error parsing timespan."); - // return; - // } - // - // CSS_ARGUMENT_END(); - // } - - // void SetSortArrays(boolean sort) { - // this.PointDataInformation.SetSortArrays(sort); - // this.CellDataInformation.SetSortArrays(sort); - // this.FieldDataInformation.SetSortArrays(sort); - // } - - // vtkPVDataSetAttributesInformation GetAttributeInformation(int - // fieldAssociation) - // { - // switch (fieldAssociation) - // { - // case vtkDataObject::FIELD_ASSOCIATION_POINTS: - // return this.PointDataInformation; - // - // case vtkDataObject::FIELD_ASSOCIATION_CELLS: - // return this.CellDataInformation; - // - // case vtkDataObject::FIELD_ASSOCIATION_VERTICES: - // return this.VertexDataInformation; - // - // case vtkDataObject::FIELD_ASSOCIATION_EDGES: - // return this.EdgeDataInformation; - // - // case vtkDataObject::FIELD_ASSOCIATION_ROWS: - // return this.RowDataInformation; - // - // case vtkDataObject::FIELD_ASSOCIATION_NONE: - // return this.FieldDataInformation; - // } - // - // return 0; - // } - - // DO NOT USE THIS METHOD, THE ITERATOR HAS MEMORY LEAK PROBLEMS - // public void AddFromCompositeDataSet(vtkCompositeDataSet data) { - // vtkCompositeDataIterator iter = data.NewIterator(); - // int counter = 0; - // for (iter.InitTraversal(); iter.IsDoneWithTraversal() == 0; - // iter.GoToNextItem()) { - // System.out.println("VTKDataInformation.AddFromCompositeDataSet() " + - // counter++); - // // vtkDataObject dobj = iter.GetCurrentDataObject(); - // // if (dobj != null) { - // // VTKDataInformation dinf = new VTKDataInformation(); - // // dinf.CopyFromObject(dobj); - // // dinf.DataClassName = dobj.GetClassName(); - // // dinf.DataSetType = dobj.GetDataObjectType(); - // // this.AddInformation(dinf, true); - // // } - // // dobj.Delete(); - // } - // iter.Delete(); - // } - // void CopyFromSelection(vtkSelection data) { - // this.SetDataClassName(data.GetClassName()); - // this.DataSetType = data.GetDataObjectType(); - // this.NumberOfDataSets = 1; - // - // this.Bounds[0] = this.Bounds[2] = this.Bounds[4] = VTK_DOUBLE_MAX; - // this.Bounds[1] = this.Bounds[3] = this.Bounds[5] = -VTK_DOUBLE_MAX; - // - // this.MemorySize = data.GetActualMemorySize(); - // this.NumberOfCells = 0; - // this.NumberOfPoints = 0; - // - // // Copy Point Data information - // this.PointDataInformation.CopyFromFieldData(data.GetFieldData()); - // } - - // void CopyFromGraph(vtkGraph data) { - // this.SetDataClassName(data.GetClassName()); - // this.DataSetType = data.GetDataObjectType(); - // this.NumberOfDataSets = 1; - // - // this.Bounds[0] = this.Bounds[2] = this.Bounds[4] = VTK_DOUBLE_MAX; - // this.Bounds[1] = this.Bounds[3] = this.Bounds[5] = -VTK_DOUBLE_MAX; - // - // if (data.GetPoints()) - // data.GetPoints().GetBounds(this.Bounds); - // - // this.MemorySize = data.GetActualMemorySize(); - // this.NumberOfCells = data.GetNumberOfEdges(); - // this.NumberOfPoints = data.GetNumberOfVertices(); - // this.NumberOfRows = 0; - // - // this.VertexDataInformation.CopyFromFieldData(data.GetVertexData()); - // this.EdgeDataInformation.CopyFromFieldData(data.GetEdgeData()); - // } - - // void CopyFromTable(vtkTable data) { - // this.SetDataClassName(data.GetClassName()); - // this.DataSetType = data.GetDataObjectType(); - // this.NumberOfDataSets = 1; - // - // this.Bounds[0] = this.Bounds[2] = this.Bounds[4] = VTK_DOUBLE_MAX; - // this.Bounds[1] = this.Bounds[3] = this.Bounds[5] = -VTK_DOUBLE_MAX; - // - // this.MemorySize = data.GetActualMemorySize(); - // this.NumberOfCells = data.GetNumberOfRows() * data.GetNumberOfColumns(); - // this.NumberOfPoints = 0; - // this.NumberOfRows = data.GetNumberOfRows(); - // - // this.RowDataInformation.CopyFromFieldData(data.GetRowData()); - // } - -} diff --git a/src/eu/engys/vtk/info/VTKDataSetAttributesInformation.java b/src/eu/engys/vtk/info/VTKDataSetAttributesInformation.java deleted file mode 100644 index ca0d46f..0000000 --- a/src/eu/engys/vtk/info/VTKDataSetAttributesInformation.java +++ /dev/null @@ -1,371 +0,0 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - - -package eu.engys.vtk.info; - -import java.io.PrintStream; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -import vtk.vtkAbstractArray; -import vtk.vtkDataSetAttributes; -import vtk.vtkFieldData; -import vtk.vtkGenericAttribute; -import vtk.vtkGenericAttributeCollection; - -public class VTKDataSetAttributesInformation { - - private static final int NUM_ATTRIBUTES = 8; - private List ArrayInformation; - private boolean SortArrays; - private int[] AttributeIndices = new int[NUM_ATTRIBUTES]; - - // ---------------------------------------------------------------------------- - public VTKDataSetAttributesInformation() { - this.ArrayInformation = new ArrayList<>(); - for (int idx = 0; idx < NUM_ATTRIBUTES; ++idx) { - this.AttributeIndices[idx] = -1; - } - this.SortArrays = true; - } - - // ---------------------------------------------------------------------------- - void PrintSelf(PrintStream os, String indent) { - - int num = this.GetNumberOfArrays(); - os.println(indent+"ArrayInformation, number of arrays: " + num); - for (int idx = 0; idx < num; ++idx) { - this.ArrayInformation.get(idx).PrintSelf(os, indent+indent); - } - os.println(indent+"SortArrays: " + this.SortArrays); - } - - // ---------------------------------------------------------------------------- - void Initialize() { - this.ArrayInformation.clear(); - for (int idx = 0; idx < NUM_ATTRIBUTES; ++idx) { - this.AttributeIndices[idx] = -1; - } - } - - // ---------------------------------------------------------------------------- - void DeepCopy(VTKDataSetAttributesInformation dataInfo) { - - // Copy array information. - this.ArrayInformation.clear(); - int num = dataInfo.GetNumberOfArrays(); - for (int idx = 0; idx < num; ++idx) { - VTKArrayInformation arrayInfo = dataInfo.ArrayInformation.get(idx); - VTKArrayInformation newArrayInfo = new VTKArrayInformation(); - newArrayInfo.DeepCopy(arrayInfo); - this.ArrayInformation.add(newArrayInfo); - } - // Now the default attributes. - for (int idx = 0; idx < NUM_ATTRIBUTES; ++idx) { - this.AttributeIndices[idx] = dataInfo.AttributeIndices[idx]; - } - } - - // ---------------------------------------------------------------------------- - void CopyFromFieldData(vtkFieldData da) { - // Clear array information. - this.ArrayInformation.clear(); - for (int idx = 0; idx < NUM_ATTRIBUTES; ++idx) { - this.AttributeIndices[idx] = -1; - } - - // Copy Field Data - int num = da.GetNumberOfArrays(); - for (int idx = 0; idx < num; ++idx) { - vtkAbstractArray array = da.GetAbstractArray(idx); - if (array.GetName() != null) { - VTKArrayInformation info = new VTKArrayInformation(); - info.CopyFromObject(array); - this.ArrayInformation.add(info); - } - } - } - - class SortedArray implements Comparable { - - public int arrayIndx; - public String arrayName; - - @Override - public int compareTo(SortedArray o) { - return arrayName.compareTo(o.arrayName); - } - - } - - // ---------------------------------------------------------------------------- - void CopyFromDataSetAttributes(vtkDataSetAttributes da) { - // Clear array information. - this.ArrayInformation.clear(); - for (int idx = 0; idx < NUM_ATTRIBUTES; ++idx) { - this.AttributeIndices[idx] = -1; - } - - // Copy Point Data - int num = da.GetNumberOfArrays(); - - // sort the arrays alphabetically - List sortArrays = new ArrayList<>(); - sortArrays.clear(); - - if (num > 0) { - for (int i = 0; i < num; i++) { - SortedArray sa = new SortedArray(); - sa.arrayIndx = i; - sa.arrayName = da.GetArrayName(i) != null ? da.GetArrayName(i) : ""; - - sortArrays.add(i, sa); - } - - if (this.SortArrays) { - Collections.sort(sortArrays); - } - } - - int infoArrayIndex = 0; - for (SortedArray sa : sortArrays) { - int arrayIndx = sa.arrayIndx; - vtkAbstractArray array = da.GetAbstractArray(arrayIndx); - - if (array.GetName() != null && !array.GetName().equals("vtkGhostLevels") && !array.GetName().equals("vtkOriginalCellIds") && !array.GetName().equals("vtkOriginalPointIds")) { - int attribute = da.IsArrayAnAttribute(arrayIndx); - VTKArrayInformation info = new VTKArrayInformation(); - info.CopyFromObject(array); - this.ArrayInformation.add(info); - // Record default attributes. - if (attribute > -1) { - this.AttributeIndices[attribute] = infoArrayIndex; - } - ++infoArrayIndex; - } - } - - sortArrays.clear(); - } - - private static final int vtkPointCentered = 0; - private static final int vtkCellCentered = 1; - private static final int vtkBoundaryCentered = 2; - - // ---------------------------------------------------------------------------- - void CopyFromGenericAttributesOnPoints(vtkGenericAttributeCollection da) { - - // Clear array information. - this.ArrayInformation.clear(); - for (int idx = 0; idx < 5; ++idx) { - this.AttributeIndices[idx] = -1; - } - - // Copy Point Data - int num = da.GetNumberOfAttributes(); - for (int idx = 0; idx < num; ++idx) { - vtkGenericAttribute array = da.GetAttribute(idx); - if (array.GetCentering() == vtkPointCentered) { - if (array.GetName() != null && (!array.GetName().equals("vtkGhostLevels"))) { - VTKGenericAttributeInformation info = new VTKGenericAttributeInformation(); - info.CopyFromObject(array); - this.ArrayInformation.add(info); - } - } - } - } - - // ---------------------------------------------------------------------------- - void CopyFromGenericAttributesOnCells(vtkGenericAttributeCollection da) { - - // Clear array information. - this.ArrayInformation.clear(); - for (int idx = 0; idx < 5; ++idx) { - this.AttributeIndices[idx] = -1; - } - - // Copy Cell Data - int num = da.GetNumberOfAttributes(); - for (int idx = 0; idx < num; ++idx) { - vtkGenericAttribute array = da.GetAttribute(idx); - if (array.GetCentering() == vtkCellCentered) { - if (array.GetName() != null && (!array.GetName().equals("vtkGhostLevels"))) { - VTKGenericAttributeInformation info = new VTKGenericAttributeInformation(); - info.CopyFromObject(array); - this.ArrayInformation.add(info); - } - } - } - } - - // ---------------------------------------------------------------------------- - void AddInformation(VTKDataSetAttributesInformation info) { - int num1 = this.GetNumberOfArrays(); - int num2 = info.GetNumberOfArrays(); - int[] newAttributeIndices = new int[NUM_ATTRIBUTES]; - - for (int idx1 = 0; idx1 < NUM_ATTRIBUTES; idx1++) { - newAttributeIndices[idx1] = -1; - } - - // First add ranges from all common arrays - for (int idx1 = 0; idx1 < num1; idx1++) { - boolean found = false; - VTKArrayInformation ai1 = this.ArrayInformation.get(idx1); - for (int idx2 = 0; idx2 < num2; idx2++) { - VTKArrayInformation ai2 = info.ArrayInformation.get(idx2); - if (ai1.Compare(ai2)) { - // Take union of range. - ai1.AddRanges(ai2); - found = true; - // Record default attributes. - int attribute1 = this.IsArrayAnAttribute(idx1); - int attribute2 = info.IsArrayAnAttribute(idx2); - if (attribute1 > -1 && attribute1 == attribute2) { - newAttributeIndices[attribute1] = idx1; - } - break; - } - } - if (!found) { - ai1.IsPartial = true; - } - } - - for (int idx1 = 0; idx1 < NUM_ATTRIBUTES; idx1++) { - this.AttributeIndices[idx1] = newAttributeIndices[idx1]; - } - - // Now add arrays that don't exist - for (int idx2 = 0; idx2 < num2; idx2++) { - VTKArrayInformation ai2 = info.ArrayInformation.get(idx2); - boolean found = false; - for (int idx1 = 0; idx1 < this.GetNumberOfArrays(); idx1++) { - VTKArrayInformation ai1 = this.ArrayInformation.get(idx1); - if (ai1.Compare(ai2)) { - found = true; - break; - } - } - if (!found) { - ai2.IsPartial = true; - this.ArrayInformation.add(ai2); - int attribute = info.IsArrayAnAttribute(idx2); - if (attribute > -1 && this.AttributeIndices[attribute] == -1) { - this.AttributeIndices[attribute] = idx2; - } - } - } - } - - // ---------------------------------------------------------------------------- - // void AddInformation(vtkPVInformation info) - // { - // vtkPVDataSetAttributesInformation* p = - // vtkPVDataSetAttributesInformation::SafeDownCast(info); - // if(p) - // { - // this.AddInformation(p); - // } - // else - // { - // vtkErrorMacro("AddInformation called with object of type " - // << (info? info.GetClassName():"")); - // } - // } - - // ---------------------------------------------------------------------------- - void AddInformation(vtkDataSetAttributes da) { - VTKDataSetAttributesInformation info = new VTKDataSetAttributesInformation(); - info.CopyFromDataSetAttributes(da); - this.AddInformation(info); - } - - // ---------------------------------------------------------------------------- - int IsArrayAnAttribute(int arrayIndex) { - int i; - - for (i = 0; i < NUM_ATTRIBUTES; ++i) { - if (this.AttributeIndices[i] == arrayIndex) { - return i; - } - } - return -1; - } - - // ---------------------------------------------------------------------------- - VTKArrayInformation GetAttributeInformation(int attributeType) { - int arrayIdx = this.AttributeIndices[attributeType]; - - if (arrayIdx < 0) { - return null; - } - return this.ArrayInformation.get(arrayIdx); - } - - // ---------------------------------------------------------------------------- - int GetNumberOfArrays() { - return this.ArrayInformation.size(); - } - - // ---------------------------------------------------------------------------- - // int GetMaximumNumberOfTuples() - // { - // VTKArrayInformation info; - // int maxNumVals = 0; - // - // this.ArrayInformation.InitTraversal(); - // while ( (info = static_cast(this.ArrayInformation.GetNextItemAsObject())) ) - // { - // maxNumVals = info.GetNumberOfTuples() > maxNumVals ? info.GetNumberOfTuples() : maxNumVals; - // } - // - // return maxNumVals; - // } - - // ---------------------------------------------------------------------------- - // vtkPVArrayInformation GetArrayInformation(String name) - // { - // vtkPVArrayInformation info; - // - // if (name == NULL) - // { - // return NULL; - // } - // - // this.ArrayInformation.InitTraversal(); - // while ( (info = static_cast(this.ArrayInformation.GetNextItemAsObject())) ) - // { - // if (strcmp(info.GetName(), name) == 0) - // { - // return info; - // } - // } - // return NULL; - // } - -} diff --git a/src/eu/engys/vtk/info/VTKGenericAttributeInformation.java b/src/eu/engys/vtk/info/VTKGenericAttributeInformation.java deleted file mode 100644 index e10c473..0000000 --- a/src/eu/engys/vtk/info/VTKGenericAttributeInformation.java +++ /dev/null @@ -1,54 +0,0 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - - -package eu.engys.vtk.info; - -import vtk.vtkGenericAttribute; - -public class VTKGenericAttributeInformation extends VTKArrayInformation { - - //---------------------------------------------------------------------------- - void CopyFromObject(vtkGenericAttribute array) - { - - this.Name = array.GetName(); - this.DataType = array.GetComponentType(); - this.NumberOfComponents = array.GetNumberOfComponents(); - - if (this.NumberOfComponents > 1) { - this.Ranges = new double[this.NumberOfComponents+1][2]; - // First store range of vector magnitude. - array.GetRange(-1,this.Ranges[0]); - for (int idx = 0; idx < this.NumberOfComponents; idx++) { - array.GetRange(idx, this.Ranges[idx + 1]); - } - } else { - this.Ranges = new double[1][2]; - array.GetRange(0,this.Ranges[0]); - } - } - -} diff --git a/src/eu/engys/vtk/modules/VTK3DModule.java b/src/eu/engys/vtk/modules/VTK3DModule.java new file mode 100644 index 0000000..acaf569 --- /dev/null +++ b/src/eu/engys/vtk/modules/VTK3DModule.java @@ -0,0 +1,70 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.vtk.modules; + +import com.google.inject.AbstractModule; +import com.google.inject.Singleton; + +import eu.engys.gui.view3D.CanvasPanel; +import eu.engys.gui.view3D.Geometry3DController; +import eu.engys.gui.view3D.Mesh3DController; +import eu.engys.gui.view3D.fallback.FallbackGeometry3DController; +import eu.engys.gui.view3D.fallback.FallbackMesh3DController; +import eu.engys.gui.view3D.fallback.FallbackView3D; +import eu.engys.util.VTKSettings; +import eu.engys.vtk.VTKEmptyView3D; +import eu.engys.vtk.VTKGeometry3DController; +import eu.engys.vtk.VTKMesh3DController; +import eu.engys.vtk.VTKView3D; + +public class VTK3DModule extends AbstractModule { + + private boolean no3D; + + public VTK3DModule(Boolean no3D) { + this.no3D = no3D; + } + + @Override + protected void configure() { + if (!VTKSettings.librariesAreLoaded()) { + VTKSettings.LoadAllNativeLibraries(); + } + if (VTKSettings.librariesAreLoaded()) { + if (no3D) { + bind(CanvasPanel.class).to(VTKEmptyView3D.class).in(Singleton.class); + } else { + bind(CanvasPanel.class).to(VTKView3D.class).in(Singleton.class); + } + bind(Geometry3DController.class).to(VTKGeometry3DController.class).in(Singleton.class); + bind(Mesh3DController.class).to(VTKMesh3DController.class).in(Singleton.class); + } else { + bind(CanvasPanel.class).to(FallbackView3D.class).in(Singleton.class); + bind(Geometry3DController.class).to(FallbackGeometry3DController.class).in(Singleton.class); + bind(Mesh3DController.class).to(FallbackMesh3DController.class).in(Singleton.class); + } + } + +} diff --git a/src/eu/engys/vtk/widgets/AxesWidget.java b/src/eu/engys/vtk/widgets/AxesWidget.java index 30ffc35..ef17591 100644 --- a/src/eu/engys/vtk/widgets/AxesWidget.java +++ b/src/eu/engys/vtk/widgets/AxesWidget.java @@ -1,35 +1,34 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.vtk.widgets; +import eu.engys.gui.view3D.RenderPanel; import vtk.vtkAxesActor; import vtk.vtkCaptionActor2D; import vtk.vtkOrientationMarkerWidget; -import eu.engys.gui.view3D.RenderPanel; public class AxesWidget { diff --git a/src/eu/engys/vtk/widgets/AxisWidget.java b/src/eu/engys/vtk/widgets/AxisWidget.java index bb29c71..bd4c5fd 100644 --- a/src/eu/engys/vtk/widgets/AxisWidget.java +++ b/src/eu/engys/vtk/widgets/AxisWidget.java @@ -1,45 +1,47 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.vtk.widgets; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; +import javax.vecmath.Matrix3d; import javax.vecmath.Vector3d; +import eu.engys.core.dictionary.model.EventActionType; +import eu.engys.gui.view3D.RenderPanel; +import eu.engys.util.ui.textfields.DoubleField; +import eu.engys.vtk.VTKRenderPanel; +import vtk.vtkAppendPolyData; import vtk.vtkArrowSource; import vtk.vtkHandleWidget; import vtk.vtkMatrix4x4; import vtk.vtkPolygonalHandleRepresentation3D; +import vtk.vtkSphereSource; import vtk.vtkTransform; import vtk.vtkTransformPolyDataFilter; -import eu.engys.core.dictionary.model.EventActionType; -import eu.engys.gui.view3D.RenderPanel; -import eu.engys.util.ui.textfields.DoubleField; public class AxisWidget { @@ -57,25 +59,43 @@ public class AxisWidget { private PropertyChangeListener listener; private DoubleField[] currentCenter = null; private DoubleField[] currentNormal = null; + private DoubleField currentAngle1 = null; + private DoubleField currentAngle2 = null; private vtkHandleWidget widget; private vtkPolygonalHandleRepresentation3D representation; - private vtkArrowSource arrowSource; + private vtkAppendPolyData append; + private double magnitude; + private int sign; public AxisWidget(RenderPanel renderPanel) { this.renderPanel = renderPanel; - arrowSource = new vtkArrowSource(); + vtkSphereSource sphereSource = new vtkSphereSource(); + sphereSource.SetCenter(0,0,0); + sphereSource.SetRadius(0.1); + sphereSource.SetThetaResolution(24); + sphereSource.SetPhiResolution(24); + sphereSource.Update(); + + vtkArrowSource arrowSource = new vtkArrowSource(); arrowSource.SetShaftResolution(24); // default = 6 arrowSource.SetTipResolution(36); // default = 6 + arrowSource.SetTipLength(0.1); + arrowSource.SetTipRadius(0.1); arrowSource.Update(); + append = new vtkAppendPolyData(); + append.AddInputData(arrowSource.GetOutput()); + append.AddInputData(sphereSource.GetOutput()); + append.Update(); + vtkTransform transform = new vtkTransform(); transform.RotateZ(-90); transform.Update(); vtkTransformPolyDataFilter transformPD = new vtkTransformPolyDataFilter(); transformPD.SetTransform(transform); - transformPD.SetInputData(arrowSource.GetOutput()); + transformPD.SetInputData(append.GetOutput()); transformPD.Update(); representation = new vtkPolygonalHandleRepresentation3D(); @@ -100,23 +120,56 @@ public class AxisWidget { widget.EnabledOff(); widget.Delete(); currentCenter = null; - currentNormal = null; + currentAngle1 = null; + currentAngle2 = null; renderPanel.unlock(); renderPanel.renderLater(); } - public void showAxis(DoubleField[] center, DoubleField[] normal, EventActionType action) { + public void showAxis(DoubleField[] center, DoubleField[] normal, double magnitude, EventActionType action) { renderPanel.lock(); if (action.equals(EventActionType.HIDE)) { widget.EnabledOff(); removeListener(); - currentCenter = null; - currentNormal = null; + this.currentCenter = null; + this.currentAngle1 = null; + this.currentAngle2 = null; + this.currentNormal = null; } else if (action.equals(EventActionType.SHOW)) { removeListener(); - currentCenter = center; - currentNormal = normal; + this.currentCenter = center; + this.currentAngle1 = null; + this.currentAngle2 = null; + this.currentNormal = normal; + this.magnitude = magnitude; changePosition(); + widget.SetCurrentRenderer(((VTKRenderPanel)renderPanel).GetSelectionRenderer()); + widget.EnabledOn(); + addListener(); + } + renderPanel.unlock(); + renderPanel.renderLater(); + } + + public void showAxis(DoubleField[] center, DoubleField angle1, DoubleField angle2, double magnitude, int sign, EventActionType action) { + renderPanel.lock(); + if (action.equals(EventActionType.HIDE)) { + widget.EnabledOff(); + removeListener(); + this.currentCenter = null; + this.currentAngle1 = null; + this.currentAngle2 = null; + this.currentNormal = null; + } else if (action.equals(EventActionType.SHOW)) { + removeListener(); + this.currentCenter = center; + this.currentAngle1 = angle1; + this.currentAngle2 = angle2; + this.currentNormal = null; + this.magnitude = magnitude; + this.sign = sign; + changePosition(); + widget.SetCurrentRenderer(((VTKRenderPanel)renderPanel).GetSelectionRenderer()); widget.EnabledOn(); addListener(); } @@ -126,16 +179,89 @@ public class AxisWidget { private void changePosition() { if (isValid()) { - double[] p1 = new double[] { currentCenter[0].getDoubleValue(), currentCenter[1].getDoubleValue(), currentCenter[2].getDoubleValue() }; - double[] p2 = new double[] { currentCenter[0].getDoubleValue() + currentNormal[0].getDoubleValue(), currentCenter[1].getDoubleValue() + currentNormal[1].getDoubleValue(), currentCenter[2].getDoubleValue() + currentNormal[2].getDoubleValue() }; - transformArrow(p1, p2); + if (currentNormal != null) { + double[] p1 = new double[] { + currentCenter[0].getDoubleValue(), + currentCenter[1].getDoubleValue(), + currentCenter[2].getDoubleValue() }; + double[] p2 = new double[] { + currentCenter[0].getDoubleValue() + magnitude * currentNormal[0].getDoubleValue(), + currentCenter[1].getDoubleValue() + magnitude * currentNormal[1].getDoubleValue(), + currentCenter[2].getDoubleValue() + magnitude * currentNormal[2].getDoubleValue() }; + transformArrow(p1, p2); + } else { +// transformArrow( +// currentCenter[0].getDoubleValue(), +// currentCenter[1].getDoubleValue(), +// currentCenter[2].getDoubleValue(), +// currentAngle1.getDoubleValue(), +// currentAngle2.getDoubleValue(), +// magnitude); + double[] normal = getAxisFromCamberAndToe(currentAngle1.getDoubleValue(), currentAngle2.getDoubleValue(), sign); + double[] p1 = new double[] { + currentCenter[0].getDoubleValue(), + currentCenter[1].getDoubleValue(), + currentCenter[2].getDoubleValue() }; + double[] p2 = new double[] { + currentCenter[0].getDoubleValue() + magnitude * normal[0], + currentCenter[1].getDoubleValue() + magnitude * normal[1], + currentCenter[2].getDoubleValue() + magnitude * normal[2] }; + transformArrow(p1, p2); + } + } } + + public static double[] getAxisFromCamberAndToe(double camber, double toe, int sign) { + /* toe: rotation around Z axis */ + Matrix3d X = new Matrix3d(); + X.rotX(Math.toRadians(sign * camber)); + Matrix3d Y = new Matrix3d(); + Y.setIdentity(); + + /* camber: rotation around X axis */ + Matrix3d Z = new Matrix3d(); + Z.rotZ(Math.toRadians(sign * toe)); + + Matrix3d R = new Matrix3d(); + R.mul(Y, X); + R.mul(Z, R); + + Vector3d axis = new Vector3d(0, -1, 0); + R.transform(axis); + return new double[] {axis.x, axis.y, axis.z}; + } + private boolean isValid() { return currentCenter != null && currentCenter[0].getValue() != null && currentCenter[1].getValue() != null && currentCenter[2].getValue() != null; } + private void transformArrow(double originX, double originY, double originZ, double camber, double toe, double magnitude) { + // Apply the transforms + vtkTransform transform = new vtkTransform(); + transform.PostMultiply(); + transform.Scale(magnitude, magnitude, magnitude); + transform.RotateZ(-90); + + transform.Translate(-originX, -originY-magnitude/2, -originZ); + transform.RotateY(0); + transform.RotateX(sign * camber); + transform.RotateZ(sign * toe); + transform.Translate(originX, originY+magnitude/2, originZ); + + transform.Translate(originX, originY, originZ); + transform.Update(); + + // Transform the polydata + vtkTransformPolyDataFilter transformPD = new vtkTransformPolyDataFilter(); + transformPD.SetTransform(transform); + transformPD.SetInputData(append.GetOutput()); + transformPD.Update(); + + representation.SetHandle(transformPD.GetOutput()); + } + private void transformArrow(double[] startPoint, double[] endPoint) { // Compute a basis Vector3d normalizedX = new Vector3d(); @@ -183,7 +309,7 @@ public class AxisWidget { // Transform the polydata vtkTransformPolyDataFilter transformPD = new vtkTransformPolyDataFilter(); transformPD.SetTransform(transform); - transformPD.SetInputData(arrowSource.GetOutput()); + transformPD.SetInputData(append.GetOutput()); transformPD.Update(); representation.SetHandle(transformPD.GetOutput()); @@ -200,6 +326,12 @@ public class AxisWidget { currentNormal[1].addPropertyChangeListener(listener); currentNormal[2].addPropertyChangeListener(listener); } + if (currentAngle1 != null) { + currentAngle1.addPropertyChangeListener(listener); + } + if (currentAngle2 != null) { + currentAngle2.addPropertyChangeListener(listener); + } } private void removeListener() { @@ -213,5 +345,11 @@ public class AxisWidget { currentNormal[1].removePropertyChangeListener(listener); currentNormal[2].removePropertyChangeListener(listener); } + if (currentAngle1 != null) { + currentAngle1.removePropertyChangeListener(listener); + } + if (currentAngle2 != null) { + currentAngle2.removePropertyChangeListener(listener); + } } } diff --git a/src/eu/engys/vtk/widgets/AxisWidgetManager.java b/src/eu/engys/vtk/widgets/AxisWidgetManager.java index 78bf95d..441d2fd 100644 --- a/src/eu/engys/vtk/widgets/AxisWidgetManager.java +++ b/src/eu/engys/vtk/widgets/AxisWidgetManager.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.vtk.widgets; @@ -51,7 +50,7 @@ public class AxisWidgetManager { widgetMap.clear(); } - public void showPoint(DoubleField[] center, DoubleField[] normal, EventActionType action) { + public void showPoint(DoubleField[] origin, DoubleField[] normal, double magnitude, EventActionType action) { if (action.equals(EventActionType.REMOVE)) { if (widgetMap.containsKey(key)) { AxisWidget w = widgetMap.remove(key); @@ -63,8 +62,24 @@ public class AxisWidgetManager { widgetMap.put(key, widget); } AxisWidget axisWidget = widgetMap.get(key); - axisWidget.showAxis(center, normal, action); + axisWidget.showAxis(origin, normal, magnitude, action); } } + public void showPoint(DoubleField[] origin, DoubleField angle1, DoubleField angle2, double magnitude, int sign, EventActionType action) { + if (action.equals(EventActionType.REMOVE)) { + if (widgetMap.containsKey(key)) { + AxisWidget w = widgetMap.remove(key); + w.clear(); + } + } else { + if (!widgetMap.containsKey(key)) { + AxisWidget widget = new AxisWidget(vtkRendererPanel); + widgetMap.put(key, widget); + } + AxisWidget axisWidget = widgetMap.get(key); + axisWidget.showAxis(origin, angle1, angle2, magnitude, sign, action); + } + } + } diff --git a/src/eu/engys/vtk/widgets/CORWidget.java b/src/eu/engys/vtk/widgets/CORWidget.java deleted file mode 100644 index dbf88a2..0000000 --- a/src/eu/engys/vtk/widgets/CORWidget.java +++ /dev/null @@ -1,125 +0,0 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - - -package eu.engys.vtk.widgets; - -import vtk.vtkActor; -import vtk.vtkAssembly; -import vtk.vtkLineSource; -import vtk.vtkPolyDataMapper; -import eu.engys.core.project.geometry.BoundingBox; -import eu.engys.vtk.VTKRenderPanel; - -public class CORWidget { - - private VTKRenderPanel vtkRendererPanel; - private vtkActor lineX; - private vtkActor lineY; - private vtkActor lineZ; - private vtkAssembly cor; - - public CORWidget(VTKRenderPanel vtkRendererPanel) { - this.vtkRendererPanel = vtkRendererPanel; - cor = new vtkAssembly(); - - lineX = getLine(new double[] {-1, 0, 0}, new double[] {1,0,0}, 1, 1,0,0); - lineY = getLine(new double[] { 0,-1, 0}, new double[] {0,1,0}, 1, 0,1,0); - lineZ = getLine(new double[] { 0, 0,-1}, new double[] {0,0,1}, 1, 0,0,1); - - cor.AddPart(lineX); - cor.AddPart(lineY); - cor.AddPart(lineZ); - cor.UseBoundsOff(); - } - - private vtkActor getLine(double[] p1, double[] p2, float gr, int r, int g, int b) { - - vtkLineSource line = new vtkLineSource(); - - line.SetPoint1(p1[0], p1[1], p1[2]); - line.SetPoint2(p2[0], p2[1], p2[2]); - - - vtkPolyDataMapper mapper = new vtkPolyDataMapper(); - mapper.SetInputData(line.GetOutput()); - - vtkActor axes = new vtkActor(); - - axes.SetMapper(mapper); - axes.GetProperty().SetColor(r, g, b); - axes.GetProperty().SetLineWidth(gr); - - line.Delete(); - mapper.Delete(); - - return axes; - } - - private void updateLine(vtkActor line, double[] start, double[] end) { - //System.out.println("CORWidget.updateLine() start: "+Arrays.toString(start)+", end: "+Arrays.toString(end)); - vtkLineSource source = new vtkLineSource(); - source.SetPoint1(start); - source.SetPoint2(end); - source.Update(); - - vtkPolyDataMapper mapper = (vtkPolyDataMapper) line.GetMapper(); - mapper.SetInputData(source.GetOutput()); - mapper.Update(); - } - - public void update(BoundingBox bb) { - double[] center = vtkRendererPanel.GetRenderer().GetActiveCamera().GetFocalPoint(); - -// System.out.println("CORWidget.update() W: " + bb.getWidth() + ", H: "+bb.getHeight()); -// System.out.println("CORWidget.update() CENTER: " + Arrays.toString(center)); - double deltaX = (bb.getXmax() - bb.getXmin()) / 4; - double deltaY = (bb.getYmax() - bb.getYmin()) / 4; - double deltaZ = (bb.getZmax() - bb.getZmin()) / 4; - - double[] start = new double[] { center[0]-deltaX, center[1], center[2] }; - double[] end = new double[] { center[0]+deltaX, center[1], center[2] }; - updateLine(lineX, start, end); - - start = new double[] { center[0], center[1]-deltaY, center[2] }; - end = new double[] { center[0], center[1]+deltaY, center[2] }; - updateLine(lineY, start, end); - - start = new double[] { center[0], center[1], center[2]-deltaZ }; - end = new double[] { center[0], center[1], center[2]+deltaZ }; - updateLine(lineZ, start, end); - - cor.Modified(); - } - - public void clear() { - - } - - public void on() { -// vtkRendererPanel.addActor(cor); - } - -} diff --git a/src/eu/engys/vtk/widgets/ExtractSelectionWidget.java b/src/eu/engys/vtk/widgets/ExtractSelectionWidget.java index 594595f..bfafffc 100644 --- a/src/eu/engys/vtk/widgets/ExtractSelectionWidget.java +++ b/src/eu/engys/vtk/widgets/ExtractSelectionWidget.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.vtk.widgets; import java.beans.PropertyChangeEvent; @@ -31,9 +30,6 @@ import java.beans.PropertyChangeListener; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import vtk.vtkHandleWidget; -import vtk.vtkPolyData; -import vtk.vtkPolygonalHandleRepresentation3D; import eu.engys.core.dictionary.model.EventActionType; import eu.engys.gui.view3D.CellPicker; import eu.engys.gui.view3D.PickInfo; @@ -42,6 +38,9 @@ import eu.engys.gui.view3D.Selection; import eu.engys.gui.view3D.Selection.SelectionType; import eu.engys.util.progress.ProgressMonitor; import eu.engys.vtk.actions.ExtractSelection; +import vtk.vtkHandleWidget; +import vtk.vtkPolyData; +import vtk.vtkPolygonalHandleRepresentation3D; public class ExtractSelectionWidget implements CellPicker { diff --git a/src/eu/engys/vtk/widgets/LayersCoverageWidget.java b/src/eu/engys/vtk/widgets/LayersCoverageWidget.java index c7e87f2..e93501d 100644 --- a/src/eu/engys/vtk/widgets/LayersCoverageWidget.java +++ b/src/eu/engys/vtk/widgets/LayersCoverageWidget.java @@ -1,136 +1,61 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.vtk.widgets; import java.awt.Component; import java.awt.GridLayout; -import java.io.File; import java.text.DecimalFormat; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.SwingConstants; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import vtk.vtkLookupTable; -import vtk.vtkPolyData; -import vtk.vtkPolyDataReader; import eu.engys.core.dictionary.model.EventActionType; import eu.engys.core.project.Model; import eu.engys.core.project.mesh.FieldItem; import eu.engys.core.project.mesh.FieldItem.DataType; -import eu.engys.gui.view3D.Actor; import eu.engys.gui.view3D.LayerInfo; import eu.engys.gui.view3D.RenderPanel; -import eu.engys.gui.view3D.Representation; import eu.engys.util.progress.ProgressMonitor; -import eu.engys.util.ui.checkboxtree.VisibleItem; import eu.engys.util.ui.textfields.AdaptativeFormat; import eu.engys.vtk.VTKColors; -import eu.engys.vtk.VTKRangeCalculator; -import eu.engys.vtk.actors.DefaultActor; public class LayersCoverageWidget { - class vtkPolyDataWidget { - - private RenderPanel renderPanel; - private Actor actor; - private vtkLookupTable lut; + private static final AdaptativeFormat DOUBLE_FORMATTER = new AdaptativeFormat(new DecimalFormat("0.0##"), new DecimalFormat("0.0##E0"), 3); + private static final DecimalFormat INT_FORMATTER = new DecimalFormat("0"); - public vtkPolyDataWidget(RenderPanel renderPanel) { - this.renderPanel = renderPanel; - - vtkPolyDataReader reader = new vtkPolyDataReader(); - reader.ReadAllFieldsOn(); - reader.ReadAllScalarsOn(); - reader.SetFileName(new File(model.getProject().getBaseDir(), LAYER_INFO_VTK).getAbsolutePath()); - reader.Update(); - - final vtkPolyData layerInfo = reader.GetOutput(); - - this.actor = new DefaultActor("LayersInfo") { - { - newActor(layerInfo, true); - } - @Override - public VisibleItem getVisibleItem() { - return null; - } - @Override - public void setRepresentation(Representation representation) { - super.setRepresentation(Representation.SURFACE); - } - }; - } - - public void update(FieldItem field) { - new VTKRangeCalculator(field).calculateRange_Automatically_For(actor); - lut = new vtkLookupTable(); - VTKColors.applyTypeToLookupTable(field, lut); - this.actor.setScalarColors(lut, field); - } - - private void On() { - renderPanel.addActor(actor); - } - - private void Off() { - renderPanel.removeActor(actor); - } - - public vtkLookupTable getLut() { - return lut; - } - - public void Delete() { - renderPanel.removeActor(actor); - actor.deleteActor(); - lut.Delete(); - } - } - - private static final String LAYER_INFO_VTK = "layerInfo.vtk"; - private static final Logger logger = LoggerFactory.getLogger(LayersCoverageWidget.class); - - private final Model model; private final RenderPanel renderPanel; - private final ProgressMonitor monitor; - private vtkPolyDataWidget widget; - private JPanel colorBar; private LayerInfo layerInfo; + private Model model; public LayersCoverageWidget(Model model, RenderPanel renderPanel, ProgressMonitor monitor) { this.model = model; this.renderPanel = renderPanel; - this.monitor = monitor; } public void activateLayersCoverage(LayerInfo layerInfo, JPanel colorBar, EventActionType action) { @@ -153,7 +78,7 @@ public class LayersCoverageWidget { renderPanel.unlock(); renderPanel.renderLater(); } - + private void hide() { if (widget != null) { widget.Off(); @@ -162,26 +87,22 @@ public class LayersCoverageWidget { private void show() { if (widget == null) { - createWidget(); + widget = new vtkPolyDataWidget(model, renderPanel); } - updateWidget(); - widget.On(); } - + private void updateWidget() { - FieldItem field = new FieldItem(layerInfo.getKey(), DataType.CELL, -1); - if (widget != null) { - widget.update(field); - } + FieldItem field = new FieldItem(layerInfo.getKey(), layerInfo.getKey(), DataType.CELL, -1, widget.getRange(layerInfo.getKey())); + widget.update(field); if (colorBar != null) { colorBar.removeAll(); colorBar.setLayout(new GridLayout(1, 0)); -// colorBar.setLayout(new FlowLayout(SwingConstants.LEFT, 2, 1)); - double[] range = field.getRange(); + // colorBar.setLayout(new FlowLayout(SwingConstants.LEFT, 2, 1)); + double[] range = field.range(); if (layerInfo.isDiscrete()) { - for (int i = (int) range[0]; i<= (int) range[1]; i++) { + for (int i = (int) range[0]; i <= (int) range[1]; i++) { colorBar.add(getLabelForValue(i, INT_FORMATTER.format(i))); } } else { @@ -193,11 +114,8 @@ public class LayersCoverageWidget { } } - private static final AdaptativeFormat DOUBLE_FORMATTER = new AdaptativeFormat(new DecimalFormat("0.0##"), new DecimalFormat("0.0##E0"), 3); - private static final DecimalFormat INT_FORMATTER = new DecimalFormat("0"); - private Component getLabelForValue(double value, String text) { - double[] color = new double[3]; + double[] color = new double[3]; JLabel label = new JLabel(text); label.setHorizontalAlignment(SwingConstants.CENTER); label.setOpaque(true); @@ -207,10 +125,6 @@ public class LayersCoverageWidget { return label; } - private void createWidget() { - widget = new vtkPolyDataWidget(renderPanel); - } - public void clear() { renderPanel.lock(); if (widget != null) { diff --git a/src/eu/engys/vtk/widgets/LogoWidget.java b/src/eu/engys/vtk/widgets/LogoWidget.java index c492c34..9a0a038 100644 --- a/src/eu/engys/vtk/widgets/LogoWidget.java +++ b/src/eu/engys/vtk/widgets/LogoWidget.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.vtk.widgets; @@ -30,14 +29,14 @@ import java.awt.Dimension; import java.nio.file.Path; import java.nio.file.Paths; +import eu.engys.gui.view3D.Interactor; +import eu.engys.gui.view3D.RenderPanel; +import eu.engys.util.ApplicationInfo; import vtk.vtkGenericRenderWindowInteractor; import vtk.vtkImageData; import vtk.vtkLogoRepresentation; import vtk.vtkLogoWidget; import vtk.vtkPNGReader; -import eu.engys.gui.view3D.Interactor; -import eu.engys.gui.view3D.RenderPanel; -import eu.engys.util.ApplicationInfo; public class LogoWidget { diff --git a/src/eu/engys/vtk/widgets/MinMaxPointWidget.java b/src/eu/engys/vtk/widgets/MinMaxPointWidget.java index b06d6de..d31289a 100644 --- a/src/eu/engys/vtk/widgets/MinMaxPointWidget.java +++ b/src/eu/engys/vtk/widgets/MinMaxPointWidget.java @@ -1,37 +1,36 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.vtk.widgets; import javax.vecmath.Point3d; -import vtk.vtkHandleWidget; -import vtk.vtkSphereHandleRepresentation; import eu.engys.gui.events.view3D.VolumeReportVisibilityEvent.Kind; import eu.engys.gui.view3D.RenderPanel; +import vtk.vtkHandleWidget; +import vtk.vtkSphereHandleRepresentation; public class MinMaxPointWidget { diff --git a/src/eu/engys/vtk/widgets/MinMaxPointWidgetManager.java b/src/eu/engys/vtk/widgets/MinMaxPointWidgetManager.java index ff44365..56d8304 100644 --- a/src/eu/engys/vtk/widgets/MinMaxPointWidgetManager.java +++ b/src/eu/engys/vtk/widgets/MinMaxPointWidgetManager.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.vtk.widgets; diff --git a/src/eu/engys/vtk/widgets/PlaneDisplayWidget.java b/src/eu/engys/vtk/widgets/PlaneDisplayWidget.java index be8a497..97ee721 100644 --- a/src/eu/engys/vtk/widgets/PlaneDisplayWidget.java +++ b/src/eu/engys/vtk/widgets/PlaneDisplayWidget.java @@ -1,36 +1,35 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.vtk.widgets; -import vtk.vtkHandleWidget; -import vtk.vtkPlaneSource; -import vtk.vtkPolygonalHandleRepresentation3D; import eu.engys.core.dictionary.model.EventActionType; import eu.engys.gui.view3D.RenderPanel; import eu.engys.util.ui.textfields.DoubleField; +import vtk.vtkHandleWidget; +import vtk.vtkPlaneSource; +import vtk.vtkPolygonalHandleRepresentation3D; public class PlaneDisplayWidget { diff --git a/src/eu/engys/vtk/widgets/PlaneWidget.java b/src/eu/engys/vtk/widgets/PlaneWidget.java index cfbbbbc..8fe0428 100644 --- a/src/eu/engys/vtk/widgets/PlaneWidget.java +++ b/src/eu/engys/vtk/widgets/PlaneWidget.java @@ -1,38 +1,37 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.vtk.widgets; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; -import vtk.vtkPlaneWidget; import eu.engys.core.dictionary.model.EventActionType; import eu.engys.gui.view3D.RenderPanel; import eu.engys.util.ui.textfields.DoubleField; +import vtk.vtkPlaneWidget; public class PlaneWidget { diff --git a/src/eu/engys/vtk/widgets/PlaneWidgetManager.java b/src/eu/engys/vtk/widgets/PlaneWidgetManager.java new file mode 100644 index 0000000..913212a --- /dev/null +++ b/src/eu/engys/vtk/widgets/PlaneWidgetManager.java @@ -0,0 +1,87 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.vtk.widgets; + +import java.util.HashMap; +import java.util.Map; + +import eu.engys.core.dictionary.model.EventActionType; +import eu.engys.util.ui.textfields.DoubleField; +import eu.engys.vtk.VTKRenderPanel; + +public class PlaneWidgetManager { + + private Map widgetMap = new HashMap<>(); + private Map widgetDisplayMap = new HashMap<>(); + private VTKRenderPanel vtkRendererPanel; + + public PlaneWidgetManager(VTKRenderPanel vtkRendererPanel) { + this.vtkRendererPanel = vtkRendererPanel; + } + + public void clear() { + for (PlaneWidget w : widgetMap.values()) { + w.clear(); + } + for (PlaneDisplayWidget w : widgetDisplayMap.values()) { + w.clear(); + } + widgetMap.clear(); + widgetDisplayMap.clear(); + } + + public void showPlane(String key, DoubleField[] origin, DoubleField[] normal, EventActionType action, double diagonal) { + if (action.equals(EventActionType.REMOVE)) { + if (widgetMap.containsKey(key)) { + PlaneWidget w = widgetMap.remove(key); + w.clear(); + } + } else { + if (!widgetMap.containsKey(key)) { + PlaneWidget widget = new PlaneWidget(vtkRendererPanel); + widgetMap.put(key, widget); + } + PlaneWidget pointWidget = widgetMap.get(key); + pointWidget.showPlane(origin, normal, action, diagonal); + } + } + + public void showPlaneDisplay(String key, DoubleField[] origin, DoubleField[] normal, EventActionType action, double diagonal) { + if (action.equals(EventActionType.REMOVE)) { + if (widgetDisplayMap.containsKey(key)) { + PlaneDisplayWidget w = widgetDisplayMap.remove(key); + w.clear(); + } + } else { + if (!widgetDisplayMap.containsKey(key)) { + PlaneDisplayWidget widget = new PlaneDisplayWidget(vtkRendererPanel); + widgetDisplayMap.put(key, widget); + } + PlaneDisplayWidget pointWidget = widgetDisplayMap.get(key); + pointWidget.showPlane(origin, normal, action, diagonal); + } + } + +} diff --git a/src/eu/engys/vtk/widgets/PointWidget.java b/src/eu/engys/vtk/widgets/PointWidget.java index d463171..9c02518 100644 --- a/src/eu/engys/vtk/widgets/PointWidget.java +++ b/src/eu/engys/vtk/widgets/PointWidget.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.vtk.widgets; @@ -30,11 +29,11 @@ import java.awt.Color; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; -import vtk.vtkHandleWidget; -import vtk.vtkSphereHandleRepresentation; import eu.engys.core.dictionary.model.EventActionType; import eu.engys.gui.view3D.RenderPanel; import eu.engys.util.ui.textfields.DoubleField; +import vtk.vtkHandleWidget; +import vtk.vtkSphereHandleRepresentation; public class PointWidget { diff --git a/src/eu/engys/vtk/widgets/PointWidgetManager.java b/src/eu/engys/vtk/widgets/PointWidgetManager.java index 349096c..0367d51 100644 --- a/src/eu/engys/vtk/widgets/PointWidgetManager.java +++ b/src/eu/engys/vtk/widgets/PointWidgetManager.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.vtk.widgets; @@ -50,7 +49,7 @@ public class PointWidgetManager { widgetMap.clear(); } - public void showPoint(DoubleField[] point, String key, EventActionType action, Color color) { + public void showPoint(String key, DoubleField[] point, EventActionType action, Color color) { if (action.equals(EventActionType.REMOVE)) { if (widgetMap.containsKey(key)) { PointWidget w = widgetMap.remove(key); diff --git a/src/eu/engys/vtk/widgets/QualityWidget.java b/src/eu/engys/vtk/widgets/QualityWidget.java index 3835127..1d1100f 100644 --- a/src/eu/engys/vtk/widgets/QualityWidget.java +++ b/src/eu/engys/vtk/widgets/QualityWidget.java @@ -1,68 +1,62 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.vtk.widgets; import java.awt.Color; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; +import java.io.File; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - +import eu.engys.core.dictionary.model.EventActionType; +import eu.engys.core.project.Model; +import eu.engys.gui.view3D.RenderPanel; +import eu.engys.gui.view3D.quality.QualityInfo; +import eu.engys.util.progress.ProgressMonitor; +import eu.engys.vtk.InternalMeshReader; +import eu.engys.vtk.VTKColors; +import eu.engys.vtk.VTKUtil; import vtk.vtkHandleWidget; import vtk.vtkPolyData; import vtk.vtkPolygonalHandleRepresentation3D; import vtk.vtkThreshold; import vtk.vtkUnstructuredGrid; -import eu.engys.core.dictionary.model.EventActionType; -import eu.engys.core.project.Model; -import eu.engys.gui.view3D.QualityInfo; -import eu.engys.gui.view3D.RenderPanel; -import eu.engys.util.progress.ProgressMonitor; -import eu.engys.vtk.VTKColors; -import eu.engys.vtk.VTKOpenFOAMDataset; -import eu.engys.vtk.VTKUtil; public class QualityWidget { - public class QualityListener implements PropertyChangeListener{ + private static final String PROPERTY_NAME = "threshold"; + + public class QualityListener implements PropertyChangeListener { + @Override public void propertyChange(PropertyChangeEvent evt) { - if (evt.getPropertyName().equals("threshold")) { - if (evt.getSource() instanceof QualityInfo) { - updateWidget(); - } + if (evt.getSource() instanceof QualityInfo) { + updateWidget(); } } } - private static final Logger logger = LoggerFactory.getLogger(QualityWidget.class); - - private static final int FIELD_ASSOCIATION_CELLS = 1; - private final Model model; private final RenderPanel renderPanel; private final ProgressMonitor monitor; @@ -93,7 +87,7 @@ public class QualityWidget { renderPanel.unlock(); renderPanel.renderLater(); } - + private void hide() { if (widget != null) { widget.Off(); @@ -107,71 +101,71 @@ public class QualityWidget { if (widget == null) { createWidget(); } - + updateWidget(); - + widget.On(); addListener(); } - + private void setColor(Color color) { double[] d = VTKColors.toVTK(color); representation.GetProperty().SetColor(d); representation.GetSelectedProperty().SetColor(d); } - + private void createWidget() { representation = new vtkPolygonalHandleRepresentation3D(); -// representation.GetProperty().LightingOff(); + // representation.GetProperty().LightingOff(); representation.DragableOff(); representation.PickableOff(); - representation.ActiveRepresentationOff();//MuDeMe! - + representation.ActiveRepresentationOff();// MuDeMe! + widget = new vtkHandleWidget(); renderPanel.getInteractor().addObserver(widget); widget.SetRepresentation(representation); - -// widget.AllowHandleResizeOff(); -// widget.EnableAxisConstraintOff(); -// widget.EnabledOff(); -// widget.ManagesCursorOff(); - widget.ProcessEventsOff();//MuDeMe! -// widget.RemoveAllObservers(); + + // widget.AllowHandleResizeOff(); + // widget.EnableAxisConstraintOff(); + // widget.EnabledOff(); + // widget.ManagesCursorOff(); + widget.ProcessEventsOff();// MuDeMe! + // widget.RemoveAllObservers(); } - private vtkUnstructuredGrid internalMesh; + private vtkUnstructuredGrid internalMeshDataset; private void updateWidget() { - if (internalMesh == null) { + if (internalMeshDataset == null) { loadInternalMesh(); } setColor(currentQualityInfo.getColor()); vtkThreshold threshold = new vtkThreshold(); -// threshold.SetAttributeModeToUseCellData(); - threshold.SetInputData(internalMesh); -// threshold.AllScalarsOff(); - - switch (currentQualityInfo.getMeasure().getTest()) { - case MORE_THAN: - threshold.ThresholdByLower(currentQualityInfo.getThreshold()); - break; - case LESS_THAN: - threshold.ThresholdByUpper(currentQualityInfo.getThreshold()); - break; - default: - System.err.println("ERROR: Threshold not set!"); - break; + // threshold.SetAttributeModeToUseCellData(); + threshold.SetInputData(internalMeshDataset); + // threshold.AllScalarsOff(); + + switch (currentQualityInfo.getMeasure().getType()) { + case MORE_THAN: + threshold.ThresholdByLower(currentQualityInfo.getThreshold()); + break; + case LESS_THAN: + threshold.ThresholdByUpper(currentQualityInfo.getThreshold()); + break; + default: + System.err.println("ERROR: Threshold not set!"); + break; } - + threshold.SetInputArrayToProcess(0, 0, 0, "vtkDataObject::FIELD_ASSOCIATION_CELLS", currentQualityInfo.getMeasure().getFieldName()); threshold.Update(); vtkPolyData dataSet = VTKUtil.geometryFilter(threshold.GetOutput()); - + representation.SetHandle(dataSet); renderPanel.renderLater(); } @@ -180,37 +174,40 @@ public class QualityWidget { monitor.start("Loading internal mesh", false, new Runnable() { @Override public void run() { - VTKOpenFOAMDataset dataset = new VTKOpenFOAMDataset(model, monitor); - dataset.loadInternalMesh(0); + File baseDir = model.getProject().getBaseDir(); + boolean parallal = model.getProject().isParallel(); + InternalMeshReader reader = new InternalMeshReader(baseDir, parallal, monitor); + reader.read(0); + monitor.info("-> Internal Mesh Actor"); - internalMesh = VTKOpenFOAMDataset.shallowCopy(dataset.getInternalMeshDataset()); - - dataset.clear(); + internalMeshDataset = VTKUtil.shallowCopy(reader.getInternalMeshDataset()); + + reader.clear(); monitor.end(); } }); } - + private void addListener() { - if (currentQualityInfo != null && !currentQualityInfo.isListenedBy(listener)) { - currentQualityInfo.addPropertyChangeListener(listener); + if (currentQualityInfo != null && !currentQualityInfo.isListenedBy(PROPERTY_NAME, listener)) { + currentQualityInfo.addPropertyChangeListener(PROPERTY_NAME, listener); } } private void removeListener() { - if (currentQualityInfo != null && currentQualityInfo.isListenedBy(listener)) { - currentQualityInfo.removePropertyChangeListener(listener); + if (currentQualityInfo != null && currentQualityInfo.isListenedBy(PROPERTY_NAME, listener)) { + currentQualityInfo.removePropertyChangeListener(PROPERTY_NAME, listener); } } - + public void clear() { widget = null; representation = null; } private void clearSelection() { - if (representation != null) { + if (representation != null) { representation.SetHandle(new vtkPolyData()); renderPanel.renderLater(); } diff --git a/src/eu/engys/vtk/widgets/fake/FakeClipperWidget.java b/src/eu/engys/vtk/widgets/fake/FakeClipperWidget.java deleted file mode 100644 index 366778b..0000000 --- a/src/eu/engys/vtk/widgets/fake/FakeClipperWidget.java +++ /dev/null @@ -1,55 +0,0 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - -package eu.engys.vtk.widgets.fake; - -import java.awt.event.ActionEvent; - -import javax.swing.AbstractButton; -import javax.swing.Icon; -import javax.swing.JToolBar; - -import eu.engys.util.ui.ResourcesUtil; -import eu.engys.util.ui.UiUtil; -import eu.engys.util.ui.ViewAction; - -public class FakeClipperWidget extends FakeWidget { - - private static final Icon ICON = ResourcesUtil.getIcon("3d.widget.plane.icon"); - - @Override - public void populate(JToolBar toolbar) { - AbstractButton button = UiUtil.createToolBarButton(new ViewAction(ICON, TOOLTIP) { - - @Override - public void actionPerformed(ActionEvent e) { - } - }); - button.setEnabled(false); - components.add(button); - toolbar.add(button); - } - -} diff --git a/src/eu/engys/vtk/widgets/fake/FakeExportImageWidget.java b/src/eu/engys/vtk/widgets/fake/FakeExportImageWidget.java deleted file mode 100644 index 4d41e16..0000000 --- a/src/eu/engys/vtk/widgets/fake/FakeExportImageWidget.java +++ /dev/null @@ -1,55 +0,0 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - -package eu.engys.vtk.widgets.fake; - -import java.awt.event.ActionEvent; - -import javax.swing.AbstractButton; -import javax.swing.Icon; -import javax.swing.JToolBar; - -import eu.engys.util.ui.ResourcesUtil; -import eu.engys.util.ui.UiUtil; -import eu.engys.util.ui.ViewAction; - -public class FakeExportImageWidget extends FakeWidget { - - private static final Icon ICON = ResourcesUtil.getIcon("3d.widget.export.icon"); - - @Override - public void populate(JToolBar toolbar) { - AbstractButton button = UiUtil.createToolBarButton(new ViewAction(ICON, TOOLTIP) { - - @Override - public void actionPerformed(ActionEvent e) { - } - }); - button.setEnabled(false); - components.add(button); - toolbar.add(button); - } - -} diff --git a/src/eu/engys/vtk/widgets/fake/FakeFieldsWidget.java b/src/eu/engys/vtk/widgets/fake/FakeFieldsWidget.java deleted file mode 100644 index d972c6d..0000000 --- a/src/eu/engys/vtk/widgets/fake/FakeFieldsWidget.java +++ /dev/null @@ -1,64 +0,0 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - -package eu.engys.vtk.widgets.fake; - -import static eu.engys.util.ui.UiUtil.createToolBarComboButton; - -import java.awt.event.ActionEvent; -import java.util.ArrayList; -import java.util.List; - -import javax.swing.AbstractAction; -import javax.swing.Action; -import javax.swing.JComboBox; -import javax.swing.JToolBar; - -import eu.engys.core.project.mesh.FieldItem; - -public class FakeFieldsWidget extends FakeWidget { - - private static final String PROTOTYPE = "UWater-Magnitude-Icon"; - - @Override - public void populate(JToolBar toolbar) { - toolbar.addSeparator(); - JComboBox fieldsCombo = createToolBarComboButton(getFieldsActions(new ArrayList()), TOOLTIP, PROTOTYPE, false, true); - fieldsCombo.setEnabled(false); - components.add(fieldsCombo); - toolbar.add(fieldsCombo); - } - - public List getFieldsActions(List fieldItems) { - List actions = new ArrayList<>(); - actions.add(new AbstractAction(FieldItem.SOLID) { - - @Override - public void actionPerformed(ActionEvent e) { - } - }); - return actions; - } -} diff --git a/src/eu/engys/vtk/widgets/fake/FakeRulerWidget.java b/src/eu/engys/vtk/widgets/fake/FakeRulerWidget.java deleted file mode 100644 index 7213305..0000000 --- a/src/eu/engys/vtk/widgets/fake/FakeRulerWidget.java +++ /dev/null @@ -1,55 +0,0 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - -package eu.engys.vtk.widgets.fake; - -import java.awt.event.ActionEvent; - -import javax.swing.AbstractButton; -import javax.swing.Icon; -import javax.swing.JToolBar; - -import eu.engys.util.ui.ResourcesUtil; -import eu.engys.util.ui.UiUtil; -import eu.engys.util.ui.ViewAction; - -public class FakeRulerWidget extends FakeWidget { - - private static final Icon ICON = ResourcesUtil.getIcon("3d.widget.ruler.icon"); - - @Override - public void populate(JToolBar toolbar) { - AbstractButton button = UiUtil.createToolBarButton(new ViewAction(ICON, TOOLTIP) { - - @Override - public void actionPerformed(ActionEvent e) { - } - }); - button.setEnabled(false); - components.add(button); - toolbar.add(button); - } - -} diff --git a/src/eu/engys/vtk/widgets/fake/FakeScalarBarWidget.java b/src/eu/engys/vtk/widgets/fake/FakeScalarBarWidget.java deleted file mode 100644 index 41c37cb..0000000 --- a/src/eu/engys/vtk/widgets/fake/FakeScalarBarWidget.java +++ /dev/null @@ -1,70 +0,0 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - -package eu.engys.vtk.widgets.fake; - -import java.awt.event.ActionEvent; - -import javax.swing.Icon; -import javax.swing.JToggleButton; -import javax.swing.JToolBar; - -import eu.engys.util.ui.ResourcesUtil; -import eu.engys.util.ui.UiUtil; -import eu.engys.util.ui.ViewAction; - -public class FakeScalarBarWidget extends FakeWidget { - - private static final Icon SCALAR_BAR_ICON = ResourcesUtil.getIcon("3d.widget.scalarbar.icon"); - private static final Icon EDIT_SCALAR_BAR_ICON = ResourcesUtil.getIcon("3d.widget.editscalarbar.icon"); - - @Override - public void populate(JToolBar toolbar) { - JToggleButton showButton = UiUtil.createToolBarToggleButton(showAction, true); - JToggleButton editButton = UiUtil.createToolBarToggleButton(editAction, true); - - showButton.setEnabled(false); - editButton.setEnabled(false); - - components.add(showButton); - components.add(editButton); - - toolbar.add(showButton); - toolbar.add(editButton); - - } - - private ViewAction showAction = new ViewAction(null, SCALAR_BAR_ICON, TOOLTIP, false) { - @Override - public void actionPerformed(ActionEvent e) { - } - }; - - private ViewAction editAction = new ViewAction(null, EDIT_SCALAR_BAR_ICON, TOOLTIP, false) { - @Override - public void actionPerformed(ActionEvent e) { - } - }; -} diff --git a/src/eu/engys/vtk/widgets/fake/FakeSelectionWidget.java b/src/eu/engys/vtk/widgets/fake/FakeSelectionWidget.java deleted file mode 100644 index 6d882e8..0000000 --- a/src/eu/engys/vtk/widgets/fake/FakeSelectionWidget.java +++ /dev/null @@ -1,56 +0,0 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - -package eu.engys.vtk.widgets.fake; - -import java.awt.event.ActionEvent; - -import javax.swing.Icon; -import javax.swing.JToggleButton; -import javax.swing.JToolBar; - -import eu.engys.util.ui.ResourcesUtil; -import eu.engys.util.ui.UiUtil; -import eu.engys.util.ui.ViewAction; - -public class FakeSelectionWidget extends FakeWidget { - - private static final Icon ICON = ResourcesUtil.getIcon("3d.widget.feature.icon"); - - @Override - public void populate(JToolBar toolbar) { - JToggleButton button = UiUtil.createToolBarToggleButton(action, true); - button.setEnabled(false); - toolbar.add(button); - components.add(button); - } - - private ViewAction action = new ViewAction(ICON, TOOLTIP) { - @Override - public void actionPerformed(ActionEvent e) { - } - }; - -} diff --git a/src/eu/engys/vtk/widgets/fake/FakeTimeStepsWidget.java b/src/eu/engys/vtk/widgets/fake/FakeTimeStepsWidget.java deleted file mode 100644 index aee6d61..0000000 --- a/src/eu/engys/vtk/widgets/fake/FakeTimeStepsWidget.java +++ /dev/null @@ -1,114 +0,0 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - -package eu.engys.vtk.widgets.fake; - -import static eu.engys.util.ui.UiUtil.createToolBarComboButton; - -import java.awt.event.ActionEvent; -import java.util.Collections; - -import javax.swing.AbstractButton; -import javax.swing.Action; -import javax.swing.Icon; -import javax.swing.JComboBox; -import javax.swing.JToolBar; - -import eu.engys.util.ui.ResourcesUtil; -import eu.engys.util.ui.UiUtil; -import eu.engys.util.ui.ViewAction; - -public class FakeTimeStepsWidget extends FakeWidget { - - private static final String PROTOTYPE = "12345.67"; - - public static final String[] COMPONENTS = new String[] { "Magnitude", "X", "Y", "Z" }; - - public static final Icon PREV_ICON = ResourcesUtil.getIcon("3d.widget.times.prev.icon"); - public static final Icon NEXT_ICON = ResourcesUtil.getIcon("3d.widget.times.next.icon"); - public static final Icon FIRST_ICON = ResourcesUtil.getIcon("3d.widget.times.first.icon"); - public static final Icon LAST_ICON = ResourcesUtil.getIcon("3d.widget.times.last.icon"); - public static final Icon REFRESH_ICON = ResourcesUtil.getIcon("3d.widget.times.refresh.icon"); - - private Action NEXT_STEP = new ViewAction(null, NEXT_ICON, TOOLTIP, false) { - @Override - public void actionPerformed(ActionEvent e) { - } - }; - private Action PREVIOUS_STEP = new ViewAction(null, PREV_ICON, TOOLTIP, false) { - @Override - public void actionPerformed(ActionEvent e) { - } - }; - private Action FIRST_STEP = new ViewAction(null, FIRST_ICON, TOOLTIP, false) { - @Override - public void actionPerformed(ActionEvent e) { - } - }; - private Action LAST_STEP = new ViewAction(null, LAST_ICON, TOOLTIP, false) { - @Override - public void actionPerformed(ActionEvent e) { - } - }; - private Action REFRESH = new ViewAction(null, REFRESH_ICON, TOOLTIP, false) { - @Override - public void actionPerformed(ActionEvent e) { - } - }; - - @Override - public void populate(JToolBar toolbar) { - JComboBox timesCombo = createToolBarComboButton(Collections. emptyList(), TOOLTIP, PROTOTYPE, true, true); - AbstractButton firstButton = UiUtil.createToolBarButton(FIRST_STEP); - AbstractButton previousButton = UiUtil.createToolBarButton(PREVIOUS_STEP); - AbstractButton nextButton = UiUtil.createToolBarButton(NEXT_STEP); - AbstractButton lastButton = UiUtil.createToolBarButton(LAST_STEP); - AbstractButton refreshButton = UiUtil.createToolBarButton(REFRESH); - - timesCombo.setEnabled(false); - firstButton.setEnabled(false); - previousButton.setEnabled(false); - nextButton.setEnabled(false); - lastButton.setEnabled(false); - refreshButton.setEnabled(false); - - toolbar.addSeparator(); - toolbar.add(timesCombo); - toolbar.add(firstButton); - toolbar.add(previousButton); - toolbar.add(nextButton); - toolbar.add(lastButton); - toolbar.add(refreshButton); - toolbar.addSeparator(); - - components.add(timesCombo); - components.add(firstButton); - components.add(previousButton); - components.add(nextButton); - components.add(lastButton); - components.add(refreshButton); - } - -} diff --git a/src/eu/engys/vtk/widgets/fake/FakeWidget.java b/src/eu/engys/vtk/widgets/fake/FakeWidget.java deleted file mode 100644 index dd3fbd6..0000000 --- a/src/eu/engys/vtk/widgets/fake/FakeWidget.java +++ /dev/null @@ -1,118 +0,0 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - -package eu.engys.vtk.widgets.fake; - -import java.util.ArrayList; -import java.util.List; - -import javax.swing.JComponent; - -import eu.engys.gui.view3D.CanvasPanel; -import eu.engys.gui.view3D.widget.Widget; -import eu.engys.gui.view3D.widget.WidgetComponent; - -public abstract class FakeWidget implements Widget { - - protected static final String TOOLTIP = "To enable this feature please contact: info@engys.com"; - - protected List components = new ArrayList(); - - @Override - public void populate(CanvasPanel view3d) { - } - - @Override - public boolean canShow() { - return false; - } - - @Override - public void show() { - disableAll(); - } - - @Override - public void hide() { - disableAll(); - } - - @Override - public void clear() { - disableAll(); - } - - @Override - public void stop() { - disableAll(); - } - - @Override - public WidgetComponent getWidgetComponent() { - return null; - } - - @Override - public void load() { - disableAll(); - } - - @Override - public void applyContext() { - disableAll(); - } - - @Override - public void handleFieldChanged() { - disableAll(); - } - - @Override - public void handleTimeStepChanged() { - disableAll(); - } - - @Override - public void handleNewTimeStepsRead() { - disableAll(); - } - -// @Override -// public void handleInitializeFieldsStarted() { -// disableAll(); -// } -// -// @Override -// public void handleInitializeFieldsFinished() { -// disableAll(); -// } - - private void disableAll() { - for (JComponent c : components) { - c.setEnabled(false); - } - } - -} diff --git a/src/eu/engys/vtk/widgets/panels/BoundingBoxBar.java b/src/eu/engys/vtk/widgets/panels/BoundingBoxBar.java index 1db2b3a..3fe596e 100644 --- a/src/eu/engys/vtk/widgets/panels/BoundingBoxBar.java +++ b/src/eu/engys/vtk/widgets/panels/BoundingBoxBar.java @@ -1,28 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.vtk.widgets.panels; diff --git a/src/eu/engys/vtk/widgets/shapes/BoxWidget.java b/src/eu/engys/vtk/widgets/shapes/BoxWidget.java index 5313015..087d040 100644 --- a/src/eu/engys/vtk/widgets/shapes/BoxWidget.java +++ b/src/eu/engys/vtk/widgets/shapes/BoxWidget.java @@ -1,47 +1,44 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.vtk.widgets.shapes; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; -import vtk.vtkActor; -import vtk.vtkBoxRepresentation; -import vtk.vtkBoxWidget2; -import vtk.vtkTransform; import eu.engys.core.dictionary.model.EventActionType; import eu.engys.gui.view3D.RenderPanel; import eu.engys.util.ui.textfields.DoubleField; +import vtk.vtkBoxRepresentation; +import vtk.vtkBoxWidget2; +import vtk.vtkTransform; public class BoxWidget { private RenderPanel renderPanel; private vtkBoxWidget2 widget; - private vtkActor actor; private BoxFieldListener listener; private DoubleField[] currentPoint1 = null; private DoubleField[] currentPoint2 = null; @@ -55,12 +52,6 @@ public class BoxWidget { vtkTransform trasform = new vtkTransform(); public void run() { - if (actor != null) { - vtkBoxRepresentation rep = (vtkBoxRepresentation) widget.GetRepresentation(); - rep.GetTransform(trasform); - actor.SetUserTransform(trasform); - } - removeListener(); double[] position = widget.GetRepresentation().GetBounds(); if (currentPoint1 != null) { @@ -77,8 +68,7 @@ public class BoxWidget { } }; - public void showBox(vtkActor actor, DoubleField[] point1, DoubleField[] point2, EventActionType action) { - this.actor = actor; + public void showBox(DoubleField[] point1, DoubleField[] point2, EventActionType action) { renderPanel.lock(); if (action.equals(EventActionType.HIDE)) { if (widget != null) { @@ -105,11 +95,7 @@ public class BoxWidget { private void createWidget() { final vtkBoxRepresentation representation = new vtkBoxRepresentation(); representation.SetPlaceFactor(1); - if (actor != null) { - representation.PlaceWidget(actor.GetBounds()); - } else { - representation.PlaceWidget(new double[]{ 0.0,1.0,0.0,1.0,0.0,1.0}); - } + representation.PlaceWidget(new double[]{ 0.0,1.0,0.0,1.0,0.0,1.0}); widget = new vtkBoxWidget2(); renderPanel.getInteractor().addObserver(widget); diff --git a/src/eu/engys/vtk/widgets/shapes/CylinderWidget.java b/src/eu/engys/vtk/widgets/shapes/CylinderWidget.java index d53a666..73a282f 100644 --- a/src/eu/engys/vtk/widgets/shapes/CylinderWidget.java +++ b/src/eu/engys/vtk/widgets/shapes/CylinderWidget.java @@ -1,43 +1,42 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.vtk.widgets.shapes; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; +import eu.engys.core.dictionary.model.EventActionType; +import eu.engys.gui.view3D.RenderPanel; +import eu.engys.util.ui.textfields.DoubleField; import vtk.vtkActor; import vtk.vtkBoxRepresentation; import vtk.vtkBoxWidget2; import vtk.vtkLineSource; import vtk.vtkTransform; import vtk.vtkTubeFilter; -import eu.engys.core.dictionary.model.EventActionType; -import eu.engys.gui.view3D.RenderPanel; -import eu.engys.util.ui.textfields.DoubleField; public class CylinderWidget { diff --git a/src/eu/engys/vtk/widgets/shapes/RotatedBoxWidget.java b/src/eu/engys/vtk/widgets/shapes/RotatedBoxWidget.java new file mode 100644 index 0000000..9f1e876 --- /dev/null +++ b/src/eu/engys/vtk/widgets/shapes/RotatedBoxWidget.java @@ -0,0 +1,238 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ + +package eu.engys.vtk.widgets.shapes; + +import static eu.engys.util.FormatUtil.format; + +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import java.util.Arrays; + +import eu.engys.core.dictionary.model.EventActionType; +import eu.engys.core.project.geometry.BoundingBox; +import eu.engys.gui.view3D.RenderPanel; +import eu.engys.util.ui.textfields.DoubleField; +import vtk.vtkBoxRepresentation; +import vtk.vtkBoxWidget2; +import vtk.vtkPolyData; +import vtk.vtkTransform; + +public class RotatedBoxWidget { + + private RenderPanel renderPanel; + private vtkBoxWidget2 widget; + private BoxFieldListener listener; + private DoubleField[] currentCenter = null; + private DoubleField[] currentDelta = null; + private DoubleField[] currentRotation = null; + + public RotatedBoxWidget(RenderPanel renderPanel) { + this.renderPanel = renderPanel; + listener = new BoxFieldListener(); + } + + final Runnable callback = new Runnable() { + + public void run() { + vtkBoxRepresentation rep = (vtkBoxRepresentation) widget.GetRepresentation(); + vtkTransform trasform = new vtkTransform(); + rep.GetTransform(trasform); + vtkPolyData polyData = new vtkPolyData(); + rep.GetPolyData(polyData); + + System.out.println("CALLBACK pos: " + format(trasform.GetPosition()) + ", rot " + format(trasform.GetOrientation()) + ", scale: " + format(trasform.GetScale())); + + removeListener(); + + System.out.println("CALLBACK bounds: " + Arrays.toString(polyData.GetBounds())); + BoundingBox bb = new BoundingBox(polyData.GetBounds()); + + if (currentCenter != null) { + double[] newCenter = trasform.TransformDoublePoint(bb.getCenter()); + currentCenter[0].setDoubleValue(newCenter[0]); + currentCenter[1].setDoubleValue(newCenter[1]); + currentCenter[2].setDoubleValue(newCenter[2]); + } + if (currentDelta != null) { + double[] scale = trasform.GetScale(); + currentDelta[0].setDoubleValue(scale[0] * bb.getDeltaX()); + currentDelta[1].setDoubleValue(scale[1] * bb.getDeltaY()); + currentDelta[2].setDoubleValue(scale[2] * bb.getDeltaZ()); + } + if (currentRotation != null) { + double[] orientation = trasform.GetOrientation(); + currentRotation[0].setDoubleValue(orientation[0]); + currentRotation[1].setDoubleValue(orientation[1]); + currentRotation[2].setDoubleValue(orientation[2]); + } + addListener(); + } + }; + + public void showBox(DoubleField[] center, DoubleField[] delta, DoubleField[] rotation, EventActionType action) { + renderPanel.lock(); + if (action.equals(EventActionType.HIDE)) { + if (widget != null) { + widget.Off(); + removeListener(); + this.currentCenter = null; + this.currentDelta = null; + this.currentRotation = null; + } + } else if (action.equals(EventActionType.SHOW)) { + removeListener(); + if (widget == null) { + createWidget(); + } + widget.On(); + this.currentCenter = center; + this.currentDelta = delta; + this.currentRotation = rotation; + changePosition(); + addListener(); + } + renderPanel.unlock(); + renderPanel.renderLater(); + } + + private void createWidget() { + vtkBoxRepresentation representation = new vtkBoxRepresentation(); + representation.SetPlaceFactor(1); + + widget = new vtkBoxWidget2(); + widget.AddObserver("EndInteractionEvent", callback, "run"); + renderPanel.getInteractor().addObserver(widget); + + widget.SetRepresentation(representation); +// widget.RotationEnabledOff(); + } + + public void clear() { + removeListener(); + renderPanel.lock(); + if (widget != null) { +// widget.RemoveAllObservers(); + widget.EnabledOff(); + widget.Delete(); + widget = null; + } + this.currentCenter = null; + this.currentDelta = null; + this.currentRotation = null; + renderPanel.unlock(); + renderPanel.renderLater(); + } + + public void hideWidget() { + clear(); + } + + private void changePosition() { + if (currentCenter != null && currentDelta != null && currentRotation != null) { + + double oX = currentCenter[0].getDoubleValue(); + double oY = currentCenter[1].getDoubleValue(); + double oZ = currentCenter[2].getDoubleValue(); + + double dX = currentDelta[0].getDoubleValue(); + double dY = currentDelta[1].getDoubleValue(); + double dZ = currentDelta[2].getDoubleValue(); + + double minX = oX - dX/2; + double maxX = oX + dX/2; + + double minY = oY - dY/2; + double maxY = oY + dY/2; + + double minZ = oZ - dZ/2; + double maxZ = oZ + dZ/2; + + System.out.println(String.format("changePosition() %s %s %s %s %s %s", format(minX).toCents(), format(maxX).toCents(), format(minY).toCents(), format(maxY).toCents(), format(minZ).toCents(), format(maxZ).toCents())); + + vtkBoxRepresentation rep = (vtkBoxRepresentation) widget.GetRepresentation(); + rep.PlaceWidget(new double[] { minX, maxX, minY, maxY, minZ, maxZ }); + if (hasRotation()) { + double rotX = currentRotation[0].getDoubleValue(); + double rotY = currentRotation[1].getDoubleValue(); + double rotZ = currentRotation[2].getDoubleValue(); + vtkTransform t = new vtkTransform(); + t.PostMultiply(); + t.Translate(-oX, -oY, -oZ); + t.RotateY(rotY); + t.RotateX(rotX); + t.RotateZ(rotZ); + t.Translate(oX, oY, oZ); + rep.SetTransform(t); + } else { + vtkTransform t = new vtkTransform(); + rep.SetTransform(t); + } + } + } + + private boolean hasRotation() { + return currentRotation[0].getDoubleValue() != 0 || currentRotation[1].getDoubleValue() != 0 || currentRotation[2].getDoubleValue() != 0; + } + + private void addListener() { + addListener(currentCenter); + addListener(currentDelta); + addListener(currentRotation); + } + + private void removeListener() { + removeListener(currentCenter); + removeListener(currentDelta); + removeListener(currentRotation); + } + + private void addListener(DoubleField[] d) { + if (d != null) { + d[0].addPropertyChangeListener(listener); + d[1].addPropertyChangeListener(listener); + d[2].addPropertyChangeListener(listener); + } + } + + private void removeListener(DoubleField[] d) { + if (d != null) { + d[0].removePropertyChangeListener(listener); + d[1].removePropertyChangeListener(listener); + d[2].removePropertyChangeListener(listener); + } + } + + private final class BoxFieldListener implements PropertyChangeListener { + @Override + public void propertyChange(PropertyChangeEvent evt) { + if (evt.getPropertyName().equals("value")) { + changePosition(); + renderPanel.renderLater(); + } + } + } + +} diff --git a/src/eu/engys/vtk/widgets/shapes/SphereWidget.java b/src/eu/engys/vtk/widgets/shapes/SphereWidget.java index 034da8a..0d684e4 100644 --- a/src/eu/engys/vtk/widgets/shapes/SphereWidget.java +++ b/src/eu/engys/vtk/widgets/shapes/SphereWidget.java @@ -1,41 +1,40 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package eu.engys.vtk.widgets.shapes; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; +import eu.engys.core.dictionary.model.EventActionType; +import eu.engys.gui.view3D.RenderPanel; +import eu.engys.util.ui.textfields.DoubleField; import vtk.vtkActor; import vtk.vtkBoxRepresentation; import vtk.vtkBoxWidget2; import vtk.vtkTransform; -import eu.engys.core.dictionary.model.EventActionType; -import eu.engys.gui.view3D.RenderPanel; -import eu.engys.util.ui.textfields.DoubleField; public class SphereWidget { diff --git a/src/eu/engys/vtk/widgets/vtkCORWidget.java b/src/eu/engys/vtk/widgets/vtkCORWidget.java new file mode 100644 index 0000000..d5528f1 --- /dev/null +++ b/src/eu/engys/vtk/widgets/vtkCORWidget.java @@ -0,0 +1,160 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ + +package eu.engys.vtk.widgets; + +import eu.engys.core.project.geometry.BoundingBox; +import eu.engys.gui.view3D.RenderPanel; +import vtk.vtkActor; +import vtk.vtkAppendPolyData; +import vtk.vtkAssembly; +import vtk.vtkLineSource; +import vtk.vtkPolyData; +import vtk.vtkPolyDataMapper; + +public class vtkCORWidget { + + private RenderPanel renderPanel; + private vtkActor lineX; + private vtkActor lineY; + private vtkActor lineZ; + private vtkAssembly cor; + + public vtkCORWidget(RenderPanel renderPanel) { + this.renderPanel = renderPanel; + cor = new vtkAssembly(); + + lineX = getLine(new double[] {-1, 0, 0}, new double[] {1,0,0}, 1, 1,0,0); + lineY = getLine(new double[] { 0,-1, 0}, new double[] {0,1,0}, 1, 0,1,0); + lineZ = getLine(new double[] { 0, 0,-1}, new double[] {0,0,1}, 1, 0,0,1); + + cor.AddPart(lineX); + cor.AddPart(lineY); + cor.AddPart(lineZ); + cor.UseBoundsOff(); + } + + public static vtkPolyData createDataSet() { + vtkAppendPolyData append = new vtkAppendPolyData(); + append.AddInputData(createLineDataSet(new double[] {-1, 0, 0}, new double[] {1,0,0})); + append.AddInputData(createLineDataSet(new double[] { 0,-1, 0}, new double[] {0,1,0})); + append.AddInputData(createLineDataSet(new double[] { 0, 0,-1}, new double[] {0,0,1})); + append.Update(); + + return append.GetOutput(); + } + + private static vtkPolyData createLineDataSet(double[] p1, double[] p2) { + vtkLineSource line = new vtkLineSource(); + line.SetPoint1(p1[0], p1[1], p1[2]); + line.SetPoint2(p2[0], p2[1], p2[2]); + line.Update(); + + return line.GetOutput(); + } + + private vtkActor getLine(double[] p1, double[] p2, float gr, int r, int g, int b) { + + vtkPolyData lineDataSet = createLineDataSet(p1, p2); + + vtkPolyDataMapper mapper = new vtkPolyDataMapper(); + mapper.SetInputData(lineDataSet); + mapper.SetResolveCoincidentTopologyToShiftZBuffer(); + mapper.SetResolveCoincidentTopologyZShift(0.0001); + + vtkActor axes = new vtkActor(); + + axes.SetMapper(mapper); + axes.GetProperty().SetColor(r, g, b); + axes.GetProperty().SetLineWidth(gr); + + lineDataSet.Delete(); + mapper.Delete(); + + return axes; + } + + private void updateLine(vtkActor line, double[] start, double[] end) { + //System.out.println("CORWidget.updateLine() start: "+Arrays.toString(start)+", end: "+Arrays.toString(end)); + vtkLineSource source = new vtkLineSource(); + source.SetPoint1(start); + source.SetPoint2(end); + source.Update(); + + vtkPolyDataMapper mapper = (vtkPolyDataMapper) line.GetMapper(); + mapper.SetInputData(source.GetOutput()); + mapper.Update(); + } + + public void update(BoundingBox bb) { + double[] center = renderPanel.getInteractor().getCenter(); +// double[] center = renderPanel.GetRenderer().GetActiveCamera().GetFocalPoint(); +// double[] center = GetDefaultRenderer().GetActiveCamera().GetFocalPoint(); + +// System.out.println("CORWidget.update() W: " + bb.getWidth() + ", H: "+bb.getHeight()); +// System.out.println("CORWidget.update() CENTER: " + Arrays.toString(center)); + double deltaX = bb != null ? (bb.getXmax() - bb.getXmin()) / 4 : 1; + double deltaY = bb != null ? (bb.getYmax() - bb.getYmin()) / 4 : 1; + double deltaZ = bb != null ? (bb.getZmax() - bb.getZmin()) / 4 : 1; + + double[] start = new double[] { center[0]-deltaX, center[1], center[2] }; + double[] end = new double[] { center[0]+deltaX, center[1], center[2] }; + updateLine(lineX, start, end); + + start = new double[] { center[0], center[1]-deltaY, center[2] }; + end = new double[] { center[0], center[1]+deltaY, center[2] }; + updateLine(lineY, start, end); + + start = new double[] { center[0], center[1], center[2]-deltaZ }; + end = new double[] { center[0], center[1], center[2]+deltaZ }; + updateLine(lineZ, start, end); + + renderPanel.renderLater(); + } + + public void clear() { + + } + +// public void activateSelection(EventActionType action) { +// if (action.equals(EventActionType.HIDE)) { +// hide(); +// } else if (action.equals(EventActionType.SHOW)) { +// show(); +// } else if (action.equals(EventActionType.REMOVE)) { +//// clearSelection(); +// } +// renderPanel.renderLater(); +// } + + public void On() { + renderPanel.addActor(cor); + } + + public void Off() { + renderPanel.removeActor(cor); + } + +} diff --git a/src/eu/engys/vtk/widgets/vtkPolyDataWidget.java b/src/eu/engys/vtk/widgets/vtkPolyDataWidget.java new file mode 100644 index 0000000..b64278f --- /dev/null +++ b/src/eu/engys/vtk/widgets/vtkPolyDataWidget.java @@ -0,0 +1,112 @@ +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ +package eu.engys.vtk.widgets; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; + +import eu.engys.core.project.Model; +import eu.engys.core.project.mesh.FieldItem; +import eu.engys.gui.view3D.Actor; +import eu.engys.gui.view3D.RenderPanel; +import eu.engys.gui.view3D.Representation; +import eu.engys.util.ui.checkboxtree.VisibleItem; +import eu.engys.vtk.VTKColors; +import eu.engys.vtk.VTKUtil; +import eu.engys.vtk.actors.DefaultActor; +import vtk.vtkDataSet; +import vtk.vtkLookupTable; +import vtk.vtkPolyData; +import vtk.vtkPolyDataReader; + +public class vtkPolyDataWidget { + + private static final String LAYER_INFO_VTK = "layerInfo.vtk"; + + private RenderPanel renderPanel; + private Actor actor; + private vtkLookupTable lut; + + private vtkPolyData layerInfo; + + public vtkPolyDataWidget(Model model, RenderPanel renderPanel) { + this.renderPanel = renderPanel; + + vtkPolyDataReader reader = new vtkPolyDataReader(); + reader.ReadAllFieldsOn(); + reader.ReadAllScalarsOn(); + reader.SetFileName(new File(model.getProject().getBaseDir(), LAYER_INFO_VTK).getAbsolutePath()); + reader.Update(); + + layerInfo = reader.GetOutput(); + + this.actor = new DefaultActor("LayersInfo") { + { + newActor(layerInfo, true); + } + + @Override + public VisibleItem getVisibleItem() { + return null; + } + + @Override + public void setRepresentation(Representation representation) { + super.setRepresentation(Representation.SURFACE); + } + }; + } + + public void update(FieldItem field) { + lut = new vtkLookupTable(); + VTKColors.applyTypeToLookupTable(field, lut); + this.actor.setScalarColors(lut, field); + } + + public void On() { + renderPanel.addActor(actor); + } + + public void Off() { + renderPanel.removeActor(actor); + } + + public vtkLookupTable getLut() { + return lut; + } + + public void Delete() { + renderPanel.removeActor(actor); + actor.deleteActor(); + lut.Delete(); + } + + public double[] getRange(String fieldName) { + List dataset = new ArrayList<>(); + dataset.add(layerInfo); + return VTKUtil.getCellFieldsRanges(dataset).get(fieldName)[0]; + } +} diff --git a/src/vtk/vtkPanel.java b/src/vtk/vtkPanel.java index 56d319a..45e4e18 100644 --- a/src/vtk/vtkPanel.java +++ b/src/vtk/vtkPanel.java @@ -1,29 +1,27 @@ -/*--------------------------------*- Java -*---------------------------------*\ - | o | - | o o | HelyxOS: The Open Source GUI for OpenFOAM | - | o O o | Copyright (C) 2012-2016 ENGYS | - | o o | http://www.engys.com | - | o | | - |---------------------------------------------------------------------------| - | License | - | This file is part of HelyxOS. | - | | - | HelyxOS is free software; you can redistribute it and/or modify it | - | under the terms of the GNU General Public License as published by the | - | Free Software Foundation; either version 2 of the License, or (at your | - | option) any later version. | - | | - | HelyxOS 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 General Public License | - | for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with HelyxOS; if not, write to the Free Software Foundation, | - | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | -\*---------------------------------------------------------------------------*/ - - +/******************************************************************************* + * | o | + * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | + * | o O o | Copyright (C) 2012-2016 ENGYS | + * | o o | http://www.engys.com | + * | o | | + * |---------------------------------------------------------------------------| + * | License | + * | This file is part of HELYX-OS. | + * | | + * | HELYX-OS is free software; you can redistribute it and/or modify it | + * | under the terms of the GNU General Public License as published by the | + * | Free Software Foundation; either version 2 of the License, or (at your | + * | option) any later version. | + * | | + * | HELYX-OS 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 General Public License | + * | for more details. | + * | | + * | You should have received a copy of the GNU General Public License | + * | along with HELYX-OS; if not, write to the Free Software Foundation, | + * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | + *******************************************************************************/ package vtk; import java.awt.Canvas;