FreeCAD
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#endif28
29#include "FeatureClip.h"30#include "FeatureView.h"31
32
33using namespace Drawing;34using namespace std;35
36//===========================================================================
37// FeaturePage
38//===========================================================================
39
40PROPERTY_SOURCE(Drawing::FeatureClip, App::DocumentObjectGroup)41
42FeatureClip::FeatureClip(void)43{
44static const char* group = "Drawing view";45App::PropertyType hidden = (App::PropertyType)(App::Prop_Hidden);46ADD_PROPERTY_TYPE(ViewResult, (""), group, hidden, "Resulting SVG view of this clip");47ADD_PROPERTY_TYPE(X,48(10),49group,50App::Prop_None,51"The left margin of the view area of this clip");52ADD_PROPERTY_TYPE(Y,53(10),54group,55App::Prop_None,56"The top margin of the view area of this clip");57ADD_PROPERTY_TYPE(Height,58(10),59group,60App::Prop_None,61"The height of the view area of this clip");62ADD_PROPERTY_TYPE(Width,63(10),64group,65App::Prop_None,66"The width of the view area of this clip");67ADD_PROPERTY_TYPE(ShowFrame,68(0),69group,70App::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' flag73// set to avoid to call the execute() method. The view provider touches the page object,74// instead.75App::PropertyType propType =76static_cast<App::PropertyType>(App::Prop_Hidden | App::Prop_Output);77ADD_PROPERTY_TYPE(Visible,78(true),79group,80propType,81"Control whether frame is visible in page object");82}
83
84FeatureClip::~FeatureClip()85{}86
87/// get called by the container when a Property was changed
88void FeatureClip::onChanged(const App::Property* prop)89{
90App::DocumentObjectGroup::onChanged(prop);91}
92
93App::DocumentObjectExecReturn* FeatureClip::execute(void)94{
95ostringstream svg;96
97// creating clip path98svg << "<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 needed105
106if (ShowFrame.getValue()) {107svg << "<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 group115svg << "<g clip-path=\"url(#" << Label.getValue() << ")\">" << endl;116
117// get through the children and collect all the views118const vector<App::DocumentObject*>& Grp = Group.getValues();119for (vector<App::DocumentObject*>::const_iterator It = Grp.begin(); It != Grp.end(); ++It) {120if ((*It)->isDerivedFrom<Drawing::FeatureView>()) {121Drawing::FeatureView* View = static_cast<Drawing::FeatureView*>(*It);122svg << View->ViewResult.getValue() << endl;123}124}125
126// closing clipped group127svg << "</g>" << endl;128
129ViewResult.setValue(svg.str().c_str());130return App::DocumentObject::StdReturn;131}
132