Tile2Hatch development

Discussion forum for contributors and developers who are using the QCAD ECMAScript development platform or the C++ plugin interface or who are otherwise looking to contribute to QCAD (translations, documentation, etc).

Moderator: andrew

Post Reply
CVH
Premier Member
Posts: 1031
Joined: Wed Sep 27, 2017 4:17 pm
Location: Belgium; Antwerp

Tile2Hatch development

Post by CVH » Thu Dec 26, 2019 9:01 am

Andrew,

Recently I did mention 'we' are developing an addon to convert a TILE to a HATCH-pattern.
Something similar exist in Lisp for AutoCAD, AutoLISP.

At a certain point I got stuck in the math and needed 2 numerical solution.
They worked fine in Excel, 105 columns wide.

Studied the Lisp and discovered it was also done numerical at drawing grid level.
This makes it nececarry to draw in a 0.01 unit grid.
Within a 1 X 1 unit Tile. Orthogonally spaced.
Pritty the same except they could have reduced their math further.
Still, I wasn't happy with all those restrictions for a simple gonio thing.

The most spectacular discovery is: It is not the drawing grid that is limited but
the orientation related to the use of a grid structure
.
Not necessarily the drawing grid but eventually the Tile grid.
Besides that, it is not the segment but only its startpoint that has to sit in the 'Master Tile'.

At this point the Qcad script has a similar outcome as the AutoLISP.
Confining to the same restriction as they have.
Except:
  • Free reference positioning, there is no drawing grid restriction.
    The startpoint thing.
    Some others details.
I Still need to thoroughly test the free Tile size/shape, free tessellation functionality.
I know that eventually this will work out because I'm doing it in Excel.

Beside working out the back-side, I also want to enhance the front-side.
Preconditioning the input.

Hatches exist of: spacings, Dots, Line-segments and ... endless lines.
Arcs, Circles, Ellipse, Splines and Polys all can be interpolated by segments.

Lets asume I have a selection of a bunch of these.
And I have them in a QList by document.querySelectedEntities()

Q1: How do I explode them at script level like we do at drawing level.
Something like: isNotSegment -> shape.GetExploded -> replace by segments.
Really exploding them in the drawing and returning the newly constructed Id's.
So I can add these to the QList of the selection.
In one go would be nice but then again, I don't mind it would be type per type.

Q2: What would be the place of your choise to put the tool in?
It is not that hard to change this later, but knowing upfront would be handy.
  • -> Misc - Script Examples - Import/Export?
    -> Misc - Import/Export?
    -> Misc - Modify? (beside Regenerate Hatch)
    -> Any other?
Thanks,
Best wishes for 2020 for those reading,
CVH
QCADpro 3.25.2.1 / win7pro 32 bit / 4GB / 1e generation i7 2.6Ghz / HDD GeForce GT 520

John Hyslop
Premier Member
Posts: 262
Joined: Mon Sep 30, 2019 6:21 am
Location: Melbourne - Australia

Re: Tile2Hatch development

Post by John Hyslop » Thu Dec 26, 2019 11:59 am

Hi CVH
I see you're busy with this one :-) it will be a great tool once you've nailed it..I found another tool that does output for hatch patterns..it converts arcs and circles and yes another AC tool.. I'm not home at the moment but will email to you when I'm back..it has a VLX extension it's limitations are 50 objects..I'll forward onto you when I get back..
Cheers
John...
IF IT IS TO BE IT IS UP TO ME [ Ten most powerful 2 letter words ]

CVH
Premier Member
Posts: 1031
Joined: Wed Sep 27, 2017 4:17 pm
Location: Belgium; Antwerp

Re: Tile2Hatch development

Post by CVH » Sat Dec 28, 2019 8:27 am

Hatching.png
Hatching.png (76.26 KiB) Viewed 1804 times
It took about 5 minutes to prepare this. :)
It took about 15 seconds to set the output filename. :D
The only thing you notice is that the file dialog closes. :P
It takes about 30.000 times longer to put the pat file with Notepad++ in the system folder as UTF8. :lol:


Edit: counted them: 143


Cheers,
CVH
QCADpro 3.25.2.1 / win7pro 32 bit / 4GB / 1e generation i7 2.6Ghz / HDD GeForce GT 520

