FreeCAD WebAssembly development snapshot
Some checks failed
FreeCAD master CI / Prepare (push) Has been cancelled
FreeCAD master CI / Pixi (push) Has been cancelled
FreeCAD master CI / Ubuntu (push) Has been cancelled
FreeCAD master CI / Windows (push) Has been cancelled
FreeCAD master CI / Lint (push) Has been cancelled
FreeCAD master CI / WrapUp (push) Has been cancelled
CodeQL Advanced / Analyze (actions) (push) Has been cancelled
CodeQL Advanced / Analyze (python) (push) Has been cancelled
Scorecard supply-chain security / Scorecard analysis (push) Has been cancelled
Stale Issues / stale (push) Has been cancelled

This commit is contained in:
2026-08-20 07:00:53 +08:00
commit b5a086fda5
12718 changed files with 7841410 additions and 0 deletions

View File

@@ -0,0 +1,337 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
/***************************************************************************
* Copyright (c) 2009 Jürgen Riegel <juergen.riegel@web.de> *
* *
* 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 <Base/Console.h>
#include <Gui/Application.h>
#include <Gui/BitmapFactory.h>
#include <Gui/Document.h>
#include <Gui/ViewProvider.h>
#include <Gui/WaitCursor.h>
#include "ui_TaskAppearance.h"
#include "TaskAppearance.h"
using namespace Gui::TaskView;
namespace sp = std::placeholders;
/* TRANSLATOR Gui::TaskView::TaskAppearance */
TaskAppearance::TaskAppearance(QWidget* parent)
: TaskBox(Gui::BitmapFactory().pixmap("document-new"), tr("Appearance"), true, parent)
{
// we need a separate container widget to add all controls to
proxy = new QWidget(this);
ui = new Ui_TaskAppearance();
ui->setupUi(proxy);
setupConnections();
ui->textLabel1_3->hide();
ui->changePlot->hide();
QMetaObject::connectSlotsByName(this);
this->groupLayout()->addWidget(proxy);
Gui::Selection().Attach(this);
// NOLINTBEGIN
this->connectChangedObject = Gui::Application::Instance->signalChangedObject.connect(
std::bind(&TaskAppearance::slotChangedObject, this, sp::_1, sp::_2)
);
// NOLINTEND
}
TaskAppearance::~TaskAppearance()
{
delete ui;
this->connectChangedObject.disconnect();
Gui::Selection().Detach(this);
}
void TaskAppearance::setupConnections()
{
// clang-format off
connect(ui->changeMode, &QComboBox::textActivated,
this, &TaskAppearance::onChangeModeActivated);
connect(ui->changePlot, &QComboBox::textActivated,
this, &TaskAppearance::onChangePlotActivated);
connect(ui->spinTransparency, qOverload<int>(&QSpinBox::valueChanged),
this, &TaskAppearance::onTransparencyValueChanged);
connect(ui->spinPointSize, qOverload<int>(&QSpinBox::valueChanged),
this, &TaskAppearance::onPointSizeValueChanged);
connect(ui->spinLineWidth, qOverload<int>(&QSpinBox::valueChanged),
this, &TaskAppearance::onLineWidthValueChanged);
// clang-format on
}
void TaskAppearance::changeEvent(QEvent* e)
{
TaskBox::changeEvent(e);
if (e->type() == QEvent::LanguageChange) {
ui->retranslateUi(proxy);
}
}
/// @cond DOXERR
void TaskAppearance::OnChange(
Gui::SelectionSingleton::SubjectType& rCaller,
Gui::SelectionSingleton::MessageType Reason
)
{
Q_UNUSED(rCaller);
if (Reason.Type == SelectionChanges::AddSelection || Reason.Type == SelectionChanges::RmvSelection
|| Reason.Type == SelectionChanges::SetSelection
|| Reason.Type == SelectionChanges::ClrSelection) {
std::vector<Gui::ViewProvider*> views = getSelection();
setDisplayModes(views);
setPointSize(views);
setLineWidth(views);
setTransparency(views);
}
}
/// @endcond
void TaskAppearance::slotChangedObject(const Gui::ViewProvider& obj, const App::Property& prop)
{
// This method gets called if a property of any view provider is changed.
// We pick out all the properties for which we need to update this dialog.
const std::vector<Gui::ViewProvider*> Provider = getSelection();
auto vp = std::find_if(Provider.begin(), Provider.end(), [&obj](Gui::ViewProvider* v) {
return v == &obj;
});
if (vp != Provider.end()) {
std::string prop_name = obj.getPropertyName(&prop);
if (prop.isDerivedFrom<App::PropertyInteger>()) {
long value = static_cast<const App::PropertyInteger&>(prop).getValue();
if (prop_name == "Transparency") {
bool blocked = ui->spinTransparency->blockSignals(true);
ui->spinTransparency->setValue(value);
ui->spinTransparency->blockSignals(blocked);
blocked = ui->horizontalSlider->blockSignals(true);
ui->horizontalSlider->setValue(value);
ui->horizontalSlider->blockSignals(blocked);
}
}
else if (prop.isDerivedFrom<App::PropertyFloat>()) {
float value = static_cast<const App::PropertyFloat&>(prop).getValue();
if (prop_name == "PointSize") {
bool blocked = ui->spinPointSize->blockSignals(true);
ui->spinPointSize->setValue((int)value);
ui->spinPointSize->blockSignals(blocked);
}
else if (prop_name == "LineWidth") {
bool blocked = ui->spinLineWidth->blockSignals(true);
ui->spinLineWidth->setValue((int)value);
ui->spinLineWidth->blockSignals(blocked);
}
}
}
}
/**
* Sets the 'Display' property of all selected view providers.
*/
void TaskAppearance::onChangeModeActivated(const QString& s)
{
Gui::WaitCursor wc;
std::vector<Gui::ViewProvider*> Provider = getSelection();
for (const auto& It : Provider) {
App::Property* prop = It->getPropertyByName("DisplayMode");
if (prop && prop->is<App::PropertyEnumeration>()) {
auto Display = static_cast<App::PropertyEnumeration*>(prop);
Display->setValue((const char*)s.toLatin1());
}
}
}
void TaskAppearance::onChangePlotActivated(const QString& s)
{
Base::Console().log("Plot = %s\n", (const char*)s.toLatin1());
}
/**
* Sets the 'Transparency' property of all selected view providers.
*/
void TaskAppearance::onTransparencyValueChanged(int transparency)
{
std::vector<Gui::ViewProvider*> Provider = getSelection();
for (const auto& It : Provider) {
App::Property* prop = It->getPropertyByName("Transparency");
if (prop && prop->isDerivedFrom<App::PropertyInteger>()) {
auto Transparency = static_cast<App::PropertyInteger*>(prop);
Transparency->setValue(transparency);
}
}
}
/**
* Sets the 'PointSize' property of all selected view providers.
*/
void TaskAppearance::onPointSizeValueChanged(int pointsize)
{
std::vector<Gui::ViewProvider*> Provider = getSelection();
for (const auto& It : Provider) {
App::Property* prop = It->getPropertyByName("PointSize");
if (prop && prop->isDerivedFrom<App::PropertyFloat>()) {
auto PointSize = static_cast<App::PropertyFloat*>(prop);
PointSize->setValue(static_cast<float>(pointsize));
}
}
}
/**
* Sets the 'LineWidth' property of all selected view providers.
*/
void TaskAppearance::onLineWidthValueChanged(int linewidth)
{
std::vector<Gui::ViewProvider*> Provider = getSelection();
for (const auto& It : Provider) {
App::Property* prop = It->getPropertyByName("LineWidth");
if (prop && prop->isDerivedFrom<App::PropertyFloat>()) {
auto LineWidth = static_cast<App::PropertyFloat*>(prop);
LineWidth->setValue(static_cast<float>(linewidth));
}
}
}
void TaskAppearance::setDisplayModes(const std::vector<Gui::ViewProvider*>& views)
{
QStringList commonModes, modes;
for (auto it = views.begin(); it != views.end(); ++it) {
App::Property* prop = (*it)->getPropertyByName("DisplayMode");
if (prop && prop->is<App::PropertyEnumeration>()) {
auto display = static_cast<App::PropertyEnumeration*>(prop);
if (!display->hasEnums()) {
return;
}
std::vector<std::string> value = display->getEnumVector();
if (it == views.begin()) {
for (const auto& jt : value) {
commonModes << QLatin1String(jt.c_str());
}
}
else {
for (const auto& jt : value) {
if (commonModes.contains(QLatin1String(jt.c_str()))) {
modes << QLatin1String(jt.c_str());
}
}
commonModes = modes;
modes.clear();
}
}
}
ui->changeMode->clear();
ui->changeMode->addItems(commonModes);
ui->changeMode->setDisabled(commonModes.isEmpty());
// find the display mode to activate
for (const auto view : views) {
App::Property* prop = view->getPropertyByName("DisplayMode");
if (prop && prop->is<App::PropertyEnumeration>()) {
auto display = static_cast<App::PropertyEnumeration*>(prop);
QString activeMode = QString::fromLatin1(display->getValueAsString());
int index = ui->changeMode->findText(activeMode);
if (index != -1) {
ui->changeMode->setCurrentIndex(index);
break;
}
}
}
}
void TaskAppearance::setPointSize(const std::vector<Gui::ViewProvider*>& views)
{
bool pointSize = false;
for (const auto& view : views) {
App::Property* prop = view->getPropertyByName("PointSize");
if (prop && prop->isDerivedFrom<App::PropertyFloat>()) {
bool blocked = ui->spinPointSize->blockSignals(true);
ui->spinPointSize->setValue((int)static_cast<App::PropertyFloat*>(prop)->getValue());
ui->spinPointSize->blockSignals(blocked);
pointSize = true;
break;
}
}
ui->spinPointSize->setEnabled(pointSize);
}
void TaskAppearance::setLineWidth(const std::vector<Gui::ViewProvider*>& views)
{
bool lineWidth = false;
for (const auto& view : views) {
App::Property* prop = view->getPropertyByName("LineWidth");
if (prop && prop->isDerivedFrom<App::PropertyFloat>()) {
bool blocked = ui->spinLineWidth->blockSignals(true);
ui->spinLineWidth->setValue((int)static_cast<App::PropertyFloat*>(prop)->getValue());
ui->spinLineWidth->blockSignals(blocked);
lineWidth = true;
break;
}
}
ui->spinLineWidth->setEnabled(lineWidth);
}
void TaskAppearance::setTransparency(const std::vector<Gui::ViewProvider*>& views)
{
bool transparency = false;
for (const auto& view : views) {
App::Property* prop = view->getPropertyByName("Transparency");
if (prop && prop->isDerivedFrom<App::PropertyInteger>()) {
bool blocked = ui->spinTransparency->blockSignals(true);
ui->spinTransparency->setValue(static_cast<App::PropertyInteger*>(prop)->getValue());
ui->spinTransparency->blockSignals(blocked);
transparency = true;
break;
}
}
ui->spinTransparency->setEnabled(transparency);
ui->horizontalSlider->setEnabled(transparency);
}
std::vector<Gui::ViewProvider*> TaskAppearance::getSelection() const
{
std::vector<Gui::ViewProvider*> views;
// get the complete selection
std::vector<SelectionSingleton::SelObj> sel = Selection().getCompleteSelection();
for (const auto& it : sel) {
Gui::ViewProvider* view = Application::Instance->getDocument(it.pDoc)->getViewProvider(
it.pObject
);
if (view) {
views.push_back(view);
}
}
return views;
}
#include "moc_TaskAppearance.cpp"

View File

@@ -0,0 +1,85 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
/***************************************************************************
* Copyright (c) 2009 Jürgen Riegel <juergen.riegel@web.de> *
* *
* 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 *
* *
***************************************************************************/
#pragma once
#include <Gui/Selection/Selection.h>
#include "TaskView.h"
namespace App
{
class Property;
}
namespace Gui
{
class ViewProvider;
namespace TaskView
{
using TaskAppearance_Connection = fastsignals::connection;
class Ui_TaskAppearance;
class TaskAppearance: public TaskBox, public Gui::SelectionSingleton::ObserverType
{
Q_OBJECT
public:
explicit TaskAppearance(QWidget* parent = nullptr);
~TaskAppearance() override;
/// Observer message from the Selection
void OnChange(
Gui::SelectionSingleton::SubjectType& rCaller,
Gui::SelectionSingleton::MessageType Reason
) override;
private Q_SLOTS:
void setupConnections();
void onChangeModeActivated(const QString&);
void onChangePlotActivated(const QString&);
void onTransparencyValueChanged(int);
void onPointSizeValueChanged(int);
void onLineWidthValueChanged(int);
protected:
void changeEvent(QEvent* e) override;
private:
void slotChangedObject(const Gui::ViewProvider&, const App::Property& Prop);
void setDisplayModes(const std::vector<Gui::ViewProvider*>&);
void setPointSize(const std::vector<Gui::ViewProvider*>&);
void setLineWidth(const std::vector<Gui::ViewProvider*>&);
void setTransparency(const std::vector<Gui::ViewProvider*>&);
std::vector<Gui::ViewProvider*> getSelection() const;
private:
QWidget* proxy;
Ui_TaskAppearance* ui;
TaskAppearance_Connection connectChangedObject;
};
} // namespace TaskView
} // namespace Gui

