[TD]Cosmetic function overhaul (#14216)
* [TD]Cosmetic geometry and tools update - all cosmetics to store geometry in same form - all cosmetics to survive scaling and rotation - extension functions to survive scaling and rotation * [TD]overhaul leader point storage and editing - add py routine makeLeader(points) * [TD]add leader conversion utility * [TD]Set Leader RotateWithView default to true * [TD]fix intersection vertex position * [TD]add CosmeticEdge::makeLineFromCanonicalPoints * [TD]fix 2 Extension tools - positioning in DrawCosmeticCircle - mishandling of points in execLineParallelPerpendicular * [TD]Remove duplicate constexpr * [TD]fix 2x Cosmetic arc tools * [TD]refactor LineFormat out of Cosmetic * [TD]move cosmetic appearance settings to LineFormat * [TD]remove 2 unused methods * [TD]apply format to blue line & circle tools * [TD]fix ballon arrowhead does not rotate with view * [TD]fix CosmeticCircle3Points * [TD]allow multiple cosmetic object deletions * [TD]fix extend/shorten centerline
This commit is contained in:
@@ -37,11 +37,8 @@
|
||||
#include "DrawUtil.h"
|
||||
#include "DrawViewPart.h"
|
||||
#include "GeometryObject.h"
|
||||
#include "LineGroup.h"
|
||||
#include "LineGenerator.h"
|
||||
#include "Preferences.h"
|
||||
|
||||
|
||||
using namespace TechDraw;
|
||||
using namespace std;
|
||||
using DU = DrawUtil;
|
||||
@@ -50,67 +47,11 @@ using DU = DrawUtil;
|
||||
#define COSMETICEDGE 1
|
||||
#define CENTERLINE 2
|
||||
|
||||
LineFormat::LineFormat()
|
||||
{
|
||||
m_style = getDefEdgeStyle();
|
||||
m_weight = getDefEdgeWidth();
|
||||
m_color= getDefEdgeColor();
|
||||
m_visible = true;
|
||||
m_lineNumber = LineGenerator::fromQtStyle((Qt::PenStyle)m_style);
|
||||
}
|
||||
|
||||
LineFormat::LineFormat(const int style,
|
||||
const double weight,
|
||||
const App::Color& color,
|
||||
const bool visible) :
|
||||
m_style(style),
|
||||
m_weight(weight),
|
||||
m_color(color),
|
||||
m_visible(visible),
|
||||
m_lineNumber(LineGenerator::fromQtStyle((Qt::PenStyle)m_style))
|
||||
{
|
||||
}
|
||||
|
||||
void LineFormat::dump(const char* title)
|
||||
{
|
||||
Base::Console().Message("LF::dump - %s \n", title);
|
||||
Base::Console().Message("LF::dump - %s \n", toString().c_str());
|
||||
}
|
||||
|
||||
std::string LineFormat::toString() const
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << m_style << ", " <<
|
||||
m_weight << ", " <<
|
||||
m_color.asHexString() << ", " <<
|
||||
m_visible;
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
//static preference getters.
|
||||
double LineFormat::getDefEdgeWidth()
|
||||
{
|
||||
return TechDraw::LineGroup::getDefaultWidth("Graphic");
|
||||
}
|
||||
|
||||
App::Color LineFormat::getDefEdgeColor()
|
||||
{
|
||||
return Preferences::normalColor();
|
||||
}
|
||||
|
||||
int LineFormat::getDefEdgeStyle()
|
||||
{
|
||||
return Preferences::getPreferenceGroup("Decorations")->GetInt("CenterLineStyle", 2); //dashed
|
||||
}
|
||||
|
||||
//******************************************
|
||||
|
||||
TYPESYSTEM_SOURCE(TechDraw::CosmeticEdge, Base::Persistence)
|
||||
|
||||
//note this ctor has no occEdge or first/last point for geometry!
|
||||
CosmeticEdge::CosmeticEdge()
|
||||
{
|
||||
// Base::Console().Message("CE::CE()\n");
|
||||
permaRadius = 0.0;
|
||||
m_geometry = std::make_shared<TechDraw::BaseGeom> ();
|
||||
initialize();
|
||||
@@ -118,7 +59,6 @@ CosmeticEdge::CosmeticEdge()
|
||||
|
||||
CosmeticEdge::CosmeticEdge(const CosmeticEdge* ce)
|
||||
{
|
||||
// Base::Console().Message("CE::CE(ce)\n");
|
||||
TechDraw::BaseGeomPtr newGeom = ce->m_geometry->copy();
|
||||
//these endpoints are already YInverted
|
||||
permaStart = ce->permaStart;
|
||||
@@ -130,13 +70,12 @@ CosmeticEdge::CosmeticEdge(const CosmeticEdge* ce)
|
||||
}
|
||||
|
||||
CosmeticEdge::CosmeticEdge(const Base::Vector3d& pt1, const Base::Vector3d& pt2) :
|
||||
// 🠓 returns TopoDS_Edge
|
||||
CosmeticEdge::CosmeticEdge(TopoDS_EdgeFromVectors(pt1, pt2))
|
||||
CosmeticEdge::CosmeticEdge(TopoDS_EdgeFromVectors(pt1, pt2))
|
||||
{
|
||||
}
|
||||
|
||||
// 🠓 returns TechDraw::BaseGeomPtr
|
||||
CosmeticEdge::CosmeticEdge(const TopoDS_Edge& e) : CosmeticEdge(TechDraw::BaseGeom::baseFactory(e))
|
||||
CosmeticEdge::CosmeticEdge(const TopoDS_Edge& e) :
|
||||
CosmeticEdge(TechDraw::BaseGeom::baseFactory(e))
|
||||
{
|
||||
}
|
||||
|
||||
@@ -153,6 +92,15 @@ CosmeticEdge::CosmeticEdge(const TechDraw::BaseGeomPtr g)
|
||||
permaStart = circ->center;
|
||||
permaEnd = circ->center;
|
||||
permaRadius = circ->radius;
|
||||
if (g->getGeomType() == TechDraw::GeomType::ARCOFCIRCLE) {
|
||||
TechDraw::AOCPtr aoc = std::static_pointer_cast<TechDraw::AOC>(circ);
|
||||
aoc->clockwiseAngle(g->clockwiseAngle());
|
||||
aoc->startPnt = g->getStartPoint();
|
||||
aoc->startAngle = g->getStartAngle();
|
||||
aoc->endPnt = g->getEndPoint();
|
||||
aoc->endAngle = g->getEndAngle();
|
||||
// aoc->largeArc = g->largeArc;
|
||||
}
|
||||
}
|
||||
initialize();
|
||||
}
|
||||
@@ -173,15 +121,10 @@ void CosmeticEdge::initialize()
|
||||
m_geometry->setCosmeticTag(getTagAsString());
|
||||
}
|
||||
|
||||
// TODO: not sure that this method should be doing the inversion. CV for example
|
||||
// accepts input point as is. The caller should have figured out the correct points.
|
||||
TopoDS_Edge CosmeticEdge::TopoDS_EdgeFromVectors(const Base::Vector3d& pt1, const Base::Vector3d& pt2)
|
||||
{
|
||||
// Base::Console().Message("CE::CE(p1, p2)\n");
|
||||
Base::Vector3d p1 = DrawUtil::invertY(pt1);
|
||||
Base::Vector3d p2 = DrawUtil::invertY(pt2);
|
||||
gp_Pnt gp1(p1.x, p1.y, p1.z);
|
||||
gp_Pnt gp2(p2.x, p2.y, p2.z);
|
||||
gp_Pnt gp1(pt1.x, pt1.y, pt1.z);
|
||||
gp_Pnt gp2(pt2.x, pt2.y, pt2.z);
|
||||
return BRepBuilderAPI_MakeEdge(gp1, gp2);
|
||||
}
|
||||
|
||||
@@ -202,7 +145,7 @@ TechDraw::BaseGeomPtr CosmeticEdge::scaledGeometry(const double scale)
|
||||
TechDraw::BaseGeomPtr CosmeticEdge::scaledAndRotatedGeometry(const double scale, const double rotDegrees)
|
||||
{
|
||||
TopoDS_Edge e = m_geometry->getOCCEdge();
|
||||
// TopoDS_Shape s = TechDraw::scaleShape(e, scale);
|
||||
bool saveCW = m_geometry->clockwiseAngle();
|
||||
// Mirror shape in Y and scale
|
||||
TopoDS_Shape s = ShapeUtils::mirrorShape(e, gp_Pnt(0.0, 0.0, 0.0), scale);
|
||||
// rotate using OXYZ as the coordinate system
|
||||
@@ -215,11 +158,11 @@ TechDraw::BaseGeomPtr CosmeticEdge::scaledAndRotatedGeometry(const double scale,
|
||||
newGeom->setCosmetic(true);
|
||||
newGeom->source(COSMETICEDGE);
|
||||
newGeom->setCosmeticTag(getTagAsString());
|
||||
newGeom->clockwiseAngle(saveCW);
|
||||
return newGeom;
|
||||
}
|
||||
|
||||
//! makes an unscaled, unrotated line from two scaled & rotated end points. If points is Gui space coordinates,
|
||||
//! they should be inverted (DU::invertY) before calling this method.
|
||||
//! makes an unscaled, unrotated line from two scaled & rotated end points.
|
||||
//! the result of this method should be used in addCosmeticEdge().
|
||||
TechDraw::BaseGeomPtr CosmeticEdge::makeCanonicalLine(DrawViewPart* dvp, Base::Vector3d start, Base::Vector3d end)
|
||||
{
|
||||
@@ -228,7 +171,16 @@ TechDraw::BaseGeomPtr CosmeticEdge::makeCanonicalLine(DrawViewPart* dvp, Base::V
|
||||
gp_Pnt gStart = DU::togp_Pnt(cStart);
|
||||
gp_Pnt gEnd = DU::togp_Pnt(cEnd);
|
||||
TopoDS_Edge edge = BRepBuilderAPI_MakeEdge(gStart, gEnd);
|
||||
return TechDraw::BaseGeom::baseFactory(edge)->inverted();
|
||||
return TechDraw::BaseGeom::baseFactory(edge);
|
||||
}
|
||||
|
||||
//! makes an unscaled, unrotated line from two canonical points.
|
||||
TechDraw::BaseGeomPtr CosmeticEdge::makeLineFromCanonicalPoints(Base::Vector3d start, Base::Vector3d end)
|
||||
{
|
||||
gp_Pnt gStart = DU::togp_Pnt(start);
|
||||
gp_Pnt gEnd = DU::togp_Pnt(end);
|
||||
TopoDS_Edge edge = BRepBuilderAPI_MakeEdge(gStart, gEnd);
|
||||
return TechDraw::BaseGeom::baseFactory(edge);
|
||||
}
|
||||
|
||||
std::string CosmeticEdge::toString() const
|
||||
@@ -261,10 +213,10 @@ void CosmeticEdge::Save(Base::Writer &writer) const
|
||||
{
|
||||
// TODO: this should be using m_format->Save(writer) instead of saving the individual
|
||||
// fields.
|
||||
writer.Stream() << writer.ind() << "<Style value=\"" << m_format.m_style << "\"/>" << endl;
|
||||
writer.Stream() << writer.ind() << "<Weight value=\"" << m_format.m_weight << "\"/>" << endl;
|
||||
writer.Stream() << writer.ind() << "<Color value=\"" << m_format.m_color.asHexString() << "\"/>" << endl;
|
||||
const char v = m_format.m_visible?'1':'0';
|
||||
writer.Stream() << writer.ind() << "<Style value=\"" << m_format.getStyle() << "\"/>" << endl;
|
||||
writer.Stream() << writer.ind() << "<Weight value=\"" << m_format.getWidth() << "\"/>" << endl;
|
||||
writer.Stream() << writer.ind() << "<Color value=\"" << m_format.getColor().asHexString() << "\"/>" << endl;
|
||||
const char v = m_format.getVisible() ? '1' : '0';
|
||||
writer.Stream() << writer.ind() << "<Visible value=\"" << v << "\"/>" << endl;
|
||||
|
||||
writer.Stream() << writer.ind() << "<GeometryType value=\"" << m_geometry->getGeomType() <<"\"/>" << endl;
|
||||
@@ -292,14 +244,16 @@ void CosmeticEdge::Restore(Base::XMLReader &reader)
|
||||
}
|
||||
// Base::Console().Message("CE::Restore - reading elements\n");
|
||||
reader.readElement("Style");
|
||||
m_format.m_style = reader.getAttributeAsInteger("value");
|
||||
m_format.setStyle(reader.getAttributeAsInteger("value"));
|
||||
reader.readElement("Weight");
|
||||
m_format.m_weight = reader.getAttributeAsFloat("value");
|
||||
m_format.setWidth(reader.getAttributeAsFloat("value"));
|
||||
reader.readElement("Color");
|
||||
std::string temp = reader.getAttribute("value");
|
||||
m_format.m_color.fromHexString(temp);
|
||||
std::string tempHex = reader.getAttribute("value");
|
||||
App::Color tempColor;
|
||||
tempColor.fromHexString(tempHex);
|
||||
m_format.setColor(tempColor);
|
||||
reader.readElement("Visible");
|
||||
m_format.m_visible = reader.getAttributeAsInteger("value") != 0;
|
||||
m_format.setVisible(reader.getAttributeAsInteger("value") != 0);
|
||||
|
||||
reader.readElement("GeometryType");
|
||||
TechDraw::GeomType gType = static_cast<TechDraw::GeomType>(reader.getAttributeAsInteger("value"));
|
||||
@@ -378,20 +332,12 @@ void CosmeticEdge::assignTag(const TechDraw::CosmeticEdge* ce)
|
||||
throw Base::TypeError("CosmeticEdge tag can not be assigned as types do not match.");
|
||||
}
|
||||
|
||||
CosmeticEdge* CosmeticEdge::copy() const
|
||||
{
|
||||
// Base::Console().Message("CE::copy()\n");
|
||||
CosmeticEdge* newCE = new CosmeticEdge();
|
||||
TechDraw::BaseGeomPtr newGeom = m_geometry->copy();
|
||||
newCE->m_geometry = newGeom;
|
||||
newCE->m_format = m_format;
|
||||
return newCE;
|
||||
}
|
||||
|
||||
CosmeticEdge* CosmeticEdge::clone() const
|
||||
{
|
||||
// Base::Console().Message("CE::clone()\n");
|
||||
CosmeticEdge* cpy = this->copy();
|
||||
Base::Console().Message("CE::clone()\n");
|
||||
CosmeticEdge* cpy = new CosmeticEdge();
|
||||
cpy->m_geometry = m_geometry->copy();
|
||||
cpy->m_format = m_format;
|
||||
cpy->tag = this->tag;
|
||||
return cpy;
|
||||
}
|
||||
@@ -412,10 +358,10 @@ TYPESYSTEM_SOURCE(TechDraw::GeomFormat, Base::Persistence)
|
||||
GeomFormat::GeomFormat() :
|
||||
m_geomIndex(-1)
|
||||
{
|
||||
m_format.m_style = LineFormat::getDefEdgeStyle();
|
||||
m_format.m_weight = LineFormat::getDefEdgeWidth();
|
||||
m_format.m_color = LineFormat::getDefEdgeColor();
|
||||
m_format.m_visible = true;
|
||||
m_format.setStyle(LineFormat::getDefEdgeStyle());
|
||||
m_format.setWidth(LineFormat::getDefEdgeWidth());
|
||||
m_format.setColor(LineFormat::getDefEdgeColor());
|
||||
m_format.setVisible(true);
|
||||
m_format.setLineNumber(LineFormat::InvalidLine);
|
||||
|
||||
createNewTag();
|
||||
@@ -424,10 +370,10 @@ GeomFormat::GeomFormat() :
|
||||
GeomFormat::GeomFormat(const GeomFormat* gf)
|
||||
{
|
||||
m_geomIndex = gf->m_geomIndex;
|
||||
m_format.m_style = gf->m_format.m_style;
|
||||
m_format.m_weight = gf->m_format.m_weight;
|
||||
m_format.m_color = gf->m_format.m_color;
|
||||
m_format.m_visible = gf->m_format.m_visible;
|
||||
m_format.setStyle(gf->m_format.getStyle());
|
||||
m_format.setWidth(gf->m_format.getWidth());
|
||||
m_format.setColor(gf->m_format.getColor());
|
||||
m_format.setVisible(gf->m_format.getVisible());
|
||||
m_format.setLineNumber(gf->m_format.getLineNumber());
|
||||
|
||||
createNewTag();
|
||||
@@ -437,10 +383,10 @@ GeomFormat::GeomFormat(const int idx,
|
||||
const TechDraw::LineFormat& fmt) :
|
||||
m_geomIndex(idx)
|
||||
{
|
||||
m_format.m_style = fmt.m_style;
|
||||
m_format.m_weight = fmt.m_weight;
|
||||
m_format.m_color = fmt.m_color;
|
||||
m_format.m_visible = fmt.m_visible;
|
||||
m_format.setStyle(fmt.getStyle());
|
||||
m_format.setWidth(fmt.getWidth());
|
||||
m_format.setColor(fmt.getColor());
|
||||
m_format.setVisible(fmt.getVisible());
|
||||
m_format.setLineNumber(fmt.getLineNumber());
|
||||
|
||||
createNewTag();
|
||||
@@ -472,13 +418,13 @@ unsigned int GeomFormat::getMemSize () const
|
||||
|
||||
void GeomFormat::Save(Base::Writer &writer) const
|
||||
{
|
||||
const char v = m_format.m_visible?'1':'0';
|
||||
const char v = m_format.getVisible() ? '1' : '0';
|
||||
writer.Stream() << writer.ind() << "<GeomIndex value=\"" << m_geomIndex << "\"/>" << endl;
|
||||
// style is deprecated in favour of line number, but we still save and restore it
|
||||
// to avoid problems with old documents.
|
||||
writer.Stream() << writer.ind() << "<Style value=\"" << m_format.m_style << "\"/>" << endl;
|
||||
writer.Stream() << writer.ind() << "<Weight value=\"" << m_format.m_weight << "\"/>" << endl;
|
||||
writer.Stream() << writer.ind() << "<Color value=\"" << m_format.m_color.asHexString() << "\"/>" << endl;
|
||||
writer.Stream() << writer.ind() << "<Style value=\"" << m_format.getStyle() << "\"/>" << endl;
|
||||
writer.Stream() << writer.ind() << "<Weight value=\"" << m_format.getWidth() << "\"/>" << endl;
|
||||
writer.Stream() << writer.ind() << "<Color value=\"" << m_format.getColor().asHexString() << "\"/>" << endl;
|
||||
writer.Stream() << writer.ind() << "<Visible value=\"" << v << "\"/>" << endl;
|
||||
writer.Stream() << writer.ind() << "<LineNumber value=\"" << m_format.getLineNumber() << "\"/>" << endl;
|
||||
}
|
||||
@@ -496,14 +442,16 @@ void GeomFormat::Restore(Base::XMLReader &reader)
|
||||
// style is deprecated in favour of line number, but we still save and restore it
|
||||
// to avoid problems with old documents.
|
||||
reader.readElement("Style");
|
||||
m_format.m_style = reader.getAttributeAsInteger("value");
|
||||
m_format.setStyle(reader.getAttributeAsInteger("value"));
|
||||
reader.readElement("Weight");
|
||||
m_format.m_weight = reader.getAttributeAsFloat("value");
|
||||
m_format.setWidth(reader.getAttributeAsFloat("value"));
|
||||
reader.readElement("Color");
|
||||
std::string temp = reader.getAttribute("value");
|
||||
m_format.m_color.fromHexString(temp);
|
||||
std::string tempHex = reader.getAttribute("value");
|
||||
App::Color tempColor;
|
||||
tempColor.fromHexString(tempHex);
|
||||
m_format.setColor(tempColor);
|
||||
reader.readElement("Visible");
|
||||
m_format.m_visible = (int)reader.getAttributeAsInteger("value")==0?false:true;
|
||||
m_format.setVisible((int)reader.getAttributeAsInteger("value") == 0 ? false : true);
|
||||
// older documents may not have the LineNumber element, so we need to check the
|
||||
// next entry. if it is a start element, then we check if it is a start element
|
||||
// for LineNumber.
|
||||
@@ -566,10 +514,10 @@ GeomFormat* GeomFormat::copy() const
|
||||
{
|
||||
GeomFormat* newFmt = new GeomFormat();
|
||||
newFmt->m_geomIndex = m_geomIndex;
|
||||
newFmt->m_format.m_style = m_format.m_style;
|
||||
newFmt->m_format.m_weight = m_format.m_weight;
|
||||
newFmt->m_format.m_color = m_format.m_color;
|
||||
newFmt->m_format.m_visible = m_format.m_visible;
|
||||
newFmt->m_format.setStyle(m_format.getStyle());
|
||||
newFmt->m_format.setWidth(m_format.getWidth());
|
||||
newFmt->m_format.setColor(m_format.getColor());
|
||||
newFmt->m_format.setVisible(m_format.getVisible());
|
||||
newFmt->m_format.setLineNumber(m_format.getLineNumber());
|
||||
return newFmt;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user