Example #1
0
        public void Dimensions(ParameterStack stack, out double width, out double height, out double lengthCut, out double lengthFold)
        {
            // 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));
            }
            // get bounding box
            PicVisitorBoundingBox visitorBoundingBox = new PicVisitorBoundingBox();

            factory.ProcessVisitor(visitorBoundingBox, ShowCotations ? PicFilter.FilterNone : !PicFilter.FilterCotation);
            Box2D box = visitorBoundingBox.Box;

            width  = box.Width;
            height = box.Height;
            // get length
            PicVisitorDieCutLength visitorLength = new PicVisitorDieCutLength();

            factory.ProcessVisitor(visitorLength, PicFilter.FilterNone);
            lengthCut  = visitorLength.Lengths.ContainsKey(PicGraphics.LT.LT_CUT) ? visitorLength.Lengths[PicGraphics.LT.LT_CUT] : 0.0;
            lengthFold = visitorLength.Lengths.ContainsKey(PicGraphics.LT.LT_CREASING) ? visitorLength.Lengths[PicGraphics.LT.LT_CREASING] : 0.0;
        }
Example #2
0
 public void BuildLayout()
 {
     using (PicFactory factory = new PicFactory())
     {
         // build factory entities
         Component.CreateFactoryEntities(factory, CurrentParameterStack);
         if (ReflectionX)
         {
             factory.ProcessVisitor(new PicVisitorTransform(Transform2D.ReflectionX));
         }
         if (ReflectionY)
         {
             factory.ProcessVisitor(new PicVisitorTransform(Transform2D.ReflectionY));
         }
         var form = new FormImposition()
         {
             FormatLoader = CardboardFormatLoader,
             Factory      = factory,
             Offset       = Component.ImpositionOffset(CurrentParameterStack)
         };
         if (DialogResult.OK == form.ShowDialog())
         {
         }
     }
 }
Example #3
0
        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;
        }
Example #4
0
        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 ProcessEntities(PicFactory factory, Dictionary <PicGraphics.LT, CutTool> dictTool, ref List <PicTypedDrawable> entities)
        {
            if (null == entities)
            {
                entities = new List <PicTypedDrawable>();
            }
            entities.Clear();
            // get factory bounding box
            PicVisitorBoundingBox visitorBBox = new PicVisitorBoundingBox();

            factory.ProcessVisitor(visitorBBox, new PicFilterTypedDrawable());
            // translate factory
            PicVisitorTransform visitorTranslation = new PicVisitorTransform(Transform2D.Translation(-visitorBBox.Box.PtMin));

            factory.ProcessVisitor(visitorTranslation, new PicFilter());
            // sort entities by type
            Vector2D currentPt = Vector2D.Zero;

            foreach (PicGraphics.LT lt in dictTool.Keys)
            {
                // get entities with linetype = lt
                PicVisitorCollectTypedDrawables visitorCollect = new PicVisitorCollectTypedDrawables();
                factory.ProcessVisitor(visitorCollect, new PicFilterLineType(lt));
                List <PicTypedDrawable> tempList1 = visitorCollect.Entities;

                // move entities from tempList1 to tempList2 from point to point
                List <PicTypedDrawable> tempList2 = new List <PicTypedDrawable>();

                while (tempList1.Count > 0)
                {
                    int    index   = 0;
                    double minDist = double.MaxValue;
                    for (int i = 0; i < tempList1.Count; ++i)
                    {
                        double dist = DistanceEntityPt(tempList1[i], currentPt);
                        if (dist < minDist)
                        {
                            index   = i;
                            minDist = dist;
                        }
                    }
                    currentPt = OppositePoint(tempList1[index], currentPt);
                    tempList2.Add(tempList1[index]);
                    tempList1.RemoveAt(index);
                }
                // concatenate list
                entities.AddRange(tempList2);
            }
        }
