Esempio n. 1
0
        public void BuildLayout()
        {
            FormImpositionSettings formSettings = new FormImpositionSettings();
            if (null != _cardboardFormatLoader)
                formSettings.FormatLoader = _cardboardFormatLoader;

            if (DialogResult.OK == formSettings.ShowDialog())
            {
                // build factory entities
                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.SpaceBetween = new Vector2D(formSettings.ImpSpaceX, formSettings.ImpSpaceX);
                _impositionTool.Margin = new Vector2D(formSettings.ImpMarginLeftRight, formSettings.ImpMarginBottomTop);
                _impositionTool.MinMargin = new Vector2D(formSettings.ImpRemainingMarginLeftRight, formSettings.ImpRemainingMarginBottomTop);
                _impositionTool.HorizontalAlignment = formSettings.HorizontalAlignment;
                _impositionTool.VerticalAlignment = formSettings.VerticalAlignment;
                // -> patterns
                _impositionTool.AllowRotationInColumnDirection = formSettings.AllowColumnRotation;
                _impositionTool.AllowRotationInRowDirection = formSettings.AllowRowRotation;
                // -> offset
                _impositionTool.ImpositionOffset = Vector2D.Zero;

                try
                {
                    // instantiate ProgressWindow and launch process
                    ProgressWindow progress = new ProgressWindow();
                    System.Threading.ThreadPool.QueueUserWorkItem(new System.Threading.WaitCallback(GenerateImpositionSolutions), progress);
                    progress.ShowDialog();

                    if (null != _solutions && _solutions.Count > 0)
                    {
                        FormImposition form = new FormImposition();
                        form.Solutions = _solutions;
                        form.Format = formSettings.CardboardFormat;
                        if (DialogResult.OK == form.ShowDialog(this))
                        {
                        }
                    }
                }
                catch (PicToolTooLongException /*ex*/)
                {
                    MessageBox.Show(
                        string.Format(Properties.Resources.ID_ABANDONPROCESSING
                        , Pic.Factory2D.Properties.Settings.Default.AreaMaxNoSegments)
                        , Application.ProductName
                        , MessageBoxButtons.OK);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
            }
        }
Esempio n. 2
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());
            }
             
        }