Geometry.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (c) 2008 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 <BRepBuilderAPI_MakeEdge.hxx>
00027 # include <BRepBuilderAPI_MakeFace.hxx>
00028 # include <BRepBuilderAPI_MakeVertex.hxx>
00029 # include <Geom_CartesianPoint.hxx>
00030 # include <Geom_Circle.hxx>
00031 # include <Geom_Curve.hxx>
00032 # include <Geom_Ellipse.hxx>
00033 # include <Geom_Hyperbola.hxx>
00034 # include <Geom_Parabola.hxx>
00035 # include <Geom_OffsetCurve.hxx>
00036 # include <Geom_TrimmedCurve.hxx>
00037 # include <Geom_Line.hxx>
00038 # include <Geom_BezierCurve.hxx>
00039 # include <Geom_BezierSurface.hxx>
00040 # include <Geom_BSplineCurve.hxx>
00041 # include <Geom_BSplineSurface.hxx>
00042 # include <Geom_Surface.hxx>
00043 # include <Geom_Plane.hxx>
00044 # include <Geom_CylindricalSurface.hxx>
00045 # include <Geom_ConicalSurface.hxx>
00046 # include <Geom_SphericalSurface.hxx>
00047 # include <Geom_ToroidalSurface.hxx>
00048 # include <Geom_OffsetSurface.hxx>
00049 # include <Geom_RectangularTrimmedSurface.hxx>
00050 # include <Geom_SurfaceOfRevolution.hxx>
00051 # include <Geom_SurfaceOfLinearExtrusion.hxx>
00052 # include <GeomConvert.hxx>
00053 # include <GeomConvert_CompCurveToBSplineCurve.hxx>
00054 # include <GeomLProp_CLProps.hxx>
00055 # include <GeomLProp_SLProps.hxx>
00056 # include <gp_Circ.hxx>
00057 # include <gp_Elips.hxx>
00058 # include <gp_Hypr.hxx>
00059 # include <gp_Parab.hxx>
00060 # include <gce_ErrorType.hxx>
00061 # include <gp_Lin.hxx>
00062 # include <gp_Pln.hxx>
00063 # include <gp_Pnt.hxx>
00064 # include <gp_Cylinder.hxx>
00065 # include <gp_Cone.hxx>
00066 # include <gp_Sphere.hxx>
00067 # include <gp_Torus.hxx>
00068 # include <Standard_Real.hxx>
00069 # include <TColgp_Array1OfPnt.hxx>
00070 # include <TColgp_Array2OfPnt.hxx>
00071 # include <TColStd_Array1OfReal.hxx>
00072 # include <TColStd_Array1OfInteger.hxx>
00073 # include <gp.hxx>
00074 # include <gp_Lin.hxx>
00075 # include <Geom_Line.hxx>
00076 # include <Geom_TrimmedCurve.hxx>
00077 # include <GC_MakeArcOfCircle.hxx>
00078 # include <GC_MakeCircle.hxx>
00079 # include <GC_MakeLine.hxx>
00080 # include <GC_MakeSegment.hxx>
00081 # include <Precision.hxx>
00082 
00083 #endif
00084 
00085 #include "LinePy.h"
00086 #include <Base/VectorPy.h>
00087 #include "CirclePy.h"
00088 #include "EllipsePy.h"
00089 #include "ArcPy.h"
00090 #include "ArcOfCirclePy.h"
00091 #include "BezierCurvePy.h"
00092 #include "BSplineCurvePy.h"
00093 #include "HyperbolaPy.h"
00094 #include "OffsetCurvePy.h"
00095 #include "ParabolaPy.h"
00096 #include "BezierSurfacePy.h"
00097 #include "BSplineSurfacePy.h"
00098 #include "ConePy.h"
00099 #include "CylinderPy.h"
00100 #include "OffsetSurfacePy.h"
00101 #include "PlanePy.h"
00102 #include "RectangularTrimmedSurfacePy.h"
00103 #include "SpherePy.h"
00104 #include "SurfaceOfExtrusionPy.h"
00105 #include "SurfaceOfRevolutionPy.h"
00106 #include "ToroidPy.h"
00107 
00108 #include <Base/Exception.h>
00109 #include <Base/Writer.h>
00110 #include <Base/Reader.h>
00111 #include <Base/Tools.h>
00112 
00113 #include "Geometry.h"
00114 
00115 using namespace Part;
00116 
00117 
00118 const char* gce_ErrorStatusText(gce_ErrorType et)
00119 {
00120     switch (et)
00121     {
00122     case gce_Done:
00123         return "Construction was successful";
00124     case gce_ConfusedPoints:
00125         return "Two points are coincident";
00126     case gce_NegativeRadius:
00127         return "Radius value is negative";
00128     case gce_ColinearPoints:
00129         return "Three points are collinear";
00130     case gce_IntersectionError:
00131         return "Intersection cannot be computed";
00132     case gce_NullAxis:
00133         return "Axis is undefined";
00134     case gce_NullAngle:
00135         return "Angle value is invalid (usually null)";
00136     case gce_NullRadius:
00137         return "Radius is null";
00138     case gce_InvertAxis:
00139         return "Axis value is invalid";
00140     case gce_BadAngle:
00141         return "Angle value is invalid";
00142     case gce_InvertRadius:
00143         return "Radius value is incorrect (usually with respect to another radius)";
00144     case gce_NullFocusLength:
00145         return "Focal distance is null";
00146     case gce_NullVector:
00147         return "Vector is null";
00148     case gce_BadEquation:
00149         return "Coefficients are incorrect (applies to the equation of a geometric object)";
00150     default:
00151         return "Creation of geometry failed";
00152     }
00153 }
00154 
00155 // ---------------------------------------------------------------
00156 
00157 TYPESYSTEM_SOURCE_ABSTRACT(Part::Geometry,Base::Persistence);
00158 
00159 Geometry::Geometry()
00160   : Construction(false)
00161 {
00162 }
00163 
00164 Geometry::~Geometry()
00165 {
00166 }
00167 
00168 // Persistence implementer 
00169 unsigned int Geometry::getMemSize (void) const               
00170 {
00171     return 1;
00172 }
00173 
00174 void         Geometry::Save       (Base::Writer &writer) const 
00175 {
00176     const char c = Construction?'1':'0';
00177     writer.Stream() << writer.ind() << "<Construction value=\"" <<  c << "\"/>" << endl;
00178 }
00179 
00180 void         Geometry::Restore    (Base::XMLReader &reader)    
00181 {
00182     // read my Element
00183     reader.readElement("Construction");
00184     // get the value of my Attribute
00185     Construction = (int)reader.getAttributeAsInteger("value")==0?false:true;   
00186 }
00187 
00188 // -------------------------------------------------
00189 
00190 TYPESYSTEM_SOURCE(Part::GeomPoint,Part::Geometry);
00191 
00192 GeomPoint::GeomPoint()
00193 {
00194     this->myPoint = new Geom_CartesianPoint(0,0,0);
00195 }
00196 
00197 GeomPoint::GeomPoint(const Handle_Geom_CartesianPoint& p)
00198 {
00199     this->myPoint = Handle_Geom_CartesianPoint::DownCast(p->Copy());
00200 }
00201 
00202 GeomPoint::GeomPoint(const Base::Vector3d& p)
00203 {
00204     this->myPoint = new Geom_CartesianPoint(p.x,p.y,p.z);
00205 }
00206 
00207 GeomPoint::~GeomPoint()
00208 {
00209 }
00210 
00211 const Handle_Geom_Geometry& GeomPoint::handle() const
00212 {
00213     return myPoint;
00214 }
00215 
00216 Geometry *GeomPoint::clone(void) const
00217 {
00218     GeomPoint *newPoint = new GeomPoint(myPoint);
00219     newPoint->Construction = this->Construction;
00220     return newPoint;
00221 }
00222 
00223 TopoDS_Shape GeomPoint::toShape() const
00224 {
00225     return BRepBuilderAPI_MakeVertex(myPoint->Pnt());
00226 }
00227 
00228 Base::Vector3d GeomPoint::getPoint(void)const
00229 {
00230     return Base::Vector3d(myPoint->X(),myPoint->Y(),myPoint->Z());
00231 }
00232 
00233 void GeomPoint::setPoint(const Base::Vector3d& p)
00234 {
00235     this->myPoint->SetCoord(p.x,p.y,p.z);
00236 }
00237 
00238 // Persistence implementer 
00239 unsigned int GeomPoint::getMemSize (void) const               
00240 {
00241     return sizeof(Geom_CartesianPoint);
00242 }
00243 
00244 void GeomPoint::Save(Base::Writer &writer) const 
00245 {
00246     // save the attributes of the father class
00247     Geometry::Save(writer);
00248 
00249     Base::Vector3d Point   =  getPoint();
00250     writer.Stream() 
00251          << writer.ind() 
00252              << "<GeomPoint " 
00253                 << "X=\"" <<  Point.x << 
00254                 "\" Y=\"" <<  Point.y << 
00255                 "\" Z=\"" <<  Point.z << 
00256              "\"/>" << endl;
00257 }
00258 
00259 void GeomPoint::Restore(Base::XMLReader &reader) 
00260 {
00261     // read the attributes of the father class
00262     Geometry::Restore(reader);
00263 
00264     double X,Y,Z;
00265     // read my Element
00266     reader.readElement("GeomPoint");
00267     // get the value of my Attribute
00268     X = reader.getAttributeAsFloat("X");
00269     Y = reader.getAttributeAsFloat("Y");
00270     Z = reader.getAttributeAsFloat("Z");
00271  
00272     // set the read geometry
00273     setPoint(Base::Vector3d(X,Y,Z) );
00274 }
00275 
00276 PyObject *GeomPoint::getPyObject(void)
00277 {
00278     return new Base::VectorPy(getPoint());
00279 }
00280 
00281 // -------------------------------------------------
00282 
00283 TYPESYSTEM_SOURCE_ABSTRACT(Part::GeomCurve,Part::Geometry);
00284 
00285 GeomCurve::GeomCurve()
00286 {
00287 }
00288 
00289 GeomCurve::~GeomCurve()
00290 {
00291 }
00292 
00293 TopoDS_Shape GeomCurve::toShape() const
00294 {
00295     Handle_Geom_Curve c = Handle_Geom_Curve::DownCast(handle());
00296     BRepBuilderAPI_MakeEdge mkBuilder(c, c->FirstParameter(), c->LastParameter());
00297     return mkBuilder.Shape();
00298 }
00299 
00300 bool GeomCurve::tangent(double u, gp_Dir& dir) const
00301 {
00302     Handle_Geom_Curve c = Handle_Geom_Curve::DownCast(handle());
00303     GeomLProp_CLProps prop(c,u,1,Precision::Confusion());
00304     if (prop.IsTangentDefined()) {
00305         prop.Tangent(dir);
00306         return true;
00307     }
00308 
00309     return false;
00310 }
00311 
00312 
00313 // -------------------------------------------------
00314 
00315 TYPESYSTEM_SOURCE(Part::GeomBezierCurve,Part::GeomCurve);
00316 
00317 GeomBezierCurve::GeomBezierCurve()
00318 {
00319     TColgp_Array1OfPnt poles(1,2);
00320     poles(1) = gp_Pnt(0.0,0.0,0.0);
00321     poles(2) = gp_Pnt(0.0,0.0,1.0);
00322     Handle_Geom_BezierCurve b = new Geom_BezierCurve(poles);
00323     this->myCurve = b;
00324 }
00325 
00326 GeomBezierCurve::GeomBezierCurve(const Handle_Geom_BezierCurve& b)
00327 {
00328     this->myCurve = Handle_Geom_BezierCurve::DownCast(b->Copy());
00329 }
00330 
00331 GeomBezierCurve::~GeomBezierCurve()
00332 {
00333 }
00334 
00335 void GeomBezierCurve::setHandle(const Handle_Geom_BezierCurve& c)
00336 {
00337     myCurve = Handle_Geom_BezierCurve::DownCast(c->Copy());
00338 }
00339 
00340 const Handle_Geom_Geometry& GeomBezierCurve::handle() const
00341 {
00342     return myCurve;
00343 }
00344 
00345 Geometry *GeomBezierCurve::clone(void) const
00346 {
00347     GeomBezierCurve *newCurve = new GeomBezierCurve(myCurve);
00348     newCurve->Construction = this->Construction;
00349     return newCurve;
00350 }
00351 
00352 // Persistence implementer 
00353 unsigned int GeomBezierCurve::getMemSize (void) const               {assert(0); return 0;/* not implemented yet */}
00354 void         GeomBezierCurve::Save       (Base::Writer &/*writer*/) const {assert(0);          /* not implemented yet */}
00355 void         GeomBezierCurve::Restore    (Base::XMLReader &/*reader*/)    {assert(0);          /* not implemented yet */}
00356 
00357 PyObject *GeomBezierCurve::getPyObject(void)
00358 {
00359     return new BezierCurvePy((GeomBezierCurve*)this->clone());
00360 }
00361 
00362 // -------------------------------------------------
00363 
00364 TYPESYSTEM_SOURCE(Part::GeomBSplineCurve,Part::GeomCurve);
00365 
00366 GeomBSplineCurve::GeomBSplineCurve()
00367 {
00368     TColgp_Array1OfPnt poles(1,2);
00369     poles(1) = gp_Pnt(0.0,0.0,0.0);
00370     poles(2) = gp_Pnt(1.0,0.0,0.0);
00371 
00372     TColStd_Array1OfReal knots(1,2);
00373     knots(1) = 0.0;
00374     knots(2) = 1.0;
00375 
00376     TColStd_Array1OfInteger mults(1,2);
00377     mults(1) = 2;
00378     mults(2) = 2;
00379 
00380     this->myCurve = new Geom_BSplineCurve(poles, knots, mults, 1);
00381 }
00382 
00383 GeomBSplineCurve::GeomBSplineCurve(const Handle_Geom_BSplineCurve& b)
00384 {
00385     this->myCurve = Handle_Geom_BSplineCurve::DownCast(b->Copy());
00386 }
00387 
00388 GeomBSplineCurve::~GeomBSplineCurve()
00389 {
00390 }
00391 
00392 void GeomBSplineCurve::setHandle(const Handle_Geom_BSplineCurve& c)
00393 {
00394     myCurve = Handle_Geom_BSplineCurve::DownCast(c->Copy());
00395 }
00396 
00397 const Handle_Geom_Geometry& GeomBSplineCurve::handle() const
00398 {
00399     return myCurve;
00400 }
00401 
00402 Geometry *GeomBSplineCurve::clone(void) const
00403 {
00404     GeomBSplineCurve *newCurve = new GeomBSplineCurve(myCurve);
00405     newCurve->Construction = this->Construction;
00406     return newCurve;
00407 }
00408 
00409 int GeomBSplineCurve::countPoles() const
00410 {
00411     return myCurve->NbPoles();
00412 }
00413 
00414 void GeomBSplineCurve::setPole(int index, const Base::Vector3d& pole, double weight)
00415 {
00416     try {
00417         gp_Pnt pnt(pole.x,pole.y,pole.z);
00418         if (weight < 0.0)
00419             myCurve->SetPole(index+1,pnt);
00420         else
00421             myCurve->SetPole(index+1,pnt,weight);
00422     }
00423     catch (Standard_Failure) {
00424         Handle_Standard_Failure e = Standard_Failure::Caught();
00425         std::cout << e->GetMessageString() << std::endl;
00426     }
00427 }
00428 
00429 std::vector<Base::Vector3d> GeomBSplineCurve::getPoles() const
00430 {
00431     std::vector<Base::Vector3d> poles;
00432     poles.reserve(myCurve->NbPoles());
00433     TColgp_Array1OfPnt p(1,myCurve->NbPoles());
00434     myCurve->Poles(p);
00435 
00436     for (Standard_Integer i=p.Lower(); i<=p.Upper(); i++) {
00437         const gp_Pnt& pnt = p(i);
00438         poles.push_back(Base::Vector3d(pnt.X(), pnt.Y(), pnt.Z()));
00439     }
00440     return poles;
00441 }
00442 
00443 bool GeomBSplineCurve::join(const Handle_Geom_BSplineCurve& spline)
00444 {
00445     GeomConvert_CompCurveToBSplineCurve ccbc(this->myCurve);
00446     if (!ccbc.Add(spline, Precision::Approximation()))
00447         return false;
00448     this->myCurve = ccbc.BSplineCurve();
00449     return true;
00450 }
00451 
00452 void GeomBSplineCurve::makeC1Continuous(double tol, double ang_tol)
00453 {
00454     GeomConvert::C0BSplineToC1BSplineCurve(this->myCurve, tol, ang_tol);
00455 }
00456 
00457 // Persistence implementer 
00458 unsigned int GeomBSplineCurve::getMemSize (void) const               {assert(0); return 0;/* not implemented yet */}
00459 void         GeomBSplineCurve::Save       (Base::Writer &/*writer*/) const {assert(0);          /* not implemented yet */}
00460 void         GeomBSplineCurve::Restore    (Base::XMLReader &/*reader*/)    {assert(0);          /* not implemented yet */}
00461 
00462 PyObject *GeomBSplineCurve::getPyObject(void)
00463 {
00464     return new BSplineCurvePy((GeomBSplineCurve*)this->clone());
00465 }
00466 
00467 // -------------------------------------------------
00468 
00469 TYPESYSTEM_SOURCE(Part::GeomCircle,Part::GeomCurve);
00470 
00471 GeomCircle::GeomCircle()
00472 {
00473     Handle_Geom_Circle c = new Geom_Circle(gp_Circ());
00474     this->myCurve = c;
00475 }
00476 
00477 GeomCircle::GeomCircle(const Handle_Geom_Circle& c)
00478 {
00479     this->myCurve = Handle_Geom_Circle::DownCast(c->Copy());
00480 }
00481 
00482 GeomCircle::~GeomCircle()
00483 {
00484 }
00485 
00486 const Handle_Geom_Geometry& GeomCircle::handle() const
00487 {
00488     return myCurve;
00489 }
00490 
00491 Geometry *GeomCircle::clone(void) const
00492 {
00493     GeomCircle *newCirc = new GeomCircle(myCurve);
00494     newCirc->Construction = this->Construction;
00495     return newCirc;
00496 }
00497 
00498 Base::Vector3d GeomCircle::getCenter(void) const
00499 {
00500     Handle_Geom_Circle circle = Handle_Geom_Circle::DownCast(handle());
00501     gp_Ax1 axis = circle->Axis();
00502     const gp_Pnt& loc = axis.Location();
00503     return Base::Vector3d(loc.X(),loc.Y(),loc.Z());
00504 }
00505 
00506 double GeomCircle::getRadius(void) const
00507 {
00508     Handle_Geom_Circle circle = Handle_Geom_Circle::DownCast(handle());
00509     return circle->Radius();
00510 }
00511 
00512 void GeomCircle::setCenter(const Base::Vector3d& Center)
00513 {
00514     gp_Pnt p1(Center.x,Center.y,Center.z);
00515     Handle_Geom_Circle circle = Handle_Geom_Circle::DownCast(handle());
00516 
00517     try {
00518         circle->SetLocation(p1);
00519     }
00520     catch (Standard_Failure) {
00521         Handle_Standard_Failure e = Standard_Failure::Caught();
00522         throw Base::Exception(e->GetMessageString());
00523     }
00524 }
00525 
00526 void GeomCircle::setRadius(double Radius)
00527 {
00528     Handle_Geom_Circle circle = Handle_Geom_Circle::DownCast(handle());
00529 
00530     try {
00531         gp_Circ c = circle->Circ();
00532         c.SetRadius(Radius);
00533         circle->SetCirc(c);
00534     }
00535     catch (Standard_Failure) {
00536         Handle_Standard_Failure e = Standard_Failure::Caught();
00537         throw Base::Exception(e->GetMessageString());
00538     }
00539 }
00540 
00541 // Persistence implementer 
00542 unsigned int GeomCircle::getMemSize (void) const
00543 {
00544     return sizeof(Geom_Circle);
00545 }
00546 
00547 void GeomCircle::Save(Base::Writer& writer) const
00548 {
00549     // save the attributes of the father class
00550     GeomCurve::Save(writer);
00551 
00552     gp_Pnt center = this->myCurve->Axis().Location();
00553     gp_Dir norm = this->myCurve->Axis().Direction();
00554 
00555     writer.Stream()
00556          << writer.ind()
00557              << "<Circle "
00558                 << "CenterX=\"" <<  center.X() <<
00559                 "\" CenterY=\"" <<  center.Y() <<
00560                 "\" CenterZ=\"" <<  center.Z() <<
00561                 "\" NormalX=\"" <<  norm.X() <<
00562                 "\" NormalY=\"" <<  norm.Y() <<
00563                 "\" NormalZ=\"" <<  norm.Z() <<
00564                 "\" Radius=\"" <<  this->myCurve->Radius() <<
00565              "\"/>" << endl;
00566 }
00567 
00568 void GeomCircle::Restore(Base::XMLReader& reader)
00569 {
00570     // read the attributes of the father class
00571     GeomCurve::Restore(reader);
00572 
00573     double CenterX,CenterY,CenterZ,NormalX,NormalY,NormalZ,Radius;
00574     // read my Element
00575     reader.readElement("Circle");
00576     // get the value of my Attribute
00577     CenterX = reader.getAttributeAsFloat("CenterX");
00578     CenterY = reader.getAttributeAsFloat("CenterY");
00579     CenterZ = reader.getAttributeAsFloat("CenterZ");
00580     NormalX = reader.getAttributeAsFloat("NormalX");
00581     NormalY = reader.getAttributeAsFloat("NormalY");
00582     NormalZ = reader.getAttributeAsFloat("NormalZ");
00583     Radius = reader.getAttributeAsFloat("Radius");
00584 
00585     // set the read geometry
00586     gp_Pnt p1(CenterX,CenterY,CenterZ);
00587     gp_Dir norm(NormalX,NormalY,NormalZ);
00588     try {
00589         GC_MakeCircle mc(p1, norm, Radius);
00590         if (!mc.IsDone())
00591             throw Base::Exception(gce_ErrorStatusText(mc.Status()));
00592 
00593         this->myCurve = mc.Value();
00594     }
00595     catch (Standard_Failure) {
00596         Handle_Standard_Failure e = Standard_Failure::Caught();
00597         throw Base::Exception(e->GetMessageString());
00598     }
00599 }
00600 
00601 PyObject *GeomCircle::getPyObject(void)
00602 {
00603     return new CirclePy((GeomCircle*)this->clone());
00604 }
00605 
00606 // -------------------------------------------------
00607 
00608 TYPESYSTEM_SOURCE(Part::GeomArcOfCircle,Part::GeomCurve);
00609 
00610 GeomArcOfCircle::GeomArcOfCircle()
00611 {
00612     Handle_Geom_Circle c = new Geom_Circle(gp_Circ());
00613     this->myCurve = new Geom_TrimmedCurve(c, c->FirstParameter(),c->LastParameter());
00614 }
00615 
00616 GeomArcOfCircle::GeomArcOfCircle(const Handle_Geom_Circle& c)
00617 {
00618     this->myCurve = new Geom_TrimmedCurve(c, c->FirstParameter(),c->LastParameter());
00619 }
00620 
00621 GeomArcOfCircle::~GeomArcOfCircle()
00622 {
00623 }
00624 
00625 void GeomArcOfCircle::setHandle(const Handle_Geom_TrimmedCurve& c)
00626 {
00627     Handle_Geom_Circle basis = Handle_Geom_Circle::DownCast(c->BasisCurve());
00628     if (basis.IsNull())
00629         Standard_Failure::Raise("Basis curve is not a circle");
00630     this->myCurve = Handle_Geom_TrimmedCurve::DownCast(c->Copy());
00631 }
00632 
00633 const Handle_Geom_Geometry& GeomArcOfCircle::handle() const
00634 {
00635     return myCurve;
00636 }
00637 
00638 Geometry *GeomArcOfCircle::clone(void) const
00639 {
00640     GeomArcOfCircle* copy = new GeomArcOfCircle();
00641     copy->setHandle(this->myCurve);
00642     copy->Construction = this->Construction;
00643     return copy;
00644 }
00645 
00646 Base::Vector3d GeomArcOfCircle::getStartPoint() const
00647 {
00648     gp_Pnt pnt = this->myCurve->StartPoint();
00649     return Base::Vector3d(pnt.X(), pnt.Y(), pnt.Z());
00650 }
00651 
00652 Base::Vector3d GeomArcOfCircle::getEndPoint() const
00653 {
00654     gp_Pnt pnt = this->myCurve->EndPoint();
00655     return Base::Vector3d(pnt.X(), pnt.Y(), pnt.Z());
00656 }
00657 
00658 Base::Vector3d GeomArcOfCircle::getCenter(void) const
00659 {
00660     Handle_Geom_Circle circle = Handle_Geom_Circle::DownCast(myCurve->BasisCurve());
00661     gp_Ax1 axis = circle->Axis();
00662     const gp_Pnt& loc = axis.Location();
00663     return Base::Vector3d(loc.X(),loc.Y(),loc.Z());
00664 }
00665 
00666 double GeomArcOfCircle::getRadius(void) const
00667 {
00668     Handle_Geom_Circle circle = Handle_Geom_Circle::DownCast(myCurve->BasisCurve());
00669     return circle->Radius();
00670 }
00671 
00672 void GeomArcOfCircle::setCenter(const Base::Vector3d& Center)
00673 {
00674     gp_Pnt p1(Center.x,Center.y,Center.z);
00675     Handle_Geom_Circle circle = Handle_Geom_Circle::DownCast(myCurve->BasisCurve());
00676 
00677     try {
00678         circle->SetLocation(p1);
00679     }
00680     catch (Standard_Failure) {
00681         Handle_Standard_Failure e = Standard_Failure::Caught();
00682         throw Base::Exception(e->GetMessageString());
00683     }
00684 }
00685 
00686 void GeomArcOfCircle::setRadius(double Radius)
00687 {
00688     Handle_Geom_Circle circle = Handle_Geom_Circle::DownCast(myCurve->BasisCurve());
00689 
00690     try {
00691         gp_Circ c = circle->Circ();
00692         c.SetRadius(Radius);
00693         circle->SetCirc(c);
00694     }
00695     catch (Standard_Failure) {
00696         Handle_Standard_Failure e = Standard_Failure::Caught();
00697         throw Base::Exception(e->GetMessageString());
00698     }
00699 }
00700 
00701 void GeomArcOfCircle::getRange(double& u, double& v) const
00702 {
00703     u = myCurve->FirstParameter();
00704     v = myCurve->LastParameter();
00705 }
00706 
00707 void GeomArcOfCircle::setRange(double u, double v)
00708 {
00709     myCurve->SetTrim(u, v);
00710 }
00711 
00712 // Persistence implementer 
00713 unsigned int GeomArcOfCircle::getMemSize (void) const
00714 {
00715     return sizeof(Geom_Circle) + 2 *sizeof(double);
00716 }
00717 
00718 void GeomArcOfCircle::Save(Base::Writer &writer) const 
00719 {
00720     // save the attributes of the father class
00721     Geometry::Save(writer);
00722 
00723     Handle_Geom_Circle circle = Handle_Geom_Circle::DownCast(this->myCurve->BasisCurve());
00724 
00725     gp_Pnt center = circle->Axis().Location();
00726     gp_Dir norm = circle->Axis().Direction();
00727 
00728     writer.Stream()
00729          << writer.ind()
00730              << "<ArcOfCircle "
00731                 << "CenterX=\"" <<  center.X() <<
00732                 "\" CenterY=\"" <<  center.Y() <<
00733                 "\" CenterZ=\"" <<  center.Z() <<
00734                 "\" NormalX=\"" <<  norm.X() <<
00735                 "\" NormalY=\"" <<  norm.Y() <<
00736                 "\" NormalZ=\"" <<  norm.Z() <<
00737                 "\" Radius=\"" <<  circle->Radius() <<
00738                 "\" StartAngle=\"" <<  this->myCurve->FirstParameter() <<
00739                 "\" EndAngle=\"" <<  this->myCurve->LastParameter() <<
00740              "\"/>" << endl;
00741 }
00742 
00743 void GeomArcOfCircle::Restore(Base::XMLReader &reader)    
00744 {
00745     // read the attributes of the father class
00746     Geometry::Restore(reader);
00747 
00748     double CenterX,CenterY,CenterZ,NormalX,NormalY,NormalZ,Radius,StartAngle,EndAngle;
00749     // read my Element
00750     reader.readElement("ArcOfCircle");
00751     // get the value of my Attribute
00752     CenterX = reader.getAttributeAsFloat("CenterX");
00753     CenterY = reader.getAttributeAsFloat("CenterY");
00754     CenterZ = reader.getAttributeAsFloat("CenterZ");
00755     NormalX = reader.getAttributeAsFloat("NormalX");
00756     NormalY = reader.getAttributeAsFloat("NormalY");
00757     NormalZ = reader.getAttributeAsFloat("NormalZ");
00758     Radius = reader.getAttributeAsFloat("Radius");
00759     StartAngle = reader.getAttributeAsFloat("StartAngle");
00760     EndAngle = reader.getAttributeAsFloat("EndAngle");
00761 
00762     // set the read geometry
00763     gp_Pnt p1(CenterX,CenterY,CenterZ);
00764     gp_Dir norm(NormalX,NormalY,NormalZ);
00765     try {
00766         GC_MakeCircle mc(p1, norm, Radius);
00767         if (!mc.IsDone())
00768             throw Base::Exception(gce_ErrorStatusText(mc.Status()));
00769         GC_MakeArcOfCircle ma(mc.Value()->Circ(), StartAngle, EndAngle, 1);
00770         if (!ma.IsDone())
00771             throw Base::Exception(gce_ErrorStatusText(ma.Status()));
00772 
00773         Handle_Geom_TrimmedCurve tmpcurve = ma.Value();
00774         Handle_Geom_Circle tmpcircle = Handle_Geom_Circle::DownCast(tmpcurve->BasisCurve());
00775         Handle_Geom_Circle circle = Handle_Geom_Circle::DownCast(this->myCurve->BasisCurve());
00776  
00777         circle->SetCirc(tmpcircle->Circ());
00778         this->myCurve->SetTrim(tmpcurve->FirstParameter(), tmpcurve->LastParameter());
00779     }
00780     catch (Standard_Failure) {
00781         Handle_Standard_Failure e = Standard_Failure::Caught();
00782         throw Base::Exception(e->GetMessageString());
00783     }
00784 }
00785 
00786 PyObject *GeomArcOfCircle::getPyObject(void)
00787 {
00788     return new ArcOfCirclePy(static_cast<GeomArcOfCircle*>(this->clone()));
00789 }
00790 
00791 // -------------------------------------------------
00792 
00793 TYPESYSTEM_SOURCE(Part::GeomEllipse,Part::GeomCurve);
00794 
00795 GeomEllipse::GeomEllipse()
00796 {
00797     Handle_Geom_Ellipse e = new Geom_Ellipse(gp_Elips());
00798     this->myCurve = e;
00799 }
00800 
00801 GeomEllipse::GeomEllipse(const Handle_Geom_Ellipse& e)
00802 {
00803     this->myCurve = Handle_Geom_Ellipse::DownCast(e->Copy());
00804 }
00805 
00806 GeomEllipse::~GeomEllipse()
00807 {
00808 }
00809 
00810 const Handle_Geom_Geometry& GeomEllipse::handle() const
00811 {
00812     return myCurve;
00813 }
00814 
00815 Geometry *GeomEllipse::clone(void) const
00816 {
00817     GeomEllipse *newEllipse = new GeomEllipse(myCurve);
00818     newEllipse->Construction = this->Construction;
00819     return newEllipse;
00820 }
00821 
00822 // Persistence implementer 
00823 unsigned int GeomEllipse::getMemSize (void) const               {assert(0); return 0;/* not implemented yet */}
00824 void         GeomEllipse::Save       (Base::Writer &/*writer*/) const {assert(0);          /* not implemented yet */}
00825 void         GeomEllipse::Restore    (Base::XMLReader &/*reader*/)    {assert(0);          /* not implemented yet */}
00826 
00827 PyObject *GeomEllipse::getPyObject(void)
00828 {
00829     return new EllipsePy((GeomEllipse*)this->clone());
00830 }
00831 
00832 // -------------------------------------------------
00833 
00834 TYPESYSTEM_SOURCE(Part::GeomHyperbola,Part::GeomCurve);
00835 
00836 GeomHyperbola::GeomHyperbola()
00837 {
00838     Handle_Geom_Hyperbola h = new Geom_Hyperbola(gp_Hypr());
00839     this->myCurve = h;
00840 }
00841 
00842 GeomHyperbola::GeomHyperbola(const Handle_Geom_Hyperbola& h)
00843 {
00844     this->myCurve = Handle_Geom_Hyperbola::DownCast(h->Copy());
00845 }
00846 
00847 GeomHyperbola::~GeomHyperbola()
00848 {
00849 }
00850 
00851 const Handle_Geom_Geometry& GeomHyperbola::handle() const
00852 {
00853     return myCurve;
00854 }
00855 
00856 Geometry *GeomHyperbola::clone(void) const
00857 {
00858     GeomHyperbola *newHyp = new GeomHyperbola(myCurve);
00859     newHyp->Construction = this->Construction;
00860     return newHyp;
00861 }
00862 
00863 // Persistence implementer 
00864 unsigned int GeomHyperbola::getMemSize (void) const               {assert(0); return 0;/* not implemented yet */}
00865 void         GeomHyperbola::Save       (Base::Writer &/*writer*/) const {assert(0);          /* not implemented yet */}
00866 void         GeomHyperbola::Restore    (Base::XMLReader &/*reader*/)    {assert(0);          /* not implemented yet */}
00867 
00868 PyObject *GeomHyperbola::getPyObject(void)
00869 {
00870     return new HyperbolaPy((GeomHyperbola*)this->clone());
00871 }
00872 
00873 // -------------------------------------------------
00874 
00875 TYPESYSTEM_SOURCE(Part::GeomParabola,Part::GeomCurve);
00876 
00877 GeomParabola::GeomParabola()
00878 {
00879     Handle_Geom_Parabola p = new Geom_Parabola(gp_Parab());
00880     this->myCurve = p;
00881 }
00882 
00883 GeomParabola::GeomParabola(const Handle_Geom_Parabola& p)
00884 {
00885     this->myCurve = Handle_Geom_Parabola::DownCast(p->Copy());
00886 }
00887 
00888 GeomParabola::~GeomParabola()
00889 {
00890 }
00891 
00892 const Handle_Geom_Geometry& GeomParabola::handle() const
00893 {
00894     return myCurve;
00895 }
00896 
00897 Geometry *GeomParabola::clone(void) const
00898 {
00899     GeomParabola *newPar = new GeomParabola(myCurve);
00900     newPar->Construction = this->Construction;
00901     return newPar;
00902 }
00903 
00904 // Persistence implementer 
00905 unsigned int GeomParabola::getMemSize (void) const               {assert(0); return 0;/* not implemented yet */}
00906 void         GeomParabola::Save       (Base::Writer &/*writer*/) const {assert(0);          /* not implemented yet */}
00907 void         GeomParabola::Restore    (Base::XMLReader &/*reader*/)    {assert(0);          /* not implemented yet */}
00908 
00909 PyObject *GeomParabola::getPyObject(void)
00910 {
00911     return new ParabolaPy((GeomParabola*)this->clone());
00912 }
00913 
00914 // -------------------------------------------------
00915 
00916 TYPESYSTEM_SOURCE(Part::GeomLine,Part::GeomCurve);
00917 
00918 GeomLine::GeomLine()
00919 {
00920     Handle_Geom_Line c = new Geom_Line(gp_Lin());
00921     this->myCurve = c;
00922 }
00923 
00924 GeomLine::GeomLine(const Handle_Geom_Line& l)
00925 {
00926     this->myCurve = Handle_Geom_Line::DownCast(l->Copy());
00927 }
00928 
00929 GeomLine::GeomLine(const Base::Vector3d& Pos, const Base::Vector3d& Dir)
00930 {
00931     this->myCurve = new Geom_Line(gp_Pnt(Pos.x,Pos.y,Pos.z),gp_Dir(Dir.x,Dir.y,Dir.z));
00932 }
00933 
00934 
00935 GeomLine::~GeomLine()
00936 {
00937 }
00938 
00939 void GeomLine::setLine(const Base::Vector3d& Pos, const Base::Vector3d& Dir)
00940 {
00941     this->myCurve->SetLocation(gp_Pnt(Pos.x,Pos.y,Pos.z));
00942     this->myCurve->SetDirection(gp_Dir(Dir.x,Dir.y,Dir.z));
00943 }
00944 
00945 Base::Vector3d GeomLine::getPos(void) const
00946 {
00947     gp_Pnt Pos = this->myCurve->Lin().Location();
00948     return Base::Vector3d(Pos.X(),Pos.Y(),Pos.Z());
00949 }
00950 
00951 Base::Vector3d GeomLine::getDir(void) const
00952 {
00953     gp_Dir Dir = this->myCurve->Lin().Direction();
00954     return Base::Vector3d(Dir.X(),Dir.Y(),Dir.Z());
00955 }
00956 
00957 const Handle_Geom_Geometry& GeomLine::handle() const
00958 {
00959     return myCurve;
00960 }
00961 
00962 Geometry *GeomLine::clone(void) const
00963 {
00964     GeomLine *newLine = new GeomLine(myCurve);
00965     newLine->Construction = this->Construction;
00966     return newLine;
00967 }
00968 
00969 // Persistence implementer 
00970 unsigned int GeomLine::getMemSize (void) const 
00971 {
00972     return sizeof(Geom_Line);
00973 }
00974 
00975 void GeomLine::Save(Base::Writer &writer) const 
00976 {
00977     // save the attributes of the father class
00978     Geometry::Save(writer);
00979 
00980     Base::Vector3d Pos   =  getPos();
00981     Base::Vector3d Dir   =  getDir();
00982 
00983     writer.Stream() 
00984          << writer.ind() 
00985              << "<GeomLine " 
00986                 << "PosX=\"" <<  Pos.x << 
00987                 "\" PosY=\"" <<  Pos.y << 
00988                 "\" PosZ=\"" <<  Pos.z << 
00989                 "\" DirX=\"" <<  Dir.x << 
00990                 "\" DirY=\"" <<  Dir.y << 
00991                 "\" DirZ=\"" <<  Dir.z <<
00992              "\"/>" << endl;
00993 }
00994 void GeomLine::Restore(Base::XMLReader &reader)
00995 {
00996     // read the attributes of the father class
00997     Geometry::Restore(reader);
00998 
00999     double PosX,PosY,PosZ,DirX,DirY,DirZ;
01000     // read my Element
01001     reader.readElement("GeomLine");
01002     // get the value of my Attribute
01003     PosX = reader.getAttributeAsFloat("PosX");
01004     PosY = reader.getAttributeAsFloat("PosY");
01005     PosZ = reader.getAttributeAsFloat("PosZ");
01006     DirX = reader.getAttributeAsFloat("DirX");
01007     DirY = reader.getAttributeAsFloat("DirY");
01008     DirZ = reader.getAttributeAsFloat("DirZ");
01009  
01010     // set the read geometry
01011     setLine(Base::Vector3d(PosX,PosY,PosZ),Base::Vector3d(DirX,DirY,DirZ) );
01012 }
01013 
01014 PyObject *GeomLine::getPyObject(void)
01015 {
01016     return 0;
01017 }
01018 
01019 // -------------------------------------------------
01020 
01021 TYPESYSTEM_SOURCE(Part::GeomLineSegment,Part::GeomCurve);
01022 
01023 GeomLineSegment::GeomLineSegment()
01024 {
01025     gp_Lin line;
01026     line.SetLocation(gp_Pnt(0.0,0.0,0.0));
01027     line.SetDirection(gp_Dir(0.0,0.0,1.0));
01028     Handle_Geom_Line c = new Geom_Line(line);
01029     this->myCurve = new Geom_TrimmedCurve(c, 0.0,1.0);
01030 }
01031 
01032 GeomLineSegment::~GeomLineSegment()
01033 {
01034 }
01035 
01036 void GeomLineSegment::setHandle(const Handle_Geom_TrimmedCurve& c)
01037 {
01038     Handle_Geom_Line basis = Handle_Geom_Line::DownCast(c->BasisCurve());
01039     if (basis.IsNull())
01040         Standard_Failure::Raise("Basis curve is not a line");
01041     this->myCurve = Handle_Geom_TrimmedCurve::DownCast(c->Copy());
01042 }
01043 
01044 const Handle_Geom_Geometry& GeomLineSegment::handle() const
01045 {
01046     return myCurve;
01047 }
01048 
01049 Geometry *GeomLineSegment::clone(void)const
01050 {
01051     GeomLineSegment *tempCurve = new GeomLineSegment();
01052     tempCurve->myCurve = Handle_Geom_TrimmedCurve::DownCast(myCurve->Copy());
01053     tempCurve->Construction = this->Construction;
01054     return tempCurve;
01055 }
01056 
01057 Base::Vector3d GeomLineSegment::getStartPoint() const
01058 {
01059     Handle_Geom_TrimmedCurve this_curve = Handle_Geom_TrimmedCurve::DownCast(handle());
01060     gp_Pnt pnt = this_curve->StartPoint();
01061     return Base::Vector3d(pnt.X(), pnt.Y(), pnt.Z());
01062 }
01063 
01064 Base::Vector3d GeomLineSegment::getEndPoint() const
01065 {
01066     Handle_Geom_TrimmedCurve this_curve = Handle_Geom_TrimmedCurve::DownCast(handle());
01067     gp_Pnt pnt = this_curve->EndPoint();
01068     return Base::Vector3d(pnt.X(), pnt.Y(), pnt.Z());
01069 }
01070 
01071 void GeomLineSegment::setPoints(const Base::Vector3d& Start, const Base::Vector3d& End)
01072 {
01073     gp_Pnt p1(Start.x,Start.y,Start.z), p2(End.x,End.y,End.z);
01074     Handle_Geom_TrimmedCurve this_curv = Handle_Geom_TrimmedCurve::DownCast(handle());
01075 
01076     try {
01077         // Create line out of two points
01078         if (p1.Distance(p2) < Precision::Confusion()) Standard_Failure::Raise("Both points are equal");
01079         GC_MakeSegment ms(p1, p2);
01080         if (!ms.IsDone()) {
01081             throw Base::Exception(gce_ErrorStatusText(ms.Status()));
01082         }
01083 
01084         // get Geom_Line of line segment
01085         Handle_Geom_Line this_line = Handle_Geom_Line::DownCast
01086             (this_curv->BasisCurve());
01087         Handle_Geom_TrimmedCurve that_curv = ms.Value();
01088         Handle_Geom_Line that_line = Handle_Geom_Line::DownCast(that_curv->BasisCurve());
01089         this_line->SetLin(that_line->Lin());
01090         this_curv->SetTrim(that_curv->FirstParameter(), that_curv->LastParameter());
01091     }
01092     catch (Standard_Failure) {
01093         Handle_Standard_Failure e = Standard_Failure::Caught();
01094         throw Base::Exception(e->GetMessageString());
01095     }
01096 }
01097 
01098 // Persistence implementer 
01099 unsigned int GeomLineSegment::getMemSize (void) const               {assert(0); return 0;/* not implemented yet */}
01100 void GeomLineSegment::Save       (Base::Writer &writer) const 
01101 {
01102     // save the attributes of the father class
01103     Geometry::Save(writer);
01104 
01105     Base::Vector3d End   =  getEndPoint();
01106     Base::Vector3d Start =  getStartPoint();
01107 
01108     writer.Stream() 
01109          << writer.ind() 
01110              << "<LineSegment " 
01111                 << "StartX=\"" <<  Start.x << 
01112                 "\" StartY=\"" <<  Start.y << 
01113                 "\" StartZ=\"" <<  Start.z << 
01114                 "\" EndX=\"" <<  End.x << 
01115                 "\" EndY=\"" <<  End.y << 
01116                 "\" EndZ=\"" <<  End.z <<
01117              "\"/>" << endl;
01118 }
01119 
01120 void GeomLineSegment::Restore    (Base::XMLReader &reader)    
01121 {
01122     // read the attributes of the father class
01123     Geometry::Restore(reader);
01124 
01125     double StartX,StartY,StartZ,EndX,EndY,EndZ;
01126     // read my Element
01127     reader.readElement("LineSegment");
01128     // get the value of my Attribute
01129     StartX = reader.getAttributeAsFloat("StartX");
01130     StartY = reader.getAttributeAsFloat("StartY");
01131     StartZ = reader.getAttributeAsFloat("StartZ");
01132     EndX   = reader.getAttributeAsFloat("EndX");
01133     EndY   = reader.getAttributeAsFloat("EndY");
01134     EndZ   = reader.getAttributeAsFloat("EndZ");
01135  
01136     // set the read geometry
01137     setPoints(Base::Vector3d(StartX,StartY,StartZ),Base::Vector3d(EndX,EndY,EndZ) );
01138 }
01139 
01140 PyObject *GeomLineSegment::getPyObject(void)
01141 {
01142     return new LinePy((GeomLineSegment*)this->clone());
01143 }
01144 
01145 // -------------------------------------------------
01146 
01147 TYPESYSTEM_SOURCE(Part::GeomOffsetCurve,Part::GeomCurve);
01148 
01149 GeomOffsetCurve::GeomOffsetCurve()
01150 {
01151 }
01152 
01153 GeomOffsetCurve::GeomOffsetCurve(const Handle_Geom_Curve& c, double offset, const gp_Dir& dir)
01154 {
01155     this->myCurve = new Geom_OffsetCurve(c, offset, dir);
01156 }
01157 
01158 GeomOffsetCurve::GeomOffsetCurve(const Handle_Geom_OffsetCurve& c)
01159 {
01160     this->myCurve = Handle_Geom_OffsetCurve::DownCast(c->Copy());
01161 }
01162 
01163 GeomOffsetCurve::~GeomOffsetCurve()
01164 {
01165 }
01166 
01167 Geometry *GeomOffsetCurve::clone(void) const
01168 {
01169     GeomOffsetCurve *newCurve = new GeomOffsetCurve(myCurve);
01170     newCurve->Construction = this->Construction;
01171     return newCurve;
01172 }
01173 
01174 void GeomOffsetCurve::setHandle(const Handle_Geom_OffsetCurve& c)
01175 {
01176     this->myCurve = Handle_Geom_OffsetCurve::DownCast(c->Copy());
01177 }
01178 
01179 const Handle_Geom_Geometry& GeomOffsetCurve::handle() const
01180 {
01181     return this->myCurve;
01182 }
01183 
01184 // Persistence implementer 
01185 unsigned int GeomOffsetCurve::getMemSize (void) const               {assert(0); return 0;/* not implemented yet */}
01186 void         GeomOffsetCurve::Save       (Base::Writer &/*writer*/) const {assert(0);          /* not implemented yet */}
01187 void         GeomOffsetCurve::Restore    (Base::XMLReader &/*reader*/)    {assert(0);          /* not implemented yet */}
01188 
01189 PyObject *GeomOffsetCurve::getPyObject(void)
01190 {
01191     return new OffsetCurvePy((GeomOffsetCurve*)this->clone());
01192 }
01193 
01194 // -------------------------------------------------
01195 
01196 TYPESYSTEM_SOURCE(Part::GeomTrimmedCurve,Part::GeomCurve);
01197 
01198 GeomTrimmedCurve::GeomTrimmedCurve()
01199 {
01200 }
01201 
01202 GeomTrimmedCurve::GeomTrimmedCurve(const Handle_Geom_TrimmedCurve& c)
01203 {
01204     this->myCurve = Handle_Geom_TrimmedCurve::DownCast(c->Copy());
01205 }
01206 
01207 GeomTrimmedCurve::~GeomTrimmedCurve()
01208 {
01209 }
01210 
01211 void GeomTrimmedCurve::setHandle(const Handle_Geom_TrimmedCurve& c)
01212 {
01213     this->myCurve = Handle_Geom_TrimmedCurve::DownCast(c->Copy());
01214 }
01215 
01216 const Handle_Geom_Geometry& GeomTrimmedCurve::handle() const
01217 {
01218     return myCurve;
01219 }
01220 
01221 Geometry *GeomTrimmedCurve::clone(void) const
01222 {
01223     GeomTrimmedCurve *newCurve =  new GeomTrimmedCurve(myCurve);
01224     newCurve->Construction = this->Construction;
01225     return newCurve;
01226 }
01227 
01228 // Persistence implementer 
01229 unsigned int GeomTrimmedCurve::getMemSize (void) const               {assert(0); return 0;/* not implemented yet */}
01230 void         GeomTrimmedCurve::Save       (Base::Writer &/*writer*/) const {assert(0);          /* not implemented yet */}
01231 void         GeomTrimmedCurve::Restore    (Base::XMLReader &/*reader*/)    {assert(0);          /* not implemented yet */}
01232 
01233 PyObject *GeomTrimmedCurve::getPyObject(void)
01234 {
01235     return 0;
01236 }
01237 
01238 // -------------------------------------------------
01239 
01240 TYPESYSTEM_SOURCE_ABSTRACT(Part::GeomSurface,Part::Geometry);
01241 
01242 GeomSurface::GeomSurface()
01243 {
01244 }
01245 
01246 GeomSurface::~GeomSurface()
01247 {
01248 }
01249 
01250 TopoDS_Shape GeomSurface::toShape() const
01251 {
01252     Handle_Geom_Surface s = Handle_Geom_Surface::DownCast(handle());
01253     Standard_Real u1,u2,v1,v2;
01254     s->Bounds(u1,u2,v1,v2);
01255     BRepBuilderAPI_MakeFace mkBuilder(s, u1, u2, v1, v2);
01256     return mkBuilder.Shape();
01257 }
01258 
01259 bool GeomSurface::tangentU(double u, double v, gp_Dir& dirU) const
01260 {
01261     Handle_Geom_Surface s = Handle_Geom_Surface::DownCast(handle());
01262     GeomLProp_SLProps prop(s,u,v,1,Precision::Confusion());
01263     if (prop.IsTangentUDefined()) {
01264         prop.TangentU(dirU);
01265         return true;
01266     }
01267 
01268     return false;
01269 }
01270 
01271 bool GeomSurface::tangentV(double u, double v, gp_Dir& dirV) const
01272 {
01273     Handle_Geom_Surface s = Handle_Geom_Surface::DownCast(handle());
01274     GeomLProp_SLProps prop(s,u,v,1,Precision::Confusion());
01275     if (prop.IsTangentVDefined()) {
01276         prop.TangentV(dirV);
01277         return true;
01278     }
01279 
01280     return false;
01281 }
01282 
01283 // -------------------------------------------------
01284 
01285 TYPESYSTEM_SOURCE(Part::GeomBezierSurface,Part::GeomSurface);
01286 
01287 GeomBezierSurface::GeomBezierSurface()
01288 {
01289     TColgp_Array2OfPnt poles(1,2,1,2);
01290     poles(1,1) = gp_Pnt(0.0,0.0,0.0);
01291     poles(2,1) = gp_Pnt(1.0,0.0,0.0);
01292     poles(1,2) = gp_Pnt(0.0,1.0,0.0);
01293     poles(2,2) = gp_Pnt(1.0,1.0,0.0);
01294     this->mySurface = new Geom_BezierSurface(poles);
01295 }
01296 
01297 GeomBezierSurface::GeomBezierSurface(const Handle_Geom_BezierSurface& b)
01298 {
01299     this->mySurface = Handle_Geom_BezierSurface::DownCast(b->Copy());
01300 }
01301 
01302 GeomBezierSurface::~GeomBezierSurface()
01303 {
01304 }
01305 
01306 const Handle_Geom_Geometry& GeomBezierSurface::handle() const
01307 {
01308     return mySurface;
01309 }
01310 
01311 Geometry *GeomBezierSurface::clone(void) const
01312 {
01313     GeomBezierSurface *newSurf =  new GeomBezierSurface(mySurface);
01314     newSurf->Construction = this->Construction;
01315     return newSurf;
01316 }
01317 
01318 // Persistence implementer 
01319 unsigned int GeomBezierSurface::getMemSize (void) const               {assert(0); return 0;/* not implemented yet */}
01320 void         GeomBezierSurface::Save       (Base::Writer &/*writer*/) const {assert(0);          /* not implemented yet */}
01321 void         GeomBezierSurface::Restore    (Base::XMLReader &/*reader*/)    {assert(0);          /* not implemented yet */}
01322 
01323 PyObject *GeomBezierSurface::getPyObject(void)
01324 {
01325     return new BezierSurfacePy((GeomBezierSurface*)this->clone());
01326 }
01327 
01328 // -------------------------------------------------
01329 
01330 TYPESYSTEM_SOURCE(Part::GeomBSplineSurface,Part::GeomSurface);
01331 
01332 GeomBSplineSurface::GeomBSplineSurface()
01333 {
01334     TColgp_Array2OfPnt poles(1,2,1,2);
01335     poles(1,1) = gp_Pnt(0.0,0.0,0.0);
01336     poles(2,1) = gp_Pnt(1.0,0.0,0.0);
01337     poles(1,2) = gp_Pnt(0.0,1.0,0.0);
01338     poles(2,2) = gp_Pnt(1.0,1.0,0.0);
01339 
01340     TColStd_Array1OfReal knots(1,2);
01341     knots(1) = 0.0;
01342     knots(2) = 1.0;
01343 
01344     TColStd_Array1OfInteger mults(1,2);
01345     mults(1) = 2;
01346     mults(2) = 2;
01347 
01348     this->mySurface = new Geom_BSplineSurface(poles, knots, knots, mults, mults, 1, 1);
01349 }
01350 
01351 GeomBSplineSurface::GeomBSplineSurface(const Handle_Geom_BSplineSurface& b)
01352 {
01353     this->mySurface = Handle_Geom_BSplineSurface::DownCast(b->Copy());
01354 }
01355 
01356 GeomBSplineSurface::~GeomBSplineSurface()
01357 {
01358 }
01359 
01360 const Handle_Geom_Geometry& GeomBSplineSurface::handle() const
01361 {
01362     return mySurface;
01363 }
01364 
01365 Geometry *GeomBSplineSurface::clone(void) const
01366 {
01367     GeomBSplineSurface *newSurf =  new GeomBSplineSurface(mySurface);
01368     newSurf->Construction = this->Construction;
01369     return newSurf;
01370 }
01371 
01372 // Persistence implementer 
01373 unsigned int GeomBSplineSurface::getMemSize (void) const               {assert(0); return 0;/* not implemented yet */}
01374 void         GeomBSplineSurface::Save       (Base::Writer &/*writer*/) const {assert(0);          /* not implemented yet */}
01375 void         GeomBSplineSurface::Restore    (Base::XMLReader &/*reader*/)    {assert(0);          /* not implemented yet */}
01376 
01377 PyObject *GeomBSplineSurface::getPyObject(void)
01378 {
01379     return new BSplineSurfacePy((GeomBSplineSurface*)this->clone());
01380 }
01381 
01382 // -------------------------------------------------
01383 
01384 TYPESYSTEM_SOURCE(Part::GeomCylinder,Part::GeomSurface);
01385 
01386 GeomCylinder::GeomCylinder()
01387 {
01388     Handle_Geom_CylindricalSurface s = new Geom_CylindricalSurface(gp_Cylinder());
01389     this->mySurface = s;
01390 }
01391 
01392 GeomCylinder::~GeomCylinder()
01393 {
01394 }
01395 
01396 const Handle_Geom_Geometry& GeomCylinder::handle() const
01397 {
01398     return mySurface;
01399 }
01400 
01401 Geometry *GeomCylinder::clone(void) const
01402 {
01403     GeomCylinder *tempCurve = new GeomCylinder();
01404     tempCurve->mySurface = Handle_Geom_CylindricalSurface::DownCast(mySurface->Copy());
01405     tempCurve->Construction = this->Construction;
01406     return tempCurve;
01407 }
01408 
01409 // Persistence implementer 
01410 unsigned int GeomCylinder::getMemSize (void) const               {assert(0); return 0;/* not implemented yet */}
01411 void         GeomCylinder::Save       (Base::Writer &/*writer*/) const {assert(0);          /* not implemented yet */}
01412 void         GeomCylinder::Restore    (Base::XMLReader &/*reader*/)    {assert(0);          /* not implemented yet */}
01413 
01414 PyObject *GeomCylinder::getPyObject(void)
01415 {
01416     return new CylinderPy((GeomCylinder*)this->clone());
01417 }
01418 
01419 // -------------------------------------------------
01420 
01421 TYPESYSTEM_SOURCE(Part::GeomCone,Part::GeomSurface);
01422 
01423 GeomCone::GeomCone()
01424 {
01425     Handle_Geom_ConicalSurface s = new Geom_ConicalSurface(gp_Cone());
01426     this->mySurface = s;
01427 }
01428 
01429 GeomCone::~GeomCone()
01430 {
01431 }
01432 
01433 const Handle_Geom_Geometry& GeomCone::handle() const
01434 {
01435     return mySurface;
01436 }
01437 
01438 Geometry *GeomCone::clone(void) const
01439 {
01440     GeomCone *tempCurve = new GeomCone();
01441     tempCurve->mySurface = Handle_Geom_ConicalSurface::DownCast(mySurface->Copy());
01442     tempCurve->Construction = this->Construction;
01443     return tempCurve;
01444 }
01445 
01446 // Persistence implementer 
01447 unsigned int GeomCone::getMemSize (void) const               {assert(0); return 0;/* not implemented yet */}
01448 void         GeomCone::Save       (Base::Writer &/*writer*/) const {assert(0);          /* not implemented yet */}
01449 void         GeomCone::Restore    (Base::XMLReader &/*reader*/)    {assert(0);          /* not implemented yet */}
01450 
01451 PyObject *GeomCone::getPyObject(void)
01452 {
01453     return new ConePy((GeomCone*)this->clone());
01454 }
01455 
01456 // -------------------------------------------------
01457 
01458 TYPESYSTEM_SOURCE(Part::GeomToroid,Part::GeomSurface);
01459 
01460 GeomToroid::GeomToroid()
01461 {
01462     Handle_Geom_ToroidalSurface s = new Geom_ToroidalSurface(gp_Torus());
01463     this->mySurface = s;
01464 }
01465 
01466 GeomToroid::~GeomToroid()
01467 {
01468 }
01469 
01470 const Handle_Geom_Geometry& GeomToroid::handle() const
01471 {
01472     return mySurface;
01473 }
01474 
01475 Geometry *GeomToroid::clone(void) const
01476 {
01477     GeomToroid *tempCurve = new GeomToroid();
01478     tempCurve->mySurface = Handle_Geom_ToroidalSurface::DownCast(mySurface->Copy());
01479     tempCurve->Construction = this->Construction;
01480     return tempCurve;
01481 }
01482 
01483 // Persistence implementer 
01484 unsigned int GeomToroid::getMemSize (void) const               {assert(0); return 0;/* not implemented yet */}
01485 void         GeomToroid::Save       (Base::Writer &/*writer*/) const {assert(0);          /* not implemented yet */}
01486 void         GeomToroid::Restore    (Base::XMLReader &/*reader*/)    {assert(0);          /* not implemented yet */}
01487 
01488 PyObject *GeomToroid::getPyObject(void)
01489 {
01490     return new ToroidPy((GeomToroid*)this->clone());
01491 }
01492 
01493 // -------------------------------------------------
01494 
01495 TYPESYSTEM_SOURCE(Part::GeomSphere,Part::GeomSurface);
01496 
01497 GeomSphere::GeomSphere()
01498 {
01499     Handle_Geom_SphericalSurface s = new Geom_SphericalSurface(gp_Sphere());
01500     this->mySurface = s;
01501 }
01502 
01503 GeomSphere::~GeomSphere()
01504 {
01505 }
01506 
01507 const Handle_Geom_Geometry& GeomSphere::handle() const
01508 {
01509     return mySurface;
01510 }
01511 
01512 Geometry *GeomSphere::clone(void) const
01513 {
01514     GeomSphere *tempCurve = new GeomSphere();
01515     tempCurve->mySurface = Handle_Geom_SphericalSurface::DownCast(mySurface->Copy());
01516     tempCurve->Construction = this->Construction;
01517     return tempCurve;
01518 }
01519 
01520 // Persistence implementer 
01521 unsigned int GeomSphere::getMemSize (void) const               {assert(0); return 0;/* not implemented yet */}
01522 void         GeomSphere::Save       (Base::Writer &/*writer*/) const {assert(0);          /* not implemented yet */}
01523 void         GeomSphere::Restore    (Base::XMLReader &/*reader*/)    {assert(0);          /* not implemented yet */}
01524 
01525 PyObject *GeomSphere::getPyObject(void)
01526 {
01527     return new SpherePy((GeomSphere*)this->clone());
01528 }
01529 
01530 // -------------------------------------------------
01531 
01532 TYPESYSTEM_SOURCE(Part::GeomPlane,Part::GeomSurface);
01533 
01534 GeomPlane::GeomPlane()
01535 {
01536     Handle_Geom_Plane s = new Geom_Plane(gp_Pln());
01537     this->mySurface = s;
01538 }
01539 
01540 GeomPlane::~GeomPlane()
01541 {
01542 }
01543 
01544 const Handle_Geom_Geometry& GeomPlane::handle() const
01545 {
01546     return mySurface;
01547 }
01548 
01549 Geometry *GeomPlane::clone(void) const
01550 {
01551     GeomPlane *tempCurve = new GeomPlane();
01552     tempCurve->mySurface = Handle_Geom_Plane::DownCast(mySurface->Copy());
01553     tempCurve->Construction = this->Construction;
01554     return tempCurve;
01555 }
01556 
01557 // Persistence implementer 
01558 unsigned int GeomPlane::getMemSize (void) const               {assert(0); return 0;/* not implemented yet */}
01559 void         GeomPlane::Save       (Base::Writer &/*writer*/) const {assert(0);          /* not implemented yet */}
01560 void         GeomPlane::Restore    (Base::XMLReader &/*reader*/)    {assert(0);          /* not implemented yet */}
01561 
01562 PyObject *GeomPlane::getPyObject(void)
01563 {
01564     return new PlanePy((GeomPlane*)this->clone());
01565 }
01566 // -------------------------------------------------
01567 
01568 TYPESYSTEM_SOURCE(Part::GeomOffsetSurface,Part::GeomSurface);
01569 
01570 GeomOffsetSurface::GeomOffsetSurface()
01571 {
01572 }
01573 
01574 GeomOffsetSurface::GeomOffsetSurface(const Handle_Geom_Surface& s, double offset)
01575 {
01576     this->mySurface = new Geom_OffsetSurface(s, offset);
01577 }
01578 
01579 GeomOffsetSurface::GeomOffsetSurface(const Handle_Geom_OffsetSurface& s)
01580 {
01581     this->mySurface = Handle_Geom_OffsetSurface::DownCast(s->Copy());
01582 }
01583 
01584 GeomOffsetSurface::~GeomOffsetSurface()
01585 {
01586 }
01587 
01588 void GeomOffsetSurface::setHandle(const Handle_Geom_OffsetSurface& s)
01589 {
01590     mySurface = Handle_Geom_OffsetSurface::DownCast(s->Copy());
01591 }
01592 
01593 const Handle_Geom_Geometry& GeomOffsetSurface::handle() const
01594 {
01595     return mySurface;
01596 }
01597 
01598 Geometry *GeomOffsetSurface::clone(void) const
01599 {
01600     GeomOffsetSurface *newSurf = new GeomOffsetSurface(mySurface);
01601     newSurf->Construction = this->Construction;
01602     return newSurf;
01603 }
01604 
01605 // Persistence implementer 
01606 unsigned int GeomOffsetSurface::getMemSize (void) const               {assert(0); return 0;/* not implemented yet */}
01607 void         GeomOffsetSurface::Save       (Base::Writer &/*writer*/) const {assert(0);          /* not implemented yet */}
01608 void         GeomOffsetSurface::Restore    (Base::XMLReader &/*reader*/)    {assert(0);          /* not implemented yet */}
01609 
01610 PyObject *GeomOffsetSurface::getPyObject(void)
01611 {
01612     return new OffsetSurfacePy((GeomOffsetSurface*)this->clone());
01613 }
01614 
01615 // -------------------------------------------------
01616 
01617 TYPESYSTEM_SOURCE(Part::GeomTrimmedSurface,Part::GeomSurface);
01618 
01619 GeomTrimmedSurface::GeomTrimmedSurface()
01620 {
01621 }
01622 
01623 GeomTrimmedSurface::GeomTrimmedSurface(const Handle_Geom_RectangularTrimmedSurface& s)
01624 {
01625     this->mySurface = Handle_Geom_RectangularTrimmedSurface::DownCast(s->Copy());
01626 }
01627 
01628 GeomTrimmedSurface::~GeomTrimmedSurface()
01629 {
01630 }
01631 
01632 void GeomTrimmedSurface::setHandle(const Handle_Geom_RectangularTrimmedSurface& s)
01633 {
01634     mySurface = Handle_Geom_RectangularTrimmedSurface::DownCast(s->Copy());
01635 }
01636 
01637 const Handle_Geom_Geometry& GeomTrimmedSurface::handle() const
01638 {
01639     return mySurface;
01640 }
01641 
01642 Geometry *GeomTrimmedSurface::clone(void) const
01643 {
01644     GeomTrimmedSurface *newSurf = new GeomTrimmedSurface(mySurface);
01645     newSurf->Construction = this->Construction;
01646     return newSurf;
01647 }
01648 
01649 // Persistence implementer 
01650 unsigned int GeomTrimmedSurface::getMemSize (void) const {assert(0); return 0;/* not implemented yet */}
01651 void         GeomTrimmedSurface::Save       (Base::Writer &/*writer*/) const {assert(0);          /* not implemented yet */}
01652 void         GeomTrimmedSurface::Restore    (Base::XMLReader &/*reader*/)    {assert(0);          /* not implemented yet */}
01653 
01654 PyObject *GeomTrimmedSurface::getPyObject(void)
01655 {
01656     return 0;
01657 }
01658 
01659 // -------------------------------------------------
01660 
01661 TYPESYSTEM_SOURCE(Part::GeomSurfaceOfRevolution,Part::GeomSurface);
01662 
01663 GeomSurfaceOfRevolution::GeomSurfaceOfRevolution()
01664 {
01665 }
01666 
01667 GeomSurfaceOfRevolution::GeomSurfaceOfRevolution(const Handle_Geom_Curve& c, const gp_Ax1& a)
01668 {
01669     this->mySurface = new Geom_SurfaceOfRevolution(c,a);
01670 }
01671 
01672 GeomSurfaceOfRevolution::GeomSurfaceOfRevolution(const Handle_Geom_SurfaceOfRevolution& s)
01673 {
01674     this->mySurface = Handle_Geom_SurfaceOfRevolution::DownCast(s->Copy());
01675 }
01676 
01677 GeomSurfaceOfRevolution::~GeomSurfaceOfRevolution()
01678 {
01679 }
01680 
01681 void GeomSurfaceOfRevolution::setHandle(const Handle_Geom_SurfaceOfRevolution& c)
01682 {
01683     mySurface = Handle_Geom_SurfaceOfRevolution::DownCast(c->Copy());
01684 }
01685 
01686 const Handle_Geom_Geometry& GeomSurfaceOfRevolution::handle() const
01687 {
01688     return mySurface;
01689 }
01690 
01691 Geometry *GeomSurfaceOfRevolution::clone(void) const
01692 {
01693     GeomSurfaceOfRevolution *newSurf = new GeomSurfaceOfRevolution(mySurface);
01694     newSurf->Construction = this->Construction;
01695     return newSurf;
01696 }
01697 
01698 // Persistence implementer 
01699 unsigned int GeomSurfaceOfRevolution::getMemSize (void) const               {assert(0); return 0;/* not implemented yet */}
01700 void         GeomSurfaceOfRevolution::Save       (Base::Writer &/*writer*/) const {assert(0);          /* not implemented yet */}
01701 void         GeomSurfaceOfRevolution::Restore    (Base::XMLReader &/*reader*/)    {assert(0);          /* not implemented yet */}
01702 
01703 PyObject *GeomSurfaceOfRevolution::getPyObject(void)
01704 {
01705     return new SurfaceOfRevolutionPy((GeomSurfaceOfRevolution*)this->clone());
01706 }
01707 
01708 // -------------------------------------------------
01709 
01710 TYPESYSTEM_SOURCE(Part::GeomSurfaceOfExtrusion,Part::GeomSurface);
01711 
01712 GeomSurfaceOfExtrusion::GeomSurfaceOfExtrusion()
01713 {
01714 }
01715 
01716 GeomSurfaceOfExtrusion::GeomSurfaceOfExtrusion(const Handle_Geom_Curve& c, const gp_Dir& d)
01717 {
01718     this->mySurface = new Geom_SurfaceOfLinearExtrusion(c,d);
01719 }
01720 
01721 GeomSurfaceOfExtrusion::GeomSurfaceOfExtrusion(const Handle_Geom_SurfaceOfLinearExtrusion& s)
01722 {
01723     this->mySurface = Handle_Geom_SurfaceOfLinearExtrusion::DownCast(s->Copy());
01724 }
01725 
01726 GeomSurfaceOfExtrusion::~GeomSurfaceOfExtrusion()
01727 {
01728 }
01729 
01730 void GeomSurfaceOfExtrusion::setHandle(const Handle_Geom_SurfaceOfLinearExtrusion& c)
01731 {
01732     mySurface = Handle_Geom_SurfaceOfLinearExtrusion::DownCast(c->Copy());
01733 }
01734 
01735 const Handle_Geom_Geometry& GeomSurfaceOfExtrusion::handle() const
01736 {
01737     return mySurface;
01738 }
01739 
01740 Geometry *GeomSurfaceOfExtrusion::clone(void) const
01741 {
01742     GeomSurfaceOfExtrusion *newSurf = new GeomSurfaceOfExtrusion(mySurface);
01743     newSurf->Construction = this->Construction;
01744     return newSurf;
01745 }
01746 
01747 // Persistence implementer 
01748 unsigned int GeomSurfaceOfExtrusion::getMemSize (void) const               {assert(0); return 0;/* not implemented yet */}
01749 void         GeomSurfaceOfExtrusion::Save       (Base::Writer &/*writer*/) const {assert(0);          /* not implemented yet */}
01750 void         GeomSurfaceOfExtrusion::Restore    (Base::XMLReader &/*reader*/)    {assert(0);          /* not implemented yet */}
01751 
01752 PyObject *GeomSurfaceOfExtrusion::getPyObject(void)
01753 {
01754     return new SurfaceOfExtrusionPy((GeomSurfaceOfExtrusion*)this->clone());
01755 }
01756 
01757 
01758 // Helper functions for fillet tools
01759 // -------------------------------------------------
01760 namespace Part {
01761 
01762 bool find2DLinesIntersection(const Base::Vector3d &orig1, const Base::Vector3d &dir1,
01763                              const Base::Vector3d &orig2, const Base::Vector3d &dir2,
01764                              Base::Vector3d &point)
01765 {
01766     double det = dir1.x*dir2.y - dir1.y*dir2.x;
01767     if ((det > 0 ? det : -det) < 1e-10)
01768         return false;
01769     double c1 = dir1.y*orig1.x - dir1.x*orig1.y;
01770     double c2 = dir2.y*orig2.x - dir2.x*orig2.y;
01771     double x = (dir1.x*c2 - dir2.x*c1)/det;
01772     double y = (dir1.y*c2 - dir2.y*c1)/det;
01773     point = Base::Vector3d(x,y,0.f);
01774     return true;
01775 }
01776 
01777 bool find2DLinesIntersection(const GeomLineSegment *lineSeg1, const GeomLineSegment *lineSeg2,
01778                              Base::Vector3d &point)
01779 {
01780     Base::Vector3d orig1 = lineSeg1->getStartPoint();
01781     Base::Vector3d orig2 = lineSeg2->getStartPoint();
01782     Base::Vector3d dir1 = (lineSeg1->getEndPoint()-lineSeg1->getStartPoint());
01783     Base::Vector3d dir2 = (lineSeg2->getEndPoint()-lineSeg2->getStartPoint());
01784     return find2DLinesIntersection(orig1, dir1, orig2, dir2, point);
01785 }
01786 
01787 bool findFilletCenter(const GeomLineSegment *lineSeg1, const GeomLineSegment *lineSeg2, double radius,
01788                       Base::Vector3d &center)
01789 {
01790     Base::Vector3d midPoint1 = (lineSeg1->getStartPoint()+lineSeg1->getEndPoint())/2;
01791     Base::Vector3d midPoint2 = (lineSeg2->getStartPoint()+lineSeg2->getEndPoint())/2;
01792     return findFilletCenter(lineSeg1, lineSeg2, radius, midPoint1, midPoint2, center);
01793 }
01794 
01795 bool findFilletCenter(const GeomLineSegment *lineSeg1, const GeomLineSegment *lineSeg2, double radius,
01796                       const Base::Vector3d &refPnt1, const Base::Vector3d &refPnt2, Base::Vector3d &center)
01797 {
01798     //Calculate directions and normals for each straight line
01799     Base::Vector3d l1p1, l1p2, l2p1, l2p2, dir1, dir2, norm1, norm2;
01800     l1p1 = lineSeg1->getStartPoint();
01801     l1p2 = lineSeg1->getEndPoint();
01802     l2p1 = lineSeg2->getStartPoint();
01803     l2p2 = lineSeg2->getEndPoint();
01804 
01805     dir1 = (l1p1 - l1p2).Normalize();
01806     dir2 = (l2p1 - l2p2).Normalize();
01807 
01808     norm1 = Base::Vector3d(dir1.y, -dir1.x, 0.).Normalize();
01809     norm2 = Base::Vector3d(dir2.y, -dir2.x, 0.).Normalize();
01810 
01811     // calculate the intersections between the normals to find inwards direction
01812 
01813     // find intersection of lines
01814     Base::Vector3d corner;
01815     if (!find2DLinesIntersection(lineSeg1,lineSeg2,corner))
01816         return false;
01817 
01818     // Just project the given reference points onto the lines, just in case they are not already lying on
01819     Base::Vector3d normPnt1, normPnt2;
01820     normPnt1.ProjToLine(refPnt1-l1p1, l1p2-l1p1);
01821     normPnt2.ProjToLine(refPnt2-l2p1, l2p2-l2p1);
01822     normPnt1 += refPnt1;
01823     normPnt2 += refPnt2;
01824 
01825     //Angle bisector
01826     Base::Vector3d bisectDir = ((normPnt1 - corner).Normalize() + (normPnt2-corner).Normalize()).Normalize();
01827 
01828     //redefine norms pointing towards bisect line
01829     Base::Vector3d normIntersection1, normIntersection2;
01830     if (find2DLinesIntersection(normPnt1, norm1, corner, bisectDir, normIntersection1) &&
01831         find2DLinesIntersection(normPnt2, norm2, corner, bisectDir, normIntersection2)) {
01832         norm1 = (normIntersection1 - normPnt1).Normalize();
01833         norm2 = (normIntersection2 - normPnt2).Normalize();
01834     } else {
01835         return false;
01836     }
01837 
01838     // Project lines to find mid point of fillet arc
01839     Base::Vector3d tmpPoint1 = l1p1 + (norm1 * radius);
01840     Base::Vector3d tmpPoint2 = l2p1 + (norm2 * radius);
01841 
01842     // found center point
01843     if (find2DLinesIntersection(tmpPoint1, dir1, tmpPoint2, dir2, center))
01844         return true;
01845     else
01846         return false;
01847 }
01848 
01849 // Returns -1 if radius cannot be suggested
01850 double suggestFilletRadius(const GeomLineSegment *lineSeg1, const GeomLineSegment *lineSeg2,
01851                            const Base::Vector3d &refPnt1, const Base::Vector3d &refPnt2)
01852 {
01853     Base::Vector3d corner;
01854     if (!Part::find2DLinesIntersection(lineSeg1, lineSeg2, corner))
01855         return -1;
01856 
01857     Base::Vector3d dir1 = lineSeg1->getEndPoint() - lineSeg1->getStartPoint();
01858     Base::Vector3d dir2 = lineSeg2->getEndPoint() - lineSeg2->getStartPoint();
01859 
01860     // Decide the line directions depending on the reference points
01861     if (dir1*(refPnt1-corner) < 0)
01862         dir1 *= -1;
01863     if (dir2*(refPnt2-corner) < 0)
01864         dir2 *= -1;
01865 
01866     //Angle bisector
01867     Base::Vector3d dirBisect = (dir1.Normalize() + dir2.Normalize()).Normalize();
01868 
01869     Base::Vector3d projPnt1, projPnt2;
01870     projPnt1.ProjToLine(refPnt1-corner, dir1);
01871     projPnt2.ProjToLine(refPnt2-corner, dir2);
01872     projPnt1 += refPnt1;
01873     projPnt2 += refPnt2;
01874 
01875     Base::Vector3d norm1(dir1.y, -dir1.x, 0.f);
01876     Base::Vector3d norm2(dir2.y, -dir2.x, 0.f);
01877 
01878     double r1=-1, r2=-1;
01879     Base::Vector3d center1, center2;
01880     if (find2DLinesIntersection(projPnt1, norm1, corner, dirBisect, center1))
01881         r1 = (projPnt1 - center1).Length();
01882     if (find2DLinesIntersection(projPnt2, norm2, corner, dirBisect, center2))
01883         r2 = (projPnt1 - center2).Length();
01884 
01885     return r1 < r2 ? r1 : r2;
01886 }
01887 
01888 GeomArcOfCircle *createFilletGeometry(const GeomLineSegment *lineSeg1, const GeomLineSegment *lineSeg2,
01889                                       const Base::Vector3d &center, double radius)
01890 {
01891     Base::Vector3d corner;
01892     if (!Part::find2DLinesIntersection(lineSeg1, lineSeg2, corner))
01893         // Parallel Lines so return null pointer
01894         return 0;
01895 
01896     Base::Vector3d dir1 = lineSeg1->getEndPoint() - lineSeg1->getStartPoint();
01897     Base::Vector3d dir2 = lineSeg2->getEndPoint() - lineSeg2->getStartPoint();
01898 
01899     Base::Vector3d radDir1, radDir2;
01900     radDir1.ProjToLine(center - corner, dir1);
01901     radDir2.ProjToLine(center - corner, dir2);
01902 
01903     // Angle Variables
01904     double startAngle, endAngle, range;
01905 
01906     startAngle = atan2(radDir1.y, radDir1.x);
01907     range = atan2(-radDir1.y*radDir2.x+radDir1.x*radDir2.y,
01908                    radDir1.x*radDir2.x+radDir1.y*radDir2.y);
01909     endAngle = startAngle + range;
01910 
01911     if (endAngle < startAngle)
01912         std::swap(startAngle, endAngle);
01913 
01914     if (endAngle > 2*M_PI )
01915         endAngle -= 2*M_PI;
01916 
01917     if (startAngle < 0 )
01918         endAngle += 2*M_PI;
01919 
01920     // Create Arc Segment
01921     GeomArcOfCircle *arc = new GeomArcOfCircle();
01922     arc->setRadius(radius);
01923     arc->setCenter(center);
01924     arc->setRange(startAngle, endAngle);
01925 
01926     return arc;
01927 }
01928 
01929 }

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