+ 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
This commit is contained in:
@@ -24,28 +24,17 @@
|
||||
#include "PreCompiled.h"
|
||||
|
||||
#ifndef _PreComp_
|
||||
# include <Inventor/SoDB.h>
|
||||
# include <Inventor/SoInput.h>
|
||||
# include <Inventor/SbVec3f.h>
|
||||
# include <Inventor/nodes/SoSeparator.h>
|
||||
# include <Inventor/nodes/SoTransform.h>
|
||||
# include <Inventor/nodes/SoSphere.h>
|
||||
# include <Inventor/nodes/SoRotation.h>
|
||||
# include <Inventor/actions/SoSearchAction.h>
|
||||
# include <Inventor/draggers/SoJackDragger.h>
|
||||
# include <Inventor/VRMLnodes/SoVRMLTransform.h>
|
||||
# include <Inventor/nodes/SoBaseColor.h>
|
||||
# include <Inventor/nodes/SoCoordinate3.h>
|
||||
# include <Inventor/nodes/SoDrawStyle.h>
|
||||
# include <Inventor/nodes/SoFaceSet.h>
|
||||
# include <Inventor/nodes/SoIndexedFaceSet.h>
|
||||
# include <Inventor/nodes/SoMarkerSet.h>
|
||||
# include <Inventor/nodes/SoShapeHints.h>
|
||||
# include <Inventor/nodes/SoImage.h>
|
||||
# include <Inventor/nodes/SoTextureCoordinate2.h>
|
||||
# include <Inventor/nodes/SoTexture2.h>
|
||||
# include <Inventor/nodes/SoCube.h>
|
||||
# include <QFile>
|
||||
# include <QFileInfo>
|
||||
# include <QImage>
|
||||
# include <QString>
|
||||
#endif
|
||||
@@ -59,6 +48,7 @@
|
||||
#include <Base/Stream.h>
|
||||
#include <Base/Console.h>
|
||||
#include <sstream>
|
||||
|
||||
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<std::string> 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<Image::ImagePlane*>(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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user