FreeCAD

Форк
0
/
TaskSketcherMessages.cpp 
193 строки · 9.0 Кб
1
/***************************************************************************
2
 *   Copyright (c) 2011 Jürgen Riegel <juergen.riegel@web.de>              *
3
 *                                                                         *
4
 *   This file is part of the FreeCAD CAx development system.              *
5
 *                                                                         *
6
 *   This library is free software; you can redistribute it and/or         *
7
 *   modify it under the terms of the GNU Library General Public           *
8
 *   License as published by the Free Software Foundation; either          *
9
 *   version 2 of the License, or (at your option) any later version.      *
10
 *                                                                         *
11
 *   This library  is distributed in the hope that it will be useful,      *
12
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
13
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
14
 *   GNU Library General Public License for more details.                  *
15
 *                                                                         *
16
 *   You should have received a copy of the GNU Library General Public     *
17
 *   License along with this library; see the file COPYING.LIB. If not,    *
18
 *   write to the Free Software Foundation, Inc., 59 Temple Place,         *
19
 *   Suite 330, Boston, MA  02111-1307, USA                                *
20
 *                                                                         *
21
 ***************************************************************************/
22

23
#include "PreCompiled.h"
24
#ifndef _PreComp_
25
#include <QAction>
26
#endif
27

28
#include <Gui/Application.h>
29
#include <Gui/BitmapFactory.h>
30
#include <Gui/Command.h>
31
#include <Mod/Sketcher/App/SketchObject.h>
32

33
#include "TaskSketcherMessages.h"
34
#include "ViewProviderSketch.h"
35
#include "ui_TaskSketcherMessages.h"
36

37

38
// clang-format off
39
using namespace SketcherGui;
40
using namespace Gui::TaskView;
41
namespace sp = std::placeholders;
42

43
TaskSketcherMessages::TaskSketcherMessages(ViewProviderSketch* sketchView)
44
    : TaskBox(Gui::BitmapFactory().pixmap("Sketcher_Sketch"), tr("Solver messages"), true, nullptr)
45
    , sketchView(sketchView)
46
    , ui(new Ui_TaskSketcherMessages)
47
{
48
    // we need a separate container widget to add all controls to
49
    proxy = new QWidget(this);
50
    ui->setupUi(proxy);
51
    setupConnections();
52

53
    this->groupLayout()->addWidget(proxy);
54

55
    //NOLINTBEGIN
56
    connectionSetUp = sketchView->signalSetUp.connect(std::bind(
57
        &SketcherGui::TaskSketcherMessages::slotSetUp, this, sp::_1, sp::_2, sp::_3, sp::_4));
58
    //NOLINTEND
59

60
    ui->labelConstrainStatus->setOpenExternalLinks(false);
61

62
    // Set up the possible state values for the status label
63
    ui->labelConstrainStatus->setParameterGroup(
64
        "User parameter:BaseApp/Preferences/Mod/Sketcher/General");
65
    ui->labelConstrainStatus->registerState(QString::fromUtf8("empty_sketch"),
66
                                            palette().windowText().color(),
67
                                            std::string("EmptySketchMessageColor"));
68
    ui->labelConstrainStatus->registerState(QString::fromUtf8("under_constrained"),
69
                                            palette().windowText().color(),
70
                                            std::string("UnderconstrainedMessageColor"));
71
    ui->labelConstrainStatus->registerState(QString::fromUtf8("malformed_constraints"),
72
                                            QColor("red"),
73
                                            std::string("MalformedConstraintMessageColor"));
74
    ui->labelConstrainStatus->registerState(QString::fromUtf8("conflicting_constraints"),
75
                                            QColor("orangered"),
76
                                            std::string("ConflictingConstraintMessageColor"));
77
    ui->labelConstrainStatus->registerState(QString::fromUtf8("redundant_constraints"),
78
                                            QColor("red"),
79
                                            std::string("RedundantConstraintMessageColor"));
80
    ui->labelConstrainStatus->registerState(
81
        QString::fromUtf8("partially_redundant_constraints"),
82
        QColor("royalblue"),
83
        std::string("PartiallyRedundantConstraintMessageColor"));
84
    ui->labelConstrainStatus->registerState(
85
        QString::fromUtf8("solver_failed"), QColor("red"), std::string("SolverFailedMessageColor"));
86
    ui->labelConstrainStatus->registerState(QString::fromUtf8("fully_constrained"),
87
                                            QColor("green"),
88
                                            std::string("FullyConstrainedMessageColor"));
89

90
    ui->labelConstrainStatusLink->setLaunchExternal(false);
91

92
    // Set Auto Update in the 'Manual Update' button menu.
93
    ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath(
94
        "User parameter:BaseApp/Preferences/Mod/Sketcher");
95
    bool state = hGrp->GetBool("AutoRecompute", false);
96

97
    sketchView->getSketchObject()->noRecomputes = !state;
98

99
    QAction* action = new QAction(tr("Auto update"), this);
100
    action->setToolTip(tr("Executes a recomputation of active document after every sketch action"));
101
    action->setCheckable(true);
102
    action->setChecked(state);
103
    ui->manualUpdate->addAction(action);
104

105
    QObject::connect(std::as_const(ui->manualUpdate)->actions()[0],
106
                     &QAction::changed,
107
                     this,
108
                     &TaskSketcherMessages::onAutoUpdateStateChanged);
109
}
110

