[TD]draw line through 2 points

This commit is contained in:
wandererfan
2020-08-17 19:34:40 -04:00
committed by WandererFan
parent e9000a0989
commit fa111f86ad
12 changed files with 1169 additions and 5 deletions

View File

@@ -512,17 +512,24 @@ void CosmeticEdge::Restore(Base::XMLReader &reader)
gen->Restore(reader);
gen->occEdge = GeometryUtils::edgeFromGeneric(gen);
m_geometry = (TechDraw::BaseGeom*) gen;
permaStart = gen->getStartPoint();
permaEnd = gen->getEndPoint();
} else if (gType == TechDraw::GeomType::CIRCLE) {
TechDraw::Circle* circ = new TechDraw::Circle();
circ->Restore(reader);
circ->occEdge = GeometryUtils::edgeFromCircle(circ);
m_geometry = (TechDraw::BaseGeom*) circ;
permaRadius = circ->radius;
permaStart = circ->center;
permaEnd = circ->center;
} else if (gType == TechDraw::GeomType::ARCOFCIRCLE) {
TechDraw::AOC* aoc = new TechDraw::AOC();
aoc->Restore(reader);
aoc->occEdge = GeometryUtils::edgeFromCircleArc(aoc);
m_geometry = (TechDraw::BaseGeom*) aoc;
permaStart = aoc->startPnt;
permaEnd = aoc->endPnt;
permaRadius = aoc->radius;
} else {
Base::Console().Warning("CE::Restore - unimplemented geomType: %d\n", gType);
}

View File