CVH
Premier Member
Posts: 1031
Joined: Wed Sep 27, 2017 4:17 pm
Location: Belgium; Antwerp

Exploding2Lines ... Tile2Hatch development

Post by CVH » Sun Dec 29, 2019 8:23 am

CVH wrote:
Thu Dec 26, 2019 9:01 am
Q1: How do I explode them at script level like we do at drawing level.
Found out this could be: Explode.explodeSelection(di, toolTitle)
But with some twists:
  • I would like to end with only line segments if applicable.
  • Arcs should not be skipped.
So I could still use it as a base to develop a specific method.
Reading further in Explode.js I stumbled on:

If solid, hatches are exploded in boundaries loops
  • & boundaries loops further in shapes
    • & boundaries loops shapes further in individual shapes.
Or if not solid, in PainterPaths
  • & Paths further in shapes
    • & Paths shapes further in individual shapes.
What I don't understand is that individual PainterPaths shapes can be splines....?
IMHO:
If the outer thing are boundaries then the inner thing of a hatch can only be line segments or dots!
And yes, Boundaries could be splines.


Snippet Explode.js

Code: Select all

    // explode hatch into lines / solid fill into boundary:
    else if (isHatchEntity(entity)) {
        if (entity.isSolid()) {
            for (k=0; k<entity.getLoopCount(); k++) {
                var shapes = entity.getLoopBoundary(k);
                for (n=0; n<shapes.length; n++) {
                    shape = shapes[n];
                    ret.push(shape.clone());
                }
            }
        }
        else {
            painterPaths = entity.getPainterPaths(false);
            for (k=0; k<painterPaths.length; k++) {
                shapes = painterPaths[k].getShapes();
                for (n=0; n<shapes.length; n++) {
                    shape = shapes[n].data();
                    if (isSplineShape(shape)) {
                        shape = ShapeAlgorithms.splineToLineOrArc(shape, 0.01);
                    }
                    ret.push(shape.clone());
                }
            }
        }
    }
QCADpro 3.25.2.1 / win7pro 32 bit / 4GB / 1e generation i7 2.6Ghz / HDD GeForce GT 520

John Hyslop
Premier Member
Posts: 262
Joined: Mon Sep 30, 2019 6:21 am
Location: Melbourne - Australia

Re: Tile2Hatch development

Post by John Hyslop » Sun Dec 29, 2019 10:12 am

Hi CVH

I emailed you about this tool but haven't heard back, I have had trouble with servers and recently moved
them.... It's an AC tool free/donation see below:-
I redid Qcad Logo in it but had settings on high quality 32 lines for arcs :-) I hope your tool is as good as this one
I'm sure it will be..It can use almost everything Arcs,Circle,Polylines, Splines and Lines to create a Hatch Pattern..
Also have the ability to set size of hatch this one was set to 25x25 ( metric ) well almost lol 25.4 would be more to the fact..
If you don't have this email let me know and I'll send again... :-)
Qcad-Logo-New = 1375 Lines of code in notepad ++ OMG :-)
Attachments
QCAD-LOGO-NEW.jpg
QCAD-LOGO-NEW.jpg (63.6 KiB) Viewed 1764 times
QCAD-LOGO-NEW.pat
(97.03 KiB) Downloaded 97 times
Draw Hatch 12.3.jpg
Draw Hatch 12.3.jpg (34.16 KiB) Viewed 1764 times
IF IT IS TO BE IT IS UP TO ME [ Ten most powerful 2 letter words ]

John Hyslop
Premier Member
Posts: 262
Joined: Mon Sep 30, 2019 6:21 am
Location: Melbourne - Australia

Re: Tile2Hatch development

Post by John Hyslop » Sun Dec 29, 2019 10:58 am

Hi CVH
What I don't understand is if I explode the qcad logo it's only 119 entities? Why would the pat file be so big?
Maybe I'll try removing lines and see what difference it makes?????
Even though it's so big I doesn't seem to lag my pc..
weird...

Cheers
John
IF IT IS TO BE IT IS UP TO ME [ Ten most powerful 2 letter words ]

CVH
Premier Member
Posts: 1031
Joined: Wed Sep 27, 2017 4:17 pm
Location: Belgium; Antwerp

Re: Tile2Hatch development

