public override void Validate() { if (NamedParam.ContainsKey("i") == false) { throw new Exception("Не инициализирован обязательный параметр i"); } if (File.Exists(NamedParam["i"]) == false) { throw new FileNotFoundException($"{NamedParam["i"]} not found"); } if (NamedParam.ContainsKey("gi") == false) { throw new Exception("Не инициализирован обязательный параметр gi"); } if (File.Exists(NamedParam["gi"]) == false) { throw new FileNotFoundException($"{NamedParam["gi"]} not found"); } if (NamedParam.ContainsKey("o") == false) { string input = NamedParam["i"]; string fDir = Path.GetDirectoryName(input); string fName = Path.GetFileNameWithoutExtension(input); string fExt = Path.GetExtension(input); NamedParam["o"] = Path.Combine(fDir, String.Concat(fName, "_o", fExt)); } input = NamedParam["i"]; output = NamedParam["o"]; guidInput = NamedParam["gi"]; }
protected static NamedParam OneOf(params NamedParam[] oneof) { NamedParam namedParam = new NamedParam("oneOf", typeof(object), null, oneof); namedParam.IsOneOf = true; return(namedParam); }
public override void MakeInfo() { Description = "List or do animation or gesture on Simulator."; Details = AddUsage("anim", "just lists anims currently running") + AddUsage("anim stopall +HOVER 5 +23423423423-4234234234-234234234-23423423 10 -CLAP", "stop all current anims, begin hover, wait 5 seconds, begin clapping (used uuid), wait 10 seconds, stop clapping (used name)"); //// we dont use sequenceOf here... for ideas NamedParam sequenceOf = SequenceOf("doList", OneOf( Required("asset_0-N", typeof(SimAsset), "+/-animuuid"), Required("stopall", typeof(bool), "stops all current anims/played items"), Required("seconds", typeof(int), "how long to pause for"))); Category = CommandCategory.Appearance; AddVersion(CreateParams("dolist", typeof(string[]), "asset play list"), "run the anim list"); AddVersion(CreateParams(), "just lists anims currently running"); ResultMap = CreateParams( "assets", typeof(List <SimAnimation>), "list of assets like animations and gestures played", "message", typeof(string), "if success was false, the reason why", "success", typeof(bool), "true if command was successful"); }
public override void Validate() { if (NamedParam.ContainsKey("if") == false) { throw new Exception("Не инициализирован обязательный параметр if"); } if (Directory.GetFiles(NamedParam["if"], "*.csv").Length == 0) { throw new FileNotFoundException($"{NamedParam["if"]} пустая"); } if (NamedParam.ContainsKey("o") == false) { string input = NamedParam["i"]; string fDir = Path.GetDirectoryName(input); string fName = Path.GetFileNameWithoutExtension(input); string fExt = Path.GetExtension(input); NamedParam["o"] = Path.Combine(fDir, String.Concat(fName, "_o", fExt)); } if (NamedParam.ContainsKey("so") == false) { string input = NamedParam["i"]; string fDir = Path.GetDirectoryName(input); string fName = Path.GetFileNameWithoutExtension(input); string fExt = Path.GetExtension(input); NamedParam["so"] = Path.Combine(fDir, String.Concat(fName, "_s", fExt)); } inputFolder = NamedParam["if"]; output = NamedParam["o"]; statisticOutput = NamedParam["so"]; }
protected static KeyParams CreateParams(params object[] paramz) { List <NamedParam> paramsz = new List <NamedParam>(); int argNum = 1; for (int i = 0; i < paramz.Length;) { var o = paramz[i++]; if (o is NamedParam) { paramsz.Add((NamedParam)o); continue; } if (o is string) { string k = (string)o; Type t = paramz[i++] as Type; string comment = "" + paramz[i++]; NamedParam namedParam = new NamedParam(k, t); namedParam.Comment = comment; paramsz.Add(namedParam); } else { throw new FormatException("CreateParams: " + o); } } return(new KeyParams(paramsz.ToArray())); }
protected static NamedParam SequenceOf(string key, NamedParam param) { NamedParam namedParam = new NamedParam(key, param.Type.MakeArrayType(), param); namedParam.Comment = "list of " + param.Key; namedParam.IsSequence = true; return(namedParam); }
protected static NamedParam Rest(string key, Type type, string description) { NamedParam namedParam = new NamedParam(key, type); namedParam.Comment = description; namedParam.IsRest = true; return(namedParam); }
static public NamedParam ToParameter(string p, object s) { while (s is NamedParam) { NamedParam nv = (NamedParam)s; s = nv.Value; } return(new NamedParam(p, s)); }
private string ToPLAtomStr(NamedParam nvc) { if (nvc == null) { return("_"); } return((nvc.IsOptional ? "o" : "p") + "(" + ToPLAtomStr(nvc.Key) + "," + ToPLAtomStr(nvc.Type) + "," + ToPLAtomStr(nvc.Comment) + ")"); }
protected static NamedParam OptionalFlag(string key, string description) { NamedParam namedParam = new NamedParam(key, typeof(bool)); namedParam.Comment = description; namedParam.IsOptional = true; namedParam.IsFlag = true; return(namedParam); }
public override void Validate() { if (NamedParam.ContainsKey("ai") == false) { throw new Exception("Не инициализирован обязательный параметр ai"); } if (File.Exists(NamedParam["ai"]) == false) { throw new FileNotFoundException($"{NamedParam["ai"]} not found"); } if (NamedParam.ContainsKey("ao") == false) { string input = NamedParam["ai"]; string fDir = Path.GetDirectoryName(input); string fName = Path.GetFileNameWithoutExtension(input); string fExt = Path.GetExtension(input); NamedParam["ao"] = Path.Combine(fDir, String.Concat(fName, "_o", fExt)); } if (Keys.IndexOf("merge") == -1) { merge = false; } else { if (File.Exists(NamedParam["ao"]) == true) { merge = true; } else { merge = false; } } aInput = NamedParam["ai"]; aOutput = NamedParam["ao"]; }
static public object GetScriptableObject(object id) { if (id is NamedParam) { NamedParam kv = (NamedParam)id; id = new NamedParam(kv.Key, GetScriptableObject(kv.Value)); } if (id is UUID) { UUID uid = (UUID)id; if (uid == UUID.Zero) return id; id = GridMaster.GetObject(uid); } if (id is Primitive) return GridMaster.GetSimObject((Primitive)id); // if (id is String) return Master.GetObject((string) id); return id; }
public override bool BooleanOnEvent(string eventName, string[] paramNames, Type[] paramTypes, params object[] parameters) { if (eventName.EndsWith("On-Image-Receive-Progress")) return true; if (eventName.EndsWith("On-Log-Message")) return true; if (eventName.EndsWith("Look-At")) return true; var parms = new NamedParam[paramNames.Length]; for (int i = 0; i < paramNames.Length; i++) { parms[i] = new NamedParam(paramNames[i], paramTypes[i],parameters[i]); } CogbotEvent evt = ACogbotEvent.CreateEvent(client, eventName, SimEventType.Once | SimEventType.UNKNOWN | SimEventType.REGIONAL, parms); client.SendPipelineEvent(evt); return true; }
public double GetNamedParameter(NamedParam param) { double value = 0d; switch (param) { case NamedParam.vmajor: value = 1d; break; case NamedParam.vminor: value = 1d; break; case NamedParam.line: value = machine.Line; break; case NamedParam.motion_mode: value = (double)machine.MotionMode; break; case NamedParam.plane: value = 170d + (double)machine.Plane.Plane * 10d; break; case NamedParam.ccomp: value = 400d; break; case NamedParam.metric: value = machine.IsImperial ? 0d : 1d; break; case NamedParam.imperial: value = machine.IsImperial ? 1d : 0d; break; case NamedParam.absolute: value = machine.DistanceMode == GCode.DistanceMode.Absolute ? 1d : 0d; break; case NamedParam.incremental: value = machine.DistanceMode == GCode.DistanceMode.Incremental ? 1d : 0d; break; case NamedParam.inverse_time: value = machine.FeedRateMode == GCode.FeedRateMode.InverseTime ? 1d : 0d; break; case NamedParam.units_per_minute: value = machine.FeedRateMode == GCode.FeedRateMode.UnitsPerMin ? 1d : 0d; break; case NamedParam.units_per_rev: value = machine.FeedRateMode == GCode.FeedRateMode.UnitsPerRev ? 1d : 0d; break; case NamedParam.coord_system: value = 540d + (machine.CoordSystem == 0 ? 0 : (machine.CoordSystem <= 6 ? (machine.CoordSystem - 1) * 10 : 44 + machine.CoordSystem)); break; case NamedParam.tool_offset: value = machine.ToolLengthOffset == GCode.ToolLengthOffset.Cancel ? 0d : 1d; break; case NamedParam.retract_r_plane: value = machine.RetractOldZ ? 0d : 1d; break; case NamedParam.retract_old_z: value = machine.RetractOldZ ? 1d : 0d; break; case NamedParam.spindle_rpm_mode: value = machine.SpindleRpmMode ? 1d : 0d; break; case NamedParam.spindle_css_mode: value = machine.SpindleRpmMode ? 0d : 1d; break; case NamedParam.ijk_absolute_mode: value = machine.IJKMode == GCode.IJKMode.Absolute ? 1d : 0d; break; case NamedParam.lathe_diameter_mode: value = machine.LatheMode != GCode.LatheMode.Radius ? 1d : 0d; break; case NamedParam.lathe_radius_mode: value = machine.LatheMode == GCode.LatheMode.Radius ? 1d : 0d; break; case NamedParam.spindle_on: value = machine.SpindleState != GCode.SpindleState.Off ? 1d : 0d; break; case NamedParam.spindle_cw: value = machine.SpindleState == GCode.SpindleState.CW ? 1d : 0d; break; case NamedParam.mist: value = machine.CoolantState.HasFlag(GCode.CoolantState.Mist) ? 1d : 0d; break; case NamedParam.flood: value = machine.CoolantState.HasFlag(GCode.CoolantState.Flood) ? 1d : 0d; break; case NamedParam.speed_override: value = 0d; // TODO break; case NamedParam.feed_override: value = 0d; // TODO break; case NamedParam.adaptive_feed: value = 0d; break; case NamedParam.feed_hold: value = 0d; // TODO break; case NamedParam.feed: value = machine.Feedrate; break; case NamedParam.rpm: value = machine.SpindleRPM; break; case NamedParam.x: case NamedParam.y: case NamedParam.z: case NamedParam.a: case NamedParam.b: case NamedParam.c: value = machine.GetPosition(param - NamedParam.x); break; case NamedParam.u: case NamedParam.v: case NamedParam.w: value = 0d; break; case NamedParam.current_tool: value = machine.Tool; break; case NamedParam.selected_tool: value = machine.SelectedTool == null ? -1d : double.Parse(machine.SelectedTool.Code); break; case NamedParam.current_pocket: value = 0d; break; case NamedParam.selected_pocket: value = -1d; break; default: value = double.NaN; break; } return(value); }