Skip to content

Commit

Permalink
[TD]Fix crash on same end points
Browse files Browse the repository at this point in the history
  • Loading branch information
WandererFan committed Jul 20, 2019
1 parent 3aa6fa1 commit 517b11e
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 69 deletions.
27 changes: 18 additions & 9 deletions src/Mod/TechDraw/App/Cosmetic.cpp
Expand Up @@ -34,6 +34,7 @@
#include <TopoDS_Edge.hxx>
#include <BRepBndLib.hxx>
#include <Bnd_Box.hxx>
#include <Precision.hxx>
#endif // #ifndef _PreComp_

#include <Base/Console.h>
Expand Down Expand Up @@ -492,7 +493,10 @@ CenterLine::~CenterLine()
{
}

CenterLine* CenterLine::CenterLineBuilder(DrawViewPart* partFeat, std::vector<std::string> subNames, int mode)
CenterLine* CenterLine::CenterLineBuilder(DrawViewPart* partFeat,
std::vector<std::string> subNames,
int mode,
bool flip)
{
// Base::Console().Message("CL::CLBuilder()\n");
std::pair<Base::Vector3d, Base::Vector3d> ends;
Expand All @@ -516,27 +520,31 @@ CenterLine* CenterLine::CenterLineBuilder(DrawViewPart* partFeat, std::vector<st
subNames,
mode,
0.0,
0.0, 0.0, 0.0, false);
0.0, 0.0, 0.0, flip);
edges = subNames;
} else if (geomType == "Vertex") {
type = CLTYPE::VERTEX;
ends = TechDraw::CenterLine::calcEndPoints2Points(partFeat,
subNames,
mode,
0.0,
0.0, 0.0, 0.0, false);
0.0, 0.0, 0.0, flip);
verts = subNames;
}
if ((ends.first).IsEqual(ends.second, Precision::Confusion())) {
Base::Console().Warning("CenterLineBuilder - endpoints are equal: %s\n",
DrawUtil::formatVector(ends.first).c_str());
Base::Console().Warning("CenterLineBuilder - check V/H/A and/or Flip parameters\n");
return nullptr;
}
TechDraw::CenterLine* cl = new TechDraw::CenterLine(ends.first, ends.second);
if (cl != nullptr) {
// cl->m_start = ends.first;
// cl->m_end = ends.second;
cl->m_type = type;
cl->m_mode = mode;
cl->m_faces = faces;
cl->m_edges = edges;
cl->m_verts = verts;
// cl->m_flip2Line = false;
cl->m_flip2Line = flip;
}
return cl;
}
Expand Down Expand Up @@ -732,7 +740,7 @@ std::pair<Base::Vector3d, Base::Vector3d> CenterLine::calcEndPoints2Lines(DrawVi
double rotate, bool flip)