Example #6
0
        public PicFactory GetFactory()
        {
            PicFactory factory = new PicFactory();

            Component.CreateFactoryEntities(factory, CurrentParameterStack);
            if (_reflectionX)
            {
                factory.ProcessVisitor(new PicVisitorTransform(Transform2D.ReflectionX));
            }
            if (_reflectionY)
            {
                factory.ProcessVisitor(new PicVisitorTransform(Transform2D.ReflectionY));
            }
            return(factory);
        }
        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 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 ImpositionTool(IEntityContainer container)
        {
            _initialEntities = container;

            using (PicFactory factory = new PicFactory(container))
            {
                // compute lengthes
                PicVisitorDieCutLength visitor = new PicVisitorDieCutLength();
                factory.ProcessVisitor(visitor);
                Dictionary <PicGraphics.LT, double> lengthes = visitor.Lengths;
                _unitLengthCut  = lengthes.ContainsKey(PicGraphics.LT.LT_CUT) ? visitor.Lengths[PicGraphics.LT.LT_CUT] : 0.0;
                _unitLengthFold = lengthes.ContainsKey(PicGraphics.LT.LT_CREASING) ? visitor.Lengths[PicGraphics.LT.LT_CREASING] : 0.0;
                // compute area
                try
                {
                    PicToolArea picToolArea = new PicToolArea();
                    factory.ProcessTool(picToolArea);
                    _unitArea = picToolArea.Area;
                }
                catch (PicToolTooLongException /*ex*/)
                {
                    _unitArea = 0;
                }
            }
        }
Example #10
0
 public override void Initialize(PicFactory factory)
 {
     _exporter.Initialize();
     // 
     PicVisitorBoundingBox visitor = new PicVisitorBoundingBox();
     factory.ProcessVisitor(visitor);
     _exporter.SetBoundingBox(visitor.Box.XMin, visitor.Box.YMin, visitor.Box.XMax, visitor.Box.YMax);
 }
        public override void Initialize(PicFactory factory)
        {
            _exporter.Initialize();
            //
            PicVisitorBoundingBox visitor = new PicVisitorBoundingBox();

            factory.ProcessVisitor(visitor);
            _exporter.SetBoundingBox(visitor.Box.XMin, visitor.Box.YMin, visitor.Box.XMax, visitor.Box.YMax);
        }
 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;
     }
 }
Example #13
0
        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;            
        }
Example #14
0
        public static void BuildQuotation(PicFactory factory)
        {
            PicAutoQuotation autoQuotation = new PicAutoQuotation();

            for (short grp = 0; grp < 16; ++grp)
            {
                // get min max box grp
                PicVisitorBoundingBox visitor = new PicVisitorBoundingBox();
                factory.ProcessVisitor(visitor, new PicFilterGroup(grp));

                autoQuotation.BuildHQuotation(factory, grp, visitor.Box);
                autoQuotation.BuildVQuotation(factory, grp, visitor.Box);
                autoQuotation.BuildGlobalQuotation(factory, grp, visitor.Box);
            }
        }
        public static Box2D BoundingBox(PicFactory factory, double marginRatio = 0.0, bool takePicBlocsIntoAccount = true)
        {
            var visitor = new PicVisitorBoundingBox()
            {
                TakePicBlocksIntoAccount = takePicBlocsIntoAccount
            };

            factory.ProcessVisitor(visitor, !PicFilter.FilterCotation);
            Box2D box = visitor.Box;

            if (box.IsValid && marginRatio > 0.0)
            {
                box.AddMarginRatio(marginRatio);
            }
            return(box);
        }
Example #16
0
        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 ComputeLengthCutFold()
 {
     if (_lengthCut <= 0)
     {
         _lengthCut = 0.0;
         using (PicFactory factory = new PicFactory())
         {
             // fill factory with entities
             CreateEntities(factory);
             // counting added length only
             PicVisitorComputeLength visitorComputeLength = new PicVisitorComputeLength();
             factory.ProcessVisitor(visitorComputeLength /*, new PicFilterLineType(PicGraphics.LT.LT_CUT)*/);
             // cut length
             _lengthCut = visitorComputeLength.Length;
         }
     }
 }
Example #18
0
 /// <summary>
 /// Initialize DES_Writer object
 /// </summary>
 /// <param name="factory"></param>
 public override void Initialize(PicFactory factory)
 {
     // save factory
     _factory = factory;
     // build .des file header
     DES_Header header = new DES_Header();
     PicVisitorBoundingBox bbVisitor = new PicVisitorBoundingBox();
     factory.ProcessVisitor(bbVisitor);
     header._xmin = (float)bbVisitor.Box.XMin;
     header._xmax = (float)bbVisitor.Box.XMax;
     header._ymin = (float)bbVisitor.Box.YMin;
     header._ymax = (float)bbVisitor.Box.YMax;
     // initialize des writer
     _desWriter = new DES_WriterMem(header);
     DES_SuperBaseHeader superBaseHeader = new DES_SuperBaseHeader();
     _desWriter.WriteSuperBaseHeader(superBaseHeader);
 }
