diff --git a/src/App/Application.cpp b/src/App/Application.cpp index 87b5c14e2f..9efd29e297 100644 --- a/src/App/Application.cpp +++ b/src/App/Application.cpp @@ -106,6 +106,8 @@ #include "OriginFeature.h" #include "OriginGroupExtension.h" #include "OriginGroupExtensionPy.h" +#include "SuppressibleExtension.h" +#include "SuppressibleExtensionPy.h" #include "Part.h" #include "PartPy.h" #include "Placement.h" @@ -2059,6 +2061,8 @@ void Application::initTypes() App::LinkBaseExtensionPython ::init(); App::LinkExtension ::init(); App::LinkExtensionPython ::init(); + App::SuppressibleExtension ::init(); + App::SuppressibleExtensionPython ::init(); // Document classes App::TransactionalObject ::init(); diff --git a/src/App/CMakeLists.txt b/src/App/CMakeLists.txt index ff9ac1dee3..100addc08b 100644 --- a/src/App/CMakeLists.txt +++ b/src/App/CMakeLists.txt @@ -87,6 +87,7 @@ generate_from_xml(LinkBaseExtensionPy) generate_from_xml(DocumentObjectGroupPy) generate_from_xml(GeoFeaturePy) generate_from_xml(GeoFeatureGroupExtensionPy) +generate_from_xml(SuppressibleExtensionPy) generate_from_xml(MetadataPy) generate_from_xml(OriginGroupExtensionPy) generate_from_xml(PartPy) @@ -112,6 +113,7 @@ SET(FreeCADApp_XML_SRCS GeoFeaturePy.xml GeoFeatureGroupExtensionPy.xml OriginGroupExtensionPy.xml + SuppressibleExtensionPy.xml PartPy.xml DocumentPy.xml PropertyContainerPy.xml @@ -154,6 +156,8 @@ SET(Document_CPP_SRCS ImagePlane.cpp OriginGroupExtensionPyImp.cpp OriginGroupExtension.cpp + SuppressibleExtensionPyImp.cpp + SuppressibleExtension.cpp PartPyImp.cpp Part.cpp Origin.cpp @@ -200,6 +204,7 @@ SET(Document_HPP_SRCS GeoFeatureGroupExtension.h ImagePlane.h OriginGroupExtension.h + SuppressibleExtension.h Part.h Origin.h Path.h diff --git a/src/App/SuppressibleExtension.cpp b/src/App/SuppressibleExtension.cpp new file mode 100644 index 0000000000..9c2348f8be --- /dev/null +++ b/src/App/SuppressibleExtension.cpp @@ -0,0 +1,61 @@ +/*************************************************************************** + * Copyright (c) 2024 Florian Foinant-Willig * + * * + * 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 + +#include "Extension.h" +#include "SuppressibleExtension.h" +#include "SuppressibleExtensionPy.h" + + +namespace App { + +EXTENSION_PROPERTY_SOURCE(App::SuppressibleExtension, App::DocumentObjectExtension) + + +EXTENSION_PROPERTY_SOURCE_TEMPLATE(App::SuppressibleExtensionPython, App::SuppressibleExtension) + +// explicit template instantiation +template class AppExport ExtensionPythonT>; + + +SuppressibleExtension::SuppressibleExtension() +{ + initExtensionType(SuppressibleExtension::getExtensionClassTypeId()); + EXTENSION_ADD_PROPERTY_TYPE(Suppressed, (false), "Base", PropertyType(Prop_None), "Is object suppressed"); +} + +SuppressibleExtension::~SuppressibleExtension() = default; + +PyObject* SuppressibleExtension::getExtensionPyObject() { + + if (ExtensionPythonObject.is(Py::_None())){ + // ref counter is set to 1 + auto ext = new SuppressibleExtensionPy(this); + ExtensionPythonObject = Py::Object(ext,true); + } + return Py::new_reference_to(ExtensionPythonObject); +} + +} //namespace App diff --git a/src/App/SuppressibleExtension.h b/src/App/SuppressibleExtension.h new file mode 100644 index 0000000000..603a4c03d8 --- /dev/null +++ b/src/App/SuppressibleExtension.h @@ -0,0 +1,63 @@ +/*************************************************************************** + * Copyright (c) 2024 Florian Foinant-Willig * + * * + * 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 SUPPRESSIBLEEXTENSION_H +#define SUPPRESSIBLEEXTENSION_H + +#include +#include +#include + +namespace App +{ +class SuppressibleExtensionPy; + +class AppExport SuppressibleExtension : public DocumentObjectExtension +{ + EXTENSION_PROPERTY_HEADER_WITH_OVERRIDE(App::SuppressibleExtension); + using inherited = DocumentObjectExtension; + +public: + /// Constructor + SuppressibleExtension(); + ~SuppressibleExtension() override; + + PyObject* getExtensionPyObject() override; + + ///Properties + PropertyBool Suppressed; +}; + +template +class SuppressibleExtensionPythonT : public ExtensionT { + +public: + + SuppressibleExtensionPythonT() = default; + ~SuppressibleExtensionPythonT() override = default; +}; + +using SuppressibleExtensionPython = ExtensionPythonT>; + +} //namespace App + +#endif // SUPPRESSIBLEEXTENSION_H diff --git a/src/App/SuppressibleExtensionPy.xml b/src/App/SuppressibleExtensionPy.xml new file mode 100644 index 0000000000..77f54b39a5 --- /dev/null +++ b/src/App/SuppressibleExtensionPy.xml @@ -0,0 +1,18 @@ + + + + + + Extension class which allows suppressing of document objects + + + + diff --git a/src/App/SuppressibleExtensionPyImp.cpp b/src/App/SuppressibleExtensionPyImp.cpp new file mode 100644 index 0000000000..3a2c99a117 --- /dev/null +++ b/src/App/SuppressibleExtensionPyImp.cpp @@ -0,0 +1,49 @@ +/*************************************************************************** + * Copyright (c) 2024 Florian Foinant-Willig * + * * + * 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 "DocumentObject.h" + +// inclusion of the generated files (generated out of SuppressibleExtensionPy.xml) +#include "SuppressibleExtensionPy.h" +#include "SuppressibleExtensionPy.cpp" +#include "DocumentObjectPy.h" + + +using namespace App; + +// returns a string which represent the object e.g. when printed in python +std::string SuppressibleExtensionPy::representation() const +{ + return {""}; +} + +PyObject *SuppressibleExtensionPy::getCustomAttributes(const char* /*attr*/) const +{ + return nullptr; +} + +int SuppressibleExtensionPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/) +{ + return 0; +} diff --git a/src/Gui/Application.cpp b/src/Gui/Application.cpp index f5118aae54..3f8810b652 100644 --- a/src/Gui/Application.cpp +++ b/src/Gui/Application.cpp @@ -107,6 +107,7 @@ #include "ViewProviderGeoFeatureGroup.h" #include "ViewProviderGeometryObject.h" #include "ViewProviderGroupExtension.h" +#include "ViewProviderSuppressibleExtension.h" #include "ViewProviderImagePlane.h" #include "ViewProviderInventorObject.h" #include "ViewProviderLine.h" @@ -2245,6 +2246,8 @@ void Application::initTypes() Gui::ViewProviderGeoFeatureGroupExtensionPython::init(); Gui::ViewProviderOriginGroupExtension ::init(); Gui::ViewProviderOriginGroupExtensionPython ::init(); + Gui::ViewProviderSuppressibleExtension ::init(); + Gui::ViewProviderSuppressibleExtensionPython::init(); Gui::ViewProviderExtern ::init(); Gui::ViewProviderDocumentObject ::init(); Gui::ViewProviderFeature ::init(); diff --git a/src/Gui/CMakeLists.txt b/src/Gui/CMakeLists.txt index cd4d3c21cf..f22cb8ffd0 100644 --- a/src/Gui/CMakeLists.txt +++ b/src/Gui/CMakeLists.txt @@ -895,6 +895,7 @@ SET(Viewprovider_CPP_SRCS ViewProviderGroupExtension.cpp ViewProviderGeoFeatureGroupExtension.cpp ViewProviderOriginGroupExtension.cpp + ViewProviderSuppressibleExtension.cpp ViewProviderAnnotation.cpp ViewProviderDocumentObject.cpp ViewProviderDocumentObjectGroup.cpp diff --git a/src/Gui/Tree.cpp b/src/Gui/Tree.cpp index 98c1ada432..640595f042 100644 --- a/src/Gui/Tree.cpp +++ b/src/Gui/Tree.cpp @@ -5072,6 +5072,9 @@ void DocumentObjectItem::setHighlight(bool set, Gui::HighlightMode high) { case HighlightMode::Overlined: f.setOverline(set); break; + case HighlightMode::StrikeOut: + f.setStrikeOut(set); + break; case HighlightMode::Blue: highlight(QColor(200, 200, 255)); break; diff --git a/src/Gui/TreeItemMode.h b/src/Gui/TreeItemMode.h index 84f13f921e..9b88f2251b 100644 --- a/src/Gui/TreeItemMode.h +++ b/src/Gui/TreeItemMode.h @@ -31,6 +31,7 @@ namespace Gui { Underlined, Italic, Overlined, + StrikeOut, Bold, Blue, LightBlue, diff --git a/src/Gui/ViewProviderSuppressibleExtension.cpp b/src/Gui/ViewProviderSuppressibleExtension.cpp new file mode 100644 index 0000000000..21845de562 --- /dev/null +++ b/src/Gui/ViewProviderSuppressibleExtension.cpp @@ -0,0 +1,129 @@ +/*************************************************************************** + * Copyright (c) 2024 Florian Foinant-Willig * + * * + * 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 "ActionFunction.h" +#include "Control.h" +#include "Document.h" +#include "PreCompiled.h" + +#include + +#include "Application.h" +#include "TreeItemMode.h" + +#include "ViewProviderSuppressibleExtension.h" +#include "BitmapFactory.h" +#include "ViewProviderDocumentObject.h" +#include "qmenu.h" + + +namespace Gui { + +EXTENSION_PROPERTY_SOURCE(Gui::ViewProviderSuppressibleExtension, Gui::ViewProviderExtension) + +ViewProviderSuppressibleExtension::ViewProviderSuppressibleExtension() +{ + initExtensionType(ViewProviderSuppressibleExtension::getExtensionClassTypeId()); +} + +ViewProviderSuppressibleExtension::~ViewProviderSuppressibleExtension() = default; + +void ViewProviderSuppressibleExtension::extensionUpdateData(const App::Property* prop) +{ + auto vp = getExtendedViewProvider(); + auto obj = vp->getObject()->getExtensionByType(); + if (obj && prop == &obj->Suppressed) { + //update the tree item + bool suppressed = obj->Suppressed.getValue(); + this->setSuppressedIcon(suppressed); + auto activeDoc = Gui::Application::Instance->activeDocument(); + activeDoc->signalHighlightObject(*vp, Gui::HighlightMode::StrikeOut, suppressed, 0, 0); + } +} + +void ViewProviderSuppressibleExtension::setSuppressedIcon(bool onoff) { + isSetSuppressedIcon = onoff; + + getExtendedViewProvider()->signalChangeIcon(); // signal icon change +} + +QIcon ViewProviderSuppressibleExtension::extensionMergeColorfullOverlayIcons (const QIcon & orig) const +{ + QIcon mergedicon = orig; + + if(isSetSuppressedIcon) { + QPixmap px; + static const char * feature_suppressed_xpm[] = { + "16 16 2 1", + " c None", + ". c #FF0000", + ". ", + " .. ", + " ... ", + " ... ", + " ... ", + " ... ", + " ... ", + " ... ", + " ... ", + " ... ", + " ... ", + " ... ", + " ... ", + " ... ", + " .. ", + " ."}; + + px = QPixmap(feature_suppressed_xpm); + + mergedicon = Gui::BitmapFactoryInst::mergePixmap(mergedicon, px, Gui::BitmapFactoryInst::TopLeft); + } + return Gui::ViewProviderExtension::extensionMergeColorfullOverlayIcons(mergedicon); +} + + +void ViewProviderSuppressibleExtension::extensionSetupContextMenu(QMenu* menu, QObject*, const char*) +{ + auto vp = getExtendedViewProvider(); + auto obj = vp->getObject()->getExtensionByType(); + //show (Un)Suppress action if the Suppressed property is visible + if (obj && ! obj->Suppressed.testStatus(App::Property::Hidden)) { + Gui::ActionFunction* func = new Gui::ActionFunction(menu); + QAction* act; + if (obj->Suppressed.getValue()) + act = menu->addAction(QObject::tr("UnSuppress")); + else + act = menu->addAction(QObject::tr("Suppress")); + + func->trigger(act, [obj](){ + obj->Suppressed.setValue(! obj->Suppressed.getValue()); + }); + } +} + + +EXTENSION_PROPERTY_SOURCE_TEMPLATE(Gui::ViewProviderSuppressibleExtensionPython, Gui::ViewProviderSuppressibleExtension) + +// explicit template instantiation +template class GuiExport ViewProviderExtensionPythonT; + +} //namespace Gui diff --git a/src/Gui/ViewProviderSuppressibleExtension.h b/src/Gui/ViewProviderSuppressibleExtension.h new file mode 100644 index 0000000000..011f475289 --- /dev/null +++ b/src/Gui/ViewProviderSuppressibleExtension.h @@ -0,0 +1,54 @@ +/*************************************************************************** + * Copyright (c) 2024 Florian Foinant-Willig * + * * + * 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 VIEWPROVIDERSUPPRESSIBLEEXTENSION_H +#define VIEWPROVIDERSUPPRESSIBLEEXTENSION_H + +#include "ViewProviderExtensionPython.h" + + +namespace Gui +{ + +class ViewProviderSuppressibleExtension : public Gui::ViewProviderExtension +{ + EXTENSION_PROPERTY_HEADER_WITH_OVERRIDE(Gui::ViewProviderSuppressibleExtension); + +public: + ViewProviderSuppressibleExtension(); + ~ViewProviderSuppressibleExtension() override; + + void extensionUpdateData(const App::Property* prop) override; + + void setSuppressedIcon(bool onoff); + QIcon extensionMergeColorfullOverlayIcons (const QIcon & orig) const override; + void extensionSetupContextMenu(QMenu* menu, QObject*, const char*) override; + +private: + bool isSetSuppressedIcon{false}; +}; + +using ViewProviderSuppressibleExtensionPython = ViewProviderExtensionPythonT; + +} //namespace Gui + +#endif // VIEWPROVIDERSUPPRESSIBLEEXTENSION_H