Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Core: Create a SuppressibleExtension to provide the Suppressed property to all the WBs #12412

Merged
merged 2 commits into from Feb 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/App/Application.cpp
Expand Up @@ -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"
Expand All @@ -125,7 +127,7 @@
// If you stumble here, run the target "BuildExtractRevision" on Windows systems
// or the Python script "SubWCRev.py" on Linux based systems which builds
// src/Build/Version.h. Or create your own from src/Build/Version.h.in!
#include <Build/Version.h>

Check failure on line 130 in src/App/Application.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

'Build/Version.h' file not found [clang-diagnostic-error]
#include "Branding.h"


Expand All @@ -146,7 +148,7 @@
# include <new>
#endif

FC_LOG_LEVEL_INIT("App", true, true)

Check warning on line 151 in src/App/Application.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

variable '_s_fclvl' is non-const and globally accessible, consider making it const [cppcoreguidelines-avoid-non-const-global-variables]

using namespace App;
using namespace Base;
Expand All @@ -160,12 +162,12 @@
// Application
//==========================================================================

Base::Reference<ParameterManager> App::Application::_pcSysParamMngr;

Check warning on line 165 in src/App/Application.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

variable '_pcSysParamMngr' is non-const and globally accessible, consider making it const [cppcoreguidelines-avoid-non-const-global-variables]
Base::Reference<ParameterManager> App::Application::_pcUserParamMngr;

Check warning on line 166 in src/App/Application.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

variable '_pcUserParamMngr' is non-const and globally accessible, consider making it const [cppcoreguidelines-avoid-non-const-global-variables]
Base::ConsoleObserverStd *Application::_pConsoleObserverStd = nullptr;

Check warning on line 167 in src/App/Application.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

variable '_pConsoleObserverStd' is non-const and globally accessible, consider making it const [cppcoreguidelines-avoid-non-const-global-variables]

Check warning on line 167 in src/App/Application.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

variable '_pConsoleObserverStd' provides global access to a non-const object; consider making the pointed-to data 'const' [cppcoreguidelines-avoid-non-const-global-variables]
Base::ConsoleObserverFile *Application::_pConsoleObserverFile = nullptr;

Check warning on line 168 in src/App/Application.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

variable '_pConsoleObserverFile' is non-const and globally accessible, consider making it const [cppcoreguidelines-avoid-non-const-global-variables]

Check warning on line 168 in src/App/Application.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

variable '_pConsoleObserverFile' provides global access to a non-const object; consider making the pointed-to data 'const' [cppcoreguidelines-avoid-non-const-global-variables]

AppExport std::map<std::string, std::string> Application::mConfig;

Check warning on line 170 in src/App/Application.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

variable 'mConfig' is non-const and globally accessible, consider making it const [cppcoreguidelines-avoid-non-const-global-variables]


//**************************************************************************
Expand Down Expand Up @@ -2059,6 +2061,8 @@
App::LinkBaseExtensionPython ::init();
App::LinkExtension ::init();
App::LinkExtensionPython ::init();
App::SuppressibleExtension ::init();
App::SuppressibleExtensionPython ::init();

