Merge branch 'master' of github.com:FreeCAD/FreeCAD into TD-DetailWork

This commit is contained in:
donovaly
2020-05-31 00:24:29 +02:00
459 changed files with 22319 additions and 11994 deletions

View File

@@ -794,6 +794,8 @@ private:
Py::Object makeDistanceDim(const Py::Tuple& args)
{
//points come in unscaled,but makeDistDim unscales them so we need to prescale here.
//makeDistDim was built for extent dims which work from scaled geometry
PyObject* pDvp;
PyObject* pDimType;
PyObject* pFrom;
@@ -827,12 +829,14 @@ private:
if (PyObject_TypeCheck(pTo, &(Base::VectorPy::Type))) {
to = static_cast<Base::VectorPy*>(pTo)->value();
}
DrawViewDimension* dvd =
DrawDimHelper::makeDistDim(dvp,
dimType,
from,
to);
return Py::None();
DrawUtil::invertY(from),
DrawUtil::invertY(to));
PyObject* dvdPy = dvd->getPyObject();
return Py::asObject(dvdPy);
// return Py::None();
}
Py::Object makeDistanceDim3d(const Py::Tuple& args)
@@ -869,8 +873,10 @@ private:
if (PyObject_TypeCheck(pTo, &(Base::VectorPy::Type))) {
to = static_cast<Base::VectorPy*>(pTo)->value();
}
//3d points are not scaled
from = DrawUtil::invertY(dvp->projectPoint(from));
to = DrawUtil::invertY(dvp->projectPoint(to));
//DrawViewDimension* =
DrawDimHelper::makeDistDim(dvp,
dimType,
from,

View File

@@ -37,7 +37,9 @@ using namespace TechDraw;
// returns a string which represents the object e.g. when printed in python
std::string CenterLinePy::representation(void) const
{
return "<CenterLine object>";
std::stringstream ss;
ss << "<CenterLine object> at " << std::hex << this;
return ss.str();
}
PyObject *CenterLinePy::PyMake(struct _typeobject *, PyObject *, PyObject *) // Python wrapper
@@ -108,68 +110,8 @@ PyObject* CenterLinePy::copy(PyObject *args)
return cpy;
}
//PyObject* CenterLinePy::setFormat(PyObject* args)
//{
//// Base::Console().Message("CLPI::setFormat()\n");
// PyObject* pTuple;
// int style = 1;
// double weight = 0.50;
// double red = 0.0, green = 0.0, blue = 0.0, alpha = 0.0;
// App::Color c(red, blue, green, alpha);
// bool visible = 1;
// if (!PyArg_ParseTuple(args, "O", &pTuple)) {
// return NULL;
// }
//
// TechDraw::CenterLine* cl = this->getCenterLinePtr();
// if (PyTuple_Check(pTuple)) {
// int tSize = (int) PyTuple_Size(pTuple);
// if (tSize > 3) {
// PyObject* pStyle = PyTuple_GetItem(pTuple,0);
// style = (int) PyLong_AsLong(pStyle);
// PyObject* pWeight = PyTuple_GetItem(pTuple,1);
// weight = PyFloat_AsDouble(pWeight);
// PyObject* pColor = PyTuple_GetItem(pTuple,2);
// c = DrawUtil::pyTupleToColor(pColor);
// PyObject* pVisible = PyTuple_GetItem(pTuple,3);
// visible = (bool) PyLong_AsLong(pVisible);
// cl->m_format.m_style = style;
// cl->m_format.m_weight = weight;
// cl->m_format.m_color = c;
// cl->m_format.m_visible = visible;
// }
// } else {
// Base::Console().Error("CLPI::setFormat - not a tuple!\n");
// }
//
// return Py_None;
//}
//PyObject* CenterLinePy::getFormat(PyObject *args)
//{
// (void) args;
//// Base::Console().Message("CLPI::getFormat()\n");
// TechDraw::CenterLine* cl = this->getCenterLinePtr();
// PyObject* pStyle = PyLong_FromLong((long) cl->m_format.m_style);
// PyObject* pWeight = PyFloat_FromDouble(cl->m_format.m_weight);
// PyObject* pColor = DrawUtil::colorToPyTuple(cl->m_format.m_color);
// PyObject* pVisible = PyBool_FromLong((long) cl->m_format.m_visible);
// PyObject* result = PyTuple_New(4);
// PyTuple_SET_ITEM(result, 0, pStyle);
// PyTuple_SET_ITEM(result, 1, pWeight);
// PyTuple_SET_ITEM(result, 2, pColor);
// PyTuple_SET_ITEM(result, 3, pVisible);
// return result;
//}
Py::Object CenterLinePy::getFormat(void) const
{
// Base::Console().Message("CLP::getFormat()\n");
TechDraw::CenterLine* cl = this->getCenterLinePtr();
PyObject* pStyle = PyLong_FromLong((long) cl->m_format.m_style);
@@ -189,7 +131,6 @@ Py::Object CenterLinePy::getFormat(void) const
void CenterLinePy::setFormat(Py::Object arg)
{
// Base::Console().Message("CLP::setFormat()\n");
PyObject* pTuple = arg.ptr();
int style = 1;
double weight = 0.50;
@@ -209,7 +150,6 @@ void CenterLinePy::setFormat(Py::Object arg)
c = DrawUtil::pyTupleToColor(pColor);
PyObject* pVisible = PyTuple_GetItem(pTuple,3);
visible = (bool) PyLong_AsLong(pVisible);
cl->m_format.m_style = style;
cl->m_format.m_weight = weight;
cl->m_format.m_color = c;

View File

@@ -318,11 +318,14 @@ CosmeticVertex* CosmeticVertex::clone(void) const
PyObject* CosmeticVertex::getPyObject(void)
{
// return new CosmeticVertexPy(new CosmeticVertex(this->copy())); //shouldn't this be clone?
PyObject* result = new CosmeticVertexPy(this->clone());
return result;
if (PythonObject.is(Py::_None())) {
// ref counter is set to 1
PythonObject = Py::Object(new CosmeticVertexPy(this),true);
}
return Py::new_reference_to(PythonObject);
}
void CosmeticVertex::dump(const char* title)
{
Base::Console().Message("CV::dump - %s \n",title);
@@ -403,12 +406,13 @@ void CosmeticEdge::initialize(void)
m_geometry->setCosmeticTag(getTagAsString());
}
void CosmeticEdge::unscaleEnds(double scale)
{
permaStart = permaStart / scale;
permaEnd = permaEnd / scale;
permaRadius = permaRadius / scale;
}
//why is this needed? isn't permaxxxx always unscaled??
//void CosmeticEdge::unscaleEnds(double scale)
//{
// permaStart = permaStart / scale;
// permaEnd = permaEnd / scale;
// permaRadius = permaRadius / scale;
//}
TechDraw::BaseGeom* CosmeticEdge::scaledGeometry(double scale)
{
@@ -567,9 +571,14 @@ CosmeticEdge* CosmeticEdge::clone(void) const
PyObject* CosmeticEdge::getPyObject(void)
{
return new CosmeticEdgePy(this->clone());
if (PythonObject.is(Py::_None())) {
// ref counter is set to 1
PythonObject = Py::Object(new CosmeticEdgePy(this),true);
}
return Py::new_reference_to(PythonObject);
}
//*********************************************************
TYPESYSTEM_SOURCE(TechDraw::CenterLine,Base::Persistence)
@@ -1419,9 +1428,14 @@ CenterLine *CenterLine::clone(void) const
PyObject* CenterLine::getPyObject(void)
{
return new CenterLinePy(this->clone());
if (PythonObject.is(Py::_None())) {
// ref counter is set to 1
PythonObject = Py::Object(new CenterLinePy(this),true);
}
return Py::new_reference_to(PythonObject);
}
void CenterLine::setShifts(double h, double v)
{
m_hShift = h;
@@ -1615,7 +1629,11 @@ GeomFormat* GeomFormat::copy(void) const
PyObject* GeomFormat::getPyObject(void)
{
return new GeomFormatPy(new GeomFormat(this->copy()));
if (PythonObject.is(Py::_None())) {
// ref counter is set to 1
PythonObject = Py::Object(new GeomFormatPy(this),true);
}
return Py::new_reference_to(PythonObject);
}
bool CosmeticVertex::restoreCosmetic(void)

View File

@@ -113,6 +113,9 @@ protected:
boost::uuids::uuid tag;
Py::Object PythonObject;
};
//********** CosmeticEdge ******************************************************
@@ -147,7 +150,7 @@ public:
Base::Vector3d permaStart; //persistent unscaled start/end points in View coords?
Base::Vector3d permaEnd;
double permaRadius;
void unscaleEnds(double scale);
// void unscaleEnds(double scale);
TechDraw::BaseGeom* m_geometry;
LineFormat m_format;
@@ -158,8 +161,10 @@ protected:
//Uniqueness
void createNewTag();
void assignTag(const TechDraw::CosmeticEdge* ce);
boost::uuids::uuid tag;
Py::Object PythonObject;
};
//***** CenterLine *************************************************************
@@ -269,6 +274,8 @@ protected:
boost::uuids::uuid tag;
Py::Object PythonObject;
};
//********** GeomFormat ********************************************************
@@ -310,6 +317,7 @@ protected:
void assignTag(const TechDraw::GeomFormat* gf);
boost::uuids::uuid tag;
Py::Object PythonObject;
};
} //end namespace TechDraw

View File

@@ -57,7 +57,7 @@
<!-- </Attribute> -->
<Attribute Name="Format">
<Documentation>
<UserDocu>The appearance attributes (style, color, weight, visible) for this CosmeticEdge.</UserDocu>
<UserDocu>The appearance attributes (style, weight, color, visible) for this CosmeticEdge.</UserDocu>
</Documentation>
<Parameter Name="Format" Type="Object"/>
</Attribute>

View File

