App::DocumentObjectExecReturn *RegularPolygon::execute(void)
{
    // Build a regular polygon
    if (Polygon.getValue() < 3)
        return new App::DocumentObjectExecReturn("the polygon is invalid, must have 3 or more sides");
    if (Circumradius.getValue() < Precision::Confusion())
        return new App::DocumentObjectExecReturn("Circumradius of the polygon is too small");

    try {
        long nodes = Polygon.getValue();

        Base::Matrix4D mat;
        mat.rotZ(Base::toRadians(360.0/nodes));

        // create polygon
        BRepBuilderAPI_MakePolygon mkPoly;
        Base::Vector3d v(Circumradius.getValue(),0,0);
        for (long i=0; i<nodes; i++) {
            mkPoly.Add(gp_Pnt(v.x,v.y,v.z));
            v = mat * v;
        }
        mkPoly.Add(gp_Pnt(v.x,v.y,v.z));
        this->Shape.setValue(mkPoly.Shape());
    }
    catch (Standard_Failure) {
        Handle_Standard_Failure e = Standard_Failure::Caught();
        return new App::DocumentObjectExecReturn(e->GetMessageString());
    }

    return App::DocumentObject::StdReturn;
}
App::DocumentObjectExecReturn *Prism::execute(void)
{
    // Build a prism
    if (Polygon.getValue() < 3)
        return new App::DocumentObjectExecReturn("Polygon of prism is invalid");
    if (Length.getValue() < Precision::Confusion())
        return new App::DocumentObjectExecReturn("Radius of prism too small");
    if (Height.getValue() < Precision::Confusion())
        return new App::DocumentObjectExecReturn("Height of prism too small");
    try {
        long nodes = Polygon.getValue();

        Base::Matrix4D mat;
        mat.rotZ(Base::toRadians(360.0/nodes));

        // create polygon
        BRepBuilderAPI_MakePolygon mkPoly;
        Base::Vector3d v(Length.getValue(),0,0);
        for (long i=0; i<nodes; i++) {
            mkPoly.Add(gp_Pnt(v.x,v.y,v.z));
            v = mat * v;
        }
        mkPoly.Add(gp_Pnt(v.x,v.y,v.z));
        BRepBuilderAPI_MakeFace mkFace(mkPoly.Wire());
        BRepPrimAPI_MakePrism mkPrism(mkFace.Face(), gp_Vec(0,0,Height.getValue()));
        this->Shape.setValue(mkPrism.Shape());
    }
    catch (Standard_Failure) {
        Handle_Standard_Failure e = Standard_Failure::Caught();
        return new App::DocumentObjectExecReturn(e->GetMessageString());
    }

    return App::DocumentObject::StdReturn;
}
Beispiel #3
0
App::DocumentObjectExecReturn *Prism::execute(void)
{
    // Build a prism
    if (Polygon.getValue() < 3)
        return new App::DocumentObjectExecReturn("Polygon of prism is invalid, must have 3 or more sides");
    if (Circumradius.getValue() < Precision::Confusion())
        return new App::DocumentObjectExecReturn("Circumradius of the polygon, of the prism, is too small");
    if (Height.getValue() < Precision::Confusion())
        return new App::DocumentObjectExecReturn("Height of prism is too small");
    try {
        long nodes = Polygon.getValue();

        Base::Matrix4D mat;
        mat.rotZ(Base::toRadians(360.0/nodes));

        // create polygon
        BRepBuilderAPI_MakePolygon mkPoly;
        Base::Vector3d v(Circumradius.getValue(),0,0);
        for (long i=0; i<nodes; i++) {
            mkPoly.Add(gp_Pnt(v.x,v.y,v.z));
            v = mat * v;
        }
        mkPoly.Add(gp_Pnt(v.x,v.y,v.z));
        BRepBuilderAPI_MakeFace mkFace(mkPoly.Wire());
        BRepPrimAPI_MakePrism mkPrism(mkFace.Face(), gp_Vec(0,0,Height.getValue()));
        this->Shape.setValue(mkPrism.Shape());
    }
    catch (Standard_Failure& e) {

        return new App::DocumentObjectExecReturn(e.GetMessageString());
    }

    return Primitive::execute();
}
Beispiel #4
0
    Py::Object wireFromSegment(const Py::Tuple& args)
    {
        PyObject *o, *m;
        if (!PyArg_ParseTuple(args.ptr(), "O!O!", &(Mesh::MeshPy::Type), &m,&PyList_Type,&o))
            throw Py::Exception();

        Py::List list(o);
        Mesh::MeshObject* mesh = static_cast<Mesh::MeshPy*>(m)->getMeshObjectPtr();
        std::vector<unsigned long> segm;
        segm.reserve(list.size());
        for (unsigned int i=0; i<list.size(); i++) {
            segm.push_back((int)Py::Int(list[i]));
        }

        std::list<std::vector<Base::Vector3f> > bounds;
        MeshCore::MeshAlgorithm algo(mesh->getKernel());
        algo.GetFacetBorders(segm, bounds);

        Py::List wires;
        std::list<std::vector<Base::Vector3f> >::iterator bt;

        for (bt = bounds.begin(); bt != bounds.end(); ++bt) {
            BRepBuilderAPI_MakePolygon mkPoly;
            for (std::vector<Base::Vector3f>::reverse_iterator it = bt->rbegin(); it != bt->rend(); ++it) {
                mkPoly.Add(gp_Pnt(it->x,it->y,it->z));
            }
            if (mkPoly.IsDone()) {
                PyObject* wire = new Part::TopoShapeWirePy(new Part::TopoShape(mkPoly.Wire()));
                wires.append(Py::Object(wire, true));
            }
        }

        return wires;
    }