View File

@@ -0,0 +1,247 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<author/>
<comment/>
<exportmacro/>
<class>Gui::TaskView::TaskAppearance</class>
<widget class="QWidget" name="Gui::TaskView::TaskAppearance">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>193</width>
<height>174</height>
</rect>
</property>
<property name="windowTitle">
<string>Appearance</string>
</property>
<layout class="QVBoxLayout">
<property name="margin">
<number>9</number>
</property>
<property name="spacing">
<number>6</number>
</property>
<item>
<layout class="QHBoxLayout">
<property name="margin">
<number>0</number>
</property>
<property name="spacing">
<number>6</number>
</property>
<item>
<widget class="QLabel" name="textLabel1">
<property name="text">
<string>Document window</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="changeMode"/>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout">
<property name="margin">
<number>0</number>
</property>
<property name="spacing">
<number>6</number>
</property>
<item>
<widget class="QLabel" name="textLabel1_3">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Plot mode</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="changePlot">
<property name="enabled">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout">
<property name="margin">
<number>0</number>
</property>
<property name="spacing">
<number>6</number>
</property>
<item>
<widget class="QLabel" name="textLabel2">
<property name="text">
<string>Point size</string>
</property>
</widget>
</item>
<item>
<spacer>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Expanding</enum>
</property>
<property name="sizeHint">
<size>
<width>71</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QSpinBox" name="spinPointSize">
<property name="maximum">
<number>64</number>
</property>
<property name="minimum">
<number>1</number>
</property>
<property name="value">
<number>2</number>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout">
<property name="margin">
<number>0</number>
</property>
<property name="spacing">
<number>6</number>
</property>
<item>
<widget class="QLabel" name="textLabel3">
<property name="text">
<string>Line width</string>
</property>
</widget>
</item>
<item>
<spacer>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Expanding</enum>
</property>
<property name="sizeHint">
<size>
<width>71</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QSpinBox" name="spinLineWidth">
<property name="maximum">
<number>64</number>
</property>
<property name="minimum">
<number>1</number>
</property>
<property name="value">
<number>2</number>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QLabel" name="textLabel1_2">
<property name="text">
<string>Transparency</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout">
<property name="margin">
<number>0</number>
</property>
<property name="spacing">
<number>6</number>
</property>
<item>
<widget class="QSlider" name="horizontalSlider">
<property name="maximum">
<number>100</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="spinTransparency">
<property name="sizePolicy">
<sizepolicy>
<hsizetype>0</hsizetype>
<vsizetype>0</vsizetype>
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximum">
<number>100</number>
</property>
<property name="singleStep">
<number>5</number>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>horizontalSlider</sender>
<signal>valueChanged(int)</signal>
<receiver>spinTransparency</receiver>
<slot>setValue(int)</slot>
<hints>
<hint type="sourcelabel">
<x>99</x>
<y>219</y>
</hint>
<hint type="destinationlabel">
<x>204</x>
<y>220</y>
</hint>
</hints>
</connection>
<connection>
<sender>spinTransparency</sender>
<signal>valueChanged(int)</signal>
<receiver>horizontalSlider</receiver>
<slot>setValue(int)</slot>
<hints>
<hint type="sourcelabel">
<x>192</x>
<y>233</y>
</hint>
<hint type="destinationlabel">
<x>132</x>
<y>233</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View File

@@ -0,0 +1,168 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
/***************************************************************************
* Copyright (c) 2009 Jürgen Riegel <juergen.riegel@web.de> *
* *
* 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 <QMessageBox>
#include <App/Document.h>
#include <Gui/Application.h>
#include <Gui/Document.h>
#include <Gui/MainWindow.h>
#include <Gui/View3DInventor.h>
#include <Gui/ViewProviderDocumentObject.h>
#include "TaskDialog.h"
#include "TaskView.h"
using namespace Gui::TaskView;
//**************************************************************************
//**************************************************************************
// TaskDialog
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
TaskDialog::TaskDialog()
: QObject(nullptr)
, pos(North)
, escapeButton(true)
, autoCloseTransaction(false)
, autoCloseDeletedDocument(false)
, autoCloseClosedView(false)
{}
TaskDialog::~TaskDialog()
{
for (auto it : Content) {
delete it;
it = nullptr;
}
}
//==== Slots ===============================================================
QWidget* TaskDialog::addTaskBox(QWidget* widget, bool expandable, QWidget* parent)
{
return addTaskBox(QPixmap(), widget, expandable, parent);
}
QWidget* TaskDialog::addTaskBox(const QPixmap& icon, QWidget* widget, bool expandable, QWidget* parent)
{
auto taskbox = new Gui::TaskView::TaskBox(icon, widget->windowTitle(), expandable, parent);
taskbox->groupLayout()->addWidget(widget);
Content.push_back(taskbox);
return taskbox;
}
QWidget* TaskDialog::addTaskBoxWithoutHeader(QWidget* widget)
{
auto taskbox = new Gui::TaskView::TaskBox();
taskbox->groupLayout()->addWidget(widget);
Content.push_back(taskbox);
return taskbox;
}
const std::vector<QWidget*>& TaskDialog::getDialogContent() const
{
return Content;
}
bool TaskDialog::canClose() const
{
QMessageBox msgBox(Gui::getMainWindow());
msgBox.setText(tr("A dialog is already open in the task panel"));
msgBox.setInformativeText(QObject::tr("Close this dialog?"));
msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
msgBox.setDefaultButton(QMessageBox::Yes);
int ret = msgBox.exec();
return (ret == QMessageBox::Yes);
}
void TaskDialog::associateToObject3dView(App::DocumentObject* obj)
{
if (!obj) {
return;
}
Gui::Document* guiDoc = Gui::Application::Instance->getDocument(obj->getDocument());
auto* vp = Gui::Application::Instance->getViewProvider(obj);
auto* vpdo = static_cast<Gui::ViewProviderDocumentObject*>(vp);
auto* view = guiDoc->openEditingView3D(vpdo);
if (!view) {
return;
}
setAssociatedView(view);
setAutoCloseOnClosedView(true);
}
//==== calls from the TaskView ===============================================================
void TaskDialog::open()
{}
void TaskDialog::closed()
{}
void TaskDialog::autoClosedOnTransactionChange()
{}
void TaskDialog::autoClosedOnDeletedDocument()
{}
void TaskDialog::autoClosedOnClosedView()
{}
void TaskDialog::clicked(int)
{}
bool TaskDialog::accept()
{
return true;
}
bool TaskDialog::reject()
{
return true;
}
void TaskDialog::helpRequested()
{}
void TaskDialog::onUndo()
{}
void TaskDialog::onRedo()
{}
void TaskDialog::activate()
{}
void TaskDialog::deactivate()
{}
#include "moc_TaskDialog.cpp"

View File

@@ -0,0 +1,261 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
/***************************************************************************
* Copyright (c) 2009 Jürgen Riegel <juergen.riegel@web.de> *
* *
* 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 *
* *
***************************************************************************/
#pragma once
#include <string>
#include <vector>
#include <QDialogButtonBox>
#include <QPointer>
#include <FCGlobal.h>
namespace App
{
class DocumentObject;
}
namespace Gui
{
class MDIView;
namespace TaskView
{
class TaskContent;
class TaskDialogAttorney;
class TaskDialogPy;
class TaskView;
/// Father class of content with header and Icon
class GuiExport TaskDialog: public QObject
{
Q_OBJECT
public:
enum ButtonPosition
{
North,
South
};
TaskDialog();
~TaskDialog() override;
QWidget* addTaskBox(QWidget* widget, bool expandable = true, QWidget* parent = nullptr);
QWidget* addTaskBox(
const QPixmap& icon,
QWidget* widget,
bool expandable = true,
QWidget* parent = nullptr
);
QWidget* addTaskBoxWithoutHeader(QWidget* widget);
void setButtonPosition(ButtonPosition p)
{
pos = p;
}
ButtonPosition buttonPosition() const
{
return pos;
}
const std::vector<QWidget*>& getDialogContent() const;
bool canClose() const;
/// tells the framework which buttons are wished for the dialog
virtual QDialogButtonBox::StandardButtons getStandardButtons() const
{
return QDialogButtonBox::Ok | QDialogButtonBox::Cancel;
}
virtual void modifyStandardButtons(QDialogButtonBox*)
{}
/// Defines whether a task dialog can be rejected by pressing Esc
void setEscapeButtonEnabled(bool on)
{
escapeButton = on;
}
bool isEscapeButtonEnabled() const
{
return escapeButton;
}
/// Defines whether a task dialog must be closed if the document changed the
/// active transaction.
void setAutoCloseOnTransactionChange(bool on)
{
autoCloseTransaction = on;
}
bool isAutoCloseOnTransactionChange() const
{
return autoCloseTransaction;
}
/// Defines whether a task dialog must be closed if the document is
/// deleted.
void setAutoCloseOnDeletedDocument(bool on)
{
autoCloseDeletedDocument = on;
}
bool isAutoCloseOnDeletedDocument() const
{
return autoCloseDeletedDocument;
}
const std::string& getDocumentName() const
{
return documentName;
}
void setDocumentName(const std::string& doc)
{
documentName = doc;
}
/// Defines whether a task dialog must be closed if the associated view
/// is deleted.
void setAutoCloseOnClosedView(bool on)
{
autoCloseClosedView = on;
}
bool isAutoCloseOnClosedView() const
{
return autoCloseClosedView;
}
void associateToObject3dView(App::DocumentObject* obj);
const Gui::MDIView* getAssociatedView() const
{
return associatedView;
}
void setAssociatedView(const Gui::MDIView* view)
{
associatedView = view;
}
/*!
Indicates whether this task dialog allows other commands to modify
the document while it is open.
*/
virtual bool isAllowedAlterDocument() const
{
return false;
}
/*!
Indicates whether this task dialog allows other commands to modify
the 3d view while it is open.
*/
virtual bool isAllowedAlterView() const
{
return true;
}
/*!
Indicates whether this task dialog allows other commands to modify
the selection while it is open.
*/
virtual bool isAllowedAlterSelection() const
{
return true;
}
virtual bool needsFullSpace() const
{
return false;
}
public:
/// is called by the framework when the dialog is opened
virtual void open();
/// is called by the framework when the dialog is closed
virtual void closed();
/// is called by the framework when the dialog is automatically closed due to
/// changing the active transaction
virtual void autoClosedOnTransactionChange();
/// is called by the framework when the dialog is automatically closed due to
/// deleting the document
virtual void autoClosedOnDeletedDocument();
/// is called by the framework when the dialog is automatically closed due to
/// closing of associated view
virtual void autoClosedOnClosedView();
/// is called by the framework if a button is clicked which has no accept or reject role
virtual void clicked(int);
/// is called by the framework if the dialog is accepted (Ok)
virtual bool accept();
/// is called by the framework if the dialog is rejected (Cancel)
virtual bool reject();
/// is called by the framework if the user press the help button
virtual void helpRequested();
/// is called by the framework if the user press the undo button
virtual void onUndo();
/// is called by the framework if the user press the redo button
virtual void onRedo();
/// Called by the framework when it becomes the shown dialog
/// of the stacked task panel (e.g. when it's document becomes active)
virtual void activate();
/// Called by the framework when it stops being the shown dialog
/// of the stacked task panel (e.g. when it's document stops being active)
virtual void deactivate();
void emitDestructionSignal()
{
Q_EMIT aboutToBeDestroyed();
}
Q_SIGNALS:
void aboutToBeDestroyed();
protected:
QPointer<QDialogButtonBox> buttonBox;
/// List of TaskBoxes of that dialog
std::vector<QWidget*> Content;
ButtonPosition pos;
private:
std::string documentName;
const Gui::MDIView* associatedView;
bool escapeButton;
bool autoCloseTransaction;
bool autoCloseDeletedDocument;
bool autoCloseClosedView;
friend class TaskDialogAttorney;
};
class TaskDialogAttorney
{
private:
static void setButtonBox(TaskDialog* dlg, QDialogButtonBox* box)
{
dlg->buttonBox = box;
}
static QDialogButtonBox* getButtonBox(TaskDialog* dlg)
{
return dlg->buttonBox;
}
friend class TaskDialogPy;
friend class TaskView;
};
} // namespace TaskView
} // namespace Gui

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,197 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
/***************************************************************************
* Copyright (c) 2011 Werner Mayer <wmayer[at]users.sourceforge.net> *
* *
* 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 *
* *
***************************************************************************/
#pragma once
#include "TaskDialog.h"
#include "TaskWatcher.h"
namespace Gui
{
namespace TaskView
{
class ControlPy: public Py::PythonExtension<ControlPy>
{
public:
static void init_type(); // announce properties and methods
static ControlPy* getInstance();
ControlPy();
~ControlPy() override;
Py::Object repr() override;
Py::Object showDialog(const Py::Tuple&);
Py::Object activeDialog(const Py::Tuple&);
Py::Object activeTaskDialog(const Py::Tuple&);
Py::Object closeDialog(const Py::Tuple&);
Py::Object addTaskWatcher(const Py::Tuple&);
Py::Object clearTaskWatcher(const Py::Tuple&);
Py::Object isAllowedAlterDocument(const Py::Tuple&);
Py::Object isAllowedAlterView(const Py::Tuple&);
Py::Object isAllowedAlterSelection(const Py::Tuple&);
Py::Object showTaskView(const Py::Tuple&);
Py::Object showModelView(const Py::Tuple&);
private:
static ControlPy* instance;
};
class GuiExport TaskWatcherPython: public TaskWatcher
{
public:
explicit TaskWatcherPython(const Py::Object&);
~TaskWatcherPython() override;
bool shouldShow() override;
private:
Py::Object watcher;
};
/**
* @brief The TaskDialogPy class
* This class exposes a TaskDialog written in C++ to Python.
*/
class TaskDialogPy: public Py::PythonExtension<TaskDialogPy>
{
public:
using BaseType = Py::PythonExtension<TaskDialogPy>;
static void init_type(); // announce properties and methods
explicit TaskDialogPy(TaskDialog*);
~TaskDialogPy() override;
Py::Object repr() override;
Py::Object getattr(const char*) override;
int setattr(const char*, const Py::Object&) override;
public:
Py::Object getDialogContent(const Py::Tuple&);
/// tells the framework which buttons are wished for the dialog
Py::Object getStandardButtons(const Py::Tuple&);
/// Defines whether a task dialog can be rejected by pressing Esc
Py::Object setEscapeButtonEnabled(const Py::Tuple&);
Py::Object isEscapeButtonEnabled(const Py::Tuple&);
/// Defines whether a task dialog must be closed if the document changed the
/// active transaction.
Py::Object setAutoCloseOnTransactionChange(const Py::Tuple&);
Py::Object isAutoCloseOnTransactionChange(const Py::Tuple&);
Py::Object setAutoCloseOnDeletedDocument(const Py::Tuple&);
Py::Object isAutoCloseOnDeletedDocument(const Py::Tuple&);
Py::Object getDocumentName(const Py::Tuple&);
Py::Object setDocumentName(const Py::Tuple&);
/*!
Indicates whether this task dialog allows other commands to modify
the document while it is open.
*/
Py::Object isAllowedAlterDocument(const Py::Tuple&);
/*!
Indicates whether this task dialog allows other commands to modify
the 3d view while it is open.
*/
Py::Object isAllowedAlterView(const Py::Tuple&);
/*!
Indicates whether this task dialog allows other commands to modify
the selection while it is open.
*/
Py::Object isAllowedAlterSelection(const Py::Tuple&);
Py::Object needsFullSpace(const Py::Tuple&);
/// is called by the framework if the dialog is accepted (Ok)
Py::Object accept(const Py::Tuple&);
/// is called by the framework if the dialog is rejected (Cancel)
Py::Object reject(const Py::Tuple&);
private:
QPointer<TaskDialog> dialog;
};
/**
* @brief The TaskDialogPython class
* This wraps a task dialog that is written in Python.
*/
class GuiExport TaskDialogPython: public TaskDialog
{
public:
explicit TaskDialogPython(const Py::Object&);
~TaskDialogPython() override;
QDialogButtonBox::StandardButtons getStandardButtons() const override;
void modifyStandardButtons(QDialogButtonBox*) override;
/*!
Indicates whether this task dialog allows other commands to modify
the document while it is open.
*/
bool isAllowedAlterDocument() const override;
/*!
Indicates whether this task dialog allows other commands to modify
the 3d view while it is open.
*/
bool isAllowedAlterView() const override;
/*!
Indicates whether this task dialog allows other commands to modify
the selection while it is open.
*/
bool isAllowedAlterSelection() const override;
bool needsFullSpace() const override;
void autoClosedOnTransactionChange() override;
void autoClosedOnDeletedDocument() override;
public:
/// is called by the framework when the dialog is opened
void open() override;
/// is called by the framework if a button is clicked which has no accept or reject role
void clicked(int) override;
/// is called by the framework if the dialog is accepted (Ok)
bool accept() override;
/// is called by the framework if the dialog is rejected (Cancel)
bool reject() override;
/// is called by the framework if the user press the help button
void helpRequested() override;
/// event handling
bool eventFilter(QObject* watched, QEvent* event) override;
private:
bool tryLoadUiFile();
bool tryLoadForm();
void appendForm(QWidget* widget, const QPixmap& icon);
void clearForm();
private:
Py::Object dlg;
};
} // namespace TaskView
} // namespace Gui

