1
/***************************************************************************
2
* Copyright (c) Jürgen Riegel (juergen.riegel@web.de) 2002 *
4
* This file is part of the FreeCAD CAx development system. *
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. *
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. *
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 *
21
***************************************************************************/
23
#include "PreCompiled.h"
25
#include <TopoDS_Shape.hxx>
29
#include <Mod/Part/App/PartFeature.h>
31
#include "FeatureViewPart.h"
32
#include "ProjectionAlgos.h"
35
using namespace Drawing;
38
//===========================================================================
40
//===========================================================================
42
App::PropertyFloatConstraint::Constraints FeatureViewPart::floatRange = {0.01, 5.0, 0.05};
44
PROPERTY_SOURCE(Drawing::FeatureViewPart, Drawing::FeatureView)
47
FeatureViewPart::FeatureViewPart(void)
49
static const char* group = "Shape view";
50
static const char* vgroup = "Drawing view";
52
ADD_PROPERTY_TYPE(Direction, (0, 0, 1.0), group, App::Prop_None, "Projection direction");
53
ADD_PROPERTY_TYPE(Source, (nullptr), group, App::Prop_None, "Shape to view");
54
ADD_PROPERTY_TYPE(ShowHiddenLines,
58
"Control the appearance of the dashed hidden lines");
59
ADD_PROPERTY_TYPE(ShowSmoothLines,
63
"Control the appearance of the smooth lines");
64
ADD_PROPERTY_TYPE(LineWidth,
68
"The thickness of the viewed lines");
69
ADD_PROPERTY_TYPE(HiddenWidth,
73
"The thickness of the hidden lines, if enabled");
74
ADD_PROPERTY_TYPE(Tolerance, (0.05), vgroup, App::Prop_None, "The tessellation tolerance");
75
Tolerance.setConstraints(&floatRange);
78
FeatureViewPart::~FeatureViewPart()
81
App::DocumentObjectExecReturn* FeatureViewPart::execute(void)
83
std::stringstream result;
84
std::string ViewName = Label.getValue();
86
App::DocumentObject* link = Source.getValue();
88
return new App::DocumentObjectExecReturn("No object linked");
90
if (!link->isDerivedFrom<Part::Feature>()) {
91
return new App::DocumentObjectExecReturn("Linked object is not a Part object");
93
TopoDS_Shape shape = static_cast<Part::Feature*>(link)->Shape.getShape().getShape();
95
return new App::DocumentObjectExecReturn("Linked shape object is empty");
97
Base::Vector3d Dir = Direction.getValue();
98
bool hidden = ShowHiddenLines.getValue();
99
bool smooth = ShowSmoothLines.getValue();
102
ProjectionAlgos Alg(shape, Dir);
104
<< " id=\"" << ViewName << "\"" << endl
105
<< " transform=\"rotate(" << Rotation.getValue() << "," << X.getValue() << ","
106
<< Y.getValue() << ") translate(" << X.getValue() << "," << Y.getValue()
107
<< ") scale(" << Scale.getValue() << "," << Scale.getValue() << ")\"" << endl
110
ProjectionAlgos::ExtractionType type = ProjectionAlgos::Plain;
112
type = (ProjectionAlgos::ExtractionType)(type | ProjectionAlgos::WithHidden);
115
type = (ProjectionAlgos::ExtractionType)(type | ProjectionAlgos::WithSmooth);
117
ProjectionAlgos::XmlAttributes visible_style = {
118
{"stroke-width", to_string(this->LineWidth.getValue() / this->Scale.getValue())}};
119
ProjectionAlgos::XmlAttributes hidden_style = {
120
{"stroke-width", to_string(this->HiddenWidth.getValue() / this->Scale.getValue())}};
121
result << Alg.getSVG(type,
122
this->Tolerance.getValue(),
130
result << "</g>" << endl;
132
// Apply the resulting fragment
133
ViewResult.setValue(result.str().c_str());
135
return App::DocumentObject::StdReturn;
137
catch (Standard_Failure& e) {
138
return new App::DocumentObjectExecReturn(e.GetMessageString());
143
// Python Drawing feature ---------------------------------------------------------
148
PROPERTY_SOURCE_TEMPLATE(Drawing::FeatureViewPartPython, Drawing::FeatureViewPart)
150
const char* Drawing::FeatureViewPartPython::getViewProviderName(void) const
152
return "DrawingGui::ViewProviderDrawingView";
156
// explicit template instantiation
157
template class DrawingExport FeaturePythonT<Drawing::FeatureViewPart>;