Edge2TracObject.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
00026 #ifndef _PreComp_
00027 #endif
00028
00029 #include "Edge2TracObject.h"
00030
00031
00032 #include <Base/Sequencer.h>
00033 #include <Mod/Part/App/edgecluster.h>
00034 #include <Mod/Part/App/PartFeature.h>
00035 #include <TopoDS.hxx>
00036 #include <TopoDS_Edge.hxx>
00037 #include <TopoDS_Vertex.hxx>
00038 #include <BRep_Tool.hxx>
00039 #include <BRepAdaptor_Curve.hxx>
00040 #include <CPnts_AbscissaPoint.hxx>
00041 #include <TopExp.hxx>
00042 #include "Waypoint.h"
00043 #include "Trajectory.h"
00044
00045 using namespace Robot;
00046 using namespace App;
00047
00048 PROPERTY_SOURCE(Robot::Edge2TracObject, Robot::TrajectoryObject)
00049
00050
00051 Edge2TracObject::Edge2TracObject()
00052 {
00053
00054 ADD_PROPERTY_TYPE( Source, (0) , "Edge2Trac",Prop_None,"Edges to generate the Trajectory");
00055 ADD_PROPERTY_TYPE( SegValue, (0.5), "Edge2Trac",Prop_None,"Max deviation from original geometry");
00056 ADD_PROPERTY_TYPE( UseRotation, (0) , "Edge2Trac",Prop_None,"use orientation of the edge");
00057 NbrOfEdges = 0;
00058 NbrOfCluster = 0;
00059 }
00060
00061 Edge2TracObject::~Edge2TracObject()
00062 {
00063 }
00064
00065 App::DocumentObjectExecReturn *Edge2TracObject::execute(void)
00066 {
00067 App::DocumentObject* link = Source.getValue();
00068 if (!link)
00069 return new App::DocumentObjectExecReturn("No object linked");
00070 if (!link->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId()))
00071 return new App::DocumentObjectExecReturn("Linked object is not a Part object");
00072 Part::Feature *base = static_cast<Part::Feature*>(Source.getValue());
00073 const Part::TopoShape& TopShape = base->Shape.getShape();
00074
00075 const std::vector<std::string>& SubVals = Source.getSubValuesStartsWith("Edge");
00076 if (SubVals.size() == 0)
00077 return new App::DocumentObjectExecReturn("No Edges specified");
00078
00079
00080 std::vector<TopoDS_Edge> edges;
00081
00082
00083 for (std::vector<std::string>::const_iterator it= SubVals.begin();it!=SubVals.end();++it) {
00084 TopoDS_Edge edge = TopoDS::Edge(TopShape.getSubShape(it->c_str()));
00085 edges.push_back(edge);
00086 }
00087
00088
00089 Part::Edgecluster acluster(edges);
00090 Part::tEdgeClusterVector aclusteroutput = acluster.GetClusters();
00091
00092 if(aclusteroutput.size() == 0)
00093 return new App::DocumentObjectExecReturn("No Edges specified");
00094
00095
00096 NbrOfCluster = aclusteroutput.size();
00097 NbrOfEdges = 0;
00098 for(std::vector<std::vector<TopoDS_Edge> >::const_iterator it=aclusteroutput.begin();it!=aclusteroutput.end();++it)
00099 NbrOfEdges += it->size();
00100
00101
00102 Robot::Trajectory trac;
00103 bool first = true;
00104
00105
00106 for(std::vector<std::vector<TopoDS_Edge> >::const_iterator it=aclusteroutput.begin();it!=aclusteroutput.end();++it)
00107 {
00108
00109 for(std::vector<TopoDS_Edge>::const_iterator it2=it->begin();it2!=it->end();++it2)
00110 {
00111 BRepAdaptor_Curve adapt(*it2);
00112
00113 switch(adapt.GetType())
00114 {
00115 case GeomAbs_Line:
00116 {
00117
00118 gp_Pnt P1 = adapt.Value(adapt.FirstParameter());
00119 gp_Pnt P2 = adapt.Value(adapt.LastParameter());
00120
00121 Base::Rotation R1;
00122 Base::Rotation R2;
00123
00124
00125 if(UseRotation.getValue()) {
00126
00127
00128
00129
00130 }
00131
00132
00133 if ( it2->Orientation() == TopAbs_REVERSED )
00134 {
00135
00136 gp_Pnt tmpP = P1;
00137 Base::Rotation tmpR = R1;
00138 P1 = P2;
00139 R1 = R2;
00140 R2 = tmpR;
00141 P2 = tmpP;
00142 }
00143 if(first){
00144 Waypoint wp("Pt",Base::Placement(Base::Vector3d(P1.X(),P1.Y(),P1.Z()),R1));
00145 trac.addWaypoint(wp);
00146 first = false;
00147 }
00148 Waypoint wp("Pt",Base::Placement(Base::Vector3d(P2.X(),P2.Y(),P2.Z()),R2));
00149 trac.addWaypoint(wp);
00150 break;
00151 }
00152 case GeomAbs_BSplineCurve:
00153 {
00154 Standard_Real Length = CPnts_AbscissaPoint::Length(adapt);
00155 Standard_Real ParLength = adapt.LastParameter()-adapt.FirstParameter();
00156 Standard_Real NbrSegments = Round(Length / SegValue.getValue());
00157
00158 Standard_Real beg = adapt.FirstParameter();
00159 Standard_Real end = adapt.LastParameter();
00160 Standard_Real stp = ParLength / NbrSegments;
00161 bool reversed = false;
00162 if (it2->Orientation() == TopAbs_REVERSED) {
00163 std::swap(beg, end);
00164 stp = - stp;
00165 reversed = true;
00166 }
00167
00168 if (first)
00169 first = false;
00170 else
00171 beg += stp;
00172 Base::SequencerLauncher seq("Create way points", static_cast<size_t>((end-beg)/stp));
00173 if(reversed)
00174 {
00175 for (;beg > end; beg += stp) {
00176 gp_Pnt P = adapt.Value(beg);
00177 Base::Rotation R1;
00178
00179 if(UseRotation.getValue()) {
00180
00181
00182 }
00183
00184 Waypoint wp("Pt",Base::Placement(Base::Vector3d(P.X(),P.Y(),P.Z()),R1));
00185 trac.addWaypoint(wp);
00186 seq.next();
00187 }
00188 }
00189 else
00190 {
00191 for (;beg < end; beg += stp) {
00192 gp_Pnt P = adapt.Value(beg);
00193 Base::Rotation R1;
00194
00195 if(UseRotation.getValue()) {
00196
00197
00198 }
00199 Waypoint wp("Pt",Base::Placement(Base::Vector3d(P.X(),P.Y(),P.Z()),R1));
00200 trac.addWaypoint(wp);
00201 seq.next();
00202 }
00203 }
00204
00205 } break;
00206 case GeomAbs_Circle:
00207 {
00208 Standard_Real Length = CPnts_AbscissaPoint::Length(adapt);
00209 Standard_Real ParLength = adapt.LastParameter()-adapt.FirstParameter();
00210 Standard_Real NbrSegments = Round(Length / SegValue.getValue());
00211 Standard_Real SegLength = ParLength / NbrSegments;
00212
00213 if ( it2->Orientation() == TopAbs_REVERSED )
00214 {
00215
00216 double i = adapt.LastParameter();
00217 if(first)
00218 first=false;
00219 else
00220 i -= SegLength;
00221 for (;i>adapt.FirstParameter();i-= SegLength){
00222 gp_Pnt P = adapt.Value(i);
00223 Base::Rotation R1;
00224
00225 if(UseRotation.getValue()) {
00226
00227
00228 }
00229 Waypoint wp("Pt",Base::Placement(Base::Vector3d(P.X(),P.Y(),P.Z()),R1));
00230 trac.addWaypoint(wp);
00231 }
00232 }
00233 else
00234 {
00235 double i = adapt.FirstParameter();
00236 if(first)
00237 first=false;
00238 else
00239 i += SegLength;
00240 for (;i<adapt.LastParameter();i+= SegLength)
00241 {
00242 gp_Pnt P = adapt.Value(i);
00243 Base::Rotation R1;
00244
00245 if(UseRotation.getValue()) {
00246
00247
00248 }
00249 Waypoint wp("Pt",Base::Placement(Base::Vector3d(P.X(),P.Y(),P.Z()),R1));
00250 trac.addWaypoint(wp);
00251 }
00252
00253 }
00254 break;
00255 }
00256
00257 default:
00258 throw Base::Exception("Unknown Edge type in Robot::Edge2TracObject::execute()");
00259 }
00260
00261
00262
00263 }
00264 }
00265
00266 Trajectory.setValue(trac);
00267
00268 return App::DocumentObject::StdReturn;
00269 }
00270
00271
00272
00273
00274
00275
00276
00277 void Edge2TracObject::onChanged(const Property* prop)
00278 {
00279
00280 App::GeoFeature::onChanged(prop);
00281 }