111
TaskSketcherMessages::~TaskSketcherMessages()
112
{
113
    connectionSetUp.disconnect();
114
}
115

116
void TaskSketcherMessages::setupConnections()
117
{
118
    connect(ui->labelConstrainStatusLink,
119
            &Gui::UrlLabel::linkClicked,
120
            this,
121
            &TaskSketcherMessages::onLabelConstrainStatusLinkClicked);
122
    connect(ui->manualUpdate,
123
            &QToolButton::clicked,
124
            this,
125
            &TaskSketcherMessages::onManualUpdateClicked);
126
}
127

128
void TaskSketcherMessages::slotSetUp(const QString& state, const QString& msg, const QString& link,
129
                                     const QString& linkText)
130
{
131
    ui->labelConstrainStatus->setState(state);
132
    ui->labelConstrainStatus->setText(msg);
133
    ui->labelConstrainStatusLink->setUrl(link);
134
    ui->labelConstrainStatusLink->setText(linkText);
135
    updateToolTip(link);
136
}
137

138
void TaskSketcherMessages::updateToolTip(const QString& link)
139
{
140
    if (link == QString::fromLatin1("#conflicting"))
141
        ui->labelConstrainStatusLink->setToolTip(
142
            tr("Click to select these conflicting constraints."));
143
    else if (link == QString::fromLatin1("#redundant"))
144
        ui->labelConstrainStatusLink->setToolTip(tr("Click to select these redundant constraints."));
145
    else if (link == QString::fromLatin1("#dofs"))
146
        ui->labelConstrainStatusLink->setToolTip(
147
            tr("The sketch has unconstrained elements giving rise to those Degrees Of Freedom. "
148
               "Click to select these unconstrained elements."));
149
    else if (link == QString::fromLatin1("#malformed"))
150
        ui->labelConstrainStatusLink->setToolTip(tr("Click to select these malformed constraints."));
151
    else if (link == QString::fromLatin1("#partiallyredundant"))
152
        ui->labelConstrainStatusLink->setToolTip(
153
            tr("Some constraints in combination are partially redundant. Click to select these "
154
               "partially redundant constraints."));
155
}
156

157
void TaskSketcherMessages::onLabelConstrainStatusLinkClicked(const QString& str)
158
{
159
    if (str == QString::fromLatin1("#conflicting"))
160
        Gui::Application::Instance->commandManager().runCommandByName(
161
            "Sketcher_SelectConflictingConstraints");
162
    else if (str == QString::fromLatin1("#redundant"))
163
        Gui::Application::Instance->commandManager().runCommandByName(
164
            "Sketcher_SelectRedundantConstraints");
165
    else if (str == QString::fromLatin1("#dofs"))
166
        Gui::Application::Instance->commandManager().runCommandByName(
167
            "Sketcher_SelectElementsWithDoFs");
168
    else if (str == QString::fromLatin1("#malformed"))
169
        Gui::Application::Instance->commandManager().runCommandByName(
170
            "Sketcher_SelectMalformedConstraints");
171
    else if (str == QString::fromLatin1("#partiallyredundant"))
172
        Gui::Application::Instance->commandManager().runCommandByName(
173
            "Sketcher_SelectPartiallyRedundantConstraints");
174
}
175

176
void TaskSketcherMessages::onAutoUpdateStateChanged()
177
{
178
    bool state = std::as_const(ui->manualUpdate)->actions()[0]->isChecked();
179

180
    ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath(
181
        "User parameter:BaseApp/Preferences/Mod/Sketcher");
182
    hGrp->SetBool("AutoRecompute", state);
183
    sketchView->getSketchObject()->noRecomputes = !state;
184
}
185

186
void TaskSketcherMessages::onManualUpdateClicked(bool checked)
187
{
188
    Q_UNUSED(checked);
189
    Gui::Command::updateActive();
190
}
191

192
#include "moc_TaskSketcherMessages.cpp"
193
// clang-format on
194

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.