From af7d257b91fbadd8bff3ce936061ef932c10c019 Mon Sep 17 00:00:00 2001 From: WandererFan Date: Sun, 31 Jul 2016 19:42:42 -0400 Subject: [PATCH] Add centermarks for circles in Views --- src/Mod/TechDraw/App/DrawViewPart.cpp | 19 ++--- src/Mod/TechDraw/App/DrawViewPart.h | 4 +- src/Mod/TechDraw/App/Geometry.cpp | 12 ++++ src/Mod/TechDraw/App/Geometry.h | 12 ++-- src/Mod/TechDraw/App/GeometryObject.cpp | 25 ++++++- src/Mod/TechDraw/Gui/CMakeLists.txt | 2 + src/Mod/TechDraw/Gui/QGICMark.cpp | 92 +++++++++++++++++++++++++ src/Mod/TechDraw/Gui/QGICMark.h | 61 ++++++++++++++++ src/Mod/TechDraw/Gui/QGIViewPart.cpp | 37 +++++++--- 9 files changed, 239 insertions(+), 25 deletions(-) create mode 100644 src/Mod/TechDraw/Gui/QGICMark.cpp create mode 100644 src/Mod/TechDraw/Gui/QGICMark.h diff --git a/src/Mod/TechDraw/App/DrawViewPart.cpp b/src/Mod/TechDraw/App/DrawViewPart.cpp index 758028701296..0d73dfc126d6 100644 --- a/src/Mod/TechDraw/App/DrawViewPart.cpp +++ b/src/Mod/TechDraw/App/DrawViewPart.cpp @@ -89,8 +89,8 @@ PROPERTY_SOURCE(TechDraw::DrawViewPart, TechDraw::DrawView) DrawViewPart::DrawViewPart(void) : geometryObject(0) { - static const char *group = "Shape view"; - static const char *vgroup = "Drawing view"; + static const char *group = "Projection"; + static const char *fgroup = "Format"; ADD_PROPERTY_TYPE(Direction ,(0,0,1.0) ,group,App::Prop_None,"Projection normal direction"); ADD_PROPERTY_TYPE(Source ,(0),group,App::Prop_None,"3D Shape to view"); @@ -98,11 +98,13 @@ DrawViewPart::DrawViewPart(void) : geometryObject(0) ADD_PROPERTY_TYPE(ShowSmoothLines ,(false),group,App::Prop_None,"Smooth lines on/off"); ADD_PROPERTY_TYPE(ShowSeamLines ,(false),group,App::Prop_None,"Seam lines on/off"); //ADD_PROPERTY_TYPE(ShowIsoLines ,(false),group,App::Prop_None,"Iso u,v lines on/off"); - ADD_PROPERTY_TYPE(LineWidth,(0.7f),vgroup,App::Prop_None,"The thickness of visible lines"); - ADD_PROPERTY_TYPE(HiddenWidth,(0.15),vgroup,App::Prop_None,"The thickness of hidden lines, if enabled"); - ADD_PROPERTY_TYPE(Tolerance,(0.05f),vgroup,App::Prop_None,"The tessellation tolerance"); //tessellation? + ADD_PROPERTY_TYPE(Tolerance,(0.05f),group,App::Prop_None,"Internal tolerance"); Tolerance.setConstraints(&floatRange); ADD_PROPERTY_TYPE(XAxisDirection ,(1,0,0) ,group,App::Prop_None,"Direction to use as X-axis in projection"); + ADD_PROPERTY_TYPE(LineWidth,(0.7f),fgroup,App::Prop_None,"The thickness of visible lines"); + ADD_PROPERTY_TYPE(HiddenWidth,(0.15),fgroup,App::Prop_None,"The thickness of hidden lines, if enabled"); + ADD_PROPERTY_TYPE(ShowCenters ,(true),fgroup,App::Prop_None,"Center marks on/off"); + ADD_PROPERTY_TYPE(CenterScale,(2.0),fgroup,App::Prop_None,"Center mark size adjustment, if enabled"); geometryObject = new TechDrawGeometry::GeometryObject(); } @@ -158,9 +160,6 @@ App::DocumentObjectExecReturn *DrawViewPart::execute(void) view->touch(); } } - - touch(); - return DrawView::execute(); } @@ -192,7 +191,9 @@ void DrawViewPart::onChanged(const App::Property* prop) prop == &ShowSmoothLines || prop == &ShowSeamLines || prop == &LineWidth || - prop == &HiddenWidth ) { + prop == &HiddenWidth || + prop == &ShowCenters || + prop == &CenterScale ) { try { App::DocumentObjectExecReturn *ret = recompute(); delete ret; diff --git a/src/Mod/TechDraw/App/DrawViewPart.h b/src/Mod/TechDraw/App/DrawViewPart.h index f73e85e1a902..b50e0e015cb8 100644 --- a/src/Mod/TechDraw/App/DrawViewPart.h +++ b/src/Mod/TechDraw/App/DrawViewPart.h @@ -70,8 +70,10 @@ class TechDrawExport DrawViewPart : public DrawView App::PropertyBool ShowSeamLines; App::PropertyFloat LineWidth; App::PropertyFloat HiddenWidth; + App::PropertyBool ShowCenters; + App::PropertyFloat CenterScale; App::PropertyFloatConstraint Tolerance; - + std::vector getHatches(void) const; //TODO: are there use-cases for Python access to TechDrawGeometry??? diff --git a/src/Mod/TechDraw/App/Geometry.cpp b/src/Mod/TechDraw/App/Geometry.cpp index 28e4ce939c92..6993709b5c66 100644 --- a/src/Mod/TechDraw/App/Geometry.cpp +++ b/src/Mod/TechDraw/App/Geometry.cpp @@ -38,6 +38,7 @@ #include #include #include +#include #include #include #include @@ -255,6 +256,8 @@ Circle::Circle(const TopoDS_Edge &e) gp_Circ circ = c.Circle(); const gp_Pnt& p = circ.Location(); + const gp_Ax2& p1 = circ.Position(); + const gp_Pnt& l = p1.Location(); radius = circ.Radius(); center = Base::Vector2D(p.X(), p.Y()); @@ -436,6 +439,15 @@ bool BSpline::isLine() //**** Vertex +Vertex::Vertex(double x, double y) +{ + pnt = Base::Vector2D(x, y); + extractType = ExtractionType::Plain; //obs? + visible = false; + ref3D = -1; //obs. never used. + isCenter = false; +} + bool Vertex::isEqual(Vertex* v, double tol) { bool result = false; diff --git a/src/Mod/TechDraw/App/Geometry.h b/src/Mod/TechDraw/App/Geometry.h index 34f169a4e80a..067c64bd5a31 100644 --- a/src/Mod/TechDraw/App/Geometry.h +++ b/src/Mod/TechDraw/App/Geometry.h @@ -221,16 +221,20 @@ class TechDrawExport Face class TechDrawExport Vertex { public: - Vertex(double x, double y) { pnt = Base::Vector2D(x, y); } - Vertex(Base::Vector2D v) { pnt = v; } + Vertex(double x, double y); + Vertex(Base::Vector2D v) : Vertex(v.fX,v.fY) {} ~Vertex() = default; Base::Vector2D pnt; - ExtractionType extractType; + ExtractionType extractType; //obs? bool visible; - int ref3D; + int ref3D; //obs. never used. + bool isCenter; TopoDS_Vertex occVertex; bool isEqual(Vertex* v, double tol); + Base::Vector3d getAs3D(void) {return Base::Vector3d(pnt.fX,pnt.fY,0.0);} + double x() {return pnt.fX;} + double y() {return pnt.fY;} }; /// Encapsulates some useful static methods diff --git a/src/Mod/TechDraw/App/GeometryObject.cpp b/src/Mod/TechDraw/App/GeometryObject.cpp index 174f9b5e3f9c..3ffd09cade38 100644 --- a/src/Mod/TechDraw/App/GeometryObject.cpp +++ b/src/Mod/TechDraw/App/GeometryObject.cpp @@ -248,8 +248,17 @@ void GeometryObject::addGeomFromCompound(TopoDS_Shape edgeCompound, edgeClass ca BaseGeom* lastAdded = edgeGeom.back(); //if (edgeGeom.empty()) {horrible_death();} //back() undefined behavior (can't happen? baseFactory always returns a Base?) bool v1Add = true, v2Add = true; + bool c1Add = true; TechDrawGeometry::Vertex* v1 = new TechDrawGeometry::Vertex(lastAdded->getStartPoint()); TechDrawGeometry::Vertex* v2 = new TechDrawGeometry::Vertex(lastAdded->getEndPoint()); + TechDrawGeometry::Circle* circle = dynamic_cast(lastAdded); + TechDrawGeometry::Vertex* c1 = nullptr; + if (circle) { + c1 = new TechDrawGeometry::Vertex(circle->center); + c1->isCenter = true; + c1->visible = true; + } + std::vector::iterator itVertex = vertexGeom.begin(); for (; itVertex != vertexGeom.end(); itVertex++) { if ((*itVertex)->isEqual(v1,Tolerance)) { @@ -258,6 +267,12 @@ void GeometryObject::addGeomFromCompound(TopoDS_Shape edgeCompound, edgeClass ca if ((*itVertex)->isEqual(v2,Tolerance)) { v2Add = false; } + if (circle) { + if ((*itVertex)->isEqual(c1,Tolerance)) { + c1Add = true; + } + } + } if (v1Add) { vertexGeom.push_back(v1); @@ -271,8 +286,16 @@ void GeometryObject::addGeomFromCompound(TopoDS_Shape edgeCompound, edgeClass ca } else { delete v2; } - } + if (circle) { + if (c1Add) { + vertexGeom.push_back(c1); + c1->visible = true; + } else { + delete c1; + } + } + } } } diff --git a/src/Mod/TechDraw/Gui/CMakeLists.txt b/src/Mod/TechDraw/Gui/CMakeLists.txt index d03ca04c763e..791e3db041de 100644 --- a/src/Mod/TechDraw/Gui/CMakeLists.txt +++ b/src/Mod/TechDraw/Gui/CMakeLists.txt @@ -130,6 +130,8 @@ SET(TechDrawGuiView_SRCS QGIViewClip.h QGIPrimPath.cpp QGIPrimPath.h + QGICMark.cpp + QGICMark.h TemplateTextField.cpp TemplateTextField.h ZVALUE.h diff --git a/src/Mod/TechDraw/Gui/QGICMark.cpp b/src/Mod/TechDraw/Gui/QGICMark.cpp new file mode 100644 index 000000000000..d9056aec0e84 --- /dev/null +++ b/src/Mod/TechDraw/Gui/QGICMark.cpp @@ -0,0 +1,92 @@ +/*************************************************************************** + * Copyright (c) 2016 Wandererfan * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + +#include "PreCompiled.h" +#ifndef _PreComp_ +#include +#include +#include +#include +#include +#include +#endif + +#include +#include +#include +#include + +#include "QGICMark.h" + +using namespace TechDrawGui; + +QGICMark::QGICMark(int index) : QGIVertex(index) +{ + m_size = 3.0; + m_thick = 0.75; + draw(); +} +void QGICMark::draw(void) +{ + QPainterPath cmPath; + cmPath.moveTo(0.0,m_size); + cmPath.lineTo(0.0,-m_size); + cmPath.moveTo(m_size,0.0); + cmPath.lineTo(-m_size,0.0); + setPath(cmPath); +} + +void QGICMark::setSize(float s) +{ + m_size = s; + draw(); +} + +void QGICMark::setThick(float t) +{ + m_thick = t; + m_pen.setWidthF(m_thick); + draw(); +} + +QColor QGICMark::getCMarkColor() +{ + Base::Reference hGrp = App::GetApplication().GetUserParameter() + .GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw/Colors"); + App::Color fcColor = App::Color((uint32_t) hGrp->GetUnsigned("CMarkColor", 0x08080800)); + return fcColor.asValue(); +} + +void QGICMark::setPrettyNormal() { + m_colCurrent = getCMarkColor(); + update(); +} + +void QGICMark::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) +{ + QStyleOptionGraphicsItem myOption(*option); + myOption.state &= ~QStyle::State_Selected; + + m_pen.setWidthF(m_thick); + + QGIVertex::paint (painter, &myOption, widget); +} diff --git a/src/Mod/TechDraw/Gui/QGICMark.h b/src/Mod/TechDraw/Gui/QGICMark.h new file mode 100644 index 000000000000..55859f21a5fc --- /dev/null +++ b/src/Mod/TechDraw/Gui/QGICMark.h @@ -0,0 +1,61 @@ +/*************************************************************************** + * Copyright (c) 2013 Luke Parry * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + +#ifndef DRAWINGGUI_QGRAPHICSITEMCMARK_H +#define DRAWINGGUI_QGRAPHICSITEMCMARK_H + +# include "QGIVertex.h" + +namespace TechDrawGui +{ + +class TechDrawGuiExport QGICMark : public QGIVertex +{ +public: + explicit QGICMark(int index); + ~QGICMark() {} + + enum {Type = QGraphicsItem::UserType + 171}; + int type() const { return Type;} + virtual void paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget = 0 ); + + int getProjIndex() const { return projIndex; } + + void draw(void); + float getSize() { return m_size; } + void setSize(float s); + float getThick() { return m_thick; } + void setThick(float t); + virtual void setPrettyNormal(); + +protected: + int projIndex; + QColor getCMarkColor(); + +private: + float m_size; + float m_thick; +}; + +} + +#endif // DRAWINGGUI_QGRAPHICSITEMCMARK_H diff --git a/src/Mod/TechDraw/Gui/QGIViewPart.cpp b/src/Mod/TechDraw/Gui/QGIViewPart.cpp index 107e438ae14a..9645b4b710d2 100644 --- a/src/Mod/TechDraw/Gui/QGIViewPart.cpp +++ b/src/Mod/TechDraw/Gui/QGIViewPart.cpp @@ -55,6 +55,7 @@ #include "QGIFace.h" #include "QGIEdge.h" #include "QGIVertex.h" +#include "QGICMark.h" #include "QGIViewPart.h" using namespace TechDrawGui; @@ -135,7 +136,6 @@ QPainterPath QGIViewPart::drawPainterPath(TechDrawGeometry::BaseGeom *baseGeom) path.addEllipse(x, y, geom->radius * 2, geom->radius * 2); //topleft@(x,y) radx,rady //Base::Console().Message("TRACE -drawPainterPath - making an CIRCLE @(%.3f,%.3f) R:%.3f\n",x, y, geom->radius); - } break; case TechDrawGeometry::ARCOFCIRCLE: { TechDrawGeometry::AOC *geom = static_cast(baseGeom); @@ -351,12 +351,25 @@ void QGIViewPart::drawViewPart() // Draw Vertexs: const std::vector &verts = viewPart->getVertexGeometry(); std::vector::const_iterator vert = verts.begin(); + bool showCenters = viewPart->ShowCenters.getValue(); + double cAdjust = viewPart->CenterScale.getValue(); for(int i = 0 ; vert != verts.end(); ++vert, i++) { - QGIVertex *item = new QGIVertex(i); - addToGroup(item); - item->setPos((*vert)->pnt.fX, (*vert)->pnt.fY); //this is in ViewPart coords - item->setRadius(lineWidth * vertexScaleFactor); - item->setZValue(ZVALUE::VERTEX); + if ((*vert)->isCenter) { + if (showCenters) { + QGICMark* cmItem = new QGICMark(i); + addToGroup(cmItem); + cmItem->setPos((*vert)->pnt.fX, (*vert)->pnt.fY); //this is in ViewPart coords + cmItem->setThick(0.5 * lineWidth * lineScaleFactor); + cmItem->setSize( cAdjust * lineWidth * vertexScaleFactor); + cmItem->setZValue(ZVALUE::VERTEX); + } + } else { + QGIVertex *item = new QGIVertex(i); + addToGroup(item); + item->setPos((*vert)->pnt.fX, (*vert)->pnt.fY); //this is in ViewPart coords + item->setRadius(lineWidth * vertexScaleFactor); + item->setZValue(ZVALUE::VERTEX); + } } } @@ -551,11 +564,15 @@ void QGIViewPart::toggleVertices(bool state) QList items = childItems(); for(QList::iterator it = items.begin(); it != items.end(); it++) { QGIVertex *vert = dynamic_cast(*it); + QGICMark *mark = dynamic_cast(*it); + if(vert) { - if(state) - vert->show(); - else - vert->hide(); + if (!mark) { //leave center marks showing + if(state) + vert->show(); + else + vert->hide(); + } } } }