@@ -1290,7 +1290,7 @@ void DrawViewPart::refreshCEGeoms(void)
std::vector<TechDraw::BaseGeom *> gEdges = getEdgeGeometry();
std::vector<TechDraw::BaseGeom *> oldGEdges;
for (auto& ge :gEdges) {
if (ge->getCosmeticTag().empty()) { //keep only non-ce edges
if (ge->source() != SourceType::COSEDGE) {
oldGEdges.push_back(ge);
}
}
@@ -1328,8 +1328,7 @@ void DrawViewPart::refreshCLGeoms(void)
std::vector<TechDraw::BaseGeom *> gEdges = getEdgeGeometry();
std::vector<TechDraw::BaseGeom *> newGEdges;
for (auto& ge :gEdges) {
//TODO: this will keep CE & CL
if (ge->getCosmeticTag().empty()) { //keep only non-cl edges
if (ge->source() != SourceType::CENTERLINE) {
newGEdges.push_back(ge);
}
}

View File

@@ -63,6 +63,11 @@
<UserDocu>tag = makeCosmeticLine(p1, p2) - add a CosmeticEdge from p1 to p2(View coordinates). Returns tag of new CosmeticEdge.</UserDocu>
</Documentation>
</Methode>
<Methode Name="makeCosmeticLine3D">
<Documentation>
<UserDocu>tag = makeCosmeticLine3D(p1, p2) - add a CosmeticEdge from p1 to p2(3D coordinates). Returns tag of new CosmeticEdge.</UserDocu>
</Documentation>
</Methode>
<Methode Name="makeCosmeticCircle">
<Documentation>
<UserDocu>tag = makeCosmeticCircle(center, radius) - add a CosmeticEdge at center with radius radius(View coordinates). Returns tag of new CosmeticEdge.</UserDocu>

View File

@@ -327,6 +327,53 @@ PyObject* DrawViewPartPy::makeCosmeticLine(PyObject *args)
return PyUnicode_FromString(newTag.c_str()); //return tag for new CE
}
PyObject* DrawViewPartPy::makeCosmeticLine3D(PyObject *args)
{
PyObject* pPnt1 = nullptr;
PyObject* pPnt2 = nullptr;
int style = LineFormat::getDefEdgeStyle();
double weight = LineFormat::getDefEdgeWidth();
App::Color defCol = LineFormat::getDefEdgeColor();
PyObject* pColor = nullptr;
if (!PyArg_ParseTuple(args, "O!O!|idO", &(Base::VectorPy::Type), &pPnt1,
&(Base::VectorPy::Type), &pPnt2,
&style, &weight,
&pColor)) {
throw Py::TypeError("expected (vector, vector,[style,weight,color])");
}
DrawViewPart* dvp = getDrawViewPartPtr();
Base::Vector3d centroid = dvp->getOriginalCentroid();
Base::Vector3d pnt1 = static_cast<Base::VectorPy*>(pPnt1)->value();
pnt1 = pnt1 - centroid;
pnt1 = DrawUtil::invertY(dvp->projectPoint(pnt1));
Base::Vector3d pnt2 = static_cast<Base::VectorPy*>(pPnt2)->value();
pnt2 = pnt2 - centroid;
pnt2 = DrawUtil::invertY(dvp->projectPoint(pnt2));
std::string newTag = dvp->addCosmeticEdge(pnt1, pnt2);
TechDraw::CosmeticEdge* ce = dvp->getCosmeticEdge(newTag);
if (ce != nullptr) {
ce->m_format.m_style = style;
ce->m_format.m_weight = weight;
if (pColor == nullptr) {
ce->m_format.m_color = defCol;
} else {
ce->m_format.m_color = DrawUtil::pyTupleToColor(pColor);
}
} else {
std::string msg = "DVPPI:makeCosmeticLine - line creation failed";
Base::Console().Message("%s\n",msg.c_str());
throw Py::RuntimeError(msg);
}
//int link =
dvp->add1CEToGE(newTag);
dvp->requestPaint();
return PyUnicode_FromString(newTag.c_str()); //return tag for new CE
}
PyObject* DrawViewPartPy::makeCosmeticCircle(PyObject *args)
{
PyObject* pPnt1 = nullptr;

View File

@@ -75,6 +75,7 @@ set(TechDrawGui_MOC_HDRS
TaskActiveView.h
TaskDetail.h
QGIGhostHighlight.h
TaskCosmeticLine.h
)
fc_wrap_cpp(TechDrawGui_MOC_SRCS ${TechDrawGui_MOC_HDRS})
@@ -112,6 +113,7 @@ set(TechDrawGui_UIC_SRCS
SymbolChooser.ui
TaskActiveView.ui
TaskDetail.ui
TaskCosmeticLine.ui
)
if(BUILD_QT5)
@@ -226,6 +228,9 @@ SET(TechDrawGui_SRCS
TaskDetail.h
PreferencesGui.cpp
PreferencesGui.h
TaskCosmeticLine.ui
TaskCosmeticLine.cpp
TaskCosmeticLine.h
)
SET(TechDrawGuiView_SRCS
@@ -393,6 +398,7 @@ SET(TechDrawGuiTaskDlgs_SRCS
SymbolChooser.ui
TaskActiveView.ui
TaskDetail.ui
TaskCosmeticLine.ui
)
SOURCE_GROUP("TaskDialogs" FILES ${TechDrawGuiTaskDlgs_SRCS})

View File

@@ -64,6 +64,7 @@
#include "TaskCenterLine.h"
#include "TaskLineDecor.h"
#include "TaskWeldingSymbol.h"
#include "TaskCosmeticLine.h"
#include "ViewProviderPage.h"
#include "ViewProviderViewPart.h"
#include "QGVPage.h"
@@ -82,6 +83,7 @@ void execQuadrants(Gui::Command* cmd);
void execCenterLine(Gui::Command* cmd);
void exec2LineCenterLine(Gui::Command* cmd);
void exec2PointCenterLine(Gui::Command* cmd);
void execLine2Points(Gui::Command* cmd);
std::vector<std::string> getSelectedSubElements(Gui::Command* cmd,
TechDraw::DrawViewPart* &dvp,
std::string subType = "Edge");
@@ -136,7 +138,9 @@ void CmdTechDrawLeaderLine::activated(int iMsg)
}
Gui::Control().showDialog(new TechDrawGui::TaskDlgLeaderLine(baseFeat,
page));
page));
updateActive();
Gui::Selection().clearSelection();
}
bool CmdTechDrawLeaderLine::isActive(void)
@@ -187,6 +191,8 @@ void CmdTechDrawRichTextAnnotation::activated(int iMsg)
Gui::Control().showDialog(new TaskDlgRichAnno(baseFeat,
page));
updateActive();
Gui::Selection().clearSelection();
}
bool CmdTechDrawRichTextAnnotation::isActive(void)
@@ -239,6 +245,8 @@ void CmdTechDrawCosmeticVertexGroup::activated(int iMsg)
default:
Base::Console().Message("CMD::CVGrp - invalid iMsg: %d\n",iMsg);
};
updateActive();
Gui::Selection().clearSelection();
}
Gui::Action * CmdTechDrawCosmeticVertexGroup::createAction(void)
@@ -423,6 +431,8 @@ void CmdTechDrawCosmeticVertex::activated(int iMsg)
Gui::Control().showDialog(new TaskDlgCosVertex(baseFeat,
page));
updateActive();
Gui::Selection().clearSelection();
}
bool CmdTechDrawCosmeticVertex::isActive(void)
@@ -870,6 +880,8 @@ void CmdTechDraw2PointCenterLine::activated(int iMsg)
}
exec2PointCenterLine(this);
updateActive();
Gui::Selection().clearSelection();
}
bool CmdTechDraw2PointCenterLine::isActive(void)
@@ -951,6 +963,155 @@ void exec2PointCenterLine(Gui::Command* cmd)
}
}
//===========================================================================
// TechDraw_2PointCosmeticLine
//===========================================================================
DEF_STD_CMD_A(CmdTechDraw2PointCosmeticLine)
CmdTechDraw2PointCosmeticLine::CmdTechDraw2PointCosmeticLine()
: Command("TechDraw_2PointCosmeticLine")
{
sAppModule = "TechDraw";
sGroup = QT_TR_NOOP("TechDraw");
sMenuText = QT_TR_NOOP("Add Cosmetic Line Through 2 Points");
sToolTipText = sMenuText;
sWhatsThis = "TechDraw_2PointCosmeticLine";
sStatusTip = sToolTipText;
sPixmap = "actions/techdraw-line2points";
}
void CmdTechDraw2PointCosmeticLine::activated(int iMsg)
{
Q_UNUSED(iMsg);
Gui::TaskView::TaskDialog *dlg = Gui::Control().activeDialog();
if (dlg != nullptr) {
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Task In Progress"),
QObject::tr("Close active task dialog and try again."));
return;
}
execLine2Points(this);
updateActive();
Gui::Selection().clearSelection();
}
bool CmdTechDraw2PointCosmeticLine::isActive(void)
{
bool havePage = DrawGuiUtil::needPage(this);
bool haveView = DrawGuiUtil::needView(this, true);
return (havePage && haveView);
}
void execLine2Points(Gui::Command* cmd)
{
TechDraw::DrawPage* page = DrawGuiUtil::findPage(cmd);
if (!page) {
return;
}
std::vector<Gui::SelectionObject> selection = cmd->getSelection().getSelectionEx();
TechDraw::DrawViewPart* baseFeat = nullptr;
std::vector<std::string> subNames2D;
std::vector< std::pair<Part::Feature*, std::string> > objs3D;
if (!selection.empty()) {
for (auto& so: selection) {
if (so.getObject()->isDerivedFrom(TechDraw::DrawViewPart::getClassTypeId())) {
baseFeat = static_cast<TechDraw::DrawViewPart*> (so.getObject());
subNames2D = so.getSubNames();
} else if (so.getObject()->isDerivedFrom(Part::Feature::getClassTypeId())) {
std::vector<std::string> subNames3D = so.getSubNames();
for (auto& sub3D: subNames3D) {
std::pair<Part::Feature*, std::string> temp;
temp.first = static_cast<Part::Feature*>(so.getObject());
temp.second = sub3D;
objs3D.push_back(temp);
}
} else {
//garbage
}
}
} else {
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong Selection"),
QObject::tr("Selection is empty."));
return;
}
if (baseFeat == nullptr) {
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong Selection"),
QObject::tr("You must select a base View for the line."));
return;
}
//TODO: should be a smarter check
if ( (subNames2D.empty()) &&
(objs3D.empty()) ) {
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong Selection"),
QObject::tr("Not enough points in selection."));
return;
}
std::vector<std::string> edgeNames;
std::vector<std::string> vertexNames;
for (auto& s: subNames2D) {
std::string geomType = DrawUtil::getGeomTypeFromName(s);
if (geomType == "Vertex") {
vertexNames.push_back(s);
} else if (geomType == "Edge") {
edgeNames.push_back(s);
}
}
//check if editing existing edge
if (!edgeNames.empty() && (edgeNames.size() == 1)) {
TechDraw::CosmeticEdge* ce = baseFeat->getCosmeticEdgeBySelection(edgeNames.front());
if (ce == nullptr) {
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong Selection"),
QObject::tr("Selection is not a Cosmetic Line."));
return;
}
Gui::Control().showDialog(new TaskDlgCosmeticLine(baseFeat,
edgeNames.front()));
return;
}
double scale = baseFeat->getScale();
std::vector<Base::Vector3d> points;
std::vector<bool> is3d;
//get the 2D points
if (!vertexNames.empty()) {
for (auto& v2d: vertexNames) {
int idx = DrawUtil::getIndexFromName(v2d);
TechDraw::Vertex* v = baseFeat->getProjVertexByIndex(idx);
Base::Vector3d p = DrawUtil::invertY(v->pnt);
points.push_back(p / scale);
is3d.push_back(false);
}
}
//get the 3D points
if (!objs3D.empty()) {
for (auto& o3D: objs3D) {
int idx = DrawUtil::getIndexFromName(o3D.second);
Part::TopoShape s = o3D.first->Shape.getShape();
TopoDS_Vertex v = TopoDS::Vertex(s.getSubShape(TopAbs_VERTEX, idx));
Base::Vector3d p = DrawUtil::vertex2Vector(v);
points.push_back(p);
is3d.push_back(true);
}
}
if (points.size() != 2) {
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong Selection"),
QObject::tr("You must select 2 Vertexes."));
return;
}
Gui::Control().showDialog(new TaskDlgCosmeticLine(baseFeat,
points,
is3d));
}
//===========================================================================
// TechDraw_CosmeticEraser
@@ -1147,6 +1308,8 @@ void CmdTechDrawDecorateLine::activated(int iMsg)
Gui::Control().showDialog(new TaskDlgLineDecor(baseFeat,
edgeNames));
updateActive();
Gui::Selection().clearSelection();
}
bool CmdTechDrawDecorateLine::isActive(void)
@@ -1274,6 +1437,8 @@ void CmdTechDrawWeldSymbol::activated(int iMsg)
weldFeat = static_cast<TechDraw::DrawWeldSymbol*> (welds.front());
Gui::Control().showDialog(new TaskDlgWeldingSymbol(weldFeat));
}
updateActive();
Gui::Selection().clearSelection();
}
bool CmdTechDrawWeldSymbol::isActive(void)
@@ -1298,6 +1463,7 @@ void CreateTechDrawCommandsAnnotate(void)
rcCmdMgr.addCommand(new CmdTechDrawFaceCenterLine());
rcCmdMgr.addCommand(new CmdTechDraw2LineCenterLine());
rcCmdMgr.addCommand(new CmdTechDraw2PointCenterLine());
rcCmdMgr.addCommand(new CmdTechDraw2PointCosmeticLine());
rcCmdMgr.addCommand(new CmdTechDrawAnnotation());
rcCmdMgr.addCommand(new CmdTechDrawCosmeticEraser());
rcCmdMgr.addCommand(new CmdTechDrawDecorateLine());

View File

@@ -75,6 +75,7 @@
<file>icons/actions/techdraw-facecenterline.svg</file>
<file>icons/actions/techdraw-2linecenterline.svg</file>
<file>icons/actions/techdraw-2pointcenterline.svg</file>
<file>icons/actions/techdraw-line2points.svg</file>
<file>icons/actions/techdraw-CosmeticEraser.svg</file>
<file>icons/actions/techdraw-DecorateLine.svg</file>
<file>icons/actions/techdraw-facedecor.svg</file>

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 7.3 KiB

View File

@@ -0,0 +1,343 @@
/***************************************************************************
* 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 "PreCompiled.h"
#ifndef _PreComp_
#include <cmath>
#include <BRepBndLib.hxx>
#include <Bnd_Box.hxx>
#endif // #ifndef _PreComp_
#include <BRepBuilderAPI_MakeEdge.hxx>
#include <QButtonGroup>
#include <QStatusBar>
#include <QGraphicsScene>
#include <Base/Console.h>
#include <Base/Tools.h>
#include <Base/UnitsApi.h>
#include <Gui/Application.h>
#include <Gui/BitmapFactory.h>
#include <Gui/Command.h>
#include <Gui/Control.h>
#include <Gui/Document.h>
#include <Gui/MainWindow.h>
#include <Gui/Selection.h>
#include <Gui/ViewProvider.h>
#include <Gui/WaitCursor.h>
#include <Mod/TechDraw/App/DrawPage.h>
#include <Mod/TechDraw/App/DrawUtil.h>
#include <Mod/TechDraw/App/DrawView.h>
#include <Mod/TechDraw/App/DrawViewPart.h>
#include <Mod/TechDraw/App/Geometry.h>
#include <Mod/TechDraw/App/Cosmetic.h>
#include <Mod/TechDraw/Gui/ui_TaskCosmeticLine.h>
#include "DrawGuiStd.h"
#include "PreferencesGui.h"
#include "QGVPage.h"
#include "QGIView.h"
#include "QGIPrimPath.h"
#include "MDIViewPage.h"
#include "ViewProviderPage.h"
#include "ViewProviderViewPart.h"
#include "Rez.h"
#include "TaskCosmeticLine.h"
using namespace Gui;
using namespace TechDraw;
using namespace TechDrawGui;
//ctor for edit
TaskCosmeticLine::TaskCosmeticLine(TechDraw::DrawViewPart* partFeat,
std::string edgeName) :
ui(new Ui_TaskCosmeticLine),
m_partFeat(partFeat),
m_edgeName(edgeName),
m_saveCE(nullptr),
m_createMode(false)
{
if (m_partFeat == nullptr) {
//should be caught in CMD caller
Base::Console().Error("TaskCosmeticLine - bad parameters. Can not proceed.\n");
return;
}
m_ce = m_partFeat->getCosmeticEdgeBySelection(m_edgeName);
if (m_ce == nullptr) {
Base::Console().Error("TaskCosmeticLine - bad parameters. Can not 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_saveCE(nullptr),
m_points(points),
m_is3d(is3d),
m_createMode(true)
{
if (m_partFeat == nullptr) {
//should be caught in CMD caller
Base::Console().Error("TaskCosmeticLine - bad parameters. Can not proceed.\n");
return;
}
ui->setupUi(this);
setUiPrimary();
}
TaskCosmeticLine::~TaskCosmeticLine()
{
delete ui;
if (m_saveCE != nullptr) {
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"));
if (m_is3d.front()) {
ui->rb2d1->setChecked(false);
ui->rb3d1->setChecked(true);
} else {
ui->rb2d1->setChecked(true);
ui->rb3d1->setChecked(false);
}
if (m_is3d.back()) {
ui->rb2d2->setChecked(false);
ui->rb3d2->setChecked(true);
} else {
ui->rb2d2->setChecked(true);
ui->rb3d2->setChecked(false);
}
Base::Vector3d p1 = m_points.front();
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);
Base::Vector3d p2 = m_points.back();
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(void)
{
double x = ui->qsbx1->value().getValue();
double y = ui->qsby1->value().getValue();
double z = ui->qsbz1->value().getValue();
Base::Vector3d p0(x, y, z);
x = ui->qsbx2->value().getValue();
y = ui->qsby2->value().getValue();
z = ui->qsbz2->value().getValue();
Base::Vector3d p1(x, y, z);
Base::Vector3d centroid = m_partFeat->getOriginalCentroid();
if (ui->rb3d1->isChecked()) {
p0 = p0 - centroid;
p0 = DrawUtil::invertY(m_partFeat->projectPoint(p0));
}
if (ui->rb3d2->isChecked()) {
p1 = p1 - centroid;
p1 = DrawUtil::invertY(m_partFeat->projectPoint(p1));
}
m_tag = m_partFeat->addCosmeticEdge(p0, p1);
m_ce = m_partFeat->getCosmeticEdge(m_tag);
}
void TaskCosmeticLine::updateCosmeticLine(void)
{
double x = ui->qsbx1->value().getValue();
double y = ui->qsby1->value().getValue();
double z = ui->qsbz1->value().getValue();
Base::Vector3d p0(x, y, z);
p0 = DrawUtil::invertY(p0);
x = ui->qsbx2->value().getValue();
y = ui->qsby2->value().getValue();
z = ui->qsbz2->value().getValue();
Base::Vector3d p1(x, y, z);
p1 = DrawUtil::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 e = BRepBuilderAPI_MakeEdge(gp1, gp2);
auto oldGeom = m_ce->m_geometry;
m_ce->m_geometry = TechDraw::BaseGeom::baseFactory(e);
delete oldGeom;
// Gui::Command::updateActive();
// Gui::Command::commitCommand();
}
//******************************************************************************
bool TaskCosmeticLine::accept()
{
if (m_createMode) {
createCosmeticLine();
m_partFeat->add1CEToGE(m_tag);
m_partFeat->refreshCEGeoms();
m_partFeat->requestPaint();
} else {
//update mode
Gui::Command::openCommand("Update CosmeticLine");
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, 0);
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, 0);
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>

View File

@@ -0,0 +1,145 @@
/***************************************************************************
* 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 *
* *
***************************************************************************/
#ifndef TECHDRAWGUI_TASKCOSMETICLINE_H
#define TECHDRAWGUI_TASKCOSMETICLINE_H
#include <App/DocumentObject.h>
#include <Base/Vector3D.h>
#include <Gui/TaskView/TaskView.h>
#include <Gui/TaskView/TaskDialog.h>
#include <Mod/TechDraw/App/Cosmetic.h>
#include <Mod/TechDraw/Gui/ui_TaskCosmeticLine.h>
class Ui_TaskCosmeticLine;
namespace App {
class DocumentObject;
}
namespace TechDraw
{
class DrawPage;
class DrawView;
class DrawViewPart;
class CosmeticEdge;
class LineFormat;
}
namespace TechDraw
{
class Face;
}
namespace TechDrawGui
{
class QGVPage;
class QGIView;
class QGIPrimPath;
class MDIViewPage;
class ViewProviderViewPart;
class TaskCosmeticLine : public QWidget
{
Q_OBJECT
public:
TaskCosmeticLine(TechDraw::DrawViewPart* baseFeat,
std::vector<Base::Vector3d> points,
std::vector<bool> is3d);
TaskCosmeticLine(TechDraw::DrawViewPart* baseFeat,
std::string edgeName);
~TaskCosmeticLine();
public Q_SLOTS:
public:
virtual bool accept();
virtual bool reject();
void updateTask();
protected Q_SLOTS:
protected:
void changeEvent(QEvent *e);
void setUiPrimary(void);
void setUiEdit(void);
void createCosmeticLine(void);
void updateCosmeticLine(void);
private:
Ui_TaskCosmeticLine * ui;
TechDraw::DrawViewPart* m_partFeat;
std::string m_edgeName;
int m_edgeIndex;
TechDraw::CosmeticEdge* m_ce;
TechDraw::CosmeticEdge* m_saveCE;
std::vector<Base::Vector3d> m_points;
std::vector<bool> m_is3d;
bool m_createMode;
std::string m_tag;
};
class TaskDlgCosmeticLine : public Gui::TaskView::TaskDialog
{
Q_OBJECT
public:
TaskDlgCosmeticLine(TechDraw::DrawViewPart* baseFeat,
std::vector<Base::Vector3d> points,
std::vector<bool> is3d);
TaskDlgCosmeticLine(TechDraw::DrawViewPart* baseFeat,
std::string edgeName);
~TaskDlgCosmeticLine();
public:
/// is called the TaskView when the dialog is opened
virtual void open();
/// is called by the framework if an button is clicked which has no accept or reject role
virtual void clicked(int);
/// is called by the framework if the dialog is accepted (Ok)
virtual bool accept();
/// is called by the framework if the dialog is rejected (Cancel)
virtual bool reject();
/// is called by the framework if the user presses the help button
virtual void helpRequested() { return;}
virtual bool isAllowedAlterDocument(void) const
{ return false; }
void update();
protected:
private:
TaskCosmeticLine* widget;
Gui::TaskView::TaskBox* taskbox;
};
} //namespace TechDrawGui
#endif // #ifndef TECHDRAWGUI_TASKCOSMETICLINE_H

View File

@@ -0,0 +1,228 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>TechDrawGui::TaskCosmeticLine</class>
<widget class="QWidget" name="TechDrawGui::TaskCosmeticLine">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>350</width>
<height>331</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>250</width>
<height>0</height>
</size>
</property>
<property name="windowTitle">
<string>Cosmetic Line</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>View</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="le_View">
<property name="enabled">
<bool>false</bool>
</property>
<property name="mouseTracking">
<bool>false</bool>
</property>
<property name="focusPolicy">
<enum>Qt::NoFocus</enum>
</property>
<property name="acceptDrops">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0">
<widget class="QRadioButton" name="rb2d1">
<property name="text">
<string>2d Point</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
<property name="autoExclusive">
<bool>false</bool>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QRadioButton" name="rb3d1">
<property name="text">
<string>3d Point</string>
</property>
<property name="autoExclusive">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QGridLayout" name="gridLayout_3" columnstretch="1,4">
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>X:</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Y:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="Gui::QuantitySpinBox" name="qsbx1">
<property name="unit" stdset="0">
<string notr="true"/>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Z:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="Gui::QuantitySpinBox" name="qsby1">
<property name="unit" stdset="0">
<string notr="true"/>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="Gui::QuantitySpinBox" name="qsbz1">
<property name="unit" stdset="0">
<string notr="true"/>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QGridLayout" name="gridLayout_4">
<item row="0" column="0">
<widget class="QRadioButton" name="rb2d2">
<property name="text">
<string>2d Point</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
<property name="autoExclusive">
<bool>false</bool>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QRadioButton" name="rb3d2">
<property name="text">
<string>3d Point</string>
</property>
<property name="autoExclusive">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QGridLayout" name="gridLayout_5" columnstretch="1,4">
<item row="0" column="1">
<widget class="Gui::QuantitySpinBox" name="qsbx2">
<property name="unit" stdset="0">
<string notr="true"/>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label_5">
<property name="text">
<string>X:</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_6">
<property name="text">
<string>Y:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="Gui::QuantitySpinBox" name="qsby2">
<property name="unit" stdset="0">
<string notr="true"/>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_7">
<property name="text">
<string>Z:</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="Gui::QuantitySpinBox" name="qsbz2">
<property name="unit" stdset="0">
<string notr="true"/>
</property>
</widget>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>Gui::QuantitySpinBox</class>
<extends>QWidget</extends>
<header>Gui/QuantitySpinBox.h</header>
</customwidget>
</customwidgets>
<resources>
<include location="Resources/TechDraw.qrc"/>
</resources>
<connections/>
</ui>

