FeatureMirroring.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (c) 2010 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 # include <gp.hxx>
00027 # include <gp_Ax2.hxx>
00028 # include <gp_Dir.hxx>
00029 # include <gp_Pnt.hxx>
00030 # include <gp_Trsf.hxx>
00031 # include <BRepBuilderAPI_Transform.hxx>
00032 #endif
00033 
00034 
00035 #include "FeatureMirroring.h"
00036 
00037 
00038 using namespace Part;
00039 
00040 PROPERTY_SOURCE(Part::Mirroring, Part::Feature)
00041 
00042 Mirroring::Mirroring()
00043 {
00044     ADD_PROPERTY(Source,(0));
00045     ADD_PROPERTY_TYPE(Base,(Base::Vector3f()),"Plane",App::Prop_None,"The base point of the plane");
00046     ADD_PROPERTY_TYPE(Normal,(Base::Vector3f(0,0,1)),"Plane",App::Prop_None,"The normal of the plane");
00047 }
00048 
00049 short Mirroring::mustExecute() const
00050 {
00051     if (Source.isTouched())
00052         return 1;
00053     if (Base.isTouched())
00054         return 1;
00055     if (Normal.isTouched())
00056         return 1;
00057     return 0;
00058 }
00059 
00060 void Mirroring::onChanged(const App::Property* prop)
00061 {
00062     if (!isRestoring()) {
00063         if (prop == &Base || prop == &Normal) {
00064             try {
00065                 App::DocumentObjectExecReturn *ret = recompute();
00066                 delete ret;
00067             }
00068             catch (...) {
00069             }
00070         }
00071     }
00072     Part::Feature::onChanged(prop);
00073 }
00074 
00075 App::DocumentObjectExecReturn *Mirroring::execute(void)
00076 {
00077     App::DocumentObject* link = Source.getValue();
00078     if (!link)
00079         return new App::DocumentObjectExecReturn("No object linked");
00080     if (!link->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId()))
00081         return new App::DocumentObjectExecReturn("Linked object is not a Part object");
00082     Part::Feature *source = static_cast<Part::Feature*>(link);
00083     Base::Vector3f base = Base.getValue();
00084     Base::Vector3f norm = Normal.getValue();
00085 
00086     try {
00087         gp_Ax2 ax2(gp_Pnt(base.x,base.y,base.z), gp_Dir(norm.x,norm.y,norm.z));
00088         this->Shape.setValue(source->Shape.getShape().mirror(ax2));
00089         return App::DocumentObject::StdReturn;
00090     }
00091     catch (Standard_Failure) {
00092         Handle_Standard_Failure e = Standard_Failure::Caught();
00093         return new App::DocumentObjectExecReturn(e->GetMessageString());
00094     }
00095 }

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