/// <summary> /// A new set of Inputs reflecting the current Procedure state. /// </summary> protected override List <Input> BuildUpdatedInputs() { List <string> args = mProcedure.Arguments; int argCount = args.Count; List <Input> inputs = new List <Input>(); // Procedure name inputs.Add(mBlock.InputList[0]); // Argument inputs for (int i = 0; i < argCount; ++i) { Input stackInput = InputFactory.Create(Define.EConnection.InputValue, "ARG" + i, Define.EAlign.Right, null); // add "with: " label if (i == 0) { FieldLabel withLabel = new FieldLabel("WITH", I18n.Msg[MsgDefine.PROCEDURES_CALL_BEFORE_PARAMS]); stackInput.AppendField(withLabel); } // add argument's label FieldLabel label = new FieldLabel(null, args[i]); stackInput.AppendField(label); inputs.Add(stackInput); } return(inputs); }
protected void UpdateInternal(List <bool> isAts) { for (int i = 0; i < isAts.Count; i++) { bool isAt = isAts[i]; AtData data = mAtDatas[i]; Input atInput = mBlock.GetInput(data.inputName); if (isAt) { if (atInput == null) { atInput = InputFactory.Create(Define.EConnection.InputValue, data.inputName, Define.EAlign.Left, CHECK); mBlock.AppendInput(atInput, data.atInputIndex); } else if (atInput.Type == Define.EConnection.DummyInput) { //remove dummy input first mBlock.RemoveInput(atInput); atInput = InputFactory.Create(Define.EConnection.InputValue, data.inputName, Define.EAlign.Left, CHECK); mBlock.AppendInput(atInput, data.atInputIndex); } } else { if (atInput != null) { mBlock.RemoveInput(atInput); } } } }
/// <summary> /// An Input to contain the procedure body statements. /// </summary> protected Input GetStatementsInput() { Input stackInput = mBlock.GetInput(ProcedureDB.STATEMENT_INPUT_NAME); if (stackInput == null) { stackInput = InputFactory.Create(Define.EConnection.NextStatement, ProcedureDB.STATEMENT_INPUT_NAME, Define.EAlign.Left, null); } return(stackInput); }
/// <summary> /// Constructs the block's header. The new header maintains the same name field instance, /// but updated argument list. /// </summary> /// <returns>a new header reflecting the latest mutator state.</returns> protected Input BuildNewHeader() { Input descriptionInput = mBlock.InputList[0]; List <Field> oldFields = descriptionInput.FieldRow; Input input = InputFactory.Create(Define.EConnection.DummyInput, null, Define.EAlign.Left, null); input.SourceBlock = mBlock; input.AppendField(oldFields[0]); input.AppendField(oldFields[1]); input.AppendField(new FieldLabel("PARAMS", GetParametersListDescription())); return(input); }
protected void UpdateInternal(bool divisible) { Input divisorInput = mBlock.GetInput(DIVISOR_INPUT); if (divisible && divisorInput == null) { divisorInput = InputFactory.Create(Define.EConnection.InputValue, DIVISOR_INPUT, Define.EAlign.Left, CHECK); mBlock.AppendInput(divisorInput); } else if (!divisible && divisorInput != null) { mBlock.RemoveInput(divisorInput); } }
private void UpdateInternal() { // currently reserve the dummy input, it will only show the Label Field on UI Input emptyInput = mBlock.GetInput(EMPTY_NAME); if (mItemCount > 0 && emptyInput != null) { mBlock.RemoveInput(emptyInput); } else if (mItemCount == 0 && emptyInput == null) { emptyInput = InputFactory.Create(Define.EConnection.DummyInput, EMPTY_NAME, Define.EAlign.Right, null); emptyInput.AppendField(new FieldLabel(null, mLabelText)); mBlock.AppendInput(emptyInput); } //add new inputs int i = 0; for (i = 0; i < mItemCount; i++) { Input addInput = mBlock.GetInput("ADD" + i); if (addInput == null) { addInput = InputFactory.Create(Define.EConnection.InputValue, ADD_INPUT_PREFIX + i, Define.EAlign.Right, null); mBlock.AppendInput(addInput); } if (i == 0) { if (mBlock.GetField("Title") == null) { addInput.AppendField(new FieldLabel("Title", mLabelText)); } } } // remove deleted inputs while (true) { Input addInput = mBlock.GetInput("ADD" + i); if (addInput == null) { break; } mBlock.RemoveInput(addInput); i++; } }
/// <summary> /// Performs the model changes for the given count. This will reuse as many inputs as possible, /// creating new inputs if necessary. Leftover inputs will be disconnected and thrown away. /// </summary> private void UpdateInternal() { List <Input> oldInputs = new List <Input>(mBlock.InputList); List <Input> newInputs = new List <Input>(); // Set aside the else input for the end. Input elseInput = mBlock.GetInput(ELSE_INPUT_NAME); if (elseInput != null) { oldInputs.Remove(elseInput); } // Move the first if/do block into the new input list newInputs.Add(oldInputs[0]); //IF0 newInputs.Add(oldInputs[1]); //DO0 oldInputs.RemoveRange(0, 2); // Copy over existing inputs if we have them, make new ones if we don't. for (int i = 1; i <= mElseIfCount; i++) { if (oldInputs.Count >= 2) { newInputs.Add(oldInputs[0]); //IFi newInputs.Add(oldInputs[1]); //DOi oldInputs.RemoveRange(0, 2); } else { // IFi value input Input inputValue = InputFactory.Create(Define.EConnection.InputValue, IF_INPUT_PREFIX + i, ALIGN, new List <string>() { CHECK }); inputValue.AppendField(new FieldLabel(null, I18n.Get(MsgDefine.CONTROLS_IF_MSG_ELSEIF))); // DOi statement input Input inputStatement = InputFactory.Create(Define.EConnection.NextStatement, DO_INPUT_PREFIX + i, ALIGN, null); inputStatement.AppendField(new FieldLabel(null, I18n.Get(MsgDefine.CONTROLS_IF_MSG_THEN))); newInputs.Add(inputValue); newInputs.Add(inputStatement); } } // Add the else clause if we need it if (mHasElse) { if (elseInput == null) { elseInput = InputFactory.Create(Define.EConnection.NextStatement, ELSE_INPUT_NAME, ALIGN, null); elseInput.AppendField(new FieldLabel(null, I18n.Get(MsgDefine.CONTROLS_IF_MSG_ELSE))); } newInputs.Add(elseInput); } else if (elseInput != null) { // dispose the else statement elseInput.Dispose(); } // Clean up extra inputs foreach (Input input in oldInputs) { input.Dispose(); } oldInputs.Clear(); mBlock.Reshape(newInputs); }
public List <Input> CreateInputList() { List <Input> inputs = new List <Input>(); List <Field> fields = new List <Field>(); int i = 0; while (!mJson["message" + i].IsNullOrUndefined()) { string message = mJson["message" + i].ToString(); JArray args = mJson["args" + i] as JArray; List <string> tokens = Utils.TokenizeInterpolation(message); Dictionary <string, bool> indexDup = new Dictionary <string, bool>(); foreach (string token in tokens) { int tokenNum; if (int.TryParse(token, out tokenNum)) { if (tokenNum <= 0 || tokenNum > args.Count) { throw new Exception("Block " + mTypeName + ": Message index %" + token + " out of range"); } if (indexDup.ContainsKey(token)) { throw new Exception("Block " + mTypeName + ": Message index %" + token + " duplicated."); } indexDup[token] = true; JObject element = args[tokenNum - 1] as JObject; if (element == null) { throw new Exception("Block " + mTypeName + " Error reading arg %" + i); } while (element != null) { string elementType = element["type"].ToString(); if (Define.FIELD_TYPES.Contains(elementType)) { fields.Add(FieldFactory.CreateFromJson(element)); break; } else if (Define.INPUT_TYPES.Contains(elementType)) { Input input = InputFactory.CreateFromJson(element); foreach (Field field in fields) { input.AppendField(field); } fields.Clear(); inputs.Add(input); break; } else { element = element["alt"] as JObject; } } } else { string newtoken = token.Trim(); if (!string.IsNullOrEmpty(newtoken)) { fields.Add(new FieldLabel(null, newtoken)); } } } // If there were leftover fields we need to add a dummy input to hold them. if (fields.Count > 0) { JObject dummyInputJson = new JObject(); dummyInputJson["type"] = "input_dummy"; if (mJson["lastDummyAlign" + i] != null) { dummyInputJson["align"] = mJson["lastDummyAlign" + i]; } Input input = InputFactory.CreateFromJson(dummyInputJson); foreach (Field field in fields) { input.AppendField(field); } fields.Clear(); inputs.Add(input); } i++; } return(inputs); }