[TD]draw line through 2 points

This commit is contained in:
wandererfan
2020-08-17 19:34:40 -04:00
committed by WandererFan
parent 1a6bbf8127
commit 1cad17c5f5
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;