FeatureMirroring.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
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 }