ToolWidget-Sketcher: Tool widget basic framework

================================================

Provides a framework to show in the taskbar a taskbox with a tool settings dialog.
This commit is contained in:
Paddle
2023-10-13 14:47:33 +02:00
committed by abdullahtahiriyo
parent a1b8a2ec70
commit c62f5f30fd
12 changed files with 1791 additions and 5 deletions

View File

@@ -30,6 +30,7 @@ generate_from_xml(ViewProviderSketchGeometryExtensionPy)
set(SketcherGui_UIC_SRCS
TaskSketcherConstraints.ui
TaskSketcherElements.ui
SketcherToolDefaultWidget.ui
TaskSketcherMessages.ui
TaskSketcherSolverAdvanced.ui
TaskSketcherValidation.ui
@@ -97,6 +98,11 @@ SET(SketcherGui_SRCS
TaskSketcherElements.h
TaskSketcherCreateCommands.cpp
TaskSketcherCreateCommands.h
SketcherToolDefaultWidget.ui
SketcherToolDefaultWidget.cpp
SketcherToolDefaultWidget.h
TaskSketcherTool.cpp
TaskSketcherTool.h
TaskSketcherMessages.ui
TaskSketcherMessages.cpp
TaskSketcherMessages.h

View File

@@ -148,6 +148,12 @@ inline void ViewProviderSketchDrawSketchHandlerAttorney::moveConstraint(ViewProv
vp.moveConstraint(constNum, toPos);
}
inline void
ViewProviderSketchDrawSketchHandlerAttorney::signalToolChanged(const ViewProviderSketch& vp,
const std::string& toolname)
{
vp.signalToolChanged(toolname);
}
/**************************** CurveConverter **********************************************/
@@ -270,6 +276,11 @@ DrawSketchHandler::DrawSketchHandler()
DrawSketchHandler::~DrawSketchHandler()
{}
std::string DrawSketchHandler::getToolName() const
{
return "DSH_None";
}
QString DrawSketchHandler::getCrosshairCursorSVGName() const
{
return QString::fromLatin1("None");
@@ -288,6 +299,8 @@ void DrawSketchHandler::activate(ViewProviderSketch* vp)
updateCursor();
this->signalToolChanged();
this->preActivated();
this->activated();
}
@@ -308,6 +321,8 @@ void DrawSketchHandler::deactivate()
resetPositionText();
unsetCursor();
setAngleSnapping(false);
ViewProviderSketchDrawSketchHandlerAttorney::signalToolChanged(*sketchgui, "DSH_None");
}
void DrawSketchHandler::preActivated()
@@ -325,6 +340,12 @@ void DrawSketchHandler::quit()
sketchgui->purgeHandler();
}
void DrawSketchHandler::toolWidgetChanged(QWidget* newwidget)
{
toolwidget = newwidget;
onWidgetChanged();
}
//**************************************************************************
// Helpers
@@ -1145,3 +1166,8 @@ void DrawSketchHandler::moveConstraint(int constNum, const Base::Vector2d& toPos
{
ViewProviderSketchDrawSketchHandlerAttorney::moveConstraint(*sketchgui, constNum, toPos);
}
void DrawSketchHandler::signalToolChanged() const
{
ViewProviderSketchDrawSketchHandlerAttorney::signalToolChanged(*sketchgui, this->getToolName());
}

View File

@@ -108,6 +108,8 @@ private:
static inline void
moveConstraint(ViewProviderSketch& vp, int constNum, const Base::Vector2d& toPos);
static inline void signalToolChanged(const ViewProviderSketch& vp, const std::string& toolname);
friend class DrawSketchHandler;
};
@@ -171,6 +173,8 @@ public:
void resetPositionText();
void renderSuggestConstraintsCursor(std::vector<AutoConstraint>& suggestedConstraints);
void toolWidgetChanged(QWidget* newwidget);
private: // NVI
virtual void preActivated();
virtual void activated()
@@ -179,8 +183,11 @@ private: // NVI
{}
virtual void postDeactivated()
{}
virtual void onWidgetChanged()
{}
protected: // NVI requiring base implementation
virtual std::string getToolName() const;
virtual QString getCrosshairCursorSVGName() const;
protected:
@@ -237,6 +244,8 @@ protected:
void moveConstraint(int constNum, const Base::Vector2d& toPos);
void signalToolChanged() const;
private:
void setSvgCursor(const QString& svgName,
int x,
@@ -262,6 +271,8 @@ protected:
QCursor oldCursor;
QCursor actCursor;
QPixmap actCursorPixmap;
QWidget* toolwidget;
};

View File

