| |
|
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| |
|
| | #ifndef SKETCHERGUI_DrawSketchDefaultWidgetController_H
|
| | #define SKETCHERGUI_DrawSketchDefaultWidgetController_H
|
| |
|
| | #include <Base/Tools.h>
|
| | #include <Gui/EditableDatumLabel.h>
|
| |
|
| | #include "DrawSketchController.h"
|
| |
|
| | #include "DrawSketchKeyboardManager.h"
|
| |
|
| | namespace SketcherGui
|
| | {
|
| |
|
| |
|
| | template<int... sizes>
|
| | class WidgetParameters: public ControlAmount<sizes...>
|
| | {
|
| | };
|
| |
|
| |
|
| | template<int... sizes>
|
| | class WidgetCheckboxes: public ControlAmount<sizes...>
|
| | {
|
| | };
|
| |
|
| |
|
| | template<int... sizes>
|
| | class WidgetComboboxes: public ControlAmount<sizes...>
|
| | {
|
| | };
|
| |
|
| | namespace sp = std::placeholders;
|
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | template<
|
| | typename HandlerT,
|
| | typename SelectModeT,
|
| | int PAutoConstraintSize,
|
| | typename OnViewParametersT,
|
| | typename WidgetParametersT,
|
| | typename WidgetCheckboxesT,
|
| | typename WidgetComboboxesT,
|
| | typename ConstructionMethodT = ConstructionMethods::DefaultConstructionMethod,
|
| | bool PFirstComboboxIsConstructionMethod = false>
|
| |
|
| | class DrawSketchDefaultWidgetController
|
| | : public DrawSketchController<HandlerT, SelectModeT, PAutoConstraintSize, OnViewParametersT, ConstructionMethodT>
|
| | {
|
| | public:
|
| |
|
| |
|
| | using ControllerBase
|
| | = DrawSketchController<HandlerT, SelectModeT, PAutoConstraintSize, OnViewParametersT, ConstructionMethodT>;
|
| |
|
| |
|
| | private:
|
| | int nParameter = WidgetParametersT::defaultMethodSize();
|
| | int nCheckbox = WidgetCheckboxesT::defaultMethodSize();
|
| | int nCombobox = WidgetComboboxesT::defaultMethodSize();
|
| |
|
| | SketcherToolDefaultWidget* toolWidget;
|
| |
|
| | using Connection = fastsignals::advanced_connection;
|
| |
|
| | Connection connectionParameterTabOrEnterPressed;
|
| | Connection connectionParameterValueChanged;
|
| | Connection connectionCheckboxCheckedChanged;
|
| | Connection connectionComboboxSelectionChanged;
|
| |
|
| |
|
| |
|
| | using WParameter = SketcherToolDefaultWidget::Parameter;
|
| | using WCheckbox = SketcherToolDefaultWidget::Checkbox;
|
| | using WCombobox = SketcherToolDefaultWidget::Combobox;
|
| |
|
| |
|
| | using SelectMode = SelectModeT;
|
| | using ControllerBase::handler;
|
| |
|
| | public:
|
| | explicit DrawSketchDefaultWidgetController(HandlerT* dshandler)
|
| | : ControllerBase(dshandler)
|
| | , toolWidget(nullptr)
|
| | {}
|
| |
|
| | DrawSketchDefaultWidgetController(const DrawSketchDefaultWidgetController&) = delete;
|
| | DrawSketchDefaultWidgetController(DrawSketchDefaultWidgetController&&) = delete;
|
| | DrawSketchDefaultWidgetController& operator=(const DrawSketchDefaultWidgetController&) = delete;
|
| | DrawSketchDefaultWidgetController& operator=(DrawSketchDefaultWidgetController&&) = delete;
|
| |
|
| | ~DrawSketchDefaultWidgetController() override
|
| | {
|
| | connectionParameterTabOrEnterPressed.disconnect();
|
| | connectionParameterValueChanged.disconnect();
|
| | connectionCheckboxCheckedChanged.disconnect();
|
| | connectionComboboxSelectionChanged.disconnect();
|
| | }
|
| |
|
| | |
| |
|
| | |
| | |
| |
|
| |
|
| | |
| | |
| |
|
| | void parameterValueChanged(int parameterindex, double value)
|
| | {
|
| | adaptDrawingToParameterChange(parameterindex, value);
|
| |
|
| |
|
| |
|
| | ControllerBase::focusAutoPassing = false;
|
| |
|
| | ControllerBase::finishControlsChanged();
|
| |
|
| | ControllerBase::focusAutoPassing = true;
|
| | }
|
| |
|
| | void parameterTabOrEnterPressed(int parameterindex)
|
| | {
|
| | Q_UNUSED(parameterindex);
|
| | passFocusToNextParameter();
|
| | }
|
| |
|
| | |
| | |
| |
|
| | void checkboxCheckedChanged(int checkboxindex, bool value)
|
| | {
|
| | adaptDrawingToCheckboxChange(checkboxindex, value);
|
| |
|
| | ControllerBase::finishControlsChanged();
|
| | }
|
| |
|
| | |
| | |
| |
|
| | void comboboxSelectionChanged(int comboboxindex, int value)
|
| | {
|
| | adaptDrawingToComboboxChange(comboboxindex, value);
|
| |
|
| | ControllerBase::finishControlsChanged();
|
| | }
|
| |
|
| |
|
| |
|
| | |
| | |
| | |
| | |
| |
|
| |
|
| | void adaptDrawingToParameterChange(int parameterindex, double value)
|
| | {
|
| | Q_UNUSED(parameterindex);
|
| | Q_UNUSED(value);
|
| | }
|
| |
|
| |
|
| | void adaptDrawingToCheckboxChange(int checkboxindex, bool value)
|
| | {
|
| | Q_UNUSED(checkboxindex);
|
| | Q_UNUSED(value);
|
| | }
|
| |
|
| |
|
| | void adaptDrawingToComboboxChange(int comboboxindex, [[maybe_unused]] int value)
|
| | {
|
| | Q_UNUSED(comboboxindex);
|
| |
|
| | if constexpr (PFirstComboboxIsConstructionMethod == true) {
|
| |
|
| | if (comboboxindex == WCombobox::FirstCombo && handler->ConstructionMethodsCount() > 1) {
|
| | handler->setConstructionMethod(static_cast<ConstructionMethodT>(value));
|
| | }
|
| | }
|
| | }
|
| |
|
| |
|
| | void addConstraints() override
|
| | {}
|
| |
|
| |
|
| | void configureToolWidget()
|
| | {}
|
| |
|
| |
|
| | void computeNextDrawSketchHandlerMode() override
|
| | {}
|
| |
|
| |
|
| | void adaptParameters(Base::Vector2d onSketchPos) override
|
| | {
|
| | Q_UNUSED(onSketchPos)
|
| | }
|
| |
|
| | |
| |
|
| | void firstKeyShortcut() override
|
| | {
|
| | if (nCheckbox >= 1) {
|
| | auto firstchecked = toolWidget->getCheckboxChecked(WCheckbox::FirstBox);
|
| | toolWidget->setCheckboxChecked(WCheckbox::FirstBox, !firstchecked);
|
| | }
|
| | }
|
| |
|
| | |
| |
|
| | void secondKeyShortcut() override
|
| | {
|
| | if (nCheckbox >= 2) {
|
| | auto secondchecked = toolWidget->getCheckboxChecked(WCheckbox::SecondBox);
|
| | toolWidget->setCheckboxChecked(WCheckbox::SecondBox, !secondchecked);
|
| | }
|
| | }
|
| |
|
| | |
| |
|
| | void thirdKeyShortcut() override
|
| | {
|
| | if (nCheckbox >= 3) {
|
| | auto thirdchecked = toolWidget->getCheckboxChecked(WCheckbox::ThirdBox);
|
| | toolWidget->setCheckboxChecked(WCheckbox::ThirdBox, !thirdchecked);
|
| | }
|
| | }
|
| |
|
| | |
| |
|
| | void fourthKeyShortcut() override
|
| | {
|
| | if (nCheckbox >= 4) {
|
| | auto fourthchecked = toolWidget->getCheckboxChecked(WCheckbox::FourthBox);
|
| | toolWidget->setCheckboxChecked(WCheckbox::FourthBox, !fourthchecked);
|
| | }
|
| | }
|
| |
|
| |
|
| | void tabShortcut() override
|
| | {
|
| | passFocusToNextParameter();
|
| | }
|
| |
|
| |
|
| |
|
| | protected:
|
| |
|
| |
|
| |
|
| | void doInitControls(QWidget* widget) override
|
| | {
|
| | initDefaultWidget(widget);
|
| | ControllerBase::doInitControls(widget);
|
| | }
|
| |
|
| |
|
| | void doResetControls() override
|
| | {
|
| | ControllerBase::doResetControls();
|
| | resetDefaultWidget();
|
| | }
|
| |
|
| |
|
| | void doConstructionMethodChanged() override
|
| | {}
|
| |
|
| |
|
| | void setFocusToParameter(unsigned int parameterindex)
|
| | {
|
| |
|
| |
|
| | if (!ControllerBase::setFocusToOnViewParameter(parameterindex)) {
|
| | parameterindex = parameterindex - ControllerBase::onViewParameters.size();
|
| |
|
| | if (parameterindex < static_cast<unsigned int>(nParameter)) {
|
| | toolWidget->setParameterFocus(parameterindex);
|
| | ControllerBase::parameterWithFocus = ControllerBase::onViewParameters.size()
|
| | + parameterindex;
|
| | }
|
| | }
|
| | }
|
| |
|
| |
|
| | void passFocusToNextParameter()
|
| | {
|
| | unsigned int index = ControllerBase::parameterWithFocus + 1;
|
| |
|
| | if (index >= ControllerBase::onViewParameters.size() + nParameter) {
|
| | index = 0;
|
| | }
|
| |
|
| | auto trySetFocus = [this](unsigned int& idx) -> bool {
|
| | while (idx < ControllerBase::onViewParameters.size()) {
|
| | if (ControllerBase::isOnViewParameterOfCurrentMode(idx)
|
| | && ControllerBase::isOnViewParameterVisible(idx)) {
|
| | setFocusToParameter(idx);
|
| | return true;
|
| | }
|
| | idx++;
|
| | }
|
| | if (idx < ControllerBase::onViewParameters.size() + nParameter) {
|
| | setFocusToParameter(idx);
|
| | return true;
|
| | }
|
| | return false;
|
| | };
|
| |
|
| | if (!trySetFocus(index)) {
|
| |
|
| |
|
| | index = 0;
|
| | trySetFocus(index);
|
| | }
|
| |
|
| |
|
| | }
|
| |
|
| |
|
| | private:
|
| |
|
| | void initDefaultWidget(QWidget* widget)
|
| | {
|
| | toolWidget = static_cast<SketcherToolDefaultWidget*>(widget);
|
| |
|
| | connectionParameterTabOrEnterPressed = toolWidget->registerParameterTabOrEnterPressed(
|
| | std::bind(&DrawSketchDefaultWidgetController::parameterTabOrEnterPressed, this, sp::_1)
|
| | );
|
| |
|
| | connectionParameterValueChanged = toolWidget->registerParameterValueChanged(
|
| | std::bind(&DrawSketchDefaultWidgetController::parameterValueChanged, this, sp::_1, sp::_2)
|
| | );
|
| |
|
| | connectionCheckboxCheckedChanged = toolWidget->registerCheckboxCheckedChanged(
|
| | std::bind(&DrawSketchDefaultWidgetController::checkboxCheckedChanged, this, sp::_1, sp::_2)
|
| | );
|
| |
|
| | connectionComboboxSelectionChanged = toolWidget->registerComboboxSelectionChanged(
|
| | std::bind(&DrawSketchDefaultWidgetController::comboboxSelectionChanged, this, sp::_1, sp::_2)
|
| | );
|
| | }
|
| |
|
| |
|
| | void resetDefaultWidget()
|
| | {
|
| | fastsignals::shared_connection_block parameter_focus_block(
|
| | connectionParameterTabOrEnterPressed
|
| | );
|
| | fastsignals::shared_connection_block parameter_block(connectionParameterValueChanged);
|
| | fastsignals::shared_connection_block checkbox_block(connectionCheckboxCheckedChanged);
|
| | fastsignals::shared_connection_block combobox_block(connectionComboboxSelectionChanged);
|
| |
|
| | nParameter = WidgetParametersT::size(handler->constructionMethod());
|
| | nCheckbox = WidgetCheckboxesT::size(handler->constructionMethod());
|
| | nCombobox = WidgetComboboxesT::size(handler->constructionMethod());
|
| |
|
| | toolWidget->initNParameters(nParameter, ControllerBase::getKeyManager());
|
| | toolWidget->initNCheckboxes(nCheckbox);
|
| | toolWidget->initNComboboxes(nCombobox);
|
| |
|
| | configureToolWidget();
|
| |
|
| |
|
| |
|
| | if constexpr (PFirstComboboxIsConstructionMethod == true) {
|
| | auto currentindex = toolWidget->getComboboxIndex(WCombobox::FirstCombo);
|
| | auto methodint = static_cast<int>(handler->constructionMethod());
|
| |
|
| | if (currentindex != methodint) {
|
| |
|
| | fastsignals::shared_connection_block combobox_block(connectionComboboxSelectionChanged);
|
| | toolWidget->setComboboxIndex(WCombobox::FirstCombo, methodint);
|
| | }
|
| | }
|
| | }
|
| |
|
| | private:
|
| |
|
| |
|
| |
|
| | bool syncHandlerToCheckbox(int checkboxindex, bool& handlerboolean)
|
| | {
|
| | bool status = toolWidget->getCheckboxChecked(checkboxindex);
|
| | handlerboolean = status;
|
| |
|
| | return status;
|
| | }
|
| |
|
| |
|
| | bool syncCheckboxToHandler(int checkboxindex, bool handlerboolean)
|
| | {
|
| | bool status = toolWidget->getCheckboxChecked(checkboxindex);
|
| | if (handlerboolean != status) {
|
| | toolWidget->setCheckboxChecked(checkboxindex, handlerboolean);
|
| | return true;
|
| | }
|
| |
|
| | return false;
|
| | }
|
| |
|
| |
|
| | void syncHandlerToConstructionMethodCombobox()
|
| | {
|
| |
|
| | if constexpr (PFirstComboboxIsConstructionMethod == true) {
|
| | auto constructionmethod = toolWidget->getComboboxIndex(WCombobox::FirstCombo);
|
| |
|
| | handler->initConstructionMethod(static_cast<ConstructionMethodT>(constructionmethod));
|
| | }
|
| | }
|
| |
|
| | void syncConstructionMethodComboboxToHandler()
|
| | {
|
| | if constexpr (PFirstComboboxIsConstructionMethod == true) {
|
| | auto constructionmethod = toolWidget->getComboboxIndex(WCombobox::FirstCombo);
|
| |
|
| | auto actualconstructionmethod = static_cast<int>(handler->constructionMethod());
|
| |
|
| | if (constructionmethod != actualconstructionmethod) {
|
| | fastsignals::shared_connection_block combobox_block(connectionComboboxSelectionChanged);
|
| | toolWidget->setComboboxIndex(WCombobox::FirstCombo, actualconstructionmethod);
|
| | }
|
| | }
|
| | }
|
| |
|
| | };
|
| |
|
| |
|
| | }
|
| |
|
| |
|
| | #endif
|
| |
|