FreeCAD

Форк
0
/
TaskCosmeticCircle.cpp 
303 строки · 9.9 Кб
1
/***************************************************************************
2
 *   Copyright (c) 2023 WandererFan <wandererfan@gmail.com>                *
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 <cmath>
26
# include <BRepBuilderAPI_MakeEdge.hxx>
27
#endif
28

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>
38

39
#include "ui_TaskCosmeticCircle.h"
40
#include "TaskCosmeticCircle.h"
41

42

43
using namespace Gui;
44
using namespace TechDraw;
45
using namespace TechDrawGui;
46
using DU = DrawUtil;
47

48
//ctor for edit
49
TaskCosmeticCircle::TaskCosmeticCircle(TechDraw::DrawViewPart* partFeat,
50
                                   std::string circleName) :
51
    ui(new Ui_TaskCosmeticCircle),
52
    m_partFeat(partFeat),
53
    m_circleName(circleName),
54
    m_ce(nullptr),
55
    m_saveCE(nullptr),
56
    m_createMode(false)
57
{
58
    //existence of partFeat is checked in calling command
59

60
    m_ce = m_partFeat->getCosmeticEdgeBySelection(m_circleName);
61
    if (!m_ce) {
62
        Base::Console().Error("TaskCosmeticCircle - bad parameters.  Can not proceed.\n");
63
        return;
64
    }
65

66
    ui->setupUi(this);
67

68
    setUiEdit();
69
}
70

71
//ctor for creation
72
TaskCosmeticCircle::TaskCosmeticCircle(TechDraw::DrawViewPart* partFeat,
73
                                   Base::Vector3d center, bool is3d) :
74
    ui(new Ui_TaskCosmeticCircle),
75
    m_partFeat(partFeat),
76
    m_ce(nullptr),
77
    m_saveCE(nullptr),
78
    m_center(center),
79
    m_createMode(true),
80
    m_is3d(is3d)
81
{
82
    //existence of partFeat is checked in calling command
83

84
    ui->setupUi(this);
85

86
    setUiPrimary();
87
}
88

89
TaskCosmeticCircle::~TaskCosmeticCircle()
90
{
91
    if (m_saveCE) {
92
        delete m_saveCE;
93
    }
94
}
95

96
void TaskCosmeticCircle::updateTask()
97
{
98
//    blockUpdate = true;
99

100
//    blockUpdate = false;
101
}
102

103
void TaskCosmeticCircle::changeEvent(QEvent *e)
104
{
105
    if (e->type() == QEvent::LanguageChange) {
106
        ui->retranslateUi(this);
107
    }
108
}
109

110
void TaskCosmeticCircle::setUiPrimary()
111
{
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();
118
    Base::Vector3d p1;
119
    if (m_is3d) {
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);
124
    } else {
125
        // invert, unscale and unrotate the selected 2d point
126
        // shift by centroid?
127
        p1 = DU::invertY(m_center) / m_partFeat->getScale();
128
        if (rotDeg != 0.0) {
129
            // we always rotate around the origin.
130
            p1.RotateZ(-rotRad);
131
        }
132
        ui->rb2d1->setChecked(true);
133
        ui->rb3d1->setChecked(false);
134
    }
135

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);
142
}
143

144
void TaskCosmeticCircle::setUiEdit()
145
{
146
    setWindowTitle(QObject::tr("Edit Cosmetic Circle"));
147

148
    ui->rb2d1->setChecked(true);
149
    ui->rb3d1->setChecked(false);
150

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);
155

156
    ui->qsbRadius->setValue(m_ce->permaRadius);
157

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);
162
}
163

164
//******************************************************************************
165
void TaskCosmeticCircle::createCosmeticCircle(void)
166
{
167
//    Base::Console().Message("TCL::createCosmeticCircle()\n");
168
    Gui::Command::openCommand(QT_TRANSLATE_NOOP("Command", "Create Cosmetic Line"));
169

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);
174

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());
179
    } else {
180
        bg = std::make_shared<TechDraw::AOC>(p0, ui->qsbRadius->value().getValue(),
181
                                     ui->qsbStartAngle->value().getValue(),
182
                                     ui->qsbEndAngle->value().getValue());
183
    }
184

185
    // note cEdges are inverted when added to the dvp geometry, so we need to
186
    // invert them here
187
    m_tag = m_partFeat->addCosmeticEdge(bg->inverted());
188
    m_ce = m_partFeat->getCosmeticEdge(m_tag);
189

190
    Gui::Command::commitCommand();
191
}
192

193
void TaskCosmeticCircle::updateCosmeticCircle(void)
194
{
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);
200

201
    //replace the geometry
202
    m_ce->permaRadius = ui->qsbRadius->value().getValue();
203

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);
208
    } else {
209
        bg = std::make_shared<TechDraw::AOC>(p0, ui->qsbRadius->value().getValue(),
210
                                             ui->qsbStartAngle->value().getValue(),
211
                                             ui->qsbEndAngle->value().getValue());
212
    }
213
    m_ce->m_geometry = bg->inverted();
214
    p0 = DU::invertY(p0);
215
    m_ce->permaStart = p0;
216
    m_ce->permaEnd = p0;
217
}
218

219
//******************************************************************************
220

221
bool TaskCosmeticCircle::accept()
222
{
223
    if (m_createMode) {
224
        createCosmeticCircle();
225
        m_partFeat->add1CEToGE(m_tag);
226
        m_partFeat->refreshCEGeoms();
227
        m_partFeat->requestPaint();
228
    } else {
229
        //update mode
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();
236
    }
237

238
    Gui::Command::doCommand(Gui::Command::Gui, "Gui.ActiveDocument.resetEdit()");
239

240
    return true;
241
}
242

243
bool TaskCosmeticCircle::reject()
244
{
245
    //there's nothing to do.
246
    Gui::Command::doCommand(Gui::Command::Gui, "Gui.ActiveDocument.resetEdit()");
247
    return false;
248
}
249
////////////////////////////////////////////////////////////////////////////////
250
TaskDlgCosmeticCircle::TaskDlgCosmeticCircle(TechDraw::DrawViewPart* partFeat,
251
                                     Base::Vector3d point,
252
                                     bool is3d)
253
    : TaskDialog()
254
{
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);
260
}
261

262
TaskDlgCosmeticCircle::TaskDlgCosmeticCircle(TechDraw::DrawViewPart* partFeat,
263
                                     std::string circleName)
264
    : TaskDialog()
265
{
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);
271
}
272

273
TaskDlgCosmeticCircle::~TaskDlgCosmeticCircle()
274
{
275
}
276

277
void TaskDlgCosmeticCircle::update()
278
{
279
//    widget->updateTask();
280
}
281

282
//==== calls from the TaskView ===============================================================
283
void TaskDlgCosmeticCircle::open()
284
{
285
}
286

287
void TaskDlgCosmeticCircle::clicked(int)
288
{
289
}
290

291
bool TaskDlgCosmeticCircle::accept()
292
{
293
    widget->accept();
294
    return true;
295
}
296

297
bool TaskDlgCosmeticCircle::reject()
298
{
299
    widget->reject();
300
    return true;
301
}
302

303
#include <Mod/TechDraw/Gui/moc_TaskCosmeticCircle.cpp>
304

305

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

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

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

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