PartFeatures.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 <BRepFill.hxx>
00027 # include <TopoDS.hxx>
00028 # include <TopoDS_Face.hxx>
00029 # include <TopoDS_Shell.hxx>
00030 #endif
00031
00032
00033 #include "PartFeatures.h"
00034
00035
00036 using namespace Part;
00037
00038 PROPERTY_SOURCE(Part::RuledSurface, Part::Feature)
00039
00040 RuledSurface::RuledSurface()
00041 {
00042 ADD_PROPERTY_TYPE(Curve1,(0),"Ruled Surface",App::Prop_None,"Curve of ruled surface");
00043 ADD_PROPERTY_TYPE(Curve2,(0),"Ruled Surface",App::Prop_None,"Curve of ruled surface");
00044 }
00045
00046 short RuledSurface::mustExecute() const
00047 {
00048 if (Curve1.isTouched())
00049 return 1;
00050 if (Curve2.isTouched())
00051 return 1;
00052 return 0;
00053 }
00054
00055 void RuledSurface::onChanged(const App::Property* prop)
00056 {
00057 Part::Feature::onChanged(prop);
00058 }
00059
00060 App::DocumentObjectExecReturn *RuledSurface::execute(void)
00061 {
00062 App::DocumentObject* c1 = Curve1.getValue();
00063 if (!(c1 && c1->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId())))
00064 return new App::DocumentObjectExecReturn("No shape linked.");
00065 const std::vector<std::string>& element1 = Curve1.getSubValues();
00066 if (element1.size() != 1)
00067 return new App::DocumentObjectExecReturn("Not exactly one sub-shape linked.");
00068 App::DocumentObject* c2 = Curve2.getValue();
00069 if (!(c2 && c2->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId())))
00070 return new App::DocumentObjectExecReturn("No shape linked.");
00071 const std::vector<std::string>& element2 = Curve2.getSubValues();
00072 if (element2.size() != 1)
00073 return new App::DocumentObjectExecReturn("Not exactly one sub-shape linked.");
00074
00075 const Part::TopoShape& shape1 = static_cast<Part::Feature*>(c1)->Shape.getValue();
00076 TopoDS_Shape curve1 = shape1.getSubShape(element1[0].c_str());
00077 if (curve1.IsNull()) curve1 = shape1._Shape;
00078
00079 const Part::TopoShape& shape2 = static_cast<Part::Feature*>(c2)->Shape.getValue();
00080 TopoDS_Shape curve2 = shape2.getSubShape(element2[0].c_str());
00081 if (curve2.IsNull()) curve2 = shape2._Shape;
00082
00083 try {
00084 if (curve1.IsNull() || curve2.IsNull())
00085 return new App::DocumentObjectExecReturn("Linked shapes are empty.");
00086 if (curve1.ShapeType() == TopAbs_EDGE && curve2.ShapeType() == TopAbs_EDGE) {
00087 TopoDS_Face face = BRepFill::Face(TopoDS::Edge(curve1), TopoDS::Edge(curve2));
00088 this->Shape.setValue(face);
00089 }
00090 else if (curve1.ShapeType() == TopAbs_WIRE && curve2.ShapeType() == TopAbs_WIRE) {
00091 TopoDS_Shell shell = BRepFill::Shell(TopoDS::Wire(curve1), TopoDS::Wire(curve2));
00092 this->Shape.setValue(shell);
00093 }
00094 else {
00095 return new App::DocumentObjectExecReturn("Curves must either be edges or wires.");
00096 }
00097 return App::DocumentObject::StdReturn;
00098 }
00099 catch (Standard_Failure) {
00100 Handle_Standard_Failure e = Standard_Failure::Caught();
00101 return new App::DocumentObjectExecReturn(e->GetMessageString());
00102 }
00103 }
00104
00105
00106
00107 PROPERTY_SOURCE(Part::Loft, Part::Feature)
00108
00109 Loft::Loft()
00110 {
00111 ADD_PROPERTY_TYPE(Sections,(0),"Loft",App::Prop_None,"List of sections");
00112 Sections.setSize(0);
00113 ADD_PROPERTY_TYPE(Solid,(false),"Loft",App::Prop_None,"Create solid");
00114 ADD_PROPERTY_TYPE(Ruled,(false),"Loft",App::Prop_None,"Ruled surface");
00115 }
00116
00117 short Loft::mustExecute() const
00118 {
00119 if (Sections.isTouched())
00120 return 1;
00121 if (Solid.isTouched())
00122 return 1;
00123 if (Ruled.isTouched())
00124 return 1;
00125 return 0;
00126 }
00127
00128 void Loft::onChanged(const App::Property* prop)
00129 {
00130 Part::Feature::onChanged(prop);
00131 }
00132
00133 App::DocumentObjectExecReturn *Loft::execute(void)
00134 {
00135 if (Sections.getSize() == 0)
00136 return new App::DocumentObjectExecReturn("No sections linked.");
00137
00138 try {
00139 TopTools_ListOfShape profiles;
00140 const std::vector<App::DocumentObject*>& shapes = Sections.getValues();
00141 std::vector<App::DocumentObject*>::const_iterator it;
00142 for (it = shapes.begin(); it != shapes.end(); ++it) {
00143 if (!(*it)->isDerivedFrom(Part::Feature::getClassTypeId()))
00144 return new App::DocumentObjectExecReturn("Linked object is not a shape.");
00145 const TopoDS_Shape& shape = static_cast<Part::Feature*>(*it)->Shape.getValue();
00146 if (shape.IsNull())
00147 return new App::DocumentObjectExecReturn("Linked shape is invalid.");
00148 if (shape.ShapeType() == TopAbs_WIRE)
00149 profiles.Append(shape);
00150 else if (shape.ShapeType() == TopAbs_EDGE)
00151 profiles.Append(shape);
00152 else
00153 return new App::DocumentObjectExecReturn("Linked shape is neither a vertex nor a wire.");
00154 }
00155
00156 Standard_Boolean isSolid = Solid.getValue() ? Standard_True : Standard_False;
00157 Standard_Boolean isRuled = Ruled.getValue() ? Standard_True : Standard_False;
00158
00159 TopoShape myShape;
00160 this->Shape.setValue(myShape.makeLoft(profiles, isSolid, isRuled));
00161 return App::DocumentObject::StdReturn;
00162 }
00163 catch (Standard_Failure) {
00164 Handle_Standard_Failure e = Standard_Failure::Caught();
00165 return new App::DocumentObjectExecReturn(e->GetMessageString());
00166 }
00167 }