@@ -0,0 +1,834 @@
/***************************************************************************
* Copyright (c) 2022 Pierre-Louis Boyer <pierrelouis.boyer@gmail.com> *
* *
* This file is part of the FreeCAD CAx development system. *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Library General Public *
* License as published by the Free Software Foundation; either *
* version 2 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Library General Public License for more details. *
* *
* You should have received a copy of the GNU Library General Public *
* License along with this library; see the file COPYING.LIB. If not, *
* write to the Free Software Foundation, Inc., 59 Temple Place, *
* Suite 330, Boston, MA 02111-1307, USA *
* *
***************************************************************************/
#include "PreCompiled.h"
#ifndef _PreComp_
#include <Inventor/events/SoKeyboardEvent.h>
#endif
#include "ui_SketcherToolDefaultWidget.h"
#include <Gui/Application.h>
#include <Gui/Document.h>
#include <Gui/BitmapFactory.h>
#include <Gui/ViewProvider.h>
#include <Gui/WaitCursor.h>
#include <Gui/View3DInventor.h>
#include <Gui/View3DInventorViewer.h>
#include <Gui/PrefWidgets.h>
#include <Base/Tools.h>
#include <Base/UnitsApi.h>
#include <Base/Exception.h>
#include <QEvent>
#include "ViewProviderSketch.h"
#include "SketcherToolDefaultWidget.h"
using namespace SketcherGui;
using namespace Gui::TaskView;
SketcherToolDefaultWidget::KeyboardManager::KeyboardManager()
: keyMode(SketcherToolDefaultWidget::KeyboardManager::KeyboardEventHandlingMode::Widget)
{
// get the active viewer, so that we can send it key events
auto doc = Gui::Application::Instance->activeDocument();
if (doc) {
auto temp = dynamic_cast<Gui::View3DInventor*>(doc->getActiveView());
if (temp) {
vpViewer = temp->getViewer();
keyMode = KeyboardEventHandlingMode::ViewProvider;
}
}
timer.setSingleShot(true);
QObject::connect(&timer, &QTimer::timeout, [this]() {
onTimeOut();
});
}
bool SketcherToolDefaultWidget::KeyboardManager::isMode(
SketcherToolDefaultWidget::KeyboardManager::KeyboardEventHandlingMode mode)
{
return mode == keyMode;
}
SketcherToolDefaultWidget::KeyboardManager::KeyboardEventHandlingMode
SketcherToolDefaultWidget::KeyboardManager::getMode()
{
return keyMode;
}
bool SketcherToolDefaultWidget::KeyboardManager::handleKeyEvent(QKeyEvent* keyEvent)
{
detectKeyboardEventHandlingMode(keyEvent); // determine the handler
if (vpViewer && isMode(KeyboardEventHandlingMode::ViewProvider)) {
return QApplication::sendEvent(vpViewer, keyEvent);
}
else {
return false; // do not intercept the event and feed it to the widget
}
}
void SketcherToolDefaultWidget::KeyboardManager::detectKeyboardEventHandlingMode(
QKeyEvent* keyEvent)
{
Q_UNUSED(keyEvent);
if (keyEvent->key() == Qt::Key_Enter || keyEvent->key() == Qt::Key_Return
|| keyEvent->key() == Qt::Key_Tab || keyEvent->key() == Qt::Key_Backtab
|| keyEvent->key() == Qt::Key_Backspace || keyEvent->key() == Qt::Key_Delete
|| keyEvent->key() == Qt::Key_Minus || keyEvent->key() == Qt::Key_Period
|| keyEvent->key() == Qt::Key_Comma
|| QRegExp(QStringLiteral("[0-9]")).exactMatch(keyEvent->text())) {
keyMode = KeyboardEventHandlingMode::Widget;
timer.start(timeOut);
}
}
void SketcherToolDefaultWidget::KeyboardManager::onTimeOut()
{
keyMode = KeyboardEventHandlingMode::ViewProvider;
}
SketcherToolDefaultWidget::SketcherToolDefaultWidget(QWidget* parent,
ViewProviderSketch* sketchView)
: QWidget(parent)
, ui(new Ui_SketcherToolDefaultWidget)
, sketchView(sketchView)
, blockParameterSlots(false)
{
ui->setupUi(this);
// connecting the needed signals
connect(ui->parameterOne,
SIGNAL(valueChanged(double)),
this,
SLOT(parameterOne_valueChanged(double)));
connect(ui->parameterTwo,
SIGNAL(valueChanged(double)),
this,
SLOT(parameterTwo_valueChanged(double)));
connect(ui->parameterThree,
SIGNAL(valueChanged(double)),
this,
SLOT(parameterThree_valueChanged(double)));
connect(ui->parameterFour,
SIGNAL(valueChanged(double)),
this,
SLOT(parameterFour_valueChanged(double)));
connect(ui->parameterFive,
SIGNAL(valueChanged(double)),
this,
SLOT(parameterFive_valueChanged(double)));
connect(ui->parameterSix,
SIGNAL(valueChanged(double)),
this,
SLOT(parameterSix_valueChanged(double)));
connect(ui->parameterSeven,
SIGNAL(valueChanged(double)),
this,
SLOT(parameterSeven_valueChanged(double)));
connect(ui->parameterEight,
SIGNAL(valueChanged(double)),
this,
SLOT(parameterEight_valueChanged(double)));
connect(ui->parameterNine,
SIGNAL(valueChanged(double)),
this,
SLOT(parameterNine_valueChanged(double)));
connect(ui->parameterTen,
SIGNAL(valueChanged(double)),
this,
SLOT(parameterTen_valueChanged(double)));
connect(ui->checkBoxTS1, SIGNAL(toggled(bool)), this, SLOT(checkBoxTS1_toggled(bool)));
connect(ui->checkBoxTS2, SIGNAL(toggled(bool)), this, SLOT(checkBoxTS2_toggled(bool)));
connect(ui->checkBoxTS3, SIGNAL(toggled(bool)), this, SLOT(checkBoxTS3_toggled(bool)));
connect(ui->checkBoxTS4, SIGNAL(toggled(bool)), this, SLOT(checkBoxTS4_toggled(bool)));
connect(ui->comboBox1,
SIGNAL(currentIndexChanged(int)),
this,
SLOT(comboBox1_currentIndexChanged(int)));
connect(ui->comboBox2,
SIGNAL(currentIndexChanged(int)),
this,
SLOT(comboBox2_currentIndexChanged(int)));
connect(ui->comboBox3,
SIGNAL(currentIndexChanged(int)),
this,
SLOT(comboBox3_currentIndexChanged(int)));
ui->parameterOne->installEventFilter(this);
ui->parameterTwo->installEventFilter(this);
ui->parameterThree->installEventFilter(this);
ui->parameterFour->installEventFilter(this);
ui->parameterFive->installEventFilter(this);
ui->parameterSix->installEventFilter(this);
reset();
}
SketcherToolDefaultWidget::~SketcherToolDefaultWidget()
{}
// pre-select the number of the spinbox when it gets the focus.
bool SketcherToolDefaultWidget::eventFilter(QObject* object, QEvent* event)
{
if (event->type() == QEvent::FocusIn) {
for (int i = 0; i < nParameters; i++) {
auto parameterSpinBox = getParameterSpinBox(i);
if (object == parameterSpinBox) {
parameterSpinBox->selectNumber();
break;
}
}
}
else if (event->type() == QEvent::KeyPress || event->type() == QEvent::KeyRelease) {
/*If a key shortcut is required to work on sketcher when a tool using Tool Setting widget
is being used, then you have to add this key to the below section such that the spinbox
doesn't keep the keypress event for itself. Note if you want the event to be handled by
the spinbox too, you can return false.*/
QKeyEvent* keyEvent = static_cast<QKeyEvent*>(event);
return keymanager.handleKeyEvent(keyEvent);
}
return false;
}
void SketcherToolDefaultWidget::reset()
{
Base::StateLocker lock(blockParameterSlots, true);
std::fill(isSet.begin(), isSet.end(), false);
for (int i = 0; i < nParameters; i++) {
setParameterVisible(i, false);
setParameter(i, 0.f);
}
for (int i = 0; i < nCheckbox; i++) {
setCheckboxVisible(i, false);
setCheckboxChecked(i, false);
setCheckboxPrefEntry(i, "");
}
for (int i = 0; i < nCombobox; i++) {
setComboboxVisible(i, false);
setComboboxIndex(i, 0);
getComboBox(i)->clear();
}
setNoticeVisible(false);
}
void SketcherToolDefaultWidget::setNoticeText(const QString& string)
{
ui->notice->setText(string);
}
void SketcherToolDefaultWidget::setNoticeVisible(bool visible)
{
ui->notice->setVisible(visible);
}
// Spinboxes functions
void SketcherToolDefaultWidget::parameterOne_valueChanged(double val)
{
if (!blockParameterSlots) {
isSet[Parameter::First] = true;
setParameterFontStyle(Parameter::First, FontStyle::Bold);
setParameterFocus(Parameter::Second);
signalParameterValueChanged(Parameter::First, val);
}
}
void SketcherToolDefaultWidget::parameterTwo_valueChanged(double val)
{
if (!blockParameterSlots) {
isSet[Parameter::Second] = true;
setParameterFontStyle(Parameter::Second, FontStyle::Bold);
setParameterFocus(Parameter::Third);
signalParameterValueChanged(Parameter::Second, val);
}
}
void SketcherToolDefaultWidget::parameterThree_valueChanged(double val)
{
if (!blockParameterSlots) {
isSet[Parameter::Third] = true;
setParameterFontStyle(Parameter::Third, FontStyle::Bold);
setParameterFocus(Parameter::Fourth);
signalParameterValueChanged(Parameter::Third, val);
}
}
void SketcherToolDefaultWidget::parameterFour_valueChanged(double val)
{
if (!blockParameterSlots) {
isSet[Parameter::Fourth] = true;
setParameterFontStyle(Parameter::Fourth, FontStyle::Bold);
setParameterFocus(Parameter::Fifth);
signalParameterValueChanged(Parameter::Fourth, val);
}
}
void SketcherToolDefaultWidget::parameterFive_valueChanged(double val)
{
if (!blockParameterSlots) {
isSet[Parameter::Fifth] = true;
setParameterFontStyle(Parameter::Fifth, FontStyle::Bold);
setParameterFocus(Parameter::Sixth);
signalParameterValueChanged(Parameter::Fifth, val);
}
}
void SketcherToolDefaultWidget::parameterSix_valueChanged(double val)
{
if (!blockParameterSlots) {
isSet[Parameter::Sixth] = true;
setParameterFontStyle(Parameter::Sixth, FontStyle::Bold);
signalParameterValueChanged(Parameter::Sixth, val);
}
}
void SketcherToolDefaultWidget::parameterSeven_valueChanged(double val)
{
if (!blockParameterSlots) {
isSet[Parameter::Seventh] = true;
setParameterFontStyle(Parameter::Seventh, FontStyle::Bold);
signalParameterValueChanged(Parameter::Seventh, val);
}
}
void SketcherToolDefaultWidget::parameterEight_valueChanged(double val)
{
if (!blockParameterSlots) {
isSet[Parameter::Eighth] = true;
setParameterFontStyle(Parameter::Eighth, FontStyle::Bold);
signalParameterValueChanged(Parameter::Eighth, val);
}
}
void SketcherToolDefaultWidget::parameterNine_valueChanged(double val)
{
if (!blockParameterSlots) {
isSet[Parameter::Ninth] = true;
setParameterFontStyle(Parameter::Ninth, FontStyle::Bold);
signalParameterValueChanged(Parameter::Ninth, val);
}
}
void SketcherToolDefaultWidget::parameterTen_valueChanged(double val)
{
if (!blockParameterSlots) {
isSet[Parameter::Tenth] = true;
setParameterFontStyle(Parameter::Tenth, FontStyle::Bold);
signalParameterValueChanged(Parameter::Tenth, val);
}
}
void SketcherToolDefaultWidget::initNParameters(int nparameters)
{
Base::StateLocker lock(blockParameterSlots, true);
isSet.resize(nparameters);
std::fill(isSet.begin(), isSet.end(), false);
for (int i = 0; i < nParameters; i++) {
setParameterVisible(i, (i < nparameters) ? true : false);
setParameter(i, 0.f);
setParameterFontStyle(i, FontStyle::Italic);
}
setParameterFocus(Parameter::First);
}
void SketcherToolDefaultWidget::setParameterVisible(int parameterindex, bool visible)
{
if (parameterindex < nParameters) {
getParameterLabel(parameterindex)->setVisible(visible);
getParameterSpinBox(parameterindex)->setVisible(visible);
}
}
void SketcherToolDefaultWidget::setParameterLabel(int parameterindex, const QString& string)
{
if (parameterindex < nParameters) {
getParameterLabel(parameterindex)->setText(string);
}
}
void SketcherToolDefaultWidget::setParameter(int parameterindex, double val)
{
if (parameterindex < nParameters) {
getParameterSpinBox(parameterindex)->setValue(Base::Quantity(val, Base::Unit::Length));
return;
}
THROWM(Base::IndexError,
QT_TRANSLATE_NOOP("Exceptions", "ToolWidget parameter index out of range"));
}
void SketcherToolDefaultWidget::configureParameterInitialValue(int parameterindex, double val)
{
Base::StateLocker lock(blockParameterSlots, true);
setParameter(parameterindex, val);
}
void SketcherToolDefaultWidget::configureParameterUnit(int parameterindex, Base::Unit unit)
{
// For reference unit can be changed with :
// setUnit(Base::Unit::Length); Base::Unit::Angle
Base::StateLocker lock(blockParameterSlots, true);
if (parameterindex < nParameters) {
getParameterSpinBox(parameterindex)->setUnit(unit);
return;
}
THROWM(Base::IndexError,
QT_TRANSLATE_NOOP("Exceptions", "ToolWidget parameter index out of range"));
}
void SketcherToolDefaultWidget::setParameterEnabled(int parameterindex, bool active)
{
if (parameterindex < nParameters) {
getParameterSpinBox(parameterindex)->setEnabled(active);
return;
}
THROWM(Base::IndexError,
QT_TRANSLATE_NOOP("Exceptions", "ToolWidget parameter index out of range"));
}
void SketcherToolDefaultWidget::setParameterFocus(int parameterindex)
{
if (parameterindex < nParameters) {
auto parameterSpinBox = getParameterSpinBox(parameterindex);
parameterSpinBox->selectNumber();
QMetaObject::invokeMethod(parameterSpinBox, "setFocus", Qt::QueuedConnection);
return;
}
THROWM(Base::IndexError,
QT_TRANSLATE_NOOP("Exceptions", "ToolWidget parameter index out of range"));
}
void SketcherToolDefaultWidget::setParameterFontStyle(int parameterindex, FontStyle fontStyle)
{
if (parameterindex < nParameters) {
auto parameterSpinBox = getParameterSpinBox(parameterindex);
switch (fontStyle) {
case FontStyle::Italic:
parameterSpinBox->setStyleSheet(QStringLiteral("font-weight: normal;"));
parameterSpinBox->setStyleSheet(QStringLiteral("font-style: italic;"));
break;
case FontStyle::Bold:
parameterSpinBox->setStyleSheet(QStringLiteral("font-style: normal;"));
parameterSpinBox->setStyleSheet(QStringLiteral("font-weight: bold;"));
break;
case FontStyle::Normal:
parameterSpinBox->setStyleSheet(QStringLiteral("font-style: normal;"));
parameterSpinBox->setStyleSheet(QStringLiteral("font-weight: normal;"));
break;
}
return;
}
THROWM(Base::IndexError,
QT_TRANSLATE_NOOP("Exceptions", "ToolWidget parameter index out of range"));
}
QLabel* SketcherToolDefaultWidget::getParameterLabel(int parameterindex)
{
switch (parameterindex) {
case Parameter::First:
return ui->label;
break;
case Parameter::Second:
return ui->label2;
break;
case Parameter::Third:
return ui->label3;
break;
case Parameter::Fourth:
return ui->label4;
break;
case Parameter::Fifth:
return ui->label5;
break;
case Parameter::Sixth:
return ui->label6;
break;
case Parameter::Seventh:
return ui->label7;
break;
case Parameter::Eighth:
return ui->label8;
break;
case Parameter::Ninth:
return ui->label9;
break;
case Parameter::Tenth:
return ui->label10;
break;
default:
THROWM(Base::IndexError, "ToolWidget spinbox index out of range");
}
}
Gui::PrefQuantitySpinBox* SketcherToolDefaultWidget::getParameterSpinBox(int parameterindex)
{
switch (parameterindex) {
case Parameter::First:
return ui->parameterOne;
break;
case Parameter::Second:
return ui->parameterTwo;
break;
case Parameter::Third:
return ui->parameterThree;
break;
case Parameter::Fourth:
return ui->parameterFour;
break;
case Parameter::Fifth:
return ui->parameterFive;
break;
case Parameter::Sixth:
return ui->parameterSix;
break;
case Parameter::Seventh:
return ui->parameterSeven;
break;
case Parameter::Eighth:
return ui->parameterEight;
break;
case Parameter::Ninth:
return ui->parameterNine;
break;
case Parameter::Tenth:
return ui->parameterTen;
break;
default:
THROWM(Base::IndexError, "ToolWidget spinbox index out of range");
}
}
double SketcherToolDefaultWidget::getParameter(int parameterindex)
{
if (parameterindex < nParameters) {
return getParameterSpinBox(parameterindex)->value().getValue();
}
THROWM(Base::IndexError, "ToolWidget parameter index out of range");
}
bool SketcherToolDefaultWidget::isParameterSet(int parameterindex)
{
if (parameterindex < nParameters) {
return isSet[parameterindex];
}
THROWM(Base::IndexError, "ToolWidget parameter index out of range");
}
void SketcherToolDefaultWidget::updateVisualValue(int parameterindex, double val, Base::Unit unit)
{
if (parameterindex < nParameters) {
Base::StateLocker lock(blockParameterSlots, true);
auto parameterSpinBox = getParameterSpinBox(parameterindex);
parameterSpinBox->setValue(Base::Quantity(val, unit));
if (parameterSpinBox->hasFocus()) {
parameterSpinBox->selectNumber();
}
return;
}
THROWM(Base::IndexError,
QT_TRANSLATE_NOOP("Exceptions", "ToolWidget parameter index out of range"));
}
// checkbox functions
void SketcherToolDefaultWidget::checkBoxTS1_toggled(bool val)
{
if (!blockParameterSlots) {
if (!isCheckBoxPrefEntryEmpty(Checkbox::FirstBox)) {
ui->checkBoxTS1->onSave();
}
signalCheckboxCheckedChanged(Checkbox::FirstBox, val);
}
}
void SketcherToolDefaultWidget::checkBoxTS2_toggled(bool val)
{
if (!blockParameterSlots) {
if (!isCheckBoxPrefEntryEmpty(Checkbox::SecondBox)) {
ui->checkBoxTS2->onSave();
}
signalCheckboxCheckedChanged(Checkbox::SecondBox, val);
}
}
void SketcherToolDefaultWidget::checkBoxTS3_toggled(bool val)
{
if (!blockParameterSlots) {
if (!isCheckBoxPrefEntryEmpty(Checkbox::ThirdBox)) {
ui->checkBoxTS3->onSave();
}
signalCheckboxCheckedChanged(Checkbox::ThirdBox, val);
}
}
void SketcherToolDefaultWidget::checkBoxTS4_toggled(bool val)
{
if (!blockParameterSlots) {
if (!isCheckBoxPrefEntryEmpty(Checkbox::FourthBox)) {
ui->checkBoxTS4->onSave();
}
signalCheckboxCheckedChanged(Checkbox::FourthBox, val);
}
}
void SketcherToolDefaultWidget::initNCheckboxes(int ncheckbox)
{
Base::StateLocker lock(blockParameterSlots, true);
for (int i = 0; i < nCheckbox; i++) {
setCheckboxVisible(i, (i < ncheckbox) ? true : false);
setCheckboxChecked(i, false);
}
}
void SketcherToolDefaultWidget::setCheckboxVisible(int checkboxindex, bool visible)
{
if (checkboxindex < nCheckbox) {
getCheckBox(checkboxindex)->setVisible(visible);
}
}
void SketcherToolDefaultWidget::setCheckboxChecked(int checkboxindex, bool checked)
{
if (checkboxindex < nCheckbox) {
getCheckBox(checkboxindex)->setChecked(checked);
}
}
void SketcherToolDefaultWidget::setCheckboxLabel(int checkboxindex, const QString& string)
{
if (checkboxindex < nCheckbox) {
getCheckBox(checkboxindex)->setText(string);
}
}
void SketcherToolDefaultWidget::setCheckboxToolTip(int checkboxindex, const QString& string)
{
if (checkboxindex < nCheckbox) {
getCheckBox(checkboxindex)->setToolTip(string);
}
}
Gui::PrefCheckBox* SketcherToolDefaultWidget::getCheckBox(int checkboxindex)
{
switch (checkboxindex) {
case Checkbox::FirstBox:
return ui->checkBoxTS1;
break;
case Checkbox::SecondBox:
return ui->checkBoxTS2;
break;
case Checkbox::ThirdBox:
return ui->checkBoxTS3;
break;
case Checkbox::FourthBox:
return ui->checkBoxTS4;
break;
default:
THROWM(Base::IndexError, "ToolWidget checkbox index out of range");
}
}
bool SketcherToolDefaultWidget::getCheckboxChecked(int checkboxindex)
{
if (checkboxindex < nParameters) {
return getCheckBox(checkboxindex)->isChecked();
}
THROWM(Base::IndexError, "ToolWidget checkbox index out of range");
}
void SketcherToolDefaultWidget::setCheckboxPrefEntry(int checkboxindex,
const std::string& prefEntry)
{
if (checkboxindex < nCheckbox) {
QByteArray byteArray(prefEntry.c_str(), prefEntry.length());
getCheckBox(checkboxindex)->setEntryName(byteArray);
}
}
void SketcherToolDefaultWidget::restoreCheckBoxPref(int checkboxindex)
{
if (checkboxindex < nCheckbox) {
getCheckBox(checkboxindex)->onRestore();
}
}
void SketcherToolDefaultWidget::setComboboxPrefEntry(int comboboxindex,
const std::string& prefEntry)
{
if (comboboxindex < nCombobox) {
QByteArray byteArray(prefEntry.c_str(), prefEntry.length());
getComboBox(comboboxindex)->setEntryName(byteArray);
}
}
void SketcherToolDefaultWidget::restoreComboboxPref(int comboboxindex)
{
if (comboboxindex < nCombobox) {
getComboBox(comboboxindex)->onRestore();
}
}
bool SketcherToolDefaultWidget::isCheckBoxPrefEntryEmpty(int checkboxindex)
{
return getCheckBox(checkboxindex)->entryName().size() == 0;
}
// Combobox functions
void SketcherToolDefaultWidget::comboBox1_currentIndexChanged(int val)
{
if (!blockParameterSlots) {
signalComboboxSelectionChanged(Combobox::FirstCombo, val);
}
ui->comboBox1->onSave();
}
void SketcherToolDefaultWidget::comboBox2_currentIndexChanged(int val)
{
if (!blockParameterSlots) {
signalComboboxSelectionChanged(Combobox::SecondCombo, val);
}
ui->comboBox2->onSave();
}
void SketcherToolDefaultWidget::comboBox3_currentIndexChanged(int val)
{
if (!blockParameterSlots) {
signalComboboxSelectionChanged(Combobox::ThirdCombo, val);
}
ui->comboBox3->onSave();
}
void SketcherToolDefaultWidget::initNComboboxes(int ncombobox)
{
Base::StateLocker lock(blockParameterSlots, true);
for (int i = 0; i < nCombobox; i++) {
setComboboxVisible(i, (i < ncombobox) ? true : false);
}
}
void SketcherToolDefaultWidget::setComboboxVisible(int comboboxindex, bool visible)
{
if (comboboxindex < nCombobox) {
getComboBox(comboboxindex)->setVisible(visible);
getComboBoxLabel(comboboxindex)->setVisible(visible);
}
}
void SketcherToolDefaultWidget::setComboboxIndex(int comboboxindex, int value)
{
if (comboboxindex < nCombobox) {
getComboBox(comboboxindex)->setCurrentIndex(value);
}
}
void SketcherToolDefaultWidget::setComboboxLabel(int comboboxindex, const QString& string)
{
if (comboboxindex < nCombobox) {
getComboBoxLabel(comboboxindex)->setText(string);
}
}
void SketcherToolDefaultWidget::setComboboxElements(int comboboxindex, const QStringList& names)
{
if (comboboxindex < nCombobox) {
getComboBox(comboboxindex)->clear();
getComboBox(comboboxindex)->addItems(names);
}
}
Gui::PrefComboBox* SketcherToolDefaultWidget::getComboBox(int comboboxindex)
{
switch (comboboxindex) {
case Combobox::FirstCombo:
return ui->comboBox1;
break;
case Combobox::SecondCombo:
return ui->comboBox2;
break;
case Combobox::ThirdCombo:
return ui->comboBox3;
break;
default:
THROWM(Base::IndexError, "ToolWidget combobox index out of range");
}
}
QLabel* SketcherToolDefaultWidget::getComboBoxLabel(int comboboxindex)
{
switch (comboboxindex) {
case Combobox::FirstCombo:
return ui->comboLabel1;
break;
case Combobox::SecondCombo:
return ui->comboLabel2;
break;
case Combobox::ThirdCombo:
return ui->comboLabel3;
break;
default:
THROWM(Base::IndexError, "ToolWidget combobox index out of range");
}
}
int SketcherToolDefaultWidget::getComboboxIndex(int comboboxindex)
{
if (comboboxindex < nCombobox) {
return getComboBox(comboboxindex)->currentIndex();
}
THROWM(Base::IndexError, "ToolWidget combobox index out of range");
}
void SketcherToolDefaultWidget::changeEvent(QEvent* e)
{
QWidget::changeEvent(e);
if (e->type() == QEvent::LanguageChange) {
ui->retranslateUi(this);
}
}
#include "moc_SketcherToolDefaultWidget.cpp"

