diff --git a/src/App/Application.cpp b/src/App/Application.cpp index ef0e383782..d5f9ac7ec6 100644 --- a/src/App/Application.cpp +++ b/src/App/Application.cpp @@ -94,6 +94,7 @@ #include "FeaturePython.h" #include "GeoFeature.h" #include "GeoFeatureGroupExtension.h" +#include "ImagePlane.h" #include "InventorObject.h" #include "Link.h" #include "LinkBaseExtensionPy.h" @@ -2053,12 +2054,13 @@ void Application::initTypes() App::DocumentObjectGroup ::init(); App::DocumentObjectGroupPython ::init(); App::DocumentObjectFileIncluded::init(); + App::ImagePlane ::init(); App::InventorObject ::init(); App::VRMLObject ::init(); App::Annotation ::init(); App::AnnotationLabel ::init(); App::MeasureDistance ::init(); - App ::MaterialObject ::init(); + App::MaterialObject ::init(); App::MaterialObjectPython ::init(); App::TextDocument ::init(); App::Placement ::init(); diff --git a/src/App/CMakeLists.txt b/src/App/CMakeLists.txt index e4b096aedd..1190eff4bc 100644 --- a/src/App/CMakeLists.txt +++ b/src/App/CMakeLists.txt @@ -147,6 +147,7 @@ SET(Document_CPP_SRCS GeoFeature.cpp GeoFeatureGroupExtensionPyImp.cpp GeoFeatureGroupExtension.cpp + ImagePlane.cpp OriginGroupExtensionPyImp.cpp OriginGroupExtension.cpp PartPyImp.cpp @@ -192,6 +193,7 @@ SET(Document_HPP_SRCS FeatureTest.h GeoFeature.h GeoFeatureGroupExtension.h + ImagePlane.h OriginGroupExtension.h Part.h Origin.h diff --git a/src/App/ImagePlane.cpp b/src/App/ImagePlane.cpp new file mode 100644 index 0000000000..842fb6fe4f --- /dev/null +++ b/src/App/ImagePlane.cpp @@ -0,0 +1,38 @@ +/*************************************************************************** + * Copyright (c) 2011 Jürgen Riegel (juergen.riegel@web.de) * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + +#include "PreCompiled.h" + +#include "ImagePlane.h" + + +using namespace App; + +PROPERTY_SOURCE(App::ImagePlane, App::GeoFeature) + + +ImagePlane::ImagePlane() +{ + ADD_PROPERTY_TYPE( ImageFile,(nullptr) , "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"); +} diff --git a/src/App/ImagePlane.h b/src/App/ImagePlane.h new file mode 100644 index 0000000000..5d73a67cc8 --- /dev/null +++ b/src/App/ImagePlane.h @@ -0,0 +1,55 @@ +/*************************************************************************** + * Copyright (c) 2011 Jürgen Riegel (juergen.riegel@web.de) * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + +#ifndef App_ImagePlane_H +#define App_ImagePlane_H + +#include +#include +#include + +namespace App +{ + +class AppExport ImagePlane : public App::GeoFeature +{ + PROPERTY_HEADER_WITH_OVERRIDE(App::ImagePlane); + +public: + /// Constructor + ImagePlane(); + ~ImagePlane() override = default; + + App::PropertyFileIncluded ImageFile; + App::PropertyLength XSize; + App::PropertyLength YSize; + + /// returns the type name of the ViewProvider + const char* getViewProviderName() const override { + return "Gui::ViewProviderImagePlane"; + } +}; + +} //namespace App + + +#endif // App_ImagePlane_H diff --git a/src/Gui/Application.cpp b/src/Gui/Application.cpp index b3685d4a35..238b0190e0 100644 --- a/src/Gui/Application.cpp +++ b/src/Gui/Application.cpp @@ -101,6 +101,7 @@ #include "ViewProviderGeoFeatureGroup.h" #include "ViewProviderGeometryObject.h" #include "ViewProviderGroupExtension.h" +#include "ViewProviderImagePlane.h" #include "ViewProviderInventorObject.h" #include "ViewProviderLine.h" #include "ViewProviderLink.h" @@ -1808,6 +1809,7 @@ void Application::initTypes() Gui::ViewProviderDocumentObjectGroupPython ::init(); Gui::ViewProviderDragger ::init(); Gui::ViewProviderGeometryObject ::init(); + Gui::ViewProviderImagePlane ::init(); Gui::ViewProviderInventorObject ::init(); Gui::ViewProviderVRMLObject ::init(); Gui::ViewProviderAnnotation ::init(); diff --git a/src/Gui/InventorAll.h b/src/Gui/InventorAll.h index 0d462fe74f..ce1a6d8916 100644 --- a/src/Gui/InventorAll.h +++ b/src/Gui/InventorAll.h @@ -224,6 +224,7 @@ #include #include #include +#include #include #include #include diff --git a/src/Gui/ViewProviderImagePlane.cpp b/src/Gui/ViewProviderImagePlane.cpp new file mode 100644 index 0000000000..d3240272e4 --- /dev/null +++ b/src/Gui/ViewProviderImagePlane.cpp @@ -0,0 +1,168 @@ +/*************************************************************************** + * Copyright (c) 2011 Jürgen Riegel (juergen.riegel@web.de) * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + +#include "PreCompiled.h" +#ifndef _PreComp_ +# include +# include +# include +# include + +# include +# include +# include +# include +# include +# include +#endif + +#include +#include +#include + +#include "ViewProviderImagePlane.h" + + +using namespace Gui; + + +PROPERTY_SOURCE(Gui::ViewProviderImagePlane, Gui::ViewProviderGeometryObject) + +ViewProviderImagePlane::ViewProviderImagePlane() +{ + texture = new SoTexture2; + texture->ref(); + + pcCoords = new SoCoordinate3(); + pcCoords->ref(); +} + +ViewProviderImagePlane::~ViewProviderImagePlane() +{ + pcCoords->unref(); + texture->unref(); +} + +void ViewProviderImagePlane::attach(App::DocumentObject *pcObj) +{ + ViewProviderGeometryObject::attach(pcObj); + + // NOTE: SoFCSelection node has beem removed because it led to + // problems using the image as a construction plane with the + // draft commands + SoSeparator* planesep = new SoSeparator; + planesep->addChild(pcCoords); + + SoTextureCoordinate2 *textCoord = new SoTextureCoordinate2; + textCoord->point.set1Value(0,0,0); + textCoord->point.set1Value(1,1,0); + textCoord->point.set1Value(2,1,1); + textCoord->point.set1Value(3,0,1); + planesep->addChild(textCoord); + + // texture + texture->model = SoTexture2::MODULATE; + planesep->addChild(texture); + + planesep->addChild(pcShapeMaterial); + + // plane + pcCoords->point.set1Value(0,0,0,0); + pcCoords->point.set1Value(1,1,0,0); + pcCoords->point.set1Value(2,1,1,0); + pcCoords->point.set1Value(3,0,1,0); + SoFaceSet *faceset = new SoFaceSet; + faceset->numVertices.set1Value(0,4); + planesep->addChild(faceset); + + addDisplayMaskMode(planesep, "ImagePlane"); +} + +void ViewProviderImagePlane::setDisplayMode(const char* ModeName) +{ + if (strcmp("ImagePlane",ModeName) == 0) + setDisplayMaskMode("ImagePlane"); + ViewProviderGeometryObject::setDisplayMode(ModeName); +} + +std::vector ViewProviderImagePlane::getDisplayModes() const +{ + std::vector StrList; + StrList.emplace_back("ImagePlane"); + 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) +{ + App::ImagePlane* pcPlaneObj = static_cast(pcObject); + if (prop == &pcPlaneObj->XSize || prop == &pcPlaneObj->YSize) { + float x = pcPlaneObj->XSize.getValue(); + float y = pcPlaneObj->YSize.getValue(); + + //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(2,+(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) { + std::string fileName = pcPlaneObj->ImageFile.getValue(); + float x = pcPlaneObj->XSize.getValue(); + float y = pcPlaneObj->YSize.getValue(); + QImage impQ; + if (!loadSvg(fileName.c_str(), x, y, impQ)) { + if (!fileName.empty()) { + impQ.load(QString::fromStdString(fileName)); + } + } + if (!impQ.isNull()) { + SoSFImage img; + // convert to Coin bitmap + BitmapFactory().convert(impQ,img); + texture->image = img; + } + } + else { + Gui::ViewProviderGeometryObject::updateData(prop); + } +} diff --git a/src/Gui/ViewProviderImagePlane.h b/src/Gui/ViewProviderImagePlane.h new file mode 100644 index 0000000000..12b5119bba --- /dev/null +++ b/src/Gui/ViewProviderImagePlane.h @@ -0,0 +1,64 @@ +/*************************************************************************** + * Copyright (c) 2011 Jürgen Riegel (juergen.riegel@web.de) * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + +#ifndef GUI_ViewProviderImagePlane_H +#define GUI_ViewProviderImagePlane_H + +#include + + +class SoCoordinate3; +class SoDrawStyle; +class SoTexture2; +class QImage; + +namespace Gui +{ + +class GuiExport ViewProviderImagePlane : public Gui::ViewProviderGeometryObject +{ + PROPERTY_HEADER_WITH_OVERRIDE(Gui::ViewProviderImagePlane); + +public: + /// constructor. + ViewProviderImagePlane(); + + /// destructor. + ~ViewProviderImagePlane() override; + + void attach(App::DocumentObject *pcObject) override; + void setDisplayMode(const char* ModeName) override; + std::vector getDisplayModes() const override; + void updateData(const App::Property*) override; + +private: + bool loadSvg(const char*, float x, float y, QImage& img); + +protected: + SoCoordinate3 * pcCoords; + SoTexture2 * texture; + }; + +} //namespace Gui + + +#endif // GUI_ViewProviderImagePlane_H