Drawing: Apply clang format

This commit is contained in:
wmayer
2023-09-10 12:33:49 +02:00
committed by wwmayer
parent ebcd846d09
commit 789912d745
52 changed files with 2650 additions and 2106 deletions

View File

@@ -22,9 +22,9 @@
#include "PreCompiled.h"
#ifndef _PreComp_
# include <sstream>
#include <sstream>
# include <QFileInfo>
#include <QFileInfo>
#endif
#include <App/DocumentObjectPy.h>
@@ -42,41 +42,42 @@
#include "DrawingView.h"
namespace DrawingGui {
class Module : public Py::ExtensionModule<Module>
namespace DrawingGui
{
class Module: public Py::ExtensionModule<Module>
{
public:
Module() : Py::ExtensionModule<Module>("DrawingGui")
Module()
: Py::ExtensionModule<Module>("DrawingGui")
{
add_varargs_method("open",&Module::open
);
add_varargs_method("insert",&Module::importer
);
add_varargs_method("export",&Module::exporter
);
initialize("This module is the DrawingGui module."); // register with Python
add_varargs_method("open", &Module::open);
add_varargs_method("insert", &Module::importer);
add_varargs_method("export", &Module::exporter);
initialize("This module is the DrawingGui module.");// register with Python
}
virtual ~Module() {}
virtual ~Module()
{}
private:
virtual Py::Object invoke_method_varargs(void *method_def, const Py::Tuple &args)
virtual Py::Object invoke_method_varargs(void* method_def, const Py::Tuple& args)
{
try {
return Py::ExtensionModule<Module>::invoke_method_varargs(method_def, args);
}
catch (const Base::Exception &e) {
catch (const Base::Exception& e) {
throw Py::RuntimeError(e.what());
}
catch (const std::exception &e) {
catch (const std::exception& e) {
throw Py::RuntimeError(e.what());
}
}
Py::Object open(const Py::Tuple& args)
{
char* Name;
if (!PyArg_ParseTuple(args.ptr(), "et","utf-8",&Name))
if (!PyArg_ParseTuple(args.ptr(), "et", "utf-8", &Name)) {
throw Py::Exception();
}
std::string EncodedName = std::string(Name);
PyMem_Free(Name);
@@ -90,7 +91,7 @@ private:
view->setWindowIcon(Gui::BitmapFactory().pixmap("actions/drawing-landscape"));
QFileInfo fi(fileName);
view->setWindowTitle(fi.fileName());
view->resize( 400, 300 );
view->resize(400, 300);
Gui::getMainWindow()->addWindow(view);
}
else {
@@ -103,8 +104,9 @@ private:
{
char* Name;
const char* dummy;
if (!PyArg_ParseTuple(args.ptr(), "et|s","utf-8",&Name,&dummy))
if (!PyArg_ParseTuple(args.ptr(), "et|s", "utf-8", &Name, &dummy)) {
throw Py::Exception();
}
std::string EncodedName = std::string(Name);
PyMem_Free(Name);
@@ -118,9 +120,10 @@ private:
view->setWindowIcon(Gui::BitmapFactory().pixmap("actions/drawing-landscape"));
QFileInfo fi(fileName);
view->setWindowTitle(fi.fileName());
view->resize( 400, 300 );
view->resize(400, 300);
Gui::getMainWindow()->addWindow(view);
} else {
}
else {
throw Py::Exception(PyExc_IOError, "unknown filetype");
}
@@ -130,8 +133,9 @@ private:
{
PyObject* object;
char* Name;
if (!PyArg_ParseTuple(args.ptr(), "Oet",&object,"utf-8",&Name))
if (!PyArg_ParseTuple(args.ptr(), "Oet", &object, "utf-8", &Name)) {
throw Py::Exception();
}
std::string EncodedName = std::string(Name);
PyMem_Free(Name);
@@ -140,7 +144,8 @@ private:
for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) {
PyObject* item = (*it).ptr();
if (PyObject_TypeCheck(item, &(App::DocumentObjectPy::Type))) {
App::DocumentObject* obj = static_cast<App::DocumentObjectPy*>(item)->getDocumentObjectPtr();
App::DocumentObject* obj =
static_cast<App::DocumentObjectPy*>(item)->getDocumentObjectPtr();
if (obj->getTypeId().isDerivedFrom(Drawing::FeaturePage::getClassTypeId())) {
Base::FileInfo fi_out(EncodedName.c_str());
Base::ofstream str_out(fi_out, std::ios::out | std::ios::binary);
@@ -150,7 +155,8 @@ private:
throw Py::Exception(PyExc_IOError, str.str().c_str());
}
if (fi_out.hasExtension("svg")) {
std::string fn = static_cast<Drawing::FeaturePage*>(obj)->PageResult.getValue();
std::string fn =
static_cast<Drawing::FeaturePage*>(obj)->PageResult.getValue();
Base::FileInfo fi_in(fn);
Base::ifstream str_in(fi_in, std::ios::in | std::ios::binary);
if (!str_in) {
@@ -165,31 +171,45 @@ private:
break;
}
else if (fi_out.hasExtension("dxf")) {
const std::vector<App::DocumentObject*>& views = static_cast<Drawing::FeaturePage*>(obj)->Group.getValues();
for (std::vector<App::DocumentObject*>::const_iterator it = views.begin(); it != views.end(); ++it) {
if ((*it)->getTypeId().isDerivedFrom(Drawing::FeatureViewPart::getClassTypeId())) {
Drawing::FeatureViewPart* view = static_cast<Drawing::FeatureViewPart*>(*it);
const std::vector<App::DocumentObject*>& views =
static_cast<Drawing::FeaturePage*>(obj)->Group.getValues();
for (std::vector<App::DocumentObject*>::const_iterator it = views.begin();
it != views.end();
++it) {
if ((*it)->getTypeId().isDerivedFrom(
Drawing::FeatureViewPart::getClassTypeId())) {
Drawing::FeatureViewPart* view =
static_cast<Drawing::FeatureViewPart*>(*it);
App::DocumentObject* link = view->Source.getValue();
if (!link) {
throw Py::ValueError("No object linked");
}
if (!link->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId())) {
if (!link->getTypeId().isDerivedFrom(
Part::Feature::getClassTypeId())) {
throw Py::TypeError("Linked object is not a Part object");
}
TopoDS_Shape shape = static_cast<Part::Feature*>(link)->Shape.getShape().getShape();
TopoDS_Shape shape =
static_cast<Part::Feature*>(link)->Shape.getShape().getShape();
if (!shape.IsNull()) {
Base::Vector3d dir = view->Direction.getValue();
bool hidden = view->ShowHiddenLines.getValue();
bool smooth = view->ShowSmoothLines.getValue();
Drawing::ProjectionAlgos::ExtractionType type = Drawing::ProjectionAlgos::Plain;
if (hidden) type = (Drawing::ProjectionAlgos::ExtractionType)(type|Drawing::ProjectionAlgos::WithHidden);
if (smooth) type = (Drawing::ProjectionAlgos::ExtractionType)(type|Drawing::ProjectionAlgos::WithSmooth);
Drawing::ProjectionAlgos::ExtractionType type =
Drawing::ProjectionAlgos::Plain;
if (hidden) {
type = (Drawing::ProjectionAlgos::ExtractionType)(
type | Drawing::ProjectionAlgos::WithHidden);
}
if (smooth) {
type = (Drawing::ProjectionAlgos::ExtractionType)(
type | Drawing::ProjectionAlgos::WithSmooth);
}
float scale = view->Scale.getValue();
float tol = view->Tolerance.getValue();
Drawing::ProjectionAlgos project(shape, dir);
str_out << project.getDXF(type, scale, tol);
break; // TODO: How to add several shapes?
break;// TODO: How to add several shapes?
}
}
}
@@ -197,11 +217,13 @@ private:
break;
}
else {
throw Py::TypeError("Export of page object as this file format is not supported by Drawing module");
throw Py::TypeError("Export of page object as this file format is not "
"supported by Drawing module");
}
}
else {
throw Py::TypeError("Export of this object type is not supported by Drawing module");
throw Py::TypeError(
"Export of this object type is not supported by Drawing module");
}
}
}
@@ -215,4 +237,4 @@ PyObject* initModule()
return Base::Interpreter().addModule(new Module);
}
} // namespace DrawingGui
}// namespace DrawingGui