View File

@@ -0,0 +1,258 @@
/***************************************************************************
* Copyright (c) 2022 Pierre-Louis Boyer <pierrelouis.boyer@gmail.com> *
* *
* This file is part of the FreeCAD CAx development system. *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Library General Public *
* License as published by the Free Software Foundation; either *
* version 2 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Library General Public License for more details. *
* *
* You should have received a copy of the GNU Library General Public *
* License along with this library; see the file COPYING.LIB. If not, *
* write to the Free Software Foundation, Inc., 59 Temple Place, *
* Suite 330, Boston, MA 02111-1307, USA *
* *
***************************************************************************/
#ifndef SketcherGui_SketcherToolDefaultWidget_H
#define SketcherGui_SketcherToolDefaultWidget_H
#include <Gui/TaskView/TaskView.h>
#include <Gui/TaskView/TaskDialog.h>
#include <Gui/Selection.h>
#include <boost_signals2.hpp>
class QComboBox;
namespace App
{
class Property;
}
namespace Gui
{
class ViewProvider;
class PrefQuantitySpinBox;
class PrefCheckBox;
class View3DInventorViewer;
class PrefComboBox;
} // namespace Gui
namespace SketcherGui
{
class Ui_SketcherToolDefaultWidget;
class ViewProviderSketch;
class SketcherToolDefaultWidget: public QWidget
{
Q_OBJECT
enum class FontStyle
{
Normal,
Bold,
Italic,
};
/** Class to decide which control is responsible of handling an key event
*using timers, type of entered event, ...
*/
class KeyboardManager
{
public:
KeyboardManager();
/// Indicates whether the widget should handle keyboard input or should signal it via boost
enum class KeyboardEventHandlingMode
{
Widget,
ViewProvider
};
bool isMode(KeyboardEventHandlingMode mode);
KeyboardEventHandlingMode getMode();
bool handleKeyEvent(QKeyEvent* keyEvent);
private:
/// This function decides whether events should be send to the ViewProvider
/// or to the UI control of the Default widget.
void detectKeyboardEventHandlingMode(QKeyEvent* keyEvent);
void onTimeOut();
private:
/// Viewer responsible for the active document
Gui::View3DInventorViewer* vpViewer = nullptr;
KeyboardEventHandlingMode keyMode;
QTimer timer;
const int timeOut = 1000;
};
public:
/// Parameter spinbox number/label
enum Parameter
{
First,
Second,
Third,
Fourth,
Fifth,
Sixth,
Seventh,
Eighth,
Ninth,
Tenth,
nParameters // Must Always be the last one
};
/// Checkbox number/label
enum Checkbox
{
FirstBox,
SecondBox,
ThirdBox,
FourthBox,
nCheckbox // Must Always be the last one
};
/// Combobox number/label
enum Combobox
{
FirstCombo,
SecondCombo,
ThirdCombo,
nCombobox // Must Always be the last one
};
SketcherToolDefaultWidget(QWidget* parent = nullptr, ViewProviderSketch* sketchView = nullptr);
~SketcherToolDefaultWidget();
bool eventFilter(QObject* object, QEvent* event);
// void keyPressEvent(QKeyEvent* event);
void setParameter(int parameterindex, double val);
void configureParameterInitialValue(int parameterindex, double value);
void configureParameterUnit(int parameterindex, Base::Unit unit);
double getParameter(int parameterindex);
bool isParameterSet(int parameterindex);
void updateVisualValue(int parameterindex, double val, Base::Unit unit = Base::Unit::Length);
void setParameterEnabled(int parameterindex, bool active = true);
void setParameterFocus(int parameterindex);
void setParameterVisible(int parameterindex, bool visible = true);
void reset();
void initNParameters(int nparameters);
void setParameterLabel(int parameterindex, const QString& string);
void setNoticeText(const QString& string);
void setNoticeVisible(bool visible);
void initNCheckboxes(int ncheckbox);
void setCheckboxVisible(int checkboxindex, bool visible);
void setCheckboxChecked(int checkboxindex, bool checked);
void setCheckboxLabel(int checkboxindex, const QString& string);
void setCheckboxToolTip(int checkboxindex, const QString& string);
bool getCheckboxChecked(int checkboxindex);
void setCheckboxPrefEntry(int checkboxindex, const std::string& prefEntry);
void restoreCheckBoxPref(int checkboxindex);
void initNComboboxes(int ncombobox);
void setComboboxVisible(int comboboxindex, bool visible);
void setComboboxIndex(int comboboxindex, int value);
void setComboboxLabel(int comboboxindex, const QString& string);
int getComboboxIndex(int comboboxindex);
void setComboboxElements(int comboboxindex, const QStringList& names);
void setComboboxPrefEntry(int comboboxindex, const std::string& prefEntry);
void restoreComboboxPref(int comboboxindex);
template<typename F>
boost::signals2::connection registerParameterValueChanged(F&& f)
{
return signalParameterValueChanged.connect(std::forward<F>(f));
}
template<typename F>
boost::signals2::connection registerCheckboxCheckedChanged(F&& f)
{
return signalCheckboxCheckedChanged.connect(std::forward<F>(f));
}
template<typename F>
boost::signals2::connection registerComboboxSelectionChanged(F&& f)
{
return signalComboboxSelectionChanged.connect(std::forward<F>(f));
}
// Q_SIGNALS:
protected Q_SLOTS:
void parameterOne_valueChanged(double val);
void parameterTwo_valueChanged(double val);
void parameterThree_valueChanged(double val);
void parameterFour_valueChanged(double val);
void parameterFive_valueChanged(double val);
void parameterSix_valueChanged(double val);
void parameterSeven_valueChanged(double val);
void parameterEight_valueChanged(double val);
void parameterNine_valueChanged(double val);
void parameterTen_valueChanged(double val);
void checkBoxTS1_toggled(bool val);
void checkBoxTS2_toggled(bool val);
void checkBoxTS3_toggled(bool val);
void checkBoxTS4_toggled(bool val);
void comboBox1_currentIndexChanged(int val);
void comboBox2_currentIndexChanged(int val);
void comboBox3_currentIndexChanged(int val);
protected:
void changeEvent(QEvent* e);
private:
QLabel* getParameterLabel(int parameterindex);
Gui::PrefQuantitySpinBox* getParameterSpinBox(int parameterindex);
Gui::PrefCheckBox* getCheckBox(int checkboxindex);
Gui::PrefComboBox* getComboBox(int comboboxindex);
QLabel* getComboBoxLabel(int comboboxindex);
void setParameterFontStyle(int parameterindex, FontStyle fontStyle);
bool isCheckBoxPrefEntryEmpty(int checkboxindex);
private:
std::unique_ptr<Ui_SketcherToolDefaultWidget> ui;
ViewProviderSketch* sketchView;
boost::signals2::signal<void(int parameterindex, double value)> signalParameterValueChanged;
boost::signals2::signal<void(int checkboxindex, bool value)> signalCheckboxCheckedChanged;
boost::signals2::signal<void(int comboindex, int value)> signalComboboxSelectionChanged;
/// lock to block QT slots
bool blockParameterSlots;
/// vector using parameter as index indicating whether the value of a parameter was set by the
/// widget
std::vector<bool> isSet;
KeyboardManager keymanager;
};
} // namespace SketcherGui
#endif // SketcherGui_SketcherToolDefaultWidget_H

