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

« back to all changes in this revision

Viewing changes to src/Mod/Part/App/FeatureRevolution.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Adam C. Powell, IV
  • Date: 2010-01-11 08:48:33 UTC
  • mfrom: (3.1.3 sid)
  • Revision ID: james.westby@ubuntu.com-20100111084833-4g9vgdqbkw8u34zb
Tags: 0.9.2646.5-1
* New upstream version (closes: #561696).
* Added swig to Build-Depends (closes: #563523, #563772).
* Removed python-opencv from Build-Depends and Recommends (closes: #560768).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
 *   Copyright (c) 2009 Werner Mayer <wmayer[at]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 <gp_Ax1.hxx>
 
27
#endif
 
28
 
 
29
 
 
30
#include "FeatureRevolution.h"
 
31
 
 
32
 
 
33
using namespace Part;
 
34
 
 
35
App::PropertyFloatConstraint::Constraints Revolution::angleRangeU = {0.0f,360.0f,1.0f};
 
36
 
 
37
PROPERTY_SOURCE(Part::Revolution, Part::Feature)
 
38
 
 
39
Revolution::Revolution()
 
40
{
 
41
    ADD_PROPERTY(Source,(0));
 
42
    ADD_PROPERTY(Base,(Base::Vector3f(0.0f,0.0f,0.0f)));
 
43
    ADD_PROPERTY(Axis,(Base::Vector3f(0.0f,0.0f,1.0f)));
 
44
    ADD_PROPERTY(Angle,(360.0f));
 
45
    Angle.setConstraints(&angleRangeU);
 
46
}
 
47
 
 
48
short Revolution::mustExecute() const
 
49
{
 
50
    if (Base.isTouched() ||
 
51
        Axis.isTouched() ||
 
52
        Source.isTouched())
 
53
        return 1;
 
54
    return 0;
 
55
}
 
56
 
 
57
App::DocumentObjectExecReturn *Revolution::execute(void)
 
58
{
 
59
    App::DocumentObject* link = Source.getValue();
 
60
    if (!link)
 
61
        return new App::DocumentObjectExecReturn("No object linked");
 
62
    if (!link->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId()))
 
63
        return new App::DocumentObjectExecReturn("Linked object is not a Part object");
 
64
    Part::Feature *base = static_cast<Part::Feature*>(Source.getValue());
 
65
 
 
66
    Base::Vector3f b = Base.getValue();
 
67
    Base::Vector3f v = Axis.getValue();
 
68
    gp_Pnt pnt(b.x,b.y,b.z);
 
69
    gp_Dir dir(v.x,v.y,v.z);
 
70
 
 
71
    try {
 
72
        // Now, let's get the TopoDS_Shape
 
73
        TopoDS_Shape revolve = base->Shape.getShape().revolve(gp_Ax1(pnt, dir),
 
74
            Angle.getValue()/180.0f*Standard_PI);
 
75
        if (revolve.IsNull())
 
76
            return new App::DocumentObjectExecReturn("Resulting shape is null");
 
77
        this->Shape.setValue(revolve);
 
78
        return App::DocumentObject::StdReturn;
 
79
    }
 
80
    catch (Standard_Failure) {
 
81
        Handle_Standard_Failure e = Standard_Failure::Caught();
 
82
        return new App::DocumentObjectExecReturn(e->GetMessageString());
 
83
    }
 
84
}