Post by CVH » Sun Dec 29, 2019 11:50 am

co-linear dashes that could be combined to one dash.
CVH

edit: no that would reduce the pat file...
Last edited by CVH on Sun Dec 29, 2019 1:14 pm, edited 1 time in total.
QCADpro 3.25.2.1 / win7pro 32 bit / 4GB / 1e generation i7 2.6Ghz / HDD GeForce GT 520

CVH
Premier Member
Posts: 1031
Joined: Wed Sep 27, 2017 4:17 pm
Location: Belgium; Antwerp

Re: Tile2Hatch development

Post by CVH » Sun Dec 29, 2019 12:38 pm

or better said bad coding....
QCAD-LOGO-NEW.pat Line 12-32
21 identical dashes angled 65,9245 each 25 spaced to the right.
startX = 24.510408--49.510408--74.510408--99.510408.....

Code: Select all

65.9245, 24.510408,2.511941, 22.825217,10.198502, 0.55088,-1286.402806
65.9245, 49.510408,2.511941, 22.825217,10.198502, 0.55088,-1286.402806
65.9245, 74.510408,2.511941, 22.825217,10.198502, 0.55088,-1286.402806
65.9245, 99.510408,2.511941, 22.825217,10.198502, 0.55088,-1286.402806
65.9245, 124.510408,2.511941, 22.825217,10.198502, 0.55088,-1286.402806
65.9245, 149.510408,2.511941, 22.825217,10.198502, 0.55088,-1286.402806
65.9245, 174.510408,2.511941, 22.825217,10.198502, 0.55088,-1286.402806
65.9245, 199.510408,2.511941, 22.825217,10.198502, 0.55088,-1286.402806
65.9245, 224.510408,2.511941, 22.825217,10.198502, 0.55088,-1286.402806
65.9245, 249.510408,2.511941, 22.825217,10.198502, 0.55088,-1286.402806
65.9245, 274.510408,2.511941, 22.825217,10.198502, 0.55088,-1286.402806
65.9245, 299.510408,2.511941, 22.825217,10.198502, 0.55088,-1286.402806
65.9245, 324.510408,2.511941, 22.825217,10.198502, 0.55088,-1286.402806
65.9245, 349.510408,2.511941, 22.825217,10.198502, 0.55088,-1286.402806
65.9245, 374.510408,2.511941, 22.825217,10.198502, 0.55088,-1286.402806
65.9245, 399.510408,2.511941, 22.825217,10.198502, 0.55088,-1286.402806
65.9245, 424.510408,2.511941, 22.825217,10.198502, 0.55088,-1286.402806
65.9245, 449.510408,2.511941, 22.825217,10.198502, 0.55088,-1286.402806
65.9245, 474.510408,2.511941, 22.825217,10.198502, 0.55088,-1286.402806
65.9245, 499.510408,2.511941, 22.825217,10.198502, 0.55088,-1286.402806
65.9245, 524.510408,2.511941, 22.825217,10.198502, 0.55088,-1286.402806

Tiles2Hatch spits out:
65.924502,24.510408,2.511941,246.220966,.485643,.55088,-1286.402888
all 21 combined in one.
dash2 is faulty too, pritty certain its .402888... instead of .402806...
Thats a trig math problem one has to catch off.

Cheers,
CVH
Last edited by CVH on Sun Jan 19, 2020 10:50 pm, edited 2 times in total.
QCADpro 3.25.2.1 / win7pro 32 bit / 4GB / 1e generation i7 2.6Ghz / HDD GeForce GT 520

CVH
Premier Member
Posts: 1031
Joined: Wed Sep 27, 2017 4:17 pm
Location: Belgium; Antwerp

Re: Tile2Hatch development

Post by CVH » Sun Dec 29, 2019 1:40 pm