View File

@@ -0,0 +1,51 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
/***************************************************************************
* Copyright (c) 2009 Jürgen Riegel <juergen.riegel@web.de> *
* *
* 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 <QDialogButtonBox>
#include <QHBoxLayout>
#include "TaskEditControl.h"
using namespace Gui::TaskView;
TaskEditControl::TaskEditControl(QWidget* parent)
: TaskWidget(parent)
{
hboxLayout = new QHBoxLayout(this);
buttonBox = new QDialogButtonBox(this);
buttonBox->setStandardButtons(QDialogButtonBox::Cancel | QDialogButtonBox::Ok);
buttonBox->setCenterButtons(true);
hboxLayout->addWidget(buttonBox);
}
TaskEditControl::~TaskEditControl() = default;
QDialogButtonBox* TaskEditControl::standardButtons() const
{
return buttonBox;
}
#include "moc_TaskEditControl.cpp"

View File

@@ -0,0 +1,62 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
/***************************************************************************
* Copyright (c) 2009 Jürgen Riegel <juergen.riegel@web.de> *
* *
* 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 *
* *
***************************************************************************/
#pragma once
#include "TaskView.h"
class Ui_TaskEditControl;
class QHBoxLayout;
class QDialogButtonBox;
namespace App
{
class Property;
}
namespace Gui
{
class ViewProvider;
namespace TaskView
{
class TaskEditControl: public TaskWidget
{
Q_OBJECT
public:
explicit TaskEditControl(QWidget* parent = nullptr);
~TaskEditControl() override;
QDialogButtonBox* standardButtons() const;
friend class TaskView;
protected:
QHBoxLayout* hboxLayout;
QDialogButtonBox* buttonBox;
};
} // namespace TaskView
} // namespace Gui

View File

@@ -0,0 +1,37 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Gui::TaskView::TaskEditControl</class>
<widget class="QWidget" name="Gui::TaskView::TaskEditControl">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>193</width>
<height>41</height>
</rect>
</property>
<property name="windowTitle">
<string>Edit</string>
</property>
<layout class="QHBoxLayout">
<property name="spacing">
<number>6</number>
</property>
<property name="margin">
<number>9</number>
</property>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
<property name="centerButtons">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View File

