1
/***************************************************************************
2
* Copyright (c) 2020 WandererFan <wandererfan@gmail.com> *
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"
26
# include <BRepBuilderAPI_MakeEdge.hxx>
29
#include <Base/Console.h>
30
#include <Gui/BitmapFactory.h>
31
#include <Gui/Command.h>
32
#include <Gui/Document.h>
33
#include <Gui/Selection.h>
34
#include <Mod/TechDraw/App/DrawUtil.h>
35
#include <Mod/TechDraw/App/DrawViewPart.h>
36
#include <Mod/TechDraw/App/Cosmetic.h>
37
#include <Mod/TechDraw/App/Geometry.h>
39
#include "ui_TaskCosmeticLine.h"
40
#include "TaskCosmeticLine.h"
44
using namespace TechDraw;
45
using namespace TechDrawGui;
49
TaskCosmeticLine::TaskCosmeticLine(TechDraw::DrawViewPart* partFeat,
50
std::string edgeName) :
51
ui(new Ui_TaskCosmeticLine),
58
//existence of partFeat is checked in calling command
60
m_ce = m_partFeat->getCosmeticEdgeBySelection(m_edgeName);
62
Base::Console().Error("TaskCosmeticLine - bad parameters. Can not proceed.\n");
72
TaskCosmeticLine::TaskCosmeticLine(TechDraw::DrawViewPart* partFeat,
73
std::vector<Base::Vector3d> points,
74
std::vector<bool> is3d) :
75
ui(new Ui_TaskCosmeticLine),
83
//existence of partFeat is checked in calling command
90
TaskCosmeticLine::~TaskCosmeticLine()
97
void TaskCosmeticLine::updateTask()
101
// blockUpdate = false;
104
void TaskCosmeticLine::changeEvent(QEvent *e)
106
if (e->type() == QEvent::LanguageChange) {
107
ui->retranslateUi(this);
111
void TaskCosmeticLine::setUiPrimary()
113
setWindowTitle(QObject::tr("Create Cosmetic Line"));
115
double rotDeg = m_partFeat->Rotation.getValue();
116
double rotRad = rotDeg * M_PI / 180.0;
117
Base::Vector3d centroid = m_partFeat->getCurrentCentroid();
118
Base::Vector3d p1, p2;
119
if (m_is3d.front()) {
120
// center, project and invert the 3d point
121
p1 = DrawUtil::invertY(m_partFeat->projectPoint(m_points.front() - centroid));
122
ui->rb2d1->setChecked(false);
123
ui->rb3d1->setChecked(true);
125
// invert, unscale and unrotate the selected 2d point
126
p1 = DU::invertY(m_points.front()) / m_partFeat->getScale();
128
// we always rotate around the origin.
131
ui->rb2d1->setChecked(true);
132
ui->rb3d1->setChecked(false);
136
p2 = DrawUtil::invertY(m_partFeat->projectPoint(m_points.back() - centroid));
137
ui->rb2d2->setChecked(false);
138
ui->rb3d2->setChecked(true);
140
p2 = DU::invertY(m_points.back()) / m_partFeat->getScale();
144
ui->rb2d2->setChecked(true);
145
ui->rb3d2->setChecked(false);
148
ui->qsbx1->setUnit(Base::Unit::Length);
149
ui->qsbx1->setValue(p1.x);
150
ui->qsby1->setUnit(Base::Unit::Length);
151
ui->qsby1->setValue(p1.y);
152
ui->qsby1->setUnit(Base::Unit::Length);
153
ui->qsbz1->setValue(p1.z);
155
ui->qsbx2->setUnit(Base::Unit::Length);
156
ui->qsbx2->setValue(p2.x);
157
ui->qsby2->setUnit(Base::Unit::Length);
158
ui->qsby2->setValue(p2.y);
159
ui->qsbz2->setUnit(Base::Unit::Length);
160
ui->qsbz2->setValue(p2.z);
163
void TaskCosmeticLine::setUiEdit()
165
setWindowTitle(QObject::tr("Edit Cosmetic Line"));
167
ui->rb2d1->setChecked(true);
168
ui->rb3d1->setChecked(false);
169
ui->rb2d2->setChecked(true);
170
ui->rb3d2->setChecked(false);
172
Base::Vector3d p1 = DrawUtil::invertY(m_ce->permaStart);
173
ui->qsbx1->setValue(p1.x);
174
ui->qsby1->setValue(p1.y);
175
ui->qsbz1->setValue(p1.z);
177
Base::Vector3d p2 = DrawUtil::invertY(m_ce->permaEnd);
178
ui->qsbx2->setValue(p2.x);
179
ui->qsby2->setValue(p2.y);
180
ui->qsbz2->setValue(p2.z);
183
//******************************************************************************
184
void TaskCosmeticLine::createCosmeticLine(void)
186
// Base::Console().Message("TCL::createCosmeticLine()\n");
187
Gui::Command::openCommand(QT_TRANSLATE_NOOP("Command", "Create Cosmetic Line"));
189
double x = ui->qsbx1->value().getValue();
190
double y = ui->qsby1->value().getValue();
191
double z = ui->qsbz1->value().getValue();
192
Base::Vector3d p0(x, y, z);
194
x = ui->qsbx2->value().getValue();
195
y = ui->qsby2->value().getValue();
196
z = ui->qsbz2->value().getValue();
197
Base::Vector3d p1(x, y, z);
199
m_tag = m_partFeat->addCosmeticEdge(p0, p1);
200
m_ce = m_partFeat->getCosmeticEdge(m_tag);
202
Gui::Command::commitCommand();
205
void TaskCosmeticLine::updateCosmeticLine(void)
207
// Base::Console().Message("TCL::updateCosmeticLine()\n");
208
double x = ui->qsbx1->value().getValue();
209
double y = ui->qsby1->value().getValue();
210
double z = ui->qsbz1->value().getValue();
211
Base::Vector3d p0(x, y, z);
212
p0 = DrawUtil::invertY(p0);
214
x = ui->qsbx2->value().getValue();
215
y = ui->qsby2->value().getValue();
216
z = ui->qsbz2->value().getValue();
217
Base::Vector3d p1(x, y, z);
218
p1 = DrawUtil::invertY(p1);
220
//replace the geometry
221
m_ce->permaStart = p0;
224
gp_Pnt gp1(p0.x, p0.y, p0.z);
225
gp_Pnt gp2(p1.x, p1.y, p1.z);
226
TopoDS_Edge e = BRepBuilderAPI_MakeEdge(gp1, gp2);
227
m_ce->m_geometry = TechDraw::BaseGeom::baseFactory(e);
230
//******************************************************************************
232
bool TaskCosmeticLine::accept()
235
createCosmeticLine();
236
m_partFeat->add1CEToGE(m_tag);
237
m_partFeat->refreshCEGeoms();
238
m_partFeat->requestPaint();
241
Gui::Command::openCommand(QT_TRANSLATE_NOOP("Command", "Update CosmeticLine"));
242
updateCosmeticLine();
243
m_partFeat->refreshCEGeoms();
244
m_partFeat->requestPaint();
245
Gui::Command::updateActive();
246
Gui::Command::commitCommand();
249
Gui::Command::doCommand(Gui::Command::Gui, "Gui.ActiveDocument.resetEdit()");
254
bool TaskCosmeticLine::reject()
256
//there's nothing to do.
257
Gui::Command::doCommand(Gui::Command::Gui, "Gui.ActiveDocument.resetEdit()");
260
////////////////////////////////////////////////////////////////////////////////
261
TaskDlgCosmeticLine::TaskDlgCosmeticLine(TechDraw::DrawViewPart* partFeat,
262
std::vector<Base::Vector3d> points,
263
std::vector<bool> is3d)
266
widget = new TaskCosmeticLine(partFeat, points, is3d);
267
taskbox = new Gui::TaskView::TaskBox(Gui::BitmapFactory().pixmap("actions/TechDraw_Line2Points"),
268
widget->windowTitle(), true, nullptr);
269
taskbox->groupLayout()->addWidget(widget);
270
Content.push_back(taskbox);
273
TaskDlgCosmeticLine::TaskDlgCosmeticLine(TechDraw::DrawViewPart* partFeat,
274
std::string edgeName)
277
widget = new TaskCosmeticLine(partFeat, edgeName);
278
taskbox = new Gui::TaskView::TaskBox(Gui::BitmapFactory().pixmap("actions/TechDraw_Line2Points"),
279
widget->windowTitle(), true, nullptr);
280
taskbox->groupLayout()->addWidget(widget);
281
Content.push_back(taskbox);
284
TaskDlgCosmeticLine::~TaskDlgCosmeticLine()
288
void TaskDlgCosmeticLine::update()
290
// widget->updateTask();
293
//==== calls from the TaskView ===============================================================
294
void TaskDlgCosmeticLine::open()
298
void TaskDlgCosmeticLine::clicked(int)
302
bool TaskDlgCosmeticLine::accept()
308
bool TaskDlgCosmeticLine::reject()
314
#include <Mod/TechDraw/Gui/moc_TaskCosmeticLine.cpp>