Commit 5901f003 authored by ics's avatar ics

Add methods to manage ForLoopStepType

parent bb735aa2
......@@ -200,12 +200,12 @@ public abstract class CommandWrapper implements IServerCommand, ICommandBoxEvent
}
@Override
public void onToggleParallel() {
public final void onToggleParallel() {
commandBoxSyncListener.onToggleParallel();
}
@Override
public void onToggleBackground() {
public final void onToggleBackground() {
commandBoxSyncListener.onToggleBackground();
}
......
......@@ -39,6 +39,7 @@ public class ForLoopCommandWrapper extends CommandWrapper implements IForLoopEve
}
public enum LoopType {RANGE, VALUES};
public enum StepType {DELTA, NBPOINTS};
public String getCommandType() {
return "forloop";
......@@ -106,7 +107,22 @@ public class ForLoopCommandWrapper extends CommandWrapper implements IForLoopEve
}
return LoopType.RANGE;
}
public void setForLoopStepType(int index, StepType stepType) {
if (stepType == StepType.DELTA) {
serverForLoopCommandBox.setForLoopStepType(index, CommandZoneAccessor.ForLoopStepType.DELTA);
} else {
serverForLoopCommandBox.setForLoopStepType(index, CommandZoneAccessor.ForLoopStepType.NBPOINTS);
}
}
public StepType getForLoopStepType(int index) {
if (serverForLoopCommandBox.getForLoopStepType(index) == CommandZoneAccessor.ForLoopStepType.DELTA) {
return StepType.DELTA;
}
return StepType.NBPOINTS;
}
public boolean addForLoopLine(int index) {
return serverForLoopCommandBox.addForLoopLine(index);
}
......
......@@ -22,13 +22,23 @@ import fr.ill.ics.nscclient.command.CommandZoneAccessor.ForLoopType;
public interface ServerCommandBoxSyncListener {
void onAddForLoopLine(int lineIndex);
void onRemoveForLoopLine(int lineIndex);
void onSetForLoopVariableName(int lineIndex, String value);
void onSetForLoopStartValue(int lineIndex, double value);
void onSetForLoopEndValue(int lineIndex, double value);
void onSetForLoopStepSize(int lineIndex, double value);
void onSetForLoopValues(int lineIndex, String value);
void onToggleParallel();
void onToggleBackground();
void onSetSettingsFileName(String fileName);
void onSetControllerName(String value);
void onSetPropertyName(String value);
void onSetValue(String value);
void onSetExpression(String value);
<<<<<<< Updated upstream
void onSetForLoopType(ForLoopType type, int lineIndex);
void onSetForLoopValues(int lineIndex, String value);
void onSetForLoopVariableName(int lineIndex, String value);
......@@ -37,4 +47,7 @@ public interface ServerCommandBoxSyncListener {
void onSetForLoopStepSize(int lineIndex, double value);
void onAddForLoopLine(int lineIndex);
void onRemoveForLoopLine(int lineIndex);
=======
void onSetForLoopType(ForLoopType type);
>>>>>>> Stashed changes
}
\ No newline at end of file
......@@ -49,6 +49,7 @@ public class CommandZoneAccessor {
public enum ExecutionPhaseState {CONSTRUCTION, RUNNING, FINISHED, PAUSED};
public enum ContainerType {COMMANDZONE, IFTHEN, IFELSE, FORLOOP, SCAN};
public enum ForLoopType {RANGE, VALUES};
public enum ForLoopStepType {DELTA, NBPOINTS};
public enum ExpressionStatus {VALID_EXPRESSION, INVALID_EXPRESSION};
public enum ExpressionError {NO_ERROR, PARSER_ERROR, DISABLED_CONTROLLER_ERROR, ENUMERATED_VALUE_ERROR, UNDEFINED_VARIABLE_ERROR};
......@@ -2405,6 +2406,7 @@ public class CommandZoneAccessor {
}
}
public ForLoopType getForLoopType(int commandBoxID, int lineIndex) {
// Create the message type.
......@@ -2444,6 +2446,82 @@ public class CommandZoneAccessor {
}
return ForLoopType.RANGE;
}
public void setForLoopStepType(int commandBoxID, int lineIndex, ForLoopStepType forLoopStepType) {
// Create the message type.
CommandZoneRequests.Message type = CommandZoneRequests.Message.newBuilder()
.setType(CommandZoneRequests.Message.Type.SetStepType)
.build();
// Create the request.
CommandZoneRequests.SetForLoopStepTypeRequest request = CommandZoneRequests.SetForLoopStepTypeRequest.newBuilder()
.setClientID(getClientID())
.setCommandBoxID(commandBoxID)
.setLineIndex(lineIndex)
.setType((forLoopStepType == ForLoopStepType.DELTA ? CommandZoneRequests.ForLoopStepType.Type.DELTA : CommandZoneRequests.ForLoopStepType.Type.NBPOINTS))
.build();
commandBoxRequester.sendTwoParts(type.toByteArray(), request.toByteArray());
try {
Common.BooleanResponse response = Common.BooleanResponse.parseFrom(commandBoxRequester.receive());
// Test the error.
if (response.hasError()) {
processError(response.getError(), commandBoxID);
}
}
catch (InvalidProtocolBufferException e) {
LOGGER.logp(Level.WARNING, this.getClass().getName(), "setForLoopStepType", "error in parsing response");
}
}
public ForLoopStepType getForLoopStepType(int commandBoxID, int lineIndex) {
// Create the message type.
CommandZoneRequests.Message type = CommandZoneRequests.Message.newBuilder()
.setType(CommandZoneRequests.Message.Type.GetStepType)
.build();
// Create the request.
CommandZoneRequests.GetForLoopValueRequest request = CommandZoneRequests.GetForLoopValueRequest.newBuilder()
.setClientID(getClientID())
.setCommandBoxID(commandBoxID)
.setLineIndex(lineIndex)
.build();
commandBoxRequester.sendTwoParts(type.toByteArray(), request.toByteArray());
try {
CommandZoneRequests.ForLoopStepTypeResponse response = CommandZoneRequests.ForLoopStepTypeResponse.parseFrom(commandBoxRequester.receive());
// Test the error.
if (response.hasError()) {
processError(response.getError(), commandBoxID);
}
else {
CommandZoneRequests.ForLoopStepType.Type forLoopStepType = response.getValue();
if (forLoopStepType == CommandZoneRequests.ForLoopStepType.Type.DELTA) {
return ForLoopStepType.DELTA;
}
else if (forLoopStepType == CommandZoneRequests.ForLoopStepType.Type.NBPOINTS) {
return ForLoopStepType.NBPOINTS;
}
return ForLoopStepType.DELTA;
}
}
catch (InvalidProtocolBufferException e) {
LOGGER.logp(Level.WARNING, this.getClass().getName(), "getForLoopType", "error in parsing response for command box " + commandBoxID);
}
return ForLoopStepType.DELTA;
}
......
......@@ -21,6 +21,7 @@ package fr.ill.ics.nscclient.command;
import java.util.Iterator;
import java.util.Set;
import fr.ill.ics.nscclient.command.CommandZoneAccessor.ForLoopStepType;
import fr.ill.ics.nscclient.command.CommandZoneAccessor.ForLoopType;
......@@ -73,7 +74,15 @@ public class ServerForLoopCommandBox extends ServerCommandBox {
public ForLoopType getForLoopType(int lineIndex) {
return CommandZoneAccessor.getInstance(serverId).getForLoopType(commandBoxId, lineIndex);
}
public void setForLoopStepType(int lineIndex, ForLoopStepType stepType) {
CommandZoneAccessor.getInstance(serverId).setForLoopStepType(commandBoxId, lineIndex, stepType);
}
public ForLoopStepType getForLoopStepType(int lineIndex) {
return CommandZoneAccessor.getInstance(serverId).getForLoopStepType(commandBoxId, lineIndex);
}
public boolean setValues(int lineIndex, String values) {
return CommandZoneAccessor.getInstance(serverId).setValues(commandBoxId, lineIndex, values);
}
......
Markdown is supported
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