View File

@@ -0,0 +1,421 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>SketcherGui::SketcherToolDefaultWidget</class>
<widget class="QWidget" name="SketcherGui::SketcherToolDefaultWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>312</width>
<height>254</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="comboLayout1">
<item>
<widget class="QLabel" name="comboLabel1">
<property name="text">
<string>Mode (M)</string>
</property>
</widget>
</item>
<item>
<widget class="Gui::PrefComboBox" name="comboBox1">
<property name="currentIndex">
<number>0</number>
</property>
<property name="prefEntry">
<cstring></cstring>
</property>
<property name="prefPath">
<cstring>Mod/Sketcher/General</cstring>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="comboLayout2">
<item>
<widget class="QLabel" name="comboLabel2">
<property name="text">
<string>Mode</string>
</property>
</widget>
</item>
<item>
<widget class="Gui::PrefComboBox" name="comboBox2">
<property name="currentIndex">
<number>0</number>
</property>
<property name="prefEntry">
<cstring></cstring>
</property>
<property name="prefPath">
<cstring>Mod/Sketcher/General</cstring>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="comboLayout3">
<item>
<widget class="QLabel" name="comboLabel3">
<property name="text">
<string>Mode</string>
</property>
</widget>
</item>
<item>
<widget class="Gui::PrefComboBox" name="comboBox3">
<property name="currentIndex">
<number>0</number>
</property>
<property name="prefEntry">
<cstring></cstring>
</property>
<property name="prefPath">
<cstring>Mod/Sketcher/General</cstring>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Parameter 1</string>
</property>
</widget>
</item>
<item>
<widget class="Gui::PrefQuantitySpinBox" name="parameterOne">
<property name="unit" stdset="0">
<string notr="true">mm</string>
</property>
<property name="keyboardTracking">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout2">
<item>
<widget class="QLabel" name="label2">
<property name="text">
<string>Parameter 2</string>
</property>
</widget>
</item>
<item>
<widget class="Gui::PrefQuantitySpinBox" name="parameterTwo">
<property name="unit" stdset="0">
<string notr="true">mm</string>
</property>
<property name="keyboardTracking">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout3">
<item>
<widget class="QLabel" name="label3">
<property name="text">
<string>Parameter 3</string>
</property>
</widget>
</item>
<item>
<widget class="Gui::PrefQuantitySpinBox" name="parameterThree">
<property name="unit" stdset="0">
<string notr="true">mm</string>
</property>
<property name="keyboardTracking">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout4">
<item>
<widget class="QLabel" name="label4">
<property name="text">
<string>Parameter 4</string>
</property>
</widget>
</item>
<item>
<widget class="Gui::PrefQuantitySpinBox" name="parameterFour">
<property name="unit" stdset="0">
<string notr="true">mm</string>
</property>
<property name="keyboardTracking">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout5">
<item>
<widget class="QLabel" name="label5">
<property name="text">
<string>Parameter 5</string>
</property>
</widget>
</item>
<item>
<widget class="Gui::PrefQuantitySpinBox" name="parameterFive">
<property name="unit" stdset="0">
<string notr="true">mm</string>
</property>
<property name="keyboardTracking">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout6">
<item>
<widget class="QLabel" name="label6">
<property name="text">
<string>Parameter 6</string>
</property>
</widget>
</item>
<item>
<widget class="Gui::PrefQuantitySpinBox" name="parameterSix">
<property name="unit" stdset="0">
<string notr="true">mm</string>
</property>
<property name="keyboardTracking">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout7">
<item>
<widget class="QLabel" name="label7">
<property name="text">
<string>Parameter 7</string>
</property>
</widget>
</item>
<item>
<widget class="Gui::PrefQuantitySpinBox" name="parameterSeven">
<property name="unit" stdset="0">
<string notr="true">mm</string>
</property>
<property name="keyboardTracking">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout8">
<item>
<widget class="QLabel" name="label8">
<property name="text">
<string>Parameter 8</string>
</property>
</widget>
</item>
<item>
<widget class="Gui::PrefQuantitySpinBox" name="parameterEight">
<property name="unit" stdset="0">
<string notr="true">mm</string>
</property>
<property name="keyboardTracking">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout9">
<item>
<widget class="QLabel" name="label9">
<property name="text">
<string>Parameter 9</string>
</property>
</widget>
</item>
<item>
<widget class="Gui::PrefQuantitySpinBox" name="parameterNine">
<property name="unit" stdset="0">
<string notr="true">mm</string>
</property>
<property name="keyboardTracking">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout10">
<item>
<widget class="QLabel" name="label10">
<property name="text">
<string>Parameter 10</string>
</property>
</widget>
</item>
<item>
<widget class="Gui::PrefQuantitySpinBox" name="parameterTen">
<property name="unit" stdset="0">
<string notr="true">mm</string>
</property>
<property name="keyboardTracking">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="Gui::PrefCheckBox" name="checkBoxTS1">
<property name="enabled">
<bool>true</bool>
</property>
<property name="toolTip">
<string>Checkbox 1 toolTip</string>
</property>
<property name="text">
<string>Checkbox 1</string>
</property>
<property name="checked">
<bool>false</bool>
</property>
<property name="prefEntry">
<cstring></cstring>
</property>
<property name="prefPath">
<cstring>Mod/Sketcher/General</cstring>
</property>
</widget>
</item>
<item>
<widget class="Gui::PrefCheckBox" name="checkBoxTS2">
<property name="enabled">
<bool>true</bool>
</property>
<property name="toolTip">
<string>Checkbox 2 toolTip</string>
</property>
<property name="text">
<string>Checkbox 2</string>
</property>
<property name="checked">
<bool>false</bool>
</property>
<property name="prefEntry">
<cstring></cstring>
</property>
<property name="prefPath">
<cstring>Mod/Sketcher/General</cstring>
</property>
</widget>
</item>
<item>
<widget class="Gui::PrefCheckBox" name="checkBoxTS3">
<property name="enabled">
<bool>true</bool>
</property>
<property name="toolTip">
<string>Checkbox 3 toolTip</string>
</property>
<property name="text">
<string>Checkbox 3</string>
</property>
<property name="checked">
<bool>false</bool>
</property>
<property name="prefEntry">
<cstring></cstring>
</property>
<property name="prefPath">
<cstring>Mod/Sketcher/General</cstring>
</property>
</widget>
</item>
<item>
<widget class="Gui::PrefCheckBox" name="checkBoxTS4">
<property name="enabled">
<bool>true</bool>
</property>
<property name="toolTip">
<string>Checkbox 4 toolTip</string>
</property>
<property name="text">
<string>Checkbox 4</string>
</property>
<property name="checked">
<bool>false</bool>
</property>
<property name="prefEntry">
<cstring></cstring>
</property>
<property name="prefPath">
<cstring>Mod/Sketcher/General</cstring>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="notice">
<property name="maximumSize">
<size>
<width>400</width>
<height>500</height>
</size>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>Gui::PrefQuantitySpinBox</class>
<extends>QWidget</extends>
<header>Gui/PrefWidgets.h</header>
</customwidget>
<customwidget>
<class>Gui::PrefCheckBox</class>
<extends>QWidget</extends>
<header>Gui/PrefWidgets.h</header>
</customwidget>
<customwidget>
<class>Gui::PrefComboBox</class>
<extends>QWidget</extends>
<header>Gui/PrefWidgets.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>