@@ -45,7 +45,10 @@ using namespace TechDraw;
// returns a string which represents the object e.g. when printed in python
std::string CosmeticEdgePy::representation(void) const
{
return "<CosmeticEdge object>";
std::stringstream ss;
ss << "<CosmeticEdge object> at " << std::hex << this;
return ss.str();
// return "<CosmeticEdge object>";
}
PyObject *CosmeticEdgePy::PyMake(struct _typeobject *, PyObject *, PyObject *) // Python wrapper
@@ -119,16 +122,12 @@ PyObject* CosmeticEdgePy::copy(PyObject *args)
void CosmeticEdgePy::setFormat(Py::Object arg)
{
// Base::Console().Message("CEP::setFormat()\n");
PyObject* pTuple = arg.ptr();
int style = 1;
double weight = 0.50;
double red = 0.0, green = 0.0, blue = 0.0, alpha = 0.0;
App::Color c(red, blue, green, alpha);
bool visible = 1;
// if (!PyArg_ParseTuple(args, "O", &pTuple)) {
// return NULL;
// }
TechDraw::CosmeticEdge* ce = this->getCosmeticEdgePtr();
if (PyTuple_Check(pTuple)) {
@@ -155,7 +154,6 @@ void CosmeticEdgePy::setFormat(Py::Object arg)
Py::Object CosmeticEdgePy::getFormat(void) const
{
// Base::Console().Message("CEP::getFormat()\n");
TechDraw::CosmeticEdge* ce = this->getCosmeticEdgePtr();
PyObject* pStyle = PyLong_FromLong((long) ce->m_format.m_style);

View File

@@ -157,20 +157,9 @@ void CosmeticExtension::removeCosmeticVertex(std::vector<std::string> delTags)
bool CosmeticExtension::replaceCosmeticVertex(CosmeticVertex* newCV)
{
// Base::Console().Message("DVP::replaceCV(%s)\n", newCV->getTagAsString().c_str());
(void) newCV;
Base::Console().Message("CX::replaceCosmeticVertex() - deprecated. do not use.\n");
bool result = false;
std::vector<CosmeticVertex*> cVerts = CosmeticVertexes.getValues();
std::vector<CosmeticVertex*> newVerts;
std::string tag = newCV->getTagAsString();
for (auto& cv: cVerts) {
if (cv->getTagAsString() == tag) {
newVerts.push_back(newCV);
result = true;
} else {
newVerts.push_back(cv);
}
}
CosmeticVertexes.setValues(newVerts);
return result;
}
@@ -275,21 +264,12 @@ void CosmeticExtension::removeCosmeticEdge(std::vector<std::string> delTags)
}
}
bool CosmeticExtension::replaceCosmeticEdge(CosmeticEdge* newCE)
{
(void) newCE;
Base::Console().Message("CX::replaceCosmeticEdge() - deprecated. do not use.\n");
bool result = false;
std::vector<CosmeticEdge*> cEdges = CosmeticEdges.getValues();
std::vector<CosmeticEdge*> newEdges;
std::string tag = newCE->getTagAsString();
for (auto& ce: cEdges) {
if (ce->getTagAsString() == tag) {
newEdges.push_back(newCE);
result = true;
} else {
newEdges.push_back(ce);
}
}
CosmeticEdges.setValues(newEdges);
return result;
}
@@ -403,20 +383,9 @@ void CosmeticExtension::removeCenterLine(std::vector<std::string> delTags)
bool CosmeticExtension::replaceCenterLine(CenterLine* newCL)
{
// Base::Console().Message("DVP::replaceCL(%s)\n", newCL->getTagAsString().c_str());
(void) newCL;
Base::Console().Message("CX::replaceCenterLine() - deprecated. do not use.\n");
bool result = false;
std::vector<CenterLine*> cLines = CenterLines.getValues();
std::vector<CenterLine*> newLines;
std::string tag = newCL->getTagAsString();
for (auto& cl: cLines) {
if (cl->getTagAsString() == tag) {
newLines.push_back(newCL);
result = true;
} else {
newLines.push_back(cl);
}
}
CenterLines.setValues(newLines);
return result;
}
@@ -486,20 +455,9 @@ TechDraw::GeomFormat* CosmeticExtension::getGeomFormatBySelection(int i) const
bool CosmeticExtension::replaceGeomFormat(GeomFormat* newGF)
{
// Base::Console().Message("CEx::replaceGF(%s)\n", newGF->getTagAsString().c_str());
(void) newGF;
Base::Console().Message("CX::replaceGeomFormat() - deprecated. do not use.\n");
bool result = false;
std::vector<GeomFormat*> gFormats = GeomFormats.getValues();
std::vector<GeomFormat*> newFormats;
std::string tag = newGF->getTagAsString();
for (auto& gf: gFormats) {
if (gf->getTagAsString() == tag) {
newFormats.push_back(newGF);
result = true;
} else {
newFormats.push_back(gf);
}
}
GeomFormats.setValues(newFormats);
return result;
}

View File

@@ -43,6 +43,23 @@
</Documentation>
<Parameter Name="Show" Type="Boolean"/>
</Attribute>
<Attribute Name="Color" ReadOnly="false">
<Documentation>
<UserDocu>set/return the vertex's colour using a tuple (rgba).</UserDocu>
</Documentation>
<Parameter Name="Color" Type="Object"/>
</Attribute>
<Attribute Name="Size" ReadOnly="false">
<Documentation>
<UserDocu>set/return the vertex's radius in mm.</UserDocu>
</Documentation>
<Parameter Name="Size" Type="Object"/>
</Attribute>
<Attribute Name="Style" ReadOnly="false">
<Documentation>
<UserDocu>set/return the vertex's style as integer.</UserDocu>
</Documentation>
<Parameter Name="Style" Type="Object"/>
</Attribute>
</PythonExport>
</GenerateModel>

View File

@@ -168,6 +168,71 @@ void CosmeticVertexPy::setShow(Py::Boolean arg)
}
}
Py::Object CosmeticVertexPy::getColor(void) const
{
App::Color color = getCosmeticVertexPtr()->color;
PyObject* pyColor = DrawUtil::colorToPyTuple(color);
return Py::asObject(pyColor);
}
void CosmeticVertexPy::setColor(Py::Object arg)
{
PyObject* pTuple = arg.ptr();
double red = 0.0, green = 0.0, blue = 0.0, alpha = 0.0;
App::Color c(red, green, blue, alpha);
if (PyTuple_Check(pTuple)) {
c = DrawUtil::pyTupleToColor(pTuple);
CosmeticVertex* cv = getCosmeticVertexPtr();
cv->color = c;
} else {
Base::Console().Error("CEPI::setColor - not a tuple!\n");
std::string error = std::string("type must be 'tuple', not ");
error += pTuple->ob_type->tp_name;
throw Py::TypeError(error);
}
}
Py::Object CosmeticVertexPy::getSize(void) const
{
CosmeticVertex* cv = getCosmeticVertexPtr();
double size = cv->size;
PyObject* pSize = PyFloat_FromDouble(size);
return Py::asObject(pSize);
}
void CosmeticVertexPy::setSize(Py::Object arg)
{
double size = 1.0;
PyObject* p = arg.ptr();
if (PyFloat_Check(p)) {
size = PyFloat_AsDouble(p);
} else {
throw Py::TypeError("expected (float)");
}
CosmeticVertex* cv = getCosmeticVertexPtr();
cv->size = size;
}
Py::Object CosmeticVertexPy::getStyle(void) const
{
CosmeticVertex* cv = getCosmeticVertexPtr();
double style = cv->style;
PyObject* pStyle = PyLong_FromLong((long) style);
return Py::asObject(pStyle);
}
void CosmeticVertexPy::setStyle(Py::Object arg)
{
int style = 1;
PyObject* p = arg.ptr();
if (PyLong_Check(p)) {
style = (int) PyLong_AsLong(p);
} else {
throw Py::TypeError("expected (float)");
}
CosmeticVertex* cv = getCosmeticVertexPtr();
cv->style = style;
}
PyObject *CosmeticVertexPy::getCustomAttributes(const char* /*attr*/) const
{

View File

@@ -107,8 +107,8 @@ void DrawDimHelper::makeExtentDim(DrawViewPart* dvp,
std::pair<Base::Vector3d, Base::Vector3d> endPoints = minMax(dvp,
edgeNames,
direction);
Base::Vector3d refMin = endPoints.first;
Base::Vector3d refMax = endPoints.second;
Base::Vector3d refMin = endPoints.first / dvp->getScale(); //unscale from geometry
Base::Vector3d refMax = endPoints.second / dvp->getScale();
//pause recomputes
dvp->getDocument()->setStatus(App::Document::Status::SkipRecompute, true);
@@ -326,11 +326,10 @@ gp_Pnt2d DrawDimHelper::findClosestPoint(std::vector<hTrimCurve> hTCurve2dList,
return result;
}
//TODO: this needs to be exposed to Python
DrawViewDimension* DrawDimHelper::makeDistDim(DrawViewPart* dvp,
std::string dimType,
Base::Vector3d inMin,
Base::Vector3d inMax,
Base::Vector3d inMin, //is this scaled or unscaled??
Base::Vector3d inMax, //expects scaled from makeExtentDim
bool extent)
{
// Base::Console().Message("DDH::makeDistDim() - inMin: %s inMax: %s\n",
@@ -346,13 +345,11 @@ DrawViewDimension* DrawDimHelper::makeDistDim(DrawViewPart* dvp,
dimName = doc->getUniqueObjectName("DimExtent");
}
double scale = dvp->getScale();
//regular dims will have trouble with geom indexes!
Base::Vector3d cleanMin = DrawUtil::invertY(inMin) / scale;
Base::Vector3d cleanMin = DrawUtil::invertY(inMin);
std::string tag1 = dvp->addCosmeticVertex(cleanMin);
int iGV1 = dvp->add1CVToGV(tag1);
Base::Vector3d cleanMax = DrawUtil::invertY(inMax) / scale;
Base::Vector3d cleanMax = DrawUtil::invertY(inMax);
std::string tag2 = dvp->addCosmeticVertex(cleanMax);
int iGV2 = dvp->add1CVToGV(tag2);
@@ -366,6 +363,7 @@ DrawViewDimension* DrawDimHelper::makeDistDim(DrawViewPart* dvp,
objs.push_back(dvp);
ss.clear();
ss.str(std::string());
ss << "Vertex" << iGV2;
vertexName = ss.str();
subs.push_back(vertexName);

View File

@@ -557,9 +557,7 @@ void DrawGeomHatch::onDocumentRestored()
std::string patFileName = FilePattern.getValue();
Base::FileInfo tfi(patFileName);
if (tfi.isReadable()) {
if (PatIncluded.isEmpty()) {
setupPatIncluded();
}
setupPatIncluded();
}
}
}

View File

@@ -461,10 +461,10 @@ App::DocumentObject * DrawProjGroup::addProjection(const char *viewProjType)
} else { //Front
Anchor.setValue(view);
Anchor.purgeTouched();
requestPaint(); //make sure the group object is on the Gui page
view->LockPosition.setValue(true); //lock "Front" position within DPG (note not Page!).
view->LockPosition.setStatus(App::Property::ReadOnly,true); //Front should stay locked.
view->LockPosition.purgeTouched();
requestPaint(); //make sure the group object is on the Gui page
}
// addView(view); //from DrawViewCollection
// if (view != getAnchor()) { //anchor is done elsewhere
@@ -1004,6 +1004,8 @@ void DrawProjGroup::updateChildrenLock(void)
Base::Console().Log("PROBLEM - DPG::updateChildrenLock - non DPGI entry in Views! %s\n",
getNameInDocument());
throw Base::TypeError("Error: projection in DPG list is not a DPGI!");
} else {
view->requestPaint();
}
}
}

View File

@@ -103,16 +103,10 @@ void DrawProjGroupItem::onChanged(const App::Property *prop)
bool DrawProjGroupItem::isLocked(void) const
{
bool isLocked = DrawView::isLocked();
if (isAnchor()) { //Anchor view is always locked to DPG
return true;
}
DrawProjGroup* parent = getPGroup();
if (parent != nullptr) {
isLocked = isLocked || parent->LockPosition.getValue();
}
return isLocked;
return DrawView::isLocked();
}
bool DrawProjGroupItem::showLock(void) const

View File