{
// Base::Console().Message("CL::calc2Lines()\n");
// Base::Console().Message("CL::calc2Lines() - mode: %d flip: %d\n", mode, flip);
std::pair<Base::Vector3d, Base::Vector3d> result;
if (edgeNames.empty()) {
Base::Console().Message("CL::calcEndPoints2Lines - no edges!\n");
Expand Down Expand Up @@ -760,12 +768,13 @@ std::pair<Base::Vector3d, Base::Vector3d> CenterLine::calcEndPoints2Lines(DrawVi
Base::Vector3d l2p1 = edges.back()->getStartPoint();
Base::Vector3d l2p2 = edges.back()->getEndPoint();

if (flip) {
if (flip) { //reverse line 2
Base::Vector3d temp;
temp = l2p1;
l2p1 = l2p2;
l2p2 = temp;
}

Base::Vector3d p1 = (l1p1 + l2p1) / 2.0;
Base::Vector3d p2 = (l1p2 + l2p2) / 2.0;
Base::Vector3d mid = (p1 + p2) / 2.0;
Expand Down Expand Up @@ -861,7 +870,7 @@ std::pair<Base::Vector3d, Base::Vector3d> CenterLine::calcEndPoints2Points(DrawV
Base::Vector3d p1 = mid + clDir * (length / 2.0);
Base::Vector3d p2 = mid - clDir * (length / 2.0);

if (flip) {
if (flip) { //is flip relevant to 2 point???
Base::Vector3d temp;
temp = p1;
p1 = p2;
Expand Down
3 changes: 2 additions & 1 deletion src/Mod/TechDraw/App/Cosmetic.h
Expand Up @@ -170,7 +170,8 @@ class TechDrawExport CenterLine: public Base::Persistence

static CenterLine* CenterLineBuilder(TechDraw::DrawViewPart* partFeat,
std::vector<std::string> subs,
int mode = 0);
int mode = 0,
bool flip = false);
TechDraw::BaseGeom* scaledGeometry(TechDraw::DrawViewPart* partFeat);
static std::pair<Base::Vector3d, Base::Vector3d> calcEndPoints(
TechDraw::DrawViewPart* partFeat,
Expand Down
82 changes: 23 additions & 59 deletions src/Mod/TechDraw/Gui/TaskCenterLine.cpp
Expand Up @@ -242,64 +242,27 @@ void TaskCenterLine::createCenterLine(void)
} else if (ui->rbAligned->isChecked()) {
m_mode = CenterLine::CLMODE::ALIGNED;
}

//TODO: call CLBuilder here.
if (m_type == CenterLine::CLTYPE::FACE) {
ends = TechDraw::CenterLine::calcEndPoints(m_partFeat,
m_subNames,
m_mode,
extendBy,
hShift, vShift, rotate);
} else if (m_type == CenterLine::CLTYPE::EDGE) {
ends = TechDraw::CenterLine::calcEndPoints2Lines(m_partFeat,
m_subNames,
m_mode,
extendBy,
hShift, vShift, rotate, m_flipped);
} else if (m_type == CenterLine::CLTYPE::VERTEX) {
ends = TechDraw::CenterLine::calcEndPoints2Points(m_partFeat,
m_subNames,
m_mode,
extendBy,
hShift, vShift, rotate, m_flipped);
}

TechDraw::CenterLine* cl = new TechDraw::CenterLine(ends.first, ends.second);
cl->m_start = ends.first;
cl->m_end = ends.second;

//TODO: cl->setShifts(hShift, vShift);
// cl->setExtend(extendBy);
// cl->setRotate(rotate);
// cl->setFlip(m_flipped);
App::Color ac;
ac.setValue<QColor>(ui->cpLineColor->color());
cl->m_format.m_color = ac;
cl->m_format.m_weight = ui->dsbWeight->value();
cl->m_format.m_style = ui->cboxStyle->currentIndex() + 1; //Qt Styles start at 0:NoLine
cl->m_format.m_visible = true;

//TODO: CLBuilder replaces this
if (m_type == CenterLine::CLTYPE::FACE) {
cl->m_faces = m_subNames;
} else if (m_type == CenterLine::CLTYPE::EDGE) {
cl->m_edges = m_subNames;
} else if (m_type == CenterLine::CLTYPE::VERTEX) {
cl->m_verts = m_subNames;
TechDraw::CenterLine* cl = CenterLine::CenterLineBuilder(m_partFeat,
m_subNames,
m_mode,
m_flipped);
if (cl != nullptr) {
cl->setShifts(hShift, vShift);
cl->setExtend(extendBy);
cl->setRotate(rotate);
cl->setFlip(m_flipped);
App::Color ac;
ac.setValue<QColor>(ui->cpLineColor->color());
cl->m_format.m_color = ac;
cl->m_format.m_weight = ui->dsbWeight->value();
cl->m_format.m_style = ui->cboxStyle->currentIndex() + 1; //Qt Styles start at 0:NoLine
cl->m_format.m_visible = true;
m_partFeat->addCenterLine(cl);
} else {
Base::Console().Log("TCL::createCenterLine - CenterLine creation failed!\n");
}

cl->m_mode = m_mode;
cl->m_rotate = rotate;
cl->m_vShift = vShift;
cl->m_hShift = hShift;
cl->m_extendBy = extendBy;
cl->m_mode = m_mode;
cl->m_type = m_type;
cl->m_flip2Line = m_flipped;
//end TODO

m_partFeat->addCenterLine(cl);

m_partFeat->recomputeFeature();
Gui::Command::updateActive();
Gui::Command::commitCommand();
Expand Down Expand Up @@ -391,6 +354,7 @@ double TaskCenterLine::getExtendBy(void)

void TaskCenterLine::setFlipped(bool b)
{
// Base::Console().Message("TCL::setFlipped(%d)\n",b);
m_flipped = b;
}

Expand Down Expand Up @@ -458,19 +422,19 @@ void TaskCL2Lines::initUi()

void TaskCL2Lines::onFlipToggled(bool b)
{
Base::Console().Message("TCL2L::onFlipToggled(%d)\n", b);
// Base::Console().Message("TCL2L::onFlipToggled(%d)\n", b);
m_tcl->setFlipped(b);
}

bool TaskCL2Lines::accept()
{
Base::Console().Message("TCL2L::accept()\n");
// Base::Console().Message("TCL2L::accept()\n");
return true;
}

bool TaskCL2Lines::reject()
{
Base::Console().Message("TCL2L::reject()\n");
// Base::Console().Message("TCL2L::reject()\n");
return false;
}

Expand All @@ -496,7 +460,7 @@ TaskDlgCenterLine::TaskDlgCenterLine(TechDraw::DrawViewPart* partFeat,

cl2Lines = new TaskCL2Lines(widget);
linesBox = new Gui::TaskView::TaskBox(Gui::BitmapFactory().pixmap("actions/techdraw-2linecenterline"),
widget->windowTitle(), true, 0);
cl2Lines->windowTitle(), true, 0);
linesBox->groupLayout()->addWidget(cl2Lines);
Content.push_back(linesBox);

Expand Down

0 comments on commit 517b11e

Please sign in to comment.