Author Topic: Convert2PDF Update  (Read 2767 times)

Agastar

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1878
    • View Profile
Re: Convert2PDF Update
« Reply #15 on: September 02, 2016, 04:07:53 AM »
I took a look at the code and it only had the number of objects that were drawn. I then opened the dxf file in wordpad and had a look. I did see some negative values in there but I'm not exactly sure what they mean. Out of curiosity I opened the Polyline4 file that ships with BCL and it does the same for that file as well. I checked your other dxf files and it only does it with that one.

Administrator

  • Administrator
  • Hero Member
  • *****
  • Posts: 1763
  • Pilot Instructor
    • View Profile
Re: Convert2PDF Update
« Reply #16 on: September 02, 2016, 07:54:29 AM »
Attached is my Polyline 4 file. I copied yours into my Drawings folder and over wrote mine but I have a backup copy of my file. I renamed it to Ploylone 40.

You get that negative space dialog because some parts of the drawing objects ARE touching the negative space and you can see how close the objects are to the 0,0 axis.

Your Polyline drawing has the visible objects well into the positive space yet we still get the negative space dialog so I'm thinking something we can't see must be in the drawing.

Ralph--Admin -- support_BenCutLaser_us
http://www.BenCutLaser.us/BenCutLaserSetup1.8.1r.exe.zip
http://www.BenCutLaser.us/BCLVirtualLaserMachineSetup1.8.1.exe.zip
BCL Paid license: $39.95
VLM Paid license: $19.95 (stand alone version)
via Paypal to bclpp@primemail.com

Zax

  • T2Laser
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3261
    • View Profile
    • T2Laser
Re: Convert2PDF Update
« Reply #17 on: September 02, 2016, 08:51:26 AM »
They both load in T2Laser without errors, the only difference is the shift to 0,0.

Administrator

  • Administrator
  • Hero Member
  • *****
  • Posts: 1763
  • Pilot Instructor
    • View Profile
Re: Convert2PDF Update
« Reply #18 on: September 02, 2016, 09:11:11 AM »
Right, Polyline 40 is my original drawing and some parts of it are in the negative space, but I can ignore it OK.

Both of those files rendered OK in T2 it looks like.
Ralph--Admin -- support_BenCutLaser_us
http://www.BenCutLaser.us/BenCutLaserSetup1.8.1r.exe.zip
http://www.BenCutLaser.us/BCLVirtualLaserMachineSetup1.8.1.exe.zip
BCL Paid license: $39.95
VLM Paid license: $19.95 (stand alone version)
via Paypal to bclpp@primemail.com

Agastar

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1878
    • View Profile
Re: Convert2PDF Update
« Reply #19 on: September 03, 2016, 06:32:44 AM »
I'm thinking that it might be the containers for the drawing objects that extends over into the negative space. I'll look to see if I can move the containers before placing objects in them.

I'll get it figured out eventually.

Administrator

  • Administrator
  • Hero Member
  • *****
  • Posts: 1763
  • Pilot Instructor
    • View Profile
Re: Convert2PDF Update
« Reply #20 on: September 03, 2016, 07:27:26 AM »
I'm not sure if the containers are even needed? If possible, we should only have the drawing objects themselves.
Ralph--Admin -- support_BenCutLaser_us
http://www.BenCutLaser.us/BenCutLaserSetup1.8.1r.exe.zip
http://www.BenCutLaser.us/BCLVirtualLaserMachineSetup1.8.1.exe.zip
BCL Paid license: $39.95
VLM Paid license: $19.95 (stand alone version)
via Paypal to bclpp@primemail.com

Zax

  • T2Laser
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3261
    • View Profile
    • T2Laser
Re: Convert2PDF Update
« Reply #21 on: September 03, 2016, 08:36:18 AM »
Both of those files rendered OK in T2 it looks like.

Yes, I'm very happy with my work on the object import and thank you for the examples that helped me find and correct some bugs.

Splines and Rotated E-Arcs are fun (or as fun as math ever gets), but appear to be working great now. I'm still not sure how to deal with curves that only have one control point, they aren't Bézier so have to be rendered as cardinal splines but the DXF doesn't appear to include any tension value. I've noticed that Inkscape doesn't import them correctly either.

The negative space isn't a problem for T2Laser, with DXF's if the entire shape is negative it is ignored otherwise anything outside of 0,0 is truncated. PLT files are shifted to 0,0 if any objects are in negative space otherwise they are treated the same as DXF.

Administrator

  • Administrator
  • Hero Member
  • *****
  • Posts: 1763
  • Pilot Instructor
    • View Profile