@@ -0,0 +1,713 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
/***************************************************************************
* Copyright (c) 2023 Werner Mayer <wmayer[at]users.sourceforge.net> *
* *
* This file is part of FreeCAD. *
* *
* FreeCAD is free software: you can redistribute it and/or modify it *
* under the terms of the GNU Lesser General Public License as *
* published by the Free Software Foundation, either version 2.1 of the *
* License, or (at your option) any later version. *
* *
* FreeCAD 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 *
* Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public *
* License along with FreeCAD. If not, see *
* <https://www.gnu.org/licenses/>. *
* *
**************************************************************************/
#include <QDialog>
#include <QPushButton>
#include <QAction>
#include <QKeyEvent>
#include <map>
#include <Inventor/SoPickedPoint.h>
#include <Inventor/events/SoLocation2Event.h>
#include <Inventor/events/SoButtonEvent.h>
#include <Inventor/events/SoMouseButtonEvent.h>
#include <Inventor/events/SoKeyboardEvent.h>
#include <Base/Console.h>
#include <Base/Precision.h>
#include <Base/Quantity.h>
#include <Base/Tools.h>
#include <App/Document.h>
#include <Gui/Application.h>
#include <Gui/BitmapFactory.h>
#include <Gui/Camera.h>
#include <Gui/Document.h>
#include <Gui/EditableDatumLabel.h>
#include <Gui/View3DInventor.h>
#include <Gui/View3DInventorViewer.h>
#include <Gui/ViewProviderDocumentObject.h>
#include <Gui/TaskView/TaskView.h>
#include "TaskImage.h"
#include "ui_TaskImage.h"
using namespace Gui;
/* TRANSLATOR Gui::TaskImage */
TaskImage::TaskImage(Image::ImagePlane* obj, QWidget* parent)
: QWidget(parent)
, ui(new Ui_TaskImage)
, feature(obj)
, aspectRatio(1.0)
{
ui->setupUi(this);
ui->groupBoxCalibration->hide();
initialiseTransparency();
// NOLINTNEXTLINE
aspectRatio = obj->XSize.getValue() / obj->YSize.getValue();
connectSignals();
}
TaskImage::~TaskImage()
{
if (!feature.expired() && scale) {
if (scale->isActive()) {
scale->deactivate();
}
scale->deleteLater();
}
}
void TaskImage::connectSignals()
{
// clang-format off
connect(ui->Reverse_checkBox, &QCheckBox::clicked,
this, &TaskImage::onPreview);
connect(ui->XY_radioButton, &QRadioButton::clicked,
this, &TaskImage::onPreview);
connect(ui->XZ_radioButton, &QRadioButton::clicked,
this, &TaskImage::onPreview);
connect(ui->YZ_radioButton, &QRadioButton::clicked,
this, &TaskImage::onPreview);
connect(ui->spinBoxZ, qOverload<double>(&QuantitySpinBox::valueChanged),
this, &TaskImage::onPreview);
connect(ui->spinBoxX, qOverload<double>(&QuantitySpinBox::valueChanged),
this, &TaskImage::onPreview);
connect(ui->spinBoxY, qOverload<double>(&QuantitySpinBox::valueChanged),
this, &TaskImage::onPreview);
connect(ui->spinBoxRotation, qOverload<double>(&QuantitySpinBox::valueChanged),
this, &TaskImage::onPreview);
connect(ui->spinBoxTransparency, qOverload<int>(&QSpinBox::valueChanged),
this, &TaskImage::changeTransparency);
connect(ui->sliderTransparency, qOverload<int>(&QSlider::valueChanged),
this, &TaskImage::changeTransparency);
connect(ui->spinBoxWidth, &QuantitySpinBox::editingFinished,
this, &TaskImage::changeWidth);
connect(ui->spinBoxHeight, &QuantitySpinBox::editingFinished,
this, &TaskImage::changeHeight);
connect(ui->pushButtonScale, &QPushButton::clicked,
this, &TaskImage::onInteractiveScale);
connect(ui->pushButtonApply, &QPushButton::clicked,
this, &TaskImage::acceptScale);
connect(ui->pushButtonCancel, &QPushButton::clicked,
this, &TaskImage::rejectScale);
// clang-format on
}
void TaskImage::initialiseTransparency()
{
// NOLINTBEGIN
auto vp = Application::Instance->getViewProvider(feature.get());
App::Property* prop = vp->getPropertyByName("Transparency");
if (prop && prop->isDerivedFrom<App::PropertyInteger>()) {
auto Transparency = static_cast<App::PropertyInteger*>(prop);
ui->spinBoxTransparency->setValue(Transparency->getValue());
ui->sliderTransparency->setValue(Transparency->getValue());
}
// NOLINTEND
}
void TaskImage::changeTransparency(int val)
{
if (feature.expired()) {
return;
}
auto vp = Application::Instance->getViewProvider(feature.get());
App::Property* prop = vp->getPropertyByName("Transparency");
if (auto Transparency = dynamic_cast<App::PropertyInteger*>(prop)) {
Transparency->setValue(val);
QSignalBlocker block(ui->spinBoxTransparency);
QSignalBlocker blocks(ui->sliderTransparency);
ui->spinBoxTransparency->setValue(val);
ui->sliderTransparency->setValue(val);
}
}
void TaskImage::changeWidth()
{
if (!feature.expired()) {
double val = ui->spinBoxWidth->value().getValue();
feature->XSize.setValue(val);
if (ui->checkBoxRatio->isChecked()) {
feature->YSize.setValue(val / aspectRatio);
QSignalBlocker block(ui->spinBoxHeight);
ui->spinBoxHeight->setValue(val / aspectRatio);
}
}
}
void TaskImage::changeHeight()
{
if (!feature.expired()) {
double val = ui->spinBoxHeight->value().getValue();
feature->YSize.setValue(val);
if (ui->checkBoxRatio->isChecked()) {
feature->XSize.setValue(val * aspectRatio);
QSignalBlocker block(ui->spinBoxWidth);
ui->spinBoxWidth->setValue(val * aspectRatio);
}
}
}
View3DInventorViewer* TaskImage::getViewer() const
{
if (!feature.expired()) {
auto vp = Application::Instance->getViewProvider(feature.get());
auto doc = static_cast<ViewProviderDocumentObject*>(vp)->getDocument(); // NOLINT
auto view = qobject_cast<View3DInventor*>(doc->getViewOfViewProvider(vp));
if (view) {
return view->getViewer();
}
}
return nullptr;
}
void TaskImage::scaleImage(double factor)
{
if (!feature.expired()) {
feature->XSize.setValue(feature->XSize.getValue() * factor);
feature->YSize.setValue(feature->YSize.getValue() * factor);
QSignalBlocker blockW(ui->spinBoxWidth);
ui->spinBoxWidth->setValue(feature->XSize.getValue());
QSignalBlocker blockH(ui->spinBoxHeight);
ui->spinBoxHeight->setValue(feature->YSize.getValue());
}
}
void TaskImage::startScale()
{
if (scale) {
scale->activate();
ui->pushButtonScale->hide();
ui->groupBoxCalibration->show();
ui->pushButtonApply->setEnabled(false);
}
}
void TaskImage::acceptScale()
{
if (scale) {
scaleImage(scale->getScaleFactor());
rejectScale();
}
}
void TaskImage::enableApplyBtn()
{
ui->pushButtonApply->setEnabled(true);
}
void TaskImage::rejectScale()
{
if (scale) {
scale->deactivate();
ui->pushButtonScale->show();
ui->groupBoxCalibration->hide();
}
}
void TaskImage::onInteractiveScale()
{
if (!feature.expired() && !scale) {
View3DInventorViewer* viewer = getViewer();
if (viewer) {
auto vp = Application::Instance->getViewProvider(feature.get());
scale = new InteractiveScale(viewer, vp, feature->globalPlacement());
connect(scale, &InteractiveScale::scaleRequired, this, &TaskImage::acceptScale);
connect(scale, &InteractiveScale::scaleCanceled, this, &TaskImage::rejectScale);
connect(scale, &InteractiveScale::enableApplyBtn, this, &TaskImage::enableApplyBtn);
}
}
startScale();
}
void TaskImage::open()
{
if (!feature.expired()) {
App::Document* doc = feature->getDocument();
doc->openTransaction(QT_TRANSLATE_NOOP("Command", "Edit image"));
restore(feature->Placement.getValue());
}
}
void TaskImage::accept()
{
if (!feature.expired()) {
App::Document* doc = feature->getDocument();
doc->commitTransaction();
doc->recompute();
}
}
void TaskImage::reject()
{
if (!feature.expired()) {
App::Document* doc = feature->getDocument();
doc->abortTransaction();
feature->purgeTouched();
}
}
void TaskImage::onPreview()
{
updateIcon();
updatePlacement();
}
// NOLINTNEXTLINE
void TaskImage::restoreAngles(const Base::Rotation& rot)
{
Base::Vector3d vec(0, 0, 1);
rot.multVec(vec, vec);
double yaw {};
double pitch {};
double roll {};
rot.getYawPitchRoll(yaw, pitch, roll);
bool reverse = false;
const double tol = 1.0e-5;
const double angle1 = 90.0;
const double angle2 = 180.0;
auto isTopOrBottom = [=](bool& reverse) {
if (std::fabs(vec.z - 1.0) < tol) {
return true;
}
if (std::fabs(vec.z + 1.0) < tol) {
reverse = true;
return true;
}
return false;
};
auto isFrontOrRear = [&](bool& reverse) {
if (std::fabs(vec.y + 1.0) < tol) {
if (std::fabs(yaw - angle2) < tol) {
pitch = -angle2 - pitch;
}
return true;
}
if (std::fabs(vec.y - 1.0) < tol) {
if (std::fabs(yaw) < tol) {
pitch = -angle2 - pitch;
}
reverse = true;
return true;
}
return false;
};
auto isRightOrLeft = [&](bool& reverse) {
if (std::fabs(vec.x - 1.0) < tol) {
if (std::fabs(yaw + angle1) < tol) {
pitch = -angle2 - pitch;
}
return true;
}
if (std::fabs(vec.x + 1.0) < tol) {
if (std::fabs(yaw - angle1) < tol) {
pitch = -angle2 - pitch;
}
reverse = true;
return true;
}
return false;
};
if (isTopOrBottom(reverse)) {
int inv = reverse ? -1 : 1;
ui->XY_radioButton->setChecked(true);
ui->spinBoxRotation->setValue(yaw * inv);
}
else if (isFrontOrRear(reverse)) {
ui->XZ_radioButton->setChecked(true);
ui->spinBoxRotation->setValue(-pitch);
}
else if (isRightOrLeft(reverse)) {
ui->YZ_radioButton->setChecked(true);
ui->spinBoxRotation->setValue(-pitch);
}
ui->Reverse_checkBox->setChecked(reverse);
}
void TaskImage::restore(const Base::Placement& plm)
{
if (feature.expired()) {
return;
}
QSignalBlocker blockW(ui->spinBoxWidth);
QSignalBlocker blockH(ui->spinBoxHeight);
ui->spinBoxWidth->setValue(feature->XSize.getValue());
ui->spinBoxHeight->setValue(feature->YSize.getValue());
Base::Rotation rot = plm.getRotation(); // NOLINT
Base::Vector3d pos = plm.getPosition();
restoreAngles(rot);
Base::Vector3d R0(0, 0, 0);
Base::Vector3d RX(1, 0, 0);
Base::Vector3d RY(0, 1, 0);
RX = rot.multVec(RX);
RY = rot.multVec(RY);
pos.TransformToCoordinateSystem(R0, RX, RY);
ui->spinBoxX->setValue(pos.x);
ui->spinBoxY->setValue(pos.y);
ui->spinBoxZ->setValue(pos.z);
onPreview();
}
void TaskImage::updatePlacement()
{
double angle = ui->spinBoxRotation->value().getValue();
bool reverse = ui->Reverse_checkBox->isChecked();
// NOLINTBEGIN
Base::Placement Pos;
Base::Rotation rot;
double dir = reverse ? 180. : 0.;
int inv = reverse ? -1 : 1;
if (ui->XY_radioButton->isChecked()) {
rot.setYawPitchRoll(inv * angle, 0., dir);
}
else if (ui->XZ_radioButton->isChecked()) {
rot.setYawPitchRoll(dir, -angle, 90.);
}
else if (ui->YZ_radioButton->isChecked()) {
rot.setYawPitchRoll(90. - dir, -angle, 90.);
}
else if (!feature.expired()) {
Base::Placement plm = feature->Placement.getValue();
rot = plm.getRotation();
}
// NOLINTEND
Base::Vector3d offset = Base::Vector3d(
ui->spinBoxX->value().getValue(),
ui->spinBoxY->value().getValue(),
ui->spinBoxZ->value().getValue()
);
offset = rot.multVec(offset);
Pos = Base::Placement(offset, rot);
if (!feature.expired()) {
feature->Placement.setValue(Pos);
if (scale) {
scale->setPlacement(feature->globalPlacement());
}
}
}
void TaskImage::updateIcon()
{
std::string icon;
bool reverse = ui->Reverse_checkBox->isChecked();
if (ui->XY_radioButton->isChecked()) {
icon = reverse ? "view-bottom" : "view-top";
}
else if (ui->XZ_radioButton->isChecked()) {
icon = reverse ? "view-rear" : "view-front";
}
else if (ui->YZ_radioButton->isChecked()) {
icon = reverse ? "view-left" : "view-right";
}
ui->previewLabel->setPixmap(
Gui::BitmapFactory().pixmapFromSvg(icon.c_str(), ui->previewLabel->size())
);
}
// ----------------------------------------------------------------------------
InteractiveScale::InteractiveScale(
View3DInventorViewer* view,
ViewProvider* vp,
const Base::Placement& plc
) // NOLINT
: active(false)
, placement(plc)
, viewer(view)
, viewProv(vp)
, midPoint(SbVec3f(0, 0, 0))
{
measureLabel = new EditableDatumLabel(viewer, placement, SbColor(1.0F, 0.149F, 0.0F)); // NOLINT
}
InteractiveScale::~InteractiveScale()
{
delete measureLabel;
}
void InteractiveScale::activate()
{
if (viewer) {
viewer->setEditing(true);
viewer->addEventCallback(
SoLocation2Event::getClassTypeId(),
InteractiveScale::getMousePosition,
this
);
viewer->addEventCallback(SoButtonEvent::getClassTypeId(), InteractiveScale::soEventFilter, this);
viewer->setSelectionEnabled(false);
viewer->getWidget()->setCursor(QCursor(Qt::CrossCursor));
active = true;
}
}
void InteractiveScale::deactivate()
{
if (viewer) {
points.clear();
measureLabel->deactivate();
viewer->setEditing(false);
viewer->removeEventCallback(
SoLocation2Event::getClassTypeId(),
InteractiveScale::getMousePosition,
this
);
viewer->removeEventCallback(
SoButtonEvent::getClassTypeId(),
InteractiveScale::soEventFilter,
this
);
viewer->setSelectionEnabled(true);
viewer->getWidget()->setCursor(QCursor(Qt::ArrowCursor));
active = false;
}
}
double InteractiveScale::getScaleFactor() const
{
if ((points[0] - points[1]).length() == 0.) {
return 1.0;
}
return measureLabel->getValue() / (points[0] - points[1]).length();
}
double InteractiveScale::getDistance(const SbVec3f& pt) const
{
if (points.empty()) {
return 0.0;
}
return (points[0] - pt).length();
}
void InteractiveScale::setDistance(const SbVec3f& pos3d)
{
Base::Quantity quantity;
quantity.setValue(getDistance(pos3d));
quantity.setUnit(Base::Unit::Length);
// Update the displayed distance
double factor {};
std::string unitStr;
std::string valueStr;
valueStr = quantity.getUserString(factor, unitStr);
measureLabel->label->string = SbString(valueStr.c_str());
measureLabel->label->setPoints(getCoordsOnImagePlane(points[0]), getCoordsOnImagePlane(pos3d));
}
void InteractiveScale::findPointOnImagePlane(SoEventCallback* ecb)
{
const SoEvent* mbe = ecb->getEvent();
auto view = static_cast<Gui::View3DInventorViewer*>(ecb->getUserData());
std::unique_ptr<SoPickedPoint> pp(view->getPointOnRay(mbe->getPosition(), viewProv));
if (pp) {
auto pos3d = pp->getPoint();
collectPoint(pos3d);
}
}
void InteractiveScale::collectPoint(const SbVec3f& pos3d)
{
if (points.empty()) {
points.push_back(pos3d);
measureLabel->label->setPoints(getCoordsOnImagePlane(pos3d), getCoordsOnImagePlane(pos3d));
measureLabel->activate();
}
else if (points.size() == 1) {
double distance = getDistance(pos3d);
if (distance > Base::Precision::Confusion()) {
points.push_back(pos3d);
midPoint = (points[0] + points[1]) / 2;
measureLabel->startEdit(getDistance(points[1]), this, true);
Q_EMIT enableApplyBtn();
}
else {
Base::Console().warning(
std::string("Image scale"),
"The second point is too close. Retry!\n"
);
}
}
}
void InteractiveScale::getMousePosition(void* ud, SoEventCallback* ecb)
{
auto scale = static_cast<InteractiveScale*>(ud);
const SoEvent* l2e = ecb->getEvent();
auto view = static_cast<Gui::View3DInventorViewer*>(ecb->getUserData());
if (scale->points.size() == 1) {
ecb->setHandled();
std::unique_ptr<SoPickedPoint> pp(view->getPointOnRay(l2e->getPosition(), scale->viewProv));
if (pp) {
SbVec3f pos3d = pp->getPoint();
scale->setDistance(pos3d);
}
}
}
void InteractiveScale::soEventFilter(void* ud, SoEventCallback* ecb)
{
auto scale = static_cast<InteractiveScale*>(ud);
const SoEvent* soEvent = ecb->getEvent();
if (soEvent->isOfType(SoKeyboardEvent::getClassTypeId())) {
/* If user presses escape, then we cancel the tool.*/
const auto kbe = static_cast<const SoKeyboardEvent*>(soEvent); // NOLINT
if (kbe->getKey() == SoKeyboardEvent::ESCAPE && kbe->getState() == SoButtonEvent::UP) {
ecb->setHandled();
Q_EMIT scale->scaleCanceled();
}
}
else if (soEvent->isOfType(SoMouseButtonEvent::getClassTypeId())) {
const auto mbe = static_cast<const SoMouseButtonEvent*>(soEvent); // NOLINT
if (mbe->getButton() == SoMouseButtonEvent::BUTTON1
&& mbe->getState() == SoButtonEvent::DOWN) {
ecb->setHandled();
scale->findPointOnImagePlane(ecb);
}
if (mbe->getButton() == SoMouseButtonEvent::BUTTON2
&& mbe->getState() == SoButtonEvent::DOWN) {
ecb->setHandled();
Q_EMIT scale->scaleCanceled();
}
}
}
bool InteractiveScale::eventFilter(QObject* object, QEvent* event)
{
if (event->type() == QEvent::KeyRelease) {
auto keyEvent = static_cast<QKeyEvent*>(event); // NOLINT
/* If user press enter in the spinbox, then we validate the tool.*/
if ((keyEvent->key() == Qt::Key_Enter || keyEvent->key() == Qt::Key_Return)
&& qobject_cast<QuantitySpinBox*>(object)) {
Q_EMIT scaleRequired();
}
/* If user press escape, then we cancel the tool. Required here as well for when checkbox
* has focus.*/
if (keyEvent->key() == Qt::Key_Escape) {
Q_EMIT scaleCanceled();
}
}
return false;
}
void InteractiveScale::setPlacement(const Base::Placement& plc)
{
placement = plc;
measureLabel->setPlacement(plc);
}
SbVec3f InteractiveScale::getCoordsOnImagePlane(const SbVec3f& point)
{
// Plane form
Base::Vector3d RX(1, 0, 0);
Base::Vector3d RY(0, 1, 0);
// move to position of Sketch
Base::Rotation tmp(placement.getRotation());
RX = tmp.multVec(RX);
RY = tmp.multVec(RY);
Base::Vector3d pos = placement.getPosition();
// we use pos as the Base because in setPlacement we set transform->translation using
// placement.getPosition() to fix the Zoffset. But this applies the X & Y translation too.
Base::Vector3d pnt(point[0], point[1], point[2]);
pnt.TransformToCoordinateSystem(pos, RX, RY);
return {float(pnt.x), float(pnt.y), 0.0F};
}
// ----------------------------------------------------------------------------
TaskImageDialog::TaskImageDialog(Image::ImagePlane* obj)
: widget {new TaskImage(obj)}
{
addTaskBox(Gui::BitmapFactory().pixmap("image-plane"), widget);
associateToObject3dView(obj);
}
void TaskImageDialog::open()
{
widget->open();
}
bool TaskImageDialog::accept()
{
widget->accept();
return true;
}
bool TaskImageDialog::reject()
{
widget->reject();
return true;
}
#include "moc_TaskImage.cpp"

