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 <BRepAlgoAPI_Fuse.hxx> 00027 #endif 00028 00029 00030 #include "FeaturePartFuse.h" 00031 00032 #include <Base/Exception.h> 00033 00034 using namespace Part; 00035 00036 PROPERTY_SOURCE(Part::Fuse, Part::Boolean) 00037 00038 00039 Fuse::Fuse(void) 00040 { 00041 } 00042 00043 TopoDS_Shape Fuse::runOperation(const TopoDS_Shape& base, const TopoDS_Shape& tool) const 00044 { 00045 // Let's call algorithm computing a fuse operation: 00046 BRepAlgoAPI_Fuse mkFuse(base, tool); 00047 // Let's check if the fusion has been successful 00048 if (!mkFuse.IsDone()) 00049 throw Base::Exception("Fusion failed"); 00050 return mkFuse.Shape(); 00051 } 00052 00053 // ---------------------------------------------------- 00054 00055 PROPERTY_SOURCE(Part::MultiFuse, Part::Feature) 00056 00057 00058 MultiFuse::MultiFuse(void) 00059 { 00060 ADD_PROPERTY(Shapes,(0)); 00061 Shapes.setSize(0); 00062 } 00063 00064 short MultiFuse::mustExecute() const 00065 { 00066 if (Shapes.isTouched()) 00067 return 1; 00068 return 0; 00069 } 00070 00071 App::DocumentObjectExecReturn *MultiFuse::execute(void) 00072 { 00073 std::vector<TopoDS_Shape> s; 00074 std::vector<App::DocumentObject*> obj = Shapes.getValues(); 00075 00076 std::vector<App::DocumentObject*>::iterator it; 00077 for (it = obj.begin(); it != obj.end(); ++it) { 00078 if ((*it)->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId())) { 00079 s.push_back(static_cast<Part::Feature*>(*it)->Shape.getValue()); 00080 } 00081 } 00082 00083 if (s.size() >= 2) { 00084 TopoDS_Shape res = s.front(); 00085 for (std::vector<TopoDS_Shape>::iterator it = s.begin()+1; it != s.end(); ++it) { 00086 // Let's call algorithm computing a fuse operation: 00087 BRepAlgoAPI_Fuse mkFuse(res, *it); 00088 // Let's check if the fusion has been successful 00089 if (!mkFuse.IsDone()) 00090 throw Base::Exception("Fusion failed"); 00091 res = mkFuse.Shape(); 00092 } 00093 if (res.IsNull()) 00094 throw Base::Exception("Resulting shape is invalid"); 00095 this->Shape.setValue(res); 00096 } 00097 else { 00098 throw Base::Exception("Not enough shape objects linked"); 00099 } 00100 00101 return App::DocumentObject::StdReturn; 00102 }