From 9f4d56a18750e8d5622b5891c6fc05ecee2fe36a Mon Sep 17 00:00:00 2001 From: Miia Rantala Date: Wed, 30 Aug 2017 12:40:15 +0300 Subject: [PATCH] New sewage system modelling features for the mapping tool. Change-Id: I275e90bd2fe3a15a65ffd22eb96fd3c83e5c25ae --- .../district/imports/ui/CSVImportModel.java | 9 ++ .../district/imports/ui/CSVImportWizard.java | 10 ++ .../imports/ui/CSVImportWizardPage.java | 19 ++- .../graph/DistrictNetwork.pgraph | 11 ++ .../Simantics/District/ComponentMapping.scl | 1 + .../ontology/DistrictNetworkResource.java | 18 +++ .../fragment.e4xmi | 6 + .../SimplifyPointVerticesHandler.java | 50 +++++++ .../SimplifySewageVerticesHandler.java | 141 ++++++++++++++++++ 9 files changed, 264 insertions(+), 1 deletion(-) create mode 100644 org.simantics.district.network.ui/src/org/simantics/district/network/ui/contributions/SimplifyPointVerticesHandler.java create mode 100644 org.simantics.district.network.ui/src/org/simantics/district/network/ui/contributions/SimplifySewageVerticesHandler.java diff --git a/org.simantics.district.imports.ui/src/org/simantics/district/imports/ui/CSVImportModel.java b/org.simantics.district.imports.ui/src/org/simantics/district/imports/ui/CSVImportModel.java index 2f13692b..eb27ebc1 100644 --- a/org.simantics.district.imports.ui/src/org/simantics/district/imports/ui/CSVImportModel.java +++ b/org.simantics.district.imports.ui/src/org/simantics/district/imports/ui/CSVImportModel.java @@ -47,6 +47,7 @@ public class CSVImportModel { private int diameterIndex; private int outerDiamterIndex; private int nominalMassFlowIndex; + private int sewageProductionIndex; // Third page @@ -275,5 +276,13 @@ public class CSVImportModel { public int getNominalMassFlowIndex() { return nominalMassFlowIndex; } + + public void setSewageProductionIndex(int sewageProductionIndex) { + this.sewageProductionIndex = sewageProductionIndex; + } + + public int getSewageProductionIndex() { + return sewageProductionIndex; + } } diff --git a/org.simantics.district.imports.ui/src/org/simantics/district/imports/ui/CSVImportWizard.java b/org.simantics.district.imports.ui/src/org/simantics/district/imports/ui/CSVImportWizard.java index 703ade17..c6b4ba16 100644 --- a/org.simantics.district.imports.ui/src/org/simantics/district/imports/ui/CSVImportWizard.java +++ b/org.simantics.district.imports.ui/src/org/simantics/district/imports/ui/CSVImportWizard.java @@ -69,6 +69,7 @@ public class CSVImportWizard extends Wizard implements IImportWizard { int zCoordColumnIndex = model.getZCoordIndex(); int tempColumnIndex = model.getTempIndex(); int pressureColumnIndex = model.getPressureIndex(); + int sewageProductionColumnIndex = model.getSewageProductionIndex(); int startXCoordColumnIndex = model.getStartXCoordIndex(); int startYCoordColumnIndex = model.getStartYCoordIndex(); @@ -154,6 +155,15 @@ public class CSVImportWizard extends Wizard implements IImportWizard { } catch (NumberFormatException e) { throw new DatabaseException(e); } + } + String sewageProductionS = row.get(sewageProductionColumnIndex); + if (!sewageProductionS.isEmpty()) { + try { + double sewageProduction = Double.parseDouble(sewageProductionS); + graph.claimLiteral(vertex, DN.Vertex_HasSewageProduction, sewageProduction, Bindings.DOUBLE); + } catch (NumberFormatException e) { + throw new DatabaseException(e); + } } } else { diff --git a/org.simantics.district.imports.ui/src/org/simantics/district/imports/ui/CSVImportWizardPage.java b/org.simantics.district.imports.ui/src/org/simantics/district/imports/ui/CSVImportWizardPage.java index e1b81e0f..df04cb32 100644 --- a/org.simantics.district.imports.ui/src/org/simantics/district/imports/ui/CSVImportWizardPage.java +++ b/org.simantics.district.imports.ui/src/org/simantics/district/imports/ui/CSVImportWizardPage.java @@ -64,6 +64,7 @@ public class CSVImportWizardPage extends WizardPage { private DynamicComboFieldEditor endZValueSelector; private DynamicComboFieldEditor tempValueSelector; private DynamicComboFieldEditor pressureValueSelector; + private DynamicComboFieldEditor sewageProductionValueSelector; private DynamicComboFieldEditor outerDiameterSelector; private DynamicComboFieldEditor diameterSelector; @@ -318,6 +319,21 @@ public class CSVImportWizardPage extends WizardPage { validatePageComplete(); } }); + + sewageProductionValueSelector = new DynamicComboFieldEditor("sewageProductionValue", "Sewage production value", parent); + sewageProductionValueSelector.addComboListener(new SelectionListener() { + + @Override + public void widgetSelected(SelectionEvent e) { + widgetDefaultSelected(e); + } + + @Override + public void widgetDefaultSelected(SelectionEvent e) { + model.setSewageProductionIndex(Integer.parseInt(sewageProductionValueSelector.getValue())); + validatePageComplete(); + } + }); } private void createEdgeIndexMappingField(Group parent) { @@ -492,6 +508,7 @@ public class CSVImportWizardPage extends WizardPage { zValueSelector.updateCombo(namesAndValues); pressureValueSelector.updateCombo(namesAndValues); tempValueSelector.updateCombo(namesAndValues); + sewageProductionValueSelector.updateCombo(namesAndValues); } private void updateHeaders() { @@ -552,7 +569,7 @@ public class CSVImportWizardPage extends WizardPage { if (model.isVertexImport()) setPageComplete(model.getXCoordIndex() != -1 && model.getYCoordIndex() != -1 && model.getComponentMappingIndex() != -1); else - setPageComplete(model.getStartXCoordIndex() != 1 && model.getStartYCoordIndex() != -1 && model.getEndXCoordIndex() != -1 && model.getEndYCoordIndex() != -1 && model.getComponentMappingIndex() != -1); + setPageComplete(model.getStartXCoordIndex() != -1 && model.getStartYCoordIndex() != -1 && model.getEndXCoordIndex() != -1 && model.getEndYCoordIndex() != -1 && model.getComponentMappingIndex() != -1); } } diff --git a/org.simantics.district.network.ontology/graph/DistrictNetwork.pgraph b/org.simantics.district.network.ontology/graph/DistrictNetwork.pgraph index e819f445..138e72ae 100644 --- a/org.simantics.district.network.ontology/graph/DistrictNetwork.pgraph +++ b/org.simantics.district.network.ontology/graph/DistrictNetwork.pgraph @@ -20,6 +20,7 @@ DN.Edge -- DN.Mapping.ComponentType --> STR.ComponentType -- DN.Mapping.VertexMapping.ElevationAttribute --> L0.String -- DN.Mapping.VertexMapping.SewageProductionAttribute --> L0.String -- DN.Mapping.VertexMapping.TemperatureAttribute --> L0.String -- DN.Mapping.VertexMapping.PressureAttribute --> L0.String -- DN.Mapping.Terminals --> DN.Mapping.TerminalPair + + @@ -19,11 +21,15 @@ + + + + diff --git a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/contributions/SimplifyPointVerticesHandler.java b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/contributions/SimplifyPointVerticesHandler.java new file mode 100644 index 00000000..14bb9e39 --- /dev/null +++ b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/contributions/SimplifyPointVerticesHandler.java @@ -0,0 +1,50 @@ +package org.simantics.district.network.ui.contributions; + +import javax.inject.Named; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.jobs.Job; +import org.eclipse.e4.core.di.annotations.Execute; +import org.eclipse.e4.ui.model.application.ui.basic.MPart; +import org.eclipse.e4.ui.services.IServiceConstants; +import org.eclipse.ui.IEditorPart; +import org.simantics.Simantics; +import org.simantics.ui.workbench.IResourceEditorInput; +import org.simantics.ui.workbench.e4.E4WorkbenchUtils; +import org.simantics.district.network.ui.internal.Activator; +import org.simantics.DatabaseJob; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.exception.DatabaseException; + +public class SimplifyPointVerticesHandler { + + @Execute + public void execute(@Named(IServiceConstants.ACTIVE_PART) MPart mActiveEditorPart) { + IEditorPart activeEditorPart = E4WorkbenchUtils.getActiveIEditorPart(mActiveEditorPart); + IResourceEditorInput input = (IResourceEditorInput) activeEditorPart.getEditorInput(); + + Job job = new DatabaseJob("Simplify Point Vertices") { + + @Override + protected IStatus run(IProgressMonitor monitor) { + try { + Simantics.getSession().syncRequest(new WriteRequest() { + + @Override + public void perform(WriteGraph graph) throws DatabaseException { + Simantics.applySCL("Apros/District/SimplifyMapping", "simplifyPointVertices", graph, input.getResource()); + } + }); + } catch (DatabaseException e) { + return new Status(IStatus.ERROR, Activator.PLUGIN_ID, getName() + " failed.", e); + } + return Status.OK_STATUS; + } + }; + job.setUser(true); + job.schedule(); + } + +} diff --git a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/contributions/SimplifySewageVerticesHandler.java b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/contributions/SimplifySewageVerticesHandler.java new file mode 100644 index 00000000..308117b1 --- /dev/null +++ b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/contributions/SimplifySewageVerticesHandler.java @@ -0,0 +1,141 @@ +package org.simantics.district.network.ui.contributions; + +import javax.inject.Named; +import java.util.HashMap; +import java.util.Map; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.jobs.Job; +import org.eclipse.e4.core.di.annotations.Execute; +import org.eclipse.e4.ui.model.application.ui.basic.MPart; +import org.eclipse.e4.ui.services.IServiceConstants; +import org.eclipse.ui.IEditorPart; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.layout.GridDataFactory; +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Combo; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Group; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.dialogs.SelectionStatusDialog; +import org.simantics.DatabaseJob; +import org.simantics.Simantics; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.ui.workbench.IResourceEditorInput; +import org.simantics.ui.workbench.e4.E4WorkbenchUtils; +import org.simantics.district.network.ui.internal.Activator; +import org.simantics.district.network.ui.function.Functions; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.request.ReadRequest; + +public class SimplifySewageVerticesHandler { + + @Execute + public void execute(@Named(IServiceConstants.ACTIVE_PART) MPart mActiveEditorPart) { + IEditorPart activeEditorPart = E4WorkbenchUtils.getActiveIEditorPart(mActiveEditorPart); + IResourceEditorInput input = (IResourceEditorInput) activeEditorPart.getEditorInput(); + + SelectMappingDialog dialog = new SelectMappingDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), input.getResource()); + if (dialog.open() != Dialog.OK) + return; + + Resource mapping = dialog.getSewageVertexMapping(); + Job job = new DatabaseJob("Simplify Sewage Vertices") { + + @Override + protected IStatus run(IProgressMonitor monitor) { + try { + Simantics.getSession().syncRequest(new WriteRequest() { + + @Override + public void perform(WriteGraph graph) throws DatabaseException { + Simantics.applySCL("Apros/District/SimplifyMapping", "simplifySewageVertices", graph, mapping, input.getResource()); + } + + }); + } catch (DatabaseException e) { + return new Status(IStatus.ERROR, Activator.PLUGIN_ID, getName() + " failed.", e); + } + return Status.OK_STATUS; + } + }; + job.setUser(true); + job.schedule(); + } + + private static class SelectMappingDialog extends SelectionStatusDialog { + + private Combo vertexMappingCombo; + + private Composite composite; + + private Resource diagram; + private Map vertexMappings = new HashMap<>(); + + private Resource sewageVertexMapping; + + protected SelectMappingDialog(Shell parentShell, Resource diagram) { + super(parentShell); + this.diagram = diagram; + setTitle("Select the sewage vertex mapping"); + } + + public Resource getSewageVertexMapping() { + return sewageVertexMapping; + } + + @Override + protected Control createDialogArea(Composite parent) { + composite = (Composite) super.createDialogArea(parent); + + createMappingsGroup(composite); + + Simantics.getSession().asyncRequest(new ReadRequest() { + + @Override + public void run(ReadGraph graph) throws DatabaseException { + vertexMappings = Functions.getVertexMappings(graph, diagram); + composite.getDisplay().asyncExec(() -> { + vertexMappingCombo.setItems(vertexMappings.keySet().toArray(new String[vertexMappings.size()])); + vertexMappingCombo.select(0); + }); + + } + }); + return composite; + } + + @Override + protected void computeResult() { + sewageVertexMapping = vertexMappings.get(vertexMappingCombo.getItem(vertexMappingCombo.getSelectionIndex())); + } + + private void createMappingsGroup(Composite parent) { + Group group= new Group(parent, SWT.NONE); + group.setFont(parent.getFont()); + group.setText("Default mappings"); + GridDataFactory.fillDefaults().grab(true, false).applyTo(group); + group.setLayout(new GridLayout(1, false)); + + Composite cmposite = new Composite(group, SWT.NONE); + cmposite.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false)); + cmposite.setLayout(new GridLayout(2, false)); + + Label vertexMappingLabel = new Label(cmposite, SWT.NONE); + vertexMappingLabel.setText("Sewage vertex mapping"); + + vertexMappingCombo = new Combo(cmposite, SWT.READ_ONLY | SWT.BORDER); + GridDataFactory.fillDefaults().grab(true, false).applyTo(vertexMappingCombo); + + } + } +} \ No newline at end of file -- 2.47.1