00001 /*************************************************************************** 00002 * Copyright (c) 2005 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 #endif 00027 00028 #include <Base/Console.h> 00029 #include <Base/Exception.h> 00030 #include <Base/Sequencer.h> 00031 00032 #include "Core/MeshKernel.h" 00033 #include "Core/Algorithm.h" 00034 #include "Core/Evaluation.h" 00035 #include "Core/Iterator.h" 00036 #include "Core/Visitor.h" 00037 00038 #include "Core/SetOperations.h" 00039 00040 #include "FeatureMeshSetOperations.h" 00041 00042 00043 using namespace Mesh; 00044 using namespace std; 00045 00046 PROPERTY_SOURCE(Mesh::SetOperations, Mesh::Feature) 00047 00048 00049 SetOperations::SetOperations(void) 00050 { 00051 ADD_PROPERTY(Source1 ,(0)); 00052 ADD_PROPERTY(Source2 ,(0)); 00053 ADD_PROPERTY(OperationType, ("union")); 00054 } 00055 00056 short SetOperations::mustExecute() const 00057 { 00058 if (Source1.getValue() && Source2.getValue()) { 00059 if (Source1.isTouched()) 00060 return 1; 00061 if (Source2.isTouched()) 00062 return 1; 00063 if (OperationType.isTouched()) 00064 return 1; 00065 } 00066 00067 return 0; 00068 } 00069 00070 App::DocumentObjectExecReturn *SetOperations::execute(void) 00071 { 00072 Mesh::Feature *mesh1 = dynamic_cast<Mesh::Feature*>(Source1.getValue()); 00073 Mesh::Feature *mesh2 = dynamic_cast<Mesh::Feature*>(Source2.getValue()); 00074 00075 if ((mesh1 != NULL) && (mesh2 != NULL)) { 00076 const MeshObject& meshKernel1 = mesh1->Mesh.getValue(); 00077 const MeshObject& meshKernel2 = mesh2->Mesh.getValue(); 00078 00079 std::auto_ptr<MeshObject> pcKernel(new MeshObject()); // Result Meshkernel 00080 00081 MeshCore::SetOperations::OperationType type; 00082 string ot(OperationType.getValue()); 00083 if (ot == "union") 00084 type = MeshCore::SetOperations::Union; 00085 else if (ot == "intersection") 00086 type = MeshCore::SetOperations::Intersect; 00087 else if (ot == "difference") 00088 type = MeshCore::SetOperations::Difference; 00089 else if (ot == "inner") 00090 type = MeshCore::SetOperations::Inner; 00091 else if (ot == "outer") 00092 type = MeshCore::SetOperations::Outer; 00093 else 00094 throw new Base::Exception("Operation type must either be 'union' or 'intersection'" 00095 " or 'difference' or 'inner' or 'outer'"); 00096 00097 MeshCore::SetOperations setOp(meshKernel1.getKernel(), meshKernel2.getKernel(), 00098 pcKernel->getKernel(), type, 1.0e-5f); 00099 setOp.Do(); 00100 Mesh.setValuePtr(pcKernel.release()); 00101 } 00102 else { 00103 // Error mesh property 00104 if (!mesh1) 00105 throw new Base::Exception("First input mesh not set"); 00106 if (!mesh2) 00107 throw new Base::Exception("Second input mesh not set"); 00108 } 00109 00110 return App::DocumentObject::StdReturn; 00111 } 00112