[pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci
This commit is contained in:
pre-commit-ci[bot]
2025-05-02 07:28:59 +00:00
parent ce25de290e
commit 3ef7ba2d9d
18 changed files with 166 additions and 140 deletions

View File

@@ -84,9 +84,10 @@ public:
&Module::getVtkVersion,
"Returns the VTK version FreeCAD is linked against");
#ifdef FC_USE_VTK_PYTHON
add_varargs_method("isVtkCompatible",
&Module::isVtkCompatible,
"Checks if the passed vtkObject is compatible with the c++ VTK version FreeCAD uses");
add_varargs_method(
"isVtkCompatible",
&Module::isVtkCompatible,
"Checks if the passed vtkObject is compatible with the c++ VTK version FreeCAD uses");
#endif
#endif
add_varargs_method("show",
@@ -334,7 +335,7 @@ private:
Py::Object getVtkVersion(const Py::Tuple& args)
{
if (!PyArg_ParseTuple(args.ptr(),"")) {
if (!PyArg_ParseTuple(args.ptr(), "")) {
throw Py::Exception();
}
@@ -345,13 +346,13 @@ private:
Py::Object isVtkCompatible(const Py::Tuple& args)
{
PyObject* pcObj = nullptr;
if (!PyArg_ParseTuple(args.ptr(),"O", &pcObj)) {
if (!PyArg_ParseTuple(args.ptr(), "O", &pcObj)) {
throw Py::Exception();
}
// if non is returned the VTK object was created by annother VTK library, and the
// python api used to create it cannot be used with FreeCAD
vtkObjectBase *obj = vtkPythonUtil::GetPointerFromObject(pcObj, "vtkObject");
vtkObjectBase* obj = vtkPythonUtil::GetPointerFromObject(pcObj, "vtkObject");
if (!obj) {
PyErr_Clear();
return Py::False();

View File

@@ -226,14 +226,14 @@ vtkSmartPointer<vtkDataSet> FemPostFilter::getInputData()
}
vtkAlgorithmOutput* output = active.source->GetInputConnection(0, 0);
if(!output) {
if (!output) {
return nullptr;
}
vtkAlgorithm* algo = output->GetProducer();
if(!algo) {
if (!algo) {
return nullptr;
}
if (Frame.getValue()>0) {
if (Frame.getValue() > 0) {
algo->UpdateTimeStep(Frame.getValue());
}
else {
@@ -302,11 +302,13 @@ namespace App
{
/// @cond DOXERR
PROPERTY_SOURCE_TEMPLATE(Fem::PostFilterPython, Fem::FemPostFilter)
template<> const char* Fem::PostFilterPython::getViewProviderName(void) const
template<>
const char* Fem::PostFilterPython::getViewProviderName(void) const
{
return "FemGui::ViewProviderPostFilterPython";
}
template<> PyObject* Fem::PostFilterPython::getPyObject()
template<>
PyObject* Fem::PostFilterPython::getPyObject()
{
if (PythonObject.is(Py::_None())) {
// ref counter is set to 1
@@ -319,8 +321,7 @@ template<> PyObject* Fem::PostFilterPython::getPyObject()
// explicit template instantiation
template class FemExport FeaturePythonT<Fem::FemPostFilter>;
}// namespace App
} // namespace App
// ***************************************************************************

View File

@@ -72,7 +72,7 @@ protected:
std::vector<vtkSmartPointer<vtkAlgorithm>> algorithmStorage;
};
//pipeline handling
// pipeline handling
void addFilterPipeline(const FilterPipeline& p, std::string name);
FilterPipeline& getFilterPipeline(std::string name);
void setActiveFilterPipeline(std::string name);
@@ -81,6 +81,7 @@ protected:
void setTransformLocation(TransformLocation loc);
friend class FemPostFilterPy;
public:
/// Constructor
FemPostFilter();

View File

@@ -36,9 +36,9 @@
// clang-format on
#ifdef FC_USE_VTK_PYTHON
#include <vtkUnstructuredGrid.h>
#include <vtkPythonUtil.h>
#endif //BUILD_FEM_VTK
#include <vtkUnstructuredGrid.h>
#include <vtkPythonUtil.h>
#endif // BUILD_FEM_VTK
using namespace Fem;
@@ -56,20 +56,20 @@ PyObject* FemPostFilterPy::addFilterPipeline(PyObject* args)
{
#ifdef FC_USE_VTK_PYTHON
const char* name;
PyObject *source = nullptr;
PyObject *target = nullptr;
PyObject* source = nullptr;
PyObject* target = nullptr;
if (PyArg_ParseTuple(args, "sOO", &name, &source, &target)) {
// extract the algorithms
vtkObjectBase *obj = vtkPythonUtil::GetPointerFromObject(source, "vtkAlgorithm");
vtkObjectBase* obj = vtkPythonUtil::GetPointerFromObject(source, "vtkAlgorithm");
if (!obj) {
// error marker is set by PythonUtil
return nullptr;
}
auto source_algo = static_cast<vtkAlgorithm*>(obj);
obj = vtkPythonUtil::GetPointerFromObject(target,"vtkAlgorithm");
obj = vtkPythonUtil::GetPointerFromObject(target, "vtkAlgorithm");
if (!obj) {
// error marker is set by PythonUtil
return nullptr;
@@ -130,7 +130,8 @@ PyObject* FemPostFilterPy::getInputData(PyObject* args)
copy = vtkUnstructuredGrid::New();
break;
default:
PyErr_SetString(PyExc_TypeError, "cannot return datatype object; not unstructured grid");
PyErr_SetString(PyExc_TypeError,
"cannot return datatype object; not unstructured grid");
Py_Return;
}
@@ -138,7 +139,7 @@ PyObject* FemPostFilterPy::getInputData(PyObject* args)
copy->DeepCopy(dataset);
PyObject* py_dataset = vtkPythonUtil::GetObjectFromPointer(copy);
return Py::new_reference_to(py_dataset);
return Py::new_reference_to(py_dataset);
#else
PyErr_SetString(PyExc_NotImplementedError, "VTK python wrapper not available");
Py_Return;
@@ -160,7 +161,7 @@ PyObject* FemPostFilterPy::getInputVectorFields(PyObject* args)
list.append(Py::String(field));
}
return Py::new_reference_to(list);
return Py::new_reference_to(list);
}
@@ -179,7 +180,7 @@ PyObject* FemPostFilterPy::getInputScalarFields(PyObject* args)
list.append(Py::String(field));
}
return Py::new_reference_to(list);
return Py::new_reference_to(list);
}
PyObject* FemPostFilterPy::getCustomAttributes(const char* /*attr*/) const

View File

@@ -169,12 +169,12 @@ int PropertyPostDataObject::getDataType()
PyObject* PropertyPostDataObject::getPyObject()
{
#ifdef FC_USE_VTK_PYTHON
//create a copy first
// create a copy first
auto copy = static_cast<PropertyPostDataObject*>(Copy());
// get the data python wrapper
PyObject* py_dataset = vtkPythonUtil::GetObjectFromPointer(copy->getValue());
auto result = Py::new_reference_to(py_dataset);
auto result = Py::new_reference_to(py_dataset);
delete copy;
return result;
@@ -187,7 +187,7 @@ PyObject* PropertyPostDataObject::getPyObject()
void PropertyPostDataObject::setPyObject(PyObject* value)
{
#ifdef FC_USE_VTK_PYTHON
vtkObjectBase *obj = vtkPythonUtil::GetPointerFromObject(value, "vtkDataObject");
vtkObjectBase* obj = vtkPythonUtil::GetPointerFromObject(value, "vtkDataObject");
if (!obj) {
throw Base::TypeError("Can only set vtkDataObject");
}

View File

@@ -204,9 +204,9 @@ void DataAlongLineMarker::customEvent(QEvent*)
// ***************************************************************************
// main task dialog
TaskPostWidget::TaskPostWidget(Gui::ViewProviderDocumentObject* view,
const QPixmap& icon,
const QString& title,
QWidget* parent)
const QPixmap& icon,
const QString& title,
QWidget* parent)
: QWidget(parent)
, m_object(view->getObject())
, m_view(view)
@@ -272,13 +272,14 @@ QDialogButtonBox::StandardButtons TaskDlgPost::getStandardButtons() const
{
bool guionly = true;
for (auto& widget : Content) {
if(auto task_box = dynamic_cast<Gui::TaskView::TaskBox*>(widget)) {
if (auto task_box = dynamic_cast<Gui::TaskView::TaskBox*>(widget)) {
// get the task widget and check if it is a post widget
auto widget = task_box->groupLayout()->itemAt(0)->widget();
if(auto post_widget = dynamic_cast<TaskPostWidget*>(widget)) {
if (auto post_widget = dynamic_cast<TaskPostWidget*>(widget)) {
guionly = guionly && post_widget->isGuiTaskOnly();
} else {
}
else {
// unknown panel, we can only assume
guionly = false;
}
@@ -334,10 +335,10 @@ void TaskDlgPost::clicked(int button)
{
if (button == QDialogButtonBox::Apply) {
for (auto& widget : Content) {
if(auto task_box = dynamic_cast<Gui::TaskView::TaskBox*>(widget)) {
if (auto task_box = dynamic_cast<Gui::TaskView::TaskBox*>(widget)) {
// get the task widget and check if it is a post widget
auto widget = task_box->groupLayout()->itemAt(0)->widget();
if(auto post_widget = dynamic_cast<TaskPostWidget*>(widget)) {
if (auto post_widget = dynamic_cast<TaskPostWidget*>(widget)) {
post_widget->apply();
}
}
@@ -350,10 +351,10 @@ bool TaskDlgPost::accept()
{
try {
for (auto& widget : Content) {
if(auto task_box = dynamic_cast<Gui::TaskView::TaskBox*>(widget)) {
if (auto task_box = dynamic_cast<Gui::TaskView::TaskBox*>(widget)) {
// get the task widget and check if it is a post widget
auto widget = task_box->groupLayout()->itemAt(0)->widget();
if(auto post_widget = dynamic_cast<TaskPostWidget*>(widget)) {
if (auto post_widget = dynamic_cast<TaskPostWidget*>(widget)) {
post_widget->applyPythonCode();
}
}
@@ -396,14 +397,13 @@ void TaskDlgPost::modifyStandardButtons(QDialogButtonBox* box)
// ***************************************************************************
// box to set the coloring
TaskPostDisplay::TaskPostDisplay(ViewProviderFemPostObject* view, QWidget* parent)
: TaskPostWidget(view,
Gui::BitmapFactory().pixmap("FEM_ResultShow"), QString(),
parent)
: TaskPostWidget(view, Gui::BitmapFactory().pixmap("FEM_ResultShow"), QString(), parent)
, ui(new Ui_TaskPostDisplay)
{
// setup the ui
ui->setupUi(this);
setWindowTitle(tr("Result display options")); // set title here as setupUi overrides the constructor title
setWindowTitle(
tr("Result display options")); // set title here as setupUi overrides the constructor title
setupConnections();
// update all fields
@@ -480,16 +480,16 @@ void TaskPostDisplay::applyPythonCode()
// functions
TaskPostFunction::TaskPostFunction(ViewProviderFemPostFunction* view, QWidget* parent)
: TaskPostWidget(view,
Gui::BitmapFactory().pixmap("fem-post-geo-plane"),
tr("Implicit function"),
parent)
Gui::BitmapFactory().pixmap("fem-post-geo-plane"),
tr("Implicit function"),
parent)
{
// we load the views widget
FunctionWidget* w = getTypedView<ViewProviderFemPostFunction>()->createControlWidget();
w->setParent(this);
w->setViewProvider(getTypedView<ViewProviderFemPostFunction>());
QVBoxLayout *layout = new QVBoxLayout;
QVBoxLayout* layout = new QVBoxLayout;
layout->addWidget(w);
setLayout(layout);
}
@@ -566,10 +566,7 @@ void TaskPostFrames::applyPythonCode()
// ***************************************************************************
// Branch
TaskPostBranch::TaskPostBranch(ViewProviderFemPostBranchFilter* view, QWidget* parent)
: TaskPostWidget(view,
Gui::BitmapFactory().pixmap("FEM_PostBranchFilter"),
QString(),
parent)
: TaskPostWidget(view, Gui::BitmapFactory().pixmap("FEM_PostBranchFilter"), QString(), parent)
, ui(new Ui_TaskPostBranch)
{
// setup the ui
@@ -621,9 +618,9 @@ void TaskPostBranch::applyPythonCode()
TaskPostDataAlongLine::TaskPostDataAlongLine(ViewProviderFemPostDataAlongLine* view,
QWidget* parent)
: TaskPostWidget(view,
Gui::BitmapFactory().pixmap("FEM_PostFilterDataAlongLine"),
QString(),
parent)
Gui::BitmapFactory().pixmap("FEM_PostFilterDataAlongLine"),
QString(),
parent)
, ui(new Ui_TaskPostDataAlongLine)
, marker(nullptr)
{
@@ -1041,9 +1038,9 @@ plt.show()\n";
// data at point filter
TaskPostDataAtPoint::TaskPostDataAtPoint(ViewProviderFemPostDataAtPoint* view, QWidget* parent)
: TaskPostWidget(view,
Gui::BitmapFactory().pixmap("FEM_PostFilterDataAtPoint"),
QString(),
parent)
Gui::BitmapFactory().pixmap("FEM_PostFilterDataAtPoint"),
QString(),
parent)
, viewer(nullptr)
, connSelectPoint(QMetaObject::Connection())
, ui(new Ui_TaskPostDataAtPoint)
@@ -1396,9 +1393,9 @@ TaskPostClip::TaskPostClip(ViewProviderFemPostClip* view,
App::PropertyLink* function,
QWidget* parent)
: TaskPostWidget(view,
Gui::BitmapFactory().pixmap("FEM_PostFilterClipRegion"),
QString(),
parent)
Gui::BitmapFactory().pixmap("FEM_PostFilterClipRegion"),
QString(),
parent)
, ui(new Ui_TaskPostClip)
{
assert(function);
@@ -1554,10 +1551,7 @@ void TaskPostClip::onInsideOutToggled(bool val)
// ***************************************************************************
// contours filter
TaskPostContours::TaskPostContours(ViewProviderFemPostContours* view, QWidget* parent)
: TaskPostWidget(view,
Gui::BitmapFactory().pixmap("FEM_PostFilterContours"),
QString(),
parent)
: TaskPostWidget(view, Gui::BitmapFactory().pixmap("FEM_PostFilterContours"), QString(), parent)
, ui(new Ui_TaskPostContours)
{
// setup the ui
@@ -1709,9 +1703,9 @@ void TaskPostContours::onRelaxationChanged(double value)
// cut filter
TaskPostCut::TaskPostCut(ViewProviderFemPostCut* view, App::PropertyLink* function, QWidget* parent)
: TaskPostWidget(view,
Gui::BitmapFactory().pixmap("FEM_PostFilterCutFunction"),
QString(),
parent)
Gui::BitmapFactory().pixmap("FEM_PostFilterCutFunction"),
QString(),
parent)
, ui(new Ui_TaskPostCut)
{
assert(function);
@@ -1847,9 +1841,9 @@ void TaskPostCut::onFunctionBoxCurrentIndexChanged(int idx)
// scalar clip filter
TaskPostScalarClip::TaskPostScalarClip(ViewProviderFemPostScalarClip* view, QWidget* parent)
: TaskPostWidget(view,
Gui::BitmapFactory().pixmap("FEM_PostFilterClipScalar"),
QString(),
parent)
Gui::BitmapFactory().pixmap("FEM_PostFilterClipScalar"),
QString(),
parent)
, ui(new Ui_TaskPostScalarClip)
{
// setup the ui
@@ -1970,10 +1964,7 @@ void TaskPostScalarClip::onInsideOutToggled(bool val)
// ***************************************************************************
// warp vector filter
TaskPostWarpVector::TaskPostWarpVector(ViewProviderFemPostWarpVector* view, QWidget* parent)
: TaskPostWidget(view,
Gui::BitmapFactory().pixmap("FEM_PostFilterWarp"),
QString(),
parent)
: TaskPostWidget(view, Gui::BitmapFactory().pixmap("FEM_PostFilterWarp"), QString(), parent)
, ui(new Ui_TaskPostWarpVector)
{
// setup the ui
@@ -2145,9 +2136,9 @@ static const std::vector<std::string> calculatorOperators = {
TaskPostCalculator::TaskPostCalculator(ViewProviderFemPostCalculator* view, QWidget* parent)
: TaskPostWidget(view,
Gui::BitmapFactory().pixmap("FEM_PostFilterCalculator"),
tr("Calculator options"),
parent)
Gui::BitmapFactory().pixmap("FEM_PostFilterCalculator"),
tr("Calculator options"),
parent)
, ui(new Ui_TaskPostCalculator)
{
// we load the views widget

View File

@@ -317,8 +317,7 @@ class TaskPostBranch: public TaskPostWidget
Q_OBJECT
public:
explicit TaskPostBranch(ViewProviderFemPostBranchFilter* view,
QWidget* parent = nullptr);
explicit TaskPostBranch(ViewProviderFemPostBranchFilter* view, QWidget* parent = nullptr);
~TaskPostBranch() override;
void applyPythonCode() override;

View File

@@ -37,7 +37,8 @@ using namespace FemGui;
PROPERTY_SOURCE(FemGui::ViewProviderFemPostFilterPythonBase, FemGui::ViewProviderFemPostObject)
ViewProviderFemPostFilterPythonBase::ViewProviderFemPostFilterPythonBase() {}
ViewProviderFemPostFilterPythonBase::ViewProviderFemPostFilterPythonBase()
{}
ViewProviderFemPostFilterPythonBase::~ViewProviderFemPostFilterPythonBase() = default;
@@ -46,10 +47,13 @@ std::vector<std::string> ViewProviderFemPostFilterPythonBase::getDisplayModes()
return std::vector<std::string>();
}
namespace Gui {
PROPERTY_SOURCE_TEMPLATE(FemGui::ViewProviderPostFilterPython, FemGui::ViewProviderFemPostFilterPythonBase)
namespace Gui
{
PROPERTY_SOURCE_TEMPLATE(FemGui::ViewProviderPostFilterPython,
FemGui::ViewProviderFemPostFilterPythonBase)
template<> PyObject* FemGui::ViewProviderPostFilterPython::getPyObject()
template<>
PyObject* FemGui::ViewProviderPostFilterPython::getPyObject()
{
if (!pyViewObject) {
pyViewObject = new ViewProviderFemPostFilterPy(this);
@@ -61,7 +65,7 @@ template<> PyObject* FemGui::ViewProviderPostFilterPython::getPyObject()
// explicit template instantiation
template class FemGuiExport ViewProviderFeaturePythonT<FemGui::ViewProviderFemPostFilterPythonBase>;
}
} // namespace Gui
// ***************************************************************************
// in the following, the different filters sorted alphabetically
@@ -154,7 +158,8 @@ void ViewProviderFemPostClip::setupTaskDialog(TaskDlgPost* dlg)
// add the function box
assert(dlg->getView() == this);
auto panel = new TaskPostClip(this, &dlg->getView()->getObject<Fem::FemPostClipFilter>()->Function);
auto panel =
new TaskPostClip(this, &dlg->getView()->getObject<Fem::FemPostClipFilter>()->Function);
dlg->addTaskBox(panel->getIcon(), panel);
// add the display options
@@ -197,7 +202,8 @@ void ViewProviderFemPostCut::setupTaskDialog(TaskDlgPost* dlg)
{
// add the function box
assert(dlg->getView() == this);
auto panel = new TaskPostCut(this, &dlg->getView()->getObject<Fem::FemPostCutFilter>()->Function);
auto panel =
new TaskPostCut(this, &dlg->getView()->getObject<Fem::FemPostCutFilter>()->Function);
dlg->addTaskBox(panel->getIcon(), panel);
// add the display options

View File

@@ -50,7 +50,8 @@ public:
// Viewprovider for the python filters
using ViewProviderPostFilterPython = Gui::ViewProviderFeaturePythonT<ViewProviderFemPostFilterPythonBase>;
using ViewProviderPostFilterPython =
Gui::ViewProviderFeaturePythonT<ViewProviderFemPostFilterPythonBase>;
// ***************************************************************************

View File

@@ -932,7 +932,7 @@ void ViewProviderFemPostObject::onChanged(const App::Property* prop)
}
if (prop == &Field && setupPipeline()) {
if(!isRestoring()) {
if (!isRestoring()) {
updateProperties();
}
WriteColorData(ResetColorBarRange);

View File

@@ -82,6 +82,7 @@ class FemWorkbench(Workbench):
# check vtk version to potentially find missmatchs
from femguiutils.vtk_module_handling import vtk_module_handling
vtk_module_handling()
def GetClassName(self):

View File

@@ -652,6 +652,7 @@ def makePostVtkFilterContours(doc, base_vtk_result, name="VtkFilterContours"):
base_vtk_result.addObject(obj)
return obj
def makePostFilterGlyph(doc, base_vtk_result, name="Glyph"):
"""makePostVtkFilterGlyph(document, [name]):
creates a FEM post processing filter that visualizes vector fields with glyphs
@@ -663,9 +664,11 @@ def makePostFilterGlyph(doc, base_vtk_result, name="Glyph"):
base_vtk_result.addObject(obj)
if FreeCAD.GuiUp:
from femviewprovider import view_post_glyphfilter
view_post_glyphfilter.VPPostGlyphFilter(obj.ViewObject)
return obj
def makePostVtkResult(doc, result_data, name="VtkResult"):
"""makePostVtkResult(document, base_result, [name]):
creates a FEM post processing result data (vtk based) to hold FEM results
@@ -682,6 +685,7 @@ def makePostVtkResult(doc, result_data, name="VtkResult"):
obj.ViewObject.DisplayMode = "Surface"
return obj
# ********* solver objects ***********************************************************************
def makeEquationDeformation(doc, base_solver=None, name="Deformation"):
"""makeEquationDeformation(document, [base_solver], [name]):

View File

@@ -1216,6 +1216,7 @@ class _SolverZ88(CommandManager):
self.is_active = "with_analysis"
self.do_activated = "add_obj_on_gui_expand_noset_edit"
class _PostFilterGlyph(CommandManager):
"The FEM_PostFilterGlyph command definition"
@@ -1223,7 +1224,10 @@ class _PostFilterGlyph(CommandManager):
super().__init__()
self.menutext = Qt.QT_TRANSLATE_NOOP("FEM_PostFilterGlyph", "Glyph filter")
self.accel = "F, G"
self.tooltip = Qt.QT_TRANSLATE_NOOP("FEM_PostFilterGlyph", "Post processing filter that adds glyphs to the mesh vertices for vertex data visualization")
self.tooltip = Qt.QT_TRANSLATE_NOOP(
"FEM_PostFilterGlyph",
"Post processing filter that adds glyphs to the mesh vertices for vertex data visualization",
)
self.is_active = "with_vtk_selresult"
self.do_activated = "add_filter_set_edit"

View File

@@ -91,9 +91,7 @@ class CommandManager:
and self.result_selected()
)
elif self.is_active == "with_vtk_selresult":
active = (
self.vtk_result_selected()
)
active = self.vtk_result_selected()
elif self.is_active == "with_part_feature":
active = FreeCADGui.ActiveDocument is not None and self.part_feature_selected()
elif self.is_active == "with_femmesh":
@@ -401,8 +399,12 @@ class CommandManager:
"FreeCAD.ActiveDocument, FreeCAD.ActiveDocument.{})".format(filtertype, group.Name)
)
# set display and selection style to assure the user sees the new object
FreeCADGui.doCommand("FreeCAD.ActiveDocument.ActiveObject.ViewObject.DisplayMode = \"Surface\"");
FreeCADGui.doCommand("FreeCAD.ActiveDocument.ActiveObject.ViewObject.SelectionStyle = \"BoundBox\"");
FreeCADGui.doCommand(
'FreeCAD.ActiveDocument.ActiveObject.ViewObject.DisplayMode = "Surface"'
)
FreeCADGui.doCommand(
'FreeCAD.ActiveDocument.ActiveObject.ViewObject.SelectionStyle = "BoundBox"'
)
# hide selected filter
FreeCADGui.doCommand(
@@ -411,9 +413,7 @@ class CommandManager:
# recompute, expand selobj in tree view
expandParentObject()
FreeCADGui.doCommand(
"FreeCAD.ActiveDocument.ActiveObject.recompute()"
)
FreeCADGui.doCommand("FreeCAD.ActiveDocument.ActiveObject.recompute()")
# set edit
FreeCADGui.Selection.clearSelection()

View File

@@ -49,6 +49,7 @@ __url__ = "https://www.freecad.org"
__user_input_received = False
def vtk_module_compatible():
# checks if the VTK library FreeCAD is build against is the one used by
# the python module
@@ -76,6 +77,7 @@ def vtk_module_compatible():
def _vtk_is_loaded():
import sys
return any("vtkmodules" in module for module in sys.modules)
@@ -84,6 +86,7 @@ def _unload_vtk_modules():
# NOTE: does not remove any stored references in objects
import sys
for module in sys.modules.copy():
if "vtkmodules" in module:
del sys.modules[module]
@@ -157,7 +160,9 @@ def vtk_module_handling():
if not vtk_module_compatible():
if not FreeCAD.GuiUp:
FreeCAD.Console.PrintError("FEM: vtk python module is not compatible with internal vtk library")
FreeCAD.Console.PrintError(
"FEM: vtk python module is not compatible with internal vtk library"
)
return
import FreeCAD, Fem
@@ -168,11 +173,16 @@ def vtk_module_handling():
translate = FreeCAD.Qt.translate
path = inspect.getfile(vtkVersion)
path = path[:path.find("vtkmodules")]
path = path[: path.find("vtkmodules")]
message = translate("FEM", ("FreeCAD is linked to a different VTK library then the imported "
"VTK python module. This is incompatible and will lead to errors."
"\n\nWrong python module is imported from: \n{}")).format(path)
message = translate(
"FEM",
(
"FreeCAD is linked to a different VTK library then the imported "
"VTK python module. This is incompatible and will lead to errors."
"\n\nWrong python module is imported from: \n{}"
),
).format(path)
buttons = QtGui.QMessageBox.Discard
@@ -181,7 +191,9 @@ def vtk_module_handling():
if compatible_module:
# there is a compatible module of VTK available.
message += translate("FEM", "\n\nCorrect module found in: \n{}").format(compatible_module)
message += translate("FEM", "\n\nCorrect module found in: \n{}").format(
compatible_module
)
if not loaded:
# vtk was not loaded beforehand, therefore we can realistically reload
@@ -190,15 +202,22 @@ def vtk_module_handling():
buttons = QtGui.QMessageBox.Yes | QtGui.QMessageBox.No
else:
message += translate("FEM", ("\n\nAs the wrong module was already loaded, a reload is not possible. "
"Restart FreeCAD to get the option for loading this module."))
message += translate(
"FEM",
(
"\n\nAs the wrong module was already loaded, a reload is not possible. "
"Restart FreeCAD to get the option for loading this module."
),
)
else:
message += translate("FEM", "\n\nNo matching module was found in the current python path.")
message += translate(
"FEM", "\n\nNo matching module was found in the current python path."
)
# raise a dialog to the user
import FreeCADGui
button = QtGui.QMessageBox.critical(
FreeCADGui.getMainWindow(),
translate("FEM", "VTK module conflict"),
@@ -222,12 +241,15 @@ def vtk_compatibility_abort(inform=True):
import FreeCAD
import FreeCADGui
from PySide import QtGui
translate = FreeCAD.Qt.translate
button = QtGui.QMessageBox.critical(
FreeCADGui.getMainWindow(),
translate("FEM", "VTK module conflict"),
translate("FEM", "This functionality is not available due to VTK python module conflict"),
translate(
"FEM", "This functionality is not available due to VTK python module conflict"
),
buttons=QtGui.QMessageBox.Discard,
)

View File

@@ -33,6 +33,7 @@ import FreeCAD
# check vtk version to potentially find missmatchs
from femguiutils.vtk_module_handling import vtk_module_handling
vtk_module_handling()
# IMPORTANT: Never import vtk directly. Often vtk is compiled with different QT
@@ -43,8 +44,10 @@ from vtkmodules.vtkFiltersCore import vtkGlyph3D
import vtkmodules.vtkFiltersSources as vtkSources
from . import base_fempythonobject
_PropHelper = base_fempythonobject._PropHelper
class PostGlyphFilter(base_fempythonobject.BaseFemPythonObject):
"""
A post processing filter adding glyphs
@@ -96,7 +99,7 @@ class PostGlyphFilter(base_fempythonobject.BaseFemPythonObject):
name="ScaleFactor",
group="Scale",
doc="A constant multiplier the glyphs are scaled with",
value= (1, 0, 1e12, 1e-12),
value=(1, 0, 1e12, 1e-12),
),
_PropHelper(
type="App::PropertyEnumeration",
@@ -109,15 +112,15 @@ class PostGlyphFilter(base_fempythonobject.BaseFemPythonObject):
type="App::PropertyIntegerConstraint",
name="Stride",
group="Masking",
doc="Define the stride for \"Every Nth\" masking mode",
value= (2, 1, 999999999, 1),
doc='Define the stride for "Every Nth" masking mode',
value=(2, 1, 999999999, 1),
),
_PropHelper(
type="App::PropertyIntegerConstraint",
name="MaxNumber",
group="Masking",
doc="Defines the maximal number of vertices used for \"Uniform Sampling\" masking mode",
value= (1000, 1, 999999999, 1),
doc='Defines the maximal number of vertices used for "Uniform Sampling" masking mode',
value=(1000, 1, 999999999, 1),
),
]
return prop
@@ -155,14 +158,14 @@ class PostGlyphFilter(base_fempythonobject.BaseFemPythonObject):
else:
glyph.SetScaleModeToScaleByVectorComponents()
glyph.SetInputArrayToProcess(2,0,0,0,obj.ScaleData)
glyph.SetInputArrayToProcess(2, 0, 0, 0, obj.ScaleData)
else:
# scalar scaling mode
if obj.VectorScaleMode != "Not a vector":
obj.VectorScaleMode = ["Not a vector"]
glyph.SetInputArrayToProcess(2,0,0,0,obj.ScaleData)
glyph.SetInputArrayToProcess(2, 0, 0, 0, obj.ScaleData)
glyph.SetScaleModeToScaleByScalar()
else:
glyph.ScalingOff()
@@ -172,11 +175,10 @@ class PostGlyphFilter(base_fempythonobject.BaseFemPythonObject):
# Orientation
if obj.OrientationData != "None":
glyph.OrientOn()
glyph.SetInputArrayToProcess(1,0,0,0,obj.OrientationData)
glyph.SetInputArrayToProcess(1, 0, 0, 0, obj.OrientationData)
else:
glyph.OrientOff()
def __setupFilterPipeline(self, obj):
# store of all algorithms for later access
@@ -184,8 +186,7 @@ class PostGlyphFilter(base_fempythonobject.BaseFemPythonObject):
self._algorithms = {}
# create all vtkalgorithm combinations and set them as filter pipeline
sources = {"Arrow": vtkSources.vtkArrowSource,
"Cube": vtkSources.vtkCubeSource}
sources = {"Arrow": vtkSources.vtkArrowSource, "Cube": vtkSources.vtkCubeSource}
for source_name in sources:
@@ -204,7 +205,6 @@ class PostGlyphFilter(base_fempythonobject.BaseFemPythonObject):
obj.setActiveFilterPipeline(obj.Glyph)
def onDocumentRestored(self, obj):
# resetup the pipeline
self.__setupFilterPipeline(obj)
@@ -213,7 +213,7 @@ class PostGlyphFilter(base_fempythonobject.BaseFemPythonObject):
# we check what new inputs
vector_fields = obj.getInputVectorFields()
all_fields = (vector_fields + obj.getInputScalarFields())
all_fields = vector_fields + obj.getInputScalarFields()
vector_fields.sort()
all_fields.sort()
@@ -233,7 +233,6 @@ class PostGlyphFilter(base_fempythonobject.BaseFemPythonObject):
# make sure parent class execute is called!
return False
def onChanged(self, obj, prop):
# check if we are setup already
@@ -270,4 +269,3 @@ class PostGlyphFilter(base_fempythonobject.BaseFemPythonObject):
for filter in self._algorithms:
glyph = self._algorithms[filter][2]
glyph.SetScaleFactor(obj.ScaleFactor)

View File

@@ -63,7 +63,9 @@ class _TaskPanel(base_femtaskpanel._BaseTaskPanel):
# ##########################
def getStandardButtons(self):
return QtGui.QDialogButtonBox.Apply | QtGui.QDialogButtonBox.Ok | QtGui.QDialogButtonBox.Cancel
return (
QtGui.QDialogButtonBox.Apply | QtGui.QDialogButtonBox.Ok | QtGui.QDialogButtonBox.Cancel
)
def clicked(self, button):
# apply button hit?
@@ -71,16 +73,15 @@ class _TaskPanel(base_femtaskpanel._BaseTaskPanel):
self.obj.Document.recompute()
def accept(self):
#self.obj.CharacteristicLength = self.elelen
#self.obj.References = self.selection_widget.references
#self.selection_widget.finish_selection()
# self.obj.CharacteristicLength = self.elelen
# self.obj.References = self.selection_widget.references
# self.selection_widget.finish_selection()
return super().accept()
def reject(self):
#self.selection_widget.finish_selection()
# self.selection_widget.finish_selection()
return super().reject()
# Helper functions
# ##################
@@ -99,7 +100,6 @@ class _TaskPanel(base_femtaskpanel._BaseTaskPanel):
cbox.setCurrentText(getattr(obj, prop))
cbox.blockSignals(False)
# Setup functions
# ###############
@@ -113,8 +113,8 @@ class _TaskPanel(base_femtaskpanel._BaseTaskPanel):
self._enumPropertyToCombobox(self.obj, "MaskMode", self.widget.MaskModeComboBox)
self.widget.ScaleFactorBox.setValue(self.obj.ScaleFactor)
self.__slide_min = self.obj.ScaleFactor*0.5
self.__slide_max = self.obj.ScaleFactor*1.5
self.__slide_min = self.obj.ScaleFactor * 0.5
self.__slide_max = self.obj.ScaleFactor * 1.5
self.widget.ScaleSlider.setValue(50)
self.widget.StrideBox.setValue(self.obj.Stride)
self.widget.MaxBox.setValue(self.obj.MaxNumber)
@@ -132,7 +132,6 @@ class _TaskPanel(base_femtaskpanel._BaseTaskPanel):
self.widget.StrideBox.valueChanged.connect(self._stride_changed)
self.widget.MaxBox.valueChanged.connect(self._max_number_changed)
def __update_scaling_ui(self):
enabled = self.widget.ScaleComboBox.currentIndex() != 0
self.widget.VectorModeComboBox.setEnabled(enabled)
@@ -144,7 +143,6 @@ class _TaskPanel(base_femtaskpanel._BaseTaskPanel):
self.widget.StrideBox.setEnabled(enabled)
self.widget.MaxBox.setEnabled(enabled)
# callbacks and logic
# ###################
@@ -169,9 +167,9 @@ class _TaskPanel(base_femtaskpanel._BaseTaskPanel):
def _scale_factor_changed(self, value):
# set slider
self.__slide_min = value*0.5
self.__slide_max = value*1.5
slider_value = (value - self.__slide_min) / (self.__slide_max - self.__slide_min) * 100.
self.__slide_min = value * 0.5
self.__slide_max = value * 1.5
slider_value = (value - self.__slide_min) / (self.__slide_max - self.__slide_min) * 100.0
self.widget.ScaleSlider.blockSignals(True)
self.widget.ScaleSlider.setValue(slider_value)
self.widget.ScaleSlider.blockSignals(False)
@@ -186,7 +184,7 @@ class _TaskPanel(base_femtaskpanel._BaseTaskPanel):
# factor = min + ( slider_value x ------------- )
# 100
#
f = self.__slide_min + (value * (self.__slide_max - self.__slide_min)/100)
f = self.__slide_min + (value * (self.__slide_max - self.__slide_min) / 100)
# sync factor spin box
self.widget.ScaleFactorBox.blockSignals(True)
@@ -197,7 +195,6 @@ class _TaskPanel(base_femtaskpanel._BaseTaskPanel):
self.obj.ScaleFactor = f
self._recompute()
def _mask_mode_changed(self, value):
self.obj.MaskMode = value
self.__update_masking_ui()
@@ -210,4 +207,3 @@ class _TaskPanel(base_femtaskpanel._BaseTaskPanel):
def _max_number_changed(self, value):
self.obj.MaxNumber = value
self._recompute()

View File

@@ -70,7 +70,7 @@ class VPPostGlyphFilter:
# build up the task panel
taskd = task_post_glyphfilter._TaskPanel(vobj)
#show it
# show it
FreeCADGui.Control.showDialog(taskd)
return True