00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "PreCompiled.h"
00025
00026 #ifndef _PreComp_
00027 # include <Inventor/SbVec3f.h>
00028 # include <Inventor/nodes/SoSeparator.h>
00029 # include <Inventor/nodes/SoCoordinate3.h>
00030 # include <Inventor/nodes/SoDrawStyle.h>
00031 # include <Inventor/nodes/SoFaceSet.h>
00032 # include <Inventor/nodes/SoShapeHints.h>
00033 # include <Inventor/nodes/SoImage.h>
00034 # include <Inventor/nodes/SoTextureCoordinate2.h>
00035 # include <Inventor/nodes/SoTexture2.h>
00036 # include <QFile>
00037 # include <QFileInfo>
00038 # include <QImage>
00039 # include <QString>
00040 #endif
00041
00042 #include "ViewProviderImagePlane.h"
00043
00044 #include <Mod/Image/App/ImagePlane.h>
00045 #include <App/Document.h>
00046 #include <Gui/BitmapFactory.h>
00047 #include <Base/FileInfo.h>
00048 #include <Base/Stream.h>
00049 #include <Base/Console.h>
00050 #include <sstream>
00051
00052 using namespace Gui;
00053 using namespace ImageGui;
00054 using namespace Image;
00055
00056
00057 PROPERTY_SOURCE(ImageGui::ViewProviderImagePlane, Gui::ViewProviderGeometryObject)
00058
00059 ViewProviderImagePlane::ViewProviderImagePlane()
00060 {
00061 texture = new SoTexture2;
00062 texture->ref();
00063
00064 pcCoords = new SoCoordinate3();
00065 pcCoords->ref();
00066 }
00067
00068 ViewProviderImagePlane::~ViewProviderImagePlane()
00069 {
00070 pcCoords->unref();
00071 texture->unref();
00072 }
00073
00074 void ViewProviderImagePlane::attach(App::DocumentObject *pcObj)
00075 {
00076 ViewProviderDocumentObject::attach(pcObj);
00077
00078
00079
00080
00081 SoSeparator* planesep = new SoSeparator;
00082 planesep->addChild(pcCoords);
00083
00084 SoTextureCoordinate2 *textCoord = new SoTextureCoordinate2;
00085 textCoord->point.set1Value(0,0,0);
00086 textCoord->point.set1Value(1,1,0);
00087 textCoord->point.set1Value(2,1,1);
00088 textCoord->point.set1Value(3,0,1);
00089 planesep->addChild(textCoord);
00090
00091
00092 texture->model = SoTexture2::MODULATE;
00093 planesep->addChild(texture);
00094
00095
00096 pcCoords->point.set1Value(0,0,0,0);
00097 pcCoords->point.set1Value(1,1,0,0);
00098 pcCoords->point.set1Value(2,1,1,0);
00099 pcCoords->point.set1Value(3,0,1,0);
00100 SoFaceSet *faceset = new SoFaceSet;
00101 faceset->numVertices.set1Value(0,4);
00102 planesep->addChild(faceset);
00103
00104 addDisplayMaskMode(planesep, "ImagePlane");
00105 }
00106
00107 void ViewProviderImagePlane::setDisplayMode(const char* ModeName)
00108 {
00109 if (strcmp("ImagePlane",ModeName) == 0)
00110 setDisplayMaskMode("ImagePlane");
00111 ViewProviderGeometryObject::setDisplayMode(ModeName);
00112 }
00113
00114 std::vector<std::string> ViewProviderImagePlane::getDisplayModes(void) const
00115 {
00116 std::vector<std::string> StrList;
00117 StrList.push_back("ImagePlane");
00118 return StrList;
00119 }
00120
00121 bool ViewProviderImagePlane::loadSvg(const char* filename, float x, float y, QImage& img)
00122 {
00123 QFileInfo fi(QString::fromUtf8(filename));
00124 if (fi.suffix().toLower() == QLatin1String("svg")) {
00125 QPixmap px = BitmapFactory().pixmapFromSvg(filename, QSize((int)x,(int)y));
00126 img = px.toImage();
00127 return true;
00128 }
00129
00130 return false;
00131 }
00132
00133 void ViewProviderImagePlane::updateData(const App::Property* prop)
00134 {
00135 Image::ImagePlane* pcPlaneObj = static_cast<Image::ImagePlane*>(pcObject);
00136 if (prop == &pcPlaneObj->XSize || prop == &pcPlaneObj->YSize) {
00137 float x = pcPlaneObj->XSize.getValue();
00138 float y = pcPlaneObj->YSize.getValue();
00139
00140
00141 pcCoords->point.set1Value(0,-(x/2),-(y/2),0.0);
00142 pcCoords->point.set1Value(1,+(x/2),-(y/2),0.0);
00143 pcCoords->point.set1Value(2,+(x/2),+(y/2),0.0);
00144 pcCoords->point.set1Value(3,-(x/2),+(y/2),0.0);
00145
00146 QImage impQ;
00147 loadSvg(pcPlaneObj->ImageFile.getValue(), x, y, impQ);
00148 if (!impQ.isNull()) {
00149 SoSFImage img;
00150
00151 BitmapFactory().convert(impQ,img);
00152 texture->image = img;
00153 }
00154 }
00155 else if (prop == &pcPlaneObj->ImageFile) {
00156 float x = pcPlaneObj->XSize.getValue();
00157 float y = pcPlaneObj->YSize.getValue();
00158 QImage impQ;
00159 if (!loadSvg(pcPlaneObj->ImageFile.getValue(),x,y, impQ))
00160 impQ.load(QString::fromUtf8(pcPlaneObj->ImageFile.getValue()));
00161 if (!impQ.isNull()) {
00162 SoSFImage img;
00163
00164 BitmapFactory().convert(impQ,img);
00165 texture->image = img;
00166 }
00167 }
00168 }