| /** |
| * Copyright (c) 2020 Robert Bosch GmbH. |
| * |
| * This program and the accompanying materials are made |
| * available under the terms of the Eclipse Public License 2.0 |
| * which is available at https://www.eclipse.org/legal/epl-2.0/ |
| * |
| * SPDX-License-Identifier: EPL-2.0 |
| * |
| * Contributors: |
| * Robert Bosch GmbH - initial API and implementation |
| */ |
| package org.eclipse.app4mc.slg.commons.m2t.generators; |
| |
| import java.util.Arrays; |
| |
| import org.eclipse.app4mc.amalthea.model.DiscreteValueBetaDistribution; |
| import org.eclipse.app4mc.amalthea.model.DiscreteValueBoundaries; |
| import org.eclipse.app4mc.amalthea.model.DiscreteValueConstant; |
| import org.eclipse.app4mc.amalthea.model.DiscreteValueGaussDistribution; |
| import org.eclipse.app4mc.amalthea.model.DiscreteValueHistogram; |
| import org.eclipse.app4mc.amalthea.model.DiscreteValueStatistics; |
| import org.eclipse.app4mc.amalthea.model.DiscreteValueUniformDistribution; |
| import org.eclipse.app4mc.amalthea.model.DiscreteValueWeibullEstimatorsDistribution; |
| import org.eclipse.app4mc.amalthea.model.IDiscreteValueDeviation; |
| import org.eclipse.app4mc.amalthea.model.Ticks; |
| import org.eclipse.app4mc.transformation.util.OutputBuffer; |
| import org.eclipse.xtend2.lib.StringConcatenation; |
| import org.slf4j.Logger; |
| import org.slf4j.LoggerFactory; |
| |
| public class TicksTranslationUnit extends TranslationUnit { |
| private static final Logger LOG = LoggerFactory.getLogger(TicksTranslationUnit.class); |
| |
| public String getBasePath() { |
| return this.tuTicksUtils.getBasePath(); |
| } |
| |
| public String getModuleName() { |
| return this.tuTicksUtils.getModuleName(); |
| } |
| |
| @Override |
| public String getCall() { |
| if (((this.ticksValue != null) && ((this.ticksValue instanceof DiscreteValueStatistics) |
| || (this.ticksValue instanceof DiscreteValueConstant)))) { |
| return this.tuTicksUtils.getExecCall(this.getParameters(this.ticksValue)).toString(); |
| } |
| TicksTranslationUnit.LOG.error("Unsupported element for Ticks : " + this.ticksValue.eClass().getName()); |
| return ""; |
| } |
| |
| private final TicksUtilsTranslationUnit tuTicksUtils; |
| private final Ticks ticks; |
| private String puName; |
| private IDiscreteValueDeviation ticksValue; |
| |
| private OutputBuffer outputBuffer; |
| |
| public TicksTranslationUnit(final OutputBuffer outputBuffer, final TicksUtilsTranslationUnit tuTicksUtils, |
| final Ticks ticks, final String puName, final IDiscreteValueDeviation ticksValue) { |
| super(); |
| this.tuTicksUtils = tuTicksUtils; |
| this.ticks = ticks; |
| this.puName = puName; |
| this.ticksValue = ticksValue; |
| this.outputBuffer = outputBuffer; |
| } |
| |
| public String getPuName() { |
| return this.puName; |
| } |
| |
| public String getIncFile() { |
| return this.getModuleName() + ".h"; |
| } |
| |
| private String _getParameters(final IDiscreteValueDeviation value) { |
| StringConcatenation _builder = new StringConcatenation(); |
| _builder.append("WARNING:VALUE_FORMAT_NOT_SUPPORTED\t\t"); |
| _builder.newLine(); |
| return _builder.toString(); |
| } |
| |
| private String _getParameters(final DiscreteValueBetaDistribution value) { |
| StringConcatenation _builder = new StringConcatenation(); |
| _builder.append("WARNING:VALUE_FORMAT_NOT_SUPPORTED"); |
| _builder.newLine(); |
| return _builder.toString(); |
| } |
| |
| private String _getParameters(final DiscreteValueBoundaries value) { |
| StringConcatenation _builder = new StringConcatenation(); |
| _builder.append("WARNING:VALUE_FORMAT_NOT_SUPPORTED"); |
| _builder.newLine(); |
| return _builder.toString(); |
| } |
| |
| private String _getParameters(final DiscreteValueConstant value) { |
| StringConcatenation _builder = new StringConcatenation(); |
| long _value = value.getValue(); |
| _builder.append(_value); |
| return _builder.toString(); |
| } |
| |
| private String _getParameters(final DiscreteValueGaussDistribution value) { |
| StringConcatenation _builder = new StringConcatenation(); |
| _builder.append("WARNING:VALUE_FORMAT_NOT_SUPPORTED"); |
| _builder.newLine(); |
| return _builder.toString(); |
| } |
| |
| private String _getParameters(final DiscreteValueHistogram value) { |
| StringConcatenation _builder = new StringConcatenation(); |
| _builder.append("WARNING:VALUE_FORMAT_NOT_SUPPORTED"); |
| _builder.newLine(); |
| return _builder.toString(); |
| } |
| |
| private String _getParameters(final DiscreteValueStatistics value) { |
| StringConcatenation _builder = new StringConcatenation(); |
| _builder.append(value.getAverage()); |
| _builder.append(", "); |
| _builder.append(value.getLowerBound()); |
| _builder.append(", "); |
| _builder.append(value.getUpperBound()); |
| return _builder.toString(); |
| } |
| |
| private String _getParameters(final DiscreteValueUniformDistribution value) { |
| StringConcatenation _builder = new StringConcatenation(); |
| _builder.append("WARNING:VALUE_FORMAT_NOT_SUPPORTED"); |
| _builder.newLine(); |
| return _builder.toString(); |
| } |
| |
| private String _getParameters(final DiscreteValueWeibullEstimatorsDistribution value) { |
| StringConcatenation _builder = new StringConcatenation(); |
| _builder.append("WARNING:VALUE_FORMAT_NOT_SUPPORTED"); |
| return _builder.toString(); |
| } |
| |
| private String getParameters(final IDiscreteValueDeviation value) { |
| if (value instanceof DiscreteValueBetaDistribution) { |
| return _getParameters((DiscreteValueBetaDistribution) value); |
| } else if (value instanceof DiscreteValueBoundaries) { |
| return _getParameters((DiscreteValueBoundaries) value); |
| } else if (value instanceof DiscreteValueGaussDistribution) { |
| return _getParameters((DiscreteValueGaussDistribution) value); |
| } else if (value instanceof DiscreteValueStatistics) { |
| return _getParameters((DiscreteValueStatistics) value); |
| } else if (value instanceof DiscreteValueUniformDistribution) { |
| return _getParameters((DiscreteValueUniformDistribution) value); |
| } else if (value instanceof DiscreteValueWeibullEstimatorsDistribution) { |
| return _getParameters((DiscreteValueWeibullEstimatorsDistribution) value); |
| } else if (value instanceof DiscreteValueConstant) { |
| return _getParameters((DiscreteValueConstant) value); |
| } else if (value instanceof DiscreteValueHistogram) { |
| return _getParameters((DiscreteValueHistogram) value); |
| } else if (value != null) { |
| return _getParameters(value); |
| } else { |
| throw new IllegalArgumentException("Unhandled parameter types: " + Arrays.<Object>asList(value).toString()); |
| } |
| } |
| |
| public String getModulePath() { |
| return getBasePath() + "/" + getModuleName(); |
| } |
| |
| @Override |
| public String getSrcFile() { |
| return getModuleName() + ".cpp"; |
| } |
| |
| public String getIncPath() { |
| return getModulePath() + "/_inc/" + getIncFile(); |
| } |
| |
| public String getSrcPath() { |
| return getModulePath() + "/_src/" + getSrcFile(); |
| } |
| |
| public boolean isIncFileEmpty() { |
| return !outputBuffer.bufferExists("INC", getModulePath() + "/_inc/" + getModuleName()); |
| } |
| |
| public boolean isSrcFileEmpty() { |
| return !outputBuffer.bufferExists("SRC", getModulePath() + "/_src/" + getModuleName()); |
| } |
| |
| public boolean incAppend(final String str) { |
| return outputBuffer.appendTo("INC", getModulePath() + "/_inc/" + getModuleName(), str); |
| } |
| |
| public boolean srcAppend(final String str) { |
| return outputBuffer.appendTo("SRC", getModulePath() + "/_src/" + getModuleName(), str); |
| } |
| |
| } |