private static void SaveToolingFile(Tooling tooling, string toolingFile) { var serializer = new System.Xml.Serialization.XmlSerializer(typeof(Tooling)); using (var writer = new System.IO.StreamWriter(toolingFile)) { serializer.Serialize(writer, tooling); } }
private void UpdateModelsFiles(Tooling tooling, string extractPath, bool save = false) { tooling.MachineFile = $"{extractPath}\\{_machineFileName}"; tooling.ToolsFile = $"{extractPath}\\{_tooSetFileName}"; if (save) { var toolingFile = $"{extractPath}\\{_toolingFileName}"; SaveToolingFile(tooling, toolingFile); } }
private void UpdateModelsFiles(Tooling tooling, string machineName, string extractPath, bool save = false) { tooling.Machine = $"{extractPath}\\{machineName}.json"; tooling.Tools = $"{extractPath}\\{_toolSetFileName}"; if (save) { var toolingFile = $"{extractPath}\\{_toolingFileName}"; DataSource.SaveTooling(toolingFile, tooling); } }
private bool AddToolingFileToArchive(Tooling tooling, ZipArchive archive) { FilterModelsNames(tooling); var serializer = new System.Xml.Serialization.XmlSerializer(typeof(Tooling)); var entry = archive.CreateEntry(_toolingFileName); using (var writer = new StreamWriter(entry.Open())) { serializer.Serialize(writer, tooling); } return(true); }
private void OnGetActiveTooling(GetActiveTooling msg) { var tooling = new Tooling() { Units = new List <ToolingUnit>() }; if (Elements.Count() > 0) { GetActiveTooling(Elements[0], tooling); } msg.Set(tooling); }
void Initialize() { _OnDrawGizmos = null; if (controlPoints.Length != 4) { throw new UnityException("Should give 4 control points"); } Vector3[] finalControlPoints = controlPoints.Select(v => { Vector3 ret = v; ret.z = transform.position.z; return(ret); }).ToArray(); _OnDrawGizmos += () => { Gizmos.color = Color.cyan; foreach (var controlPoint in finalControlPoints) { Gizmos.DrawSphere(transform.TransformPoint(scale * controlPoint), 0.6f); } }; var func = Tooling.SinusoidalFromBezierCubic01(finalControlPoints); lineRenderer.positionCount = nSegments * 2 + 1; for (int i = 0; i < nSegments * 2 + 1; i++) { float t = (float)i / (nSegments * 2); Vector3 point = func(t); if (t > 0.5) { point.x = 2 - point.x; } Debug.Log($"i {i} t {t} point {point}"); Vector3 worldPoint = transform.TransformPoint(scale * point); _OnDrawGizmos += () => { Gizmos.color = Color.Lerp(Color.yellow, Color.red, t); Gizmos.DrawSphere(worldPoint, 0.5f); }; lineRenderer.SetPosition(i, worldPoint); } }
private void GetActiveTooling(MachineElementViewModel vm, Tooling tooling) { if (vm is IToolHolderManagement thm) { if (thm.IsToolPresent) { if (thm is IToolingUnitProvider tup) { tooling.Units.Add(tup.GetToolingUnit()); } } } else if (vm.Children.Count() > 0) { foreach (var item in vm.Children) { GetActiveTooling(item, tooling); } } }
void Initialize() { _OnDrawGizmos = null; if (controlPoints.Length != 4) { throw new UnityException("Should give 4 control points"); } Vector3[] finalControlPoints = controlPoints.Select(v => { Vector3 ret = v; ret.z = transform.position.z; return(ret); }).ToArray(); _OnDrawGizmos += () => { Gizmos.color = Color.cyan; foreach (var controlPoint in finalControlPoints) { Gizmos.DrawSphere(transform.TransformPoint(scale * controlPoint), 0.6f); } }; lineRenderer.positionCount = nSegments + 1; for (int i = 0; i < nSegments + 1; i++) { var t = (float)i / nSegments; Vector3 point = Tooling.GetBezierCurvePoint(t, finalControlPoints); if (modifierX != null) { point.x = modifierX.Modify(point.x); } if (modifierY != null) { point.y = modifierY.Modify(point.y); } var worldPoint = transform.TransformPoint(scale * point); _OnDrawGizmos += () => { Gizmos.color = Color.Lerp(Color.yellow, Color.red, modifierX != null ? modifierX.Modify(t) : t); Gizmos.DrawSphere(worldPoint, 0.5f); }; lineRenderer.SetPosition(i, worldPoint); } }
//pass in list of spacers and whole part of mult width public static List <Tooling> Sum_Whole(List <decimal> spacers, decimal mult) { //decimal startMult = mult; //List<Tooling> wholeSetup = new List<Tooling>(); for (int i = 0; i < spacers.Count; i++) { // create new tooling object. Function return a list of these objects. Tooling t = new Tooling(); // get current space from list (ie: 3.2, 1.8, 0.1 and so on) decimal n = spacers[i]; // Find largest integer <= mult / current spacer decimal numSp = Math.Floor(mult / n); // if spacer > mult, numSp = 0 // don't execute until spacer < mult if (numSp != 0) { // Create tooling object t.loc = "arbor"; t.tp = "whole"; t.qty = Convert.ToInt16(numSp); t.sz = n; // Add tooling object to list wholeSetup.Add(t); // subract spacer from mult balance mult = mult - numSp * n; } } return(wholeSetup); }
private void FilterModelsNames(Tooling tooling) { tooling.MachineFile = _machineFileName; tooling.ToolsFile = _tooSetFileName; }
/// <summary> /// Compiles SQL command interpolating all the entities /// </summary> /// <param name="command">Sql command to compile</param> /// <returns>Interpolated query with extracted parameters</returns> public InterpolatedQuery Compile(Sql command) { return(Tooling.Compile(command)); }
void FixedUpdate() { _OnDrawGizmos = null; Vector3 gravity = (planet.transform.position - transform.position).normalized; Vector3 groundDirection = gravity; // TODO shift it with velocity Ray groundRay = new Ray(transform.position, groundDirection); RaycastHit groundHit; if (Physics.Raycast(groundRay, out groundHit, Mathf.Infinity, ~terrainLayer)) { float hoverDelta = altitude - groundHit.distance; Vector3 velocity = m_rigidbody.velocity; float upwardSpeed = (transform.worldToLocalMatrix * velocity).y; float lift = hoverDelta * Mathf.Pow(hoverForce, 2); lift += (1 * Mathf.Sign(hoverDelta)) * hoverAmplitude * hoverSinusoidal((Time.fixedTime % hoverPeriod) / hoverPeriod).y / lift; // Debug.Log($"lift {lift} velocity.y {velocity.y} upwardSpeed {upwardSpeed}"); m_rigidbody.AddForce(lift * -groundDirection, ForceMode.Acceleration); } Vector3 transformUp = transform.up; Vector3 forwardShift = Vector3.Cross(groundDirection, transform.right).normalized; // Debug.Log("dot gravity transformDown" + Vector3.Dot(gravity, transformUp)); // Debug.DrawRay(transform.position, transform.forward, Color.red); // Debug.DrawRay(transform.position, forwardShift, Color.green); forwardShift *= Mathf.Sign(Vector3.Dot(transform.forward, forwardShift)) * shipRadius; Vector3 groundNormal = transform.GetGroundNormal(planet, groundDirection, terrainLayer); Plane gravityPlane = new Plane(-gravity, transform.position); Debug.DrawRay(transform.position, groundNormal, Color.cyan); Quaternion rotateToGround = Quaternion.FromToRotation(transform.up, groundNormal); rotateToGround = _rotateToGround = Quaternion.SlerpUnclamped(_rotateToGround, rotateToGround, 30 * Time.fixedDeltaTime); // Debug.Log("groundNormal " + groundNormal + " magnitude " + groundNormal.magnitude + " rotateToGround " + rotateToGround); Vector3 _mouseDirection = Vector3.zero; Vector2 mousePosition = Mouse.current.position.ReadValue(); Ray mouseRay = m_camera.ScreenPointToRay(mousePosition); // Debug.Log("dot gravity groundNormal: " + Vector3.Dot(gravity, groundNormal)); float enter; if (gravityPlane.Raycast(mouseRay, out enter)) { Vector3 hitPoint = mouseRay.GetPoint(enter); _mouseDirection = (hitPoint - transform.position).normalized; _OnDrawGizmos += () => { // Gizmos.DrawSphere(hitPoint, 0.1f); // Gizmos.color = Color.cyan; // CGizmos.DrawPlane(gravityPlane, transform.position, 0.25f * Vector3.one); }; } Plane normalPlane = new Plane(groundNormal, transform.position); Vector3 mouseDirection = Vector3.ProjectOnPlane(_mouseDirection, groundNormal).normalized; _OnDrawGizmos += () => { // Gizmos.color = Color.magenta; // CGizmos.DrawPlane(normalPlane, transform.position, 0.25f * Vector3.one); // Gizmos.color = Color.black; // Gizmos.DrawRay(transform.position, _mouseDirection); // Gizmos.color = Color.yellow; // Gizmos.DrawRay(transform.position, mouseDirection); }; Quaternion rotateToMouseDirection = Quaternion.FromToRotation(transform.forward, mouseDirection); // Debug.Log($"unit length: rotateToMouseDirection {rotateToMouseDirection} rotateToGround {rotateToGround}"); m_rigidbody.MoveRotation( rotateToMouseDirection.normalized * rotateToGround.normalized * m_rigidbody.rotation ); float t = 0; var ctx2 = lastMoves.Get(2); var ctx1 = lastMoves.Get(1); Vector2 move1 = ctx1?.value ?? Vector2.zero; var ctx0 = lastMoves.ElementAtOrDefault(0); Vector2 move0 = ctx0.value; double moveDeltaTime = Time.realtimeSinceStartupAsDouble - ctx0.time; double delay = ctx0.time - (ctx1?.time ?? -1); if ((move1.magnitude == 0 || move0.magnitude == 0) && (delay > delayBeforeStop)) // stop or go { t = (float)moveDeltaTime / accelerationTime; } else // only direction change { t = 1; } float kvelocity = Tooling.GetBezierCubicPoint(Mathf.Clamp01(t), speedCurve).y; if (move0.magnitude == 0) { kvelocity = 1 - kvelocity; } bool same = ctx0.Equals(ctx2); // choose the move direction from the last move or not Vector2 _moveDirection = move0.magnitude == 0 ? move1 // deceleration : move0 // acceleration ; _moveDirection.Normalize(); Resolution resolution = Screen.currentResolution; Ray forwardRay = m_camera.ScreenPointToRay(new Vector2(resolution.width / 2, resolution.height)); if (gravityPlane.Raycast(forwardRay, out enter)) { Vector3 hitPoint = forwardRay.GetPoint(enter); Vector3 mouseForward = (hitPoint - transform.position).normalized; Vector3 moveDirection = Quaternion.FromToRotation(transform.forward, mouseForward) * transform.TransformDirection(_moveDirection.x, 0, _moveDirection.y); const float C = 100; m_rigidbody.velocity = C * moveDirection * kvelocity * moveSpeed * Time.deltaTime; } m_camera.transform.position = transform.position + 25 * -gravity; }
// pass in spacers, fraction part of mult width and empty list for recursion public static List <Tooling> Sum_Fraction_Recursive1(List <decimal> spacers, decimal mult, List <decimal> partial, string fName) { // Keep of list of combinations List <string> combo = new List <string>(); // variable to keep the sum of current spacer combination decimal s = 0; foreach (decimal x in partial) { s += x; } combo.Add("Partial(" + string.Join(",", partial.ToArray()) + ") - " + s.ToString()); Console.WriteLine("Partial(" + string.Join(",", partial.ToArray()) + ") - " + s.ToString()); if (s == mult) { combo.Add("Spacers(" + string.Join(",", partial.ToArray()) + ") = " + mult); Console.WriteLine("Spacers(" + string.Join(",", partial.ToArray()) + ") = " + mult); // Can have more than one correct combo, just keep the first if (fractionSetup.Count == 0) { for (int k = 0; k < partial.Count; k++) { Tooling t = new Tooling(); decimal sp = partial[k]; // Create tooling object t.loc = "arbor"; t.tp = "frac"; t.qty = 1; t.sz = sp; fractionSetup.Add(t); } } } if (s >= mult) { //Helpers.WriteList(combo, fName); return(fractionSetup); } for (int i = 0; i < spacers.Count; i++) { List <decimal> remaining = new List <decimal>(); decimal n = spacers[i]; for (int j = i + 1; j < spacers.Count; j++) { remaining.Add(spacers[j]); } List <decimal> partial_rec = new List <decimal>(partial); partial_rec.Add(n); Sum_Fraction_Recursive1(remaining, mult, partial_rec, fName); } //Helpers.WriteList(combo, fName); return(fractionSetup); }
// pass in spacers, fraction part of mult width and empty list for recursion public static List <Tooling> Sum_Fraction_Recursive(List <decimal> spacers, decimal mult, List <decimal> partial) { // variable to keep the sum of current spacer combination decimal s = 0; foreach (decimal x in partial) { s += x; } Console.WriteLine("Invty(" + string.Join(",", spacers.ToArray()) + ")"); Console.WriteLine("Combo(" + string.Join(",", partial.ToArray()) + ") - " + s.ToString()); // Exact match (s == mult) // Allow a match if sum of spacers is mult +/- 0.001 ((s >= (mult - 0.001m)) && (s <= (mult + 0.001m))) if (s == mult) { Console.WriteLine("Match(" + string.Join(",", partial.ToArray()) + ") = " + mult + " ***** MATCH *****"); // Can have more than one correct combo, just keep the first if (fractionSetup.Count == 0) { fnd = true; // Step through partial and create a spacer object for each item in list for (int k = 0; k < partial.Count; k++) { Tooling t = new Tooling(); decimal sp = partial[k]; // Create tooling object t.loc = "arbor"; t.tp = "frac"; t.qty = 1; t.sz = sp; // Add object to list fractionSetup.Add(t); } } return(fractionSetup); } // was s >= mult if (s > mult) { return(fractionSetup); } for (int i = 0; i < spacers.Count; i++) { // Not sure how to end recursion when match is found. // Short circuit loop by advanding to Count-1. Reduces // the remaining passes through the loop. if (fnd) { i = spacers.Count - 1; } List <decimal> remaining = new List <decimal>(); decimal n = spacers[i]; for (int j = i + 1; j < spacers.Count; j++) { remaining.Add(spacers[j]); } List <decimal> partial_rec = new List <decimal>(partial); partial_rec.Add(n); Sum_Fraction_Recursive(remaining, mult, partial_rec); } return(fractionSetup); }
public void Post([FromBody] Tooling tooling) { _db.Toolings.Add(tooling); _db.SaveChanges(); }
public void Run(CmdLine src) => Tooling.create(Wf).Run(src);