Core: support to load old project files containing image planes

See forum: https://forum.freecad.org/viewtopic.php?p=670545#p670545
This commit is contained in:
wmayer
2023-03-24 23:25:48 +01:00
committed by wwmayer
parent cdb47d2f4f
commit a2579ebb92
7 changed files with 33 additions and 17 deletions

View File

@@ -217,6 +217,18 @@ init_freecad_module(void)
return PyModule_Create(&FreeCADModuleDef);
}
PyMODINIT_FUNC
init_image_module()
{
static struct PyModuleDef ImageModuleDef = {
PyModuleDef_HEAD_INIT,
"Image", "", -1,
nullptr,
nullptr, nullptr, nullptr, nullptr
};
return PyModule_Create(&ImageModuleDef);
}
Application::Application(std::map<std::string,std::string> &mConfig)
: _mConfig(mConfig), _pActiveDoc(nullptr), _isRestoring(false),_allowPartial(false)
, _isClosingAll(false), _objCount(-1), _activeTransactionID(0)
@@ -254,6 +266,10 @@ void Application::setupPythonTypes()
};
PyObject* pConsoleModule = PyModule_Create(&ConsoleModuleDef);
// fake Image module
PyObject* imageModule = init_image_module();
PyDict_SetItemString(modules, "Image", imageModule);
// introducing additional classes
// NOTE: To finish the initialization of our own type objects we must
@@ -2054,7 +2070,7 @@ void Application::initTypes()
App::DocumentObjectGroup ::init();
App::DocumentObjectGroupPython ::init();
App::DocumentObjectFileIncluded::init();
App::ImagePlane ::init();
Image::ImagePlane ::init();
App::InventorObject ::init();
App::VRMLObject ::init();
App::Annotation ::init();

View File

@@ -25,18 +25,18 @@
#include "ImagePlane.h"
using namespace App;
using namespace Image;
PROPERTY_SOURCE(App::ImagePlane, App::GeoFeature)
PROPERTY_SOURCE(Image::ImagePlane, App::GeoFeature)
ImagePlane::ImagePlane()
: XPixelsPerMeter{1000.0}
, YPixelsPerMeter{1000.0}
{
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");
ADD_PROPERTY_TYPE( ImageFile,(nullptr) , "ImagePlane",App::Prop_None,"File of the image");
ADD_PROPERTY_TYPE( XSize, (100), "ImagePlane",App::Prop_None,"Size of a pixel in X");
ADD_PROPERTY_TYPE( YSize, (100), "ImagePlane",App::Prop_None,"Size of a pixel in Y");
}
int ImagePlane::getXSizeInPixel()

View File

@@ -27,12 +27,12 @@
#include <App/PropertyFile.h>
#include <App/PropertyUnits.h>
namespace App
namespace Image
{
class AppExport ImagePlane : public App::GeoFeature
{
PROPERTY_HEADER_WITH_OVERRIDE(App::ImagePlane);
PROPERTY_HEADER_WITH_OVERRIDE(Image::ImagePlane);
public:
/// Constructor
@@ -57,7 +57,7 @@ public:
}
};
} //namespace App
} //namespace Image
#endif // App_ImagePlane_H

View File

@@ -201,7 +201,7 @@ void FileHandler::openImage()
QFileInfo fi;
fi.setFile(filename);
Gui::cmdAppDocumentArgs(doc, "addObject('%s', '%s')", "App::ImagePlane", fi.baseName().toStdString());
Gui::cmdAppDocumentArgs(doc, "addObject('%s', '%s')", "Image::ImagePlane", fi.baseName().toStdString());
Gui::cmdAppDocumentArgs(doc, "ActiveObject.ImageFile = '%s'", fi.absoluteFilePath().toStdString());
Gui::cmdAppDocumentArgs(doc, "ActiveObject.Label = '%s'", fi.baseName().toStdString());
Gui::cmdAppDocument(doc, "recompute()");

View File

@@ -39,7 +39,7 @@
using namespace Gui;
TaskImageScale::TaskImageScale(App::ImagePlane* obj, QWidget* parent)
TaskImageScale::TaskImageScale(Image::ImagePlane* obj, QWidget* parent)
: QWidget(parent)
, ui(new Ui_TaskImageScale)
, feature(obj)

View File

@@ -37,7 +37,7 @@ class TaskImageScale : public QWidget
Q_OBJECT
public:
explicit TaskImageScale(App::ImagePlane* obj, QWidget* parent = nullptr);
explicit TaskImageScale(Image::ImagePlane* obj, QWidget* parent = nullptr);
~TaskImageScale() override;
private:
@@ -46,7 +46,7 @@ private:
private:
std::unique_ptr<Ui_TaskImageScale> ui;
App::WeakPtrT<App::ImagePlane> feature;
App::WeakPtrT<Image::ImagePlane> feature;
double aspectRatio;
};

View File

@@ -163,7 +163,7 @@ void ViewProviderImagePlane::manipulateImage()
dynamic_cast<App::GeoFeature*>(getObject())
);
dialog->addTaskBox(new TaskImageScale(
dynamic_cast<App::ImagePlane*>(getObject())
dynamic_cast<Image::ImagePlane*>(getObject())
));
Gui::Control().showDialog(dialog);
@@ -179,7 +179,7 @@ void ViewProviderImagePlane::resizePlane(float xsize, float ysize)
void ViewProviderImagePlane::loadImage()
{
App::ImagePlane* imagePlane = static_cast<App::ImagePlane*>(pcObject);
Image::ImagePlane* imagePlane = static_cast<Image::ImagePlane*>(pcObject);
std::string fileName = imagePlane->ImageFile.getValue();
if (!fileName.empty()) {
@@ -223,7 +223,7 @@ QSizeF ViewProviderImagePlane::loadRaster(const char* fileName, QImage& img)
void ViewProviderImagePlane::reloadIfSvg()
{
App::ImagePlane* imagePlane = static_cast<App::ImagePlane*>(pcObject);
Image::ImagePlane* imagePlane = static_cast<Image::ImagePlane*>(pcObject);
std::string fileName = imagePlane->ImageFile.getValue();
double xsize = imagePlane->XSize.getValue();
@@ -266,7 +266,7 @@ void ViewProviderImagePlane::convertToSFImage(const QImage& img)
void ViewProviderImagePlane::updateData(const App::Property* prop)
{
App::ImagePlane* pcPlaneObj = static_cast<App::ImagePlane*>(pcObject);
Image::ImagePlane* pcPlaneObj = static_cast<Image::ImagePlane*>(pcObject);
if (prop == &pcPlaneObj->XSize || prop == &pcPlaneObj->YSize) {
float xsize = pcPlaneObj->XSize.getValue();
float ysize = pcPlaneObj->YSize.getValue();