Re: Convert2PDF Update
« Reply #22 on: September 03, 2016, 09:33:21 AM »
The negative space isn't an issue with BCL either...I just popup a dialog warning the user they some part of their drawing in negative space.

If they choose to continue that way, that's their choice.

They can put their entire drawing in negative space if they want but our 'standards' is that 0,0 is in the lower left corner...so I don't know how the laser would respond if you had your entire drawing in negative space and actually tried to send it to the laser machine that way...but I would imagine your steppers would be hitting their physical stops!
Ralph--Admin -- support_BenCutLaser_us
http://www.BenCutLaser.us/BenCutLaserSetup1.8.1r.exe.zip
http://www.BenCutLaser.us/BCLVirtualLaserMachineSetup1.8.1.exe.zip
BCL Paid license: $39.95
VLM Paid license: $19.95 (stand alone version)
via Paypal to bclpp@primemail.com

Agastar

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1878
    • View Profile
Re: Convert2PDF Update
« Reply #23 on: September 03, 2016, 11:11:18 PM »
Well, I did a bit of code refactoring today and I'm getting better results which just means I'm able to convert more PDFs now. I still have a bit of work to do on the arcs and I spent a bit of time on the math subject lol. I have attached a sample from one of my Fight Test PDFs where I have taken the parts of the airplane and split them out into separate PDFs. This one is the firewall and will be cut out of wood.

I have a function that takes a cubic bezier path and allows me to plot the curve points for it. I use this to help me figure out if the curve can be turned into an arc. From there I see if there are for consecutive arcs with the same center point and I turn those into circles.

Tomorrow (or should I say later today), I'll be wiring up the following code that I've added, which should fix my start and end agle issues with my arcs. Once I determine that the cubic bezier path is compatible with being an arc, I'll use this to compute the needed parameters for the dxf library.

Quote
    public class Arc2D : IEquatable<Arc2D>
    {
        public Point2D CenterPoint { get; private set; }
        public Point2D StartPoint { get; private set; }
        public Point2D EndPoint { get; private set; }
        public double Radius { get; private set; }
        public double StartAngle { get; private set; }
        public double EndAngle { get; private set; }
        public double SweepAngle { get; private set; }
        public double Width { get; private set; }
        public double Height { get; private set; }
        public ArcBoundingBox BoundingBox { get; private set; }

        public Arc2D(Point2D startPoint, Point2D endPoint)
        {
            this.StartPoint = startPoint;
            this.EndPoint = endPoint;
            this.BoundingBox = new ArcBoundingBox(startPoint, endPoint);
            CalculateArcFromPoints();
        }

        private void CalculateArcFromPoints()
        {
            if ((StartPoint.X > EndPoint.X && StartPoint.Y < EndPoint.Y) ||
                (StartPoint.X < EndPoint.X && StartPoint.Y > EndPoint.Y))
                CenterPoint = new Point2D(EndPoint.X, StartPoint.Y);
            else
                CenterPoint = new Point2D(StartPoint.X, EndPoint.Y);

            var newP1 = new Point2D(StartPoint.X - CenterPoint.X, StartPoint.Y - CenterPoint.Y);
            var newP2 = new Point2D((EndPoint.X - CenterPoint.X), EndPoint.Y - CenterPoint.Y);

            double startRadians = Math.Atan2(newP1.Y, newP1.X);
            StartAngle = startRadians * (180 / Math.PI);

            double endRadians = Math.Atan2(newP2.Y, newP2.X);
            EndAngle = endRadians * (180 / Math.PI);

            SweepAngle = Math.Acos(newP1.X * newP2.X + newP1.Y * newP2.Y) * (180 / Math.PI);

            Width = Math.Abs(newP1.X + newP2.X);
            Height = Math.Abs(newP1.Y + newP2.Y);

            var chord = Math.Sqrt(Math.Pow(Width, 2) + Math.Pow(Height, 2));

            Radius = Math.Round(chord / (2 * Math.Sin(SweepAngle / 2)), 2);
        }

        public bool Equals(Arc2D other)
        {
            return this.StartPoint.Equals(other.StartPoint) && this.EndPoint.Equals(other.EndPoint);
        }

        public class ArcBoundingBox
        {
            public Point2D UpperLeftPoint { get; private set; }
            public Point2D UpperRightPoint { get; private set; }
            public Point2D LowerLeftPoint { get; private set; }
            public Point2D LowerRightPoint { get; private set; }

            internal ArcBoundingBox(Point2D startPoint, Point2D endPoint)
            {
                if (startPoint.X > endPoint.X && startPoint.Y < endPoint.Y)
                {
                    UpperLeftPoint = new Point2D(endPoint.X, endPoint.Y);
                    UpperRightPoint = new Point2D(startPoint.X, endPoint.Y);
                    LowerRightPoint = new Point2D(startPoint.X, startPoint.Y);
                    LowerLeftPoint = new Point2D(endPoint.X, startPoint.Y);
                }
                else if (startPoint.X < endPoint.X && startPoint.Y > endPoint.Y)
                {
                    UpperLeftPoint = new Point2D(startPoint.X, startPoint.Y);
                    UpperRightPoint = new Point2D(endPoint.X, startPoint.Y);
                    LowerRightPoint = new Point2D(endPoint.X, endPoint.Y);
                    LowerLeftPoint = new Point2D(startPoint.X, endPoint.Y);
                }
                else if (startPoint.X > endPoint.X && startPoint.Y > endPoint.Y)
                {
                    UpperLeftPoint = new Point2D(endPoint.X, startPoint.Y);
                    UpperRightPoint = new Point2D(startPoint.X, startPoint.Y);
                    LowerRightPoint = new Point2D(startPoint.X, endPoint.Y);
                    LowerLeftPoint = new Point2D(endPoint.X, endPoint.Y);
                }
                else
                {
                    UpperLeftPoint = new Point2D(startPoint.X, endPoint.Y);
                    UpperRightPoint = new Point2D(endPoint.X, endPoint.Y);
                    LowerRightPoint = new Point2D(endPoint.X, startPoint.Y);
                    LowerLeftPoint = new Point2D(startPoint.X, startPoint.Y);
                }
            }
        }
    }