View File

@@ -30,6 +30,8 @@
using namespace SketcherGui;
namespace sp = std::placeholders;
//**************************************************************************
//**************************************************************************
// TaskDialog
@@ -40,6 +42,7 @@ TaskDlgEditSketch::TaskDlgEditSketch(ViewProviderSketch* sketchView)
, sketchView(sketchView)
{
assert(sketchView);
ToolSettings = new TaskSketcherTool(sketchView);
Constraints = new TaskSketcherConstraints(sketchView);
Elements = new TaskSketcherElements(sketchView);
Messages = new TaskSketcherMessages(sketchView);
@@ -49,6 +52,7 @@ TaskDlgEditSketch::TaskDlgEditSketch(ViewProviderSketch* sketchView)
"User parameter:BaseApp/Preferences/Mod/Sketcher");
setEscapeButtonEnabled(hGrp->GetBool("LeaveSketchWithEscape", true));
Content.push_back(ToolSettings);
Content.push_back(Messages);
if (hGrp->GetBool("ShowSolverAdvancedWidget", false)) {
@@ -70,6 +74,11 @@ TaskDlgEditSketch::TaskDlgEditSketch(ViewProviderSketch* sketchView)
if (!hGrp->GetBool("ExpandedElementsWidget", true)) {
Elements->hideGroupBox();
}
connectionToolSettings = sketchView->registerToolChanged(
std::bind(&SketcherGui::TaskDlgEditSketch::slotToolChanged, this, sp::_1));
ToolSettings->setHidden(true);
}
TaskDlgEditSketch::~TaskDlgEditSketch()
@@ -80,6 +89,18 @@ TaskDlgEditSketch::~TaskDlgEditSketch()
if (it == Content.end()) {
Content.push_back(SolverAdvanced);
}
connectionToolSettings.disconnect();
}
void TaskDlgEditSketch::slotToolChanged(const std::string& toolname)
{
bool hidden = toolname == "DSH_None" || toolname == "DSH_Point";
ToolSettings->setHidden(hidden);
if (toolname != "DSH_None") {
ToolSettings->toolChanged(toolname);
}
}
//==== calls from the TaskView ===============================================================

