Commit df7afa0b authored by Hafiz Muhammad Wahaj Aziz's avatar Hafiz Muhammad Wahaj Aziz
Browse files

prevent deletion of ports for FMU

refs 3055
parent bacca39a
CCodeGeneratorEasyStartMenu.java 0ff9ab8229297bc08aec4e3deab92f958640db6a GREEN
CGeneratorExecutionTarget.java 1987bd2add540d4c82bb392b19cd87f5d9ef324a GREEN
FMUGeneratorEasyStartMenu.java 253342882ec92cc40f83f3de3efca432bfb08786 GREEN
FMUGeneratorExecutionTarget.java 9cfd7978436c4426ac5521d32c5085a34e3a4c36 RED
FMUGeneratorExecutionTarget.java e5824f183509bee08c51d71e81f20f7b507b3dc4 GREEN
JavaCodeGeneratorEasyStartMenu.java 92dcdecd8c65b17cbd4177d333d996d3f21f361c GREEN
JavaGeneratorExecutionTarget.java f433c2230bf4946ef4ac34ad12cea8804cddb94f GREEN
/*-------------------------------------------------------------------------+
| Copyright 2017 fortiss GmbH |
/*--------------------------------------------------------------------------+
$Id$
| |
| Copyright 2017 fortiss GmbH |
| |
| Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. |
......@@ -16,6 +18,7 @@
package org.fortiss.af3.component.ui.generator;
import static org.eclipse.ui.PlatformUI.getWorkbench;
import static org.fortiss.af3.expression.utils.DataDictionaryUtils.findDataDictionary;
import static org.fortiss.af3.project.ui.utils.FolderOrProjectDialogUtils.openFolderDialog;
import static org.fortiss.tooling.kernel.utils.LoggingUtils.error;
import static org.fortiss.tooling.kernel.utils.ResourceUtils.getResourceURI;
......@@ -49,12 +52,19 @@ import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.emf.common.util.EList;
import org.eclipse.jface.dialogs.IInputValidator;
import org.eclipse.jface.dialogs.InputDialog;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.window.Window;
import org.eclipse.swt.widgets.Shell;
import org.fortiss.af3.component.model.ComponentArchitecture;
import org.fortiss.af3.component.ui.AF3ComponentUIActivator;
import org.fortiss.af3.expression.model.DataDictionary;
import org.fortiss.af3.expression.model.definitions.FunctionDefinition;
import org.fortiss.af3.expression.model.terms.DoubleConst;
import org.fortiss.af3.expression.model.terms.imperative.IStatementTerm;
import org.fortiss.af3.expression.model.terms.imperative.Return;
import org.fortiss.af3.generator.common.AF3GeneratorCommonActivator;
import org.fortiss.af3.generator.common.model.fmu.FMUArchivePackage;
import org.fortiss.af3.generator.common.model.source.AbstractUnit;
......@@ -64,9 +74,12 @@ import org.fortiss.af3.project.extension.base.ExecutionTargetBase;
import org.fortiss.af3.project.extension.data.Executable;
/**
* TODO (AB, B1) class comment missing.
* Execution target implementation for the FMU generator.
*
* @author aravantinos
* @author $Author$
* @version $Rev$
* @ConQAT.Rating YELLOW Hash: 2717D946E7F3098D65A56EC0EC783513
*/
public class FMUGeneratorExecutionTarget extends ExecutionTargetBase {
/** {@inheritDoc} */
......@@ -88,19 +101,13 @@ public class FMUGeneratorExecutionTarget extends ExecutionTargetBase {
Shell currentShell = getWorkbench().getActiveWorkbenchWindow().getShell();
InputDialog durationDlg =
new InputDialog(currentShell, "Frequency",
"Please provide the frequency of the component in Hertz:",
lastSelectedFrequency + "", new NumberValidator());
DataDictionary dd = findDataDictionary(((ComponentArchitecture)executable.getSource()));
if(durationDlg.open() != Window.OK) {
Double samplingTime = getSamplingTime(dd);
if(samplingTime == null) {
return;
}
// Parsing should not throw any exception since the string went through NumberValidator
lastSelectedFrequency = Double.parseDouble(durationDlg.getValue());
double lastSelectedStepSize = 1000.0 / (lastSelectedFrequency);
fmuSource.setStepDuration(lastSelectedStepSize);
fmuSource.setStepDuration(samplingTime);
IResource targetFolder = openFolderDialog();
if(targetFolder == null) {
......@@ -162,6 +169,67 @@ public class FMUGeneratorExecutionTarget extends ExecutionTargetBase {
.getModelDescription().getName() + ".fmu was successfuly generated!");
}
/**
* Returns the sampling time from the user defined function (samplingTime) if correctly defined,
* otherwise asks from the user.
*/
private Double getSamplingTime(DataDictionary dd) {
Shell currentShell = getWorkbench().getActiveWorkbenchWindow().getShell();
String message = "";
String baseMsg = "The \"samplingTime\" function should ";
Double samplingTime = null;
for(FunctionDefinition function : dd.getFunctions()) {
if(function.getFunction().getName().toString().equals("samplingTime")) {
if(!function.getReturnType().toString().contains("double")) {
message +=
baseMsg + "return a value of type \"double\"." + System.lineSeparator();
}
EList<IStatementTerm> statements = function.getDefinition().getStatements();
if(statements.size() != 1) {
message +=
baseMsg + "contain one and only one statement." +
System.lineSeparator();
} else {
// get(0): this is fine because of the check above
IStatementTerm singleStatement = statements.get(0);
if(!(singleStatement instanceof Return)) {
message +=
baseMsg + "contain a \"return\" statement." +
System.lineSeparator();
}
Return returnStatement = (Return)singleStatement;
if(!(returnStatement.getValue() instanceof DoubleConst)) {
message += baseMsg + "return a constant value.";
} else {
samplingTime = ((DoubleConst)returnStatement.getValue()).getValue();
}
}
}
}
if(!message.equals("")) {
InputDialog durationDlg =
new InputDialog(
currentShell,
"Frequency",
"samplingTime() function definition error:" +
System.lineSeparator() +
message +
System.lineSeparator() +
"As sampling time function is not (properly) defined, please provide the frequency of the component in Hertz:",
lastSelectedFrequency + "", new NumberValidator());
if(durationDlg.open() != Window.OK) {
return null;
}
// Parsing should not throw any exception since the string went through NumberValidator
lastSelectedFrequency = Double.parseDouble(durationDlg.getValue());
// Multiplying with 1000 to convert time to milliseconds
samplingTime = 1000.0 / lastSelectedFrequency;
}
return samplingTime;
}
/**
* Collects all the source files to be compiled, prefixing with the given prefix and appending
* the given extension.
......@@ -197,7 +265,7 @@ public class FMUGeneratorExecutionTarget extends ExecutionTargetBase {
}
/**
* Check the architecture of the Java(32-Bit or 64-Bit). Then, returns the necessary folder name
* Check the architecture of the Java(32-Bit or 64-Bit) and returns the necessary folder name
* for fmu binaries
*/
private String checkArchitecture() throws IOException {
......
ComponentSpecificationPropertySection.java d20927a428e18e7d03319e223452bcc837049a78 GREEN
PortDataPropagation.java 88c5090f294a6e97de3b0d8e2db83f0b6f0d31fa GREEN
PortInitValueSection.java 295cf97636227139117e32c0bd8acab3d817c843 GREEN
PortSpecificationPropertySection.java f67d12a325b8f389b9fea045073c6239ecbc7be8 GREEN
PortInitValueSection.java 291c752de3452175e5887a21aae70157e6e4e42d GREEN
PortSpecificationPropertySection.java a035fbfd9031f7ad4ac4a4486ba03ceb31517efa GREEN
TypeLabelProvider.java e9b9733cee117eaabffb095d9808e098afec3e3f GREEN
/*-------------------------------------------------------------------------+
| Copyright 2017 fortiss GmbH |
/*--------------------------------------------------------------------------+
$Id$
| |
| Copyright 2017 fortiss GmbH |
| |
| Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. |
......@@ -16,6 +18,7 @@
package org.fortiss.af3.component.ui.properties;
import static org.fortiss.af3.component.ui.utils.ComponentCompletionProposalUtils.createInitialValueProposals;
import static org.fortiss.af3.component.utils.ComponentArchitectureUtils.hasReadOnlyBehaviorSpecification;
import java.util.function.Function;
......@@ -46,7 +49,12 @@ import org.fortiss.tooling.kernel.ui.util.DataBindingUtils;
import org.fortiss.tooling.kernel.ui.util.ObservableUtils;
/**
* Property section for {@link PortInitValueSection}s.
*
* @author lazyBisa
* @author $Author$
* @version $Rev$
* @ConQAT.Rating YELLOW Hash: A89899BB1B061BDA6B2C7E585A55CF29
*/
@SuppressWarnings("javadoc")
public class PortInitValueSection extends PropertySectionBase {
......@@ -114,8 +122,9 @@ public class PortInitValueSection extends PropertySectionBase {
new ITermToStringConverter(), new StringToIExpressionTermConverter(this.spec),
new StringToIExpressionTermValidator(this.spec), null);
boolean isEnabled =
((Component)port.getOwner()).isStronglyCausal() && port instanceof OutputPort;
boolean isStronglyCausal = ((Component)port.getOwner()).isStronglyCausal();
boolean isReadOnly = hasReadOnlyBehaviorSpecification(port.getComponent());
boolean isEnabled = isStronglyCausal && port instanceof OutputPort && !isReadOnly;
initialValueText.setEnabled(isEnabled);
}
......@@ -148,6 +157,11 @@ public class PortInitValueSection extends PropertySectionBase {
* Simple Selection Listener interface which provides a default (empty) implementation of
* widgedDefaultSelected. This way you can provide lambdas and method references as selection
* listeners by writing (SSL) e -> foo().
*
* @author lazyBisa
* @author $Author$
* @version $Rev$
* @ConQAT.Rating RED Hash:
*/
@FunctionalInterface
private interface SSL extends SelectionListener {
......
/*-------------------------------------------------------------------------+
| Copyright 2011 fortiss GmbH |
/*--------------------------------------------------------------------------+
$Id$
| |
| Copyright 2011 ForTISS GmbH |
| |
| Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. |
......@@ -17,10 +19,12 @@ package org.fortiss.af3.component.ui.properties;
import static org.fortiss.af3.component.AF3ComponentActivator.getDefault;
import static org.fortiss.af3.component.ui.properties.PortDataPropagation.getPortsToPropagate;
import static org.fortiss.af3.component.utils.ComponentArchitectureUtils.hasReadOnlyBehaviorSpecification;
import static org.fortiss.af3.expression.utils.ExpressionUtils.getAllVisibleTypes;
import static org.fortiss.tooling.kernel.utils.EcoreUtils.copy;
import static org.fortiss.tooling.kernel.utils.LoggingUtils.error;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
......@@ -69,6 +73,9 @@ import org.fortiss.tooling.kernel.ui.util.WidgetsFactory;
* TODO: USE DATABINDINGS, OMG
*
* @author eder
* @author $Author$
* @version $Rev$
* @ConQAT.Rating YELLOW Hash: AD268AFF9EF744E9FF9FFB751C9092DF
*/
@SuppressWarnings("javadoc")
public final class PortSpecificationPropertySection extends PropertySectionBase implements
......@@ -200,7 +207,7 @@ public final class PortSpecificationPropertySection extends PropertySectionBase
IType selectedType = (IType)selection.getFirstElement();
if(!isBuiltInType(selectedType)) {
DataDictionary dd = DataDictionaryUtils.findDataDictionary(port);
goToTypeButton.setEnabled(true);
goToTypeButton.setEnabled(!hasReadOnlyBehaviorSpecification(port.getComponent()));
IModelEditorBindingService.getInstance().openInEditor(dd);
DataDictionaryEditorGUI.setFilteredTree(selectedType.toString());
}
......@@ -257,9 +264,13 @@ public final class PortSpecificationPropertySection extends PropertySectionBase
refreshBoundsControls();
userInput = false;
List<IType> types = getAllVisibleTypes(spec);
typeComboViewer.setInput(types);
List<IType> types = new ArrayList<IType>();
types.add(spec.getType());
if(!hasReadOnlyBehaviorSpecification(port.getComponent())) {
types = getAllVisibleTypes(spec);
}
typeComboViewer.setInput(types);
typeComboViewer.setSelection(new StructuredSelection(types.stream()
.filter(t -> typesAreEqual(t, spec.getType())).collect(Collectors.toList())));
userInput = true;
......@@ -297,7 +308,11 @@ public final class PortSpecificationPropertySection extends PropertySectionBase
TInt intType = (TInt)spec.getType();
lowerBound.setText(intType.getLowerBound() + "");
upperBound.setText(intType.getUpperBound() + "");
enableBoundControls();
if(hasReadOnlyBehaviorSpecification(port.getComponent())) {
disableBoundControls();
} else {
enableBoundControls();
}
} else {
upperBound.setText(" ");
lowerBound.setText(" ");
......@@ -326,7 +341,7 @@ public final class PortSpecificationPropertySection extends PropertySectionBase
@Override
protected void disableControls() {
super.disableControls();
propagate.enableControls(true);
propagate.enableControls(!hasReadOnlyBehaviorSpecification(port.getComponent()));
}
/** {@inheritDoc} */
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment