"Professional CMake" book suggest the following: "Targets should build successfully with or without compiler support for precompiled headers. It should be considered an optimization, not a requirement. In particular, do not explicitly include a precompile header (e.g. stdafx.h) in the source code, let CMake force-include an automatically generated precompile header on the compiler command line instead. This is more portable across the major compilers and is likely to be easier to maintain. It will also avoid warnings being generated from certain code checking tools like iwyu (include what you use)." Therefore, removed the "#include <PreCompiled.h>" from sources, also there is no need for the "#ifdef _PreComp_" anymore
325 lines
10 KiB
C++
325 lines
10 KiB
C++
/***************************************************************************
|
|
* Copyright (c) 2020 WandererFan <wandererfan@gmail.com> *
|
|
* *
|
|
* This file is part of the FreeCAD CAx development system. *
|
|
* *
|
|
* This library is free software; you can redistribute it and/or *
|
|
* modify it under the terms of the GNU Library General Public *
|
|
* License as published by the Free Software Foundation; either *
|
|
* version 2 of the License, or (at your option) any later version. *
|
|
* *
|
|
* This library is distributed in the hope that it will be useful, *
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
* GNU Library General Public License for more details. *
|
|
* *
|
|
* You should have received a copy of the GNU Library General Public *
|
|
* License along with this library; see the file COPYING.LIB. If not, *
|
|
* write to the Free Software Foundation, Inc., 59 Temple Place, *
|
|
* Suite 330, Boston, MA 02111-1307, USA *
|
|
* *
|
|
***************************************************************************/
|
|
|
|
# include <cmath>
|
|
# include <BRepBuilderAPI_MakeEdge.hxx>
|
|
|
|
|
|
#include <Base/Console.h>
|
|
#include <Gui/BitmapFactory.h>
|
|
#include <Gui/Command.h>
|
|
#include <Gui/Document.h>
|
|
#include <Gui/Selection/Selection.h>
|
|
#include <Mod/TechDraw/App/DrawUtil.h>
|
|
#include <Mod/TechDraw/App/DrawViewPart.h>
|
|
#include <Mod/TechDraw/App/Cosmetic.h>
|
|
#include <Mod/TechDraw/App/Geometry.h>
|
|
|
|
#include "ui_TaskCosmeticLine.h"
|
|
#include "TaskCosmeticLine.h"
|
|
|
|
|
|
using namespace Gui;
|
|
using namespace TechDraw;
|
|
using namespace TechDrawGui;
|
|
using DU = DrawUtil;
|
|
|
|
//ctor for edit
|
|
TaskCosmeticLine::TaskCosmeticLine(TechDraw::DrawViewPart* partFeat,
|
|
std::string edgeName) :
|
|
ui(new Ui_TaskCosmeticLine),
|
|
m_partFeat(partFeat),
|
|
m_edgeName(edgeName),
|
|
m_ce(nullptr),
|
|
m_saveCE(nullptr),
|
|
m_createMode(false)
|
|
{
|
|
//existence of partFeat is checked in calling command
|
|
|
|
m_ce = m_partFeat->getCosmeticEdgeBySelection(m_edgeName);
|
|
if (!m_ce) {
|
|
Base::Console().error("TaskCosmeticLine - bad parameters. Cannot proceed.\n");
|
|
return;
|
|
}
|
|
|
|
ui->setupUi(this);
|
|
|
|
setUiEdit();
|
|
}
|
|
|
|
//ctor for creation
|
|
TaskCosmeticLine::TaskCosmeticLine(TechDraw::DrawViewPart* partFeat,
|
|
std::vector<Base::Vector3d> points,
|
|
std::vector<bool> is3d) :
|
|
ui(new Ui_TaskCosmeticLine),
|
|
m_partFeat(partFeat),
|
|
m_ce(nullptr),
|
|
m_saveCE(nullptr),
|
|
m_points(points),
|
|
m_is3d(is3d),
|
|
m_createMode(true)
|
|
{
|
|
//existence of partFeat is checked in calling command
|
|
|
|
ui->setupUi(this);
|
|
|
|
setUiPrimary();
|
|
}
|
|
|
|
TaskCosmeticLine::~TaskCosmeticLine()
|
|
{
|
|
if (m_saveCE) {
|
|
delete m_saveCE;
|
|
}
|
|
}
|
|
|
|
void TaskCosmeticLine::updateTask()
|
|
{
|
|
// blockUpdate = true;
|
|
|
|
// blockUpdate = false;
|
|
}
|
|
|
|
void TaskCosmeticLine::changeEvent(QEvent *e)
|
|
{
|
|
if (e->type() == QEvent::LanguageChange) {
|
|
ui->retranslateUi(this);
|
|
}
|
|
}
|
|
|
|
void TaskCosmeticLine::setUiPrimary()
|
|
{
|
|
setWindowTitle(QObject::tr("Create Cosmetic Line"));
|
|
|
|
// double rotDeg = m_partFeat->Rotation.getValue();
|
|
// double rotRad = Base::toRadians(rotDeg);
|
|
Base::Vector3d centroid = m_partFeat->getCurrentCentroid();
|
|
Base::Vector3d p1, p2;
|
|
if (m_is3d.front()) {
|
|
// center, project and invert the 3d point
|
|
p1 = m_partFeat->projectPoint(m_points.front() - centroid);
|
|
} else {
|
|
// if the points are selected from 2d, they are already inverted
|
|
// unscale and unrotate the selected 2d point
|
|
p1 = CosmeticVertex::makeCanonicalPointInverted(m_partFeat, m_points.front());
|
|
}
|
|
|
|
if (m_is3d.back()) {
|
|
p2 = m_partFeat->projectPoint(m_points.back() - centroid);
|
|
} else {
|
|
p2 = CosmeticVertex::makeCanonicalPointInverted(m_partFeat, m_points.back());
|
|
}
|
|
|
|
// 3d points are projected above, so they are now 2d point and we need to set the radio buttons appropriately
|
|
ui->rb2d1->setChecked(true);
|
|
ui->rb3d1->setChecked(false);
|
|
|
|
ui->qsbx1->setUnit(Base::Unit::Length);
|
|
ui->qsbx1->setValue(p1.x);
|
|
ui->qsby1->setUnit(Base::Unit::Length);
|
|
ui->qsby1->setValue(-p1.y);
|
|
ui->qsby1->setUnit(Base::Unit::Length);
|
|
ui->qsbz1->setValue(p1.z);
|
|
|
|
ui->qsbx2->setUnit(Base::Unit::Length);
|
|
ui->qsbx2->setValue(p2.x);
|
|
ui->qsby2->setUnit(Base::Unit::Length);
|
|
ui->qsby2->setValue(-p2.y);
|
|
ui->qsbz2->setUnit(Base::Unit::Length);
|
|
ui->qsbz2->setValue(p2.z);
|
|
}
|
|
|
|
void TaskCosmeticLine::setUiEdit()
|
|
{
|
|
setWindowTitle(QObject::tr("Edit Cosmetic Line"));
|
|
|
|
ui->rb2d1->setChecked(true);
|
|
ui->rb3d1->setChecked(false);
|
|
ui->rb2d2->setChecked(true);
|
|
ui->rb3d2->setChecked(false);
|
|
|
|
Base::Vector3d p1 = DrawUtil::invertY(m_ce->permaStart);
|
|
ui->qsbx1->setValue(p1.x);
|
|
ui->qsby1->setValue(p1.y);
|
|
ui->qsbz1->setValue(p1.z);
|
|
|
|
Base::Vector3d p2 = DrawUtil::invertY(m_ce->permaEnd);
|
|
ui->qsbx2->setValue(p2.x);
|
|
ui->qsby2->setValue(p2.y);
|
|
ui->qsbz2->setValue(p2.z);
|
|
}
|
|
|
|
//******************************************************************************
|
|
void TaskCosmeticLine::createCosmeticLine()
|
|
{
|
|
// Base::Console().message("TCL::createCosmeticLine()\n");
|
|
Gui::Command::openCommand(QT_TRANSLATE_NOOP("Command", "Create Cosmetic Line"));
|
|
|
|
// ui 2d points are interpreted as unscaled, unrotated, uninverted
|
|
double x = ui->qsbx1->value().getValue();
|
|
double y = ui->qsby1->value().getValue();
|
|
double z = ui->qsbz1->value().getValue();
|
|
Base::Vector3d p0(x, y, z);
|
|
if (ui->rb3d1->isChecked()) {
|
|
Base::Vector3d centroid = m_partFeat->getCurrentCentroid();
|
|
p0 = m_partFeat->projectPoint(p0 - centroid);
|
|
} else {
|
|
p0 = DU::invertY(p0);
|
|
}
|
|
|
|
x = ui->qsbx2->value().getValue();
|
|
y = ui->qsby2->value().getValue();
|
|
z = ui->qsbz2->value().getValue();
|
|
Base::Vector3d p1(x, y, z);
|
|
if (ui->rb3d2->isChecked()) {
|
|
Base::Vector3d centroid = m_partFeat->getCurrentCentroid();
|
|
p1 = m_partFeat->projectPoint(p1 - centroid);
|
|
} else {
|
|
p1 = DU::invertY(p1);
|
|
}
|
|
m_tag = m_partFeat->addCosmeticEdge(p0, p1);
|
|
m_ce = m_partFeat->getCosmeticEdge(m_tag);
|
|
m_ce->setFormat(LineFormat::getCurrentLineFormat());
|
|
|
|
Gui::Command::commitCommand();
|
|
}
|
|
|
|
void TaskCosmeticLine::updateCosmeticLine()
|
|
{
|
|
// Base::Console().message("TCL::updateCosmeticLine()\n");
|
|
double x = ui->qsbx1->value().getValue();
|
|
double y = ui->qsby1->value().getValue();
|
|
double z = ui->qsbz1->value().getValue();
|
|
Base::Vector3d p0(x, y, z);
|
|
if (ui->rb3d1->isChecked()) {
|
|
Base::Vector3d centroid = m_partFeat->getCurrentCentroid();
|
|
p0 = m_partFeat->projectPoint(p0 - centroid);
|
|
} else {
|
|
p0 = DU::invertY(p0);
|
|
}
|
|
|
|
x = ui->qsbx2->value().getValue();
|
|
y = ui->qsby2->value().getValue();
|
|
z = ui->qsbz2->value().getValue();
|
|
Base::Vector3d p1(x, y, z);
|
|
if (ui->rb3d2->isChecked()) {
|
|
Base::Vector3d centroid = m_partFeat->getCurrentCentroid();
|
|
p1 = m_partFeat->projectPoint(p1 - centroid);
|
|
} else {
|
|
p1 = DU::invertY(p1);
|
|
}
|
|
//replace the geometry
|
|
m_ce->permaStart = p0;
|
|
m_ce->permaEnd = p1;
|
|
|
|
gp_Pnt gp1(p0.x, p0.y, p0.z);
|
|
gp_Pnt gp2(p1.x, p1.y, p1.z);
|
|
TopoDS_Edge edge = BRepBuilderAPI_MakeEdge(gp1, gp2);
|
|
m_ce->m_geometry = TechDraw::BaseGeom::baseFactory(edge);
|
|
}
|
|
|
|
//******************************************************************************
|
|
|
|
bool TaskCosmeticLine::accept()
|
|
{
|
|
if (m_createMode) {
|
|
createCosmeticLine();
|
|
m_partFeat->add1CEToGE(m_tag);
|
|
m_partFeat->refreshCEGeoms();
|
|
m_partFeat->requestPaint();
|
|
} else {
|
|
//update mode
|
|
Gui::Command::openCommand(QT_TRANSLATE_NOOP("Command", "Update Cosmetic Line"));
|
|
updateCosmeticLine();
|
|
m_partFeat->refreshCEGeoms();
|
|
m_partFeat->requestPaint();
|
|
Gui::Command::updateActive();
|
|
Gui::Command::commitCommand();
|
|
}
|
|
|
|
Gui::Command::doCommand(Gui::Command::Gui, "Gui.ActiveDocument.resetEdit()");
|
|
|
|
return true;
|
|
}
|
|
|
|
bool TaskCosmeticLine::reject()
|
|
{
|
|
//there's nothing to do.
|
|
Gui::Command::doCommand(Gui::Command::Gui, "Gui.ActiveDocument.resetEdit()");
|
|
return false;
|
|
}
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
TaskDlgCosmeticLine::TaskDlgCosmeticLine(TechDraw::DrawViewPart* partFeat,
|
|
std::vector<Base::Vector3d> points,
|
|
std::vector<bool> is3d)
|
|
: TaskDialog()
|
|
{
|
|
widget = new TaskCosmeticLine(partFeat, points, is3d);
|
|
taskbox = new Gui::TaskView::TaskBox(Gui::BitmapFactory().pixmap("actions/TechDraw_Line2Points"),
|
|
widget->windowTitle(), true, nullptr);
|
|
taskbox->groupLayout()->addWidget(widget);
|
|
Content.push_back(taskbox);
|
|
}
|
|
|
|
TaskDlgCosmeticLine::TaskDlgCosmeticLine(TechDraw::DrawViewPart* partFeat,
|
|
std::string edgeName)
|
|
: TaskDialog()
|
|
{
|
|
widget = new TaskCosmeticLine(partFeat, edgeName);
|
|
taskbox = new Gui::TaskView::TaskBox(Gui::BitmapFactory().pixmap("actions/TechDraw_Line2Points"),
|
|
widget->windowTitle(), true, nullptr);
|
|
taskbox->groupLayout()->addWidget(widget);
|
|
Content.push_back(taskbox);
|
|
}
|
|
|
|
TaskDlgCosmeticLine::~TaskDlgCosmeticLine()
|
|
{
|
|
}
|
|
|
|
void TaskDlgCosmeticLine::update()
|
|
{
|
|
// widget->updateTask();
|
|
}
|
|
|
|
//==== calls from the TaskView ===============================================================
|
|
void TaskDlgCosmeticLine::open()
|
|
{
|
|
}
|
|
|
|
void TaskDlgCosmeticLine::clicked(int)
|
|
{
|
|
}
|
|
|
|
bool TaskDlgCosmeticLine::accept()
|
|
{
|
|
widget->accept();
|
|
return true;
|
|
}
|
|
|
|
bool TaskDlgCosmeticLine::reject()
|
|
{
|
|
widget->reject();
|
|
return true;
|
|
}
|
|
|
|
#include <Mod/TechDraw/Gui/moc_TaskCosmeticLine.cpp>
|