PyObject* CylinderPy::vIso(PyObject * args)
{
    double v;
    if (!PyArg_ParseTuple(args, "d", &v))
        return 0;

    try {
        Handle_Geom_CylindricalSurface cyl = Handle_Geom_CylindricalSurface::DownCast
            (getGeomCylinderPtr()->handle());
        Handle_Geom_Curve c = cyl->VIso(v);
        if (!Handle_Geom_Circle::DownCast(c).IsNull()) {
            return new CirclePy(new GeomCircle(Handle_Geom_Circle::DownCast(c)));
        }
        if (!Handle_Geom_Ellipse::DownCast(c).IsNull()) {
            return new EllipsePy(new GeomEllipse(Handle_Geom_Ellipse::DownCast(c)));
        }

        PyErr_SetString(PyExc_NotImplementedError, "this type of conical curve is not implemented");
        return 0;
    }
    catch (Standard_Failure) {
        Handle_Standard_Failure e = Standard_Failure::Caught();
        PyErr_SetString(PartExceptionOCCError, e->GetMessageString());
        return 0;
    }
}
Py::Object CylinderPy::getCenter(void) const
{
    Handle_Geom_CylindricalSurface cyl = Handle_Geom_CylindricalSurface::DownCast
        (getGeomCylinderPtr()->handle());
    gp_Pnt loc = cyl->Location();
    return Py::Vector(Base::Vector3d(loc.X(), loc.Y(), loc.Z()));
}
PyObject* CylinderPy::uIso(PyObject * args)
{
    double v;
    if (!PyArg_ParseTuple(args, "d", &v))
        return 0;

    try {
        Handle_Geom_CylindricalSurface cyl = Handle_Geom_CylindricalSurface::DownCast
            (getGeomCylinderPtr()->handle());
        Handle_Geom_Curve c = cyl->UIso(v);
        if (!Handle_Geom_Line::DownCast(c).IsNull()) {
            GeomLine* line = new GeomLine();
            Handle_Geom_Line this_curv = Handle_Geom_Line::DownCast
                (line->handle());
            this_curv->SetLin(Handle_Geom_Line::DownCast(c)->Lin());
            return new LinePy(line);
        }

        PyErr_SetString(PyExc_NotImplementedError, "this type of conical curve is not implemented");
        return 0;
    }
    catch (Standard_Failure) {
        Handle_Standard_Failure e = Standard_Failure::Caught();
        PyErr_SetString(PartExceptionOCCError, e->GetMessageString());
        return 0;
    }
}
void CylinderPy::setCenter(Py::Object arg)
{
    PyObject* p = arg.ptr();
    if (PyObject_TypeCheck(p, &(Base::VectorPy::Type))) {
        Base::Vector3d loc = static_cast<Base::VectorPy*>(p)->value();
        Handle_Geom_CylindricalSurface cyl = Handle_Geom_CylindricalSurface::DownCast
            (getGeomCylinderPtr()->handle());
        cyl->SetLocation(gp_Pnt(loc.x, loc.y, loc.z));
    }
    else if (PyObject_TypeCheck(p, &PyTuple_Type)) {
        Base::Vector3d loc = Base::getVectorFromTuple<double>(p);
        Handle_Geom_CylindricalSurface cyl = Handle_Geom_CylindricalSurface::DownCast
            (getGeomCylinderPtr()->handle());
        cyl->SetLocation(gp_Pnt(loc.x, loc.y, loc.z));
    }
    else {
        std::string error = std::string("type must be 'Vector', not ");
        error += p->ob_type->tp_name;
        throw Py::TypeError(error);
    }
}
示例#5
0
文件: surface.cpp 项目: A1kmm/libzinc
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");
}
// constructor method
int CylinderPy::PyInit(PyObject* args, PyObject* kwds)
{
    // cylinder and distance for offset
    PyObject *pCyl;
    double dist;
    static char* keywords_cd[] = {"Cylinder","Distance",NULL};
    if (PyArg_ParseTupleAndKeywords(args, kwds, "O!d", keywords_cd, &(CylinderPy::Type), &pCyl, &dist)) {
        CylinderPy* pcCylinder = static_cast<CylinderPy*>(pCyl);
        Handle_Geom_CylindricalSurface cylinder = Handle_Geom_CylindricalSurface::DownCast
            (pcCylinder->getGeomCylinderPtr()->handle());
        GC_MakeCylindricalSurface mc(cylinder->Cylinder(), dist);
        if (!mc.IsDone()) {
            PyErr_SetString(PartExceptionOCCError, gce_ErrorStatusText(mc.Status()));
            return -1;
        }

        Handle_Geom_CylindricalSurface cyl = Handle_Geom_CylindricalSurface::DownCast
            (getGeomCylinderPtr()->handle());
        cyl->SetCylinder(mc.Value()->Cylinder());
        return 0;
    }

    static char* keywords_c[] = {"Cylinder",NULL};
    PyErr_Clear();
    if (PyArg_ParseTupleAndKeywords(args, kwds, "O!", keywords_c, &(CylinderPy::Type), &pCyl)) {
        CylinderPy* pcCylinder = static_cast<CylinderPy*>(pCyl);
        Handle_Geom_CylindricalSurface cyl1 = Handle_Geom_CylindricalSurface::DownCast
            (pcCylinder->getGeomCylinderPtr()->handle());
        Handle_Geom_CylindricalSurface cyl2 = Handle_Geom_CylindricalSurface::DownCast
            (this->getGeomCylinderPtr()->handle());
        cyl2->SetCylinder(cyl1->Cylinder());
        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_MakeCylindricalSurface 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_CylindricalSurface cyl = Handle_Geom_CylindricalSurface::DownCast
            (getGeomCylinderPtr()->handle());
        cyl->SetCylinder(mc.Value()->Cylinder());
        return 0;
    }

    static char* keywords_cc[] = {"Circle",NULL};
    PyErr_Clear();
    PyObject *pCirc;
    if (PyArg_ParseTupleAndKeywords(args, kwds, "O!", keywords_cc, &(CirclePy::Type), &pCirc)) {
        CirclePy* pcCircle = static_cast<CirclePy*>(pCirc);
        Handle_Geom_Circle circ = Handle_Geom_Circle::DownCast
            (pcCircle->getGeomCirclePtr()->handle());
        GC_MakeCylindricalSurface mc(circ->Circ());
        if (!mc.IsDone()) {
            PyErr_SetString(PartExceptionOCCError, gce_ErrorStatusText(mc.Status()));
            return -1;
        }

        Handle_Geom_CylindricalSurface cyl = Handle_Geom_CylindricalSurface::DownCast
            (getGeomCylinderPtr()->handle());
        cyl->SetCylinder(mc.Value()->Cylinder());
        return 0;
    }

    static char* keywords_n[] = {NULL};
    PyErr_Clear();
    if (PyArg_ParseTupleAndKeywords(args, kwds, "", keywords_n)) {
        Handle_Geom_CylindricalSurface cyl = Handle_Geom_CylindricalSurface::DownCast
            (getGeomCylinderPtr()->handle());
        cyl->SetRadius(1.0);
        return 0;
    }

    // All checks failed
    PyErr_SetString(PyExc_TypeError, "Cylinder constructor accepts:\n"
        "-- empty parameter list\n"
        "-- Cylinder\n"
        "-- Cylinder, Distance\n"
        "-- Point1, Point2, Point3\n"
        "-- Circle");
    return -1;
}
void CylinderPy::setRadius(Py::Float arg)
{
    Handle_Geom_CylindricalSurface cyl = Handle_Geom_CylindricalSurface::DownCast
        (getGeomCylinderPtr()->handle());
    cyl->SetRadius((double)arg);
}
Py::Float CylinderPy::getRadius(void) const
{
    Handle_Geom_CylindricalSurface cyl = Handle_Geom_CylindricalSurface::DownCast
        (getGeomCylinderPtr()->handle());
    return Py::Float(cyl->Radius()); 
}
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;
}