View File

@@ -69,6 +69,7 @@ Gui::MenuItem* Workbench::setupMenuBar() const
lines->setCommand("Add Lines");
*lines << "TechDraw_LeaderLine" << "TechDraw_FaceCenterLine"
<< "TechDraw_2LineCenterLine" << "TechDraw_2PointCenterLine";
*lines << "TechDraw_2PointCosmeticLine";
// vertices
Gui::MenuItem* vertices = new Gui::MenuItem;
@@ -183,6 +184,7 @@ Gui::ToolBarItem* Workbench::setupToolBars() const
// *anno << "TechDraw_FaceCenterLine";
// *anno << "TechDraw_2LineCenterLine";
// *anno << "TechDraw_2PointCenterLine";
*anno << "TechDraw_2PointCosmeticLine";
*anno << "TechDraw_CosmeticEraser";
*anno << "TechDraw_DecorateLine";
*anno << "TechDraw_ShowAll";
@@ -256,6 +258,7 @@ Gui::ToolBarItem* Workbench::setupCommandBars() const
// *anno << "TechDraw_FaceCenterLine";
// *anno << "TechDraw_2LineCenterLine";
// *anno << "TechDraw_2PointCenterLine";
*anno << "TechDraw_2PointCosmeticLine";
*anno << "TechDraw_CosmeticEraser";
*anno << "TechDraw_DecorateLine";
*anno << "TechDraw_ShowAll";