Beispiel #5
0
int OCCFace::createPolygonal(std::vector<OCCStruct3d> points)
{
    try {
        BRepBuilderAPI_MakePolygon MP;
        for (unsigned i=0; i<points.size(); i++) {
            MP.Add(gp_Pnt(points[i].x, points[i].y, points[i].z));
        }
        MP.Close();
        if (!MP.IsDone()) {
            StdFail_NotDone::Raise("failed to create face");;
        }
        BRepBuilderAPI_MakeFace MF(MP.Wire(), false);
        this->setShape(MF.Face());
        
        // possible fix shape
        if (!this->fixShape())
            StdFail_NotDone::Raise("Shapes not valid");
        
    } catch(Standard_Failure &err) {
        Handle_Standard_Failure e = Standard_Failure::Caught();
        const Standard_CString msg = e->GetMessageString();
        if (msg != NULL && strlen(msg) > 1) {
            setErrorMessage(msg);
        } else {
            setErrorMessage("Failed to create face");
        }
        return 0;
    }
    return 1;
}
static TopoDS_Wire mkPolygonWire(const Standard_Integer nPoints,
                                 const Standard_Real theCoords[][3],
                                 const Standard_Real aScale = 1,
                                 const gp_XYZ& aShift = gp_XYZ(0,0,0))
{
    BRepBuilderAPI_MakePolygon aPol;
    for (Standard_Integer i=0; i < nPoints; i++)
    {
        gp_XYZ aP(theCoords[i][0], theCoords[i][1], theCoords[i][2]);
        aPol.Add (gp_Pnt (aP * aScale + aShift));
    }
    return aPol.Wire();
}
Beispiel #7
0
void occQt::makeLoft()
{
    // bottom wire.
    TopoDS_Edge aCircleEdge = BRepBuilderAPI_MakeEdge(gp_Circ(gp_Ax2(gp_Pnt(0.0, 80.0, 0.0), gp::DZ()), 1.5));
    TopoDS_Wire aCircleWire = BRepBuilderAPI_MakeWire(aCircleEdge);

    // top wire.
    BRepBuilderAPI_MakePolygon aPolygon;
    aPolygon.Add(gp_Pnt(-3.0, 77.0, 6.0));
    aPolygon.Add(gp_Pnt(3.0, 77.0, 6.0));
    aPolygon.Add(gp_Pnt(3.0, 83.0, 6.0));
    aPolygon.Add(gp_Pnt(-3.0, 83.0, 6.0));
    aPolygon.Close();

    BRepOffsetAPI_ThruSections aShellGenerator;
    BRepOffsetAPI_ThruSections aSolidGenerator(true);

    aShellGenerator.AddWire(aCircleWire);
    aShellGenerator.AddWire(aPolygon.Wire());

    aSolidGenerator.AddWire(aCircleWire);
    aSolidGenerator.AddWire(aPolygon.Wire());

    // translate the solid.
    gp_Trsf aTrsf;
    aTrsf.SetTranslation(gp_Vec(18.0, 0.0, 0.0));
    BRepBuilderAPI_Transform aTransform(aSolidGenerator.Shape(), aTrsf);

    Handle_AIS_Shape anAisShell = new AIS_Shape(aShellGenerator.Shape());
    Handle_AIS_Shape anAisSolid = new AIS_Shape(aTransform.Shape());

    anAisShell->SetColor(Quantity_NOC_OLIVEDRAB);
    anAisSolid->SetColor(Quantity_NOC_PEACHPUFF);

    mContext->Display(anAisShell);
    mContext->Display(anAisSolid);
}
Beispiel #8
0
App::DocumentObjectExecReturn *Part::Polygon::execute(void)
{
    BRepBuilderAPI_MakePolygon poly;
    const std::vector<Base::Vector3d> nodes = Nodes.getValues();

    for (std::vector<Base::Vector3d>::const_iterator it = nodes.begin(); it != nodes.end(); ++it) {
        gp_Pnt pnt(it->x, it->y, it->z);
        poly.Add(pnt);
    }

    if (Close.getValue())
        poly.Close();

    if (!poly.IsDone())
        throw Base::CADKernelError("Cannot create polygon because less than two vertices are given");
    TopoDS_Wire wire = poly.Wire();
    this->Shape.setValue(wire);

    return App::DocumentObject::StdReturn;
}
Beispiel #9
0
static PyObject *
wireFromSegment(PyObject *self, PyObject *args)
{
    PyObject *o, *m;
    if (!PyArg_ParseTuple(args, "O!O!", &(Mesh::MeshPy::Type), &m,&PyList_Type,&o))
        return 0;
    Py::List list(o);
    Mesh::MeshObject* mesh = static_cast<Mesh::MeshPy*>(m)->getMeshObjectPtr();
    std::vector<unsigned long> segm;
    segm.reserve(list.size());
    for (unsigned int i=0; i<list.size(); i++) {
        segm.push_back((int)Py::Int(list[i]));
    }

    std::list<std::vector<Base::Vector3f> > bounds;
    MeshCore::MeshAlgorithm algo(mesh->getKernel());
    algo.GetFacetBorders(segm, bounds);

    Py::List wires;
    std::list<std::vector<Base::Vector3f> >::iterator bt;

    try {
        for (bt = bounds.begin(); bt != bounds.end(); ++bt) {
            BRepBuilderAPI_MakePolygon mkPoly;
            for (std::vector<Base::Vector3f>::reverse_iterator it = bt->rbegin(); it != bt->rend(); ++it) {
                mkPoly.Add(gp_Pnt(it->x,it->y,it->z));
            }
            if (mkPoly.IsDone()) {
                PyObject* wire = new Part::TopoShapeWirePy(new Part::TopoShape(mkPoly.Wire()));
                wires.append(Py::Object(wire, true));
            }
        }
    }
    catch (Standard_Failure) {
        Handle_Standard_Failure e = Standard_Failure::Caught();
        PyErr_SetString(Base::BaseExceptionFreeCADError, e->GetMessageString());
        return 0;
    }

    return Py::new_reference_to(wires);
}
bool IfcGeom::Kernel::convert(const IfcSchema::IfcPolyLoop* l, TopoDS_Wire& result) {
	IfcSchema::IfcCartesianPoint::list::ptr points = l->Polygon();

	// Parse and store the points in a sequence
	TColgp_SequenceOfPnt polygon;
	for(IfcSchema::IfcCartesianPoint::list::it it = points->begin(); it != points->end(); ++ it) {
		gp_Pnt pnt;
		IfcGeom::Kernel::convert(*it, pnt);
		polygon.Append(pnt);
	}

	// A loop should consist of at least three vertices
	int original_count = polygon.Length();
	if (original_count < 3) {
		Logger::Message(Logger::LOG_ERROR, "Not enough edges for:", l->entity);
		return false;
	}

	// Remove points that are too close to one another
	remove_redundant_points_from_loop(polygon, true);

	int count = polygon.Length();
	if (original_count - count != 0) {
		std::stringstream ss; ss << (original_count - count) << " edges removed for:"; 
		Logger::Message(Logger::LOG_WARNING, ss.str(), l->entity);
	}

	if (count < 3) {
		Logger::Message(Logger::LOG_ERROR, "Not enough edges for:", l->entity);
		return false;
	}

	BRepBuilderAPI_MakePolygon w;
	for (int i = 1; i <= polygon.Length(); ++i) {
		w.Add(polygon.Value(i));
	}
	w.Close();

	result = w.Wire();	
	return true;
}
bool IfcGeom::Kernel::convert(const IfcSchema::IfcPolyline* l, TopoDS_Wire& result) {
	IfcSchema::IfcCartesianPoint::list::ptr points = l->Points();

	// Parse and store the points in a sequence
	TColgp_SequenceOfPnt polygon;
	for(IfcSchema::IfcCartesianPoint::list::it it = points->begin(); it != points->end(); ++ it) {
		gp_Pnt pnt;
		IfcGeom::Kernel::convert(*it, pnt);
		polygon.Append(pnt);
	}

	// Remove points that are too close to one another
	remove_redundant_points_from_loop(polygon, false);
	
	BRepBuilderAPI_MakePolygon w;
	for (int i = 1; i <= polygon.Length(); ++i) {
		w.Add(polygon.Value(i));
	}

	result = w.Wire();
	return true;
}
bool DrawingLineWallCtrller::UpdateMesh()
{
	if ( !NeedUpdateMesh_ )
	{
		return true;
	}

	if ( Pnts_.size() > 1 )
	{
		{//Triangle Mesh
			BRepBuilderAPI_MakePolygon mp;
			for ( const auto& curPnt : Pnts_ )
			{
				mp.Add(gp_Pnt(curPnt.X, curPnt.Y, curPnt.Z));
			}
			assert(mp.IsDone());

			auto wallPath = mp.Wire();
			assert(!wallPath.IsNull());

			auto& wallPnt1 = Pnts_[0];
			auto& wallPnt2 = Pnts_[1];

			auto beginThickPnt = (wallPnt2 - wallPnt1).normalize().crossProduct(s_PntNormal) * WallThickness_;
			beginThickPnt = wallPnt1 + beginThickPnt;

			auto thickEdge = BRepBuilderAPI_MakeEdge(gp_Pnt(wallPnt1.X,wallPnt1.Y, wallPnt1.Z), gp_Pnt(beginThickPnt.X,beginThickPnt.Y, beginThickPnt.Z) ).Edge();
			BRepBuilderAPI_MakeWire dirWireMaker(thickEdge);
			TopoDS_Wire dirWire = dirWireMaker.Wire();

			BRepOffsetAPI_MakePipeShell pipeMaker(wallPath);
			pipeMaker.SetTransitionMode(BRepBuilderAPI_RightCorner);//延切线方向缝合
			pipeMaker.Add(dirWire);
			pipeMaker.Build();

			FaceShape_ = pipeMaker.Shape();
			if ( wallPath.Closed() )
			{
				State_ = EDWLS_FINISH;
				return false;
			}

			if ( MeshBuf_ )
			{
				MeshBuf_->drop();
			}

			auto mesh = ODLTools::CreateMesh(FaceShape_);
			assert(mesh);
			MeshBuf_ = mesh->getMeshBuffer(0);
			MeshBuf_->grab();

			auto tex = GetRenderContextSPtr()->Smgr_->getVideoDriver()->getTexture("../Data/Resource/3D/wallLine.png");
			MeshBuf_->getMaterial().setTexture(0, tex);
			float uLen = 200;
			float vLen = 200;
			irr::core::matrix4 scaleMat,rotateMat;
			scaleMat.setScale(irr::core::vector3df(1/uLen, 1/vLen, 1));
			rotateMat.setTextureRotationCenter(static_cast<float>(M_PI/4));
			MeshBuf_->getMaterial().setTextureMatrix(0, rotateMat*scaleMat);
			MeshBuf_->getMaterial().Lighting = false;
			MeshBuf_->getMaterial().ZWriteEnable = false;
			MeshBuf_->getMaterial().BackfaceCulling = false;
			mesh->drop();
		}

		{//Line Mesh
			if ( LineMeshBuf_ )
			{
				LineMeshBuf_->drop();
			}

			auto newSmesh = new SMeshBuffer;
			for ( TopExp_Explorer exp(FaceShape_, TopAbs_EDGE); exp.More(); exp.Next() )
			{
				auto& curEdge = TopoDS::Edge(exp.Current());
				auto& v1 = TopExp::FirstVertex(curEdge);
				auto& v2 = TopExp::LastVertex(curEdge);

				auto p1 = BRep_Tool::Pnt(v1);
				auto p2 = BRep_Tool::Pnt(v2);

				S3DVertex sv1(irr::core::vector3df(static_cast<float>(p1.X()), static_cast<float>(p1.Y()), static_cast<float>(p1.Z())), s_PntNormal, s_LineColor, s_PntCoord);
				S3DVertex sv2(irr::core::vector3df(static_cast<float>(p2.X()), static_cast<float>(p2.Y()), static_cast<float>(p2.Z())), s_PntNormal, s_LineColor, s_PntCoord);

				newSmesh->Vertices.push_back(sv1);
				newSmesh->Vertices.push_back(sv2);
				newSmesh->Indices.push_back(newSmesh->getIndexCount());
				newSmesh->Indices.push_back(newSmesh->getIndexCount());
			}

			LineMeshBuf_ = newSmesh;

			LineMeshBuf_->getMaterial().Lighting = false;
			LineMeshBuf_->getMaterial().ZWriteEnable = false;
			LineMeshBuf_->getMaterial().BackfaceCulling = false;
			LineMeshBuf_->getMaterial().Thickness = 3;
			LineMeshBuf_->getMaterial().MaterialType = IrrEngine::GetInstance()->GetShaderType(EST_LINE);
			LineMeshBuf_->getMaterial().DiffuseColor = s_LineColor;
		}
	}


	{//Path Mesh
		auto smeshBuf = static_cast<irr::scene::SMeshBuffer*>(PathMeshBuf_);
		smeshBuf->Vertices.clear();
		smeshBuf->Indices.clear();

		auto curCount = PathMeshBuf_->getIndexCount();
		for ( const auto& curPnt : Pnts_ )
		{
			smeshBuf->Vertices.push_back(irr::video::S3DVertex(curPnt, s_PntNormal, s_PathColor, s_PntCoord));
			smeshBuf->Indices.push_back(curCount++);
		}
	}

	NeedUpdateMesh_ = false;

	return true;
}
App::DocumentObjectExecReturn *Fractal::execute(void)
{
	faces.clear();
	//Appel de la fonction de generation avec des valeurs prereglees(taille) et la valeur de l'utilisateur
	//sierpin([-7, -4, 0], [0, 8, 0], [7, -4, 0], [0, 0, 11], 6)
	//sierpin(Base::Vector3d(-5, -5, -5), Base::Vector3d(5, 5, -5), Base::Vector3d(-5, 5, 5), Base::Vector3d(5, -5, 5), 1, Nodes.getValues());
	
	sierpin(Base::Vector3d(-Length.getValue(), -Width.getValue(), -Height.getValue()), Base::Vector3d(Length.getValue(), Width.getValue(), -Height.getValue()), Base::Vector3d(-Length.getValue(), Width.getValue(), Height.getValue()), Base::Vector3d(Length.getValue(), -Width.getValue(), Height.getValue()), Depth.getValue(), Nodes.getValues());
	//Sponge();

		/*//Creation du shell avec la liste des faces
		myShell = Part.makeShell(partFaces);
		// Creation du polygon avec le shell
		mySolid = Part.makeSolid(myShell);
		// Mise a jour de l'orientation des faces
		mySolidRev = mySolid.copy();
		mySolidRev.reverse();

		//Affichage du solide
		Part.show(mySolidRev);*/

	BRepBuilderAPI_MakePolygon poly;
	//const std::vector<Base::Vector3d> nodes = Nodes;
	/*_nodes.push_back(Base::Vector3d(0, 0, 0));
	_nodes.push_back(Base::Vector3d(0, 0, 1));
	_nodes.push_back(Base::Vector3d(0, 0, 3));
	_nodes.push_back(Base::Vector3d(0, 0, 5));
	_nodes.push_back(Base::Vector3d(0, 5, 0));
	_nodes.push_back(Base::Vector3d(0, 0, 8));*/

	/*std::string s = std::to_string(_nodes.size());
	char const *pchar = s.c_str();
	Base::Console().Message(pchar);
	Base::Console().Log(pchar);*/

	for (std::vector<Base::Vector3d>::const_iterator it = _nodes.begin(); it != _nodes.end(); ++it) {
		gp_Pnt pnt(it->x, it->y, it->z);
		poly.Add(pnt);
	}

	if (!poly.IsDone())
		throw Base::Exception("Cannot create polygon because less than two vetices are given");
	//TopoDS_Wire wire = poly.Wire();
	//BRepBuilderAPI_MakeFace makeFace(poly.Wire());

	/*gp_Pnt point1 = gp_Pnt(1,0,0);
	gp_Pnt point2 = gp_Pnt(1,1,0);
	gp_Pnt point3 = gp_Pnt(1,0,1);*/
	//TopoDS_Wire wire = BRepBuilderAPI_MakePolygon(, Standard_True);
	//TopoDS_Face face = BRepBuilderAPI_MakeFace(wire, Standard_True);
	//TopoDS_Shape s;

	/*if (makeFace.Error() == BRepBuilderAPI_FaceDone)
	{
		TopoDS_Face faceCurrent = makeFace.Face();
	}
	BRepBuilderAPI_MakeFace makeFace(faceCurrent);
	makeFace.Add(MP.Wire());
	if (makeFace.Error() == BRepBuilderAPI_FaceDone)
	{
		faceCurrent = makeFace.Face();
	}*/

	//this->Shape.setValue();



	//TopoDS_Face tf;

	//BRepBuilderAPI_MakeFace mkFace(TopoDS::Wire(sh));

	//Handle_Geom_Surface gs;
	//Handle<Geom_Surface> dd;
	//gs.Access = 0;

	/*RepOffsetAPI_MakeOffsetShape mkOffset(this->_Shape, offset, tol, BRepOffset_Mode(offsetMode),
        intersection ? Standard_True : Standard_False,
        selfInter ? Standard_True : Standard_False,
        GeomAbs_JoinType(join));
   
    if (!fill)
        return res;
#if 1
    //s=Part.makePlane(10,10)
    //s.makeOffsetShape(1.0,0.01,False,False,0,0,True)*/

	//BRepOffsetAPI_MakeOffsetShape myOffsetShape;
	//TopoShape ts;
	//myOffsetShape = ts.makeOffsetShape(1.0, 0.01, False, False, 0, 0, True);
	//const TopoDS_Shape& res = myOffsetShape.Shape();

	BRep_Builder builder;
	TopoDS_Shell shell;
	builder.MakeShell(shell);
	/*s = std::to_string(faces.size());
	pchar = s.c_str();
	Base::Console().Message(pchar);
	Base::Console().Log(pchar);*/
	for (int i = 0; i < faces.size(); i++) {
		builder.Add(shell, faces[i]);
		//this->Shape.setValue(shell);
	}
	//this->Shape.setValue(builder.sh);

	//BRepBuilderAPI_MakeShell myShell(gs);
	//const TopoDS_Shell& td = gs.sh;

	/*TopoDS_Solid mysolid;
	builder.MakeSolid(mysolid);
	builder.Add(mysolid, shell);*/

	BRepBuilderAPI_MakeSolid mySolid(shell);
	this->Shape.setValue(mySolid.Shape());


	return App::DocumentObject::StdReturn;
	}