Example #19
0
        /// <summary>
        /// Initialize DES_Writer object
        /// </summary>
        /// <param name="factory"></param>
        public override void Initialize(PicFactory factory)
        {
            // save factory
            _factory = factory;
            // build .des file header
            DES_Header            header    = new DES_Header();
            PicVisitorBoundingBox bbVisitor = new PicVisitorBoundingBox();

            factory.ProcessVisitor(bbVisitor);
            header._xmin = (float)bbVisitor.Box.XMin;
            header._xmax = (float)bbVisitor.Box.XMax;
            header._ymin = (float)bbVisitor.Box.YMin;
            header._ymax = (float)bbVisitor.Box.YMax;
            // initialize des writer
            _desWriter = new DES_WriterMem(header);
            DES_SuperBaseHeader superBaseHeader = new DES_SuperBaseHeader();

            _desWriter.WriteSuperBaseHeader(superBaseHeader);
        }
        public override void GeneratePattern(IEntityContainer container, Vector2D minDistance, Vector2D impositionOffset, bool ortho)
        {
            using (PicFactory factory = new PicFactory())
            {
                // instantiate block and BlockRef
                PicBlock    block      = factory.AddBlock(container);
                PicBlockRef blockRef00 = factory.AddBlockRef(block, new Vector2D(0.0, 0.0), ortho ? 90.0 : 0.0);

                // compute bounding box
                PicVisitorBoundingBox visitor = new PicVisitorBoundingBox();
                visitor.TakePicBlocksIntoAccount = false;
                factory.ProcessVisitor(visitor, !PicFilter.FilterCotation);
                Box2D boxEntities = visitor.Box;

                // compute default X step
                PicBlockRef blockRef01         = factory.AddBlockRef(block, new Vector2D(5.0 * boxEntities.Width + minDistance.X, 0.0), ortho ? 90.0 : 0.0);
                double      horizontalDistance = 0.0;
                if (!PicBlockRef.Distance(blockRef00, blockRef01, PicBlockRef.DistDirection.HORIZONTAL_RIGHT, out horizontalDistance))
                {
                    throw new Exception("Failed to compute distance between to block refs");
                }
                _patternStep.X = 5.0 * boxEntities.Width - horizontalDistance + 2.0 * minDistance.X;

                // compute default Y step
                PicBlockRef blockRef10       = factory.AddBlockRef(block, new Vector2D(0.0, 5.0 * boxEntities.Height + minDistance.Y), ortho ? 90.0 : 0.0);
                double      verticalDistance = 0.0;
                if (!PicBlockRef.Distance(blockRef00, blockRef10, PicBlockRef.DistDirection.VERTICAL_TOP, out verticalDistance))
                {
                    throw new Exception("Failed to compute distance between to block refs");
                }
                _patternStep.Y = 5.0 * boxEntities.Height - verticalDistance + 2.0 * minDistance.Y;

                // positions
                _relativePositions = new BPosition[1, 1];
                BPosition position = new BPosition(Vector2D.Zero, ortho ? 90.0 : 0.0);
                _relativePositions[0, 0] = position;

                // bboxes
                _bboxes       = new Box2D[1, 1];
                _bboxes[0, 0] = blockRef00.Box;//boxEntities;
            }
        }
Example #21
0
        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());
            }
        }
