FeaturePartPolygon.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (c) 2006 Werner Mayer <wmayer[at]users.sourceforge.net>     *
00003  *                                                                         *
00004  *   This file is part of the FreeCAD CAx development system.              *
00005  *                                                                         *
00006  *   This library is free software; you can redistribute it and/or         *
00007  *   modify it under the terms of the GNU Library General Public           *
00008  *   License as published by the Free Software Foundation; either          *
00009  *   version 2 of the License, or (at your option) any later version.      *
00010  *                                                                         *
00011  *   This library  is distributed in the hope that it will be useful,      *
00012  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00013  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00014  *   GNU Library General Public License for more details.                  *
00015  *                                                                         *
00016  *   You should have received a copy of the GNU Library General Public     *
00017  *   License along with this library; see the file COPYING.LIB. If not,    *
00018  *   write to the Free Software Foundation, Inc., 59 Temple Place,         *
00019  *   Suite 330, Boston, MA  02111-1307, USA                                *
00020  *                                                                         *
00021  ***************************************************************************/
00022 
00023 
00024 #include "PreCompiled.h"
00025 #ifndef _PreComp_
00026 # include <BRep_Builder.hxx>
00027 # include <BRepBuilderAPI_MakePolygon.hxx>
00028 # include <gp_Pnt.hxx>
00029 # include <TopoDS_Wire.hxx>
00030 #endif
00031 
00032 #include "FeaturePartPolygon.h"
00033 #include <Base/Exception.h>
00034 
00035 PROPERTY_SOURCE(Part::Polygon, Part::Feature)
00036 
00037 
00038 Part::Polygon::Polygon()
00039 {
00040     ADD_PROPERTY(Nodes,(Base::Vector3f()));
00041     ADD_PROPERTY(Close,(false));
00042 }
00043 
00044 Part::Polygon::~Polygon()
00045 {
00046 }
00047 
00048 short Part::Polygon::mustExecute() const
00049 {
00050     if (Nodes.isTouched() || Close.isTouched())
00051         return 1;
00052     return 0;
00053 }
00054 
00055 App::DocumentObjectExecReturn *Part::Polygon::execute(void)
00056 {
00057     BRepBuilderAPI_MakePolygon poly;
00058     const std::vector<Base::Vector3f> nodes = Nodes.getValues();
00059 
00060     for (std::vector<Base::Vector3f>::const_iterator it = nodes.begin(); it != nodes.end(); ++it) {
00061         gp_Pnt pnt(it->x, it->y, it->z);
00062         poly.Add(pnt);
00063     }
00064 
00065     if (Close.getValue())
00066         poly.Close();
00067 
00068     if (!poly.IsDone())
00069         throw Base::Exception("Cannot create polygon because less than two vetices are given");
00070     TopoDS_Wire wire = poly.Wire();
00071     this->Shape.setValue(wire);
00072 
00073     return App::DocumentObject::StdReturn;
00074 }

Generated on Wed Nov 23 19:00:12 2011 for FreeCAD by  doxygen 1.6.1