FeatureHole.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (c) 2011 Juergen Riegel <FreeCAD@juergen-riegel.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 <Bnd_Box.hxx>
00027 # include <gp_Dir.hxx>
00028 # include <gp_Pln.hxx>
00029 # include <BRep_Builder.hxx>
00030 # include <BRepAdaptor_Surface.hxx>
00031 # include <BRepBndLib.hxx>
00032 # include <BRepPrimAPI_MakePrism.hxx>
00033 # include <BRepBuilderAPI_Copy.hxx>
00034 # include <BRepBuilderAPI_MakeFace.hxx>
00035 # include <Geom_Plane.hxx>
00036 # include <Handle_Geom_Surface.hxx>
00037 # include <TopoDS.hxx>
00038 # include <TopoDS_Face.hxx>
00039 # include <TopoDS_Wire.hxx>
00040 # include <TopExp_Explorer.hxx>
00041 # include <BRepAlgoAPI_Cut.hxx>
00042 #endif
00043 
00044 #include <Base/Placement.h>
00045 #include <Mod/Part/App/Part2DObject.h>
00046 
00047 #include "FeatureHole.h"
00048 
00049 
00050 using namespace PartDesign;
00051 
00052 const char* Hole::TypeEnums[]    = {"Dimension","UpToLast","UpToFirst",NULL};
00053 const char* Hole::HoleTypeEnums[]= {"Simple","Counterbore","Countersunk",NULL};
00054 const char* Hole::ThreadEnums[]  = {"None","Metric","MetricFine",NULL};
00055 
00056 PROPERTY_SOURCE(PartDesign::Hole, PartDesign::SketchBased)
00057 
00058 Hole::Hole()
00059 {
00060     ADD_PROPERTY(Type,((long)0));
00061     Type.setEnums(TypeEnums);
00062     ADD_PROPERTY(HoleType,((long)0));
00063     Type.setEnums(HoleTypeEnums);
00064     ADD_PROPERTY(ThreadType,((long)0));
00065     Type.setEnums(ThreadEnums);
00066     ADD_PROPERTY(Length,(100.0));
00067     ADD_PROPERTY(ThreadSize,(6.0));
00068 }
00069 
00070 //short Hole::mustExecute() const
00071 //{
00072 //    if (Sketch.isTouched() ||
00073 //        Length.isTouched())
00074 //        return 1;
00075 //    return 0;
00076 //}
00077 
00078 App::DocumentObjectExecReturn *Hole::execute(void)
00079 {
00080     //App::DocumentObject* link = Sketch.getValue();
00081     //if (!link)
00082     //    return new App::DocumentObjectExecReturn("No sketch linked");
00083     //if (!link->getTypeId().isDerivedFrom(Part::Part2DObject::getClassTypeId()))
00084     //    return new App::DocumentObjectExecReturn("Linked object is not a Sketch or Part2DObject");
00085     //TopoDS_Shape shape = static_cast<Part::Part2DObject*>(link)->Shape.getShape()._Shape;
00086     //if (shape.IsNull())
00087     //    return new App::DocumentObjectExecReturn("Linked shape object is empty");
00088 
00093     //BRepBuilderAPI_Copy copy(shape);
00094     //shape = copy.Shape();
00095     //if (shape.IsNull())
00096     //    return new App::DocumentObjectExecReturn("Linked shape object is empty");
00097 
00098     //TopExp_Explorer ex;
00099     //std::vector<TopoDS_Wire> wires;
00100     //for (ex.Init(shape, TopAbs_WIRE); ex.More(); ex.Next()) {
00101     //    wires.push_back(TopoDS::Wire(ex.Current()));
00102     //}
00103     //if (/*shape.ShapeType() != TopAbs_WIRE*/wires.empty()) // there can be several wires
00104     //    return new App::DocumentObjectExecReturn("Linked shape object is not a wire");
00105 
00107     //Base::Placement SketchPos = static_cast<Part::Part2DObject*>(link)->Placement.getValue();
00108     //Base::Rotation SketchOrientation = SketchPos.getRotation();
00109     //Base::Vector3d SketchVector(0,0,1);
00110     //SketchOrientation.multVec(SketchVector,SketchVector);
00111 
00113     //App::DocumentObject* SupportLink = static_cast<Part::Part2DObject*>(link)->Support.getValue();
00114     //Part::Feature *SupportObject = 0;
00115     //if (SupportLink && SupportLink->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId()))
00116     //    SupportObject = static_cast<Part::Feature*>(SupportLink);
00117 
00118     //if (!SupportObject)
00119     //    return new App::DocumentObjectExecReturn("No support in Sketch!");
00120 
00121     //TopoDS_Shape aFace = makeFace(wires);
00122     //if (aFace.IsNull())
00123     //    return new App::DocumentObjectExecReturn("Creating a face from sketch failed");
00124 
00126     //SketchVector *= Length.getValue();
00127 
00129     //SketchVector *= -1;
00130 
00132     //gp_Vec vec(SketchVector.x,SketchVector.y,SketchVector.z);
00133     //BRepPrimAPI_MakePrism PrismMaker(aFace,vec,0,1);
00134     //if (PrismMaker.IsDone()) {
00135     //    // if the sketch has a support fuse them to get one result object (PAD!)
00136     //    if (SupportObject) {
00137     //        const TopoDS_Shape& support = SupportObject->Shape.getValue();
00138     //        if (support.IsNull())
00139     //            return new App::DocumentObjectExecReturn("Support shape is invalid");
00140     //        TopExp_Explorer xp (support, TopAbs_SOLID);
00141     //        if (!xp.More())
00142     //            return new App::DocumentObjectExecReturn("Support shape is not a solid");
00143     //        // Let's call algorithm computing a fuse operation:
00144     //        BRepAlgoAPI_Cut mkCut(support, PrismMaker.Shape());
00145     //        // Let's check if the fusion has been successful
00146     //        if (!mkCut.IsDone()) 
00147     //            return new App::DocumentObjectExecReturn("Cut with support failed");
00148     //        this->Shape.setValue(mkCut.Shape());
00149     //    }
00150     //    else{
00151     //        return new App::DocumentObjectExecReturn("Cannot create a tool out of sketch with no support");
00152     //    }
00153     //}
00154     //else
00155     //    return new App::DocumentObjectExecReturn("Could not extrude the sketch!");
00156 
00157     return App::DocumentObject::StdReturn;
00158 }
00159 

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