Merge pull request #12412 from FlachyJoe/suppressibleExt
Core: Create a SuppressibleExtension to provide the Suppressed property to all the WBs
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -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
|
||||
|
||||
61
src/App/SuppressibleExtension.cpp
Normal file
61
src/App/SuppressibleExtension.cpp
Normal file
@@ -0,0 +1,61 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2024 Florian Foinant-Willig <ffw@2f2v.fr> *
|
||||
* *
|
||||
* 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 <Base/Tools.h>
|
||||
|
||||
#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<SuppressibleExtensionPythonT<SuppressibleExtension>>;
|
||||
|
||||
|
||||
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
|
||||
63
src/App/SuppressibleExtension.h
Normal file
63
src/App/SuppressibleExtension.h
Normal file
@@ -0,0 +1,63 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2024 Florian Foinant-Willig <ffw@2f2v.fr> *
|
||||
* *
|
||||
* 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 <App/DocumentObject.h>
|
||||
#include <App/DocumentObjectExtension.h>
|
||||
#include <App/ExtensionPython.h>
|
||||
|
||||
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<typename ExtensionT>
|
||||
class SuppressibleExtensionPythonT : public ExtensionT {
|
||||
|
||||
public:
|
||||
|
||||
SuppressibleExtensionPythonT() = default;
|
||||
~SuppressibleExtensionPythonT() override = default;
|
||||
};
|
||||
|
||||
using SuppressibleExtensionPython = ExtensionPythonT<SuppressibleExtensionPythonT<SuppressibleExtension>>;
|
||||
|
||||
} //namespace App
|
||||
|
||||
#endif // SUPPRESSIBLEEXTENSION_H
|
||||
18
src/App/SuppressibleExtensionPy.xml
Normal file
18
src/App/SuppressibleExtensionPy.xml
Normal file
@@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<GenerateModel xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="generateMetaModel_Module.xsd">
|
||||
<PythonExport
|
||||
Father="DocumentObjectExtensionPy"
|
||||
Name="SuppressibleExtensionPy"
|
||||
Twin="SuppressibleExtension"
|
||||
TwinPointer="SuppressibleExtension"
|
||||
Include="App/SuppressibleExtension.h"
|
||||
Namespace="App"
|
||||
FatherInclude="App/DocumentObjectExtensionPy.h"
|
||||
FatherNamespace="App">
|
||||
<Documentation>
|
||||
<Author Licence="LGPL" Name="Florian Foinant-Willig" EMail="flachyjoe@users.sourceforge.net" />
|
||||
<UserDocu>Extension class which allows suppressing of document objects</UserDocu>
|
||||
</Documentation>
|
||||
<CustomAttributes />
|
||||
</PythonExport>
|
||||
</GenerateModel>
|
||||
49
src/App/SuppressibleExtensionPyImp.cpp
Normal file
49
src/App/SuppressibleExtensionPyImp.cpp
Normal file
@@ -0,0 +1,49 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2024 Florian Foinant-Willig <ffw@2f2v.fr> *
|
||||
* *
|
||||
* 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 {"<suppressible extension object>"};
|
||||
}
|
||||
|
||||
PyObject *SuppressibleExtensionPy::getCustomAttributes(const char* /*attr*/) const
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
int SuppressibleExtensionPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
@@ -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();
|
||||
|
||||
@@ -895,6 +895,7 @@ SET(Viewprovider_CPP_SRCS
|
||||
ViewProviderGroupExtension.cpp
|
||||
ViewProviderGeoFeatureGroupExtension.cpp
|
||||
ViewProviderOriginGroupExtension.cpp
|
||||
ViewProviderSuppressibleExtension.cpp
|
||||
ViewProviderAnnotation.cpp
|
||||
ViewProviderDocumentObject.cpp
|
||||
ViewProviderDocumentObjectGroup.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;
|
||||
|
||||
@@ -31,6 +31,7 @@ namespace Gui {
|
||||
Underlined,
|
||||
Italic,
|
||||
Overlined,
|
||||
StrikeOut,
|
||||
Bold,
|
||||
Blue,
|
||||
LightBlue,
|
||||
|
||||
129
src/Gui/ViewProviderSuppressibleExtension.cpp
Normal file
129
src/Gui/ViewProviderSuppressibleExtension.cpp
Normal file
@@ -0,0 +1,129 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2024 Florian Foinant-Willig <ffw@2f2v.fr> *
|
||||
* *
|
||||
* 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 <App/SuppressibleExtension.h>
|
||||
|
||||
#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<App::SuppressibleExtension>();
|
||||
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<App::SuppressibleExtension>();
|
||||
//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<ViewProviderSuppressibleExtension>;
|
||||
|
||||
} //namespace Gui
|
||||
54
src/Gui/ViewProviderSuppressibleExtension.h
Normal file
54
src/Gui/ViewProviderSuppressibleExtension.h
Normal file
@@ -0,0 +1,54 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2024 Florian Foinant-Willig <ffw@2f2v.fr> *
|
||||
* *
|
||||
* 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<Gui::ViewProviderSuppressibleExtension>;
|
||||
|
||||
} //namespace Gui
|
||||
|
||||
#endif // VIEWPROVIDERSUPPRESSIBLEEXTENSION_H
|
||||
Reference in New Issue
Block a user