// Document classes
App::TransactionalObject ::init();
Expand Down
5 changes: 5 additions & 0 deletions src/App/CMakeLists.txt
Expand Up @@ -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)
Expand All @@ -112,6 +113,7 @@ SET(FreeCADApp_XML_SRCS
GeoFeaturePy.xml
GeoFeatureGroupExtensionPy.xml
OriginGroupExtensionPy.xml
SuppressibleExtensionPy.xml
PartPy.xml
DocumentPy.xml
PropertyContainerPy.xml
Expand Down Expand Up @@ -154,6 +156,8 @@ SET(Document_CPP_SRCS
ImagePlane.cpp
OriginGroupExtensionPyImp.cpp
OriginGroupExtension.cpp
SuppressibleExtensionPyImp.cpp
SuppressibleExtension.cpp
PartPyImp.cpp
Part.cpp
Origin.cpp
Expand Down Expand Up @@ -200,6 +204,7 @@ SET(Document_HPP_SRCS
GeoFeatureGroupExtension.h
ImagePlane.h
OriginGroupExtension.h
SuppressibleExtension.h
Part.h
Origin.h
Path.h
Expand Down
61 changes: 61 additions & 0 deletions src/App/SuppressibleExtension.cpp
@@ -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 changes: 63 additions & 0 deletions src/App/SuppressibleExtension.h
@@ -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 changes: 18 additions & 0 deletions src/App/SuppressibleExtensionPy.xml
@@ -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 changes: 49 additions & 0 deletions src/App/SuppressibleExtensionPyImp.cpp
@@ -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;
}
3 changes: 3 additions & 0 deletions src/Gui/Application.cpp
Expand Up @@ -75,7 +75,7 @@
#include "ExpressionBindingPy.h"
#include "FileDialog.h"
#include "GuiApplication.h"
#include "GuiInitScript.h"

Check failure on line 78 in src/Gui/Application.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

'GuiInitScript.h' file not found [clang-diagnostic-error]
#include "LinkViewPy.h"
#include "MainWindow.h"
#include "Macro.h"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -225,7 +226,7 @@
}


void initGuiAppPostMainWindow(bool calledByGuiPy, QApplication &mApp, MainWindow &mw, GUIApplicationNativeEventAware *pmAppNativeEventAware)

Check warning on line 229 in src/Gui/Application.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

mApp ==> map
{
Application &app = *Gui::Application::Instance;

Expand All @@ -242,11 +243,11 @@
QString point = QString::fromLatin1(config["BuildVersionPoint"].c_str());
QString suffix = QString::fromLatin1(config["BuildVersionSuffix"].c_str());
QString title =
QString::fromLatin1("%1 %2.%3.%4%5").arg(mApp.applicationName(), major, minor, point, suffix);

Check warning on line 246 in src/Gui/Application.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

mApp ==> map
mw.setWindowTitle(title);
}
else {
QString title = mApp.applicationName();

Check warning on line 250 in src/Gui/Application.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

mApp ==> map
if (title.isEmpty()) {
title = QString::fromLatin1(App::Application::Config()["ExeName"].c_str());
}
Expand All @@ -254,8 +255,8 @@
}

if (pmAppNativeEventAware != nullptr) {
QObject::connect(&mApp, SIGNAL(messageReceived(const QList<QByteArray> &)),

Check warning on line 258 in src/Gui/Application.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

mApp ==> map

Check warning on line 258 in src/Gui/Application.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

QObject::connect(&mApp, SIGNAL(messageReceived(const QList<QByteArray> &)), <--Consider using Functor-Based Connections
&mw, SLOT(processMessages(const QList<QByteArray> &)));

Check warning on line 259 in src/Gui/Application.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

&mw, SLOT(processMessages(const QList<QByteArray> &))); <--Consider using Functor-Based Connections
}

ParameterGrp::handle hDocGrp = WindowParameter::getDefaultParameter()->GetGroup("Document");
Expand All @@ -273,8 +274,8 @@

// filter wheel events for combo boxes
if (hGrp->GetBool("ComboBoxWheelEventFilter", false)) {
auto filter = new WheelEventFilter(&mApp);

Check warning on line 277 in src/Gui/Application.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

mApp ==> map
mApp.installEventFilter(filter);

Check warning on line 278 in src/Gui/Application.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

mApp ==> map
}

// For values different to 1 and 2 use the OS locale settings
Expand Down Expand Up @@ -401,7 +402,7 @@
// stop splash screen and set immediately the active window that may be of interest
// for scripts using Python binding for Qt
mw.stopSplasher();
mApp.setActiveWindow(&mw);

Check warning on line 405 in src/Gui/Application.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

mApp ==> map

// Activate the correct workbench
std::string start = App::Application::Config()["StartWorkbench"];
Expand Down Expand Up @@ -2245,6 +2246,8 @@
Gui::ViewProviderGeoFeatureGroupExtensionPython::init();
Gui::ViewProviderOriginGroupExtension ::init();
Gui::ViewProviderOriginGroupExtensionPython ::init();
Gui::ViewProviderSuppressibleExtension ::init();
Gui::ViewProviderSuppressibleExtensionPython::init();
Gui::ViewProviderExtern ::init();
Gui::ViewProviderDocumentObject ::init();
Gui::ViewProviderFeature ::init();
Expand Down Expand Up @@ -2435,7 +2438,7 @@
Instance->d->startingUp = false;

// gets called once we start the event loop
QTimer::singleShot(0, &mw, SLOT(delayedStartup()));

Check warning on line 2441 in src/Gui/Application.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

QTimer::singleShot(0, &mw, SLOT(delayedStartup())); <--Consider using Functor-Based Connections

// run the Application event loop
Base::Console().Log("Init: Entering event loop\n");
Expand Down
1 change: 1 addition & 0 deletions src/Gui/CMakeLists.txt
Expand Up @@ -895,6 +895,7 @@ SET(Viewprovider_CPP_SRCS
ViewProviderGroupExtension.cpp
ViewProviderGeoFeatureGroupExtension.cpp
ViewProviderOriginGroupExtension.cpp
ViewProviderSuppressibleExtension.cpp
ViewProviderAnnotation.cpp
ViewProviderDocumentObject.cpp
ViewProviderDocumentObjectGroup.cpp
Expand Down
3 changes: 3 additions & 0 deletions src/Gui/Tree.cpp
Expand Up @@ -965,7 +965,7 @@
auto selItems = this->selectedItems();
// if only one item is selected, setup the edit menu
if (selItems.size() == 1) {
objitem->object()->setupContextMenu(&editMenu, this, SLOT(onStartEditing()));

Check warning on line 968 in src/Gui/Tree.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

objitem->object()->setupContextMenu(&editMenu, this, SLOT(onStartEditing()));
QList<QAction*> editAct = editMenu.actions();
if (!editAct.isEmpty()) {
QAction* topact = contextMenu.actions().constFirst();
Expand Down Expand Up @@ -4800,6 +4800,9 @@
case HighlightMode::Overlined:
f.setOverline(set);
break;
case HighlightMode::StrikeOut:
f.setStrikeOut(set);
break;
case HighlightMode::Blue:
highlight(QColor(200, 200, 255));
break;
Expand Down Expand Up @@ -5348,4 +5351,4 @@
return static_cast<TreeWidget*>(treeWidget());
}

#include "moc_Tree.cpp"

Check failure on line 5354 in src/Gui/Tree.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

'moc_Tree.cpp' file not found [clang-diagnostic-error]
1 change: 1 addition & 0 deletions src/Gui/TreeItemMode.h
Expand Up @@ -31,6 +31,7 @@ namespace Gui {
Underlined,
Italic,
Overlined,
StrikeOut,
Bold,
Blue,
LightBlue,
Expand Down