From 9ef6b76977c8219a7da127c9c637b6227037fb7b Mon Sep 17 00:00:00 2001 From: WandererFan Date: Thu, 6 Apr 2017 15:48:24 -0400 Subject: [PATCH] implement detail view highlight in base view --- src/Mod/TechDraw/App/DrawViewDetail.cpp | 6 + src/Mod/TechDraw/App/DrawViewPart.cpp | 13 ++ src/Mod/TechDraw/App/DrawViewPart.h | 2 + src/Mod/TechDraw/Gui/CMakeLists.txt | 2 + src/Mod/TechDraw/Gui/QGIHighlight.cpp | 154 ++++++++++++++++++++++++ src/Mod/TechDraw/Gui/QGIHighlight.h | 83 +++++++++++++ src/Mod/TechDraw/Gui/QGIViewPart.cpp | 36 ++++++ src/Mod/TechDraw/Gui/QGIViewPart.h | 2 + src/Mod/TechDraw/Gui/ZVALUE.h | 1 + 9 files changed, 299 insertions(+) create mode 100644 src/Mod/TechDraw/Gui/QGIHighlight.cpp create mode 100644 src/Mod/TechDraw/Gui/QGIHighlight.h diff --git a/src/Mod/TechDraw/App/DrawViewDetail.cpp b/src/Mod/TechDraw/App/DrawViewDetail.cpp index 6b04ef377a..f712e62a8f 100644 --- a/src/Mod/TechDraw/App/DrawViewDetail.cpp +++ b/src/Mod/TechDraw/App/DrawViewDetail.cpp @@ -134,6 +134,12 @@ void DrawViewDetail::onChanged(const App::Property* prop) std::string(Reference.getValue()); Label.setValue(lblText); } + if ((prop == &Reference) || + (prop == &Radius) || + (prop == &AnchorPoint)) { + BaseView.getValue()->touch(); //hack. sb "update graphics" + } + } DrawView::onChanged(prop); } diff --git a/src/Mod/TechDraw/App/DrawViewPart.cpp b/src/Mod/TechDraw/App/DrawViewPart.cpp index c9588b8490..42f5c47311 100644 --- a/src/Mod/TechDraw/App/DrawViewPart.cpp +++ b/src/Mod/TechDraw/App/DrawViewPart.cpp @@ -91,6 +91,7 @@ #include "DrawHatch.h" #include "DrawGeomHatch.h" #include "DrawViewDimension.h" +#include "DrawViewDetail.h" #include "DrawPage.h" #include "EdgeWalker.h" @@ -623,6 +624,18 @@ std::vector DrawViewPart::getSectionRefs(void) const return result; } +std::vector DrawViewPart::getDetailRefs(void) const +{ + std::vector result; + std::vector inObjs = getInList(); + for (auto& o:inObjs) { + if (o->getTypeId().isDerivedFrom(DrawViewDetail::getClassTypeId())) { + result.push_back(static_cast(o)); + } + } + return result; +} + const std::vector DrawViewPart::getVisibleFaceEdges() const { return geometryObject->getVisibleFaceEdges(SmoothVisible.getValue(),SeamVisible.getValue()); diff --git a/src/Mod/TechDraw/App/DrawViewPart.h b/src/Mod/TechDraw/App/DrawViewPart.h index 07d3b90aeb..279a68fcb1 100644 --- a/src/Mod/TechDraw/App/DrawViewPart.h +++ b/src/Mod/TechDraw/App/DrawViewPart.h @@ -60,6 +60,7 @@ class DrawGeomHatch; class DrawViewDimension; class DrawProjectSplit; class DrawViewSection; +class DrawViewDetail; } namespace TechDraw @@ -120,6 +121,7 @@ public: double getBoxY(void) const; virtual QRectF getRect() const; virtual std::vector getSectionRefs() const; //are there ViewSections based on this ViewPart? + virtual std::vector getDetailRefs() const; const Base::Vector3d& getUDir(void) const {return uDir;} //paperspace X const Base::Vector3d& getVDir(void) const {return vDir;} //paperspace Y const Base::Vector3d& getWDir(void) const {return wDir;} //paperspace Z diff --git a/src/Mod/TechDraw/Gui/CMakeLists.txt b/src/Mod/TechDraw/Gui/CMakeLists.txt index 7ce4ee9cf8..38d2ab2470 100644 --- a/src/Mod/TechDraw/Gui/CMakeLists.txt +++ b/src/Mod/TechDraw/Gui/CMakeLists.txt @@ -173,6 +173,8 @@ SET(TechDrawGuiView_SRCS QGIDecoration.h QGICenterLine.cpp QGICenterLine.h + QGIHighlight.cpp + QGIHighlight.h TemplateTextField.cpp TemplateTextField.h ZVALUE.h diff --git a/src/Mod/TechDraw/Gui/QGIHighlight.cpp b/src/Mod/TechDraw/Gui/QGIHighlight.cpp new file mode 100644 index 0000000000..a132376d25 --- /dev/null +++ b/src/Mod/TechDraw/Gui/QGIHighlight.cpp @@ -0,0 +1,154 @@ +/*************************************************************************** + * 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 +#endif + +#include +#include +#include +#include + +#include +#include "Rez.h" +#include "QGIView.h" +#include "QGIHighlight.h" + +using namespace TechDrawGui; + +QGIHighlight::QGIHighlight() +{ + m_circle = new QGraphicsEllipseItem(); + addToGroup(m_circle); + m_rect = new QGCustomRect(); + addToGroup(m_rect); + m_reference = new QGCustomText(); + addToGroup(m_reference); + + setWidth(Rez::guiX(0.75)); + setStyle(getHighlightStyle()); + setColor(getHighlightColor()); + +} + +void QGIHighlight::draw() +{ + prepareGeometryChange(); + makeHighlight(); + makeReference(); + update(); +} + +void QGIHighlight::makeHighlight() +{ + QRectF r(m_start,m_end); + m_circle->setRect(r); + m_rect->setRect(r); + if (getHoleStyle() == 0) { + m_rect->hide(); + m_circle->show(); + } else { + m_rect->show(); + m_circle->hide(); + } +} + +void QGIHighlight::makeReference() +{ + prepareGeometryChange(); + m_refFont.setPointSize(m_refSize); + m_reference->setFont(m_refFont); + m_reference->setPlainText(QString::fromUtf8(m_refText)); + double fudge = Rez::guiX(1.0); +// m_reference->centerAt(m_end.x() + fudge, m_start.y() - fudge); + m_reference->setPos(m_end.x() + fudge, m_start.y() - m_refSize - fudge); +} + + +void QGIHighlight::setBounds(double x1,double y1,double x2,double y2) +{ + m_start = QPointF(Rez::guiX(x1),Rez::guiX(-y1)); + m_end = QPointF(Rez::guiX(x2),Rez::guiX(-y2)); +} + +void QGIHighlight::setReference(char* ref) +{ + m_refText = ref; +} + +void QGIHighlight::setFont(QFont f, double fsize) +{ + m_refFont = f; + m_refSize = fsize; +} + + +QColor QGIHighlight::getHighlightColor() +{ + Base::Reference hGrp = App::GetApplication().GetUserParameter() + .GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw/Colors"); + App::Color fcColor = App::Color((uint32_t) hGrp->GetUnsigned("SectionColor", 0x08080800)); + return fcColor.asValue(); +} + +Qt::PenStyle QGIHighlight::getHighlightStyle() +{ + Base::Reference hGrp = App::GetApplication().GetUserParameter().GetGroup("BaseApp")-> + GetGroup("Preferences")->GetGroup("Mod/TechDraw"); + Qt::PenStyle sectStyle = static_cast (hGrp->GetInt("SectionLine",2)); + return sectStyle; +} + +int QGIHighlight::getHoleStyle() +{ + Base::Reference hGrp = App::GetApplication().GetUserParameter() + .GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw/Decorations"); + int style = hGrp->GetInt("MattingStyle", 1l); + return style; +} + + +void QGIHighlight::paint ( QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget) { + QStyleOptionGraphicsItem myOption(*option); + myOption.state &= ~QStyle::State_Selected; + + setTools(); + QGIDecoration::paint (painter, &myOption, widget); +} + +void QGIHighlight::setTools() +{ + m_pen.setWidthF(m_width); + m_pen.setColor(m_colCurrent); + m_pen.setStyle(m_styleCurrent); + m_brush.setStyle(m_brushCurrent); + m_brush.setColor(m_colCurrent); + + m_circle->setPen(m_pen); + m_rect->setPen(m_pen); + + m_reference->setDefaultTextColor(m_colCurrent); +} diff --git a/src/Mod/TechDraw/Gui/QGIHighlight.h b/src/Mod/TechDraw/Gui/QGIHighlight.h new file mode 100644 index 0000000000..809f9b3fe3 --- /dev/null +++ b/src/Mod/TechDraw/Gui/QGIHighlight.h @@ -0,0 +1,83 @@ +/*************************************************************************** + * 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 * + * * + ***************************************************************************/ + +#ifndef TECHDRAWGUI_QGIHIGHLIGHT_H +#define TECHDRAWGUI_QGIHIGHLIGHT_H + +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "QGIArrow.h" +#include "QGCustomText.h" +#include "QGCustomRect.h" +#include "QGIDecoration.h" + +namespace TechDrawGui +{ + +class TechDrawGuiExport QGIHighlight : public QGIDecoration +{ +public: + explicit QGIHighlight(); + ~QGIHighlight() {} + + enum {Type = QGraphicsItem::UserType + 172}; + int type() const { return Type;} + + virtual void paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget = 0 ); + + void setBounds(double x1,double y1,double x2,double y2); + void setReference(char* sym); + void setFont(QFont f, double fsize); + virtual void draw(); + +protected: + QColor getHighlightColor(); + Qt::PenStyle getHighlightStyle(); + void makeHighlight(); + void makeReference(); + void setTools(); + int getHoleStyle(void); + + +private: + char* m_refText; + QGraphicsEllipseItem* m_circle; + QGCustomRect* m_rect; + QGCustomText* m_reference; + std::string m_refFontName; + QFont m_refFont; + double m_refSize; + QPointF m_start; + QPointF m_end; +}; + +} + +#endif // TECHDRAWGUI_QGIHIGHLIGHT_H diff --git a/src/Mod/TechDraw/Gui/QGIViewPart.cpp b/src/Mod/TechDraw/Gui/QGIViewPart.cpp index 8dae423e17..c552a9b797 100644 --- a/src/Mod/TechDraw/Gui/QGIViewPart.cpp +++ b/src/Mod/TechDraw/Gui/QGIViewPart.cpp @@ -63,6 +63,7 @@ #include "QGICMark.h" #include "QGISectionLine.h" #include "QGICenterLine.h" +#include "QGIHighlight.h" #include "QGCustomBorder.h" #include "QGCustomLabel.h" #include "QGCustomRect.h" @@ -500,6 +501,13 @@ void QGIViewPart::drawViewPart() drawSectionLine(r, true); } } + + //draw detail highlights + auto drefs = viewPart->getDetailRefs(); + for (auto& r:drefs) { + drawHighlight(r, true); + } + //draw center lines drawCenterLines(true); } @@ -685,6 +693,34 @@ void QGIViewPart::drawCenterLines(bool b) } } +void QGIViewPart::drawHighlight(TechDraw::DrawViewDetail* viewDetail, bool b) +{ + TechDraw::DrawViewPart *viewPart = static_cast(getViewObject()); + if (!viewPart || + !viewDetail) { + return; + } + + if (!viewDetail->hasGeometry()) { + return; + } + + if (b) { + QGIHighlight* highlight = new QGIHighlight(); + addToGroup(highlight); + highlight->setPos(0.0,0.0); //sb setPos(center.x,center.y)? + highlight->setReference(const_cast(viewDetail->Reference.getValue())); + Base::Vector3d center = viewDetail->AnchorPoint.getValue(); + double radius = viewDetail->Radius.getValue(); + highlight->setBounds(center.x - radius, center.y + radius,center.x + radius, center.y - radius); + highlight->setWidth(Rez::guiX(viewPart->LineWidth.getValue())); + highlight->setFont(m_font,Rez::guiX(6.0)); + highlight->setZValue(ZVALUE::HIGHLIGHT); + highlight->draw(); + } +} + + void QGIViewPart::drawMatting() { auto viewPart( dynamic_cast(getViewObject()) ); diff --git a/src/Mod/TechDraw/Gui/QGIViewPart.h b/src/Mod/TechDraw/Gui/QGIViewPart.h index 92f3000c21..682a323426 100644 --- a/src/Mod/TechDraw/Gui/QGIViewPart.h +++ b/src/Mod/TechDraw/Gui/QGIViewPart.h @@ -35,6 +35,7 @@ class DrawViewPart; class DrawViewSection; class DrawHatch; class DrawGeomHatch; +class DrawViewDetail; } namespace TechDrawGui @@ -61,6 +62,7 @@ public: virtual QRectF boundingRect() const override; virtual void drawSectionLine(TechDraw::DrawViewSection* s, bool b); virtual void drawCenterLines(bool b); + virtual void drawHighlight(TechDraw::DrawViewDetail* viewDetail, bool b); virtual void drawMatting(void); bool showSection; diff --git a/src/Mod/TechDraw/Gui/ZVALUE.h b/src/Mod/TechDraw/Gui/ZVALUE.h index ab2b3da4fc..d4d85ab1fd 100644 --- a/src/Mod/TechDraw/Gui/ZVALUE.h +++ b/src/Mod/TechDraw/Gui/ZVALUE.h @@ -14,6 +14,7 @@ namespace ZVALUE { const int SECTIONHATCH = 66; const int DIMENSION = 110; const int SECTIONLINE = 80; //TODO: change to "DECORATION"? section lines, symmetry lines, etc? + const int HIGHLIGHT = 80; const int MATTING = 100; } #endif