public void GenerateImage(Size size, ParameterStack stack, out Image bmp) { // check if plugin was instantiated if (null == Component) { throw new Exception("No valid plugin instance loaded!"); } // instantiate factory PicFactory factory = new PicFactory(); // generate entities Component.CreateFactoryEntities(factory, stack); // apply any needed transformation if (ReflexionX) { factory.ProcessVisitor(new PicVisitorTransform(Transform2D.ReflectionX)); } if (ReflexionY) { factory.ProcessVisitor(new PicVisitorTransform(Transform2D.ReflectionY)); } // draw image PicGraphicsImage picImage = new PicGraphicsImage(size, Factory2D.Tools.BoundingBox(factory, 0.05)); factory.Draw(picImage, ShowCotations ? PicFilter.FilterNone : !PicFilter.FilterCotation); bmp = picImage.Bitmap; }
public static void Generate(string pluginPath, out Image bmp, Size size, PicFilter filter) { // instantiate factory PicFactory factory = new PicFactory(); factory.Clear(); // instantiate plugin Pic.Plugin.PluginServices pluginHost = new Pic.Plugin.PluginServices(pluginPath); IPlugin plugin = pluginHost.GetFirstPlugin(); // generate entities ParameterStack stack = plugin.Parameters; plugin.CreateFactoryEntities(factory, stack); // get bounding box PicVisitorBoundingBox visitor = new PicVisitorBoundingBox(); factory.ProcessVisitor(visitor); // draw image PicGraphicsImage picImage = new PicGraphicsImage(); picImage.ImageSize = size; PicBox2D box = visitor.Box; box.AddMarginRatio(0.05); picImage.DrawingBox = box; factory.Draw(picImage, filter); bmp = picImage.Bitmap; }
public static void GenerateImage(Size size, PicFactory factory, bool showCotations, out Image bmp) { // get bounding box Box2D box = Tools.BoundingBox(factory, 0.05); // draw image PicGraphicsImage picImage = new PicGraphicsImage(size, box); factory.Draw(picImage, showCotations ? PicFilter.FilterNone : !PicFilter.FilterCotation); bmp = picImage.Bitmap; }
public static void GenerateImage(Size size, PicFactory factory, bool showCotations, out Image bmp) { // get bounding box PicVisitorBoundingBox visitor = new PicVisitorBoundingBox(); factory.ProcessVisitor(visitor); Box2D box = visitor.Box; box.AddMarginRatio(0.05); // draw image PicGraphicsImage picImage = new PicGraphicsImage(size, box); factory.Draw(picImage, showCotations ? PicFilter.FilterNone : PicFilter.FilterCotation); bmp = picImage.Bitmap; }
public void GenerateThumbnail() { using (PicFactory factory = new PicFactory()) { CreateEntities(factory); // insert format factory.InsertCardboardFormat(CardboardPosition, CardboardDimensions); // draw thumbnail PicGraphicsImage picImage = new PicGraphicsImage(new Size(ThumbnailWidth, ThumbnailWidth), Tools.BoundingBox(factory, PicFilter.FilterNone, 0.01)); factory.Draw(picImage); // save thumbnail Thumbnail = picImage.Bitmap; } }
public void GenerateThumbnail() { using (PicFactory factory = new PicFactory()) { CreateEntities(factory); // compute bounding box without format PicVisitorBoundingBox visitor0 = new PicVisitorBoundingBox(); factory.ProcessVisitor(visitor0); _box = visitor0.Box; // insert format factory.InsertCardboardFormat(CardboardPosition, CardboardDimensions); // compute bounding box with format PicVisitorBoundingBox visitor1 = new PicVisitorBoundingBox(); factory.ProcessVisitor(visitor1); // draw thumbnail PicGraphicsImage picImage = new PicGraphicsImage(new System.Drawing.Size(50, 50), visitor1.Box); factory.Draw(picImage); // save thumbnail _thumbnail = picImage.Bitmap; } }
/// <summary> /// Generate an image from plugin with default parameters /// </summary> /// <param name="size"></param> /// <param name="filter"></param> /// <param name="bmp"></param> public void GenerateImage(Size size, out Image bmp) { // check if plugin was instantiated if (null == _component) { throw new Exception("No valid plugin instance loaded!"); } // instantiate factory PicFactory factory = new PicFactory(); // generate entities ParameterStack stack = _component.BuildParameterStack(null); _component.CreateFactoryEntities(factory, stack); // apply any needed transformation if (_reflexionX) { factory.ProcessVisitor(new PicVisitorTransform(Transform2D.ReflectionX)); } if (_reflexionY) { factory.ProcessVisitor(new PicVisitorTransform(Transform2D.ReflectionY)); } // get bounding box PicVisitorBoundingBox visitor = new PicVisitorBoundingBox(); factory.ProcessVisitor(visitor); Box2D box = visitor.Box; box.AddMarginRatio(0.05); // draw image PicGraphicsImage picImage = new PicGraphicsImage(size, box); factory.Draw(picImage, _showCotations ? PicFilter.FilterNone : !PicFilter.FilterCotation); bmp = picImage.Bitmap; }
static void Main(string[] args) { // set up a simple configuration that logs on the console. XmlConfigurator.Configure(); string assemblyName = System.Reflection.Assembly.GetExecutingAssembly().CodeBase; try { _log.Info(assemblyName + " starting..."); const PicGraphics.LT ltCut = PicGraphics.LT.LT_CUT; // instantiate factory PicFactory initialFactory = new PicFactory(); ParameterStack stack = Program.Parameters; Program.CreateFactoryEntities(initialFactory, stack, Transform2D.Identity); // imposition double width = 1000.0, height = 1000.0; ImpositionTool impositionTool = new ImpositionToolCardboardFormat(initialFactory, new CardboardFormat(0, "Format1", "Format1", width, height)); impositionTool.SpaceBetween = new Vector2D(0.0, 0.0); impositionTool.Margin = new Vector2D(0.0, 0.0); List <ImpositionSolution> solutions; impositionTool.GenerateSortedSolutionList(null, out solutions); _log.Info(string.Format("{0} : Solutions", solutions.Count)); if (solutions.Count <= 0) { return; } foreach (ImpositionSolution chosenSolution in solutions) { _log.Info(string.Format("NoRows={0}, NoCols={1}", chosenSolution.Rows, chosenSolution.Cols)); PicFactory factoryOut = new PicFactory(); chosenSolution.CreateEntities(factoryOut); factoryOut.AddSegment(ltCut, new Vector2D(0.0, 0.0), new Vector2D(width, 0.0)); factoryOut.AddSegment(ltCut, new Vector2D(width, 0.0), new Vector2D(width, height)); factoryOut.AddSegment(ltCut, new Vector2D(width, height), new Vector2D(0.0, height)); factoryOut.AddSegment(ltCut, new Vector2D(0.0, height), new Vector2D(0.0, 0.0)); // get bounding box Box2D box = new Box2D(); using (PicVisitorBoundingBox visitor = new PicVisitorBoundingBox()) { factoryOut.ProcessVisitor(visitor); box = visitor.Box; } string filePath = Path.Combine(Path.GetTempPath(), "Imposition.bmp"); PicGraphicsImage picImage = new PicGraphicsImage(); picImage.ImageSize = new System.Drawing.Size(4096, 4096); box.AddMargin(1.0); picImage.DrawingBox = box; factoryOut.Draw(picImage); picImage.SaveAs(filePath); System.Diagnostics.Process.Start(Path.Combine(Environment.SystemDirectory, "mspaint.exe"), filePath); _log.Info(assemblyName + " ending..."); } } catch (Exception ex) { _log.Error(ex.ToString()); } }
static void Main(string[] args) { // set up a simple configuration that logs on the console. XmlConfigurator.Configure(); try { _log.Info("Pic.Factory2D.Test.exe starting..."); // testing Sharp3D.Math.Core.Matrix3D Transform2D transf0 = Transform2D.Translation(new Vector2D(10.0, 10.0)) * Transform2D.Rotation(45.0); Vector2D pt0 = transf0.transform(new Vector2D(100.0, 100.0)); _log.Info(pt0.ToString()); Transform2D transf1 = transf0.Inverse(); Vector2D pt1 = transf1.transform(pt0); _log.Info(pt1.ToString()); // instantiate factory1 PicFactory factory0 = new PicFactory(); factory0.AddPoint(PicGraphics.LT.LT_CUT, 0, 0, new Vector2D(0.0, 0.0)); factory0.AddSegment(PicGraphics.LT.LT_CUT, 0, 0, new Vector2D(50.0, 50.0), new Vector2D(100.0, 100.0)); factory0.AddSegment(PicGraphics.LT.LT_CUT, 0, 0, new Vector2D(-100.0, 100.0), new Vector2D(100.0, -100.0)); factory0.AddArc(PicGraphics.LT.LT_CUT, 0, 0, new Vector2D(50.0, 50.0), 50.0 * Math.Sqrt(2.0), 0.0, 360.0); factory0.AddArc(PicGraphics.LT.LT_CUT, 0, 0, new Vector2D(75.0, 75.0), 25.0 * Math.Sqrt(2.0), 0.0, 360.0); factory0.AddNurb(PicGraphics.LT.LT_CUT, 0, 0); _log.Debug(factory0.ToString()); // get bounding box + draw using (PicVisitorBoundingBox visitor = new PicVisitorBoundingBox()) { factory0.ProcessVisitor(visitor); _log.Info(visitor.Box.ToString()); // save as image string filePath = Path.Combine(Path.GetTempPath(), "PicImage0.jpeg"); PicGraphicsImage picImage = new PicGraphicsImage(); picImage.ImageSize = new System.Drawing.Size(512, 512); Box2D box = visitor.Box; box.AddMargin(5); picImage.DrawingBox = box; factory0.Draw(picImage); picImage.SaveAs(filePath); _log.Debug("File path = " + filePath); _log.Debug("Path = " + Path.Combine(Environment.SystemDirectory, "mspaint.exe")); System.Diagnostics.Process.Start(Path.Combine(Environment.SystemDirectory, "mspaint.exe"), filePath); } // output to dxf file Pic.Factory2D.PicVisitorDxfOutput dxfOutputVisitor = new Pic.Factory2D.PicVisitorDxfOutput(); factory0.ProcessVisitor(dxfOutputVisitor); // load dxf file PicFactory factory1 = new PicFactory(); PicLoaderDxf loaderDxf = new PicLoaderDxf(factory1); loaderDxf.Load(@"K:\Codesion\PicSharp\Samples\F1034.EV.DXF"); loaderDxf.FillFactory(); // save as image // get bounding box + draw using (PicVisitorBoundingBox visitor1 = new PicVisitorBoundingBox()) { factory1.ProcessVisitor(visitor1); _log.Info(visitor1.Box.ToString()); string filePath1 = Path.Combine(Path.GetTempPath(), "PicImage1.jpeg"); PicGraphicsImage picImage1 = new PicGraphicsImage(); picImage1.ImageSize = new System.Drawing.Size(512, 512); Box2D box1 = visitor1.Box; box1.AddMargin(5); picImage1.DrawingBox = box1; factory1.Draw(picImage1); picImage1.SaveAs(filePath1); _log.Debug("File path = " + filePath1); _log.Debug("Path = " + Path.Combine(Environment.SystemDirectory, "mspaint.exe")); System.Diagnostics.Process.Start(Path.Combine(Environment.SystemDirectory, "mspaint.exe"), filePath1); } // instantiate factory2 PicFactory factory2 = new PicFactory(); PicBlock block = factory2.AddBlock(factory0); factory2.AddBlockRef(block, new Vector2D(0.0, 0.0), 0.0); factory2.AddBlockRef(block, new Vector2D(400.0, 0.0), 0.0); factory2.AddBlockRef(block, new Vector2D(0.0, 400.0), 0.0); factory2.AddBlockRef(block, new Vector2D(400.0, 400.0), 45.0); // get bounding box of factory2 using (PicVisitorBoundingBox visitor = new PicVisitorBoundingBox()) { factory2.ProcessVisitor(visitor); _log.Info(visitor.Box.ToString()); // save as image string filePath = Path.Combine(Path.GetTempPath(), "PicImage2.jpeg"); PicGraphicsImage picImage = new PicGraphicsImage(); picImage.ImageSize = new System.Drawing.Size(512, 512); Box2D box = visitor.Box; box.AddMargin(5); picImage.DrawingBox = box; factory2.Draw(picImage); picImage.SaveAs(filePath); _log.Debug("File path = " + filePath); _log.Debug("Path = " + Path.Combine(Environment.SystemDirectory, "mspaint.exe")); System.Diagnostics.Process.Start(Path.Combine(Environment.SystemDirectory, "mspaint.exe"), filePath); } // compute area PicFactory factory3 = new PicFactory(); factory3.AddSegment(PicGraphics.LT.LT_CUT, 0, 0, new Vector2D(-100.0, -100.0), new Vector2D(100.0, -100.0)); factory3.AddSegment(PicGraphics.LT.LT_CUT, 0, 0, new Vector2D(100.0, -100.0), new Vector2D(100.0, 100.0)); factory3.AddSegment(PicGraphics.LT.LT_CUT, 0, 0, new Vector2D(100.0, 100.0), new Vector2D(-100.0, 100.0)); factory3.AddSegment(PicGraphics.LT.LT_CUT, 0, 0, new Vector2D(-100.0, 100.0), new Vector2D(-100.0, -100.0)); PicToolArea picToolArea = new PicToolArea(); factory3.ProcessTool(picToolArea); _log.Info(string.Format("Area of factory3 is {0}", picToolArea.Area)); _log.Info("Pic.Factory2D.Test.exe finishing..."); } catch (Exception ex) { _log.Error(ex.ToString()); } }
public void GenerateImage(Size size, ParameterStack stack, out Image bmp) { // check if plugin was instantiated if (null == _component) throw new Exception("No valid plugin instance loaded!"); // instantiate factory PicFactory factory = new PicFactory(); // generate entities _component.CreateFactoryEntities(factory, stack); // apply any needed transformation if (_reflexionX) factory.ProcessVisitor(new PicVisitorTransform(Transform2D.ReflectionX)); if (_reflexionY) factory.ProcessVisitor(new PicVisitorTransform(Transform2D.ReflectionY)); // get bounding box PicVisitorBoundingBox visitor = new PicVisitorBoundingBox(); factory.ProcessVisitor(visitor); Pic.Factory2D.Box2D box = visitor.Box; box.AddMarginRatio(0.05); // draw image PicGraphicsImage picImage = new PicGraphicsImage(size, box); factory.Draw(picImage, _showCotations ? PicFilter.FilterNone : PicFilter.FilterCotation); bmp = picImage.Bitmap; }
public byte[] GenerateExportFile(string fileFormat, ParameterStack stack) { // build factory PicFactory factory = new PicFactory(); Component.CreateFactoryEntities(factory, stack); if (ReflexionX) { factory.ProcessVisitor(new PicVisitorTransform(Transform2D.ReflectionX)); } if (ReflexionY) { factory.ProcessVisitor(new PicVisitorTransform(Transform2D.ReflectionY)); } // instantiate filter PicFilter filter = (ShowCotations ? PicFilter.FilterNone : !PicFilter.FilterCotation) & PicFilter.FilterNoZeroEntities; // get bounding box PicVisitorBoundingBox visitorBoundingBox = new PicVisitorBoundingBox(); factory.ProcessVisitor(visitorBoundingBox, filter); Box2D box = visitorBoundingBox.Box; // add margins : 5 % of the smallest value among height box.AddMarginRatio(0.05); // get file content if ("des" == fileFormat) { PicVisitorDesOutput visitor = new PicVisitorDesOutput { Author = "treeDiM" }; // process visitor factory.ProcessVisitor(visitor, filter); return(visitor.GetResultByteArray()); } else if ("dxf" == fileFormat) { PicVisitorOutput visitor = new PicVisitorDxfOutput(); visitor.Author = "treeDiM"; // process visitor factory.ProcessVisitor(visitor, filter); return(visitor.GetResultByteArray()); } #if PDFSharp else if ("pdf" == fileFormat) { PicGraphicsPdf graphics = new PicGraphicsPdf(box) { Author = "treeDiM", Title = "Pdf Export" }; // draw factory.Draw(graphics, filter); return(graphics.GetResultByteArray()); } #endif else { throw new Exception("Invalid file format : " + fileFormat); } }
static void Main(string[] args) { XmlConfigurator.Configure(); try { // instantiate factory PicFactory factory = new PicFactory(); // load plugins PluginPathData configData = ConfigurationManager.GetSection("PluginSettings") as PluginPathData; if (null == configData) throw new Exception("Failed to load valid PluinPathData object!"); if (!Directory.Exists(configData.Path)) throw new Exception(string.Format("Directory \"{0}\" does not exist.", configData.Path)); ComponentLoader loader = new ComponentLoader(); DirectoryInfo dir = new DirectoryInfo(configData.Path); foreach (FileInfo fileInfo in dir.GetFiles()) { try { Component component = loader.LoadComponent(fileInfo.FullName); if (null == component) continue; System.Console.WriteLine("Name = " + component.Name); System.Console.WriteLine("Description = " + component.Description); System.Console.WriteLine("Author = " + component.Author); System.Console.WriteLine("Source code = " + component.SourceCode); System.Console.WriteLine("------------"); // get thumbnail if (component.HasEmbeddedThumbnail) { string thumbPath = Path.Combine(Path.GetTempPath(), component.Name + "_thumbnail.bmp"); System.Drawing.Bitmap thumbnail = component.Thumbnail; thumbnail.Save(thumbPath); if (launchPaint) System.Diagnostics.Process.Start(Path.Combine(Environment.SystemDirectory, "mspaint.exe"), "\"" + thumbPath + "\""); } // generate entities ParameterStack stack = component.BuildParameterStack(null); factory.Clear(); component.CreateFactoryEntities(factory, stack); // get bounding box PicVisitorBoundingBox visitor = new PicVisitorBoundingBox(); factory.ProcessVisitor(visitor); // save string filePath = Path.Combine(Path.GetTempPath(), component.Name + ".jpeg"); PicGraphicsImage picImage = new PicGraphicsImage(); picImage.ImageSize = new System.Drawing.Size(512, 512); Box2D box = visitor.Box; box.AddMargin(5); picImage.DrawingBox = box; factory.Draw(picImage); picImage.SaveAs(filePath); if (launchPaint) System.Diagnostics.Process.Start(Path.Combine(Environment.SystemDirectory, "mspaint.exe"), "\"" + filePath + "\""); } catch (System.Exception ex) { _log.Debug(ex.Message); } } } catch (System.Exception ex) { _log.Error(ex.ToString()); } }
public byte[] GetExportFile(string fileExt, ParameterStack stack) { // build factory PicFactory factory = new PicFactory(); Component.CreateFactoryEntities(factory, stack); if (_reflectionX) { factory.ProcessVisitor(new PicVisitorTransform(Transform2D.ReflectionX)); } if (_reflectionY) { factory.ProcessVisitor(new PicVisitorTransform(Transform2D.ReflectionY)); } // remove existing quotations if (!_showCotationCode) { factory.Remove(PicFilter.FilterCotation); } // build auto quotations if (_showCotationAuto) { PicAutoQuotation.BuildQuotation(factory); } // instantiate filter PicFilter filter = !PicFilter.FilterCotation & !(new PicFilterLineType(PicGraphics.LT.LT_COTATION) | new PicFilterLineType(PicGraphics.LT.LT_AXIS)) & PicFilter.FilterNoZeroEntities; // get bounding box PicVisitorBoundingBox visitorBoundingBox = new PicVisitorBoundingBox(); factory.ProcessVisitor(visitorBoundingBox, filter); Box2D box = visitorBoundingBox.Box; // add margins : 5 % of the smallest value among height box.AddMarginHorizontal(box.Width * 0.05); box.AddMarginVertical(box.Height * 0.05); string author = Application.ProductName + " (" + Application.CompanyName + ")"; string title = Application.ProductName + " export"; string fileFormat = fileExt.StartsWith(".") ? fileExt.Substring(1) : fileExt; fileFormat = fileFormat.ToLower(); // get file content if (string.Equals("des", fileFormat)) { PicVisitorDesOutput visitor = new PicVisitorDesOutput { Author = author }; factory.ProcessVisitor(visitor, filter); return(visitor.GetResultByteArray()); } else if (string.Equals("dxf", fileFormat)) { PicVisitorOutput visitor = new PicVisitorDxfOutput { Author = author }; factory.ProcessVisitor(visitor, filter); return(visitor.GetResultByteArray()); } #if PDFSharp else if (string.Equals("pdf", fileFormat)) { PicGraphicsPdf graphics = new PicGraphicsPdf(box) { Author = author, Title = title }; factory.Draw(graphics, filter); return(graphics.GetResultByteArray()); } #endif else if (string.Equals("ai", fileFormat) || string.Equals("cf2", fileFormat)) { PicVisitorDiecutOutput visitor = new PicVisitorDiecutOutput(fileFormat) { Author = author, Title = title }; factory.ProcessVisitor(visitor, filter); return(visitor.GetResultByteArray()); } else { throw new Exception("Invalid file format:" + fileFormat); } }
private void RePaint(PaintEventArgs e, ParameterStack stack) { try { SplitterPanel panel1 = splitContHorizLeft.Panel1; // instantiate PicGraphics if (_picGraphics == null) { _picGraphics = new PicGraphicsCtrlBased(panel1.ClientSize, e.Graphics) { BackgroundColor = Factory2D.Control.Properties.Settings.Default.BackgroundColor }; } _picGraphics.GdiGraphics = e.Graphics; _picGraphics.Size = panel1.ClientSize; // build factory using (PicFactory factory = new PicFactory()) { // create entities Component.CreateFactoryEntities(factory, stack); if (_reflectionX) { factory.ProcessVisitor(new PicVisitorTransform(Transform2D.ReflectionX)); } if (_reflectionY) { factory.ProcessVisitor(new PicVisitorTransform(Transform2D.ReflectionY)); } // remove existing quotations if (!_showCotationCode) { factory.Remove(PicFilter.FilterCotation); } // build auto quotations if (_showCotationAuto) { PicAutoQuotation.BuildQuotation(factory); } // filter PicFilter filter = _showAxes ? PicFilter.FilterNone : PicFilter.FilterCotation | !(new PicFilterLineType(PicGraphics.LT.LT_COTATION) | new PicFilterLineType(PicGraphics.LT.LT_AXIS)); // update drawing box? if (_computeBbox) { PicVisitorBoundingBox visitor = new PicVisitorBoundingBox(); factory.ProcessVisitor(visitor, filter); Box = new Box2D(visitor.Box); Box2D box = visitor.Box; box.AddMarginRatio(0.05); _picGraphics.DrawingBox = box; // update factory data if (null != factoryDataCtrl) { factoryDataCtrl.Factory = factory; } _computeBbox = false; } // draw factory.Draw(_picGraphics, filter); } } catch (PluginException ex) { _picGraphics.ShowMessage(ex.Message); } catch (ComponentSearchException ex) { _picGraphics.ShowMessage(ex.Message); } catch (Exception ex) { _picGraphics.ShowMessage(ex.ToString()); log.Error(ex.ToString()); } }
static void Main(string[] args) { // set up a simple configuration that logs on the console. XmlConfigurator.Configure(); string assemblyName = System.Reflection.Assembly.GetExecutingAssembly().CodeBase; try { _log.Info(assemblyName + " starting..."); const PicGraphics.LT ltCut = PicGraphics.LT.LT_CUT; // instantiate factory PicFactory initialFactory = new PicFactory(); ParameterStack stack = Program.Parameters; Program.CreateFactoryEntities(initialFactory, stack, Transform2D.Identity); // imposition double width = 1000.0, height = 1000.0; ImpositionTool impositionTool = new ImpositionToolCardboardFormat(initialFactory, new CardboardFormat(0, "Format1", "Format1", width, height)); impositionTool.SpaceBetween = new Vector2D(0.0, 0.0); impositionTool.Margin = new Vector2D(0.0, 0.0); List<ImpositionSolution> solutions; impositionTool.GenerateSortedSolutionList(null, out solutions); _log.Info(string.Format("{0} : Solutions", solutions.Count)); if (solutions.Count <= 0) return; foreach (ImpositionSolution chosenSolution in solutions) { _log.Info(string.Format("NoRows={0}, NoCols={1}", chosenSolution.Rows, chosenSolution.Cols)); PicFactory factoryOut = new PicFactory(); chosenSolution.CreateEntities(factoryOut); factoryOut.AddSegment(ltCut, new Vector2D(0.0, 0.0), new Vector2D(width, 0.0)); factoryOut.AddSegment(ltCut, new Vector2D(width, 0.0), new Vector2D(width, height)); factoryOut.AddSegment(ltCut, new Vector2D(width, height), new Vector2D(0.0, height)); factoryOut.AddSegment(ltCut, new Vector2D(0.0, height), new Vector2D(0.0, 0.0)); // get bounding box Box2D box = new Box2D(); using (PicVisitorBoundingBox visitor = new PicVisitorBoundingBox()) { factoryOut.ProcessVisitor(visitor); box = visitor.Box; } string filePath = Path.Combine(Path.GetTempPath(), "Imposition.bmp"); PicGraphicsImage picImage = new PicGraphicsImage(); picImage.ImageSize = new System.Drawing.Size(4096, 4096); box.AddMargin(1.0); picImage.DrawingBox = box; factoryOut.Draw(picImage); picImage.SaveAs(filePath); System.Diagnostics.Process.Start(Path.Combine(Environment.SystemDirectory, "mspaint.exe"), filePath); _log.Info(assemblyName + " ending..."); } } catch (Exception ex) { _log.Error(ex.ToString()); } }
static void Main(string[] args) { // set up a simple configuration that logs on the console. XmlConfigurator.Configure(); try { _log.Info("Pic.Factory2D.Test.exe starting..."); // testing Sharp3D.Math.Core.Matrix3D Transform2D transf0 = Transform2D.Translation(new Vector2D(10.0, 10.0)) * Transform2D.Rotation(45.0); Vector2D pt0 = transf0.transform(new Vector2D(100.0, 100.0)); _log.Info(pt0.ToString()); Transform2D transf1 = transf0.Inverse(); Vector2D pt1 = transf1.transform(pt0); _log.Info(pt1.ToString()); // instantiate factory1 PicFactory factory0 = new PicFactory(); factory0.AddPoint(PicGraphics.LT.LT_CUT, new Vector2D(0.0, 0.0)); factory0.AddSegment(PicGraphics.LT.LT_CUT, new Vector2D(50.0, 50.0), new Vector2D(100.0, 100.0)); factory0.AddSegment(PicGraphics.LT.LT_CUT, new Vector2D(-100.0, 100.0), new Vector2D(100.0, -100.0)); factory0.AddArc(PicGraphics.LT.LT_CUT, new Vector2D(50.0, 50.0), 50.0 * Math.Sqrt(2.0), 0.0, 360.0); factory0.AddArc(PicGraphics.LT.LT_CUT, new Vector2D(75.0, 75.0), 25.0 * Math.Sqrt(2.0), 0.0, 360.0); factory0.AddNurb(PicGraphics.LT.LT_CUT); _log.Debug(factory0.ToString()); // get bounding box + draw using (PicVisitorBoundingBox visitor = new PicVisitorBoundingBox()) { factory0.ProcessVisitor(visitor); _log.Info(visitor.Box.ToString()); // save as image string filePath = Path.Combine(Path.GetTempPath(), "PicImage0.jpeg"); PicGraphicsImage picImage = new PicGraphicsImage(); picImage.ImageSize = new System.Drawing.Size(512, 512); Box2D box = visitor.Box; box.AddMargin(5); picImage.DrawingBox = box; factory0.Draw(picImage); picImage.SaveAs(filePath); _log.Debug("File path = " + filePath); _log.Debug("Path = " + Path.Combine(Environment.SystemDirectory, "mspaint.exe")); System.Diagnostics.Process.Start(Path.Combine(Environment.SystemDirectory, "mspaint.exe"), filePath); } // output to dxf file Pic.Factory2D.PicVisitorDxfOutput dxfOutputVisitor = new Pic.Factory2D.PicVisitorDxfOutput(); factory0.ProcessVisitor(dxfOutputVisitor); // load dxf file PicFactory factory1 = new PicFactory(); PicLoaderDxf loaderDxf = new PicLoaderDxf(factory1); loaderDxf.Load(@"K:\Codesion\PicSharp\Samples\F1034.EV.DXF"); loaderDxf.FillFactory(); // save as image // get bounding box + draw using (PicVisitorBoundingBox visitor1 = new PicVisitorBoundingBox()) { factory1.ProcessVisitor(visitor1); _log.Info(visitor1.Box.ToString()); string filePath1 = Path.Combine(Path.GetTempPath(), "PicImage1.jpeg"); PicGraphicsImage picImage1 = new PicGraphicsImage(); picImage1.ImageSize = new System.Drawing.Size(512, 512); Box2D box1 = visitor1.Box; box1.AddMargin(5); picImage1.DrawingBox = box1; factory1.Draw(picImage1); picImage1.SaveAs(filePath1); _log.Debug("File path = " + filePath1); _log.Debug("Path = " + Path.Combine(Environment.SystemDirectory, "mspaint.exe")); System.Diagnostics.Process.Start(Path.Combine(Environment.SystemDirectory, "mspaint.exe"), filePath1); } // instantiate factory2 PicFactory factory2 = new PicFactory(); PicBlock block = factory2.AddBlock(factory0); factory2.AddBlockRef(block, new Vector2D(0.0, 0.0), 0.0); factory2.AddBlockRef(block, new Vector2D(400.0, 0.0), 0.0); factory2.AddBlockRef(block, new Vector2D(0.0, 400.0), 0.0); factory2.AddBlockRef(block, new Vector2D(400.0, 400.0), 45.0); // get bounding box of factory2 using (PicVisitorBoundingBox visitor = new PicVisitorBoundingBox()) { factory2.ProcessVisitor(visitor); _log.Info(visitor.Box.ToString()); // save as image string filePath = Path.Combine(Path.GetTempPath(), "PicImage2.jpeg"); PicGraphicsImage picImage = new PicGraphicsImage(); picImage.ImageSize = new System.Drawing.Size(512, 512); Box2D box = visitor.Box; box.AddMargin(5); picImage.DrawingBox = box; factory2.Draw(picImage); picImage.SaveAs(filePath); _log.Debug("File path = " + filePath); _log.Debug("Path = " + Path.Combine(Environment.SystemDirectory, "mspaint.exe")); System.Diagnostics.Process.Start(Path.Combine(Environment.SystemDirectory, "mspaint.exe"), filePath); } // compute area PicFactory factory3 = new PicFactory(); factory3.AddSegment(PicGraphics.LT.LT_CUT, new Vector2D(-100.0, -100.0), new Vector2D(100.0, -100.0)); factory3.AddSegment(PicGraphics.LT.LT_CUT, new Vector2D(100.0, -100.0), new Vector2D(100.0, 100.0)); factory3.AddSegment(PicGraphics.LT.LT_CUT, new Vector2D(100.0, 100.0), new Vector2D(-100.0, 100.0)); factory3.AddSegment(PicGraphics.LT.LT_CUT, new Vector2D(-100.0, 100.0), new Vector2D(-100.0, -100.0)); PicToolArea picToolArea = new PicToolArea(); factory3.ProcessTool(picToolArea); _log.Info(string.Format("Area of factory3 is {0}", picToolArea.Area)); _log.Info("Pic.Factory2D.Test.exe finishing..."); } catch (Exception ex) { _log.Error(ex.ToString()); } }