FreeCAD

Форк
0
/
QGIEdge.cpp 
141 строка · 4.6 Кб
1
/***************************************************************************
2
 *   Copyright (c) 2013 Luke Parry <l.parry@warwick.ac.uk>                 *
3
 *                                                                         *
4
 *   This file is part of the FreeCAD CAx development system.              *
5
 *                                                                         *
6
 *   This library is free software; you can redistribute it and/or         *
7
 *   modify it under the terms of the GNU Library General Public           *
8
 *   License as published by the Free Software Foundation; either          *
9
 *   version 2 of the License, or (at your option) any later version.      *
10
 *                                                                         *
11
 *   This library  is distributed in the hope that it will be useful,      *
12
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
13
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
14
 *   GNU Library General Public License for more details.                  *
15
 *                                                                         *
16
 *   You should have received a copy of the GNU Library General Public     *
17
 *   License along with this library; see the file COPYING.LIB. If not,    *
18
 *   write to the Free Software Foundation, Inc., 59 Temple Place,         *
19
 *   Suite 330, Boston, MA  02111-1307, USA                                *
20
 *                                                                         *
21
 ***************************************************************************/
22

23
#include "PreCompiled.h"
24

25
#ifndef _PreComp_
26
# include <QPainterPath>
27
# include <QPainterPathStroker>
28
#endif
29

30
#include <App/Application.h>
31
#include <App/Material.h>
32
#include <Base/Console.h>
33
#include <Base/Parameter.h>
34
#include <Gui/Control.h>
35
#include <Mod/TechDraw/App/DrawUtil.h>
36

37
#include "QGIEdge.h"
38
#include "PreferencesGui.h"
39
#include "TaskLineDecor.h"
40
#include "QGIView.h"
41

42
using namespace TechDrawGui;
43
using namespace TechDraw;
44

45
QGIEdge::QGIEdge(int index) :
46
    projIndex(index),
47
    isCosmetic(false),
48
    isHiddenEdge(false),
49
    isSmoothEdge(false)
50
{
51
    setFlag(QGraphicsItem::ItemIsFocusable, true);      // to get key press events
52
    setFlag(QGraphicsItem::ItemIsSelectable, true);
53

54
    m_width = 1.0;
55
    setCosmetic(isCosmetic);
56
    setFill(Qt::NoBrush);
57
}
58

59
// NOTE this refers to Qt cosmetic lines (a line with minimum width),
60
// not FreeCAD cosmetic lines
61
void QGIEdge::setCosmetic(bool state)
62
{
63
//    Base::Console().Message("QGIE::setCosmetic(%d)\n", state);
64
    isCosmetic = state;
65
    if (state) {
66
        setWidth(0.0);
67
    }
68
}
69

70
void QGIEdge::setHiddenEdge(bool b) {
71
    isHiddenEdge = b;
72
    if (b) {
73
        m_styleCurrent = getHiddenStyle();
74
    } else {
75
        m_styleCurrent = Qt::SolidLine;
76
    }
77
}
78

79
void QGIEdge::setPrettyNormal() {
80
//    Base::Console().Message("QGIE::setPrettyNormal()\n");
81
    if (isHiddenEdge) {
82
        m_colCurrent = getHiddenColor();
83
    } else {
84
        m_colCurrent = getNormalColor();
85
    }
86
    //should call QGIPP::setPrettyNormal()?
87
}
88

89
QColor QGIEdge::getHiddenColor()
90
{
91
    App::Color fcColor = App::Color((uint32_t) Preferences::getPreferenceGroup("Colors")->GetUnsigned("HiddenColor", 0x000000FF));
92
    return PreferencesGui::getAccessibleQColor(fcColor.asValue<QColor>());
93
}
94

95
Qt::PenStyle QGIEdge::getHiddenStyle()
96
{
97
    //Qt::PenStyle - NoPen, Solid, Dashed, ...
98
    //Preferences::General - Solid, Dashed
99
    // Dashed lines should use ISO Line #2 instead of Qt::DashedLine
100
    Qt::PenStyle hidStyle = static_cast<Qt::PenStyle> (Preferences::getPreferenceGroup("General")->GetInt("HiddenLine", 0) + 1);
101
    return hidStyle;
102
}
103

104
 double QGIEdge::getEdgeFuzz() const
105
{
106
    return PreferencesGui::edgeFuzz();
107
}
108

109

110
QRectF QGIEdge::boundingRect() const
111
{
112
    return shape().controlPointRect();
113
}
114

115
QPainterPath QGIEdge::shape() const
116
{
117
    QPainterPath outline;
118
    QPainterPathStroker stroker;
119
    stroker.setWidth(getEdgeFuzz());
120
    outline = stroker.createStroke(path());
121
    return outline;
122
}
123

124
void QGIEdge::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
125
{
126
    Q_UNUSED(event)
127
    QGIView *parent = dynamic_cast<QGIView *>(parentItem());
128
    if (parent && parent->getViewObject() && parent->getViewObject()->isDerivedFrom(TechDraw::DrawViewPart::getClassTypeId())) {
129
        TechDraw::DrawViewPart *baseFeat = static_cast<TechDraw::DrawViewPart *>(parent->getViewObject());
130
        std::vector<std::string> edgeName(1, DrawUtil::makeGeomName("Edge", getProjIndex()));
131

132
        Gui::Control().showDialog(new TaskDlgLineDecor(baseFeat, edgeName));
133
    }
134
}
135

136

137

138
void QGIEdge::setLinePen(QPen linePen)
139
{
140
    m_pen = linePen;
141
}
142

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.