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
00026 #ifndef _PreComp_
00027 # include <sstream>
00028 # include <BRep_Builder.hxx>
00029 # include <TopoDS_Compound.hxx>
00030 #endif
00031
00032
00033 #include <strstream>
00034 #include <Base/Writer.h>
00035 #include <Base/Reader.h>
00036 #include <Base/Exception.h>
00037 #include <Base/FileInfo.h>
00038
00039 #include "FeatureProjection.h"
00040 #include "ProjectionAlgos.h"
00041
00042 using namespace Drawing;
00043
00044
00045 PROPERTY_SOURCE(Drawing::FeatureProjection, Part::Feature)
00046
00047
00048 FeatureProjection::FeatureProjection()
00049 {
00050 static const char *group = "Projection";
00051 ADD_PROPERTY_TYPE(Source ,(0),group,App::Prop_None,"Shape to project");
00052 ADD_PROPERTY_TYPE(Direction ,(Base::Vector3f(0,0,1)),group,App::Prop_None,"Projection direction");
00053 ADD_PROPERTY_TYPE(VCompound ,(true),group,App::Prop_None,"Projection parameter");
00054 ADD_PROPERTY_TYPE(Rg1LineVCompound ,(true),group,App::Prop_None,"Projection parameter");
00055 ADD_PROPERTY_TYPE(RgNLineVCompound ,(true),group,App::Prop_None,"Projection parameter");
00056 ADD_PROPERTY_TYPE(OutLineVCompound ,(true),group,App::Prop_None,"Projection parameter");
00057 ADD_PROPERTY_TYPE(IsoLineVCompound ,(true),group,App::Prop_None,"Projection parameter");
00058 ADD_PROPERTY_TYPE(HCompound ,(true),group,App::Prop_None,"Projection parameter");
00059 ADD_PROPERTY_TYPE(Rg1LineHCompound ,(true),group,App::Prop_None,"Projection parameter");
00060 ADD_PROPERTY_TYPE(RgNLineHCompound ,(true),group,App::Prop_None,"Projection parameter");
00061 ADD_PROPERTY_TYPE(OutLineHCompound ,(true),group,App::Prop_None,"Projection parameter");
00062 ADD_PROPERTY_TYPE(IsoLineHCompound ,(true),group,App::Prop_None,"Projection parameter");
00063 }
00064
00065 FeatureProjection::~FeatureProjection()
00066 {
00067 }
00068
00069 App::DocumentObjectExecReturn *FeatureProjection::execute(void)
00070 {
00071 App::DocumentObject* link = Source.getValue();
00072 if (!link)
00073 return new App::DocumentObjectExecReturn("No object linked");
00074 if (!link->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId()))
00075 return new App::DocumentObjectExecReturn("Linked object is not a Part object");
00076 const TopoDS_Shape& shape = static_cast<Part::Feature*>(link)->Shape.getShape()._Shape;
00077 if (shape.IsNull())
00078 return new App::DocumentObjectExecReturn("Linked shape object is empty");
00079
00080 try {
00081 const Base::Vector3f& dir = Direction.getValue();
00082 Drawing::ProjectionAlgos alg(shape, dir);
00083
00084 TopoDS_Compound comp;
00085 BRep_Builder builder;
00086 builder.MakeCompound(comp);
00087 if (!alg.V.IsNull() && VCompound.getValue())
00088 builder.Add(comp, alg.V);
00089 if (!alg.V1.IsNull() && Rg1LineVCompound.getValue())
00090 builder.Add(comp, alg.V1);
00091 if (!alg.VN.IsNull() && RgNLineVCompound.getValue())
00092 builder.Add(comp, alg.VN);
00093 if (!alg.VO.IsNull() && OutLineVCompound.getValue())
00094 builder.Add(comp, alg.VO);
00095 if (!alg.VI.IsNull() && IsoLineVCompound.getValue())
00096 builder.Add(comp, alg.VI);
00097 if (!alg.H.IsNull() && HCompound.getValue())
00098 builder.Add(comp, alg.H);
00099 if (!alg.H1.IsNull() && Rg1LineHCompound.getValue())
00100 builder.Add(comp, alg.H1);
00101 if (!alg.HN.IsNull() && RgNLineHCompound.getValue())
00102 builder.Add(comp, alg.HN);
00103 if (!alg.HO.IsNull() && OutLineHCompound.getValue())
00104 builder.Add(comp, alg.HO);
00105 if (!alg.HI.IsNull() && IsoLineHCompound.getValue())
00106 builder.Add(comp, alg.HI);
00107
00108 Shape.setValue(comp);
00109 return App::DocumentObject::StdReturn;
00110 }
00111 catch (Standard_Failure) {
00112 Handle_Standard_Failure e = Standard_Failure::Caught();
00113 return new App::DocumentObjectExecReturn(e->GetMessageString());
00114 }
00115 }