Zax

  • T2Laser
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3261
    • View Profile
    • T2Laser
Re: Convert2PDF Update
« Reply #24 on: September 04, 2016, 05:22:25 AM »
Looks good with T2Laser.

Why would you convert the bezier to an arc, I don't have a problem with either just wondering why the extra effort?

Agastar

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1878
    • View Profile
Re: Convert2PDF Update
« Reply #25 on: September 04, 2016, 06:25:33 AM »
my mom used to say jokingly that if all else fails, read the instructions. Yes, John should RTM lol.

I started this post asking for ideas to solve a problem I was having. I fixed the problem but I didn't like my solution as it seemed like more of a hack than a well thought approach. But, while typing up this post I had another look at the PDF reference guide https://partners.adobe.com/public/developer/en/pdf/PDFReference.pdf#page181. Of course the answer was right there!

Ok well, that should be easy enough to refactor what I have written already. I was already on the right track with how to handle the command for a given path but I missed the concept of sub paths and that is why I was experiencing difficulties with certain PDFs.

Ok, I'll knock that out today and then I should be able to handle drawing any PDF paths.

Agastar

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1878
    • View Profile
Re: Convert2PDF Update
« Reply #26 on: September 04, 2016, 06:32:36 AM »
That is a feature for reducing the number of objects specifically for BCL. It will add to the conversion time to do that but I'm going to make it optional. You can tell it to not convert and you will get lines and splines.

This reminds me, I need to save the conversations until the current other is closed and then have the conversion multithreaded to save time.


Agastar

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1878
    • View Profile
Re: Convert2PDF Update
« Reply #27 on: September 06, 2016, 06:39:55 AM »
Here is a teaser for some of the other PDFs I've been converting. Still a few bugs to work out on converting the objects to LwPolylines, arcs, and circles. Some convert fine and some don't while all of the ones I don't convert are working fine so far.

Once I get that last few bugs worked out it will be time to move onto text. :)

Zax

  • T2Laser
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3261
    • View Profile
    • T2Laser
Re: Convert2PDF Update
« Reply #28 on: September 06, 2016, 07:36:50 AM »
I didn't load them with anything else to confirm, but they look ok in T2Laser.

Administrator

  • Administrator
  • Hero Member
  • *****
  • Posts: 1763
  • Pilot Instructor
    • View Profile
Re: Convert2PDF Update
« Reply #29 on: September 06, 2016, 08:23:40 AM »
These all loaded into BCL without any problems...!!!

I can tell you, I could laser these 4 drawings absolutely perfectly!

The elevator is beautiful...if the rest of the plane drawings come out this perfect...we are in business building airplanes...!!!

Beautiful work, absolutely beautiful...job well done...!!!
Ralph--Admin -- support_BenCutLaser_us
http://www.BenCutLaser.us/BenCutLaserSetup1.8.1r.exe.zip
http://www.BenCutLaser.us/BCLVirtualLaserMachineSetup1.8.1.exe.zip
BCL Paid license: $39.95
VLM Paid license: $19.95 (stand alone version)
via Paypal to bclpp@primemail.com