View File

@@ -0,0 +1,153 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
/***************************************************************************
* Copyright (c) 2023 Werner Mayer <wmayer[at]users.sourceforge.net> *
* *
* This file is part of FreeCAD. *
* *
* FreeCAD is free software: you can redistribute it and/or modify it *
* under the terms of the GNU Lesser General Public License as *
* published by the Free Software Foundation, either version 2.1 of the *
* License, or (at your option) any later version. *
* *
* FreeCAD 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 *
* Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public *
* License along with FreeCAD. If not, see *
* <https://www.gnu.org/licenses/>. *
* *
**************************************************************************/
#pragma once
#include <Inventor/SbVec3f.h>
#include <QPointer>
#include <Gui/TaskView/TaskDialog.h>
#include <App/DocumentObserver.h>
#include <App/ImagePlane.h>
#include <memory>
#include <vector>
class SbVec3f;
class SoEventCallback;
class EditableDatumLabel;
namespace Gui
{
class View3DInventorViewer;
class ViewProvider;
class InteractiveScale: public QObject
{
Q_OBJECT
Q_DISABLE_COPY(InteractiveScale)
public:
explicit InteractiveScale(View3DInventorViewer* view, ViewProvider* vp, const Base::Placement& plc);
~InteractiveScale() override;
bool eventFilter(QObject* object, QEvent* event) override;
void activate();
void deactivate();
bool isActive() const
{
return active;
}
double getScaleFactor() const;
double getDistance(const SbVec3f&) const;
void setPlacement(const Base::Placement& plc);
private:
static void soEventFilter(void* ud, SoEventCallback* ecb);
static void getMousePosition(void* ud, SoEventCallback* ecb);
void findPointOnImagePlane(SoEventCallback* ecb);
void collectPoint(const SbVec3f&);
void setDistance(const SbVec3f&);
/// give the coordinates of a line on the image plane in imagePlane (2D) coordinates
SbVec3f getCoordsOnImagePlane(const SbVec3f& point);
Q_SIGNALS:
void scaleRequired();
void scaleCanceled();
void enableApplyBtn();
private:
bool active;
Base::Placement placement;
EditableDatumLabel* measureLabel;
QPointer<Gui::View3DInventorViewer> viewer;
ViewProvider* viewProv;
std::vector<SbVec3f> points;
SbVec3f midPoint;
};
class Ui_TaskImage;
class TaskImage: public QWidget
{
Q_OBJECT
Q_DISABLE_COPY(TaskImage)
public:
explicit TaskImage(Image::ImagePlane* obj, QWidget* parent = nullptr);
~TaskImage() override;
void open();
void accept();
void reject();
private:
void initialiseTransparency();
void connectSignals();
void onInteractiveScale();
View3DInventorViewer* getViewer() const;
void scaleImage(double);
void startScale();
void acceptScale();
void rejectScale();
void enableApplyBtn();
void restore(const Base::Placement&);
void restoreAngles(const Base::Rotation&);
void onPreview();
void updateIcon();
void updatePlacement();
private:
void changeTransparency(int val);
void changeWidth();
void changeHeight();
private:
std::unique_ptr<Ui_TaskImage> ui;
QPointer<InteractiveScale> scale;
App::WeakPtrT<Image::ImagePlane> feature;
double aspectRatio;
};
class TaskImageDialog: public Gui::TaskView::TaskDialog
{
Q_OBJECT
public:
explicit TaskImageDialog(Image::ImagePlane* obj);
public:
void open() override;
bool accept() override;
bool reject() override;
QDialogButtonBox::StandardButtons getStandardButtons() const override
{
return QDialogButtonBox::Ok | QDialogButtonBox::Cancel;
}
private:
TaskImage* widget;
};
} // namespace Gui

View File

@@ -0,0 +1,288 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Gui::TaskImage</class>
<widget class="QWidget" name="Gui::TaskImage">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>421</width>
<height>267</height>
</rect>
</property>
<property name="windowTitle">
<string>Image Plane Settings</string>
</property>
<layout class="QGridLayout" name="gridLayout_5">
<item row="0" column="0" colspan="2">
<layout class="QGridLayout" name="gridLayout_8">
<item row="0" column="0">
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Planes</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QRadioButton" name="XY_radioButton">
<property name="text">
<string>XY-plane</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="XZ_radioButton">
<property name="text">
<string>XZ-plane</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="YZ_radioButton">
<property name="text">
<string>YZ-plane</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="0" column="1">
<widget class="QLabel" name="previewLabel">
<property name="minimumSize">
<size>
<width>48</width>
<height>48</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>48</width>
<height>48</height>
</size>
</property>
<property name="text">
<string notr="true">Preview</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="1" column="0" colspan="2">
<widget class="QCheckBox" name="Reverse_checkBox">
<property name="text">
<string>Reverse direction</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="labelZ">
<property name="text">
<string>Offset</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="Gui::QuantitySpinBox" name="spinBoxZ">
<property name="unit" stdset="0">
<string notr="true">mm</string>
</property>
<property name="minimum" stdset="0">
<double>-999999999.000000000000000</double>
</property>
<property name="maximum" stdset="0">
<double>999999999.000000000000000</double>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="labelX">
<property name="text">
<string>X distance</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="Gui::QuantitySpinBox" name="spinBoxX">
<property name="unit" stdset="0">
<string notr="true">mm</string>
</property>
<property name="minimum" stdset="0">
<double>-999999999.000000000000000</double>
</property>
<property name="maximum" stdset="0">
<double>999999999.000000000000000</double>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="labelY">
<property name="text">
<string>Y distance</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="Gui::QuantitySpinBox" name="spinBoxY">
<property name="unit" stdset="0">
<string notr="true">mm</string>
</property>
<property name="minimum" stdset="0">
<double>-999999999.000000000000000</double>
</property>
<property name="maximum" stdset="0">
<double>999999999.000000000000000</double>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QLabel" name="labelRotation">
<property name="text">
<string>Rotation</string>
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="Gui::QuantitySpinBox" name="spinBoxRotation">
<property name="unit" stdset="0">
<string notr="true">deg</string>
</property>
</widget>
</item>
<item row="6" column="0" colspan="2">
<layout class="QHBoxLayout">
<item>
<widget class="QLabel" name="labelTransparency">
<property name="text">
<string>Transparency</string>
</property>
</widget>
</item>
<item>
<widget class="QSlider" name="sliderTransparency">
<property name="maximum">
<number>100</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="spinBoxTransparency">
<property name="value">
<number>0</number>
</property>
<property name="minimum">
<number>0</number>
</property>
<property name="maximum">
<number>100</number>
</property>
</widget>
</item>
</layout>
</item>
<item row="7" column="0" colspan="2">
<widget class="QGroupBox" name="groupBox1">
<property name="title">
<string>Image Size</string>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Width</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="Gui::QuantitySpinBox" name="spinBoxWidth">
<property name="unit" stdset="0">
<string notr="true">mm</string>
</property>
<property name="minimum" stdset="0">
<double>0.00000001</double>
</property>
<property name="maximum" stdset="0">
<double>999999999.000000000000000</double>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Height</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="Gui::QuantitySpinBox" name="spinBoxHeight">
<property name="unit" stdset="0">
<string notr="true">mm</string>
</property>
<property name="minimum" stdset="0">
<double>0.00000001</double>
</property>
<property name="maximum" stdset="0">
<double>999999999.000000000000000</double>
</property>
</widget>
</item>
<item row="2" column="0" colspan="2">
<widget class="QCheckBox" name="checkBoxRatio">
<property name="text">
<string>Keep aspect ratio</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item row="3" column="0" colspan="2">
<widget class="QPushButton" name="pushButtonScale">
<property name="toolTip">
<string>Scales the image interactively by setting a length between two points of the image</string>
</property>
<property name="text">
<string>Calibrate</string>
</property>
</widget>
</item>
<item row="4" column="0" colspan="2">
<widget class="QGroupBox" name="groupBoxCalibration">
<property name="title">
<string>Calibration</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QPushButton" name="pushButtonApply">
<property name="text">
<string>Apply</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButtonCancel">
<property name="text">
<string>Cancel</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>Gui::QuantitySpinBox</class>
<extends>QWidget</extends>
<header>Gui/QuantitySpinBox.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>

View File