View File

@@ -31,6 +31,7 @@
#include "TaskSketcherElements.h"
#include "TaskSketcherMessages.h"
#include "TaskSketcherSolverAdvanced.h"
#include "TaskSketcherTool.h"
#include "ViewProviderSketch.h"
@@ -73,16 +74,29 @@ public:
return QDialogButtonBox::Close;
}
template<typename F>
boost::signals2::connection registerToolWidgetChanged(F&& f)
{
return ToolSettings->registerToolWidgetChanged(std::forward<F>(f));
}
protected:
void slotUndoDocument(const App::Document&);
void slotRedoDocument(const App::Document&);
private:
void slotToolChanged(const std::string& toolname);
protected:
ViewProviderSketch* sketchView;
TaskSketcherConstraints* Constraints;
TaskSketcherElements* Elements;
TaskSketcherMessages* Messages;
TaskSketcherSolverAdvanced* SolverAdvanced;
TaskSketcherTool* ToolSettings;
private:
Connection connectionToolSettings;
};

View File

@@ -0,0 +1,86 @@
/***************************************************************************
* Copyright (c) 2022 Pierre-Louis Boyer <pierrelouis.boyer@gmail.com> *
* *
* This file is part of the FreeCAD CAx development system. *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Library General Public *
* License as published by the Free Software Foundation; either *
* version 2 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Library General Public License for more details. *
* *
* You should have received a copy of the GNU Library General Public *
* License along with this library; see the file COPYING.LIB. If not, *
* write to the Free Software Foundation, Inc., 59 Temple Place, *
* Suite 330, Boston, MA 02111-1307, USA *
* *
***************************************************************************/
#include "PreCompiled.h"
#ifndef _PreComp_
#endif
#include "TaskSketcherTool.h"
#include <Gui/Application.h>
#include <Gui/Document.h>
#include <Gui/BitmapFactory.h>
#include <Gui/ViewProvider.h>
#include <Gui/WaitCursor.h>
#include <Base/Tools.h>
#include <Base/UnitsApi.h>
#include <QEvent>
#include "ViewProviderSketch.h"
#include "SketcherToolDefaultWidget.h"
using namespace SketcherGui;
using namespace Gui::TaskView;
TaskSketcherTool::TaskSketcherTool(ViewProviderSketch* sketchView)
: TaskBox(Gui::BitmapFactory().pixmap("document-new"), tr("Tool parameters"), true, nullptr)
, sketchView(sketchView)
{
widget = std::make_unique<SketcherToolDefaultWidget>(this, sketchView);
this->groupLayout()->addWidget(widget.get());
}
TaskSketcherTool::~TaskSketcherTool()
{}
void TaskSketcherTool::toolChanged(const std::string& toolname)
{
// TODO: Implement a factory here to get an appropriate widget from the toolname
// At this stage, we add a Default tool widget for all tools with a defined name, but this needs
// to change
if (toolname != "DSH_None") {
widget = std::make_unique<SketcherToolDefaultWidget>(this, sketchView);
this->groupLayout()->addWidget(widget.get());
if (toolname == "DSH_Line") {
setHeaderText(tr("Line parameters"));
setHeaderIcon(Gui::BitmapFactory().pixmap("Sketcher_CreateLine"));
}
else if (toolname == "DSH_Circle") {
setHeaderText(tr("Circle parameters"));
setHeaderIcon(Gui::BitmapFactory().pixmap("Sketcher_CreateCircle"));
}
signalToolWidgetChanged(this->widget.get());
}
else {
signalToolWidgetChanged(nullptr);
}
}
#include "moc_TaskSketcherTool.cpp"

