protected override bool OnClickStart(ScreenPoint cursorPos, Line cursorRay) { IDocObject selection = null; IDocObject preselection = InteractionContext.Preselection; var desFace = preselection as DesignFace; if (desFace != null) { WriteBlock.ExecuteTask("Create Sphere Set", () => selection = SphereSet.Create(desFace, count, strength, radius, color).Subject); } else { SphereSet sphereSet = SphereSet.GetWrapper(preselection as CustomObject); if (sphereSet != null) { selection = sphereSet.Subject; CountSlider.Value = sphereSet.Count; StrengthSlider.Value = sphereSet.Strength; ColorComboBox.Value = sphereSet.Color; RadiusSlider.Value = sphereSet.Radius; } } Window.ActiveContext.Selection = new[] { selection }; return(false); }
protected override bool OnClickStart(ScreenPoint cursorPos, Line cursorRay) { var iDesignFace = InteractionContext.Preselection as IDesignFace; if (iDesignFace == null) { return(false); } SurfaceEvaluation eval = iDesignFace.Shape.GetSingleRayIntersection(cursorRay); if (eval == null) { return(false); } double defaultHeight = 0.02; WriteBlock.ExecuteTask("Create Oscillator", () => { OscillatorPart.Create(HandleTypeEnum.Shaft, iDesignFace, eval.Param, defaultHeight, 0); OscillatorPart.Create(HandleTypeEnum.Base, iDesignFace, eval.Param, defaultHeight, 0); OscillatorPart.Create(HandleTypeEnum.Start, iDesignFace, eval.Param, defaultHeight, 0); OscillatorPart.Create(HandleTypeEnum.End, iDesignFace, eval.Param, defaultHeight, 0); }); return(false); }
void FreezeThread() { WaitHandle[] waitHandles = new WaitHandle[] { exitThreadEvent }; int step = 0; int sleep = 100; // 10 frames per second while (EventWaitHandle.WaitAny(waitHandles, 0, false) != 0) { System.Windows.Forms.Application.OpenForms[0].BeginInvoke(new MethodInvoker(delegate { // wrap to make thread-safe WriteBlock.ExecuteTask("Iterate Freeze", delegate { foreach (IDocObject docObject in Window.ActiveWindow.ActiveContext.Selection) { ITransformable geometry = docObject as ITransformable; //if (geometry == null) // geometry = docObject.GetParent<IDesignBody>(); if (geometry == null) { return; } Matrix newTrans = Window.ActiveWindow.Projection.Inverse * StartViewTrans; geometry.Transform(newTrans * LastTrans.Inverse); LastTrans = newTrans; } }); })); Thread.Sleep(sleep); step++; } }
void AnimateThread() { WaitHandle[] waitHandles = new WaitHandle[] { exitThreadEvent }; int step = 0; startTime = DateTime.Now; int sleep = 100; // 10 frames per second while (EventWaitHandle.WaitAny(waitHandles, 0, false) != 0) { System.Windows.Forms.Application.OpenForms[0].BeginInvoke(new MethodInvoker(delegate { // wrap to make thread-safe WriteBlock.ExecuteTask("Iterate Animation", delegate { double time = (DateTime.Now - startTime).TotalSeconds; foreach (Component component in componentAnimations.Keys) { component.Placement = Matrix.Identity; component.Transform(componentAnimations[component].GetTransform(time)); } }); })); Thread.Sleep(sleep); step++; } }
private void StartThreadImages() { isThreadRunning = true; Part mainPart = Window.ActiveWindow.Scene as Part; thread = new System.Threading.Thread((System.Threading.ThreadStart) delegate { while (isThreadRunning) { buttonCapsule.UpdateProperties(); // Window.ActiveWindow.SetProjection(Matrix.CreateRotation(Line.Create(Point.Origin, Direction.DirY), 2 * Math.PI / 300) * Window.ActiveWindow.Projection, false, false); WriteBlock.ExecuteTask("Save JPEG", delegate { lawson.CreateCircularTabsOnly(mainPart); Window.ActiveWindow.Export(WindowExportFormat.Jpeg, System.IO.Path.GetTempPath() + lawson.Iteration.ToString("TumbleFrame{0000.}.jpg")); foreach (Component component in mainPart.Components) { component.Delete(); } } ); lawson.Iterate(); // Rendering = Graphic.Create(null, null, LawsonRelaxGraphics.GetGraphic(lawson)); StatusText = string.Format("Iteration {0} Error {1} Max {2}", lawson.Iteration, lawson.CumulativeError, lawson.MaxError); } }); thread.Start(); }
void WiggleThread() { WaitHandle[] waitHandles = new WaitHandle[] { exitThreadEvent }; int step = 0; DateTime startTime = DateTime.Now; int sleep = 200; // 5 frames per second while (EventWaitHandle.WaitAny(waitHandles, 0, false) != 0) { System.Windows.Forms.Application.OpenForms[0].BeginInvoke(new MethodInvoker(delegate { // wrap to make thread-safe WriteBlock.ExecuteTask("Iterate Wiggle", delegate { double time = (DateTime.Now - startTime).TotalSeconds; wiggleGroup.SetDimensionValue(wiggleInitialValue + wiggleAmplitude * Math.Sin(time * 2 * Math.PI / wiggleFrequency)); //foreach (IDocObject docObject in Window.ActiveWindow.Selection) { // ITransformable geometry = docObject as ITransformable; // //if (geometry == null) // // geometry = docObject.GetParent<IDesignBody>(); // if (geometry == null) // return; // Matrix newTrans = Window.ActiveWindow.Projection.Inverse * StartViewTrans; // geometry.Transform(newTrans * LastTrans.Inverse); // LastTrans = newTrans; //} }); })); Thread.Sleep(sleep); step++; } }
void Document_DocumentRemoved(object sender, SubjectEventArgs <Document> e) { Document.DocumentRemoved -= Document_DocumentRemoved; WriteBlock.AppendTask(() => { Document.Open(mFilePath, null); }); }
void TumbleThread() { WaitHandle[] waitHandles = new WaitHandle[] { exitThreadEvent }; int step = 0; int savingImagesStartStep = step; int sleep = 1000 / 40; // 40 frames per second Matrix transformStep; Part part = Window.ActiveWindow.Scene as Part; while (EventWaitHandle.WaitAny(waitHandles, 0, false) != 0) { // System.Windows.Forms.Application.OpenForms[0].Invoke(new MethodInvoker(delegate { // wrap to make thread-safe System.Windows.Forms.Application.OpenForms[0].BeginInvoke(new MethodInvoker( delegate { // wrap to make thread-safe double timeScale = speed * sleep / (1000 * 60); transformStep = Iterate(timeScale * 2 * Math.PI, step); if (!isCenteredOnSelection) { Window.ActiveWindow.SetProjection(transformStep * Window.ActiveWindow.Projection, false, false); } else { Matrix translation = Matrix.CreateTranslation(Window.ActiveWindow.Projection * Center.Vector); Window.ActiveWindow.SetProjection(translation * transformStep * translation.Inverse * Window.ActiveWindow.Projection, false, false); } if (IsChangingColors) { // Command.GetCommand("AEColorsVaryHue").Execute(); WriteBlock.ExecuteTask("Set Colors", delegate { foreach (IDesignBody iDesBody in part.GetDescendants <IDesignBody>()) { HSBColor HsbColor = new HSBColor(iDesBody.Master.GetVisibleColor()); HsbColor.H += (float)360 * (float)timeScale; iDesBody.Master.SetColor(null, HsbColor.Color); } } ); } if (IsSavingImages) { if (step - savingImagesStartStep < 1 / timeScale) { WriteBlock.ExecuteTask("Save PNG", delegate { Window.ActiveWindow.Export(WindowExportFormat.Png, System.IO.Path.GetTempPath() + step.ToString("TumbleFrame{0000.}.png")); } ); } } step++; } )); Thread.Sleep(sleep); } }
private void WriteToFile(byte[] hash) { var block = new WriteBlock { Filename = _filename.Value, Hash = hash }; _writeBuffer.Post(block); }
void Document_DocumentRemoved(object sender, SubjectEventArgs <Document> e) { Document.DocumentRemoved -= Document_DocumentRemoved; WriteBlock.AppendTask(() => { var windows = Document.Open(mFilePath, null); Window.ActiveWindow = windows.First(); }); }
private void ApplicationVersion() { WriteBlock.AppendTask(() => { var appVer = Application.Version; MessageBox.Show( "ReleaseNumber = " + appVer.ReleaseNumber + Environment.NewLine + "ServicePack = " + appVer.ServicePack, "Application.Version"); }); }
void radiusSliderCommand_TextChanged(object sender, CommandTextChangedEventArgs e) { radius = RadiusSlider.Value; SphereSet sphereSet = SelectedSphereSet; if (sphereSet != null) { WriteBlock.ExecuteTask("Adjust radius", () => sphereSet.Radius = radius); } }
void colorCommand_TextChanged(object sender, CommandTextChangedEventArgs e) { color = ColorComboBox.Value; SphereSet sphereSet = SelectedSphereSet; if (sphereSet != null) { WriteBlock.ExecuteTask("Adjust color", () => sphereSet.Color = color); } }
void strengthSliderCommand_TextChanged(object sender, CommandTextChangedEventArgs e) { strength = StrengthSlider.Value; SphereSet sphereSet = SelectedSphereSet; if (sphereSet != null) { WriteBlock.ExecuteTask("Adjust radius", () => sphereSet.Strength = strength); } }
public void Reset() { WriteBlock.ExecuteTask("Reset Animation", delegate { startTime = DateTime.Now; foreach (Component component in componentAnimations.Keys) { component.Placement = componentAnimations[component].InitialPosition; } }); }
private void CreatePanelTab() { WriteBlock.AppendTask(() => { var command = Command.Create(Guid.NewGuid().ToString()); command.Image = Resources.robot; command.Text = "PanelTab Created by EllieWare"; command.IsVisible = true; var tab = PanelTab.Create(command, new TextBox(), Panel.Structure); }); }
/// <summary> /// Procesa una exportación de una consulta a un archivo parquet /// </summary> public long Write(System.Data.IDataReader reader, int rowGroupSize = 45_000) { long records = 0; List <(string, FieldType)> columns = GetColumnsSchema(reader); // Obtiene la información de zona horario try { _timeZoneCentral = TimeZoneInfo.FindSystemTimeZoneById("Central Standard Time"); } catch { _timeZoneCentral = TimeZoneInfo.Local; } // Escribe en el archivo using (System.IO.FileStream stream = System.IO.File.Open(FileName, System.IO.FileMode.Create, System.IO.FileAccess.Write)) { Schema schema = GetSchema(columns); using (ParquetWriter writer = new ParquetWriter(schema, stream)) { Table table = new Table(schema); // Establece el método de compresión //? No asigna el nivel de compresión: deja el predeterminado para el método writer.CompressionMethod = CompressionMethod.Snappy; // Carga los registros y los va añadiendo a la lista para meterlos en un grupo de filas while (reader.Read()) { // Escribe la tabla en el archivo si se ha superado el número máximo de filas if (table.Count >= rowGroupSize) { // Escribe la tabla en un grupo de filas FlushRowGroup(writer, table); // Limpia la tabla table.Clear(); } // Añade los datos del registro a la lista table.Add(ConvertData(reader, columns)); // Lanza el evento de progreso if (++records % NotifyAfter == 0) { WriteBlock?.Invoke(this, new EventArguments.AffectedEvntArgs(records)); } } // Graba las últimas filas FlushRowGroup(writer, table); } } // Devuelve el número de registros escritos return(records); }
// static Create method follows the API convention and parent should be first argument public static FaceToolPathObject Create(IDesignFace desFace, FaceToolPath toolPath, Color color) { Debug.Assert(desFace == null || desFace.Master.Shape == toolPath.Face); FaceToolPathObject toolPathObj = null; WriteBlock.ExecuteTask("New toolpath", () => toolPathObj = new FaceToolPathObject(desFace, toolPath, color)); toolPathObj.Initialize(); // IList<CutterLocation> cutterLocations; // toolPath.TryGetCutterLocations(out cutterLocations); // toolPathObj.cutterLocations = cutterLocations; return(toolPathObj); }
private void ColorFaceRed() { WriteBlock.AppendTask(() => { var ctx = Window.ActiveWindow.ActiveContext; var selection = ctx.Selection; var desFaces = selection.OfType <DesignFace>(); foreach (var thisDesFace in desFaces) { thisDesFace.SetColor(null, Color.Red); } }); }
private static T DoInWriteBlock <T>(Func <T> func) { if (WriteBlock.IsActive) { return(func()); } else { T result = default(T); WriteBlock.ExecuteTask("API busywork", () => { result = func(); }); return(result); } }
private void Reload() { WriteBlock.AppendTask(() => { Document.DocumentRemoved += Document_DocumentRemoved; mFilePath = Window.ActiveWindow.Document.Path; var allWindows = Window.GetWindows(Window.ActiveWindow.Document); foreach (var thisWindow in allWindows) { thisWindow.Close(); } }); }
public override int Advance(int frame) { Debug.Assert(frame >= 1); SphereSet sphereSet = DistributeSpheresTool.SelectedSphereSet; if (sphereSet == null) { return(frame); } WriteBlock.ExecuteTask("Animate Spheres", () => CalculateFrame(sphereSet)); return(frame + 2); }
protected override void OnEnable(bool enable) { if (enable) { Window.SelectionChanged += Window_SelectionChanged; HandleSelectionChanged(); } else { Window.SelectionChanged -= Window_SelectionChanged; if (prototypeObj != null && !prototypeObj.IsDeleted) { WriteBlock.ExecuteTask("Delete path", () => prototypeObj.Delete()); } } }
public override void SaveFile(string path) { mainPart = Window.ActiveWindow.Scene as Part; if (mainPart == null) { return; } path = mainPart.Document.Path; WriteBlock.ExecuteTask("Adjust visibility", new Task(delegate { mainPart.Export(PartExportFormat.Step, path, true, null); })); path = Path.Combine(Path.GetDirectoryName(path), Path.GetFileNameWithoutExtension(path)); foreach (IComponent component in mainPart.Components) { RecurseComponents(path, component); } }
public override bool Run() { var evt = new AutoResetEvent(false); var retVal = false; WriteBlock.AppendTask(() => { try { retVal = DoRun(); } finally { evt.Set(); } }); return(evt.WaitOne(60000) && retVal); }
protected override bool OnClickStart(ScreenPoint cursorPos, Line cursorRay) { DesignFace designFace = InteractionContext.Preselection as DesignFace; if (designFace == null) { return(false); } CurveSegment innerCurve, outerCurveA, outerCurveB; CreateThreadCurves(designFace.Shape, pitch, angle, positionOffset, out innerCurve, out outerCurveA, out outerCurveB); WriteBlock.ExecuteTask(Resources.ThreadStructureText, () => { DesignBody.Create(designFace.Parent.Parent, Resources.ThreadStructureText, CreateThreadBody(designFace.Shape, pitch, angle, positionOffset)); }); return(false); }
public bool Run() { var evt = new AutoResetEvent(false); var retVal = false; WriteBlock.AppendTask(() => { try { retVal = DoRun(); } finally { evt.Set(); } }); // allow 1 hour for timeout return(evt.WaitOne(60 * 60 * 1000) && retVal); }
protected override bool OnClickStart(ScreenPoint cursorPos, Line cursorRay) { DesignEdge designEdge = InteractionContext.Preselection as DesignEdge; if (designEdge == null) { return(false); } Circle edgeCircle = (Circle)designEdge.Shape.Geometry; Frame frame = edgeCircle.Frame; Face face = designEdge.Faces.Where(f => f.Shape.Geometry is Plane).First().Shape; Plane plane = (Plane)face.Geometry; if (frame.DirZ == plane.Frame.DirZ ^ !face.IsReversed) { frame = Frame.Create(frame.Origin, -frame.DirZ); } double angle = apiGroove.Angle; double depth = apiGroove.Depth; var points = new[] { Point.Create(apiGroove.InnerDiameter / 2, 0, 0), Point.Create(apiGroove.InnerDiameter / 2 + Math.Sin(angle) * depth, 0, -Math.Cos(angle) * depth), Point.Create(apiGroove.OuterDiameter / 2 - Math.Sin(angle) * depth, 0, -Math.Cos(angle) * depth), Point.Create(apiGroove.OuterDiameter / 2, 0, 0) }; var profile = points.AsPolygon(); var path = new[] { CurveSegment.Create(Circle.Create(Frame.World, 1)) }; WriteBlock.ExecuteTask("Create Profile", () => { var body = Body.SweepProfile(Plane.PlaneZX, profile, path); body.Transform(Matrix.CreateMapping(frame)); var cutter = DesignBody.Create(designEdge.Parent.Parent, "temp", body); designEdge.Parent.Shape.Subtract(new[] { cutter.Shape }); }); return(false); }
private void RecurseComponents(string namePath, IComponent component) { if (!Directory.Exists(namePath)) { Directory.CreateDirectory(namePath); } string newNamePath = Path.Combine(namePath, component.Master.Template.Name); string fileName = newNamePath + ".stp"; if (File.Exists(fileName)) { return; } WriteBlock.ExecuteTask("Adjust visibility", new Task(delegate { foreach (IDesignBody body in mainPart.GetDescendants <IDesignBody>()) { body.SetVisibility(null, false); } foreach (IDesignBody body in component.Content.GetDescendants <IDesignBody>()) { body.SetVisibility(null, null); } mainPart.Export(PartExportFormat.Step, fileName, true, null); foreach (IDesignBody body in mainPart.GetDescendants <IDesignBody>()) { body.SetVisibility(null, null); } })); foreach (IComponent c in component.Content.Components) { RecurseComponents(newNamePath + "-", c); } }
private void RemoveFace() { WriteBlock.AppendTask(() => { try { var ctx = Window.ActiveWindow.ActiveContext; var selection = ctx.Selection; var desFaces = selection.OfType <DesignFace>(); var modFaces = from thisDesFace in desFaces select thisDesFace.Shape; foreach (var thisModFace in modFaces) { var desBody = thisModFace.Body; desBody.DeleteFaces(new[] { thisModFace }, RepairAction.GrowSurrounding); } } catch (InvalidOperationException ex) { // Body.DeleteFaces() throws InvalidOperationException on failure MessageBox.Show(ex.Message); } }); }