FreeCAD

Форк
0
/
FeatureViewPart.cpp 
158 строк · 6.5 Кб
1
/***************************************************************************
2
 *   Copyright (c) Jürgen Riegel          (juergen.riegel@web.de) 2002     *
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
#ifndef _PreComp_
25
#include <TopoDS_Shape.hxx>
26
#include <sstream>
27
#endif
28

29
#include <Mod/Part/App/PartFeature.h>
30

31
#include "FeatureViewPart.h"
32
#include "ProjectionAlgos.h"
33

34

35
using namespace Drawing;
36
using namespace std;
37

38
//===========================================================================
39
// FeatureViewPart
40
//===========================================================================
41

42
App::PropertyFloatConstraint::Constraints FeatureViewPart::floatRange = {0.01, 5.0, 0.05};
43

44
PROPERTY_SOURCE(Drawing::FeatureViewPart, Drawing::FeatureView)
45

46

47
FeatureViewPart::FeatureViewPart(void)
48
{
49
    static const char* group = "Shape view";
50
    static const char* vgroup = "Drawing view";
51

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,
55
                      (false),
56
                      group,
57
                      App::Prop_None,
58
                      "Control the appearance of the dashed hidden lines");
59
    ADD_PROPERTY_TYPE(ShowSmoothLines,
60
                      (false),
61
                      group,
62
                      App::Prop_None,
63
                      "Control the appearance of the smooth lines");
64
    ADD_PROPERTY_TYPE(LineWidth,
65
                      (0.35),
66
                      vgroup,
67
                      App::Prop_None,
68
                      "The thickness of the viewed lines");
69
    ADD_PROPERTY_TYPE(HiddenWidth,
70
                      (0.15),
71
                      vgroup,
72
                      App::Prop_None,
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);
76
}
77

78
FeatureViewPart::~FeatureViewPart()
79
{}
80

81
App::DocumentObjectExecReturn* FeatureViewPart::execute(void)
82
{
83
    std::stringstream result;
84
    std::string ViewName = Label.getValue();
85

86
    App::DocumentObject* link = Source.getValue();
87
    if (!link) {
88
        return new App::DocumentObjectExecReturn("No object linked");
89
    }
90
    if (!link->isDerivedFrom<Part::Feature>()) {
91
        return new App::DocumentObjectExecReturn("Linked object is not a Part object");
92
    }
93
    TopoDS_Shape shape = static_cast<Part::Feature*>(link)->Shape.getShape().getShape();
94
    if (shape.IsNull()) {
95
        return new App::DocumentObjectExecReturn("Linked shape object is empty");
96
    }
97
    Base::Vector3d Dir = Direction.getValue();
98
    bool hidden = ShowHiddenLines.getValue();
99
    bool smooth = ShowSmoothLines.getValue();
100

101
    try {
102
        ProjectionAlgos Alg(shape, Dir);
103
        result << "<g"
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
108
               << "  >" << endl;
109

110
        ProjectionAlgos::ExtractionType type = ProjectionAlgos::Plain;
111
        if (hidden) {
112
            type = (ProjectionAlgos::ExtractionType)(type | ProjectionAlgos::WithHidden);
113
        }
114
        if (smooth) {
115
            type = (ProjectionAlgos::ExtractionType)(type | ProjectionAlgos::WithSmooth);
116
        }
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(),
123
                             visible_style,
124
                             visible_style,
125
                             visible_style,
126
                             hidden_style,
127
                             hidden_style,
128
                             hidden_style);
129

130
        result << "</g>" << endl;
131

132
        // Apply the resulting fragment
133
        ViewResult.setValue(result.str().c_str());
134

135
        return App::DocumentObject::StdReturn;
136
    }
137
    catch (Standard_Failure& e) {
138
        return new App::DocumentObjectExecReturn(e.GetMessageString());
139
    }
140
}
141

142

143
// Python Drawing feature ---------------------------------------------------------
144

145
namespace App
146
{
147
/// @cond DOXERR
148
PROPERTY_SOURCE_TEMPLATE(Drawing::FeatureViewPartPython, Drawing::FeatureViewPart)
149
template<>
150
const char* Drawing::FeatureViewPartPython::getViewProviderName(void) const
151
{
152
    return "DrawingGui::ViewProviderDrawingView";
153
}
154
/// @endcond
155

156
// explicit template instantiation
157
template class DrawingExport FeaturePythonT<Drawing::FeatureViewPart>;
158
}  // namespace App
159

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

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

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

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