~ubuntu-branches/ubuntu/maverick/freecad/maverick

« back to all changes in this revision

Viewing changes to src/Mod/Part/App/FeaturePartPolygon.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Teemu Ikonen
  • Date: 2009-07-16 18:37:41 UTC
  • Revision ID: james.westby@ubuntu.com-20090716183741-oww9kcxqrk991i1n
Tags: upstream-0.8.2237
ImportĀ upstreamĀ versionĀ 0.8.2237

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
 *   Copyright (c) 2006 Werner Mayer <werner.wm.mayer@gmx.de>              *
 
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
 
 
24
#include "PreCompiled.h"
 
25
#ifndef _PreComp_
 
26
# include <BRep_Builder.hxx>
 
27
# include <BRepBuilderAPI_MakePolygon.hxx>
 
28
# include <gp_Pnt.hxx>
 
29
# include <TopoDS_Wire.hxx>
 
30
#endif
 
31
 
 
32
#include "FeaturePartPolygon.h"
 
33
#include <Base/Exception.h>
 
34
 
 
35
using namespace Part;
 
36
 
 
37
PROPERTY_SOURCE(Part::Polygon, Part::Feature)
 
38
 
 
39
 
 
40
Polygon::Polygon()
 
41
{
 
42
    ADD_PROPERTY(Nodes,(Base::Vector3f()));
 
43
    ADD_PROPERTY(Close,(false));
 
44
}
 
45
 
 
46
Polygon::~Polygon()
 
47
{
 
48
}
 
49
 
 
50
short Polygon::mustExecute() const
 
51
{
 
52
    if (Nodes.isTouched() || Close.isTouched())
 
53
        return 1;
 
54
    return 0;
 
55
}
 
56
 
 
57
App::DocumentObjectExecReturn *Polygon::execute(void)
 
58
{
 
59
    BRepBuilderAPI_MakePolygon poly;
 
60
    const std::vector<Base::Vector3f> nodes = Nodes.getValues();
 
61
 
 
62
    for (std::vector<Base::Vector3f>::const_iterator it = nodes.begin(); it != nodes.end(); ++it) {
 
63
        gp_Pnt pnt(it->x, it->y, it->z);
 
64
        poly.Add(pnt);
 
65
    }
 
66
 
 
67
    if (Close.getValue())
 
68
        poly.Close();
 
69
 
 
70
    if (!poly.IsDone())
 
71
        throw Base::Exception("Cannot create polygon because less than two vetices are given");
 
72
    TopoDS_Wire wire = poly.Wire();
 
73
    this->Shape.setValue(wire);
 
74
 
 
75
    return App::DocumentObject::StdReturn;
 
76
}