Example #22
0
        public void BuildLayout()
        {
            Pic.Factory2D.Control.FormImpositionSettings formSettings = new Pic.Factory2D.Control.FormImpositionSettings();
            if (null != _cardboardFormatLoader)
                formSettings.FormatLoader = _cardboardFormatLoader;

            // get offset
            Vector2D impositionOffset = Component.ImpositionOffset(CurrentParameterStack);
            // initialize form with offsets
            formSettings.OffsetX = impositionOffset.X;
            formSettings.OffsetY = impositionOffset.Y;

            if (DialogResult.OK == formSettings.ShowDialog())
            {
                using (PicFactory factory = new PicFactory())
                {
                    // build factory entities
                    Component.CreateFactoryEntities(factory, CurrentParameterStack);
                    if (_reflectionX) factory.ProcessVisitor(new PicVisitorTransform(Transform2D.ReflectionX));
                    if (_reflectionY) factory.ProcessVisitor(new PicVisitorTransform(Transform2D.ReflectionY));
                    // build imposition solutions
                    if (formSettings.Mode == 0)
                        _impositionTool = new ImpositionToolCardboardFormat(factory, formSettings.CardboardFormat);
                    else
                        _impositionTool = new ImpositionToolXY(factory, formSettings.NumberDirX, formSettings.NumberDirY);
                    // -> margins
                    _impositionTool.HorizontalAlignment = formSettings.HorizontalAlignment;
                    _impositionTool.VerticalAlignment = formSettings.VerticalAlignment;
                    _impositionTool.SpaceBetween = new Vector2D(formSettings.ImpSpaceX, formSettings.ImpSpaceY);
                    _impositionTool.Margin = new Vector2D(formSettings.ImpMarginLeftRight, formSettings.ImpMarginBottomTop);
                    _impositionTool.MinMargin = new Vector2D(formSettings.ImpRemainingMarginLeftRight, formSettings.ImpRemainingMarginBottomTop);
                    // -> allowed patterns
                    _impositionTool.AllowRotationInColumnDirection = formSettings.AllowColumnRotation;
                    _impositionTool.AllowRotationInRowDirection = formSettings.AllowRowRotation;
                    // -> offsets
                    _impositionTool.ImpositionOffset = new Vector2D(formSettings.OffsetX, formSettings.OffsetY);
                    // instantiate ProgressWindow and launch process
                    ProgressWindow progress = new ProgressWindow();
                    System.Threading.ThreadPool.QueueUserWorkItem(new System.Threading.WaitCallback(GenerateImpositionSolutions), progress);
                    progress.ShowDialog();
                    // show dialog
                    if (null != _solutions && _solutions.Count > 0)
                    {
                        Pic.Factory2D.Control.FormImposition form = new Pic.Factory2D.Control.FormImposition();
                        form.Solutions = _solutions;
                        form.Format = formSettings.CardboardFormat;
                        if (DialogResult.OK == form.ShowDialog(this))
                        {
                        }
                    }
                }
            }            
        }
Example #23
0
        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;
        }
Example #24
0
        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);
            }
        }
Example #25
0
        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());
            }
        }
Example #26
0
        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());
            }
        }
Example #27
0
        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);
            }
        }
