From 52ce6c4e2f07017e93ba412639662abefd7ef4f8 Mon Sep 17 00:00:00 2001 From: wmayer Date: Mon, 14 Nov 2011 10:05:28 +0000 Subject: [PATCH] + fix bug with mirrored image + special handling of SVG images to have best resolution git-svn-id: https://free-cad.svn.sourceforge.net/svnroot/free-cad/trunk@5129 e8eeb9e2-ec13-0410-a4a9-efa5cf37419d --- src/Mod/Image/App/ImagePlane.cpp | 9 +-- src/Mod/Image/Gui/ViewProviderImagePlane.cpp | 64 +++++++++++--------- src/Mod/Image/Gui/ViewProviderImagePlane.h | 6 +- 3 files changed, 44 insertions(+), 35 deletions(-) diff --git a/src/Mod/Image/App/ImagePlane.cpp b/src/Mod/Image/App/ImagePlane.cpp index 332b92dc3..a8975db4f 100644 --- a/src/Mod/Image/App/ImagePlane.cpp +++ b/src/Mod/Image/App/ImagePlane.cpp @@ -38,14 +38,11 @@ PROPERTY_SOURCE(Image::ImagePlane, App::GeoFeature) ImagePlane::ImagePlane() { - - ADD_PROPERTY_TYPE( ImageFile,(0) , "ImagePlane",Prop_None,"File of the image"); - ADD_PROPERTY_TYPE( XSize, (100) , "ImagePlane",Prop_None,"Size of a pixel in X"); - ADD_PROPERTY_TYPE( YSize, (100) , "ImagePlane",Prop_None,"Size of a pixel in Y"); - + ADD_PROPERTY_TYPE( ImageFile,(0) , "ImagePlane",Prop_None,"File of the image"); + ADD_PROPERTY_TYPE( XSize, (100), "ImagePlane",Prop_None,"Size of a pixel in X"); + ADD_PROPERTY_TYPE( YSize, (100), "ImagePlane",Prop_None,"Size of a pixel in Y"); } ImagePlane::~ImagePlane() { } - diff --git a/src/Mod/Image/Gui/ViewProviderImagePlane.cpp b/src/Mod/Image/Gui/ViewProviderImagePlane.cpp index 83d3a701f..92c536a1e 100644 --- a/src/Mod/Image/Gui/ViewProviderImagePlane.cpp +++ b/src/Mod/Image/Gui/ViewProviderImagePlane.cpp @@ -24,28 +24,17 @@ #include "PreCompiled.h" #ifndef _PreComp_ -# include -# include # include # include -# include -# include -# include -# include -# include -# include -# include # include # include # include -# include -# include # include # include # include # include -# include # include +# include # include # include #endif @@ -59,6 +48,7 @@ #include #include #include + using namespace Gui; using namespace ImageGui; using namespace Image; @@ -68,8 +58,7 @@ PROPERTY_SOURCE(ImageGui::ViewProviderImagePlane, Gui::ViewProviderGeometryObjec ViewProviderImagePlane::ViewProviderImagePlane() { - - pcImagePlaneRoot = new Gui::SoFCSelection(); + pcImagePlaneRoot = new Gui::SoFCSelection(); pcImagePlaneRoot->highlightMode = Gui::SoFCSelection::OFF; pcImagePlaneRoot->selectionMode = Gui::SoFCSelection::SEL_OFF; //pcImageRoot->style = Gui::SoFCSelection::BOX; @@ -84,7 +73,6 @@ ViewProviderImagePlane::ViewProviderImagePlane() pcDrawStyle->ref(); pcDrawStyle->style = SoDrawStyle::LINES; pcDrawStyle->lineWidth = 2; - } ViewProviderImagePlane::~ViewProviderImagePlane() @@ -97,7 +85,6 @@ ViewProviderImagePlane::~ViewProviderImagePlane() void ViewProviderImagePlane::attach(App::DocumentObject *pcObj) { - ViewProviderDocumentObject::attach(pcObj); //// Draw trajectory lines @@ -106,10 +93,10 @@ void ViewProviderImagePlane::attach(App::DocumentObject *pcObj) SoTextureCoordinate2 *textCoord = new SoTextureCoordinate2; textCoord->point.set1Value(0,0,0); - textCoord->point.set1Value(1,0,1); + textCoord->point.set1Value(1,1,0); textCoord->point.set1Value(2,1,1); - textCoord->point.set1Value(3,1,0); - planesep->addChild( textCoord ); + textCoord->point.set1Value(3,0,1); + planesep->addChild(textCoord); // texture texture->model = SoTexture2::MODULATE; @@ -118,9 +105,9 @@ void ViewProviderImagePlane::attach(App::DocumentObject *pcObj) //planesep->addChild( pcDrawStyle ); // plane pcCoords->point.set1Value(0,0,0,0); - pcCoords->point.set1Value(1,0,1,0); + pcCoords->point.set1Value(1,1,0,0); pcCoords->point.set1Value(2,1,1,0); - pcCoords->point.set1Value(3,1,0,0); + pcCoords->point.set1Value(3,0,1,0); SoFaceSet *faceset = new SoFaceSet; faceset->numVertices.set1Value(0,4); planesep->addChild( faceset ); @@ -131,7 +118,6 @@ void ViewProviderImagePlane::attach(App::DocumentObject *pcObj) pcImagePlaneRoot->objectName = pcObj->getNameInDocument(); pcImagePlaneRoot->documentName = pcObj->getDocument()->getName(); pcImagePlaneRoot->subElementName = "Main"; - } void ViewProviderImagePlane::setDisplayMode(const char* ModeName) @@ -148,6 +134,18 @@ std::vector ViewProviderImagePlane::getDisplayModes(void) const return StrList; } +bool ViewProviderImagePlane::loadSvg(const char* filename, float x, float y, QImage& img) +{ + QFileInfo fi(QString::fromUtf8(filename)); + if (fi.suffix().toLower() == QLatin1String("svg")) { + QPixmap px = BitmapFactory().pixmapFromSvg(filename, QSize((int)x,(int)y)); + img = px.toImage(); + return true; + } + + return false; +} + void ViewProviderImagePlane::updateData(const App::Property* prop) { Image::ImagePlane* pcPlaneObj = static_cast(pcObject); @@ -157,13 +155,26 @@ void ViewProviderImagePlane::updateData(const App::Property* prop) //pcCoords->point.setNum(4); pcCoords->point.set1Value(0,-(x/2),-(y/2),0.0); - pcCoords->point.set1Value(1,-(x/2),+(y/2),0.0); + pcCoords->point.set1Value(1,+(x/2),-(y/2),0.0); pcCoords->point.set1Value(2,+(x/2),+(y/2),0.0); - pcCoords->point.set1Value(3,+(x/2),-(y/2),0.0); + pcCoords->point.set1Value(3,-(x/2),+(y/2),0.0); + + QImage impQ; + loadSvg(pcPlaneObj->ImageFile.getValue(), x, y, impQ); + if (!impQ.isNull()) { + SoSFImage img; + // convert to Coin bitmap + BitmapFactory().convert(impQ,img); + texture->image = img; + } } else if (prop == &pcPlaneObj->ImageFile) { - QImage impQ(QString::fromUtf8(pcPlaneObj->ImageFile.getValue())); - if(! impQ.isNull()){ + float x = pcPlaneObj->XSize.getValue(); + float y = pcPlaneObj->YSize.getValue(); + QImage impQ; + if (!loadSvg(pcPlaneObj->ImageFile.getValue(),x,y, impQ)) + impQ.load(QString::fromUtf8(pcPlaneObj->ImageFile.getValue())); + if (!impQ.isNull()) { SoSFImage img; // convert to Coin bitmap BitmapFactory().convert(impQ,img); @@ -171,4 +182,3 @@ void ViewProviderImagePlane::updateData(const App::Property* prop) } } } - diff --git a/src/Mod/Image/Gui/ViewProviderImagePlane.h b/src/Mod/Image/Gui/ViewProviderImagePlane.h index 337bf0620..cf03ce246 100644 --- a/src/Mod/Image/Gui/ViewProviderImagePlane.h +++ b/src/Mod/Image/Gui/ViewProviderImagePlane.h @@ -27,11 +27,10 @@ #include #include -class SoDragger; -class SoJackDragger; class SoCoordinate3; class SoDrawStyle; class SoTexture2; +class QImage; namespace ImageGui { @@ -52,6 +51,9 @@ public: std::vector getDisplayModes() const; void updateData(const App::Property*); +private: + bool loadSvg(const char*, float x, float y, QImage& img); + protected: Gui::SoFCSelection * pcImagePlaneRoot; SoCoordinate3 * pcCoords;