00001 /*************************************************************************** 00002 * Copyright (c) 2007 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 <BRepBuilderAPI_MakeEdge.hxx> 00027 # include <gp_Circ.hxx> 00028 # include <TopoDS.hxx> 00029 # include <TopoDS_Edge.hxx> 00030 #endif 00031 00032 #include "FeaturePartCircle.h" 00033 #include <Base/Tools.h> 00034 00035 using namespace Part; 00036 00037 App::PropertyFloatConstraint::Constraints Circle::angleRange = {0.0,360.0,1.0}; 00038 00039 PROPERTY_SOURCE(Part::Circle, Part::Primitive) 00040 00041 00042 Circle::Circle() 00043 { 00044 ADD_PROPERTY(Radius,(2.0f)); 00045 ADD_PROPERTY(Angle0,(0.0f)); 00046 Angle0.setConstraints(&angleRange); 00047 ADD_PROPERTY(Angle1,(360.0f)); 00048 Angle1.setConstraints(&angleRange); 00049 } 00050 00051 Circle::~Circle() 00052 { 00053 } 00054 00055 short Circle::mustExecute() const 00056 { 00057 if (Angle0.isTouched() || 00058 Angle1.isTouched() || 00059 Radius.isTouched()) 00060 return 1; 00061 return Part::Feature::mustExecute(); 00062 } 00063 00064 App::DocumentObjectExecReturn *Circle::execute(void) 00065 { 00066 gp_Circ circle; 00067 circle.SetRadius(this->Radius.getValue()); 00068 00069 BRepBuilderAPI_MakeEdge clMakeEdge(circle, Base::toRadians<double>(this->Angle0.getValue()), 00070 Base::toRadians<double>(this->Angle1.getValue())); 00071 const TopoDS_Edge& edge = clMakeEdge.Edge(); 00072 this->Shape.setValue(edge); 00073 00074 return App::DocumentObject::StdReturn; 00075 } 00076 00077 void Circle::onChanged(const App::Property* prop) 00078 { 00079 if (!isRestoring()) { 00080 if (prop == &Radius || prop == &Angle0 || prop == &Angle1){ 00081 try { 00082 App::DocumentObjectExecReturn *ret = recompute(); 00083 delete ret; 00084 } 00085 catch (...) { 00086 } 00087 } 00088 } 00089 Part::Feature::onChanged(prop); 00090 }