Example #28
0
        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());
            }
             
        }
        public override void GeneratePattern(IEntityContainer container, Vector2D minDistance, Vector2D impositionOffset, bool ortho)
        {
            using (PicFactory factory = new PicFactory())
            {
                // 20 21
                // 10 11 12
                // 00 01 02
                //

                // instantiate block and BlockRef
                PicBlock    block      = factory.AddBlock(container);
                PicBlockRef blockRef00 = factory.AddBlockRef(block, new Vector2D(0.0, 0.0), ortho ? 90.0 : 0.0);

                // compute bounding box
                PicVisitorBoundingBox visitor = new PicVisitorBoundingBox();
                visitor.TakePicBlocksIntoAccount = false;
                factory.ProcessVisitor(visitor, new PicFilter());
                Box2D boxEntities = visitor.Box;

                // compute second entity position
                PicBlockRef blockRef10 = factory.AddBlockRef(block
                                                             , new Vector2D(
                                                                 boxEntities.XMin + boxEntities.XMax + (ortho ? 0.0 : 1.0) * impositionOffset.X
                                                                 , boxEntities.YMin + boxEntities.YMax + 5.0 * boxEntities.Height + minDistance.Y + (ortho ? 1.0 : 0.0) * impositionOffset.Y
                                                                 ), ortho ? 270.0 : 180.0);
                double verticalDistance = 0.0;
                if (!PicBlockRef.Distance(blockRef00, blockRef10, PicBlockRef.DistDirection.VERTICAL_TOP, out verticalDistance))
                {
                    throw new Exception("Failed to compute distance between to block refs");
                }
                Vector2D vecPosition = new Vector2D(
                    boxEntities.XMin + boxEntities.XMax + (ortho ? 0.0 : 1.0) * impositionOffset.X
                    , boxEntities.YMin + boxEntities.YMax + 5.0 * boxEntities.Height + 2.0 * minDistance.Y - verticalDistance + (ortho ? 1.0 : 0.0) * impositionOffset.Y);
                blockRef10.Position = vecPosition;

                // positions
                _relativePositions       = new BPosition[2, 1];
                _relativePositions[0, 0] = new BPosition(Vector2D.Zero, ortho ? 90.0 : 0.0);
                _relativePositions[1, 0] = new BPosition(vecPosition, ortho ? 270.0 : 180.0);
                // bboxes
                _bboxes       = new Box2D[2, 1];
                _bboxes[0, 0] = blockRef00.Box;//boxEntities;
                _bboxes[1, 0] = blockRef10.Box;

                // compute X step (col1 / col0)
                // col0
                List <PicBlockRef> listCol0 = new List <PicBlockRef>();
                listCol0.Add(blockRef00);
                listCol0.Add(blockRef10);

                // col1
                PicBlockRef blockRef01 = factory.AddBlockRef(block
                                                             , new Vector2D(5.0 * boxEntities.Width + minDistance.X, 0.0)
                                                             , ortho ? 90.0 : 0.0);
                PicBlockRef blockRef11 = factory.AddBlockRef(block
                                                             , new Vector2D(5.0 * boxEntities.Width + minDistance.X + vecPosition.X, vecPosition.Y)
                                                             , ortho ? 270.0 : 180.0);
                List <PicBlockRef> listCol1 = new List <PicBlockRef>();
                listCol1.Add(blockRef01);
                listCol1.Add(blockRef11);
                double horizontalDistance = 0.0;
                if (!PicBlockRef.Distance(listCol0, listCol1, PicBlockRef.DistDirection.HORIZONTAL_RIGHT, out horizontalDistance))
                {
                    throw new Exception("Failed to compute distance between to block refs");
                }
                _patternStep.X      = 5.0 * boxEntities.Width - horizontalDistance + 2.0 * minDistance.X;
                blockRef01.Position = vecPosition;
                blockRef11.Position = new Vector2D(vecPosition.X + _patternStep.X, vecPosition.Y);

                // compute Y step (row2 / row1)
                // row1
                List <PicBlockRef> listRow1 = new List <PicBlockRef>();
                listRow1.Add(blockRef10);
                listRow1.Add(blockRef11);

                PicBlockRef blockRef20 = factory.AddBlockRef(block
                                                             , new Vector2D(0.0, 5.0 * (boxEntities.Height + minDistance.Y))
                                                             , ortho ? 90.0 : 0.0);
                PicBlockRef blockRef21 = factory.AddBlockRef(block
                                                             , new Vector2D(_patternStep.X, 5.0 * (boxEntities.Height + minDistance.Y))
                                                             , ortho ? 90.0 : 0.0);

                List <PicBlockRef> listRow2 = new List <PicBlockRef>();
                listRow2.Add(blockRef20);
                listRow2.Add(blockRef21);

                verticalDistance = 0.0;
                if (!PicBlockRef.Distance(listRow1, listRow2, PicBlockRef.DistDirection.VERTICAL_TOP, out verticalDistance))
                {
                    throw new Exception("Failed to compute distance between to block refs");
                }
                _patternStep.Y = 5.0 * boxEntities.Height - verticalDistance + 6.0 * minDistance.Y;
            }
        }