@@ -0,0 +1,216 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
/***************************************************************************
* Copyright (c) 2023 Werner Mayer <wmayer[at]users.sourceforge.net> *
* *
* This file is part of FreeCAD. *
* *
* FreeCAD is free software: you can redistribute it and/or modify it *
* under the terms of the GNU Lesser General Public License as *
* published by the Free Software Foundation, either version 2.1 of the *
* License, or (at your option) any later version. *
* *
* FreeCAD 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 *
* Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public *
* License along with FreeCAD. If not, see *
* <https://www.gnu.org/licenses/>. *
* *
**************************************************************************/
#include <QDialog>
#include <map>
#include <Base/Tools.h>
#include <App/Document.h>
#include <Gui/BitmapFactory.h>
#include <Gui/Camera.h>
#include <Gui/TaskView/TaskView.h>
#include "TaskOrientation.h"
#include "ui_TaskOrientation.h"
using namespace Gui;
TaskOrientation::TaskOrientation(App::GeoFeature* obj, QWidget* parent)
: QWidget(parent)
, ui(new Ui_TaskOrientation)
, feature(obj)
{
ui->setupUi(this);
// clang-format off
connect(ui->Reverse_checkBox, &QCheckBox::clicked,
this, &TaskOrientation::onPreview);
connect(ui->XY_radioButton , &QRadioButton::clicked,
this, &TaskOrientation::onPreview);
connect(ui->XZ_radioButton , &QRadioButton::clicked,
this, &TaskOrientation::onPreview);
connect(ui->YZ_radioButton , &QRadioButton::clicked,
this, &TaskOrientation::onPreview);
connect(ui->Offset_doubleSpinBox, qOverload<double>(&QuantitySpinBox::valueChanged),
this, &TaskOrientation::onPreview);
// clang-format on
}
TaskOrientation::~TaskOrientation() = default;
void TaskOrientation::open()
{
if (!feature.expired()) {
App::Document* doc = feature->getDocument();
doc->openTransaction(QT_TRANSLATE_NOOP("Command", "Edit image"));
restore(feature->Placement.getValue());
}
}
void TaskOrientation::accept()
{
if (!feature.expired()) {
App::Document* doc = feature->getDocument();
doc->commitTransaction();
doc->recompute();
}
}
void TaskOrientation::reject()
{
if (!feature.expired()) {
App::Document* doc = feature->getDocument();
doc->abortTransaction();
feature->purgeTouched();
}
}
void TaskOrientation::onPreview()
{
updateIcon();
updatePlacement();
}
void TaskOrientation::restore(const Base::Placement& plm)
{
auto isReversed = [](Camera::Orientation type) {
return (type == Camera::Bottom) || (type == Camera::Rear) || (type == Camera::Left);
};
std::map<Camera::Orientation, Base::Rotation> rotations {
{Camera::Top, Camera::convert(Camera::Top)},
{Camera::Bottom, Camera::convert(Camera::Bottom)},
{Camera::Front, Camera::convert(Camera::Front)},
{Camera::Rear, Camera::convert(Camera::Rear)},
{Camera::Right, Camera::convert(Camera::Right)},
{Camera::Left, Camera::convert(Camera::Left)}
};
Base::Rotation rot = plm.getRotation();
Base::Vector3d pos = plm.getPosition();
double prec = 1.0e-5;
for (const auto& it : rotations) {
if (rot.isSame(it.second, prec)) {
if (it.first == Camera::Top || it.first == Camera::Bottom) {
ui->XY_radioButton->setChecked(true);
ui->Offset_doubleSpinBox->setValue(pos.z);
}
else if (it.first == Camera::Front || it.first == Camera::Rear) {
ui->XZ_radioButton->setChecked(true);
ui->Offset_doubleSpinBox->setValue(pos.y);
}
else if (it.first == Camera::Right || it.first == Camera::Left) {
ui->YZ_radioButton->setChecked(true);
ui->Offset_doubleSpinBox->setValue(pos.x);
}
if (isReversed(it.first)) {
ui->Reverse_checkBox->setChecked(true);
}
}
}
onPreview();
}
void TaskOrientation::updatePlacement()
{
Base::Placement Pos;
double offset = ui->Offset_doubleSpinBox->value().getValue();
bool reverse = ui->Reverse_checkBox->isChecked();
if (ui->XY_radioButton->isChecked()) {
if (!reverse) {
Pos = Base::Placement(Base::Vector3d(0, 0, offset), Camera::convert(Camera::Top));
}
else {
Pos = Base::Placement(Base::Vector3d(0, 0, offset), Camera::convert(Camera::Bottom));
}
}
else if (ui->XZ_radioButton->isChecked()) {
if (!reverse) {
Pos = Base::Placement(Base::Vector3d(0, offset, 0), Camera::convert(Camera::Front));
}
else {
Pos = Base::Placement(Base::Vector3d(0, offset, 0), Camera::convert(Camera::Rear));
}
}
else if (ui->YZ_radioButton->isChecked()) {
if (!reverse) {
Pos = Base::Placement(Base::Vector3d(offset, 0, 0), Camera::convert(Camera::Right));
}
else {
Pos = Base::Placement(Base::Vector3d(offset, 0, 0), Camera::convert(Camera::Left));
}
}
if (!feature.expired()) {
feature->Placement.setValue(Pos);
}
}
void TaskOrientation::updateIcon()
{
std::string icon;
bool reverse = ui->Reverse_checkBox->isChecked();
if (ui->XY_radioButton->isChecked()) {
icon = reverse ? "view-bottom" : "view-top";
}
else if (ui->XZ_radioButton->isChecked()) {
icon = reverse ? "view-rear" : "view-front";
}
else if (ui->YZ_radioButton->isChecked()) {
icon = reverse ? "view-left" : "view-right";
}
ui->previewLabel->setPixmap(
Gui::BitmapFactory().pixmapFromSvg(icon.c_str(), ui->previewLabel->size())
);
}
// ----------------------------------------------------------------------------
TaskOrientationDialog::TaskOrientationDialog(App::GeoFeature* obj)
{
widget = new TaskOrientation(obj);
addTaskBox(widget);
}
void TaskOrientationDialog::open()
{
widget->open();
}
bool TaskOrientationDialog::accept()
{
widget->accept();
return true;
}
bool TaskOrientationDialog::reject()
{
widget->reject();
return true;
}
#include "moc_TaskOrientation.cpp"

View File

@@ -0,0 +1,79 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
/***************************************************************************
* Copyright (c) 2023 Werner Mayer <wmayer[at]users.sourceforge.net> *
* *
* This file is part of FreeCAD. *
* *
* FreeCAD is free software: you can redistribute it and/or modify it *
* under the terms of the GNU Lesser General Public License as *
* published by the Free Software Foundation, either version 2.1 of the *
* License, or (at your option) any later version. *
* *
* FreeCAD 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 *
* Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public *
* License along with FreeCAD. If not, see *
* <https://www.gnu.org/licenses/>. *
* *
**************************************************************************/
#pragma once
#include <Gui/TaskView/TaskDialog.h>
#include <App/DocumentObserver.h>
#include <App/GeoFeature.h>
#include <memory>
namespace Gui
{
class Ui_TaskOrientation;
class TaskOrientation: public QWidget
{
Q_OBJECT
public:
explicit TaskOrientation(App::GeoFeature* obj, QWidget* parent = nullptr);
~TaskOrientation() override;
void open();
void accept();
void reject();
private:
void restore(const Base::Placement&);
void onPreview();
void updateIcon();
void updatePlacement();
private:
std::unique_ptr<Ui_TaskOrientation> ui;
App::WeakPtrT<App::GeoFeature> feature;
};
class TaskOrientationDialog: public Gui::TaskView::TaskDialog
{
Q_OBJECT
public:
explicit TaskOrientationDialog(App::GeoFeature* obj);
public:
void open() override;
bool accept() override;
bool reject() override;
QDialogButtonBox::StandardButtons getStandardButtons() const override
{
return QDialogButtonBox::Ok | QDialogButtonBox::Cancel;
}
private:
TaskOrientation* widget;
};
} // namespace Gui

View File

@@ -0,0 +1,114 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Gui::TaskOrientation</class>
<widget class="QWidget" name="Gui::TaskOrientation">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>194</width>
<height>200</height>
</rect>
</property>
<property name="windowTitle">
<string>Choose Orientation</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Planes</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QRadioButton" name="XY_radioButton">
<property name="text">
<string>XY-plane</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="XZ_radioButton">
<property name="text">
<string>XZ-plane</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="YZ_radioButton">
<property name="text">
<string>YZ-plane</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="1" column="0" colspan="2">
<widget class="QCheckBox" name="Reverse_checkBox">
<property name="text">
<string>Reverse direction</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLabel" name="previewLabel">
<property name="minimumSize">
<size>
<width>48</width>
<height>48</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>48</width>
<height>48</height>
</size>
</property>
<property name="text">
<string notr="true">Preview</string>
</property>
</widget>
</item>
<item row="2" column="0" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Offset</string>
</property>
</widget>
</item>
<item>
<widget class="Gui::QuantitySpinBox" name="Offset_doubleSpinBox" native="true">
<property name="unit" stdset="0">
<string notr="true">mm</string>
</property>
<property name="minimum" stdset="0">
<double>-999999999.000000000000000</double>
</property>
<property name="maximum" stdset="0">
<double>999999999.000000000000000</double>
</property>
<property name="singleStep" stdset="0">
<double>1.000000000000000</double>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>Gui::QuantitySpinBox</class>
<extends>QWidget</extends>
<header>Gui/QuantitySpinBox.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>

View File

@@ -0,0 +1,254 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
/***************************************************************************
* Copyright (c) 2010 Jürgen Riegel <juergen.riegel@web.de> *
* *
* 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 <App/Document.h>
#include <App/DocumentObject.h>
#include <Base/Console.h>
#include <Gui/BitmapFactory.h>
#include <Gui/Selection/SelectionFilter.h>
#include <Gui/Selection/SelectionObject.h>
#include "ui_TaskSelectLinkProperty.h"
#include "TaskSelectLinkProperty.h"
using namespace Gui::TaskView;
/* TRANSLATOR Gui::TaskView::TaskSelectLinkProperty */
TaskSelectLinkProperty::TaskSelectLinkProperty(const char* sFilter, App::Property* prop, QWidget* parent)
: TaskBox(Gui::BitmapFactory().pixmap("mouse_pointer"), tr("edit selection"), true, parent)
, Filter(nullptr)
, LinkSub(nullptr)
, LinkList(nullptr)
{
// we need a separate container widget to add all controls to
proxy = new QWidget(this);
ui = new Ui_TaskSelectLinkProperty();
ui->setupUi(proxy);
setupConnections();
this->groupLayout()->addWidget(proxy);
Gui::Selection().Attach(this);
ui->Remove->setIcon(Gui::BitmapFactory().iconFromTheme("delete"));
ui->Add->setIcon(Gui::BitmapFactory().iconFromTheme("list-add"));
ui->Invert->setIcon(Gui::BitmapFactory().iconFromTheme("list-remove"));
ui->Help->setIcon(Gui::BitmapFactory().iconFromTheme("help-browser"));
// deactivate not implemented stuff
ui->Remove->setDisabled(true);
ui->Add->setDisabled(true);
ui->Invert->setDisabled(true);
ui->Help->setDisabled(true);
// property have to be set!
assert(prop);
StartObject = nullptr;
if (prop->isDerivedFrom<App::PropertyLinkSub>()) {
LinkSub = dynamic_cast<App::PropertyLinkSub*>(prop);
}
else if (prop->isDerivedFrom<App::PropertyLinkList>()) {
LinkList = dynamic_cast<App::PropertyLinkList*>(prop);
}
else {
Base::Console().warning(
"Unknown Link property type in "
"Gui::TaskView::TaskSelectLinkProperty::TaskSelectLinkProperty()"
);
}
setFilter(sFilter);
}
TaskSelectLinkProperty::~TaskSelectLinkProperty()
{
delete ui;
Gui::Selection().Detach(this);
}
void TaskSelectLinkProperty::setupConnections()
{
// clang-format off
connect(ui->Remove, &QToolButton::clicked,
this, &TaskSelectLinkProperty::onRemoveClicked);
connect(ui->Add, &QToolButton::clicked,
this, &TaskSelectLinkProperty::onAddClicked);
connect(ui->Invert, &QToolButton::clicked,
this, &TaskSelectLinkProperty::onInvertClicked);
connect(ui->Help, &QToolButton::clicked,
this, &TaskSelectLinkProperty::onHelpClicked);
// clang-format on
}
void TaskSelectLinkProperty::changeEvent(QEvent* e)
{
TaskBox::changeEvent(e);
if (e->type() == QEvent::LanguageChange) {
ui->retranslateUi(proxy);
}
}
/// @cond DOXERR
bool TaskSelectLinkProperty::setFilter(const char* sFilter)
{
Filter = new SelectionFilter(sFilter);
return Filter->isValid();
}
void TaskSelectLinkProperty::activate()
{
// first clear the selection
Gui::Selection().clearSelection();
// set the gate for the filter
Gui::Selection().addSelectionGate(new SelectionFilterGate(Filter));
// In case of LinkSub property
if (LinkSub) {
// save the start values for a cnacel operation (reject())
StartValueBuffer = LinkSub->getSubValues();
StartObject = LinkSub->getValue();
if (StartObject) {
std::string ObjName = StartObject->getNameInDocument();
std::string DocName = StartObject->getDocument()->getName();
for (const auto& it : StartValueBuffer) {
Gui::Selection().addSelection(DocName.c_str(), ObjName.c_str(), it.c_str());
}
}
}
// In case of LinkList property
else if (LinkList) {
// save the start values for a cnacel operation (reject())
const std::vector<App::DocumentObject*>& Values = LinkList->getValues();
for (const auto& Value : Values) {
std::string ObjName = Value->getNameInDocument();
std::string DocName = Value->getDocument()->getName();
Gui::Selection().addSelection(DocName.c_str(), ObjName.c_str());
}
}
checkSelectionStatus();
}
bool TaskSelectLinkProperty::accept()
{
// set the property with the selection
sendSelection2Property();
// clear selection and remove gate (return to normal operation)
Gui::Selection().clearSelection();
Gui::Selection().rmvSelectionGate();
return true;
}
bool TaskSelectLinkProperty::reject()
{
if (LinkSub) {
// restore the old values
LinkSub->setValue(StartObject, StartValueBuffer);
}
// clear selection and remove gate (return to normal operation)
Gui::Selection().clearSelection();
Gui::Selection().rmvSelectionGate();
return true;
}
void TaskSelectLinkProperty::sendSelection2Property()
{
if (LinkSub) {
std::vector<Gui::SelectionObject> temp = Gui::Selection().getSelectionEx();
assert(temp.size() >= 1);
LinkSub->setValue(temp[0].getObject(), temp[0].getSubNames());
}
else if (LinkList) {
std::vector<Gui::SelectionObject> sel = Gui::Selection().getSelectionEx();
std::vector<App::DocumentObject*> temp;
for (auto& it : sel) {
temp.push_back(it.getObject());
}
LinkList->setValues(temp);
}
}
void TaskSelectLinkProperty::checkSelectionStatus()
{
QPalette palette(QApplication::palette());
if (Filter->match()) {
palette.setBrush(QPalette::Base, QColor(200, 250, 200));
Q_EMIT emitSelectionFit();
}
else {
palette.setBrush(QPalette::Base, QColor(250, 200, 200));
Q_EMIT emitSelectionMisfit();
}
// ui->listWidget->setAutoFillBackground(true);
ui->listWidget->setPalette(palette);
}
void TaskSelectLinkProperty::OnChange(
Gui::SelectionSingleton::SubjectType& rCaller,
Gui::SelectionSingleton::MessageType Reason
)
{
Q_UNUSED(rCaller);
if (Reason.Type == SelectionChanges::AddSelection || Reason.Type == SelectionChanges::RmvSelection
|| Reason.Type == SelectionChanges::SetSelection
|| Reason.Type == SelectionChanges::ClrSelection) {
ui->listWidget->clear();
std::vector<Gui::SelectionSingleton::SelObj> sel = Gui::Selection().getSelection();
for (const auto& it : sel) {
std::string temp;
temp += it.FeatName;
if (strcmp(it.SubName, "") != 0) {
temp += "::";
temp += it.SubName;
}
new QListWidgetItem(QString::fromLatin1(temp.c_str()), ui->listWidget);
}
checkSelectionStatus();
}
}
/// @endcond
void TaskSelectLinkProperty::onRemoveClicked(bool)
{}
void TaskSelectLinkProperty::onAddClicked(bool)
{}
void TaskSelectLinkProperty::onInvertClicked(bool)
{}
void TaskSelectLinkProperty::onHelpClicked(bool)
{}
#include "moc_TaskSelectLinkProperty.cpp"

