FreeCAD

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

24
#include "PreCompiled.h"
25

26
#include <App/DocumentObject.h>
27
#include <Gui/Control.h>
28
#include <Gui/Selection.h>
29

30
#include <Mod/TechDraw/App/DrawRichAnno.h>
31
#include <Mod/TechDraw/App/LineGroup.h>
32

33
#include "PreferencesGui.h"
34
#include "ZVALUE.h"
35
#include "QGIView.h"
36
#include "TaskRichAnno.h"
37
#include "QGSPage.h"
38
#include "ViewProviderPage.h"
39
#include "ViewProviderRichAnno.h"
40

41
using namespace TechDrawGui;
42
using namespace TechDraw;
43

44
PROPERTY_SOURCE(TechDrawGui::ViewProviderRichAnno, TechDrawGui::ViewProviderDrawingView)
45

46
const char* ViewProviderRichAnno::LineStyleEnums[] = { "NoLine",
47
                                                  "Continuous",
48
                                                  "Dash",
49
                                                  "Dot",
50
                                                  "DashDot",
51
                                                  "DashDotDot",
52
                                                  nullptr };
53

54
//**************************************************************************
55
// Construction/Destruction
56

57
ViewProviderRichAnno::ViewProviderRichAnno()
58
{
59
    sPixmap = "actions/TechDraw_RichTextAnnotation";
60

61
    static const char *group = "Frame Format";
62

63
    ADD_PROPERTY_TYPE(LineWidth, (getDefLineWeight()), group, (App::PropertyType)(App::Prop_None), "Frame line width");
64
    LineStyle.setEnums(LineStyleEnums);
65
    ADD_PROPERTY_TYPE(LineStyle, (1), group, (App::PropertyType)(App::Prop_None), "Frame line style");
66
    ADD_PROPERTY_TYPE(LineColor, (getDefLineColor()), group, App::Prop_None, "The color of the frame");
67

68
    StackOrder.setValue(ZVALUE::DIMENSION);
69
}
70

71
ViewProviderRichAnno::~ViewProviderRichAnno()
72
{
73
}
74

75
bool ViewProviderRichAnno::doubleClicked()
76
{
77
//    Base::Console().Message("VPRA::doubleClicked()\n");
78
    setEdit(ViewProvider::Default);
79
    return true;
80
}
81

82
void ViewProviderRichAnno::updateData(const App::Property* p)
83
{
84
    // only if there is a frame we can enable the frame line parameters
85
    if (getViewObject()) {
86
        if (getViewObject()->ShowFrame.getValue()) {
87
            LineWidth.setStatus(App::Property::ReadOnly, false);
88
            LineStyle.setStatus(App::Property::ReadOnly, false);
89
            LineColor.setStatus(App::Property::ReadOnly, false);
90
        }
91
        else {
92
            LineWidth.setStatus(App::Property::ReadOnly, true);
93
            LineStyle.setStatus(App::Property::ReadOnly, true);
94
            LineColor.setStatus(App::Property::ReadOnly, true);
95
        }
96
    }
97

98
    ViewProviderDrawingView::updateData(p);
99
}
100

101
void ViewProviderRichAnno::onChanged(const App::Property* p)
102
{
103
    if ((p == &LineColor) ||
104
        (p == &LineWidth) ||
105
        (p == &LineStyle)) {
106
        QGIView* qgiv = getQView();
107
        if (qgiv) {
108
            qgiv->updateView(true);
109
        }
110
    }
111

112
    ViewProviderDrawingView::onChanged(p);
113
}
114

115
TechDraw::DrawRichAnno* ViewProviderRichAnno::getViewObject() const
116
{
117
    return dynamic_cast<TechDraw::DrawRichAnno*>(pcObject);
118
}
119

120
TechDraw::DrawRichAnno* ViewProviderRichAnno::getFeature() const
121
{
122
    return dynamic_cast<TechDraw::DrawRichAnno*>(pcObject);
123
}
124

125
App::Color ViewProviderRichAnno::getDefLineColor()
126
{
127
    return PreferencesGui::leaderColor();
128
}
129

130
std::string ViewProviderRichAnno::getDefFont()
131
{
132
    return Preferences::labelFont();
133
}
134

135
double ViewProviderRichAnno::getDefFontSize()
136
{
137
    return Preferences::dimFontSizeMM();
138
}
139

140
double ViewProviderRichAnno::getDefLineWeight()
141
{
142
    return TechDraw::LineGroup::getDefaultWidth("Graphics");
143
}
144

145
void ViewProviderRichAnno::handleChangedPropertyType(Base::XMLReader &reader, const char *TypeName, App::Property *prop)
146
// transforms properties that had been changed
147
{
148
    // property LineWidth had App::PropertyFloat and was changed to App::PropertyLength
149
    if (prop == &LineWidth && strcmp(TypeName, "App::PropertyFloat") == 0) {
150
        App::PropertyFloat LineWidthProperty;
151
        // restore the PropertyFloat to be able to set its value
152
        LineWidthProperty.Restore(reader);
153
        LineWidth.setValue(LineWidthProperty.getValue());
154
    }
155

156
    // property LineStyle had App::PropertyInteger and was changed to App::PropertyIntegerConstraint
157
    else if (prop == &LineStyle && strcmp(TypeName, "App::PropertyInteger") == 0) {
158
        App::PropertyInteger LineStyleProperty;
159
        // restore the PropertyInteger to be able to set its value
160
        LineStyleProperty.Restore(reader);
161
        LineStyle.setValue(LineStyleProperty.getValue());
162
    }
163

164
    // property LineStyle had App::PropertyIntegerConstraint and was changed to App::PropertyEnumeration
165
    else if (prop == &LineStyle && strcmp(TypeName, "App::PropertyIntegerConstraint") == 0) {
166
        App::PropertyIntegerConstraint LineStyleProperty;
167
        // restore the PropertyIntegerConstraint to be able to set its value
168
        LineStyleProperty.Restore(reader);
169
        LineStyle.setValue(LineStyleProperty.getValue());
170
    }
171

172
    else {
173
        ViewProviderDrawingView::handleChangedPropertyType(reader, TypeName, prop);
174
    }
175
}
176

177
bool ViewProviderRichAnno::canDelete(App::DocumentObject *obj) const
178
{
179
    // deletions of RichAnno objects don't destroy anything
180
    // thus we can pass this action
181
    // only for information: RichAnnos that have a parent
182
    // view will get the page as new parent if the view is deleted
183
    Q_UNUSED(obj)
184
    return true;
185
}
186

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

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

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

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