Core: move image plane to core system
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -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
|
||||
|
||||
38
src/App/ImagePlane.cpp
Normal file
38
src/App/ImagePlane.cpp
Normal file
@@ -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");
|
||||
}
|
||||
55
src/App/ImagePlane.h
Normal file
55
src/App/ImagePlane.h
Normal file
@@ -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 <App/GeoFeature.h>
|
||||
#include <App/PropertyFile.h>
|
||||
#include <App/PropertyUnits.h>
|
||||
|
||||
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
|
||||
@@ -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();
|
||||
|
||||
@@ -224,6 +224,7 @@
|
||||
#include <Inventor/nodes/SoText2.h>
|
||||
#include <Inventor/nodes/SoTexture2.h>
|
||||
#include <Inventor/nodes/SoTexture3.h>
|
||||
#include <Inventor/nodes/SoTextureCoordinate2.h>
|
||||
#include <Inventor/nodes/SoTextureCoordinate3.h>
|
||||
#include <Inventor/nodes/SoTransform.h>
|
||||
#include <Inventor/nodes/SoTransformation.h>
|
||||
|
||||
168
src/Gui/ViewProviderImagePlane.cpp
Normal file
168
src/Gui/ViewProviderImagePlane.cpp
Normal file
@@ -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 <sstream>
|
||||
# include <QFileInfo>
|
||||
# include <QImage>
|
||||
# include <QString>
|
||||
|
||||
# include <Inventor/nodes/SoCoordinate3.h>
|
||||
# include <Inventor/nodes/SoFaceSet.h>
|
||||
# include <Inventor/nodes/SoMaterial.h>
|
||||
# include <Inventor/nodes/SoSeparator.h>
|
||||
# include <Inventor/nodes/SoTexture2.h>
|
||||
# include <Inventor/nodes/SoTextureCoordinate2.h>
|
||||
#endif
|
||||
|
||||
#include <App/Document.h>
|
||||
#include <Gui/BitmapFactory.h>
|
||||
#include <App/ImagePlane.h>
|
||||
|
||||
#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<std::string> ViewProviderImagePlane::getDisplayModes() const
|
||||
{
|
||||
std::vector<std::string> 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<App::ImagePlane*>(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);
|
||||
}
|
||||
}
|
||||
64
src/Gui/ViewProviderImagePlane.h
Normal file
64
src/Gui/ViewProviderImagePlane.h
Normal file
@@ -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 <Gui/ViewProviderGeometryObject.h>
|
||||
|
||||
|
||||
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<std::string> 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
|
||||
Reference in New Issue
Block a user