View File

@@ -0,0 +1,122 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
/***************************************************************************
* Copyright (c) 2009 Jürgen Riegel <juergen.riegel@web.de> *
* *
* 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 *
* *
***************************************************************************/
#pragma once
#include "TaskView.h"
#include <Gui/Selection/Selection.h>
#include <App/PropertyLinks.h>
class Ui_TaskSelectLinkProperty;
namespace App
{
class Property;
}
namespace Gui
{
class ViewProvider;
namespace TaskView
{
/** General Link/Selection editor for the Task view
* This can be used as part of a TaskDialog to alter
* the content of a LinkProperty by user input/selection.
* If set active it reflects the selection to the Property
* given and acts due the selection filter given to the constructor.
* It will allow only allowed elements to be selected (SelectionFilter)
* and shows by the background color if the selection criterion is met.
* With the call of accept() or reject() the result gets permanent or
* discarded in the given Property.
*/
class GuiExport TaskSelectLinkProperty: public TaskBox, public Gui::SelectionSingleton::ObserverType
{
Q_OBJECT
public:
TaskSelectLinkProperty(const char*, App::Property*, QWidget* parent = nullptr);
~TaskSelectLinkProperty() override;
/// Observer message from the Selection
void OnChange(
Gui::SelectionSingleton::SubjectType& rCaller,
Gui::SelectionSingleton::MessageType Reason
) override;
/// set the filter criterion (same as in constructor)
bool setFilter(const char*);
/// set the TaskSelectLinkProperty active, means setting the selection and control it
void activate();
/// call this to accept the changes the user has made and send back to the Property (Ok)
bool accept();
/// This discards the changes of the user and leaves the Property untouched (Cancel)
bool reject();
/// send the selection to the Property for e.g. forced recomputation of a feature
void sendSelection2Property();
/// checks if the filter is currently met
inline bool isSelectionValid() const
{
return Filter->match();
}
private:
void setupConnections();
void onRemoveClicked(bool);
void onAddClicked(bool);
void onInvertClicked(bool);
void onHelpClicked(bool);
Q_SIGNALS:
void emitSelectionFit();
void emitSelectionMisfit();
protected:
void changeEvent(QEvent* e) override;
private:
// checks for selection and set background color and signals
void checkSelectionStatus();
QWidget* proxy;
Ui_TaskSelectLinkProperty* ui;
// selection filter for the session
Gui::SelectionFilter* Filter;
// possible used property types, only one is used
App::PropertyLinkSub* LinkSub;
App::PropertyLinkList* LinkList;
// string stores the Property at the beginning (for Cancel)
std::vector<std::string> StartValueBuffer;
App::DocumentObject* StartObject;
};
} // namespace TaskView
} // namespace Gui

View File

@@ -0,0 +1,69 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Gui::TaskView::TaskSelectLinkProperty</class>
<widget class="QWidget" name="Gui::TaskView::TaskSelectLinkProperty">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>257</width>
<height>313</height>
</rect>
</property>
<property name="windowTitle">
<string>Appearance</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QToolButton" name="Remove">
<property name="text">
<string notr="true">…</string>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="Add">
<property name="text">
<string notr="true">…</string>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="Invert">
<property name="text">
<string notr="true">…</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QToolButton" name="Help">
<property name="text">
<string notr="true">…</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QListWidget" name="listWidget"/>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View File

@@ -0,0 +1,149 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
/****************************************************************************
* *
* Copyright (c) 2011 Jürgen Riegel <juergen.riegel@web.de> *
* *
* This file is part of FreeCAD. *
* *
* FreeCAD is free software: you can redistribute it and/or modify it *
* under the terms of the GNU Lesser General Public License as *
* published by the Free Software Foundation, either version 2.1 of the *
* License, or (at your option) any later version. *
* *
* FreeCAD 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 *
* Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public *
* License along with FreeCAD. If not, see *
* <https://www.gnu.org/licenses/>. *
* *
***************************************************************************/
#include <QAction>
#include <QMenu>
#include <Gui/Application.h>
#include <Gui/BitmapFactory.h>
#include <Gui/Command.h>
#include <Gui/ViewProvider.h>
#include "TaskSolverMessages.h"
#include "ui_TaskSolverMessages.h"
using namespace Gui;
using namespace Gui::TaskView;
namespace sp = std::placeholders;
TaskSolverMessages::TaskSolverMessages(const QPixmap& icon, const QString& title)
: TaskBox(icon, title, true, nullptr)
, ui(new Ui_TaskSolverMessages)
{
// we need a separate container widget to add all controls to
auto* proxy = new QWidget(this);
ui->setupUi(proxy);
setupConnections();
this->groupLayout()->addWidget(proxy);
ui->labelStatus->setOpenExternalLinks(false);
// Set up the possible state values for the status label
ui->labelStatus->setParameterGroup("User parameter:BaseApp/Preferences/Mod/Sketcher/General");
ui->labelStatus->registerState(
QStringLiteral("empty"),
palette().windowText().color(),
std::string("EmptySketchMessageColor")
);
ui->labelStatus->registerState(
QStringLiteral("under_constrained"),
palette().windowText().color(),
std::string("UnderconstrainedMessageColor")
);
ui->labelStatus->registerState(
QStringLiteral("malformed_constraints"),
QColor("red"),
std::string("MalformedConstraintMessageColor")
);
ui->labelStatus->registerState(
QStringLiteral("conflicting_constraints"),
QColor("orangered"),
std::string("ConflictingConstraintMessageColor")
);
ui->labelStatus->registerState(
QStringLiteral("redundant_constraints"),
QColor("red"),
std::string("RedundantConstraintMessageColor")
);
ui->labelStatus->registerState(
QStringLiteral("partially_redundant_constraints"),
QColor("royalblue"),
std::string("PartiallyRedundantConstraintMessageColor")
);
ui->labelStatus->registerState(
QStringLiteral("solver_failed"),
QColor("red"),
std::string("SolverFailedMessageColor")
);
ui->labelStatus->registerState(
QStringLiteral("fully_constrained"),
QColor("green"),
std::string("FullyConstrainedMessageColor")
);
ui->labelStatusLink->setLaunchExternal(false);
createSettingsButtonActions();
}
TaskSolverMessages::~TaskSolverMessages() = default;
void TaskSolverMessages::setupConnections()
{
connect(
ui->labelStatusLink,
&Gui::UrlLabel::linkClicked,
this,
&TaskSolverMessages::onLabelStatusLinkClicked
);
connect(ui->manualUpdate, &QToolButton::clicked, this, &TaskSolverMessages::onManualUpdateClicked);
}
void TaskSolverMessages::slotSetUp(
const QString& state,
const QString& msg,
const QString& link,
const QString& linkText
)
{
ui->labelStatus->setState(state);
ui->labelStatus->setText(msg);
ui->labelStatusLink->setUrl(link);
ui->labelStatusLink->setText(linkText);
updateToolTip(link);
}
void TaskSolverMessages::setLinkTooltip(const QString& tooltip)
{
ui->labelStatusLink->setToolTip(tooltip);
}
QToolButton* TaskSolverMessages::getSettingsButton()
{
return ui->settingsButton;
}
void TaskSolverMessages::onManualUpdateClicked(bool checked)
{
Q_UNUSED(checked);
Gui::Command::updateActive();
}
void TaskSolverMessages::createSettingsButtonActions()
{
ui->settingsButton->hide();
}
#include "moc_TaskSolverMessages.cpp"

View File

@@ -0,0 +1,70 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
/****************************************************************************
* *
* Copyright (c) 2011 Jürgen Riegel <juergen.riegel@web.de> *
* *
* This file is part of FreeCAD. *
* *
* FreeCAD is free software: you can redistribute it and/or modify it *
* under the terms of the GNU Lesser General Public License as *
* published by the Free Software Foundation, either version 2.1 of the *
* License, or (at your option) any later version. *
* *
* FreeCAD 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 *
* Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public *
* License along with FreeCAD. If not, see *
* <https://www.gnu.org/licenses/>. *
* *
***************************************************************************/
#pragma once
#include <fastsignals/signal.h>
#include <Gui/TaskView/TaskView.h>
class Ui_TaskSolverMessages;
using Connection = fastsignals::connection;
namespace App
{
class Property;
}
namespace Gui
{
class GuiExport TaskSolverMessages: public Gui::TaskView::TaskBox
{
Q_OBJECT
public:
explicit TaskSolverMessages(const QPixmap& icon, const QString& title);
~TaskSolverMessages() override;
FC_DISABLE_COPY_MOVE(TaskSolverMessages)
void slotSetUp(const QString& state, const QString& msg, const QString& link, const QString& linkText);
private:
void setupConnections();
virtual void createSettingsButtonActions();
virtual void onLabelStatusLinkClicked(const QString&) = 0;
void onManualUpdateClicked(bool checked);
virtual void updateToolTip(const QString&) = 0;
protected:
void setLinkTooltip(const QString& tooltip);
QToolButton* getSettingsButton();
Connection connectionSetUp;
private:
std::unique_ptr<Ui_TaskSolverMessages> ui;
};
} // namespace Gui

View File

@@ -0,0 +1,102 @@
<?xml version="1.0" encoding="utf-8"?>
<ui version="4.0">
<class>TaskSolverMessages</class>
<widget class="QWidget" name="TaskSolverMessages">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>350</width>
<height>48</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>320</width>
<height>0</height>
</size>
</property>
<property name="windowTitle">
<string notr="true">Form</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="Gui::StatefulLabel" name="labelStatus">
<property name="text">
<string>DOF</string>
</property>
</widget>
</item>
<item>
<widget class="Gui::UrlLabel" name="labelStatusLink">
<property name="text">
<string>Link</string>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="manualUpdate">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="toolTip">
<string>Forces the recomputation of the active document</string>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset>
<normaloff>:/icons/view-refresh.svg</normaloff>:/icons/view-refresh.svg</iconset>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="settingsButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>Settings</string>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset>
<normaloff>:/icons/preferences-general.svg</normaloff>:/icons/preferences-general.svg</iconset>
</property>
<property name="popupMode">
<enum>QToolButton::MenuButtonPopup</enum>
</property>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>Gui::StatefulLabel</class>
<extends>QLabel</extends>
<header>Gui/Widgets.h</header>
</customwidget>
<customwidget>
<class>Gui::UrlLabel</class>
<extends>QLabel</extends>
<header>Gui/Widgets.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>

File diff suppressed because it is too large Load Diff

266
src/Gui/TaskView/TaskView.h Normal file
View File

