FreeCAD

Форк
0
/
ViewProviderHatch.cpp 
145 строк · 5.3 Кб
1
/***************************************************************************
2
 *   Copyright (c) 2004 Jürgen Riegel <juergen.riegel@web.de>              *
3
 *   Copyright (c) 2015 WandererFan <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

25
#include "PreCompiled.h"
26

27
#ifndef _PreComp_
28
#include <Precision.hxx>
29
#endif
30

31
#include <App/DocumentObject.h>
32
#include <Base/UnitsApi.h>
33
#include <Gui/Application.h>
34
#include <Gui/Control.h>
35

36
#include <Mod/TechDraw/App/DrawHatch.h>
37
#include <Mod/TechDraw/App/DrawViewPart.h>
38

39
#include "TaskHatch.h"
40
#include "ViewProviderHatch.h"
41

42
using namespace TechDrawGui;
43

44
//scaleRange = {lowerLimit, upperLimit, stepSize}
45
//original range is far too broad for drawing.  causes massive loop counts.
46
//App::PropertyFloatConstraint::Constraints ViewProviderHatch::scaleRange = {Precision::Confusion(),
47
//                                                                  std::numeric_limits<double>::max(),
48
//                                                                  pow(10, - Base::UnitsApi::getDecimals())};
49
App::PropertyFloatConstraint::Constraints ViewProviderHatch::scaleRange = {pow(10, - Base::UnitsApi::getDecimals()),
50
                                                                  1000.0,
51
                                                                  0.1};
52

53

54
PROPERTY_SOURCE(TechDrawGui::ViewProviderHatch, Gui::ViewProviderDocumentObject)
55

56
//**************************************************************************
57
// Construction/Destruction
58

59
ViewProviderHatch::ViewProviderHatch()
60
{
61
    sPixmap = "TechDraw_TreeHatch";
62

63
    static const char *vgroup = "Hatch";
64
    ADD_PROPERTY_TYPE(HatchColor, (TechDraw::DrawHatch::prefSvgHatchColor()),
65
                        vgroup, App::Prop_None, "The color of the hatch pattern");
66
    ADD_PROPERTY_TYPE(HatchScale, (1.0), vgroup, App::Prop_None, "Hatch pattern size adjustment");
67
    HatchScale.setConstraints(&scaleRange);
68
    ADD_PROPERTY_TYPE(HatchRotation, (0.0), vgroup, App::Prop_None, "Hatch pattern rotation");
69
    ADD_PROPERTY_TYPE(HatchOffset, (0.0, 0.0, 0.0), vgroup, App::Prop_None, "Hatch pattern offset");
70
}
71

72
ViewProviderHatch::~ViewProviderHatch()
73
{
74
}
75

76
bool ViewProviderHatch::setEdit(int ModNum)
77
{
78
    if (ModNum != ViewProvider::Default) {
79
        return Gui::ViewProviderDocumentObject::setEdit(ModNum);
80
    }
81
    if (Gui::Control().activeDialog()) {
82
        return false; //TaskPanel already open!
83
    }
84

85
    // clear the selection (convenience)
86
    Gui::Selection().clearSelection();
87
    Gui::Control().showDialog(new TaskDlgHatch(this));
88
    return true;
89
}
90

91
bool ViewProviderHatch::doubleClicked()
92
{
93
    setEdit(0);
94
    return true;
95
}
96

97
void ViewProviderHatch::onChanged(const App::Property* prop)
98
{
99
    if (prop == &HatchScale ||
100
        prop == &HatchColor ||
101
        prop == &HatchRotation ||
102
        prop == &HatchOffset)  {
103
        if (HatchScale.getValue() > 0.0) {
104
            TechDraw::DrawViewPart* parent = getViewObject()->getSourceView();
105
            if (parent) {
106
                parent->requestPaint();
107
            }
108
        }
109
    }
110
}
111

112
void ViewProviderHatch::updateData(const App::Property* prop)
113
{
114
    if (prop == &(getViewObject()->HatchPattern)) {
115
        TechDraw::DrawViewPart* parent = getViewObject()->getSourceView();
116
        if (parent) {
117
            parent->requestPaint();
118
        }
119
    }
120
    Gui::ViewProviderDocumentObject::updateData(prop);
121
}
122

123
TechDraw::DrawHatch* ViewProviderHatch::getViewObject() const
124
{
125
    return dynamic_cast<TechDraw::DrawHatch*>(pcObject);
126
}
127

128
bool ViewProviderHatch::canDelete(App::DocumentObject *obj) const
129
{
130
    // deletion of hatches don't destroy anything
131
    // thus we can pass this action
132
    Q_UNUSED(obj)
133
    return true;
134
}
135

136
Gui::MDIView *ViewProviderHatch::getMDIView() const
137
{
138
    auto obj = getViewObject();
139
    if(!obj)
140
        return nullptr;
141
    auto vp = Gui::Application::Instance->getViewProvider(obj->getSourceView());
142
    if(!vp)
143
        return nullptr;
144
    return vp->getMDIView();
145
}
146

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

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

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

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