FeaturePatternRectangular.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 <BRep_Builder.hxx>
00028 # include <BRepBndLib.hxx>
00029 # include <BRepBuilderAPI_MakeFace.hxx>
00030 # include <BRepAdaptor_Surface.hxx>
00031 # include <BRepCheck_Analyzer.hxx>
00032 # include <TopoDS.hxx>
00033 # include <TopoDS_Compound.hxx>
00034 # include <TopoDS_Face.hxx>
00035 # include <TopoDS_Wire.hxx>
00036 # include <TopExp_Explorer.hxx>
00037 # include <gp_Pln.hxx>
00038 # include <ShapeFix_Face.hxx>
00039 # include <ShapeFix_Wire.hxx>
00040 # include <ShapeAnalysis.hxx>
00041 # include <TopTools_IndexedMapOfShape.hxx>
00042 #endif
00043 
00044 
00045 #include "FeaturePatternRectangular.h"
00046 
00047 
00048 using namespace PartDesign;
00049 
00050 namespace PartDesign {
00051 
00052 
00053 PROPERTY_SOURCE(PartDesign::PatternRectangular, PartDesign::Feature)
00054 
00055 PatternRectangular::PatternRectangular()
00056 {
00057     ADD_PROPERTY(Base,(0));
00058 }
00059 
00060 //short PatternRectangular::mustExecute() const
00061 //{
00062 //    if (Sketch.isTouched() ||
00063 //        Length.isTouched())
00064 //        return 1;
00065 //    return 0;
00066 //}
00067 
00068 App::DocumentObjectExecReturn *PatternRectangular::execute(void)
00069 {
00070     //App::DocumentObject* link = Sketch.getValue();
00071     //if (!link)
00072     //    return new App::DocumentObjectExecReturn("No sketch linked");
00073     //if (!link->getTypeId().isDerivedFrom(Part::Part2DObject::getClassTypeId()))
00074     //    return new App::DocumentObjectExecReturn("Linked object is not a Sketch or Part2DObject");
00075     //TopoDS_Shape shape = static_cast<Part::Part2DObject*>(link)->Shape.getShape()._Shape;
00076     //if (shape.IsNull())
00077     //    return new App::DocumentObjectExecReturn("Linked shape object is empty");
00078 
00083     //BRepBuilderAPI_Copy copy(shape);
00084     //shape = copy.Shape();
00085     //if (shape.IsNull())
00086     //    return new App::DocumentObjectExecReturn("Linked shape object is empty");
00087 
00088     //TopExp_Explorer ex;
00089     //std::vector<TopoDS_Wire> wires;
00090     //for (ex.Init(shape, TopAbs_WIRE); ex.More(); ex.Next()) {
00091     //    wires.push_back(TopoDS::Wire(ex.Current()));
00092     //}
00093     //if (/*shape.ShapeType() != TopAbs_WIRE*/wires.empty()) // there can be several wires
00094     //    return new App::DocumentObjectExecReturn("Linked shape object is not a wire");
00095 
00097     //Base::Placement SketchPos = static_cast<Part::Part2DObject*>(link)->Placement.getValue();
00098     //Base::Rotation SketchOrientation = SketchPos.getRotation();
00099     //Base::Vector3d SketchVector(0,0,1);
00100     //SketchOrientation.multVec(SketchVector,SketchVector);
00101 
00103     //App::DocumentObject* SupportLink = static_cast<Part::Part2DObject*>(link)->Support.getValue();
00104     //Part::Feature *SupportObject = 0;
00105     //if (SupportLink && SupportLink->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId()))
00106     //    SupportObject = static_cast<Part::Feature*>(SupportLink);
00107 
00108     //if (!SupportObject)
00109     //    return new App::DocumentObjectExecReturn("No support in Sketch!");
00110 
00111     //TopoDS_Shape aFace = makeFace(wires);
00112     //if (aFace.IsNull())
00113     //    return new App::DocumentObjectExecReturn("Creating a face from sketch failed");
00114 
00116     //SketchVector *= Length.getValue();
00117 
00119     //SketchVector *= -1;
00120 
00122     //gp_Vec vec(SketchVector.x,SketchVector.y,SketchVector.z);
00123     //BRepPrimAPI_MakePrism PrismMaker(aFace,vec,0,1);
00124     //if (PrismMaker.IsDone()) {
00125     //    // if the sketch has a support fuse them to get one result object (PAD!)
00126     //    if (SupportObject) {
00127     //        const TopoDS_Shape& support = SupportObject->Shape.getValue();
00128     //        if (support.IsNull())
00129     //            return new App::DocumentObjectExecReturn("Support shape is invalid");
00130     //        TopExp_Explorer xp (support, TopAbs_SOLID);
00131     //        if (!xp.More())
00132     //            return new App::DocumentObjectExecReturn("Support shape is not a solid");
00133     //        // Let's call algorithm computing a fuse operation:
00134     //        BRepAlgoAPI_Cut mkCut(support, PrismMaker.Shape());
00135     //        // Let's check if the fusion has been successful
00136     //        if (!mkCut.IsDone()) 
00137     //            return new App::DocumentObjectExecReturn("Cut with support failed");
00138     //        this->Shape.setValue(mkCut.Shape());
00139     //    }
00140     //    else{
00141     //        return new App::DocumentObjectExecReturn("Cannot create a tool out of sketch with no support");
00142     //    }
00143     //}
00144     //else
00145     //    return new App::DocumentObjectExecReturn("Could not extrude the sketch!");
00146 
00147     return App::DocumentObject::StdReturn;
00148 }
00149 
00150 
00151 
00152 
00153 }

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