1
/***************************************************************************
2
* Copyright (c) 2011 Jürgen Riegel <juergen.riegel@web.de> *
4
* This file is part of the FreeCAD CAx development system. *
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. *
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. *
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 *
21
***************************************************************************/
23
#include "PreCompiled.h"
28
#include <Gui/Application.h>
29
#include <Gui/BitmapFactory.h>
30
#include <Gui/Command.h>
31
#include <Mod/Sketcher/App/SketchObject.h>
33
#include "TaskSketcherMessages.h"
34
#include "ViewProviderSketch.h"
35
#include "ui_TaskSketcherMessages.h"
39
using namespace SketcherGui;
40
using namespace Gui::TaskView;
41
namespace sp = std::placeholders;
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)
48
// we need a separate container widget to add all controls to
49
proxy = new QWidget(this);
53
this->groupLayout()->addWidget(proxy);
56
connectionSetUp = sketchView->signalSetUp.connect(std::bind(
57
&SketcherGui::TaskSketcherMessages::slotSetUp, this, sp::_1, sp::_2, sp::_3, sp::_4));
60
ui->labelConstrainStatus->setOpenExternalLinks(false);
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"),
73
std::string("MalformedConstraintMessageColor"));
74
ui->labelConstrainStatus->registerState(QString::fromUtf8("conflicting_constraints"),
76
std::string("ConflictingConstraintMessageColor"));
77
ui->labelConstrainStatus->registerState(QString::fromUtf8("redundant_constraints"),
79
std::string("RedundantConstraintMessageColor"));
80
ui->labelConstrainStatus->registerState(
81
QString::fromUtf8("partially_redundant_constraints"),
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"),
88
std::string("FullyConstrainedMessageColor"));
90
ui->labelConstrainStatusLink->setLaunchExternal(false);
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);
97
sketchView->getSketchObject()->noRecomputes = !state;
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);
105
QObject::connect(std::as_const(ui->manualUpdate)->actions()[0],
108
&TaskSketcherMessages::onAutoUpdateStateChanged);
111
TaskSketcherMessages::~TaskSketcherMessages()
113
connectionSetUp.disconnect();
116
void TaskSketcherMessages::setupConnections()
118
connect(ui->labelConstrainStatusLink,
119
&Gui::UrlLabel::linkClicked,
121
&TaskSketcherMessages::onLabelConstrainStatusLinkClicked);
122
connect(ui->manualUpdate,
123
&QToolButton::clicked,
125
&TaskSketcherMessages::onManualUpdateClicked);
128
void TaskSketcherMessages::slotSetUp(const QString& state, const QString& msg, const QString& link,
129
const QString& linkText)
131
ui->labelConstrainStatus->setState(state);
132
ui->labelConstrainStatus->setText(msg);
133
ui->labelConstrainStatusLink->setUrl(link);
134
ui->labelConstrainStatusLink->setText(linkText);
138
void TaskSketcherMessages::updateToolTip(const QString& link)
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."));
157
void TaskSketcherMessages::onLabelConstrainStatusLinkClicked(const QString& str)
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");
176
void TaskSketcherMessages::onAutoUpdateStateChanged()
178
bool state = std::as_const(ui->manualUpdate)->actions()[0]->isChecked();
180
ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath(
181
"User parameter:BaseApp/Preferences/Mod/Sketcher");
182
hGrp->SetBool("AutoRecompute", state);
183
sketchView->getSketchObject()->noRecomputes = !state;
186
void TaskSketcherMessages::onManualUpdateClicked(bool checked)
189
Gui::Command::updateActive();
192
#include "moc_TaskSketcherMessages.cpp"