[TD]Fix crash on same end points
This commit is contained in:
@@ -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>
|
||||
@@ -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;
|
||||
@@ -516,7 +520,7 @@ 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;
|
||||
@@ -524,19 +528,23 @@ 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);
|
||||
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;
|
||||
}
|
||||
@@ -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");
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
|
||||
@@ -170,7 +170,8 @@ public:
|
||||
|
||||
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,
|
||||
|
||||
@@ -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 = 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");
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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();
|
||||
@@ -391,6 +354,7 @@ double TaskCenterLine::getExtendBy(void)
|
||||
|
||||
void TaskCenterLine::setFlipped(bool b)
|
||||
{
|
||||
// Base::Console().Message("TCL::setFlipped(%d)\n",b);
|
||||
m_flipped = b;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user