@@ -284,6 +284,62 @@ bool DrawUtil::fpCompare(const double& d1, const double& d2, double tolerance)
return result;
}
//brute force intersection points of line(point, dir) with box(xRange, yRange)
std::pair<Base::Vector3d, Base::Vector3d> DrawUtil::boxIntersect2d(Base::Vector3d point,
Base::Vector3d dirIn,
double xRange,
double yRange)
{
std::pair<Base::Vector3d, Base::Vector3d> result;
Base::Vector3d p1, p2;
Base::Vector3d dir = dirIn;
dir.Normalize();
// y = mx + b
// m = (y1 - y0) / (x1 - x0)
if (DrawUtil::fpCompare(dir.x, 0.0) ) {
p1 = Base::Vector3d(point.x, - yRange / 2.0, 0.0);
p2 = Base::Vector3d(point.x, yRange / 2.0, 0.0);
} else {
double slope = dir.y / dir.x;
double left = -xRange / 2.0;
double right = xRange / 2.0;
double top = yRange / 2.0;
double bottom = -yRange / 2.0;
double yLeft = point.y - slope * (point.x - left) ;
double yRight = point.y - slope * (point.x - right);
double xTop = point.x - ( (point.y - top) / slope );
double xBottom = point.x - ( (point.y - bottom) / slope );
if ( (bottom < yLeft) &&
(top > yLeft) ) {
p1 = Base::Vector3d(left, yLeft);
} else if (yLeft <= bottom) {
p1 = Base::Vector3d(xBottom, bottom);
} else if (yLeft >= top) {
p1 = Base::Vector3d(xTop, top);
}
if ( (bottom < yRight) &&
(top > yRight) ) {
p2 = Base::Vector3d(right, yRight);
} else if (yRight <= bottom) {
p2 = Base::Vector3d(xBottom, bottom);
} else if (yRight >= top) {
p2 = Base::Vector3d(xTop, top);
}
}
result.first = p1;
result.second = p2;
Base::Vector3d dirCheck = p2 - p1;
dirCheck.Normalize();
if (!dir.IsEqual(dirCheck, 0.00001)) {
result.first = p2;
result.second = p1;
}
return result;
}
Base::Vector3d DrawUtil::vertex2Vector(const TopoDS_Vertex& v)
{
gp_Pnt gp = BRep_Tool::Pnt(v);
@@ -613,7 +669,7 @@ App::Color DrawUtil::pyTupleToColor(PyObject* pColor)
{
// Base::Console().Message("DU::pyTupleToColor()\n");
double red = 0.0, green = 0.0, blue = 0.0, alpha = 0.0;
App::Color c(red, blue, green, alpha);
App::Color c(red, green, blue, alpha);
if (PyTuple_Check(pColor)) {
int tSize = (int) PyTuple_Size(pColor);
if (tSize > 2) {
@@ -628,7 +684,7 @@ App::Color DrawUtil::pyTupleToColor(PyObject* pColor)
PyObject* pAlpha = PyTuple_GetItem(pColor,3);
alpha = PyFloat_AsDouble(pAlpha);
}
c = App::Color(red, blue, green, alpha);
c = App::Color(red, green, blue, alpha);
}
return c;
}

View File

@@ -79,6 +79,10 @@ class TechDrawExport DrawUtil {
static bool isFirstVert(TopoDS_Edge e, TopoDS_Vertex v, double tolerance = VERTEXTOLERANCE);
static bool isLastVert(TopoDS_Edge e, TopoDS_Vertex v, double tolerance = VERTEXTOLERANCE);
static bool fpCompare(const double& d1, const double& d2, double tolerance = FLT_EPSILON);
static std::pair<Base::Vector3d, Base::Vector3d> boxIntersect2d(Base::Vector3d point,
Base::Vector3d dir,
double xRange,
double yRange) ;
static Base::Vector3d vertex2Vector(const TopoDS_Vertex& v);
static std::string formatVector(const Base::Vector3d& v);
static std::string formatVector(const gp_Dir& v);

View File

@@ -76,17 +76,17 @@ DrawView::DrawView(void):
mouseMove(false)
{
static const char *group = "Base";
ADD_PROPERTY_TYPE(X, (0.0), group, App::Prop_None, "X position");
ADD_PROPERTY_TYPE(Y, (0.0), group, App::Prop_None, "Y position");
ADD_PROPERTY_TYPE(LockPosition, (false), group, App::Prop_None, "Lock View position to parent Page or Group");
ADD_PROPERTY_TYPE(Rotation, (0.0), group, App::Prop_None, "Rotation in degrees counterclockwise");
ADD_PROPERTY_TYPE(X, (0.0), group, (App::PropertyType)(App::Prop_Output | App::Prop_NoRecompute), "X position");
ADD_PROPERTY_TYPE(Y, (0.0), group, (App::PropertyType)(App::Prop_Output | App::Prop_NoRecompute), "Y position");
ADD_PROPERTY_TYPE(LockPosition, (false), group, App::Prop_Output, "Lock View position to parent Page or Group");
ADD_PROPERTY_TYPE(Rotation, (0.0), group, App::Prop_Output, "Rotation in degrees counterclockwise");
ScaleType.setEnums(ScaleTypeEnums);
ADD_PROPERTY_TYPE(ScaleType, (prefScaleType()), group, App::Prop_None, "Scale Type");
ADD_PROPERTY_TYPE(Scale, (prefScale()), group, App::Prop_None, "Scale factor of the view");
ADD_PROPERTY_TYPE(ScaleType, (prefScaleType()), group, App::Prop_Output, "Scale Type");
ADD_PROPERTY_TYPE(Scale, (prefScale()), group, App::Prop_Output, "Scale factor of the view");
Scale.setConstraints(&scaleRange);
ADD_PROPERTY_TYPE(Caption, (""), group, App::Prop_None, "Short text about the view");
ADD_PROPERTY_TYPE(Caption, (""), group, App::Prop_Output, "Short text about the view");
}
DrawView::~DrawView()
@@ -95,10 +95,17 @@ DrawView::~DrawView()
App::DocumentObjectExecReturn *DrawView::execute(void)
{
// Base::Console().Message("DV::execute() - %s\n", getNameInDocument());
// Base::Console().Message("DV::execute() - %s touched: %d\n", getNameInDocument(), isTouched());
if (findParentPage() == nullptr) {
return App::DocumentObject::execute();
}
handleXYLock();
requestPaint();
return App::DocumentObject::execute();
//documentobject::execute doesn't do anything useful for us.
//documentObject::recompute causes an infinite loop.
//should not be necessary to purgeTouched here, but it prevents a superfluous feature recompute
purgeTouched(); //this should not be necessary!
return App::DocumentObject::StdReturn;
}
void DrawView::checkScale(void)
@@ -146,11 +153,15 @@ void DrawView::onChanged(const App::Property* prop)
}
} else if (prop == &LockPosition) {
handleXYLock();
requestPaint(); //change lock icon
LockPosition.purgeTouched();
}
if ((prop == &Caption) ||
} else if ((prop == &Caption) ||
(prop == &Label)) {
requestPaint();
} else if ((prop == &X) ||
(prop == &Y)) {
X.purgeTouched();
Y.purgeTouched();
}
}
App::DocumentObject::onChanged(prop);
@@ -195,11 +206,7 @@ short DrawView::mustExecute() const
short result = 0;
if (!isRestoring()) {
result = (Scale.isTouched() ||
ScaleType.isTouched() ||
Caption.isTouched() ||
X.isTouched() ||
Y.isTouched() ||
LockPosition.isTouched());
ScaleType.isTouched());
}
if ((bool) result) {
return result;

View File

@@ -13,6 +13,11 @@
<Author Licence="LGPL" Name="WandererFan" EMail="wandererfan@gmail.com" />
<UserDocu>Feature for creating and manipulating Technical Drawing Dimensions</UserDocu>
</Documentation>
<Methode Name="getRawValue">
<Documentation>
<UserDocu>getRawValue() - returns Dimension value in mm.</UserDocu>
</Documentation>
</Methode>
<Methode Name="getText">
<Documentation>
<UserDocu>getText() - returns Dimension text.</UserDocu>

View File

@@ -42,6 +42,16 @@ std::string DrawViewDimensionPy::representation(void) const
{
return std::string("<DrawViewDimension object>");
}
PyObject* DrawViewDimensionPy::getRawValue(PyObject* args)
{
(void) args;
DrawViewDimension* dvd = getDrawViewDimensionPtr();
double val = dvd->getDimValue();
PyObject* pyVal = PyFloat_FromDouble(val);
return pyVal;
}
PyObject* DrawViewDimensionPy::getText(PyObject* args)
{
(void) args;

View File

@@ -248,14 +248,10 @@ std::vector<App::DocumentObject*> DrawViewPart::getAllSources(void) const
App::DocumentObjectExecReturn *DrawViewPart::execute(void)
{
// Base::Console().Message("DVP::execute() - %s\n", Label.getValue());
if (!keepUpdated()) {
return App::DocumentObject::StdReturn;
}
// Base::Console().Message("DVP::execute - Source: %d XSource: %d\n",
// Source.getValues().size(), XSource.getValues().size());
App::Document* doc = getDocument();
bool isRestoring = doc->testStatus(App::Document::Status::Restoring);
const std::vector<App::DocumentObject*>& links = getAllSources();
@@ -291,7 +287,6 @@ App::DocumentObjectExecReturn *DrawViewPart::execute(void)
XDirection.purgeTouched(); //don't trigger updates!
//unblock
}
auto start = std::chrono::high_resolution_clock::now();
m_saveShape = shape;
partExec(shape);
@@ -312,14 +307,7 @@ App::DocumentObjectExecReturn *DrawViewPart::execute(void)
}
}
auto end = std::chrono::high_resolution_clock::now();
auto diff = end - start;
double diffOut = std::chrono::duration <double, std::milli> (diff).count();
Base::Console().Log("TIMING - %s DVP spent: %.3f millisecs handling Faces\n",
getNameInDocument(),diffOut);
//#endif //#if MOD_TECHDRAW_HANDLE_FACES
// Base::Console().Message("DVP::execute - exits\n");
return DrawView::execute();
}
@@ -366,7 +354,6 @@ void DrawViewPart::partExec(TopoDS_Shape shape)
}
#if MOD_TECHDRAW_HANDLE_FACES
// auto start = std::chrono::high_resolution_clock::now();
if (handleFaces() && !geometryObject->usePolygonHLR()) {
try {
extractFaces();
@@ -463,8 +450,6 @@ TechDraw::GeometryObject* DrawViewPart::buildGeometryObject(TopoDS_Shape shape,
viewAxis);
}
auto start = std::chrono::high_resolution_clock::now();
go->extractGeometry(TechDraw::ecHARD, //always show the hard&outline visible lines
true);
go->extractGeometry(TechDraw::ecOUTLINE,
@@ -499,10 +484,6 @@ TechDraw::GeometryObject* DrawViewPart::buildGeometryObject(TopoDS_Shape shape,
go->extractGeometry(TechDraw::ecUVISO,
false);
}
auto end = std::chrono::high_resolution_clock::now();
auto diff = end - start;
double diffOut = std::chrono::duration <double, std::milli> (diff).count();
Base::Console().Log("TIMING - %s DVP spent: %.3f millisecs in GO::extractGeometry\n",getNameInDocument(),diffOut);
const std::vector<TechDraw::BaseGeom *> & edges = go->getEdgeGeometry();
if (edges.empty()) {
@@ -533,34 +514,32 @@ void DrawViewPart::extractFaces()
if (!DrawUtil::isZeroEdge(e)) {
nonZero.push_back(e);
} else {
Base::Console().Message("INFO - DVP::extractFaces for %s found ZeroEdge!\n",getNameInDocument());
Base::Console().Log("INFO - DVP::extractFaces for %s found ZeroEdge!\n",getNameInDocument());
}
}
faceEdges = nonZero;
origEdges = nonZero;
//HLR algo does not provide all edge intersections for edge endpoints.
//need to split long edges touched by Vertex of another edge
std::vector<splitPoint> splits;
std::vector<TopoDS_Edge>::iterator itOuter = origEdges.begin();
std::vector<TopoDS_Edge>::iterator itOuter = nonZero.begin();
int iOuter = 0;
for (; itOuter != origEdges.end(); ++itOuter, iOuter++) {
for (; itOuter != nonZero.end(); ++itOuter, iOuter++) { //*** itOuter != nonZero.end() - 1
TopoDS_Vertex v1 = TopExp::FirstVertex((*itOuter));
TopoDS_Vertex v2 = TopExp::LastVertex((*itOuter));
Bnd_Box sOuter;
BRepBndLib::Add(*itOuter, sOuter);
sOuter.SetGap(0.1);
if (sOuter.IsVoid()) {
Base::Console().Message("DVP::Extract Faces - outer Bnd_Box is void for %s\n",getNameInDocument());
Base::Console().Log("DVP::Extract Faces - outer Bnd_Box is void for %s\n",getNameInDocument());
continue;
}
if (DrawUtil::isZeroEdge(*itOuter)) {
Base::Console().Message("DVP::extractFaces - outerEdge: %d is ZeroEdge\n",iOuter); //this is not finding ZeroEdges
Base::Console().Log("DVP::extractFaces - outerEdge: %d is ZeroEdge\n",iOuter); //this is not finding ZeroEdges
continue; //skip zero length edges. shouldn't happen ;)
}
int iInner = 0;
std::vector<TopoDS_Edge>::iterator itInner = faceEdges.begin();
for (; itInner != faceEdges.end(); ++itInner,iInner++) {
std::vector<TopoDS_Edge>::iterator itInner = nonZero.begin(); //***sb itOuter + 1;
for (; itInner != nonZero.end(); ++itInner,iInner++) {
if (iInner == iOuter) {
continue;
}
@@ -602,10 +581,10 @@ void DrawViewPart::extractFaces()
std::vector<splitPoint> sorted = DrawProjectSplit::sortSplits(splits,true);
auto last = std::unique(sorted.begin(), sorted.end(), DrawProjectSplit::splitEqual); //duplicates to back
sorted.erase(last, sorted.end()); //remove dupl splits
std::vector<TopoDS_Edge> newEdges = DrawProjectSplit::splitEdges(faceEdges,sorted);
std::vector<TopoDS_Edge> newEdges = DrawProjectSplit::splitEdges(nonZero,sorted);
if (newEdges.empty()) {
Base::Console().Log("LOG - DVP::extractFaces - no newEdges\n");
Base::Console().Log("DVP::extractFaces - no newEdges\n");
return;
}
@@ -646,8 +625,7 @@ std::vector<TechDraw::DrawHatch*> DrawViewPart::getHatches() const
std::vector<TechDraw::DrawHatch*> result;
std::vector<App::DocumentObject*> children = getInList();
for (std::vector<App::DocumentObject*>::iterator it = children.begin(); it != children.end(); ++it) {
if ( ((*it)->getTypeId().isDerivedFrom(DrawHatch::getClassTypeId())) &&
(!(*it)->isRemoving()) ) {
if ((*it)->getTypeId().isDerivedFrom(DrawHatch::getClassTypeId())) {
TechDraw::DrawHatch* hatch = dynamic_cast<TechDraw::DrawHatch*>(*it);
result.push_back(hatch);
}
@@ -1189,6 +1167,7 @@ void DrawViewPart::resetReferenceVerts()
//********
//* Cosmetics
//********
void DrawViewPart::clearCosmeticVertexes(void)
{
std::vector<CosmeticVertex*> noVerts;
@@ -1242,15 +1221,11 @@ int DrawViewPart::getCVIndex(std::string tag)
// Base::Console().Message("DVP::getCVIndex(%s)\n", tag.c_str());
int result = -1;
std::vector<TechDraw::Vertex *> gVerts = getVertexGeometry();
Base::Console().Message("DVP::getCVIndex - gVerts: %d\n", gVerts.size());
std::vector<TechDraw::CosmeticVertex*> cVerts = CosmeticVertexes.getValues();
Base::Console().Message("DVP::getCVIndex - cVerts: %d\n", cVerts.size());
int i = 0;
bool found = false;
for (auto& gv :gVerts) {
Base::Console().Message("DVP::getCVIndex - gv cosmetic: %d ctag: %s\n",
gv->cosmetic, gv->cosmeticTag.c_str());
if (gv->cosmeticTag == tag) {
result = i;
found = true;

View File

@@ -148,6 +148,11 @@
<UserDocu>getVertexByIndex(vertexIndex). Returns Part.TopoShape.</UserDocu>
</Documentation>
</Methode>
<Methode Name="requestPaint">
<Documentation>
<UserDocu>requestPaint(). Redraw the graphic for this View.</UserDocu>
</Documentation>
</Methode>
<CustomAttributes />
</PythonExport>
</GenerateModel>

View File

@@ -105,8 +105,16 @@ PyObject* DrawViewPartPy::getHiddenEdges(PyObject *args)
return pEdgeList;
}
// remove all cosmetics
PyObject* DrawViewPartPy::requestPaint(PyObject *args)
{
(void) args;
DrawViewPart* item = getDrawViewPartPtr();
item->requestPaint();
Py_INCREF(Py_None);
return Py_None;
}
// remove all cosmetics
PyObject* DrawViewPartPy::clearCosmeticVertices(PyObject *args)
{
(void) args;
@@ -273,17 +281,21 @@ PyObject* DrawViewPartPy::removeCosmeticVertex(PyObject *args)
PyObject* DrawViewPartPy::replaceCosmeticVertex(PyObject *args)
{
PyObject* pNewCV = nullptr;
if (!PyArg_ParseTuple(args, "O!", &(TechDraw::CosmeticVertexPy::Type), &pNewCV)) {
throw Py::TypeError("expected (CosmeticVertex)");
}
DrawViewPart* dvp = getDrawViewPartPtr();
TechDraw::CosmeticVertexPy* cvPy = static_cast<TechDraw::CosmeticVertexPy*>(pNewCV);
TechDraw::CosmeticVertex* cv = cvPy->getCosmeticVertexPtr();
bool result = dvp->replaceCosmeticVertex(cv);
dvp->refreshCVGeoms();
dvp->requestPaint();
return PyBool_FromLong((long) result);
(void) args;
Base::Console().Message("DVPP::replaceCosmeticVertex() - deprecated. do not use.\n");
return PyBool_FromLong(0l);
// PyObject* pNewCV = nullptr;
// if (!PyArg_ParseTuple(args, "O!", &(TechDraw::CosmeticVertexPy::Type), &pNewCV)) {
// throw Py::TypeError("expected (CosmeticVertex)");
// }
// DrawViewPart* dvp = getDrawViewPartPtr();
// TechDraw::CosmeticVertexPy* cvPy = static_cast<TechDraw::CosmeticVertexPy*>(pNewCV);
// TechDraw::CosmeticVertex* cv = cvPy->getCosmeticVertexPtr();
// bool result = dvp->replaceCosmeticVertex(cv);
// dvp->refreshCVGeoms();
// dvp->requestPaint();
// return PyBool_FromLong((long) result);
}
@@ -456,9 +468,7 @@ PyObject* DrawViewPartPy::getCosmeticEdge(PyObject *args)
DrawViewPart* dvp = getDrawViewPartPtr();
TechDraw::CosmeticEdge* ce = dvp->getCosmeticEdge(tag);
if (ce != nullptr) {
// result = new CosmeticEdgePy(new CosmeticEdge(ce));
result = new CosmeticEdgePy(ce->clone());
// result = ce->getPyObject();
result = ce->getPyObject();
} else {
Base::Console().Error("DVPPI::getCosmeticEdge - edge %s not found\n", tag);
}
@@ -478,8 +488,7 @@ PyObject* DrawViewPartPy::getCosmeticEdgeBySelection(PyObject *args)
TechDraw::CosmeticEdge* ce = dvp->getCosmeticEdgeBySelection(name);
if (ce != nullptr) {
// result = ce->getPyObject();
result = new CosmeticEdgePy(ce->clone());
result = ce->getPyObject();
} else {
Base::Console().Error("DVPPI::getCosmeticEdgebySelection - edge for name %s not found\n", name);
}
@@ -488,18 +497,25 @@ PyObject* DrawViewPartPy::getCosmeticEdgeBySelection(PyObject *args)
PyObject* DrawViewPartPy::replaceCosmeticEdge(PyObject *args)
{
(void) args;
Base::Console().Message("DVPP::replaceCosmeticEdge() - deprecated. do not use.\n");
return PyBool_FromLong(0l);
// Base::Console().Message("DVPPI::replaceCosmeticEdge()\n");
PyObject* pNewCE;
if (!PyArg_ParseTuple(args, "O!", &(TechDraw::CosmeticEdgePy::Type), &pNewCE)) {
throw Py::TypeError("expected (CosmeticEdge)");
}
DrawViewPart* dvp = getDrawViewPartPtr();
TechDraw::CosmeticEdgePy* cePy = static_cast<TechDraw::CosmeticEdgePy*>(pNewCE);
TechDraw::CosmeticEdge* ce = cePy->getCosmeticEdgePtr();
bool result = dvp->replaceCosmeticEdge(ce);
dvp->refreshCEGeoms();
dvp->requestPaint();
return PyBool_FromLong((long) result);
// bool result = false;
// PyObject* pNewCE;
// if (!PyArg_ParseTuple(args, "O!", &(TechDraw::CosmeticEdgePy::Type), &pNewCE)) {
// throw Py::TypeError("expected (CosmeticEdge)");
// }
// DrawViewPart* dvp = getDrawViewPartPtr();
// TechDraw::CosmeticEdgePy* cePy = static_cast<TechDraw::CosmeticEdgePy*>(pNewCE);
// TechDraw::CosmeticEdge* ce = cePy->getCosmeticEdgePtr();
// if (ce != nullptr) {
// result = dvp->replaceCosmeticEdge(ce); //<<<
// dvp->refreshCEGeoms();
// dvp->requestPaint();
// }
// return PyBool_FromLong((long) result);
}
PyObject* DrawViewPartPy::removeCosmeticEdge(PyObject *args)
@@ -578,7 +594,7 @@ PyObject* DrawViewPartPy::getCenterLine(PyObject *args)
DrawViewPart* dvp = getDrawViewPartPtr();
TechDraw::CenterLine* cl = dvp->getCenterLine(tag);
if (cl != nullptr) {
result = new CenterLinePy(cl->clone());
result = cl->getPyObject();
} else {
Base::Console().Error("DVPPI::getCenterLine - centerLine %s not found\n", tag);
}
@@ -598,7 +614,7 @@ PyObject* DrawViewPartPy::getCenterLineBySelection(PyObject *args)
TechDraw::CenterLine* cl = dvp->getCenterLineBySelection(tag);
if (cl != nullptr) {
result = new CenterLinePy(cl->clone());
result = cl->getPyObject();
} else {
Base::Console().Error("DVPPI::getCenterLinebySelection - centerLine for tag %s not found\n", tag);
}
@@ -607,18 +623,22 @@ PyObject* DrawViewPartPy::getCenterLineBySelection(PyObject *args)
PyObject* DrawViewPartPy::replaceCenterLine(PyObject *args)
{
(void) args;
Base::Console().Message("DVPP::replaceCenterLine() - deprecated. do not use.\n");
return PyBool_FromLong(0l);
// Base::Console().Message("DVPPI::replace CenterLine()\n");
PyObject* pNewCL;
if (!PyArg_ParseTuple(args, "O!", &(TechDraw::CenterLinePy::Type), &pNewCL)) {
throw Py::TypeError("expected (CenterLine)");
}
DrawViewPart* dvp = getDrawViewPartPtr();
TechDraw::CenterLinePy* clPy = static_cast<TechDraw::CenterLinePy*>(pNewCL);
TechDraw::CenterLine* cl = clPy->getCenterLinePtr();
bool result = dvp->replaceCenterLine(cl);
dvp->refreshCLGeoms();
dvp->requestPaint();
return PyBool_FromLong((long) result);
// PyObject* pNewCL;
// if (!PyArg_ParseTuple(args, "O!", &(TechDraw::CenterLinePy::Type), &pNewCL)) {
// throw Py::TypeError("expected (CenterLine)");
// }
// DrawViewPart* dvp = getDrawViewPartPtr();
// TechDraw::CenterLinePy* clPy = static_cast<TechDraw::CenterLinePy*>(pNewCL);
// TechDraw::CenterLine* cl = clPy->getCenterLinePtr();
// bool result = dvp->replaceCenterLine(cl);
// dvp->refreshCLGeoms();
// dvp->requestPaint();
// return PyBool_FromLong((long) result);
}
PyObject* DrawViewPartPy::removeCenterLine(PyObject *args)

View File

@@ -230,13 +230,12 @@ void DrawViewSection::onChanged(const App::Property* prop)
void DrawViewSection::makeLineSets(void)
{
// Base::Console().Message("DVS::makeLineSets()\n");
if (!FileGeomPattern.isEmpty()) {
std::string fileSpec = FileGeomPattern.getValue();
if (!PatIncluded.isEmpty()) {
std::string fileSpec = PatIncluded.getValue();
Base::FileInfo fi(fileSpec);
std::string ext = fi.extension();
if (!fi.isReadable()) {
Base::Console().Message("%s can not read hatch file: %s\n", getNameInDocument(), fileSpec.c_str());
Base::Console().Message("%s using included hatch file.\n", getNameInDocument());
} else {
if ( (ext == "pat") ||
(ext == "PAT") ) {
@@ -678,6 +677,36 @@ TopoDS_Face DrawViewSection::projectFace(const TopoDS_Shape &face,
return projectedFace;
}
//calculate the ends of the section line in BaseView's coords
std::pair<Base::Vector3d, Base::Vector3d> DrawViewSection::sectionLineEnds(void)
{
std::pair<Base::Vector3d, Base::Vector3d> result;
auto sNorm = SectionNormal.getValue();
double angle = M_PI / 2.0;
auto axis = getBaseDVP()->Direction.getValue();
Base::Vector3d stdOrg(0.0, 0.0, 0.0);
Base::Vector3d sLineDir = DrawUtil::vecRotate(sNorm, angle, axis, stdOrg);
sLineDir.Normalize();
Base::Vector3d sLineDir2 = - axis.Cross(sNorm);
sLineDir2.Normalize();
Base::Vector3d sLineOnBase = getBaseDVP()->projectPoint(sLineDir2);
sLineOnBase.Normalize();
auto sOrigin = SectionOrigin.getValue();
Base::Vector3d adjSectionOrg = sOrigin - getBaseDVP()->getOriginalCentroid();
Base::Vector3d sOrgOnBase = getBaseDVP()->projectPoint(adjSectionOrg);
auto bbx = getBaseDVP()->getBoundingBox();
double xRange = bbx.MaxX - bbx.MinX;
xRange /= getBaseDVP()->getScale();
double yRange = bbx.MaxY - bbx.MinY;
yRange /= getBaseDVP()->getScale();
result = DrawUtil::boxIntersect2d(sOrgOnBase, sLineOnBase, xRange, yRange); //unscaled
return result;
}
//this should really be in BoundBox.h
//!check if point is in box or on boundary of box
//!compare to isInBox which doesn't allow on boundary
@@ -842,6 +871,7 @@ gp_Ax2 DrawViewSection::rotateCSArbitrary(gp_Ax2 oldCS,
std::vector<LineSet> DrawViewSection::getDrawableLines(int i)
{
// Base::Console().Message("DVS::getDrawableLines(%d) - lineSets: %d\n", i, m_lineSets.size());
std::vector<LineSet> result;
result = DrawGeomHatch::getTrimmedLines(this,m_lineSets,i,HatchScale.getValue());
return result;
@@ -919,26 +949,27 @@ int DrawViewSection::prefCutSurface(void) const
void DrawViewSection::onDocumentRestored()
{
// Base::Console().Message("DVS::onDocumentRestored()\n");
if (!FileHatchPattern.isEmpty()) {
std::string svgFileName = FileHatchPattern.getValue();
Base::FileInfo tfi(svgFileName);
if (tfi.isReadable()) {
if (SvgIncluded.isEmpty()) {
if (SvgIncluded.isEmpty()) {
if (!FileHatchPattern.isEmpty()) {
std::string svgFileName = FileHatchPattern.getValue();
Base::FileInfo tfi(svgFileName);
if (tfi.isReadable()) {
setupSvgIncluded();
}
}
}
if (!FileGeomPattern.isEmpty()) {
std::string patFileName = FileGeomPattern.getValue();
Base::FileInfo tfi(patFileName);
if (tfi.isReadable()) {
if (PatIncluded.isEmpty()) {
setupPatIncluded();
if (PatIncluded.isEmpty()) {
if (!FileGeomPattern.isEmpty()) {
std::string patFileName = FileGeomPattern.getValue();
Base::FileInfo tfi(patFileName);
if (tfi.isReadable()) {
setupPatIncluded();
}
makeLineSets();
}
}
makeLineSets();
DrawViewPart::onDocumentRestored();
}

View File

@@ -119,6 +119,8 @@ public:
static const char* SectionDirEnums[];
static const char* CutSurfaceEnums[];
std::pair<Base::Vector3d, Base::Vector3d> sectionLineEnds(void);
protected:
TopoDS_Compound sectionFaces;
std::vector<TopoDS_Wire> sectionFaceWires;

View File

@@ -636,7 +636,7 @@ int GeometryObject::addCosmeticVertex(Base::Vector3d pos, std::string tagString)
// insertGeomForCE(ce)
int GeometryObject::addCosmeticEdge(CosmeticEdge* ce)
{
Base::Console().Message("GO::addCosmeticEdge(%X)\n", ce);
// Base::Console().Message("GO::addCosmeticEdge(%X) 0\n", ce);
double scale = m_parent->getScale();
TechDraw::BaseGeom* e = ce->scaledGeometry(scale);
e->cosmetic = true;
@@ -652,7 +652,7 @@ int GeometryObject::addCosmeticEdge(CosmeticEdge* ce)
int GeometryObject::addCosmeticEdge(Base::Vector3d start,
Base::Vector3d end)
{
Base::Console().Message("GO::addCosmeticEdge() 1 - deprec?\n");
// Base::Console().Message("GO::addCosmeticEdge() 1 - deprec?\n");
gp_Pnt gp1(start.x, start.y, start.z);
gp_Pnt gp2(end.x, end.y, end.z);
TopoDS_Edge occEdge = BRepBuilderAPI_MakeEdge(gp1, gp2);
@@ -670,7 +670,7 @@ int GeometryObject::addCosmeticEdge(Base::Vector3d start,
Base::Vector3d end,
std::string tagString)
{
Base::Console().Message("GO::addCosmeticEdge() 2\n");
// Base::Console().Message("GO::addCosmeticEdge() 2\n");
gp_Pnt gp1(start.x, start.y, start.z);
gp_Pnt gp2(end.x, end.y, end.z);
TopoDS_Edge occEdge = BRepBuilderAPI_MakeEdge(gp1, gp2);
@@ -687,6 +687,7 @@ int GeometryObject::addCosmeticEdge(Base::Vector3d start,
int GeometryObject::addCosmeticEdge(TechDraw::BaseGeom* base,
std::string tagString)
{
// Base::Console().Message("GO::addCosmeticEdge(%X, %s) 3\n", base, tagString.c_str());
base->cosmetic = true;
base->hlrVisible = true;
base->source(1); //1-CosmeticEdge, 2-CenterLine

View File

@@ -63,14 +63,12 @@ PropertyCenterLineList::PropertyCenterLineList()
PropertyCenterLineList::~PropertyCenterLineList()
{
for (std::vector<CenterLine*>::iterator it = _lValueList.begin(); it != _lValueList.end(); ++it)
if (*it) delete *it;
}
void PropertyCenterLineList::setSize(int newSize)
{
for (unsigned int i = newSize; i < _lValueList.size(); i++)
delete _lValueList[i];
// for (unsigned int i = newSize; i < _lValueList.size(); i++)
// delete _lValueList[i];
_lValueList.resize(newSize);
}
@@ -79,15 +77,12 @@ int PropertyCenterLineList::getSize(void) const
return static_cast<int>(_lValueList.size());
}
void PropertyCenterLineList::setValue(const CenterLine* lValue)
void PropertyCenterLineList::setValue(CenterLine* lValue)
{
if (lValue) {
aboutToSetValue();
CenterLine* newVal = lValue->clone();
for (unsigned int i = 0; i < _lValueList.size(); i++)
delete _lValueList[i];
_lValueList.resize(1);
_lValueList[0] = newVal;
_lValueList[0] = lValue;
hasSetValue();
}
}
@@ -95,13 +90,9 @@ void PropertyCenterLineList::setValue(const CenterLine* lValue)
void PropertyCenterLineList::setValues(const std::vector<CenterLine*>& lValue)
{
aboutToSetValue();
std::vector<CenterLine*> oldVals(_lValueList);
_lValueList.resize(lValue.size());
// copy all objects
for (unsigned int i = 0; i < lValue.size(); i++)
_lValueList[i] = lValue[i]->clone();
for (unsigned int i = 0; i < oldVals.size(); i++)
delete oldVals[i];
_lValueList[i] = lValue[i];
hasSetValue();
}
@@ -115,9 +106,6 @@ PyObject *PropertyCenterLineList::getPyObject(void)
void PropertyCenterLineList::setPyObject(PyObject *value)
{
// check container of this property to notify about changes
// Part2DObject* part2d = dynamic_cast<Part2DObject*>(this->getContainer());
if (PySequence_Check(value)) {
Py_ssize_t nSize = PySequence_Size(value);
std::vector<CenterLine*> values;
@@ -135,8 +123,6 @@ void PropertyCenterLineList::setPyObject(PyObject *value)
}
setValues(values);
// if (part2d)
// part2d->acceptCenterLine();
}
else if (PyObject_TypeCheck(value, &(CenterLinePy::Type))) {
CenterLinePy *pcObject = static_cast<CenterLinePy*>(value);
@@ -153,7 +139,7 @@ void PropertyCenterLineList::Save(Writer &writer) const
{
writer.Stream() << writer.ind() << "<CenterLineList count=\"" << getSize() <<"\">" << endl;
writer.incInd();
for (int i = 0; i < getSize(); i++) {
for (int i = 0; i < getSize(); i++) {
writer.Stream() << writer.ind() << "<CenterLine type=\""
<< _lValueList[i]->getTypeId().getName() << "\">" << endl;
writer.incInd();

View File

@@ -47,16 +47,7 @@ class TechDrawExport PropertyCenterLineList: public App::PropertyLists
TYPESYSTEM_HEADER();
public:
/**
* A constructor.
* A more elaborate description of the constructor.
*/
PropertyCenterLineList();
/**
* A destructor.
* A more elaborate description of the destructor.
*/
virtual ~PropertyCenterLineList();
virtual void setSize(int newSize);
@@ -64,7 +55,7 @@ public:
/** Sets the property
*/
void setValue(const CenterLine*);
void setValue(CenterLine*);
void setValues(const std::vector<CenterLine*>&);
/// index operator

View File

@@ -63,14 +63,12 @@ PropertyCosmeticEdgeList::PropertyCosmeticEdgeList()
PropertyCosmeticEdgeList::~PropertyCosmeticEdgeList()
{
for (std::vector<CosmeticEdge*>::iterator it = _lValueList.begin(); it != _lValueList.end(); ++it)
if (*it) delete *it;
}
void PropertyCosmeticEdgeList::setSize(int newSize)
{
for (unsigned int i = newSize; i < _lValueList.size(); i++)
delete _lValueList[i];
// for (unsigned int i = newSize; i < _lValueList.size(); i++)
// delete _lValueList[i];
_lValueList.resize(newSize);
}
@@ -79,15 +77,14 @@ int PropertyCosmeticEdgeList::getSize(void) const
return static_cast<int>(_lValueList.size());
}
void PropertyCosmeticEdgeList::setValue(const CosmeticEdge* lValue)
//_lValueList is not const. so why do we pass a const paramter?
void PropertyCosmeticEdgeList::setValue(CosmeticEdge* lValue)
{
if (lValue) {
aboutToSetValue();
CosmeticEdge* newVal = lValue->clone();
for (unsigned int i = 0; i < _lValueList.size(); i++)
delete _lValueList[i];
_lValueList.resize(1);
_lValueList[0] = newVal;
_lValueList[0] = lValue;
hasSetValue();
}
}
@@ -95,13 +92,9 @@ void PropertyCosmeticEdgeList::setValue(const CosmeticEdge* lValue)
void PropertyCosmeticEdgeList::setValues(const std::vector<CosmeticEdge*>& lValue)
{
aboutToSetValue();
std::vector<CosmeticEdge*> oldVals(_lValueList);
_lValueList.resize(lValue.size());
// copy all objects
for (unsigned int i = 0; i < lValue.size(); i++)
_lValueList[i] = lValue[i]->clone();
for (unsigned int i = 0; i < oldVals.size(); i++)
delete oldVals[i];
_lValueList[i] = lValue[i];
hasSetValue();
}
@@ -115,8 +108,6 @@ PyObject *PropertyCosmeticEdgeList::getPyObject(void)
void PropertyCosmeticEdgeList::setPyObject(PyObject *value)
{
// check container of this property to notify about changes
if (PySequence_Check(value)) {
Py_ssize_t nSize = PySequence_Size(value);
std::vector<CosmeticEdge*> values;

View File

@@ -64,7 +64,8 @@ public:
/** Sets the property
*/
void setValue(const CosmeticEdge*);
/* void setValue(const CosmeticEdge*);*/
void setValue(CosmeticEdge*);
void setValues(const std::vector<CosmeticEdge*>&);
/// index operator

View File

@@ -63,8 +63,6 @@ PropertyCosmeticVertexList::PropertyCosmeticVertexList()
PropertyCosmeticVertexList::~PropertyCosmeticVertexList()
{
for (std::vector<CosmeticVertex*>::iterator it = _lValueList.begin(); it != _lValueList.end(); ++it)
if (*it) delete *it;
}
void PropertyCosmeticVertexList::setSize(int newSize)
@@ -79,15 +77,12 @@ int PropertyCosmeticVertexList::getSize(void) const
return static_cast<int>(_lValueList.size());
}
void PropertyCosmeticVertexList::setValue(const CosmeticVertex* lValue)
void PropertyCosmeticVertexList::setValue(CosmeticVertex* lValue)
{
if (lValue) {
aboutToSetValue();
CosmeticVertex* newVal = lValue->clone();
for (unsigned int i = 0; i < _lValueList.size(); i++)
delete _lValueList[i];
_lValueList.resize(1);
_lValueList[0] = newVal;
_lValueList[0] = lValue;
hasSetValue();
}
}
@@ -95,13 +90,9 @@ void PropertyCosmeticVertexList::setValue(const CosmeticVertex* lValue)
void PropertyCosmeticVertexList::setValues(const std::vector<CosmeticVertex*>& lValue)
{
aboutToSetValue();
std::vector<CosmeticVertex*> oldVals(_lValueList);
_lValueList.resize(lValue.size());
// copy all objects
for (unsigned int i = 0; i < lValue.size(); i++)
_lValueList[i] = lValue[i]->clone();
for (unsigned int i = 0; i < oldVals.size(); i++)
delete oldVals[i];
_lValueList[i] = lValue[i];
hasSetValue();
}
@@ -134,8 +125,6 @@ void PropertyCosmeticVertexList::setPyObject(PyObject *value)
}
setValues(values);
// if (part2d)
// part2d->acceptCosmeticVertex();
}
else if (PyObject_TypeCheck(value, &(CosmeticVertexPy::Type))) {
CosmeticVertexPy *pcObject = static_cast<CosmeticVertexPy*>(value);

View File

@@ -64,7 +64,7 @@ public:
/** Sets the property
*/
void setValue(const CosmeticVertex*);
void setValue(CosmeticVertex*);
void setValues(const std::vector<CosmeticVertex*>&);
/// index operator

View File

@@ -348,6 +348,8 @@ void CmdTechDrawView::activated(int iMsg)
openCommand("Create view");
std::string FeatName = getUniqueObjectName("View");
doCommand(Doc,"App.activeDocument().addObject('TechDraw::DrawViewPart','%s')",FeatName.c_str());
doCommand(Doc,"App.activeDocument().%s.addView(App.activeDocument().%s)",PageName.c_str(),FeatName.c_str());
App::DocumentObject *docObj = getDocument()->getObject(FeatName.c_str());
TechDraw::DrawViewPart* dvp = dynamic_cast<TechDraw::DrawViewPart *>(docObj);
if (!dvp) {
@@ -355,7 +357,6 @@ void CmdTechDrawView::activated(int iMsg)
}
dvp->Source.setValues(shapes);
dvp->XSource.setValues(xShapes);
doCommand(Doc,"App.activeDocument().%s.addView(App.activeDocument().%s)",PageName.c_str(),FeatName.c_str());
if (faceName.size()) {
std::pair<Base::Vector3d,Base::Vector3d> dirs = DrawGuiUtil::getProjDirFromFace(partObj,faceName);
projDir = dirs.first;
@@ -1085,6 +1086,7 @@ void CmdTechDrawDraftView::activated(int iMsg)
return;
}
std::pair<Base::Vector3d,Base::Vector3d> dirs = DrawGuiUtil::get3DDirAndRot();
int draftItemsFound = 0;
for (std::vector<App::DocumentObject*>::iterator it = objects.begin(); it != objects.end(); ++it) {
if (DrawGuiUtil::isDraftObject((*it))) {
@@ -1097,6 +1099,8 @@ void CmdTechDrawDraftView::activated(int iMsg)
FeatName.c_str(),SourceName.c_str());
doCommand(Doc,"App.activeDocument().%s.addView(App.activeDocument().%s)",
PageName.c_str(),FeatName.c_str());
doCommand(Doc,"App.activeDocument().%s.Direction = FreeCAD.Vector(%.3f,%.3f,%.3f)",
FeatName.c_str(), dirs.first.x, dirs.first.y, dirs.first.z);
updateActive();
commitCommand();
}

View File

@@ -167,6 +167,8 @@ bool DrawGuiUtil::isDraftObject(App::DocumentObject* obj)
ss << (std::string)mod;
if (ss.str().find("Draft") != std::string::npos) {
result = true;
} else if (ss.str().find("draft") != std::string::npos) {
result = true;
}
}
}

View File

@@ -74,6 +74,15 @@ bool QGCustomImage::load(QString fileSpec)
return(success);
}
bool QGCustomImage::load(QPixmap map)
{
bool success = true;
m_px = map;
prepareGeometryChange();
setPixmap(m_px);
return(success);
}
QSize QGCustomImage::imageSize(void)
{
QSize result = m_px.size();

View File

@@ -53,6 +53,7 @@ public:
virtual void centerAt(QPointF centerPos);
virtual void centerAt(double cX, double cY);
virtual bool load(QString fileSpec);
virtual bool load(QPixmap map);
virtual QSize imageSize(void);
protected:

View File

@@ -58,7 +58,9 @@
#include "ZVALUE.h"
//
#include "Rez.h"
#include "DrawGuiUtil.h"
#include "QGCustomSvg.h"
#include "QGCustomImage.h"
#include "QGCustomRect.h"
#include "QGIViewPart.h"
#include "QGIPrimPath.h"
@@ -84,6 +86,9 @@ QGIFace::QGIFace(int index) :
setPrettyNormal();
m_texture = QPixmap(); //empty texture
m_image = new QGCustomImage();
m_image->setParentItem(this);
m_svg = new QGCustomSvg();
m_rect = new QGCustomRect();
@@ -139,10 +144,13 @@ void QGIFace::draw()
m_styleNormal = m_styleDef;
m_fillStyleCurrent = m_styleNormal;
loadSvgHatch(m_fileSpec);
buildSvgHatch();
if (m_hideSvgTiles) {
buildPixHatch();
m_rect->hide();
m_image->show();
} else {
buildSvgHatch();
m_image->hide();
m_rect->show();
}
} else if ((ext.toUpper() == QString::fromUtf8("JPG")) ||
@@ -553,6 +561,89 @@ void QGIFace::clearSvg()
hideSvg(true);
}
void QGIFace::buildPixHatch()
{
double wTile = SVGSIZEW * m_fillScale;
double hTile = SVGSIZEH * m_fillScale;
double w = m_outline.boundingRect().width();
double h = m_outline.boundingRect().height();
QRectF r = m_outline.boundingRect();
QPointF fCenter = r.center();
double nw = ceil(w / wTile);
double nh = ceil(h / hTile);
w = nw * wTile;
h = nh * hTile;
m_rect->setRect(0.,0.,w,-h);
m_rect->centerAt(fCenter);
r = m_rect->rect();
QByteArray before,after;
before.append(QString::fromStdString(SVGCOLPREFIX + SVGCOLDEFAULT));
after.append(QString::fromStdString(SVGCOLPREFIX + m_svgCol));
QByteArray colorXML = m_svgXML.replace(before,after);
QSvgRenderer renderer;
bool success = renderer.load(colorXML);
if (!success) {
Base::Console().Error("QGIF::buildPixHatch - renderer failed to load\n");
}
QImage imageIn(64, 64, QImage::Format_ARGB32);
imageIn.fill(Qt::transparent);
QPainter painter(&imageIn);
renderer.render(&painter);
if (imageIn.isNull()) {
Base::Console().Error("QGIF::buildPixHatch - imageIn is null\n");
return;
}
QPixmap pm(64, 64);
pm = QPixmap::fromImage(imageIn);
pm = pm.scaled(wTile, hTile);
if (pm.isNull()) {
Base::Console().Error("QGIF::buildPixHatch - pm is null\n");
return;
}
QImage tileField(w, h, QImage::Format_ARGB32);
QPointF fieldCenter(w / 2.0, h / 2.0);
tileField.fill(Qt::transparent);
QPainter painter2(&tileField);
QPainter::RenderHints hints = painter2.renderHints();
hints = hints & QPainter::Antialiasing;
painter2.setRenderHints(hints);
QPainterPath clipper = path();
QPointF offset = (fieldCenter - fCenter);
clipper.translate(offset);
painter2.setClipPath(clipper);
long int tileCount = 0;
for (int iw = 0; iw < int(nw); iw++) {
for (int ih = 0; ih < int(nh); ih++) {
painter2.drawPixmap(QRectF(iw*wTile, ih*hTile, wTile, hTile), //target rect
pm, //map
QRectF(0, 0, wTile, hTile)); //source rect
tileCount++;
if (tileCount > m_maxTile) {
Base::Console().Warning("Pixmap tile count exceeded: %ld\n",tileCount);
break;
}
}
if (tileCount > m_maxTile) {
break;
}
}
QPixmap bigMap(fabs(r.width()), fabs(r.height()));
bigMap = QPixmap::fromImage(tileField);
QPixmap nothing;
m_image->setPixmap(nothing);
m_image->load(bigMap);
m_image->centerAt(fCenter);
}
//this isn't used currently
QPixmap QGIFace::textureFromSvg(std::string fileSpec)
{

View File

@@ -29,6 +29,7 @@
#include <QByteArray>
#include <QBrush>
#include <QPixmap>
#include <QImage>
#include <Mod/TechDraw/App/HatchLine.h>
#include <Mod/TechDraw/App/Geometry.h>
@@ -39,6 +40,7 @@ namespace TechDrawGui
{
class QGCustomSvg;
class QGCustomRect;
class QGCustomImage;
const double SVGSIZEW = 64.0; //width and height of standard FC SVG pattern
const double SVGSIZEH = 64.0;
@@ -92,7 +94,10 @@ public:
void buildSvgHatch(void);
void hideSvg(bool b);
void clearSvg(void);
//tiled pixmap fill from svg
void buildPixHatch();
//PAT fill parms & methods
void setGeomHatchWeight(double w) { m_geomWeight = w; }
void setLineWeight(double w);
@@ -128,6 +133,8 @@ protected:
std::string m_svgCol;
std::string m_fileSpec; //for svg & bitmaps
QGCustomImage* m_image;
double m_fillScale;
bool m_isHatched;
QGIFace::fillMode m_mode;

View File

@@ -80,7 +80,7 @@ void QGIGhostHighlight::mousePressEvent(QGraphicsSceneMouseEvent * event)
{
// Base::Console().Message("QGIGhostHighlight::mousePress() - %X\n", this);
if ( (event->button() == Qt::LeftButton) &&
(flags() && QGraphicsItem::ItemIsMovable) ) {
(flags() & QGraphicsItem::ItemIsMovable) ) {
m_dragging = true;
event->accept();
}

View File

@@ -63,8 +63,6 @@ QGIHighlight::QGIHighlight()
m_reference->setFlag(QGraphicsItem::ItemIsSelectable, false);
setWidth(Rez::guiX(0.75));
setStyle(getHighlightStyle());
setColor(getHighlightColor());
}
QGIHighlight::~QGIHighlight()
@@ -72,41 +70,6 @@ QGIHighlight::~QGIHighlight()
}
//really only want to emit signal at end of movement
//QVariant QGIHighlight::itemChange(GraphicsItemChange change, const QVariant &value)
//{
// if (change == ItemPositionHasChanged && scene()) {
// // nothing to do here
// }
// return QGraphicsItem::itemChange(change, value);
//}
//void QGIHighlight::mousePressEvent(QGraphicsSceneMouseEvent * event)
//{
// Base::Console().Message("QGIHighlight::mousePress() - %X\n", this);
//// if(scene() && m_reference == scene()->mouseGrabberItem()) {
// if ( (event->button() == Qt::LeftButton) &&
// (flags() && QGraphicsItem::ItemIsMovable) ) {
// m_dragging = true;
// }
//// }
// QGIDecoration::mousePressEvent(event);
//}
//void QGIHighlight::mouseReleaseEvent(QGraphicsSceneMouseEvent * event)
//{
// Base::Console().Message("QGIHighlight::mouseRelease() - %X grabber: %X\n", this, scene()->mouseGrabberItem());
//// if(scene() && this == scene()->mouseGrabberItem()) {
// if (m_dragging) {
// m_dragging = false;
//// QString itemName = data(0).toString();
// Q_EMIT positionChange(pos());
// return;
// }
//// }
// QGIDecoration::mouseReleaseEvent(event);
//}
void QGIHighlight::draw()
{
prepareGeometryChange();
@@ -175,11 +138,13 @@ void QGIHighlight::setFont(QFont f, double fsize)
}
//obs?
QColor QGIHighlight::getHighlightColor()
{
return PreferencesGui::sectionLineQColor();
}
//obs??
Qt::PenStyle QGIHighlight::getHighlightStyle()
{
return PreferencesGui::sectionLineStyle();

View File

@@ -75,6 +75,13 @@ QGISectionLine::QGISectionLine()
void QGISectionLine::draw()
{
prepareGeometryChange();
int format = getPrefSectionStandard();
if (format == ANSISTANDARD) { //"ASME"/"ANSI"
extensionEndsTrad();
} else {
extensionEndsISO();
}
makeLine();
makeArrows();
makeSymbols();
@@ -84,37 +91,15 @@ void QGISectionLine::draw()
void QGISectionLine::makeLine()
{
QPainterPath pp;
QPointF beginExtLine1,beginExtLine2; //ext line start pts for measure Start side and measure End side
QPointF endExtLine1, endExtLine2;
QPointF offsetDir(m_arrowDir.x,-m_arrowDir.y);
int format = getPrefSectionStandard();
if (format == ANSISTANDARD) { //"ASME"/"ANSI"
//draw from section line endpoint
QPointF offsetBegin = m_extLen * offsetDir;
beginExtLine1 = m_start; //from
beginExtLine2 = m_end; //to
endExtLine1 = m_start + offsetBegin;
endExtLine2 = m_end + offsetBegin;
pp.moveTo(beginExtLine1);
pp.lineTo(endExtLine1);
pp.moveTo(beginExtLine2);
pp.lineTo(endExtLine2);
} else { //"ISO"
//draw from just short of section line away from section line
QPointF offsetBegin = Rez::guiX(QGIArrow::getOverlapAdjust(0,QGIArrow::getPrefArrowSize())) * offsetDir;
QPointF offsetEnd = offsetBegin + (m_extLen * offsetDir);
beginExtLine1 = m_start - offsetBegin;
beginExtLine2 = m_end - offsetBegin;
endExtLine1 = m_start - offsetEnd;
endExtLine2 = m_end - offsetEnd;
pp.moveTo(beginExtLine1);
pp.lineTo(endExtLine1);
pp.moveTo(beginExtLine2);
pp.lineTo(endExtLine2);
}
pp.moveTo(m_end);
pp.lineTo(m_start); //sectionLine
pp.moveTo(m_beginExt1);
pp.lineTo(m_endExt1);
pp.moveTo(m_beginExt2);
pp.lineTo(m_endExt2);
pp.moveTo(m_start);
pp.lineTo(m_end);
m_line->setPath(pp);
}
@@ -165,8 +150,14 @@ void QGISectionLine::makeArrowsTrad()
QPointF posArrow1,posArrow2;
QPointF offsetDir(m_arrowDir.x,-m_arrowDir.y); //remember Y dir is flipped
double offsetLength = m_extLen + Rez::guiX(QGIArrow::getOverlapAdjust(0,QGIArrow::getPrefArrowSize()));
double oblique = 1.0;
if ( !DrawUtil::fpCompare((m_arrowDir.x + m_arrowDir.y), 1.0) ) {
oblique = 1.25;
}
double offsetLength = (m_extLen * oblique) + Rez::guiX(QGIArrow::getPrefArrowSize());
QPointF offsetVec = offsetLength * offsetDir;
posArrow1 = m_start + offsetVec;
posArrow2 = m_end + offsetVec;
@@ -195,58 +186,114 @@ void QGISectionLine::makeSymbols()
void QGISectionLine::makeSymbolsTrad()
{
QPointF extLineStart,extLineEnd;
QPointF offset(m_arrowDir.x,-m_arrowDir.y);
offset = 1.5 * m_extLen * offset;
extLineStart = m_start + offset;
extLineEnd = m_end + offset;
prepareGeometryChange();
m_symFont.setPixelSize(QGIView::calculateFontPixelSize(m_symSize));
m_symbol1->setFont(m_symFont);
m_symbol1->setPlainText(QString::fromUtf8(m_symbol));
m_symbol2->setFont(m_symFont);
m_symbol2->setPlainText(QString::fromUtf8(m_symbol));
QRectF symRect = m_symbol1->boundingRect();
double symWidth = symRect.width();
double symHeight = symRect.height();
double symbolFudge = 1.0;
double symbolFudge = 0.75;
double angle = atan2f(m_arrowDir.y,m_arrowDir.x);
if (angle < 0.0) {
angle = 2 * M_PI + angle;
}
Base::Vector3d adjustVector(cos(angle) * symWidth, sin(angle) * symHeight, 0.0);
adjustVector = (DrawUtil::invertY(adjustVector) / 2.0) * symbolFudge;
adjustVector = DrawUtil::invertY(adjustVector) * symbolFudge;
QPointF qAdjust(adjustVector.x, adjustVector.y);
extLineStart += qAdjust;
m_symbol1->centerAt(extLineStart);
QPointF posSymbol1 = m_arrow1->pos() + qAdjust;
m_symbol1->centerAt(posSymbol1);
m_symbol2->setFont(m_symFont);
m_symbol2->setPlainText(QString::fromUtf8(m_symbol));
extLineEnd += qAdjust;
m_symbol2->centerAt(extLineEnd);
QPointF posSymbol2 = m_arrow2->pos() + qAdjust;
m_symbol2->centerAt(posSymbol2);
}
void QGISectionLine::makeSymbolsISO()
{
QPointF symPosStart, symPosEnd;
QPointF dist = (m_start - m_end);
double lenDist = sqrt(dist.x()*dist.x() + dist.y()*dist.y());
QPointF distDir = dist / lenDist;
QPointF offset = m_extLen * distDir;
symPosStart = m_start + offset;
symPosEnd = m_end - offset;
prepareGeometryChange();
m_symFont.setPixelSize(QGIView::calculateFontPixelSize(m_symSize));
m_symbol1->setFont(m_symFont);
m_symbol1->setPlainText(QString::fromUtf8(m_symbol));
m_symbol1->centerAt(symPosStart);
m_symbol2->setFont(m_symFont);
m_symbol2->setPlainText(QString::fromUtf8(m_symbol));
m_symbol2->centerAt(symPosEnd);
QPointF symPosStart, symPosEnd;
//no normalize() for QPointF
QPointF dist = (m_start - m_end);
double lenDist = sqrt(dist.x()*dist.x() + dist.y()*dist.y());
QPointF offsetDir = dist / lenDist;
QRectF symRect = m_symbol1->boundingRect();
double symWidth = symRect.width();
double symHeight = symRect.height();
double symbolFudge = 0.75;
double angle = atan2f(offsetDir.y(), offsetDir.x());
if (angle < 0.0) {
angle = 2.0 * M_PI + angle;
}
Base::Vector3d adjustVector(cos(angle) * symWidth, sin(angle) * symHeight, 0.0);
adjustVector = adjustVector * symbolFudge;
QPointF qAdjust(adjustVector.x, adjustVector.y);
symPosStart = m_start + qAdjust;
symPosEnd = m_end - qAdjust;
m_symbol1->centerAt(symPosStart);
m_symbol2->centerAt(symPosEnd);
}
void QGISectionLine::extensionEndsTrad()
{
QPointF offsetDir(m_arrowDir.x,-m_arrowDir.y);
//extensions for oblique section line needs to be a bit longer
double oblique = 1.0;
if ( !DrawUtil::fpCompare((m_arrowDir.x + m_arrowDir.y), 1.0) ) {
oblique = 1.25;
}
//draw from section line endpoint
QPointF offsetEnd = oblique * m_extLen * offsetDir;
m_beginExt1 = m_start;
m_endExt1 = m_start + offsetEnd;
m_beginExt2 = m_end;
m_endExt2 = m_end + offsetEnd;
}
void QGISectionLine::extensionEndsISO()
{
//lines are offset to other side of section line!
QPointF offsetDir(m_arrowDir.x,-m_arrowDir.y);
offsetDir = offsetDir * -1.0;
//extensions for oblique section line needs to be a bit longer?
//this is just esthetics
double oblique = 1.0;
if ( !DrawUtil::fpCompare((m_arrowDir.x + m_arrowDir.y), 1.0) ) {
oblique = 1.10;
}
//draw from section line endpoint less arrow length
QPointF offsetStart = offsetDir * Rez::guiX(QGIArrow::getPrefArrowSize());
QPointF offsetEnd = oblique * m_extLen * offsetDir;
m_beginExt1 = m_start + offsetStart;
m_endExt1 = m_start + offsetStart + offsetEnd;
m_beginExt2 = m_end + offsetStart;
m_endExt2 = m_end + offsetStart + offsetEnd;
}
void QGISectionLine::setEnds(Base::Vector3d l1, Base::Vector3d l2)
{
m_l1 = l1;
m_start = QPointF(l1.x, l1.y);
m_l2 = l2;
m_end = QPointF(l2.x, l2.y);
}
void QGISectionLine::setBounds(double x1,double y1,double x2,double y2)
@@ -269,6 +316,7 @@ void QGISectionLine::setDirection(double xDir,double yDir)
void QGISectionLine::setDirection(Base::Vector3d dir)
{
m_arrowDir = dir;
m_arrowDir.Normalize();
}
void QGISectionLine::setFont(QFont f, double fsize)

View File

@@ -49,6 +49,7 @@ public:
virtual void paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget = 0 );
void setEnds(Base::Vector3d l1, Base::Vector3d l2);
void setBounds(double x1,double y1,double x2,double y2);
void setSymbol(char* sym);
void setDirection(double xDir,double yDir);
@@ -71,6 +72,9 @@ protected:
void makeSymbolsISO();
void setTools();
int getPrefSectionStandard();
void extensionEndsISO();
void extensionEndsTrad();
private:
char* m_symbol;
@@ -89,6 +93,12 @@ private:
//QColor m_color;
double m_extLen;
// int m_sectionFormat; //0 = ASME, 1 = ISO
Base::Vector3d m_l1; //end of main section line
Base::Vector3d m_l2; //end of main section line
QPointF m_beginExt1; //start of extension line 1
QPointF m_endExt1; //end of extension line 1
QPointF m_beginExt2; //start of extension line 2
QPointF m_endExt2; //end of extension line 1
};
}

View File

@@ -43,6 +43,7 @@
#include <Mod/TechDraw/App/DrawViewImage.h>
#include "Rez.h"
#include "ViewProviderImage.h"
#include "QGCustomImage.h"
#include "QGCustomClip.h"
#include "QGIViewImage.h"
@@ -117,9 +118,21 @@ void QGIViewImage::draw()
auto viewImage( dynamic_cast<TechDraw::DrawViewImage*>(getViewObject()) );
if (!viewImage)
return;
QRectF newRect(0.0,0.0,viewImage->Width.getValue(),viewImage->Height.getValue());
m_cliparea->setRect(newRect);
auto vp = static_cast<ViewProviderImage*>(getViewProvider(getViewObject()));
if ( vp == nullptr ) {
return;
}
bool crop = vp->Crop.getValue();
drawImage();
if (crop) {
QRectF cropRect(0.0,0.0,Rez::guiX(viewImage->Width.getValue()),Rez::guiX(viewImage->Height.getValue()));
m_cliparea->setRect(cropRect);
} else {
QRectF cropRect(0.0, 0.0, m_imageItem->imageSize().width(), m_imageItem->imageSize().height());
m_cliparea->setRect(cropRect);
}
m_cliparea->centerAt(0.0,0.0);
QGIView::draw();

View File

@@ -84,6 +84,7 @@
using namespace TechDraw;
using namespace TechDrawGui;
using namespace std;
#define GEOMETRYEDGE 0
#define COSMETICEDGE 1
@@ -407,7 +408,6 @@ QPainterPath QGIViewPart::geomToPainterPath(TechDraw::BaseGeom *baseGeom, double
void QGIViewPart::updateView(bool update)
{
// Base::Console().Message("QGIVP::updateView()\n");
auto start = std::chrono::high_resolution_clock::now();
auto viewPart( dynamic_cast<TechDraw::DrawViewPart *>(getViewObject()) );
if( viewPart == nullptr ) {
return;
@@ -421,15 +421,9 @@ void QGIViewPart::updateView(bool update)
draw();
}
QGIView::updateView(update);
auto end = std::chrono::high_resolution_clock::now();
auto diff = end - start;
double diffOut = std::chrono::duration <double, std::milli> (diff).count();
Base::Console().Log("TIMING - QGIVP::updateView - %s - total %.3f millisecs\n",getViewName(),diffOut);
}
void QGIViewPart::draw() {
// Base::Console().Message("QGIVP::draw()\n");
if (!isVisible()) {
return;
}
@@ -459,7 +453,6 @@ void QGIViewPart::drawViewPart()
return;
}
float lineWidth = vp->LineWidth.getValue() * lineScaleFactor;
float lineWidthHid = vp->HiddenWidth.getValue() * lineScaleFactor;
float lineWidthIso = vp->IsoWidth.getValue() * lineScaleFactor;
@@ -513,22 +506,20 @@ void QGIViewPart::drawViewPart()
if (!fHatch->SvgIncluded.isEmpty()) {
if (getExporting()) {
newFace->hideSvg(true);
newFace->isHatched(false);
newFace->setFillMode(QGIFace::PlainFill);
} else {
newFace->hideSvg(false);
newFace->isHatched(true);
newFace->setFillMode(QGIFace::FromFile);
newFace->setHatchFile(fHatch->SvgIncluded.getValue());
Gui::ViewProvider* gvp = QGIView::getViewProvider(fHatch);
ViewProviderHatch* hatchVp = dynamic_cast<ViewProviderHatch*>(gvp);
if (hatchVp != nullptr) {
double hatchScale = hatchVp->HatchScale.getValue();
if (hatchScale > 0.0) {
newFace->setHatchScale(hatchVp->HatchScale.getValue());
}
newFace->setHatchColor(hatchVp->HatchColor.getValue());
}
newFace->isHatched(true);
newFace->setFillMode(QGIFace::SvgFill);
newFace->setHatchFile(fHatch->SvgIncluded.getValue());
Gui::ViewProvider* gvp = QGIView::getViewProvider(fHatch);
ViewProviderHatch* hatchVp = dynamic_cast<ViewProviderHatch*>(gvp);
if (hatchVp != nullptr) {
double hatchScale = hatchVp->HatchScale.getValue();
if (hatchScale > 0.0) {
newFace->setHatchScale(hatchVp->HatchScale.getValue());
}
newFace->setHatchColor(hatchVp->HatchColor.getValue());
}
}
}
@@ -844,88 +835,31 @@ void QGIViewPart::drawSectionLine(TechDraw::DrawViewSection* viewSection, bool b
sectionLine->setSectionStyle(vp->SectionLineStyle.getValue());
sectionLine->setSectionColor(vp->SectionLineColor.getValue().asValue<QColor>());
//TODO: handle oblique section lines?
//find smallest internal angle(normalDir,get?Dir()) and use -1*get?Dir() +/- angle
//Base::Vector3d normalDir = viewSection->SectionNormal.getValue();
Base::Vector3d arrowDir(0,1,0); //for drawing only, not geom
Base::Vector3d lineDir(1,0,0);
bool horiz = false;
//this is a hack we can use since we don't support oblique section lines yet.
//better solution will be need if oblique is ever implemented
double rot = viewPart->Rotation.getValue();
bool switchWH = false;
if (TechDraw::DrawUtil::fpCompare(fabs(rot), 90.0)) {
switchWH = true;
}
if (viewSection->SectionDirection.isValue("Right")) {
arrowDir = Base::Vector3d(1,0,0);
lineDir = Base::Vector3d(0,1,0);
} else if (viewSection->SectionDirection.isValue("Left")) {
arrowDir = Base::Vector3d(-1,0,0);
lineDir = Base::Vector3d(0,-1,0);
} else if (viewSection->SectionDirection.isValue("Up")) {
arrowDir = Base::Vector3d(0,1,0);
lineDir = Base::Vector3d(1,0,0);
horiz = true;
} else if (viewSection->SectionDirection.isValue("Down")) {
arrowDir = Base::Vector3d(0,-1,0);
lineDir = Base::Vector3d(-1,0,0);
horiz = true;
}
sectionLine->setDirection(arrowDir.x,arrowDir.y);
//dvp is centered on centroid looking along dvp direction
//dvs is centered on SO looking along section normal
//dvp view origin is 000 + centroid
Base::Vector3d org = viewSection->SectionOrigin.getValue();
Base::Vector3d cent = viewPart->getOriginalCentroid();
Base::Vector3d adjOrg = org - cent;
//find the ends of the section line
double scale = viewPart->getScale();
std::pair<Base::Vector3d, Base::Vector3d> sLineEnds = viewSection->sectionLineEnds();
Base::Vector3d l1 = Rez::guiX(sLineEnds.first) * scale;
Base::Vector3d l2 = Rez::guiX(sLineEnds.second) * scale;
Base::Vector3d pAdjOrg = scale * viewPart->projectPoint(adjOrg);
//which way to the arrows point?
Base::Vector3d lineDir = l2 - l1;
lineDir.Normalize();
Base::Vector3d normalDir = viewSection->SectionNormal.getValue();
Base::Vector3d projNormal = viewPart->projectPoint(normalDir);
projNormal.Normalize();
Base::Vector3d arrowDir = viewSection->SectionNormal.getValue();
arrowDir = - viewPart->projectPoint(arrowDir); //arrows point reverse of sectionNormal(extrusion dir)
sectionLine->setDirection(arrowDir.x, -arrowDir.y); //invert Y
//now project pOrg onto arrowDir
Base::Vector3d displace;
displace.ProjectToLine(pAdjOrg, arrowDir);
Base::Vector3d offset = pAdjOrg + displace;
//make the section line a little longer
double fudge = Rez::guiX(2.0 * Preferences::dimFontSizeMM());
sectionLine->setEnds(l1 - lineDir * fudge,
l2 + lineDir * fudge);
// makeMark(0.0, 0.0); //red
// makeMark(Rez::guiX(offset.x),
// Rez::guiX(offset.y),
// Qt::green);
sectionLine->setPos(Rez::guiX(offset.x),Rez::guiX(offset.y));
double sectionSpan;
double sectionFudge = Rez::guiX(10.0);
double xVal, yVal;
// double fontSize = getPrefFontSize();
// double fontSize = getDimFontSize();
double fontSize = Preferences::dimFontSizeMM();
if (horiz) {
double width = Rez::guiX(viewPart->getBoxX());
double height = Rez::guiX(viewPart->getBoxY());
if (switchWH) {
sectionSpan = height + sectionFudge;
} else {
sectionSpan = width + sectionFudge;
}
xVal = sectionSpan / 2.0;
yVal = 0.0;
} else {
double width = Rez::guiX(viewPart->getBoxX());
double height = Rez::guiX(viewPart->getBoxY());
if (switchWH) {
sectionSpan = width + sectionFudge;
} else {
sectionSpan = height + sectionFudge;
}
xVal = 0.0;
yVal = sectionSpan / 2.0;
}
sectionLine->setBounds(-xVal,-yVal,xVal,yVal);
//set the general parameters
sectionLine->setPos(0.0, 0.0);
sectionLine->setWidth(Rez::guiX(vp->LineWidth.getValue()));
double fontSize = Preferences::dimFontSizeMM();
sectionLine->setFont(m_font, fontSize);
sectionLine->setZValue(ZVALUE::SECTIONLINE);
sectionLine->setRotation(viewPart->Rotation.getValue());

View File

@@ -115,18 +115,15 @@ void QGIViewSection::drawSectionFace()
} else if (section->CutSurfaceDisplay.isValue("SvgHatch")) {
if (getExporting()) {
newFace->hideSvg(true);
newFace->isHatched(false);
newFace->setFillMode(QGIFace::PlainFill);
} else {
newFace->hideSvg(false);
newFace->isHatched(true);
newFace->setFillMode(QGIFace::SvgFill);
newFace->setHatchColor(sectionVp->HatchColor.getValue());
newFace->setHatchScale(section->HatchScale.getValue());
// std::string hatchSpec = section->FileHatchPattern.getValue();
std::string hatchSpec = section->SvgIncluded.getValue();
newFace->setHatchFile(hatchSpec);
}
newFace->setFillMode(QGIFace::SvgFill);
newFace->setHatchColor(sectionVp->HatchColor.getValue());
newFace->setHatchScale(section->HatchScale.getValue());
// std::string hatchSpec = section->FileHatchPattern.getValue();
std::string hatchSpec = section->SvgIncluded.getValue();
newFace->setHatchFile(hatchSpec);
} else if (section->CutSurfaceDisplay.isValue("PatHatch")) {
newFace->isHatched(true);
newFace->setFillMode(QGIFace::GeomHatchFill);

View File

@@ -773,18 +773,22 @@ void QGVPage::refreshViews(void)
void QGVPage::setExporting(bool enable)
{
// Base::Console().Message("QGVP::setExporting(%d)\n", enable);
QList<QGraphicsItem*> sceneItems = scene()->items();
std::vector<QGIViewPart*> dvps;
for (auto& qgi:sceneItems) {
QGIViewPart* qgiPart = dynamic_cast<QGIViewPart *>(qgi);
QGIRichAnno* qgiRTA = dynamic_cast<QGIRichAnno *>(qgi);
if(qgiPart) {
qgiPart->setExporting(enable);
dvps.push_back(qgiPart);
}
if (qgiRTA) {
qgiRTA->setExporting(enable);
}
}
for (auto& v: dvps) {
v->draw();
}
}
void QGVPage::saveSvg(QString filename)
@@ -848,7 +852,7 @@ void QGVPage::saveSvg(QString filename)
QPainter p;
p.begin(&svgGen);
scene()->render(&p, targetRect,sourceRect);
scene()->render(&p, targetRect,sourceRect); //note: scene render, not item render!
p.end();
m_vpPage->setFrameState(saveState);

View File

@@ -397,7 +397,6 @@ void TaskCenterLine::updateCenterLine(void)
m_cl->m_extendBy = ui->qsbExtend->rawValue();
m_cl->m_type = m_type;
m_cl->m_flip2Line = ui->cbFlip->isChecked();
m_partFeat->replaceCenterLine(m_cl);
m_partFeat->refreshCLGeoms();
m_partFeat->requestPaint();

View File

@@ -49,6 +49,8 @@ PROPERTY_SOURCE(TechDrawGui::ViewProviderImage, TechDrawGui::ViewProviderDrawing
ViewProviderImage::ViewProviderImage()
{
sPixmap = "actions/techdraw-image";
ADD_PROPERTY_TYPE(Crop ,(false),"Image", App::Prop_None, "Crop image to Width x Height");
}
ViewProviderImage::~ViewProviderImage()
@@ -79,6 +81,25 @@ void ViewProviderImage::updateData(const App::Property* prop)
ViewProviderDrawingView::updateData(prop);
}
void ViewProviderImage::onChanged(const App::Property *prop)
{
App::DocumentObject* obj = getObject();
if (!obj || obj->isRestoring()) {
Gui::ViewProviderDocumentObject::onChanged(prop);
return;
}
if (prop == &Crop) {
QGIView* qgiv = getQView();
if (qgiv) {
qgiv->updateView(true);
}
}
Gui::ViewProviderDocumentObject::onChanged(prop);
}
TechDraw::DrawViewImage* ViewProviderImage::getViewObject() const
{
return dynamic_cast<TechDraw::DrawViewImage*>(pcObject);

View File

@@ -41,6 +41,7 @@ public:
/// destructor
virtual ~ViewProviderImage();
App::PropertyBool Crop; //crop to feature width x height
virtual void attach(App::DocumentObject *);
virtual void setDisplayMode(const char* ModeName);
@@ -48,6 +49,7 @@ public:
/// returns a list of all possible modes
virtual std::vector<std::string> getDisplayModes(void) const;
virtual void updateData(const App::Property*);
virtual void onChanged(const App::Property *prop);
virtual TechDraw::DrawViewImage* getViewObject() const;
};