Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add centermarks for circles in Views
  • Loading branch information
WandererFan authored and wwmayer committed Aug 16, 2016
1 parent 464a8f3 commit af7d257
Show file tree
Hide file tree
Showing 9 changed files with 239 additions and 25 deletions.
19 changes: 10 additions & 9 deletions src/Mod/TechDraw/App/DrawViewPart.cpp
Expand Up @@ -89,20 +89,22 @@ 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");
ADD_PROPERTY_TYPE(ShowHiddenLines ,(false),group,App::Prop_None,"Hidden lines on/off");
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();
}
Expand Down Expand Up @@ -158,9 +160,6 @@ App::DocumentObjectExecReturn *DrawViewPart::execute(void)
view->touch();
}
}

touch();

return DrawView::execute();
}

Expand Down Expand Up @@ -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;
Expand Down
4 changes: 3 additions & 1 deletion src/Mod/TechDraw/App/DrawViewPart.h
Expand Up @@ -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<TechDraw::DrawHatch*> getHatches(void) const;

//TODO: are there use-cases for Python access to TechDrawGeometry???
Expand Down
12 changes: 12 additions & 0 deletions src/Mod/TechDraw/App/Geometry.cpp
Expand Up @@ -38,6 +38,7 @@
#include <gp_Pnt.hxx>
#include <gp_Dir.hxx>
#include <gp_Vec.hxx>
#include <gp_Ax2.hxx>
#include <Geom_BSplineCurve.hxx>
#include <Geom_BezierCurve.hxx>
#include <GeomConvert_BSplineCurveToBezierCurve.hxx>
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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;
Expand Down
12 changes: 8 additions & 4 deletions src/Mod/TechDraw/App/Geometry.h
Expand Up @@ -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
Expand Down
25 changes: 24 additions & 1 deletion src/Mod/TechDraw/App/GeometryObject.cpp
Expand Up @@ -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<TechDrawGeometry::Circle*>(lastAdded);
TechDrawGeometry::Vertex* c1 = nullptr;
if (circle) {
c1 = new TechDrawGeometry::Vertex(circle->center);
c1->isCenter = true;
c1->visible = true;
}

std::vector<Vertex *>::iterator itVertex = vertexGeom.begin();
for (; itVertex != vertexGeom.end(); itVertex++) {
if ((*itVertex)->isEqual(v1,Tolerance)) {
Expand All @@ -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);
Expand All @@ -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;
}
}
}
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/Mod/TechDraw/Gui/CMakeLists.txt
Expand Up @@ -130,6 +130,8 @@ SET(TechDrawGuiView_SRCS
QGIViewClip.h
QGIPrimPath.cpp
QGIPrimPath.h
QGICMark.cpp
QGICMark.h
TemplateTextField.cpp
TemplateTextField.h
ZVALUE.h
Expand Down
92 changes: 92 additions & 0 deletions src/Mod/TechDraw/Gui/QGICMark.cpp
@@ -0,0 +1,92 @@
/***************************************************************************
* Copyright (c) 2016 Wandererfan <WandererFan@gmail.com> *
* *
* 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 <assert.h>
#include <QGraphicsScene>
#include <QGraphicsSceneHoverEvent>
#include <QMouseEvent>
#include <QPainter>
#include <QStyleOptionGraphicsItem>
#endif

#include <App/Application.h>
#include <App/Material.h>
#include <Base/Console.h>
#include <Base/Parameter.h>

#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<ParameterGrp> 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<QColor>();
}

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);
}
61 changes: 61 additions & 0 deletions src/Mod/TechDraw/Gui/QGICMark.h
@@ -0,0 +1,61 @@
/***************************************************************************
* Copyright (c) 2013 Luke Parry <l.parry@warwick.ac.uk> *
* *
* 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
37 changes: 27 additions & 10 deletions src/Mod/TechDraw/Gui/QGIViewPart.cpp
Expand Up @@ -55,6 +55,7 @@
#include "QGIFace.h"
#include "QGIEdge.h"
#include "QGIVertex.h"
#include "QGICMark.h"
#include "QGIViewPart.h"

using namespace TechDrawGui;
Expand Down Expand Up @@ -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<TechDrawGeometry::AOC *>(baseGeom);
Expand Down Expand Up @@ -351,12 +351,25 @@ void QGIViewPart::drawViewPart()
// Draw Vertexs:
const std::vector<TechDrawGeometry::Vertex *> &verts = viewPart->getVertexGeometry();
std::vector<TechDrawGeometry::Vertex *>::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);
}
}
}

Expand Down Expand Up @@ -551,11 +564,15 @@ void QGIViewPart::toggleVertices(bool state)
QList<QGraphicsItem*> items = childItems();
for(QList<QGraphicsItem*>::iterator it = items.begin(); it != items.end(); it++) {
QGIVertex *vert = dynamic_cast<QGIVertex *>(*it);
QGICMark *mark = dynamic_cast<QGICMark *>(*it);

if(vert) {
if(state)
vert->show();
else
vert->hide();
if (!mark) { //leave center marks showing
if(state)
vert->show();
else
vert->hide();
}
}
}
}
Expand Down

0 comments on commit af7d257

Please sign in to comment.