FeaturePartCommon.cpp

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

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