FreeCAD

Форк
0
/
TaskCosmeticLine.cpp 
314 строк · 9.6 Кб
1
/***************************************************************************
2
 *   Copyright (c) 2020 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_TaskCosmeticLine.h"
40
#include "TaskCosmeticLine.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
TaskCosmeticLine::TaskCosmeticLine(TechDraw::DrawViewPart* partFeat,
50
                                   std::string edgeName) :
51
    ui(new Ui_TaskCosmeticLine),
52
    m_partFeat(partFeat),
53
    m_edgeName(edgeName),
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_edgeName);
61
    if (!m_ce) {
62
        Base::Console().Error("TaskCosmeticLine - bad parameters.  Can not proceed.\n");
63
        return;
64
    }
65

66
    ui->setupUi(this);
67

68
    setUiEdit();
69
}
70

71
//ctor for creation
72
TaskCosmeticLine::TaskCosmeticLine(TechDraw::DrawViewPart* partFeat,
73
                                   std::vector<Base::Vector3d> points,
74
                                   std::vector<bool> is3d) :
75
    ui(new Ui_TaskCosmeticLine),
76
    m_partFeat(partFeat),
77
    m_ce(nullptr),
78
    m_saveCE(nullptr),
79
    m_points(points),
80
    m_is3d(is3d),
81
    m_createMode(true)
82
{
83
    //existence of partFeat is checked in calling command
84

85
    ui->setupUi(this);
86

87
    setUiPrimary();
88
}
89

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

97
void TaskCosmeticLine::updateTask()
98
{
99
//    blockUpdate = true;
100

101
//    blockUpdate = false;
102
}
103

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

111
void TaskCosmeticLine::setUiPrimary()
112
{
113
    setWindowTitle(QObject::tr("Create Cosmetic Line"));
114

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);
124
    } else {
125
        // invert, unscale and unrotate the selected 2d point
126
        p1 = DU::invertY(m_points.front()) / m_partFeat->getScale();
127
        if (rotDeg != 0.0) {
128
            // we always rotate around the origin.
129
            p1.RotateZ(-rotRad);
130
        }
131
        ui->rb2d1->setChecked(true);
132
        ui->rb3d1->setChecked(false);
133
    }
134

135
    if (m_is3d.back()) {
136
        p2 = DrawUtil::invertY(m_partFeat->projectPoint(m_points.back() - centroid));
137
        ui->rb2d2->setChecked(false);
138
        ui->rb3d2->setChecked(true);
139
    } else {
140
        p2 = DU::invertY(m_points.back()) / m_partFeat->getScale();
141
        if (rotDeg != 0.0) {
142
            p2.RotateZ(-rotRad);
143
        }
144
        ui->rb2d2->setChecked(true);
145
        ui->rb3d2->setChecked(false);
146
    }
147

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

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

163
void TaskCosmeticLine::setUiEdit()
164
{
165
    setWindowTitle(QObject::tr("Edit Cosmetic Line"));
166

167
    ui->rb2d1->setChecked(true);
168
    ui->rb3d1->setChecked(false);
169
    ui->rb2d2->setChecked(true);
170
    ui->rb3d2->setChecked(false);
171

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

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);
181
}
182

183
//******************************************************************************
184
void TaskCosmeticLine::createCosmeticLine(void)
185
{
186
//    Base::Console().Message("TCL::createCosmeticLine()\n");
187
    Gui::Command::openCommand(QT_TRANSLATE_NOOP("Command", "Create Cosmetic Line"));
188

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

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

199
    m_tag = m_partFeat->addCosmeticEdge(p0, p1);
200
    m_ce = m_partFeat->getCosmeticEdge(m_tag);
201

202
    Gui::Command::commitCommand();
203
}
204

205
void TaskCosmeticLine::updateCosmeticLine(void)
206
{
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);
213

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

220
    //replace the geometry
221
    m_ce->permaStart = p0;
222
    m_ce->permaEnd = p1;
223

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);
228
}
229

230
//******************************************************************************
231

232
bool TaskCosmeticLine::accept()
233
{
234
    if (m_createMode) {
235
        createCosmeticLine();
236
        m_partFeat->add1CEToGE(m_tag);
237
        m_partFeat->refreshCEGeoms();
238
        m_partFeat->requestPaint();
239
    } else {
240
        //update mode
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();
247
    }
248

249
    Gui::Command::doCommand(Gui::Command::Gui, "Gui.ActiveDocument.resetEdit()");
250

251
    return true;
252
}
253

254
bool TaskCosmeticLine::reject()
255
{
256
    //there's nothing to do.
257
    Gui::Command::doCommand(Gui::Command::Gui, "Gui.ActiveDocument.resetEdit()");
258
    return false;
259
}
260
////////////////////////////////////////////////////////////////////////////////
261
TaskDlgCosmeticLine::TaskDlgCosmeticLine(TechDraw::DrawViewPart* partFeat,
262
                                     std::vector<Base::Vector3d> points,
263
                                     std::vector<bool> is3d)
264
    : TaskDialog()
265
{
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);
271
}
272

273
TaskDlgCosmeticLine::TaskDlgCosmeticLine(TechDraw::DrawViewPart* partFeat,
274
                                     std::string edgeName)
275
    : TaskDialog()
276
{
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);
282
}
283

284
TaskDlgCosmeticLine::~TaskDlgCosmeticLine()
285
{
286
}
287

288
void TaskDlgCosmeticLine::update()
289
{
290
//    widget->updateTask();
291
}
292

293
//==== calls from the TaskView ===============================================================
294
void TaskDlgCosmeticLine::open()
295
{
296
}
297

298
void TaskDlgCosmeticLine::clicked(int)
299
{
300
}
301

302
bool TaskDlgCosmeticLine::accept()
303
{
304
    widget->accept();
305
    return true;
306
}
307

308
bool TaskDlgCosmeticLine::reject()
309
{
310
    widget->reject();
311
    return true;
312
}
313

314
#include <Mod/TechDraw/Gui/moc_TaskCosmeticLine.cpp>
315

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

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

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

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