View File

@@ -0,0 +1,79 @@
/***************************************************************************
* Copyright (c) 2022 Pierre-Louis Boyer <pierrelouis.boyer@gmail.com> *
* *
* This file is part of the FreeCAD CAx development system. *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Library General Public *
* License as published by the Free Software Foundation; either *
* version 2 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Library General Public License for more details. *
* *
* You should have received a copy of the GNU Library General Public *
* License along with this library; see the file COPYING.LIB. If not, *
* write to the Free Software Foundation, Inc., 59 Temple Place, *
* Suite 330, Boston, MA 02111-1307, USA *
* *
***************************************************************************/
#ifndef GUI_TASKVIEW_TaskSketcherTool_H
#define GUI_TASKVIEW_TaskSketcherTool_H
#include <Gui/TaskView/TaskView.h>
#include <Gui/TaskView/TaskDialog.h>
#include <Gui/Selection.h>
#include <boost_signals2.hpp>
namespace App
{
class Property;
}
namespace Gui
{
class ViewProvider;
}
namespace SketcherGui
{
class ViewProviderSketch;
class TaskSketcherTool: public Gui::TaskView::TaskBox
{
Q_OBJECT
public:
TaskSketcherTool(ViewProviderSketch* sketchView);
~TaskSketcherTool();
QWidget* getWidget()
{
return widget.get();
}
void toolChanged(const std::string& toolname);
template<typename F>
boost::signals2::connection registerToolWidgetChanged(F&& f)
{
return signalToolWidgetChanged.connect(std::forward<F>(f));
}
private:
ViewProviderSketch* sketchView;
std::unique_ptr<QWidget> widget;
boost::signals2::scoped_connection changedSketchView;
boost::signals2::signal<void(QWidget* newwidget)> signalToolWidgetChanged;
};
} // namespace SketcherGui
#endif // GUI_TASKVIEW_TaskSketcherTool_H

