LibreCad-2.2.0.alpha - Need help with drawing a line in C++

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

LibreCad-2.2.0.alpha - Need help with drawing a line in C++

mad-hattter
Hello,

I wonder if somebody could help?
I'm writng an add on (C++) for LibreCad that will allow one to divide an entity
in to multiple even segments, so far I've managed to select a line, drawn at any
position and angle , divide it and get a list of x-y pairs. I can't work out which
of the existing functions to use to draw my dividing lines. I'll think about dividing
the line later, for now I just want be able to draw lines.
Suggestions please.

Redards

When finished I'll make it available to LibreCad users.

//Data I have:-
line x1-y1, x2-y2   -11.6315 -12.8005  -   -10.2243 -14.8783   on layer 2
line x1-y1, x2-y2   -4.70536 -8.10979  -   -3.29815 -10.1876   on layer 2
line x1-y1, x2-y2   2.22076 -3.41909   -   3.62797 -5.49692    on layer 2
line x1-y1, x2-y2   9.14688 1.27162    -   10.5541 -0.806215   on layer 2
line x1-y1, x2-y2   16.073 5.96233     -   17.4802 3.88449     on layer 2


Reply | Threaded
Open this post in threaded view
|

Re: LibreCad-2.2.0.alpha - Need help with drawing a line in C++

LordOfBikes
Administrator
You may have a look at the sample plugin source \plugins\sample\sample.cpp
or one of the other plugins how to create entities.

The sample plugin asks for two points and create a line between them.
The method where the line is added is:
lc_Sampledlg::processAction(Document_Interface *doc)

And the magic is done here:
    doc->addLine(&start, &end);

Read the Document_Interface class to learn its possibilities.
The Document_Interface class grant you access to the current RS_Document, which contains the current drawing.
This is how it works, you don't have to draw anything yourself, that is done by the application. In the plugin, you modify the document by removing and adding entities.

Look at the existing plugins to see how to iterate over all or only selected entities.

You can delete the original line with Document_Interface::removeEntity() or keep it and add the split lines on a different layer.
For the split lines you may use Document_Interface::addLines() or  Document_Interface::addPolyline().

Good luck!