John Hyslop wrote:
Sun Dec 29, 2019 10:12 am
I emailed you about this tool but haven't heard back,
Well, if someone can decompile VLX to something else but crab.
The UI is readable, VLX is intended to keep out copycats.
John Hyslop wrote:
Sun Dec 29, 2019 10:12 am
..It can use almost everything Arcs,Circle,Polylines, Splines and Lines to create a Hatch Pattern..
Hope you saw the preview:
https://qcad.org/rsforum/viewtopic.php? ... 058#p26053
Dots, Line-segments, Xlines, Arcs, Circles, Ellipse-Arcs, Ellipses,...
... Splines, Polys, Mixed Polys, Polys with widths, Texts, Solids, ... Hatches
Crafting a relative uniform explosion method for curved curves at this instance.
John Hyslop wrote:
Sun Dec 29, 2019 10:58 am
Even though it's so big I doesn't seem to lag my pc..
That's another issue...Mine tend to be slow as far as I notice untill now.
Maybe copying isn't a bad idea..
Halfway:
https://qcad.org/rsforum/viewtopic.php? ... 636#p25607
CVH wrote:
Thu Nov 21, 2019 11:30 pm

When I stepped across by 2 or by 3 'Tiles' the definitions have to be repeated by posX+10 and by posX+10 and posX+20.
In the vertical direction I only stepped by 1, so there is no need to repeat definitions in that direction.
IFSO I have to alter my approach.

Cheers,
CVH
QCADpro 3.25.2.1 / win7pro 32 bit / 4GB / 1e generation i7 2.6Ghz / HDD GeForce GT 520

Luca
Registered Member
Posts: 2
Joined: Thu Nov 19, 2020 8:45 pm

Re: Tile2Hatch development

Post by Luca » Fri Nov 20, 2020 10:36 am

CVH wrote:
Sun Dec 29, 2019 1:40 pm
John Hyslop wrote:
Sun Dec 29, 2019 10:12 am
I emailed you about this tool but haven't heard back,
Well, if someone can decompile VLX to something else but crab.
The UI is readable, VLX is intended to keep out copycats.
Decompiling vlx might work. There are also numerous online viewers available.

CVH
Premier Member
Posts: 1031
Joined: Wed Sep 27, 2017 4:17 pm
Location: Belgium; Antwerp

Re: Tile2Hatch development

Post by CVH » Fri Nov 20, 2020 12:17 pm

Well, Luca, all,

I, we, have left the LISP and VLX path.
We cannot really talk about optimal here. Rather Not at all.
The best example was HatchKit and their pattern coding has been matched, even surpassed at some points.

The addon is fully functional at the moment and generates optimized Hatch patterns so far the numeric system is able to.
But in John Hyslop words 'Only for the developer'. :oops:

The math core was perfected half May 2020 and is unchanged since.
It is the implementation under QCAD that is proven to be very hard.
The envelope itself has taken 6 moths up to now ... on and off.
12,887 lines of code, 3 custom UIs with over 80 parameters.
8 for hatching, 11 for tiling and the rest to handle complex entities not a line segment or a dot.

T2H handles:
- Points, Line segments (of course)
- XLines (some, others are possible but get messy very quick)
(Rays don't have a meaning while hatching)
- Arcs, Circles
- Polylines, Polylines widths as outline
- Leaders, Solids as outline, Faces as outline
- Ellipses, Splines
- Texts, TTF as outline, Dimensions
- Patterned hatches and solid hatches as outline
+ Orphaned hatch patterns only included in drawings.
+ Viewing pattern files, but in fact casting them as real entities.
... Transformation of hatch patterns files are a next step. The math is ready.
All this in one go and it takes longer to enter a pattern name than T2H needs to code them.

Not at all K.I.S.S. but it is kept super versatile for the moment on purpose.
Implementing constrictions or hard coding parameters is a simple matter.

Thanks for at least showing some interest. :wink:
I am still waiting on a place to insert the addon in the GUI -> see Q2

Regards,
CVH
QCADpro 3.25.2.1 / win7pro 32 bit / 4GB / 1e generation i7 2.6Ghz / HDD GeForce GT 520

CVH
Premier Member
Posts: 1031
Joined: Wed Sep 27, 2017 4:17 pm
Location: Belgium; Antwerp

Re: Tile2Hatch development

Post by CVH » Fri Nov 20, 2020 2:06 pm

Luca wrote:
Fri Nov 20, 2020 10:36 am
Decompiling vlx might work.
Still, I was curious ... dropped the VLX and:
  • "Something went wrong. Please try again."
Regards,
CVH
QCADpro 3.25.2.1 / win7pro 32 bit / 4GB / 1e generation i7 2.6Ghz / HDD GeForce GT 520

Post Reply

Return to “QCAD Developers and Contributors”