Example #30
0
        // build horizontal quotation
        private void BuildHQuotation(PicFactory factory, short grp, Box2D box)
        {
            // get entities
            PicVisitorAutoQuotationEntities visitor = new PicVisitorAutoQuotationEntities(grp);

            factory.ProcessVisitor(visitor);
            List <PicTypedDrawable> list = visitor.Entities;
            // list of vertical segments
            List <PicSegment> vSegments = new List <PicSegment>();
            Box2D             bbox      = new Box2D();
            double            minY_Xmin = double.MaxValue;
            double            minY_Xmax = double.MaxValue;

            foreach (PicTypedDrawable typedDrawable in list)
            {
                // get entity bounding box
                Box2D entityBox = typedDrawable.Box;
                // save y of minx
                if (entityBox.XMin <= bbox.XMin)
                {
                    if (Math.Abs(entityBox.XMin - bbox.XMin) < 0.1)
                    {
                        minY_Xmin = Math.Min(entityBox.YMin, minY_Xmin);
                    }
                    else
                    {
                        minY_Xmin = entityBox.YMin;
                    }
                }
                if (entityBox.XMax >= bbox.XMax)
                {
                    if (Math.Abs(entityBox.XMax - bbox.XMax) < 0.1)
                    {
                        minY_Xmax = Math.Min(entityBox.YMin, minY_Xmax);
                    }
                    else
                    {
                        minY_Xmax = entityBox.YMin;
                    }
                }
                // expand global bounding box
                bbox.Extend(entityBox);
                // save vertical fold segments
                if (typedDrawable is PicSegment &&
                    (
                        (typedDrawable.LineType == PicGraphics.LT.LT_CREASING) ||
                        (typedDrawable.LineType == PicGraphics.LT.LT_HALFCUT) ||
                        (typedDrawable.LineType == PicGraphics.LT.LT_PERFO) ||
                        (typedDrawable.LineType == PicGraphics.LT.LT_PERFOCREASING)
                    )
                    )
                {
                    PicSegment seg = typedDrawable as PicSegment;
                    if (Math.Abs(seg.Pt1.X - seg.Pt0.X) / seg.Length < 0.01)
                    {
                        vSegments.Add(seg);
                    }
                }
            }
            // exit if no horizontal folds
            if (vSegments.Count == 0)
            {
                return;
            }
            // sort vertical segments by increasing x
            vSegments.Sort(new ComparerVerticalFoldsByIncreasingX());
            // remove redundants x abscissa
            double            prevx = bbox.XMin;
            List <PicSegment> sameAbscissaSegments = new List <PicSegment>();
            List <PicSegment> resultSegments       = new List <PicSegment>();

            foreach (PicSegment seg in vSegments)
            {
                if (sameAbscissaSegments.Count > 0)
                {
                    if (seg.Pt0.X - sameAbscissaSegments[0].Pt0.X > _tolerance)
                    {
                        // sort segments vertically
                        sameAbscissaSegments.Sort(new ComparerVerticalFoldsByIncreasingY());
                        resultSegments.Add(sameAbscissaSegments[0]);
                        sameAbscissaSegments.Clear();
                    }
                }
                sameAbscissaSegments.Add(seg);
            }

            // add last segment if any
            if (sameAbscissaSegments.Count > 0)
            {
                // sort segments vertically
                sameAbscissaSegments.Sort(new ComparerVerticalFoldsByIncreasingY());
                resultSegments.Add(sameAbscissaSegments[0]);
                sameAbscissaSegments.Clear();
            }

            // ### create horizontal quotations
            double   delta  = 0.05 * Math.Max(bbox.Width, bbox.Height);
            double   ypos   = bbox.YMin - delta;
            Vector2D ptPrev = bbox.PtMin;
            int      i      = 0;

            if (resultSegments.Count > 0 && (bbox.XMin + _tolerance < resultSegments[0].Pt0.X))
            {
                ptPrev = new Vector2D(bbox.XMin, minY_Xmin);
            }
            else
            {
                ptPrev = GetLowestPoint(resultSegments[i]);
                ++i;
            }

            // between folds
            for (; i < resultSegments.Count; ++i)
            {
                Vector2D pt = GetLowestPoint(resultSegments[i]);
                CreateQuotationH(factory, ptPrev, pt, ypos, grp);
                ptPrev = pt;
            }
            // last : from last fold to maxx
            double yposTemp = bbox.XMax - ptPrev.X > delta ? ypos : ptPrev.Y;

            if (resultSegments.Count == 0)
            {
                CreateQuotationH(factory, ptPrev, new Vector2D(), ypos, grp);
            }
            else if (resultSegments[resultSegments.Count - 1].Pt0.X + _tolerance < bbox.XMax)
            {
                CreateQuotationH(factory, ptPrev, new Vector2D(bbox.XMax, minY_Xmax), ypos, grp);
            }
        }
Example #31
0
        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());
            }
        }
Example #32
0
        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()); }
        }
Example #33
0
        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());
            }
        }