1
/***************************************************************************
2
* Copyright (c) 2023 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_TaskCosmeticCircle.h"
40
#include "TaskCosmeticCircle.h"
44
using namespace TechDraw;
45
using namespace TechDrawGui;
49
TaskCosmeticCircle::TaskCosmeticCircle(TechDraw::DrawViewPart* partFeat,
50
std::string circleName) :
51
ui(new Ui_TaskCosmeticCircle),
53
m_circleName(circleName),
58
//existence of partFeat is checked in calling command
60
m_ce = m_partFeat->getCosmeticEdgeBySelection(m_circleName);
62
Base::Console().Error("TaskCosmeticCircle - bad parameters. Can not proceed.\n");
72
TaskCosmeticCircle::TaskCosmeticCircle(TechDraw::DrawViewPart* partFeat,
73
Base::Vector3d center, bool is3d) :
74
ui(new Ui_TaskCosmeticCircle),
82
//existence of partFeat is checked in calling command
89
TaskCosmeticCircle::~TaskCosmeticCircle()
96
void TaskCosmeticCircle::updateTask()
100
// blockUpdate = false;
103
void TaskCosmeticCircle::changeEvent(QEvent *e)
105
if (e->type() == QEvent::LanguageChange) {
106
ui->retranslateUi(this);
110
void TaskCosmeticCircle::setUiPrimary()
112
setWindowTitle(QObject::tr("Create Cosmetic Circle"));
113
// Base::Console().Message("TCC::setUiPrimary() - m_center: %s is3d: %d\n",
114
// DU::formatVector(m_center).c_str(), m_is3d);
115
double rotDeg = m_partFeat->Rotation.getValue();
116
double rotRad = rotDeg * M_PI / 180.0;
117
Base::Vector3d centroid = m_partFeat->getCurrentCentroid();
120
// center, project and invert the 3d point
121
p1 = DrawUtil::invertY(m_partFeat->projectPoint(m_center - centroid));
122
ui->rb2d1->setChecked(false);
123
ui->rb3d1->setChecked(true);
125
// invert, unscale and unrotate the selected 2d point
126
// shift by centroid?
127
p1 = DU::invertY(m_center) / m_partFeat->getScale();
129
// we always rotate around the origin.
132
ui->rb2d1->setChecked(true);
133
ui->rb3d1->setChecked(false);
136
ui->qsbCenterX->setUnit(Base::Unit::Length);
137
ui->qsbCenterX->setValue(p1.x);
138
ui->qsbCenterY->setUnit(Base::Unit::Length);
139
ui->qsbCenterY->setValue(p1.y);
140
ui->qsbCenterY->setUnit(Base::Unit::Length);
141
ui->qsbCenterZ->setValue(p1.z);
144
void TaskCosmeticCircle::setUiEdit()
146
setWindowTitle(QObject::tr("Edit Cosmetic Circle"));
148
ui->rb2d1->setChecked(true);
149
ui->rb3d1->setChecked(false);
151
Base::Vector3d p1 = DrawUtil::invertY(m_ce->permaStart);
152
ui->qsbCenterX->setValue(p1.x);
153
ui->qsbCenterY->setValue(p1.y);
154
ui->qsbCenterZ->setValue(p1.z);
156
ui->qsbRadius->setValue(m_ce->permaRadius);
158
double angleDeg = m_ce->m_geometry->getStartAngle() * 180.0 / M_PI;
159
ui->qsbStartAngle->setValue(angleDeg);
160
angleDeg = m_ce->m_geometry->getEndAngle() * 180.0 / M_PI;
161
ui->qsbEndAngle->setValue(angleDeg);
164
//******************************************************************************
165
void TaskCosmeticCircle::createCosmeticCircle(void)
167
// Base::Console().Message("TCL::createCosmeticCircle()\n");
168
Gui::Command::openCommand(QT_TRANSLATE_NOOP("Command", "Create Cosmetic Line"));
170
double x = ui->qsbCenterX->value().getValue();
171
double y = ui->qsbCenterY->value().getValue();
172
double z = ui->qsbCenterZ->value().getValue();
173
Base::Vector3d p0(x, y, z);
175
TechDraw::BaseGeomPtr bg;
176
if (ui->qsbStartAngle->value().getValue() == 0.0 &&
177
ui->qsbEndAngle->value().getValue() == 0.0) {
178
bg = std::make_shared<TechDraw::Circle> (p0, ui->qsbRadius->value().getValue());
180
bg = std::make_shared<TechDraw::AOC>(p0, ui->qsbRadius->value().getValue(),
181
ui->qsbStartAngle->value().getValue(),
182
ui->qsbEndAngle->value().getValue());
185
// note cEdges are inverted when added to the dvp geometry, so we need to
187
m_tag = m_partFeat->addCosmeticEdge(bg->inverted());
188
m_ce = m_partFeat->getCosmeticEdge(m_tag);
190
Gui::Command::commitCommand();
193
void TaskCosmeticCircle::updateCosmeticCircle(void)
195
// Base::Console().Message("TCL::updateCosmeticCircle()\n");
196
double x = ui->qsbCenterX->value().getValue();
197
double y = ui->qsbCenterY->value().getValue();
198
double z = ui->qsbCenterZ->value().getValue();
199
Base::Vector3d p0(x, y, z);
201
//replace the geometry
202
m_ce->permaRadius = ui->qsbRadius->value().getValue();
204
TechDraw::BaseGeomPtr bg;
205
if (ui->qsbStartAngle->value().getValue() == 0.0 &&
206
ui->qsbEndAngle->value().getValue() == 0.0) {
207
bg = std::make_shared<TechDraw::Circle> (p0, m_ce->permaRadius);
209
bg = std::make_shared<TechDraw::AOC>(p0, ui->qsbRadius->value().getValue(),
210
ui->qsbStartAngle->value().getValue(),
211
ui->qsbEndAngle->value().getValue());
213
m_ce->m_geometry = bg->inverted();
214
p0 = DU::invertY(p0);
215
m_ce->permaStart = p0;
219
//******************************************************************************
221
bool TaskCosmeticCircle::accept()
224
createCosmeticCircle();
225
m_partFeat->add1CEToGE(m_tag);
226
m_partFeat->refreshCEGeoms();
227
m_partFeat->requestPaint();
230
Gui::Command::openCommand(QT_TRANSLATE_NOOP("Command", "Update CosmeticCircle"));
231
updateCosmeticCircle();
232
m_partFeat->refreshCEGeoms();
233
m_partFeat->requestPaint();
234
Gui::Command::updateActive();
235
Gui::Command::commitCommand();
238
Gui::Command::doCommand(Gui::Command::Gui, "Gui.ActiveDocument.resetEdit()");
243
bool TaskCosmeticCircle::reject()
245
//there's nothing to do.
246
Gui::Command::doCommand(Gui::Command::Gui, "Gui.ActiveDocument.resetEdit()");
249
////////////////////////////////////////////////////////////////////////////////
250
TaskDlgCosmeticCircle::TaskDlgCosmeticCircle(TechDraw::DrawViewPart* partFeat,
251
Base::Vector3d point,
255
widget = new TaskCosmeticCircle(partFeat, point, is3d);
256
taskbox = new Gui::TaskView::TaskBox(Gui::BitmapFactory().pixmap("actions/TechDraw_CosmeticCircle"),
257
widget->windowTitle(), true, nullptr);
258
taskbox->groupLayout()->addWidget(widget);
259
Content.push_back(taskbox);
262
TaskDlgCosmeticCircle::TaskDlgCosmeticCircle(TechDraw::DrawViewPart* partFeat,
263
std::string circleName)
266
widget = new TaskCosmeticCircle(partFeat, circleName);
267
taskbox = new Gui::TaskView::TaskBox(Gui::BitmapFactory().pixmap("actions/TechDraw_CosmeticCircle"),
268
widget->windowTitle(), true, nullptr);
269
taskbox->groupLayout()->addWidget(widget);
270
Content.push_back(taskbox);
273
TaskDlgCosmeticCircle::~TaskDlgCosmeticCircle()
277
void TaskDlgCosmeticCircle::update()
279
// widget->updateTask();
282
//==== calls from the TaskView ===============================================================
283
void TaskDlgCosmeticCircle::open()
287
void TaskDlgCosmeticCircle::clicked(int)
291
bool TaskDlgCosmeticCircle::accept()
297
bool TaskDlgCosmeticCircle::reject()
303
#include <Mod/TechDraw/Gui/moc_TaskCosmeticCircle.cpp>