@@ -0,0 +1,266 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
/***************************************************************************
* Copyright (c) 2009 Jürgen Riegel <juergen.riegel@web.de> *
* *
* 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 *
* *
***************************************************************************/
#pragma once
#include <vector>
#include <optional>
#include <QScrollArea>
#include <QStackedWidget>
#include <Base/Parameter.h>
#include <Gui/QSint/include/QSint>
#include <Gui/Selection/Selection.h>
#include "TaskWatcher.h"
namespace App
{
class Property;
}
namespace Gui
{
class MDIView;
class ControlSingleton;
class ViewProviderDocumentObject;
namespace DockWnd
{
class ComboView;
}
namespace TaskView
{
using Connection = fastsignals::connection;
class TaskEditControl;
class TaskDialog;
/// Father class of all content in TaskView
class GuiExport TaskContent {
public :
// TaskContent();
//~TaskContent();
};
class GuiExport TaskGroup: public QSint::ActionBox, public TaskContent
{
Q_OBJECT
public:
explicit TaskGroup(QWidget* parent = nullptr);
explicit TaskGroup(const QString& headerText, QWidget* parent = nullptr);
explicit TaskGroup(const QPixmap& icon, const QString& headerText, QWidget* parent = nullptr);
~TaskGroup() override;
protected:
void actionEvent(QActionEvent*) override;
};
/// Father class of content with header and Icon
class GuiExport TaskBox: public QSint::ActionGroup, public TaskContent
{
Q_OBJECT
public:
/** Constructor. Creates TaskBox without header.
*/
explicit TaskBox(QWidget* parent = nullptr);
/** Constructor. Creates TaskBox with header's
text set to \a title, but with no icon.
If \a expandable set to \a true (default), the group can be expanded/collapsed by the user.
*/
explicit TaskBox(const QString& title, bool expandable = true, QWidget* parent = nullptr);
/** Constructor. Creates TaskBox with header's
text set to \a title and icon set to \a icon.
If \a expandable set to \a true (default), the group can be expanded/collapsed by the user.
*/
explicit TaskBox(
const QPixmap& icon,
const QString& title,
bool expandable = true,
QWidget* parent = nullptr
);
QSize minimumSizeHint() const override;
~TaskBox() override;
void hideGroupBox();
bool isGroupVisible() const;
protected:
void showEvent(QShowEvent*) override;
void actionEvent(QActionEvent*) override;
private:
bool wasShown;
};
class GuiExport TaskPanel: public QWidget
{
Q_OBJECT
public:
explicit TaskPanel(QWidget* parent = nullptr);
~TaskPanel() override;
public:
QVBoxLayout* mainLayout;
QScrollArea* scrollArea;
QVBoxLayout* contextualPanelsLayout;
QVBoxLayout* dialogLayout;
QList<QWidget*> contextualPanels;
QSint::ActionPanel* actionPanel;
};
/// Father class of content of a Free widget (without header and Icon), shut be an exception!
class GuiExport TaskWidget: public QWidget, public TaskContent
{
Q_OBJECT
public:
explicit TaskWidget(QWidget* parent = nullptr);
~TaskWidget() override;
};
struct TaskInfo
{
TaskPanel* taskPanel {nullptr};
TaskDialog* ActiveDialog {nullptr};
TaskEditControl* ActiveCtrl {nullptr};
App::Document* Document {nullptr};
};
/** TaskView class
* handles the FreeCAD task view panel. Keeps track of the inserted content elements.
* This elements get injected mostly by the ViewProvider classes of the selected
* DocumentObjects.
*/
class GuiExport TaskView: public QStackedWidget, public Gui::SelectionSingleton::ObserverType
{
Q_OBJECT
public:
explicit TaskView(QWidget* parent = nullptr);
~TaskView() override;
/// Observer message from the Selection
void OnChange(
Gui::SelectionSingleton::SubjectType& rCaller,
Gui::SelectionSingleton::MessageType Reason
) override;
friend class Gui::DockWnd::ComboView;
friend class Gui::ControlSingleton;
/// sets the task watcher and shows it
void addTaskWatcher(const std::vector<TaskWatcher*>& Watcher);
void clearTaskWatcher();
void takeTaskWatcher(TaskView* other);
bool isEmpty(bool includeWatcher = true) const;
void clearActionStyle();
void restoreActionStyle();
/// Add a persistent panel at the top of the task view, independent of the active dialog.
void addContextualPanel(QWidget* panel, App::Document* doc);
void removeContextualPanel(QWidget* panel, App::Document* doc);
QSize minimumSizeHint() const override;
// Restore width before opening a task panel
void setRestoreWidth(bool on);
bool shouldRestoreWidth() const;
std::optional<TaskInfo> currentTaskInfo() const;
TaskDialog* dialog(App::Document* doc);
// Show the task info at the index
// or taskwatcher if index = -1
void setShownTaskInfo(int index);
Q_SIGNALS:
void taskUpdate();
protected:
void accept(App::Document* doc);
void reject(App::Document* doc);
void helpRequested(App::Document* doc);
void clicked(QAbstractButton* button, App::Document* doc);
private:
void triggerMinimumSizeHint();
void adjustMinimumSizeHint();
void saveCurrentWidth();
void tryRestoreWidth();
void slotActiveDocument(const App::Document&);
void slotInEdit(const Gui::ViewProviderDocumentObject&);
void slotDeletedDocument(const App::Document&);
void slotViewClosed(const Gui::MDIView*);
void slotUndoDocument(const App::Document&);
void slotRedoDocument(const App::Document&);
void transactionChangeOnDocument(const App::Document&, bool undo);
protected:
void keyPressEvent(QKeyEvent* event) override;
bool event(QEvent* event) override;
void addTaskWatcher();
void removeTaskWatcher();
/// update the visibility of the TaskWatcher accordant to the selection
void updateWatcher();
/// used by Gui::Control to register Dialogs, returns true if the dialog was not already there
bool showDialog(TaskDialog* dlg, App::Document* doc);
// removes the running dialog after accept() or reject() from the TaskView
void removeDialog(App::Document* doc);
void removeDialog(std::vector<TaskInfo>::iterator infoIt);
void setShowTaskWatcher(bool show);
std::vector<TaskWatcher*> ActiveWatcher;
TaskPanel* TaskWatcherPanel;
// First index of the stack is reserved to the active watcher
std::vector<TaskInfo> taskInfos;
bool restoreWidth = false;
int currentWidth = 0;
ParameterGrp::handle hGrp;
bool showTaskWatcher;
Connection connectApplicationActiveDocument;
Connection connectApplicationDeleteDocument;
Connection connectApplicationClosedView;
Connection connectApplicationUndoDocument;
Connection connectApplicationRedoDocument;
Connection connectApplicationInEdit;
Connection connectShowTaskWatcherSetting;
};
} // namespace TaskView
} // namespace Gui

View File

@@ -0,0 +1,183 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
/***************************************************************************
* Copyright (c) 2009 Jürgen Riegel <juergen.riegel@web.de> *
* *
* 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 <QObject>
#include <App/Application.h>
#include <App/Document.h>
#include <Gui/Application.h>
#include <Gui/BitmapFactory.h>
#include <Gui/Command.h>
#include <Gui/TaskView/TaskView.h>
#include "TaskWatcher.h"
using namespace Gui::TaskView;
//**************************************************************************
//**************************************************************************
// TaskWatcher
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
TaskWatcher::TaskWatcher(const char* Filter)
: QObject(nullptr)
, SelectionFilter(Filter)
{}
TaskWatcher::~TaskWatcher()
{
for (auto it : Content) {
delete it;
it = nullptr;
}
}
//==== implementer ===========================================================================
QWidget* TaskWatcher::addTaskBox(QWidget* widget, bool expandable, QWidget* parent)
{
return addTaskBox(QPixmap(), widget, expandable, parent);
}
QWidget* TaskWatcher::addTaskBox(const QPixmap& icon, QWidget* widget, bool expandable, QWidget* parent)
{
auto taskbox = new Gui::TaskView::TaskBox(icon, widget->windowTitle(), expandable, parent);
taskbox->groupLayout()->addWidget(widget);
Content.push_back(taskbox);
return taskbox;
}
QWidget* TaskWatcher::addTaskBoxWithoutHeader(QWidget* widget)
{
auto taskbox = new Gui::TaskView::TaskBox();
taskbox->groupLayout()->addWidget(widget);
Content.push_back(taskbox);
return taskbox;
}
std::vector<QWidget*>& TaskWatcher::getWatcherContent()
{
return Content;
}
//==== calls from the TaskView ===============================================================
bool TaskWatcher::shouldShow()
{
return false;
}
//**************************************************************************
//**************************************************************************
// TaskWatcherCommands
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
TaskWatcherCommands::TaskWatcherCommands(
const char* Filter,
const char* commands[],
const char* name,
const char* pixmap
)
: TaskWatcher(Filter)
{
if (commands) {
CommandManager& mgr = Gui::Application::Instance->commandManager();
auto tb = new Gui::TaskView::TaskBox(BitmapFactory().pixmap(pixmap), tr(name), true, nullptr);
for (const char** i = commands; *i; i++) {
Command* c = mgr.getCommandByName(*i);
if (c) {
// handled in TaskBox::actionEvent()
c->addTo(tb);
}
}
Content.push_back(tb);
}
}
//==== implementer ===========================================================================
//==== calls from the TaskView ===============================================================
bool TaskWatcherCommands::shouldShow()
{
return match();
}
//**************************************************************************
//**************************************************************************
// TaskWatcherCommandsEmptyDoc
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
TaskWatcherCommandsEmptyDoc::TaskWatcherCommandsEmptyDoc(
const char* commands[],
const char* name,
const char* pixmap
)
: TaskWatcherCommands(nullptr, commands, name, pixmap)
{}
//==== implementer ===========================================================================
//==== calls from the TaskView ===============================================================
bool TaskWatcherCommandsEmptyDoc::shouldShow()
{
App::Document* doc = App::GetApplication().getActiveDocument();
return doc && doc->countObjects() == 0;
}
//**************************************************************************
//**************************************************************************
// TaskWatcherCommandsEmptySelection
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
TaskWatcherCommandsEmptySelection::TaskWatcherCommandsEmptySelection(
const char* commands[],
const char* name,
const char* pixmap
)
: TaskWatcherCommands(nullptr, commands, name, pixmap)
{}
TaskWatcherCommandsEmptySelection::~TaskWatcherCommandsEmptySelection() = default;
//==== implementer ===========================================================================
//==== calls from the TaskView ===============================================================
bool TaskWatcherCommandsEmptySelection::shouldShow()
{
return (App::GetApplication().getActiveDocument() && Gui::Selection().size() == 0);
}
#include "moc_TaskWatcher.cpp"

View File

@@ -0,0 +1,117 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
/***************************************************************************
* Copyright (c) 2009 Jürgen Riegel <juergen.riegel@web.de> *
* *
* 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 *
* *
***************************************************************************/
#pragma once
#include <vector>
#include <QObject>
#include <Gui/Selection/SelectionFilter.h>
namespace Gui
{
namespace TaskView
{
class TaskContent;
/// Father class of watcher classes
class GuiExport TaskWatcher: public QObject, public Gui::SelectionFilter
{
Q_OBJECT
public:
explicit TaskWatcher(const char* Filter);
~TaskWatcher() override;
QWidget* addTaskBox(QWidget* widget, bool expandable = true, QWidget* parent = nullptr);
QWidget* addTaskBox(
const QPixmap& icon,
QWidget* widget,
bool expandable = true,
QWidget* parent = nullptr
);
QWidget* addTaskBoxWithoutHeader(QWidget* widget);
std::vector<QWidget*>& getWatcherContent();
public:
/// is called wenn the document or the Selection changes.
virtual bool shouldShow();
protected:
/// List of TaskBoxes of that dialog
std::vector<QWidget*> Content;
};
// --------------------------------------------------------------------------
/// Special watcher class for showing commands dependene on the selection
class GuiExport TaskWatcherCommands: public TaskWatcher
{
Q_OBJECT
public:
TaskWatcherCommands(const char* Filter, const char* commands[], const char* name, const char* pixmap);
public:
/// is called wenn the document or the Selection changes.
bool shouldShow() override;
};
// --------------------------------------------------------------------------
/// Special watcher class for showing commands when active document is empty
class GuiExport TaskWatcherCommandsEmptyDoc: public TaskWatcherCommands
{
Q_OBJECT
public:
TaskWatcherCommandsEmptyDoc(const char* commands[], const char* name, const char* pixmap);
public:
/// is called wenn the document or the Selection changes.
bool shouldShow() override;
};
// --------------------------------------------------------------------------
/// Special watcher class for showing commands when there is nothing selected
class GuiExport TaskWatcherCommandsEmptySelection: public TaskWatcherCommands
{
Q_OBJECT
public:
TaskWatcherCommandsEmptySelection(const char* commands[], const char* name, const char* pixmap);
~TaskWatcherCommandsEmptySelection() override;
public:
/// is called wenn the document or the Selection changes.
bool shouldShow() override;
};
} // namespace TaskView
} // namespace Gui