/// <summary> /// Set the output value of ShadowedOutputNode. This is the same as for /// the super class methodd, except that it updates the shadowing inputs /// </summary> /// <param name="index"></param> /// <param name="value"></param> /// <param name="t"></param> /// <param name="send"></param> /// <returns></returns> public override DXTypeVals setOutputValue(int index, String value, DXTypeVals t, bool send) { DXTypeVals type; Debug.Assert(value != null); // Defer visual notification in case, we do more then one set*Value(). deferVisualNotification(); // When data-driven, outputs that have shadowing inputs are not sent and // instead their shadows are sent.. int shadow_input = getShadowingInput(index); if (shadow_input > 0) { type = base.setOutputValue(index, value, t, false); if (type != DXTypeVals.UndefinedType) { value = getOutputValueString(index); setInputValue(shadow_input, value, type, false); if (send) sendValues(false); } } else { type = base.setOutputValue(index, value, t, send); } undeferVisualNotification(); return type; }
/// <summary> /// // We implement this for FileSelector node so that we can keep the /// 2nd output (the basename of the full file name) up to date. /// One should never use this method to set the 2nd output, only the 1st. /// Well, this is used when we parse a .net file. /// </summary> /// <param name="index"></param> /// <param name="value"></param> /// <param name="t"></param> /// <param name="send"></param> /// <returns></returns> public override DXTypeVals setOutputValue(int index, String value, DXTypeVals t, bool send) { Regex regex = new Regex(@"\\"); String localValue = regex.Replace(value, "/"); if (index == 2) return base.setOutputValue(2, localValue, t, send); DXTypeVals type = base.setOutputValue(1, localValue, t, false); if (type != DXTypeVals.UndefinedType) { String basename = getOutputValueString(1); basename = regex.Replace(basename, "/"); if (!basename.Contains("/")) type = base.setOutputValue(2, value, type, send); else { // Not quite sure what the code is trying to do here. throw new Exception("Not Yet Implemented"); } } return type; }
/// <summary> /// Update any inputs that are being updated by the server (i.e. the /// module that is doing the data-driven operations). /// We update the values internally, and send the shadowing input /// value back to the executive with an Executive() call. /// We use the Executive call instead of a direct assignment, because if /// we are currently in execute-on-change mode, the assignment would cause /// extra executions. /// The Executive() call (a dictionary update) avoids that. /// </summary> /// <param name="output_index"></param> /// <param name="val"></param> /// <param name="t"></param> /// <returns></returns> protected DXTypeVals setShadowedOutputSentFromServer(int output_index, String val, DXTypeVals t) { // Set the values internally // Set the output quietly instead of just setting it and not sending it // for the following scenario with out the quietly: // // 1) Interactor->Echo, Execute echos 0 // (references GLOBAL main_Interactor_1_out_1) // 2) Set Interactor:min value to 5, Execute echos 5 // (references LOCAL main_Interactor_1_out_1) // 3) Tab up Interactor:min, Execute echos 0 // (references GLOBAL main_Interactor_1_out_1) // // So, setting the output quietly makes sure that the global value // is up to date. int input_index = getShadowingInput(output_index); DXTypeVals type = setOutputValueQuietly(output_index, val, t); if (type != DXTypeVals.UndefinedType) { clearOutputDirty(output_index); setInputValueQuietly(input_index, val, type); } return type; }
public ParamClass(int pIndex, int opIndex, DXTypeVals pType, ParamCats pcat) { paramIndex = pIndex; oldParamIndex = opIndex; paramType = pType; category = pcat; }
public override DXTypeVals setInputValue(int index, string value, DXTypeVals type, bool send) { DXTypeVals result; bool trans = translating; translating = false; switch (index) { case (int)Params.usevector: if (trans) { if (value.StartsWith("1")) value = "0"; else if (value.StartsWith("2")) value = "1"; } if (value == "NULL") value = "0"; notifyUseVectorChange(!value.StartsWith("0")); break; case (int)Params.aaenabled: if (trans) { if (value.StartsWith("1")) value = "0"; else if (value.StartsWith("2")) value = "1"; } break; case (int)Params.recenable: if (trans) { if (value.StartsWith("1")) value = "0"; else if (value.StartsWith("2")) value = "1"; } break; case (int)Params.projection: notifyProjectionChange(!value.StartsWith("0")); break; case (int)Params.render_mode: if (value == "\"hardware\"" || value == "hardware") value = "1"; else if (value == "\"software\"" || value == "software") value = "0"; else if (trans) { if (value.StartsWith("1")) value = "0"; else if (value.StartsWith("2")) value = "1"; } if (type == DXTypeVals.StringType) type = DXTypeVals.FlagType; break; case (int)Params.button_up_approx: case (int)Params.button_down_approx: if (value == "\"flat\"") value = "\"none\""; break; } result = base.setInputValue(index, value, type, send); translating = trans; return result; }
/// <summary> /// For the given type, try and augment the given string value with /// syntactic sugar to coerce the given value to the given type. /// The types we can coerce are StringType, ListType, VectorType and /// TensorType. /// If the value is coerceable return a new string that does not need to /// be coerced to the given value, otherwise return NULL. /// On success, the returned string must be freed by the caller. /// </summary> /// <param name="val"></param> /// <param name="type"></param> /// <returns></returns> public static String CoerceValue(String val, DXTypeVals type) { String s; bool failed = true; if (type == DXTypeVals.ValueType) { s = DXValue.CoerceValue(val, DXTypeVals.VectorType); } else { if (val == null) s = ""; else s = val.Trim(); if ((type == DXTypeVals.StringType) || (type == DXTypeVals.WhereType)) { s = "\"" + s + "\""; } else if (type == DXTypeVals.ListType) { s = "{" + s + "}"; } else if (type == DXTypeVals.TensorType || type == DXTypeVals.VectorType) { s = "[" + s + "]"; } if (!DXValue.IsValidValue(s, type)) failed = true; else failed = false; // Try and coerce a list with a single element (i.e. coerce both the // element and the overall value. if (failed && (long)(type & DXTypeVals.ListType) > 0) { DXTypeVals basetype = type & DXTypeVals.ListTypeMask; String p = DXValue.CoerceValue(val, basetype); if (p != null) { String p2 = DXValue.CoerceValue(p, type); if (p2 != null) { s = p2; failed = false; } } } if (failed) { s = null; } } return s; }
/// <summary> /// Make sure all values (Scalar[List], Integer[List] and Vector[List] /// components) are within the given ranges for each component. /// 'val' is the given string value representing the Scalar, Integer or /// Vector and 'valtype' is expected to be its type. /// mins/maxs are arrays of minimum and maximum values for the /// corresponding components (scalar and integer only have a single /// component). /// TRUE is returned if the value needs to be clamped to be within the /// given ranges, FALSE otherwise. If clampedval is provided, then a /// string is passed back which represents the clamped value. /// </summary> /// <param name="val"></param> /// <param name="valtype"></param> /// <param name="mins"></param> /// <param name="maxs"></param> /// <param name="clampedval"></param> /// <returns></returns> public static bool ClampVSIValue(String val, DXTypeVals valtype, ref double mins, ref double maxs, ref String clampedval) { throw new Exception("Not yet implemented"); }
/// <summary> /// Replace a list item in a list value. /// null is returned on failure. Positions begin at 1. /// This works on the same list types that NextListItem() does. /// </summary> /// <param name="list"></param> /// <param name="item"></param> /// <param name="listtype"></param> /// <param name="position"></param> /// <returns></returns> public static String ReplaceListItem(String list, String item, DXTypeVals listtype, int position) { throw new Exception("Not yet implemented"); }
/// <summary> /// Get the next item from a list of the given type. /// Currently, only ScalarListType, IntegerListType, VectorListType and /// StringListType are supported. /// Search for the item is started a s[*index], and upon a successfull, /// return *index is updated to point to the character not parsed as a list. /// item. If *index is less than zero then we parse the initial list /// delimiter '{'. If buf is provided (!NULL), then the list item is copied /// into it otherwise a new string is allocated to hold the list item. In /// either case a pointer to the string holding the list item is returned . /// upon success. /// </summary> /// <param name="s"></param> /// <param name="index"></param> /// <param name="listtype"></param> /// <param name="buf"></param> /// <returns></returns> public static String NextListItem(String s, ref int index, DXTypeVals listtype, ref String buf) { throw new Exception("Not yet implemented"); }
public bool setValue(String value, DXTypeVals type, bool coerce) { bool success = false; if (this.value == null) this.value = new DXValue(); if (type == DXTypeVals.UndefinedType && value == null) { this.value = null; success = true; } else { ParameterDefinition pd = this.Definition; bool typeMatch = false; foreach (DXType dxt in pd.getTypes()) { if (DXType.MatchType(type, dxt.getType())) { typeMatch = true; break; } } if (typeMatch && ( this.value.setValue(value, type) || (coerce && this.coerceAndSetValue(value, type)))) success = true; else success = false; } if (success) { setDirty(); if (type == DXTypeVals.UndefinedType && value == null) setUnconnectedDefaultingStatus(true); else setUnconnectedDefaultingStatus(false); } return success; }
/// <summary> /// Set the value of this parameter to the value represented by v which /// must match the given type. If coerce is TRUE, then try and add /// syntactic sugar to make the value match the type. /// </summary> /// <param name="v"></param> /// <param name="t"></param> /// <param name="coerce"></param> /// <returns></returns> public bool setValue(String value, DXTypeVals type) { return setValue(value, type, true); }
/// <summary> /// Uset setValue(v,t,c) to set the stored value. /// If the parameter is not defaulting, this is /// the same as setValue, but if it is defaulting, then we set the /// value but leave the parameter clean and defaulting. /// </summary> /// <param name="value"></param> /// <param name="type"></param> /// <returns></returns> public bool setSetValue(String value, DXTypeVals type) { throw new Exception("Not Yet Implemented"); }
public ToggleNode(NodeDefinition nd, Network net, int instnc) : base(nd, net, instnc) { outputType = DXTypeVals.UndefinedType; is_set = false; }
/// <summary> /// Make sure the given output's current value complies with any attributes. /// This is called by InteractorInstance::setOutputValue() which is /// intern intended to be called by the Interactors. /// If verification fails (returns FALSE), then a reason is expected to /// placed in reason. /// At this level we always return TRUE (assuming that there are no /// attributes) and set *reason to NULL. /// </summary> /// <param name="output"></param> /// <param name="val"></param> /// <param name="t"></param> /// <param name="reason"></param> /// <returns></returns> protected virtual bool verifyValueAgainstAttributes(int output, String val, DXTypeVals t, ref String[] reason) { throw new Exception("Not Yet Implemented"); }
/// <summary> /// Make sure the given value complies with any attributes and if so /// set the value in the Node. This should generally be called from /// interactors that can't directly enforce attributes. For example, /// the Text style versus the Stepper style Vector interactor. The /// Stepper style enforces its attributes itself, but the Text style /// accepts any value and then must have the value checked for type /// and attribute compliance. /// If we fail because attribute verification fails, then *reason contains /// the reason (as passed back by verifyValueAgainstAttributes()) for /// failure. /// </summary> /// <param name="index"></param> /// <param name="val"></param> /// <param name="type"></param> /// <param name="send"></param> /// <param name="reason"></param> /// <returns></returns> public bool setAndVerifyOutput(int index, String val, DXTypeVals type, bool send, ref String reason) { throw new Exception("Not Yet Implemented"); }
public static bool IsValidValue(String str, DXTypeVals type) { bool result = false; int tuple = 0; if (str == null) return false; str = str.Trim(); if (str == "" || str.ToLower() == "null") result = true; else if (type == DXTypeVals.FlagType) { Regex r = new Regex(@"^(true|false|\d+)$"); result = r.IsMatch(str); } else if (type == DXTypeVals.IntegerType) { Regex r = new Regex(Scanning.Scanner.IntegerOnlyPattern); result = r.IsMatch(str); } else if (type == DXTypeVals.ScalarType) { Regex r = new Regex(Scanning.Scanner.DoubleOnlyPattern); result = r.IsMatch(str); } else if (type == DXTypeVals.VectorType) { result = DXTensor.IsVector(str, ref tuple); } else if (type == DXTypeVals.TensorType) { result = DXTensor.IsTensor(str); } else if (type == DXTypeVals.ValueType) { DXTypeVals value_type = DXTypeVals.UndefinedType; result = IsValue(str, ref value_type); } else if (type == DXTypeVals.StringType) { Regex r = new Regex(@"^""[^""]*""$"); result = r.IsMatch(str); } else if (type == DXTypeVals.ObjectType) { result = IsObject(str); } else if ((type & DXTypeVals.ListType) > 0) { DXTypeVals list_type = type & DXTypeVals.ListTypeMask; result = IsList(str, list_type); } else if ((type & DXTypeVals.WhereType) > 0) { Regex r = new Regex(@"^""[^""]*""$"); result = r.IsMatch(str); } else if (type == DXTypeVals.UserType1 || type == DXTypeVals.UserType2 || type == DXTypeVals.UserType4 || type == DXTypeVals.UserType5 || type == DXTypeVals.UserType6 || type == DXTypeVals.DescriptionType) { return true; } return result; }
public static bool IsValue(String str, ref DXTypeVals type) { int tuple = 0; if (str == null) return false; Regex r = new Regex(Scanning.Scanner.DoubleOnlyPattern); switch (type) { case DXTypeVals.ScalarType: return r.IsMatch(str); break; case DXTypeVals.VectorType: return DXTensor.IsVector(str, ref tuple); break; case DXTypeVals.TensorType: return DXTensor.IsTensor(str); break; default: if (r.IsMatch(str)) { type = DXTypeVals.ScalarType; return true; } if (DXTensor.IsVector(str, ref tuple)) { type = DXTypeVals.VectorType; return true; } if (DXTensor.IsTensor(str)) { type = DXTypeVals.TensorType; return true; } break; } return false; }
/// <summary> /// For the given type, try and augment the given string value with /// syntactic sugar to coerce the given value to the given type. /// The types we can coerce are StringType, ListType, VectorType and /// TensorType. /// </summary> /// <param name="value"></param> /// <param name="type"></param> /// <returns>t/f indicating whether the value was successfully set</returns> protected bool coerceAndSetValue(String value, DXTypeVals type) { String s = DXValue.CoerceValue(value, type); bool r = false; if (s != null) { r = this.value.setValue(s, type); } return r; }
public static String NextListItem(String s, ref int index, DXTypeVals listtype) { String tmp = null; return NextListItem(s, ref index, listtype, ref tmp); }
protected DXTypeVals setInputAttributeFromServer(int index, String val, DXTypeVals t) { Parameter p = getInputParameter(index); Debug.Assert(p is AttributeParameter); bool was_dirty = p.IsDirty; bool r = setInputAttributeParameter(index, val); if (!was_dirty) clearInputDirty(index); Debug.Assert(r); if (t == DXTypeVals.UndefinedType) { AttributeParameter ap = (AttributeParameter)p; t = ap.getAttributeValueType(); } return t; }
/// <summary> /// Assigns a string value of the specified type (DXType constant). /// Returns TRUE if the new value has been assigned; /// returns FALSE otherwise. /// </summary> /// <param name="str"></param> /// <param name="type"></param> /// <returns></returns> public bool setValue(String strp, DXTypeVals typep) { bool result = false; if (DXValue.IsValidValue(strp, typep)) { this.clear(); this.type.setType(typep); this.str = strp; if (String.Compare(str, "NULL", true) == 0) { this.type.setType(typep); } else { // Convert the string to internal, native form according to type double d; int v; switch (typep) { case DXTypeVals.FlagType: // The executive dow not recognize 'true' or 'false', so // we convert them to integer values. if (String.Compare(strp, "false", true) == 0) { this.integer = 0; this.scalar = 0; this.str = "0"; } else if (String.Compare(strp, "true", true) == 0) { this.integer = 1; this.scalar = 1; this.str = "1"; } else { v = int.Parse(strp); this.integer = v; d = double.Parse(strp); this.scalar = d; } break; case DXTypeVals.IntegerType: v = int.Parse(strp); this.integer = v; d = double.Parse(strp); this.scalar = d; break; case DXTypeVals.ScalarType: d = double.Parse(strp); this.scalar = d; if (strp.Contains(".")) this.str = this.scalar.ToString(); break; case DXTypeVals.VectorType: tensor = new DXTensor(); result = tensor.setValue(strp); Debug.Assert(result); break; case DXTypeVals.TensorType: case DXTypeVals.ValueType: case DXTypeVals.StringType: case DXTypeVals.ObjectType: case DXTypeVals.WhereType: case DXTypeVals.DescriptionType: break; default: if ((typep & DXTypeVals.ListType) > 0) { List<String> toks; String buf; switch (typep & DXTypeVals.ListTypeMask) { case DXTypeVals.ScalarType: // Convert '{ 1 2.0000 3.3 }' into '{ 1.0 2.0 3.3 }' // Ignore lists specified with the elipsis '{ 1..2: 3}' if (this.str.Contains(":") || this.str.Contains("..")) break; toks = Utils.StringTokenizer(strp, " ,\t{}", null); buf = "{ "; foreach (String tok in toks) { buf += double.Parse(tok).ToString("0.0") + " "; } buf += "}"; this.str = buf; break; case DXTypeVals.IntegerType: // Ignore lists specified with the ellipsis '{ 1..2:3 }' if (this.str.Contains(":") || this.str.Contains("..")) break; toks = Utils.StringTokenizer(strp, " ,\t{}", null); buf = "{ "; foreach (String tok in toks) { buf += int.Parse(tok).ToString() + " "; } buf += "}"; this.str = buf; break; case DXTypeVals.StringType: toks = Utils.StringTokenizer(strp, " ,\t{}", null); buf = "{ "; foreach (String tok in toks) { buf += tok + " "; } buf += "}"; this.str = buf; break; case DXTypeVals.FlagType: case DXTypeVals.VectorType: case DXTypeVals.TensorType: case DXTypeVals.ValueType: break; } } else if ((long)(typep & DXTypeVals.UserType1) > 0 || (long)(typep & DXTypeVals.UserType2) > 0 || (long)(typep & DXTypeVals.UserType4) > 0 || (long)(typep & DXTypeVals.UserType5) > 0 || (long)(typep & DXTypeVals.UserType6) > 0) { } else Debug.Assert(false); break; } } return true; } else return false; }
/// <summary> /// Parse the floating point numbers out of either a ScalarList or a /// VectorList. Numbers are parsed into an array created from within. /// The values are placed into the array in the order they are encountered /// in the list. In the case of VectorLists, all vectors in the list must /// be of the same dimensionality. /// The return value is the number of list items parsed out of the list. /// *data is the allocated array of values. /// *tuple is the dimensionality of the VectorList items (1 for ScalarList). /// '*tuple * return-val' is the number of items in the *data array. /// </summary> /// <param name="list"></param> /// <param name="listtype"></param> /// <param name="data"></param> /// <param name="tuple"></param> /// <returns></returns> public static int GetDoublesFromList(String list, DXTypeVals listtype, ref double[] data, ref int tuple) { throw new Exception("Not yet implemented"); }
/// <summary> /// Does the given string represent the given type? /// </summary> /// <param name="str"></param> /// <param name="type"></param> /// <returns></returns> public bool Valid(String str, DXTypeVals type) { throw new Exception("Not Yet Implemented"); }
/// <summary> /// Get the index'th list item from the given string which /// is expected to be a list. /// null is returned if the item was not found or if the listtype is wrong. /// </summary> /// <param name="list"></param> /// <param name="index"></param> /// <param name="listtype"></param> /// <returns></returns> public static String GetListItem(String list, int index, DXTypeVals listtype) { throw new Exception("Not yet implemented"); }
/// <summary> /// Calls setOutputAndOtherInteractorValues to update all interactor /// instances. /// </summary> /// <param name="index"></param> /// <param name="value"></param> /// <param name="type"></param> /// <param name="send"></param> /// <returns></returns> public override DXTypeVals setOutputValue(int index, string value, DXTypeVals type, bool send) { // Set the output value of an interactor. This is the same as for // Node::setOutputValue(), except that it also updates the interactors // in this->instanceList with // InteractorInstance->Interactor->updateDisplayedInteractorValue(). DXTypeVals dxtype; dxtype = base.setOutputValue(index, value, type, send); if ((dxtype != DXTypeVals.UndefinedType) && !isVisualNotificationDeferred()) { foreach (InteractorInstance ii in instanceList) { Interactor interactor = ii.getInteractor(); if (interactor != null) interactor.updateDisplayedInteractorValue(); } } return dxtype; }
/// <summary> /// Get the number of items in the list. /// </summary> /// <param name="list"></param> /// <param name="listtype"></param> /// <returns></returns> public static int GetListItemCount(String list, DXTypeVals listtype) { throw new Exception("Not yet implemented"); }
public ParamClass(int pIndex, int opIndex, DXTypeVals pType) { paramIndex = pIndex; oldParamIndex = opIndex; paramType = pType; category = ParamCats.unknown; }
public static bool IsList(String str, DXTypeVals type) { bool r = IsListExplicit(str, type); if (!r && ((type & DXTypeVals.ValueType) > 0)) r = IsListConstructor(str); return r; }
public static bool IsListExplicit(String str, DXTypeVals type) { bool lexed; int tuple = 0, first_tuple = -1; if (str == null) return false; str = str.Trim(); if (!str.StartsWith("{") || !str.EndsWith("}")) return false; str = str.Substring(1); str = str.Substring(0, str.Length -1); DXTypeVals value_type = DXTypeVals.UndefinedType; List<String> toks = Utils.StringTokenizer(str, " ,\t", new String[] { "\"", "[]" }); Regex r; int elements = 0; foreach (String tok in toks) { switch (type) { case DXTypeVals.FlagType: r = new Regex(@"^(true|false|\d+)$"); lexed = r.IsMatch(tok); break; case DXTypeVals.IntegerType: r = new Regex(Scanning.Scanner.IntegerOnlyPattern); lexed = r.IsMatch(tok); break; case DXTypeVals.ScalarType: r = new Regex(Scanning.Scanner.DoubleOnlyPattern); lexed = r.IsMatch(tok); break; case DXTypeVals.VectorType: lexed = DXTensor.IsVector(tok, ref tuple); if (elements == 0) first_tuple = tuple; else if (tuple != first_tuple) return false; break; case DXTypeVals.TensorType: lexed = DXTensor.IsTensor(tok); break; case DXTypeVals.ValueType: lexed = IsValue(str, ref value_type); break; case DXTypeVals.StringType: r = new Regex(@"^""[^""]*""$"); lexed = r.IsMatch(tok); break; default: return false; } if (lexed) elements++; else return false; } return true; }
private DXTypeVals setIOValueQuietly(ref List<Parameter> io, int index, String value, DXTypeVals t) { throw new Exception("Not Yet Implemented"); }