View File

@@ -495,7 +495,9 @@ ViewProviderSketch::ViewProviderSketch()
}
ViewProviderSketch::~ViewProviderSketch()
{}
{
connectionToolWidget.disconnect();
}
void ViewProviderSketch::slotUndoDocument(const Gui::Document& /*doc*/)
{
@@ -3242,10 +3244,12 @@ bool ViewProviderSketch::setEdit(int ModNum)
}
// start the edit dialog
if (sketchDlg)
Gui::Control().showDialog(sketchDlg);
else
Gui::Control().showDialog(new TaskDlgEditSketch(this));
if (!sketchDlg)
sketchDlg = new TaskDlgEditSketch(this);
connectionToolWidget = sketchDlg->registerToolWidgetChanged(std::bind(&SketcherGui::ViewProviderSketch::slotToolWidgetChanged, this, sp::_1));
Gui::Control().showDialog(sketchDlg);
// This call to the solver is needed to initialize the DoF and solve time controls
// The false parameter indicates that the geometry of the SketchObject shall not be updateData
@@ -3879,6 +3883,12 @@ QIcon ViewProviderSketch::mergeColorfulOverlayIcons(const QIcon& orig) const
return Gui::ViewProvider::mergeColorfulOverlayIcons(mergedicon);
}
void ViewProviderSketch::slotToolWidgetChanged(QWidget* newwidget)
{
if (sketchHandler)
sketchHandler->toolWidgetChanged(newwidget);
}
/*************************** functions ViewProviderSketch offers to friends such as
* DrawHandlerSketch ************************/

View File

@@ -653,6 +653,15 @@ public:
boost::signals2::signal<void()> signalElementsChanged;
//@}
/** @name Register slot for signal */
//@{
template<typename F>
boost::signals2::connection registerToolChanged(F&& f)
{
return signalToolChanged.connect(std::forward<F>(f));
}
//@}
/** @name Attorneys for collaboration with helper classes */
//@{
friend class ViewProviderSketchDrawSketchHandlerAttorney;
@@ -761,6 +770,14 @@ private:
bool isInEditMode() const;
//@}
/** @name signals*/
//@{
/// signals a tool change
boost::signals2::signal<void(const std::string& toolname)> signalToolChanged;
//@}
void slotToolWidgetChanged(QWidget* newwidget);
/** @name Attorney functions*/
//@{
/* private functions to decouple Attorneys and Clients from the internal implementation of
@@ -885,6 +902,9 @@ private:
ViewProviderParameters viewProviderParameters;
using Connection = boost::signals2::connection;
Connection connectionToolWidget;
SoNodeSensor cameraSensor;
int viewOrientationFactor; // stores if sketch viewed from front or back
};