FreeCAD

Форк
0
/
FeatureClip.cpp 
131 строка · 5.4 Кб
1
/***************************************************************************
2
 *   Copyright (c) Yorik van Havre <yorik@uncreated.net> 2012              *
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 <iostream>
26
#include <sstream>
27
#endif
28

29
#include "FeatureClip.h"
30
#include "FeatureView.h"
31

32

33
using namespace Drawing;
34
using namespace std;
35

36
//===========================================================================
37
// FeaturePage
38
//===========================================================================
39

40
PROPERTY_SOURCE(Drawing::FeatureClip, App::DocumentObjectGroup)
41

42
FeatureClip::FeatureClip(void)
43
{
44
    static const char* group = "Drawing view";
45
    App::PropertyType hidden = (App::PropertyType)(App::Prop_Hidden);
46
    ADD_PROPERTY_TYPE(ViewResult, (""), group, hidden, "Resulting SVG view of this clip");
47
    ADD_PROPERTY_TYPE(X,
48
                      (10),
49
                      group,
50
                      App::Prop_None,
51
                      "The left margin of the view area of this clip");
52
    ADD_PROPERTY_TYPE(Y,
53
                      (10),
54
                      group,
55
                      App::Prop_None,
56
                      "The top margin of the view area of this clip");
57
    ADD_PROPERTY_TYPE(Height,
58
                      (10),
59
                      group,
60
                      App::Prop_None,
61
                      "The height of the view area of this clip");
62
    ADD_PROPERTY_TYPE(Width,
63
                      (10),
64
                      group,
65
                      App::Prop_None,
66
                      "The width of the view area of this clip");
67
    ADD_PROPERTY_TYPE(ShowFrame,
68
                      (0),
69
                      group,
70
                      App::Prop_None,
71
                      "Specifies if the clip frame appears on the page or not");
72
    // The 'Visible' property is handled by the view provider exclusively. It has the 'Output' flag
73
    // set to avoid to call the execute() method. The view provider touches the page object,
74
    // instead.
75
    App::PropertyType propType =
76
        static_cast<App::PropertyType>(App::Prop_Hidden | App::Prop_Output);
77
    ADD_PROPERTY_TYPE(Visible,
78
                      (true),
79
                      group,
80
                      propType,
81
                      "Control whether frame is visible in page object");
82
}
83

84
FeatureClip::~FeatureClip()
85
{}
86

87
/// get called by the container when a Property was changed
88
void FeatureClip::onChanged(const App::Property* prop)
89
{
90
    App::DocumentObjectGroup::onChanged(prop);
91
}
92

93
App::DocumentObjectExecReturn* FeatureClip::execute(void)
94
{
95
    ostringstream svg;
96

97
    // creating clip path
98
    svg << "<clipPath id=\"" << Label.getValue() << "\">"
99
        << "<rect x=\"" << X.getValue() << "\""
100
        << " y=\"" << Y.getValue() << "\""
101
        << " width=\"" << Width.getValue() << "\""
102
        << " height=\"" << Height.getValue() << "\"/></clipPath>" << endl;
103

104
    // show clip frame on the page if needed
105

106
    if (ShowFrame.getValue()) {
107
        svg << "<rect fill=\"None\" stroke=\"#ff0000\" stroke-width=\"1px\""
108
            << " x=\"" << X.getValue() << "\""
109
            << " y=\"" << Y.getValue() << "\""
110
            << " width=\"" << Width.getValue() << "\""
111
            << " height=\"" << Height.getValue() << "\"/>" << endl;
112
    }
113

114
    // create clipped group
115
    svg << "<g clip-path=\"url(#" << Label.getValue() << ")\">" << endl;
116

117
    // get through the children and collect all the views
118
    const vector<App::DocumentObject*>& Grp = Group.getValues();
119
    for (vector<App::DocumentObject*>::const_iterator It = Grp.begin(); It != Grp.end(); ++It) {
120
        if ((*It)->isDerivedFrom<Drawing::FeatureView>()) {
121
            Drawing::FeatureView* View = static_cast<Drawing::FeatureView*>(*It);
122
            svg << View->ViewResult.getValue() << endl;
123
        }
124
    }
125

126
    // closing clipped group
127
    svg << "</g>" << endl;
128

129
    ViewResult.setValue(svg.str().c_str());
130
    return App::DocumentObject::StdReturn;
131
}
132

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

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

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

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