~ubuntu-branches/ubuntu/maverick/freecad/maverick

« back to all changes in this revision

Viewing changes to src/Mod/PartDesign/App/FeatureFillet.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Teemu Ikonen
  • Date: 2009-07-16 18:37:41 UTC
  • Revision ID: james.westby@ubuntu.com-20090716183741-oww9kcxqrk991i1n
Tags: upstream-0.8.2237
ImportĀ upstreamĀ versionĀ 0.8.2237

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
 *   Copyright (c) 2008 Werner Mayer <wmayer@users.sourceforge.net>        *
 
3
 *                                                                         *
 
4
 *   This file is part of the FreeCAD CAx development system.              *
 
5
 *                                                                         *
 
6
 *   This library is free software; you can redistribute it and/or         *
 
7
 *   modify it under the terms of the GNU Library General Public           *
 
8
 *   License as published by the Free Software Foundation; either          *
 
9
 *   version 2 of the License, or (at your option) any later version.      *
 
10
 *                                                                         *
 
11
 *   This library  is distributed in the hope that it will be useful,      *
 
12
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 
13
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 
14
 *   GNU Library General Public License for more details.                  *
 
15
 *                                                                         *
 
16
 *   You should have received a copy of the GNU Library General Public     *
 
17
 *   License along with this library; see the file COPYING.LIB. If not,    *
 
18
 *   write to the Free Software Foundation, Inc., 59 Temple Place,         *
 
19
 *   Suite 330, Boston, MA  02111-1307, USA                                *
 
20
 *                                                                         *
 
21
 ***************************************************************************/
 
22
 
 
23
 
 
24
#include "PreCompiled.h"
 
25
#ifndef _PreComp_
 
26
# include <BRepFilletAPI_MakeFillet.hxx>
 
27
# include <TopExp_Explorer.hxx>
 
28
# include <TopoDS.hxx>
 
29
# include <TopoDS_Edge.hxx>
 
30
#endif
 
31
 
 
32
 
 
33
#include "FeatureFillet.h"
 
34
 
 
35
 
 
36
using namespace PartDesign;
 
37
 
 
38
 
 
39
PROPERTY_SOURCE(PartDesign::Fillet, Part::Feature)
 
40
 
 
41
Fillet::Fillet()
 
42
{
 
43
    ADD_PROPERTY(Base,(0));
 
44
    ADD_PROPERTY(Contour,(0,0,0));
 
45
    Contour.setSize(0);
 
46
}
 
47
 
 
48
short Fillet::mustExecute() const
 
49
{
 
50
    if (Base.isTouched() || Contour.isTouched())
 
51
        return 1;
 
52
    return 0;
 
53
}
 
54
 
 
55
App::DocumentObjectExecReturn *Fillet::execute(void)
 
56
{
 
57
    App::DocumentObject* link = Base.getValue();
 
58
    if (!link)
 
59
        return new App::DocumentObjectExecReturn("No object linked");
 
60
    if (!link->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId()))
 
61
        return new App::DocumentObjectExecReturn("Linked object is not a Part object");
 
62
    Part::Feature *base = static_cast<Part::Feature*>(Base.getValue());
 
63
 
 
64
    float radius = 5;
 
65
 
 
66
    BRepFilletAPI_MakeFillet mkFillet(base->Shape.getValue());
 
67
    TopExp_Explorer xp(base->Shape.getValue(), TopAbs_EDGE);
 
68
 
 
69
    //std::map<int, TopoDS_Edge> edgeMap;
 
70
    for (;xp.More();xp.Next()) {
 
71
        TopoDS_Edge edge = TopoDS::Edge(xp.Current());
 
72
        mkFillet.Add(radius, radius, edge);
 
73
        //edgeMap[edge.HashCode(IntegerLast())] = edge;
 
74
    }
 
75
/*
 
76
    std::vector<FilletElement> values = Contour.getValues();
 
77
    for (std::vector<FilletElement>::iterator it = values.begin(); it != values.end(); ++it) {
 
78
        int id = it->hashval;
 
79
        double radius1 = it->radius1;
 
80
        double radius2 = it->radius2;
 
81
        std::map<int, TopoDS_Edge>::iterator ed = edgeMap.find(id);
 
82
        if (ed != edgeMap.end())
 
83
            mkFillet.Add(radius1, radius2, ed->second);
 
84
    }
 
85
*/
 
86
    try {
 
87
        TopoDS_Shape shape = mkFillet.Shape();
 
88
        if (shape.IsNull())
 
89
            return new App::DocumentObjectExecReturn("Resulting shape is null");
 
90
        this->Shape.setValue(shape);
 
91
        return App::DocumentObject::StdReturn;
 
92
    }
 
93
    catch (Standard_Failure) {
 
94
        Handle_Standard_Failure e = Standard_Failure::Caught();
 
95
        return new App::DocumentObjectExecReturn(e->GetMessageString());
 
96
    }
 
97
}