1
/***************************************************************************
2
* Copyright (c) 2004 Jürgen Riegel <juergen.riegel@web.de> *
3
* Copyright (c) 2015 WandererFan <wandererfan@gmail.com> *
5
* This file is part of the FreeCAD CAx development system. *
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. *
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. *
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 *
22
***************************************************************************/
25
#include "PreCompiled.h"
28
#include <Precision.hxx>
31
#include <App/DocumentObject.h>
32
#include <Base/UnitsApi.h>
33
#include <Gui/Application.h>
34
#include <Gui/Control.h>
36
#include <Mod/TechDraw/App/DrawHatch.h>
37
#include <Mod/TechDraw/App/DrawViewPart.h>
40
#include "ViewProviderHatch.h"
42
using namespace TechDrawGui;
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()),
54
PROPERTY_SOURCE(TechDrawGui::ViewProviderHatch, Gui::ViewProviderDocumentObject)
56
//**************************************************************************
57
// Construction/Destruction
59
ViewProviderHatch::ViewProviderHatch()
61
sPixmap = "TechDraw_TreeHatch";
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");
72
ViewProviderHatch::~ViewProviderHatch()
76
bool ViewProviderHatch::setEdit(int ModNum)
78
if (ModNum != ViewProvider::Default) {
79
return Gui::ViewProviderDocumentObject::setEdit(ModNum);
81
if (Gui::Control().activeDialog()) {
82
return false; //TaskPanel already open!
85
// clear the selection (convenience)
86
Gui::Selection().clearSelection();
87
Gui::Control().showDialog(new TaskDlgHatch(this));
91
bool ViewProviderHatch::doubleClicked()
97
void ViewProviderHatch::onChanged(const App::Property* prop)
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();
106
parent->requestPaint();
112
void ViewProviderHatch::updateData(const App::Property* prop)
114
if (prop == &(getViewObject()->HatchPattern)) {
115
TechDraw::DrawViewPart* parent = getViewObject()->getSourceView();
117
parent->requestPaint();
120
Gui::ViewProviderDocumentObject::updateData(prop);
123
TechDraw::DrawHatch* ViewProviderHatch::getViewObject() const
125
return dynamic_cast<TechDraw::DrawHatch*>(pcObject);
128
bool ViewProviderHatch::canDelete(App::DocumentObject *obj) const
130
// deletion of hatches don't destroy anything
131
// thus we can pass this action
136
Gui::MDIView *ViewProviderHatch::getMDIView() const
138
auto obj = getViewObject();
141
auto vp = Gui::Application::Instance->getViewProvider(obj->getSourceView());
144
return vp->getMDIView();