Referencing Image from a PlugIn

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Referencing Image from a PlugIn

CLamb
I would like to develop a plugin to fit a line to a set of points in a bitmap image. LibreCAD doesn't seem to allow selection of part of a bitmap so I would have the user draw a polygon enclosing the points to be used. I don't see any easy way to retrieve an image though. The only way I see is to use getAllEntities and then search it for the only Image entity. This seems cumbersome. Is there a better way of doing this?
Reply | Threaded
Open this post in threaded view
|

Re: Referencing Image from a PlugIn

LordOfBikes
Administrator
Other plugins use
doc->getSelect()
which returns a list of selected objects.

When the polygon is created as polyline, then selected with image, you should get 2 objects.
One is the polyline, the other the image.

I don't know what getEnt() and getData() will return for polyline and image, but I assume that it should be possible to extract the vertices from these data and also the image path and location.
But I never used image or polyline in plugins, so it's also possible, that the interface lacks functionality here.
Reply | Threaded
Open this post in threaded view
|

Re: Referencing Image from a PlugIn

perepujal
In reply to this post by CLamb
Just an snippet from an old, unfinished and abandoned plugin I started long time ago.
HTH

void LC_ImageVec::execComm(Document_Interface *doc,
                             QWidget *parent, QString cmd)
{
    Q_UNUSED(cmd);
    Q_UNUSED(parent);
    QPointF base1;
    Plug_Entity *img = doc->getEnt("Select an image");
    if (img == NULL) return;
    QHash<int, QVariant> imgData;
    img->getData(&imgData);
    if (imgData.value(DPI::ETYPE) != DPI::IMAGE) return;
    QPointF bottomLeft, dir;
    bottomLeft.setX(imgData.value(DPI::STARTX).toDouble());
    bottomLeft.setY(imgData.value(DPI::STARTY).toDouble());
    pixelSize.setX(imgData.value(DPI::SIZEU).toDouble());
    pixelSize.setY(imgData.value(DPI::SIZEV).toDouble());
    dir.setX(imgData.value(DPI::ENDX).toDouble());
    dir.setY(imgData.value(DPI::ENDY).toDouble());
    QString name = imgData.value(DPI::BLKNAME).toString();

    QImage image;
    if ( !image.load (name) ) return;
Reply | Threaded
Open this post in threaded view
|

Re: Referencing Image from a PlugIn

CLamb
In reply to this post by LordOfBikes
But how does one select an image?
Reply | Threaded
Open this post in threaded view
|

Re: Referencing Image from a PlugIn

perepujal
File Import Insert Image to put it in the drawing,

then click it to select, alternative you could drag a rectangle enclosing it
or crossing it, depending on the direction of the drag.

Once it is selected, your code could use doc->getSelect() as LordOfBikes says.

The snippet I posted uses doc->getEnt("Select an image") which not cares
about what it is selected and prompts you to click an image.