Skip to content

Commit

Permalink
Core: support to load old project files containing image planes
Browse files Browse the repository at this point in the history
  • Loading branch information
wwmayer committed Mar 26, 2023
1 parent 251022c commit 07cf291
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 17 deletions.
18 changes: 17 additions & 1 deletion src/App/Application.cpp
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand Down
10 changes: 5 additions & 5 deletions src/App/ImagePlane.cpp
Expand Up @@ -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()
Expand Down
6 changes: 3 additions & 3 deletions src/App/ImagePlane.h
Expand Up @@ -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
Expand All @@ -57,7 +57,7 @@ class AppExport ImagePlane : public App::GeoFeature
}
};

} //namespace App
} //namespace Image


#endif // App_ImagePlane_H
2 changes: 1 addition & 1 deletion src/Gui/FileHandler.cpp
Expand Up @@ -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()");
Expand Down
2 changes: 1 addition & 1 deletion src/Gui/TaskView/TaskImageScale.cpp
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions src/Gui/TaskView/TaskImageScale.h
Expand Up @@ -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:
Expand All @@ -46,7 +46,7 @@ class TaskImageScale : public QWidget

private:
std::unique_ptr<Ui_TaskImageScale> ui;
App::WeakPtrT<App::ImagePlane> feature;
App::WeakPtrT<Image::ImagePlane> feature;
double aspectRatio;
};

Expand Down
8 changes: 4 additions & 4 deletions src/Gui/ViewProviderImagePlane.cpp
Expand Up @@ -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);
Expand All @@ -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()) {
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 07cf291

Please sign in to comment.