PyObject* GeometryCurvePy::intersect2d(PyObject *args) { PyObject *c,*p; if (!PyArg_ParseTuple(args, "O!O!", &(Part::GeometryCurvePy::Type), &c, &(Part::PlanePy::Type), &p)) return 0; try { Handle_Geom_Curve self = Handle_Geom_Curve::DownCast(getGeometryPtr()->handle()); Handle_Geom_Curve curv = Handle_Geom_Curve::DownCast(static_cast<GeometryPy*>(c)-> getGeometryPtr()->handle()); Handle_Geom_Plane plane = Handle_Geom_Plane::DownCast(static_cast<GeometryPy*>(p)-> getGeometryPtr()->handle()); Handle_Geom2d_Curve curv1 = GeomAPI::To2d(self, plane->Pln()); Handle_Geom2d_Curve curv2 = GeomAPI::To2d(curv, plane->Pln()); Geom2dAPI_InterCurveCurve intCC(curv1, curv2); int nbPoints = intCC.NbPoints(); Py::List list; for (int i=1; i<= nbPoints; i++) { gp_Pnt2d pt = intCC.Point(i); Py::Tuple tuple(2); tuple.setItem(0, Py::Float(pt.X())); tuple.setItem(1, Py::Float(pt.Y())); list.append(tuple); } return Py::new_reference_to(list); } catch (Standard_Failure) { Handle_Standard_Failure e = Standard_Failure::Caught(); PyErr_SetString(PartExceptionOCCError, e->GetMessageString()); return 0; } }
static Handle(Geom_Plane) getGeomPlane(const TopoDS_Face &faceIn) { Handle_Geom_Plane planeSurfaceOut; Handle_Geom_Surface surface = BRep_Tool::Surface(faceIn); if (!surface.IsNull()) { planeSurfaceOut = Handle(Geom_Plane)::DownCast(surface); if (planeSurfaceOut.IsNull()) { Handle_Geom_RectangularTrimmedSurface trimmedSurface = Handle(Geom_RectangularTrimmedSurface)::DownCast(surface); if (!trimmedSurface.IsNull()) planeSurfaceOut = Handle(Geom_Plane)::DownCast(trimmedSurface->BasisSurface()); } } return planeSurfaceOut; }
PyObject* PlanePy::vIso(PyObject * args) { double v; if (!PyArg_ParseTuple(args, "d", &v)) return 0; try { Handle_Geom_Plane plane = Handle_Geom_Plane::DownCast (getGeomPlanePtr()->handle()); Handle_Geom_Line c = Handle_Geom_Line::DownCast(plane->VIso(v)); GeomLine* line = new GeomLine(); Handle_Geom_Line this_curv = Handle_Geom_Line::DownCast (line->handle()); this_curv->SetLin(c->Lin()); return new LinePy(line); } catch (Standard_Failure) { Handle_Standard_Failure e = Standard_Failure::Caught(); PyErr_SetString(PartExceptionOCCError, e->GetMessageString()); return 0; } }
void Surface::information() const { display_message(INFORMATION_MESSAGE, " %s", geomTypeString().c_str()); if (m_surface->DynamicType() == STANDARD_TYPE(Geom_CylindricalSurface)) { Handle_Geom_CylindricalSurface cylinder = Handle_Geom_CylindricalSurface::DownCast(m_surface); display_message(INFORMATION_MESSAGE, " with radius = %.3g", cylinder->Radius()); } else if (m_surface->DynamicType() == STANDARD_TYPE(Geom_Plane)) { Handle_Geom_Plane plane = Handle_Geom_Plane::DownCast(m_surface); Standard_Real a, b, c, d; plane->Coefficients(a, b, c, d); display_message(INFORMATION_MESSAGE, " with equation: %.3g x + %.3g y + %.3g z + %.3g = 0", a, b, c, d); } else if (m_surface->DynamicType() == STANDARD_TYPE(Geom_SphericalSurface)) { Handle_Geom_SphericalSurface sphere = Handle_Geom_SphericalSurface::DownCast(m_surface); display_message(INFORMATION_MESSAGE, " with area: %.3g", sphere->Area()); } display_message(INFORMATION_MESSAGE, "\n"); }
PyObject* PlanePy::uIso(PyObject * args) { double u; if (!PyArg_ParseTuple(args, "d", &u)) return 0; try { Handle_Geom_Plane plane = Handle_Geom_Plane::DownCast (getGeomPlanePtr()->handle()); Handle_Geom_Line c = Handle_Geom_Line::DownCast(plane->UIso(u)); GeomLineSegment* line = new GeomLineSegment(); Handle_Geom_TrimmedCurve this_curv = Handle_Geom_TrimmedCurve::DownCast (line->handle()); Handle_Geom_Line this_line = Handle_Geom_Line::DownCast (this_curv->BasisCurve()); this_line->SetLin(c->Lin()); return new LinePy(line); } catch (Standard_Failure) { Handle_Standard_Failure e = Standard_Failure::Caught(); PyErr_SetString(PyExc_Exception, e->GetMessageString()); return 0; } }
// constructor method int PlanePy::PyInit(PyObject* args, PyObject* kwds) { // plane and distance for offset PyObject *pPlane; double dist; static char* keywords_pd[] = {"Plane","Distance",NULL}; if (PyArg_ParseTupleAndKeywords(args, kwds, "O!d", keywords_pd, &(PlanePy::Type), &pPlane, &dist)) { PlanePy* pcPlane = static_cast<PlanePy*>(pPlane); Handle_Geom_Plane plane = Handle_Geom_Plane::DownCast (pcPlane->getGeometryPtr()->handle()); GC_MakePlane mc(plane->Pln(), dist); if (!mc.IsDone()) { PyErr_SetString(PartExceptionOCCError, gce_ErrorStatusText(mc.Status())); return -1; } Handle_Geom_Plane plan = Handle_Geom_Plane::DownCast(getGeometryPtr()->handle()); plan->SetPln(mc.Value()->Pln()); return 0; } // plane from equation double a,b,c,d; static char* keywords_abcd[] = {"A","B","C","D",NULL}; PyErr_Clear(); if (PyArg_ParseTupleAndKeywords(args, kwds, "dddd", keywords_abcd, &a,&b,&c,&d)) { GC_MakePlane mc(a,b,c,d); if (!mc.IsDone()) { PyErr_SetString(PartExceptionOCCError, gce_ErrorStatusText(mc.Status())); return -1; } Handle_Geom_Plane plane = Handle_Geom_Plane::DownCast(getGeometryPtr()->handle()); plane->SetPln(mc.Value()->Pln()); return 0; } PyObject *pV1, *pV2, *pV3; static char* keywords_ppp[] = {"Point1","Point2","Point3",NULL}; PyErr_Clear(); if (PyArg_ParseTupleAndKeywords(args, kwds, "O!O!O!", keywords_ppp, &(Base::VectorPy::Type), &pV1, &(Base::VectorPy::Type), &pV2, &(Base::VectorPy::Type), &pV3)) { Base::Vector3d v1 = static_cast<Base::VectorPy*>(pV1)->value(); Base::Vector3d v2 = static_cast<Base::VectorPy*>(pV2)->value(); Base::Vector3d v3 = static_cast<Base::VectorPy*>(pV3)->value(); GC_MakePlane mc(gp_Pnt(v1.x,v1.y,v1.z), gp_Pnt(v2.x,v2.y,v2.z), gp_Pnt(v3.x,v3.y,v3.z)); if (!mc.IsDone()) { PyErr_SetString(PartExceptionOCCError, gce_ErrorStatusText(mc.Status())); return -1; } Handle_Geom_Plane plane = Handle_Geom_Plane::DownCast(getGeometryPtr()->handle()); plane->SetPln(mc.Value()->Pln()); return 0; } // location and normal static char* keywords_cnr[] = {"Location","Normal",NULL}; PyErr_Clear(); if (PyArg_ParseTupleAndKeywords(args, kwds, "O!O!", keywords_cnr, &(Base::VectorPy::Type), &pV1, &(Base::VectorPy::Type), &pV2)) { Base::Vector3d v1 = static_cast<Base::VectorPy*>(pV1)->value(); Base::Vector3d v2 = static_cast<Base::VectorPy*>(pV2)->value(); GC_MakePlane mc(gp_Pnt(v1.x,v1.y,v1.z), gp_Dir(v2.x,v2.y,v2.z)); if (!mc.IsDone()) { PyErr_SetString(PartExceptionOCCError, gce_ErrorStatusText(mc.Status())); return -1; } Handle_Geom_Plane plane = Handle_Geom_Plane::DownCast(getGeometryPtr()->handle()); plane->SetPln(mc.Value()->Pln()); return 0; } static char* keywords_p[] = {"Plane",NULL}; PyErr_Clear(); if (PyArg_ParseTupleAndKeywords(args, kwds, "O!", keywords_p, &(PlanePy::Type), &pPlane)) { PlanePy* pcPlane = static_cast<PlanePy*>(pPlane); Handle_Geom_Plane plane1 = Handle_Geom_Plane::DownCast (pcPlane->getGeometryPtr()->handle()); Handle_Geom_Plane plane2 = Handle_Geom_Plane::DownCast (this->getGeometryPtr()->handle()); plane2->SetPln(plane1->Pln()); return 0; } static char* keywords_n[] = {NULL}; PyErr_Clear(); if (PyArg_ParseTupleAndKeywords(args, kwds, "", keywords_n)) { // do nothing return 0; } PyErr_SetString(PyExc_TypeError, "Plane constructor accepts:\n" "-- empty parameter list\n" "-- Plane\n" "-- Plane, Distance\n" "-- Location, Normal\n" "-- Point1, Point2, Point3\n" "-- A, B, C, D\n" " (as equation: Ax + By + Cz + D = 0.0)"); return -1; }
int convert_to_ifc(const Handle_Geom_Surface& s, IfcSchema::IfcSurface*& surface, bool advanced) { if (s->DynamicType() == STANDARD_TYPE(Geom_Plane)) { Handle_Geom_Plane plane = Handle_Geom_Plane::DownCast(s); IfcSchema::IfcAxis2Placement3D* place; /// @todo: Note that the Ax3 is converted to an Ax2 here if (!convert_to_ifc(plane->Position().Ax2(), place, advanced)) { return 0; } surface = new IfcSchema::IfcPlane(place); return 1; } #ifdef USE_IFC4 else if (s->DynamicType() == STANDARD_TYPE(Geom_CylindricalSurface)) { Handle_Geom_CylindricalSurface cyl = Handle_Geom_CylindricalSurface::DownCast(s); IfcSchema::IfcAxis2Placement3D* place; /// @todo: Note that the Ax3 is converted to an Ax2 here if (!convert_to_ifc(cyl->Position().Ax2(), place, advanced)) { return 0; } surface = new IfcSchema::IfcCylindricalSurface(place, cyl->Radius()); return 1; } else if (s->DynamicType() == STANDARD_TYPE(Geom_BSplineSurface)) { typedef IfcTemplatedEntityListList<IfcSchema::IfcCartesianPoint> points_t; Handle_Geom_BSplineSurface bspline = Handle_Geom_BSplineSurface::DownCast(s); points_t::ptr points(new points_t); TColgp_Array2OfPnt poles(1, bspline->NbUPoles(), 1, bspline->NbVPoles()); bspline->Poles(poles); for (int i = 1; i <= bspline->NbUPoles(); ++i) { std::vector<IfcSchema::IfcCartesianPoint*> ps; ps.reserve(bspline->NbVPoles()); for (int j = 1; j <= bspline->NbVPoles(); ++j) { IfcSchema::IfcCartesianPoint* p; if (!convert_to_ifc(poles.Value(i, j), p, advanced)) { return 0; } ps.push_back(p); } points->push(ps); } IfcSchema::IfcKnotType::IfcKnotType knot_spec_u = opencascade_knotspec_to_ifc(bspline->UKnotDistribution()); IfcSchema::IfcKnotType::IfcKnotType knot_spec_v = opencascade_knotspec_to_ifc(bspline->VKnotDistribution()); if (knot_spec_u != knot_spec_v) { knot_spec_u = IfcSchema::IfcKnotType::IfcKnotType_UNSPECIFIED; } std::vector<int> umults; std::vector<int> vmults; std::vector<double> uknots; std::vector<double> vknots; std::vector< std::vector<double> > weights; TColStd_Array1OfInteger bspline_umults(1, bspline->NbUKnots()); TColStd_Array1OfInteger bspline_vmults(1, bspline->NbVKnots()); TColStd_Array1OfReal bspline_uknots(1, bspline->NbUKnots()); TColStd_Array1OfReal bspline_vknots(1, bspline->NbVKnots()); TColStd_Array2OfReal bspline_weights(1, bspline->NbUPoles(), 1, bspline->NbVPoles()); bspline->UMultiplicities(bspline_umults); bspline->VMultiplicities(bspline_vmults); bspline->UKnots(bspline_uknots); bspline->VKnots(bspline_vknots); bspline->Weights(bspline_weights); opencascade_array_to_vector(bspline_umults, umults); opencascade_array_to_vector(bspline_vmults, vmults); opencascade_array_to_vector(bspline_uknots, uknots); opencascade_array_to_vector(bspline_vknots, vknots); opencascade_array_to_vector2(bspline_weights, weights); bool rational = false; for (std::vector< std::vector<double> >::const_iterator it = weights.begin(); it != weights.end(); ++it) { for (std::vector<double>::const_iterator jt = it->begin(); jt != it->end(); ++jt) { if ((*jt) != 1.) { rational = true; break; } } } if (rational) { surface = new IfcSchema::IfcRationalBSplineSurfaceWithKnots( bspline->UDegree(), bspline->VDegree(), points, IfcSchema::IfcBSplineSurfaceForm::IfcBSplineSurfaceForm_UNSPECIFIED, bspline->IsUClosed(), bspline->IsVClosed(), false, umults, vmults, uknots, vknots, knot_spec_u, weights ); } else { surface = new IfcSchema::IfcBSplineSurfaceWithKnots( bspline->UDegree(), bspline->VDegree(), points, IfcSchema::IfcBSplineSurfaceForm::IfcBSplineSurfaceForm_UNSPECIFIED, bspline->IsUClosed(), bspline->IsVClosed(), false, umults, vmults, uknots, vknots, knot_spec_u ); } return 1; } #endif return 0; }