TopoDS_Shape CreateRectangle::executeCreation() const
	{
		try
		{
			gp_Pnt pt1(point);
			gp_Pnt pt2(point.X() + width, point.Y(), point.Z());
			gp_Pnt pt3(point.X() + width, point.Y() + height, point.Z());
			gp_Pnt pt4(point.X(), point.Y() + height, point.Z());

			Handle(Geom_TrimmedCurve) segment1 = GC_MakeSegment(pt1, pt2);
			Handle(Geom_TrimmedCurve) segment2 = GC_MakeSegment(pt2, pt3);
			Handle(Geom_TrimmedCurve) segment3 = GC_MakeSegment(pt3, pt4);
			Handle(Geom_TrimmedCurve) segment4 = GC_MakeSegment(pt4, pt1);

			TopoDS_Edge edge1 = BRepBuilderAPI_MakeEdge(segment1);
			TopoDS_Edge edge2 = BRepBuilderAPI_MakeEdge(segment2);
			TopoDS_Edge edge3 = BRepBuilderAPI_MakeEdge(segment3);
			TopoDS_Edge edge4 = BRepBuilderAPI_MakeEdge(segment4);

			TopoDS_Wire wire  = BRepBuilderAPI_MakeWire(edge1 , edge2 , edge3, edge4);

			BRepBuilderAPI_MakeFace makeFace(wire);
			return makeFace.Shape();
		}
		catch(const StdFail_NotDone& ex)
		{
			throw Common::Exception(QObject::tr("Create rectangle error"));
		}
	}
Exemplo n.º 2
0
void occQt::makeRevol()
{
    gp_Ax1 anAxis;

    // revol a vertex result is an edge.
    anAxis.SetLocation(gp_Pnt(0.0, 70.0, 0.0));
    TopoDS_Vertex aVertex = BRepBuilderAPI_MakeVertex(gp_Pnt(2.0, 70.0, 0.0));
    TopoDS_Shape aRevolVertex = BRepPrimAPI_MakeRevol(aVertex, anAxis);
    Handle_AIS_Shape anAisRevolVertex = new AIS_Shape(aRevolVertex);

    // revol an edge result is a face.
    anAxis.SetLocation(gp_Pnt(8.0, 70.0, 0.0));
    TopoDS_Edge anEdge = BRepBuilderAPI_MakeEdge(gp_Pnt(6.0, 70.0, 0.0), gp_Pnt(6.0, 70.0, 5.0));
    TopoDS_Shape aRevolEdge = BRepPrimAPI_MakeRevol(anEdge, anAxis);
    Handle_AIS_Shape anAisRevolEdge = new AIS_Shape(aRevolEdge);

    // revol a wire result is a shell.
    anAxis.SetLocation(gp_Pnt(20.0, 70.0, 0.0));
    anAxis.SetDirection(gp::DY());

    TopoDS_Edge aCircleEdge = BRepBuilderAPI_MakeEdge(gp_Circ(gp_Ax2(gp_Pnt(15.0, 70.0, 0.0), gp::DZ()), 1.5));
    TopoDS_Wire aCircleWire = BRepBuilderAPI_MakeWire(aCircleEdge);
    TopoDS_Shape aRevolCircle = BRepPrimAPI_MakeRevol(aCircleWire, anAxis, M_PI_2);
    Handle_AIS_Shape anAisRevolCircle = new AIS_Shape(aRevolCircle);

    // revol a face result is a solid.
    anAxis.SetLocation(gp_Pnt(30.0, 70.0, 0.0));
    anAxis.SetDirection(gp::DY());

    TopoDS_Edge aEllipseEdge = BRepBuilderAPI_MakeEdge(gp_Elips(gp_Ax2(gp_Pnt(25.0, 70.0, 0.0), gp::DZ()), 3.0, 2.0));
    TopoDS_Wire aEllipseWire = BRepBuilderAPI_MakeWire(aEllipseEdge);
    TopoDS_Face aEllipseFace = BRepBuilderAPI_MakeFace(gp_Pln(gp::XOY()), aEllipseWire);
    TopoDS_Shape aRevolEllipse = BRepPrimAPI_MakeRevol(aEllipseFace, anAxis, M_PI_4);
    Handle_AIS_Shape anAisRevolEllipse = new AIS_Shape(aRevolEllipse);

    anAisRevolVertex->SetColor(Quantity_NOC_LIMEGREEN);
    anAisRevolEdge->SetColor(Quantity_NOC_LINEN);
    anAisRevolCircle->SetColor(Quantity_NOC_MAGENTA1);
    anAisRevolEllipse->SetColor(Quantity_NOC_MAROON);

    mContext->Display(anAisRevolVertex);
    mContext->Display(anAisRevolEdge);
    mContext->Display(anAisRevolCircle);
    mContext->Display(anAisRevolEllipse);
}
Exemplo n.º 3
0
TopoDS_Shape OCCPartFactory::makeCube( const Standard_Real width,
                                       const Standard_Real height,
                                       const Standard_Real depth)
{
    // define points
    gp_Pnt pt1( -width / 2.0, 0.0, 0.0 );
    gp_Pnt pt2( -width / 2.0, -depth / 2.0, 0.0 );
    gp_Pnt pt3( width / 2.0, -depth / 2.0, 0.0 );
    gp_Pnt pt4( width /2.0, 0.0, 0.0 );

    // define segments
    Handle_Geom_TrimmedCurve seg1 = GC_MakeSegment( pt1, pt2 );
    Handle_Geom_TrimmedCurve seg2 = GC_MakeSegment( pt2, pt3 );
    Handle_Geom_TrimmedCurve seg3 = GC_MakeSegment( pt3, pt4 );

    // make edge
    TopoDS_Edge edge1 = BRepBuilderAPI_MakeEdge( seg1 );
    TopoDS_Edge edge2 = BRepBuilderAPI_MakeEdge( seg2 );
    TopoDS_Edge edge3 = BRepBuilderAPI_MakeEdge( seg3 );

    // make wire
    TopoDS_Wire wire1 = BRepBuilderAPI_MakeWire( edge1, edge2, edge3 );

    //Complete Profile
    gp_Ax1 xAxis = gp::OX();
    gp_Trsf transfer;
    
    transfer.SetMirror( xAxis );
    
    BRepBuilderAPI_Transform aBRepTrsf( wire1 , transfer );
    TopoDS_Shape mirroredShape = aBRepTrsf.Shape();
    TopoDS_Wire mirroredWire1 = TopoDS::Wire( mirroredShape );
    
    BRepBuilderAPI_MakeWire mkWire;
    
    mkWire.Add( wire1 );
    mkWire.Add( mirroredWire1 );
    
    TopoDS_Wire wireProfile = mkWire.Wire();
    
    //Body : Prism the Profile
    TopoDS_Face faceProfile = BRepBuilderAPI_MakeFace( wireProfile );
    gp_Vec prismVec( 0.0 , 0.0 , height );
    
    TopoDS_Shape cube = BRepPrimAPI_MakePrism( faceProfile, prismVec);

//     cube.setMaterial( Graphic3d_NOM_JADE );

//     Handle_AIS_Shape shape = new AIS_Shape( cube );
//     shape->SetColor( Quantity_NOC_RED );

//     return shape;
    return cube;
}
Exemplo n.º 4
0
// Returns the chord line as a wire
TopoDS_Wire CCPACSWingProfile::GetChordLineWire() 
{
    // convert 2d chordline to 3d
    Handle(Geom2d_TrimmedCurve) chordLine = GetChordLine();
    gp_Pnt origin;
    gp_Dir yDir(0.0, 1.0, 0.0);
    gp_Pln xzPlane(origin, yDir);
    Handle(Geom_Curve) chordLine3d = GeomAPI::To3d(chordLine, xzPlane);
    TopoDS_Edge chordEdge = BRepBuilderAPI_MakeEdge(chordLine3d);
    TopoDS_Wire chordWire = BRepBuilderAPI_MakeWire(chordEdge);
    return chordWire;
}
Exemplo n.º 5
0
void occQt::makeExtrude()
{
    // prism a vertex result is an edge.
    TopoDS_Vertex aVertex = BRepBuilderAPI_MakeVertex(gp_Pnt(0.0, 60.0, 0.0));
    TopoDS_Shape aPrismVertex = BRepPrimAPI_MakePrism(aVertex, gp_Vec(0.0, 0.0, 5.0));
    Handle_AIS_Shape anAisPrismVertex = new AIS_Shape(aPrismVertex);

    // prism an edge result is a face.
    TopoDS_Edge anEdge = BRepBuilderAPI_MakeEdge(gp_Pnt(5.0, 60.0, 0.0), gp_Pnt(10.0, 60.0, 0.0));
    TopoDS_Shape aPrismEdge = BRepPrimAPI_MakePrism(anEdge, gp_Vec(0.0, 0.0, 5.0));
    Handle_AIS_Shape anAisPrismEdge = new AIS_Shape(aPrismEdge);

    // prism a wire result is a shell.
    gp_Ax2 anAxis;
    anAxis.SetLocation(gp_Pnt(16.0, 60.0, 0.0));

    TopoDS_Edge aCircleEdge = BRepBuilderAPI_MakeEdge(gp_Circ(anAxis, 3.0));
    TopoDS_Wire aCircleWire = BRepBuilderAPI_MakeWire(aCircleEdge);
    TopoDS_Shape aPrismCircle = BRepPrimAPI_MakePrism(aCircleWire, gp_Vec(0.0, 0.0, 5.0));
    Handle_AIS_Shape anAisPrismCircle = new AIS_Shape(aPrismCircle);

    // prism a face or a shell result is a solid.
    anAxis.SetLocation(gp_Pnt(24.0, 60.0, 0.0));
    TopoDS_Edge aEllipseEdge = BRepBuilderAPI_MakeEdge(gp_Elips(anAxis, 3.0, 2.0));
    TopoDS_Wire aEllipseWire = BRepBuilderAPI_MakeWire(aEllipseEdge);
    TopoDS_Face aEllipseFace = BRepBuilderAPI_MakeFace(gp_Pln(gp::XOY()), aEllipseWire);
    TopoDS_Shape aPrismEllipse = BRepPrimAPI_MakePrism(aEllipseFace, gp_Vec(0.0, 0.0, 5.0));
    Handle_AIS_Shape anAisPrismEllipse = new AIS_Shape(aPrismEllipse);

    anAisPrismVertex->SetColor(Quantity_NOC_PAPAYAWHIP);
    anAisPrismEdge->SetColor(Quantity_NOC_PEACHPUFF);
    anAisPrismCircle->SetColor(Quantity_NOC_PERU);
    anAisPrismEllipse->SetColor(Quantity_NOC_PINK);

    mContext->Display(anAisPrismVertex);
    mContext->Display(anAisPrismEdge);
    mContext->Display(anAisPrismCircle);
    mContext->Display(anAisPrismEllipse);
}
Exemplo n.º 6
0
void Werkstuck::BulkForm(float Xmin, float Ymin, float Zmin, float Xmax, float Ymax, float Zmax)
{

    Xstart=Xmax+10; //начальное положение инструмента
    Ystart=Ymax+10; // за заготовкой
    Zstart=Zmax+10;
    Xwz=Xstart;
    Ywz=Ystart;
    Zwz=Zstart;
    H0=Zmax;
    Xfmin=Xmin;
    Xfmax=Xmax;
    Yfmin=Ymin;
    Yfmax=Ymax;

    gp_Pnt punkt1(Xmin, Ymin, Zmin);
    gp_Pnt punkt2(Xmin, Ymax, Zmin);
    gp_Pnt punkt3(Xmax, Ymax, Zmin);
    gp_Pnt punkt4(Xmax, Ymin, Zmin);

    Handle(Geom_TrimmedCurve) aSeg1 = GC_MakeSegment(punkt1 , punkt2);
    Handle(Geom_TrimmedCurve) aSeg2 = GC_MakeSegment(punkt2 , punkt3);
    Handle(Geom_TrimmedCurve) aSeg3 = GC_MakeSegment(punkt3 , punkt4);
    Handle(Geom_TrimmedCurve) aSeg4 = GC_MakeSegment(punkt4 , punkt1);

    TopoDS_Edge aEdge1 = BRepBuilderAPI_MakeEdge(aSeg1);
    TopoDS_Edge aEdge2 = BRepBuilderAPI_MakeEdge(aSeg2);
    TopoDS_Edge aEdge3 = BRepBuilderAPI_MakeEdge(aSeg3);
    TopoDS_Edge aEdge4 = BRepBuilderAPI_MakeEdge(aSeg4);

    TopoDS_Wire Basis  = BRepBuilderAPI_MakeWire(aEdge1 , aEdge2 , aEdge3, aEdge4);

    TopoDS_Face FlacheBasis = BRepBuilderAPI_MakeFace(Basis);

    gp_Vec PrismVec(0 , 0 , Zmax-Zmin);

    TopoDS_Shape sBulkForm = BRepPrimAPI_MakePrism(FlacheBasis , PrismVec);

    WS = sBulkForm;

    //Erst_weg = true;
}
Exemplo n.º 7
0
// Returns the point where the distance between the selected fuselage and the ground is at minimum.
// The Fuselage could be turned with a given angle at at given axis, specified by a point and a direction.
gp_Pnt CCPACSFuselage::GetMinumumDistanceToGround(gp_Ax1 RAxis, double angle)
{

    TopoDS_Shape fusedFuselage = GetLoft()->Shape();

    // now rotate the fuselage
    gp_Trsf myTrsf;
    myTrsf.SetRotation(RAxis, angle * M_PI / 180.);
    BRepBuilderAPI_Transform xform(fusedFuselage, myTrsf);
    fusedFuselage = xform.Shape();

    // build cutting plane for intersection
    // We move the "ground" to "-1000" to be sure it is _under_ the fuselage
    gp_Pnt p1(-1.0e7, -1.0e7, -1000);
    gp_Pnt p2( 1.0e7, -1.0e7, -1000);
    gp_Pnt p3( 1.0e7,  1.0e7, -1000);
    gp_Pnt p4(-1.0e7,  1.0e7, -1000);

    Handle(Geom_TrimmedCurve) shaft_line1 = GC_MakeSegment(p1,p2);
    Handle(Geom_TrimmedCurve) shaft_line2 = GC_MakeSegment(p2,p3);
    Handle(Geom_TrimmedCurve) shaft_line3 = GC_MakeSegment(p3,p4);
    Handle(Geom_TrimmedCurve) shaft_line4 = GC_MakeSegment(p4,p1);

    TopoDS_Edge shaft_edge1 = BRepBuilderAPI_MakeEdge(shaft_line1);
    TopoDS_Edge shaft_edge2 = BRepBuilderAPI_MakeEdge(shaft_line2);
    TopoDS_Edge shaft_edge3 = BRepBuilderAPI_MakeEdge(shaft_line3);
    TopoDS_Edge shaft_edge4 = BRepBuilderAPI_MakeEdge(shaft_line4);

    TopoDS_Wire shaft_wire = BRepBuilderAPI_MakeWire(shaft_edge1, shaft_edge2, shaft_edge3, shaft_edge4);
    TopoDS_Face shaft_face = BRepBuilderAPI_MakeFace(shaft_wire);

    // calculate extrema
    BRepExtrema_DistShapeShape extrema(fusedFuselage, shaft_face);
    extrema.Perform();

    return extrema.PointOnShape1(1);
}
Exemplo n.º 8
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);
}
Exemplo n.º 9
0
	QString Dr=*(parameterList["PARIMD0"]);
	x=LVPS_Utility::ToDouble(Dr);
	Dr=*(parameterList["PARIMD1"]);
	y=LVPS_Utility::ToDouble(Dr);

	Dr=*(parameterList["PARIMD2"]);
	double length=LVPS_Utility::ToDouble(Dr);
	Dr=*(parameterList["PARIMD3"]);
	double con=LVPS_Utility::ToDouble(Dr);

	gp_Pnt A=gp_Pnt(x+length/2,y,0);
	gp_Pnt B=gp_Pnt(x-length/2,y,0);
	
	TopoDS_Edge aEdge1 = BRepBuilderAPI_MakeEdge(A , B);
	Shape = BRepBuilderAPI_MakeWire(aEdge1);
	gp_Trsf trsf;
	trsf.SetRotation(gp_Ax1(gp_Pnt(x,y,0),gp_Dir(0,0,1)),con);
	Shape = BRepBuilderAPI_Transform(Shape,trsf);
	
	myAISShape = new AIS_Shape (Shape);
	myAISShape->SetMaterial (Graphic3d_NOM_PLASTIC);
	SetColor(myAISShape);

	return 0;
};

LVPS_GraphicModel* LVPS_Lined::Clone()
{
	return (LVPS_GraphicModel*)(new LVPS_Lined());
}
Exemplo n.º 10
0
BRLTopo::BRLTopo(struct rt_tgc_internal *tgc)
{
    /*  We use the same names as BRL-CAD, but use 4 vertices on the edges.
        These additional vertices have their letter repeated and the
        direction vector inverted.
     */
    gp_Pnt v(scale*tgc->v[0], scale*tgc->v[1], scale*tgc->v[2]);
    gp_Pnt a(
        scale*(v.Coord(1)+tgc->a[0]), 
        scale*(v.Coord(2)+tgc->a[1]), 
        scale*(v.Coord(3)+tgc->a[2]));
    gp_Pnt b(
        scale*(v.Coord(1)+tgc->b[0]), 
        scale*(v.Coord(2)+tgc->b[1]), 
        scale*(v.Coord(3)+tgc->b[2]));
    gp_Pnt aa(
        scale*(v.Coord(1)-tgc->a[0]), 
        scale*(v.Coord(2)-tgc->a[1]), 
        scale*(v.Coord(3)-tgc->a[2]));
    gp_Pnt bb(
        scale*(v.Coord(1)-tgc->b[0]), 
        scale*(v.Coord(2)-tgc->b[1]), 
        scale*(v.Coord(3)-tgc->b[2]));
    Handle(Geom_Ellipse) top;
    if(v.SquareDistance(a)<v.SquareDistance(b))
        top=GC_MakeEllipse(b, aa, v); 
    else
        top=GC_MakeEllipse(a, b, v); 
    TopoDS_Edge e_t[4];
    e_t[0]=BRepBuilderAPI_MakeEdge(top,a,b);
    e_t[1]=BRepBuilderAPI_MakeEdge(top,b,aa);
    e_t[2]=BRepBuilderAPI_MakeEdge(top,aa,bb);
    e_t[3]=BRepBuilderAPI_MakeEdge(top,bb,a);

    gp_Pnt h(
        scale*(v.Coord(1)+tgc->h[0]), 
        scale*(v.Coord(2)+tgc->h[1]), 
        scale*(v.Coord(3)+tgc->h[2]));
    gp_Pnt c(
        scale*(h.Coord(1)+tgc->c[0]), 
        scale*(h.Coord(2)+tgc->c[1]), 
        scale*(h.Coord(3)+tgc->c[2]));
    gp_Pnt d(
        scale*(h.Coord(1)+tgc->d[0]), 
        scale*(h.Coord(2)+tgc->d[1]), 
        scale*(h.Coord(3)+tgc->d[2]));
    gp_Pnt cc(
        scale*(h.Coord(1)-tgc->c[0]), 
        scale*(h.Coord(2)-tgc->c[1]), 
        scale*(h.Coord(3)-tgc->c[2]));
    gp_Pnt dd(
        scale*(h.Coord(1)-tgc->d[0]), 
        scale*(h.Coord(2)-tgc->d[1]), 
        scale*(h.Coord(3)-tgc->d[2]));
    Handle(Geom_Ellipse) bottom;
    if(h.SquareDistance(c)<h.SquareDistance(d))
        bottom=GC_MakeEllipse(d, cc, h); 
    else
        bottom=GC_MakeEllipse(c, d, h); 
    TopoDS_Edge e_b[4];
    e_b[0]=BRepBuilderAPI_MakeEdge(bottom,c,d);
    e_b[1]=BRepBuilderAPI_MakeEdge(bottom,d,cc);
    e_b[2]=BRepBuilderAPI_MakeEdge(bottom,cc,dd);
    e_b[3]=BRepBuilderAPI_MakeEdge(bottom,dd,c);

#if 1
    BRepOffsetAPI_ThruSections BB(Standard_True);
    BB.AddWire(BRepBuilderAPI_MakeWire(e_t[0],e_t[1],e_t[2],e_t[3]));
    BB.AddWire(BRepBuilderAPI_MakeWire(e_b[0],e_b[1],e_b[2],e_b[3]));
    BB.CheckCompatibility(Standard_False);
    shape=BB.Shape();
#else
    BRep_Builder BB;
    TopoDS_Compound result;
    BB.MakeCompound(result);
    for(int i=0;i<4;i++) {
        BB.Add(result,e_t[i]);
        BB.Add(result,e_b[i]);
    }
    shape=result;
#endif
}
Exemplo n.º 11
0
////////////////////////////////////////////////////////////////////////////////
// Construct TopoDS from BRL-CAD data
////////////////////////////////////////////////////////////////////////////////
BRLTopo::BRLTopo(struct rt_arb_internal *arb)
{
    TopoDS_Vertex v[8];
    for(int i=0;i<8;i++)
        v[i]=BRepBuilderAPI_MakeVertex(
            gp_Pnt(
                scale*arb->pt[i][0],
                scale*arb->pt[i][1],
                scale*arb->pt[i][2]
            )
        );

    int arbn;
    if(!BRepTools::Compare(v[6],v[7]))
        arbn=8;
    else if(!BRepTools::Compare(v[4],v[5]))
        arbn=7;
    else if(!BRepTools::Compare(v[5],v[6]))
        arbn=6;
    else if(!BRepTools::Compare(v[0],v[3]))
        arbn=5;
    else
        arbn=4;

    switch(arbn) {
    case 8: {
        TopoDS_Edge e[12];
        for(int i=0;i<4;i++) { 
            e[i]=BRepBuilderAPI_MakeEdge(v[i],v[(i+1)%4]);
            e[i+4]=BRepBuilderAPI_MakeEdge(v[i+4],v[(i+1)%4+4]);
            e[i+8]=BRepBuilderAPI_MakeEdge(v[i],v[(i+4)%8]);
        }

        TopoDS_Wire w[6];
        w[0]=BRepBuilderAPI_MakeWire(e[0],e[1],e[2],e[3]);
        w[1]=BRepBuilderAPI_MakeWire(e[4],e[5],e[6],e[7]);
        w[2]=BRepBuilderAPI_MakeWire(e[0],e[9],e[4],e[8]);
        w[3]=BRepBuilderAPI_MakeWire(e[1],e[10],e[5],e[9]);
        w[4]=BRepBuilderAPI_MakeWire(e[2],e[11],e[6],e[10]);
        w[5]=BRepBuilderAPI_MakeWire(e[3],e[8],e[7],e[11]);

        BRep_Builder BB;
        TopoDS_Shell shell;
        BB.MakeShell(shell);
        for(int i=0;i<6;i++) {
            TopoDS_Face f=BRepBuilderAPI_MakeFace(w[i]);
            BB.Add(shell,i? f.Reversed():f);
        }
        TopoDS_Solid solid;
        BB.MakeSolid(solid);
        BB.Add(solid,shell);
        ShapeFix_Solid sf(solid);
        sf.Perform();
        shape=sf.Solid();
        } break;
    case 6: {
        TopoDS_Edge e[9];
        e[0]=BRepBuilderAPI_MakeEdge(v[0],v[1]);
        e[1]=BRepBuilderAPI_MakeEdge(v[1],v[2]);
        e[2]=BRepBuilderAPI_MakeEdge(v[2],v[3]);
        e[3]=BRepBuilderAPI_MakeEdge(v[3],v[0]);
        e[4]=BRepBuilderAPI_MakeEdge(v[0],v[4]);
        e[5]=BRepBuilderAPI_MakeEdge(v[1],v[4]);
        e[6]=BRepBuilderAPI_MakeEdge(v[2],v[6]);
        e[7]=BRepBuilderAPI_MakeEdge(v[3],v[6]);
        e[8]=BRepBuilderAPI_MakeEdge(v[4],v[6]);

        TopoDS_Wire w[5];
        w[0]=BRepBuilderAPI_MakeWire(e[0],e[1],e[2],e[3]);
        w[1]=BRepBuilderAPI_MakeWire(e[0],e[4],e[5]);
        w[2]=BRepBuilderAPI_MakeWire(e[2],e[6],e[7]);
        w[3]=BRepBuilderAPI_MakeWire(e[3],e[4],e[8],e[7]);
        w[4]=BRepBuilderAPI_MakeWire(e[1],e[5],e[8],e[6]);

        BRep_Builder BB;
#if 0
        TopoDS_Compound result;
        BB.MakeCompound(result);
        for(int i=0;i<5;i++) {
            BB.Add(result,BRepBuilderAPI_MakeFace(w[i]));
        }
        shape=result;
#else
        TopoDS_Shell shell;
        BB.MakeShell(shell);
        for(int i=0;i<5;i++) {
            TopoDS_Face f=BRepBuilderAPI_MakeFace(w[i]);
            BB.Add(shell,f); //i? f:f.Reversed());
        }
        TopoDS_Solid solid;
        BB.MakeSolid(solid);
        BB.Add(solid,shell);
        ShapeFix_Solid sf(solid);
        sf.Perform();
        shape=sf.Solid();
#endif
        } break;
    default:
        cerr << "Unhandled arb8 type n=" << arbn << '\n';
    }
}
Exemplo n.º 12
0
//=======================================================================
//function : MakeScaledPrism
//purpose  :
//=======================================================================
TopoDS_Shape GEOMImpl_PrismDriver::MakeScaledPrism (const TopoDS_Shape& theShapeBase,
                                                    const gp_Vec&       theVector,
                                                    const Standard_Real theScaleFactor,
                                                    const gp_Pnt&       theCDG,
                                                    bool                isCDG)
{
  TopoDS_Shape aShape;
  BRep_Builder B;

  // 1. aCDG = geompy.MakeCDG(theBase)
  gp_Pnt aCDG = theCDG;
  if (!isCDG) {
    gp_Ax3 aPos = GEOMImpl_IMeasureOperations::GetPosition(theShapeBase);
    aCDG = aPos.Location();
  }
  TopoDS_Shape aShapeCDG_1 = BRepBuilderAPI_MakeVertex(aCDG).Shape();

  // Process case of several given shapes
  if (theShapeBase.ShapeType() == TopAbs_COMPOUND ||
      theShapeBase.ShapeType() == TopAbs_SHELL) {
    int nbSub = 0;
    TopoDS_Shape aShapeI;
    TopoDS_Compound aCompound;
    B.MakeCompound(aCompound);
    TopoDS_Iterator It (theShapeBase, Standard_True, Standard_True);
    for (; It.More(); It.Next()) {
      nbSub++;
      aShapeI = MakeScaledPrism(It.Value(), theVector, theScaleFactor, aCDG, true);
      B.Add(aCompound, aShapeI);
    }
    if (nbSub == 1)
      aShape = aShapeI;
    else if (nbSub > 1)
      aShape = GEOMImpl_GlueDriver::GlueFaces(aCompound, Precision::Confusion(), Standard_True);
    return aShape;
  }

  // 2. Scale = geompy.MakeScaleTransform(theBase, aCDG, theScaleFactor)

  // Bug 6839: Check for standalone (not included in faces) degenerated edges
  TopTools_IndexedDataMapOfShapeListOfShape aEFMap;
  TopExp::MapShapesAndAncestors(theShapeBase, TopAbs_EDGE, TopAbs_FACE, aEFMap);
  Standard_Integer i, nbE = aEFMap.Extent();
  for (i = 1; i <= nbE; i++) {
    TopoDS_Shape anEdgeSh = aEFMap.FindKey(i);
    if (BRep_Tool::Degenerated(TopoDS::Edge(anEdgeSh))) {
      const TopTools_ListOfShape& aFaces = aEFMap.FindFromIndex(i);
      if (aFaces.IsEmpty())
        Standard_ConstructionError::Raise
          ("Scaling aborted : cannot scale standalone degenerated edge");
    }
  }

  // Perform Scaling
  gp_Trsf aTrsf;
  aTrsf.SetScale(aCDG, theScaleFactor);
  BRepBuilderAPI_Transform aBRepTrsf (theShapeBase, aTrsf, Standard_False);
  TopoDS_Shape aScale = aBRepTrsf.Shape();

  // 3. aBase2 = geompy.MakeTranslationVectorDistance(Scale, theVec, theH)
  gp_Trsf aTrsf3;
  aTrsf3.SetTranslation(theVector);
  TopLoc_Location aLocOrig = aScale.Location();
  gp_Trsf aTrsfOrig = aLocOrig.Transformation();
  TopLoc_Location aLocRes (aTrsf3 * aTrsfOrig);
  TopoDS_Shape aBase2 = aScale.Located(aLocRes);

  // 4. aCDG_2 = geompy.MakeTranslationVectorDistance(aCDG, theVec, theH)
  gp_Pnt aCDG_2 = aCDG.Translated(theVector);
  TopoDS_Shape aShapeCDG_2 = BRepBuilderAPI_MakeVertex(aCDG_2).Shape();

  // 5. Vector = geompy.MakeVector(aCDG, aCDG_2)
  TopoDS_Shape aShapeVec = BRepBuilderAPI_MakeEdge(aCDG, aCDG_2).Shape();
  TopoDS_Edge anEdge = TopoDS::Edge(aShapeVec);
  TopoDS_Wire aWirePath = BRepBuilderAPI_MakeWire(anEdge);

  // 6. aPrism = geompy.MakePipeWithDifferentSections([theBase, aBase2], [aCDG, aCDG_2], Vector, False, False)
  Handle(TopTools_HSequenceOfShape) aBases = new TopTools_HSequenceOfShape;
  aBases->Append(theShapeBase);
  aBases->Append(aBase2);

  Handle(TopTools_HSequenceOfShape) aLocs = new TopTools_HSequenceOfShape;
  aLocs->Append(aShapeCDG_1);
  aLocs->Append(aShapeCDG_2);

  aShape = GEOMImpl_PipeDriver::CreatePipeWithDifferentSections(aWirePath, aBases, aLocs, false, false);

  // 7. Make a solid, if possible
  if (theShapeBase.ShapeType() == TopAbs_FACE) {
    BRepBuilderAPI_Sewing aSewing (Precision::Confusion()*10.0);
    TopExp_Explorer expF (aShape, TopAbs_FACE);
    Standard_Integer ifa = 0;
    for (; expF.More(); expF.Next()) {
      aSewing.Add(expF.Current());
      ifa++;
    }
    if (ifa > 0) {
      aSewing.Perform();
      TopoDS_Shape aShell;

      TopoDS_Shape sh = aSewing.SewedShape();
      if (sh.ShapeType() == TopAbs_FACE && ifa == 1) {
        // case for creation of shell from one face
        TopoDS_Shell ss;
        B.MakeShell(ss);
        B.Add(ss,sh);
        aShell = ss;
      }
      else {
        TopExp_Explorer exp (sh, TopAbs_SHELL);
        Standard_Integer ish = 0;
        for (; exp.More(); exp.Next()) {
          aShell = exp.Current();
          ish++;
        }
        if (ish != 1)
          aShell = sh;
      }
      BRepCheck_Shell chkShell (TopoDS::Shell(aShell));
      if (chkShell.Closed() == BRepCheck_NoError) {
        TopoDS_Solid Sol;
        B.MakeSolid(Sol);
        B.Add(Sol, aShell);
        BRepClass3d_SolidClassifier SC (Sol);
        SC.PerformInfinitePoint(Precision::Confusion());
        if (SC.State() == TopAbs_IN) {
          B.MakeSolid(Sol);
          B.Add(Sol, aShell.Reversed());
        }
        aShape = Sol;
      }
    }
  }

  return aShape;
}
Exemplo n.º 13
0
//=======================================================================
//function : Execute
//purpose  :
//======================================================================= 
Standard_Integer GEOMImpl_PrismDriver::Execute(TFunction_Logbook& log) const
{
  if (Label().IsNull()) return 0;    
  Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());

  GEOMImpl_IPrism aCI (aFunction);
  Standard_Integer aType = aFunction->GetType();

  TopoDS_Shape aShape;

  if (aType == PRISM_BASE_VEC_H || aType == PRISM_BASE_VEC_H_2WAYS) {
	Handle(GEOM_Function) aRefBase = aCI.GetBase();
	Handle(GEOM_Function) aRefVector = aCI.GetVector();
	TopoDS_Shape aShapeBase = aRefBase->GetValue();
	TopoDS_Shape aShapeVec = aRefVector->GetValue();
	if (aShapeVec.ShapeType() == TopAbs_EDGE) {
	  TopoDS_Edge anE = TopoDS::Edge(aShapeVec);
	  TopoDS_Vertex V1, V2;
	  TopExp::Vertices(anE, V1, V2, Standard_True);
	  if (!V1.IsNull() && !V2.IsNull()) {
		gp_Vec aV (BRep_Tool::Pnt(V1), BRep_Tool::Pnt(V2));
		if (Abs(aCI.GetH()) < Precision::Confusion()) {
		  Standard_ConstructionError::Raise("Absolute value of prism height is too small");
		}
		if (aV.Magnitude() > Precision::Confusion()) {
		  aV.Normalize();
          if (aType != PRISM_BASE_DXDYDZ_2WAYS && aCI.GetScale() > Precision::Confusion()) {
            aShape = MakeScaledPrism(aShapeBase, aV * aCI.GetH(), aCI.GetScale());
          }
          else {
		  if (aType == PRISM_BASE_VEC_H_2WAYS) {
			gp_Trsf aTrsf;
			aTrsf.SetTranslation( (-aV) * aCI.GetH() );
			BRepBuilderAPI_Transform aTransformation(aShapeBase, aTrsf, Standard_False);
			aShapeBase = aTransformation.Shape();
			aCI.SetH( aCI.GetH()*2 );
		  }
		  aShape = BRepPrimAPI_MakePrism(aShapeBase, aV * aCI.GetH(), Standard_False).Shape();
		}
	  }
	}
    }
  } else if (aType == PRISM_BASE_TWO_PNT || aType == PRISM_BASE_TWO_PNT_2WAYS) {
	Handle(GEOM_Function) aRefBase = aCI.GetBase();
	Handle(GEOM_Function) aRefPnt1 = aCI.GetFirstPoint();
	Handle(GEOM_Function) aRefPnt2 = aCI.GetLastPoint();
	TopoDS_Shape aShapeBase = aRefBase->GetValue();
	TopoDS_Shape aShapePnt1 = aRefPnt1->GetValue();
	TopoDS_Shape aShapePnt2 = aRefPnt2->GetValue();
	if (aShapePnt1.ShapeType() == TopAbs_VERTEX &&
		aShapePnt2.ShapeType() == TopAbs_VERTEX) {
	  TopoDS_Vertex V1 = TopoDS::Vertex(aShapePnt1);
	  TopoDS_Vertex V2 = TopoDS::Vertex(aShapePnt2);
	  if (!V1.IsNull() && !V2.IsNull()) {
		gp_Vec aV (BRep_Tool::Pnt(V1), BRep_Tool::Pnt(V2));
		if (aV.Magnitude() > gp::Resolution()) {
          if (aType != PRISM_BASE_DXDYDZ_2WAYS && aCI.GetScale() > Precision::Confusion()) {
            aShape = MakeScaledPrism(aShapeBase, aV, aCI.GetScale());
          }
          else {
		  if (aType == PRISM_BASE_TWO_PNT_2WAYS) {
			gp_Trsf aTrsf;
			aTrsf.SetTranslation(-aV);
			BRepBuilderAPI_Transform aTransformation(aShapeBase, aTrsf, Standard_False);
			aShapeBase = aTransformation.Shape();
			aV = aV * 2;
		  }
		  aShape = BRepPrimAPI_MakePrism(aShapeBase, aV, Standard_False).Shape();
		}
	  }
	}
  }
  }
  else if (aType == PRISM_BASE_VEC_H_ANG) {
	Handle(GEOM_Function) aRefBase = aCI.GetBase();
	Handle(GEOM_Function) aRefVector = aCI.GetVector();
	TopoDS_Shape aShapeBase = aRefBase->GetValue();
	TopoDS_Shape aShapeVec = aRefVector->GetValue();
	if (aShapeVec.ShapeType() == TopAbs_EDGE) {
	  TopoDS_Edge anE = TopoDS::Edge(aShapeVec);
	  TopoDS_Vertex V1, V2;
	  TopExp::Vertices(anE, V1, V2, Standard_True);
	  if (!V1.IsNull() && !V2.IsNull()) {
		gp_Vec aV (BRep_Tool::Pnt(V1), BRep_Tool::Pnt(V2));
		if (Abs(aCI.GetH()) < Precision::Confusion()) {
		  Standard_ConstructionError::Raise("Absolute value of prism height is too small");
		}
		if (aV.Magnitude() > Precision::Confusion()) {
		  aV.Normalize();
		  TopAbs_ShapeEnum myBaseType = aShapeBase.ShapeType();

		  if (  (myBaseType != TopAbs_EDGE) && (myBaseType != TopAbs_WIRE) &&
				(myBaseType != TopAbs_FACE) && (myBaseType != TopAbs_SHELL) )
			Standard_ConstructionError::Raise("Base shape type is not of the requested type");

		  if (myBaseType == TopAbs_EDGE)
			aShapeBase = BRepBuilderAPI_MakeWire(TopoDS::Edge(aShapeBase));

		  BRepOffsetAPI_MakeDraft aDraft(aShapeBase, aV, aCI.GetAngle());

		  if (aCI.GetAngle() < 0.)
		    aDraft.SetDraft(Standard_True);

		  aDraft.Perform(aCI.GetH());
		  aShape = aDraft.Shape();
		}
	  }
	}
  } else if (aType == PRISM_BASE_DXDYDZ || aType == PRISM_BASE_DXDYDZ_2WAYS) {
    Handle(GEOM_Function) aRefBase = aCI.GetBase();
    TopoDS_Shape aShapeBase = aRefBase->GetValue();
    gp_Vec aV (aCI.GetDX(), aCI.GetDY(), aCI.GetDZ());
    if (aV.Magnitude() > gp::Resolution()) {
      if (aType != PRISM_BASE_DXDYDZ_2WAYS && aCI.GetScale() > Precision::Confusion()) {
        aShape = MakeScaledPrism(aShapeBase, aV, aCI.GetScale());
      }
      else {
        if (aType == PRISM_BASE_DXDYDZ_2WAYS) {
	  gp_Trsf aTrsf;
	  aTrsf.SetTranslation(-aV);
	  BRepBuilderAPI_Transform aTransformation(aShapeBase, aTrsf, Standard_False);
	  aShapeBase = aTransformation.Shape();
	  aV = aV * 2;
	}
      aShape = BRepPrimAPI_MakePrism(aShapeBase, aV, Standard_False).Shape();
    }
    }
  }

  if (aShape.IsNull()) return 0;

  TopoDS_Shape aRes = GEOMImpl_IShapesOperations::CompsolidToCompound(aShape);
  aFunction->SetValue(aRes);

  log.SetTouched(Label()); 

  return 1;    
}
Exemplo n.º 14
0
bool IfcGeom::Kernel::convert(const IfcSchema::IfcSweptDiskSolid* l, TopoDS_Shape& shape) {
    TopoDS_Wire wire, section1, section2;

    bool hasInnerRadius = l->hasInnerRadius();

    if (!convert_wire(l->Directrix(), wire)) {
        return false;
    }

    gp_Ax2 directrix;
    {
        gp_Pnt directrix_origin;
        gp_Vec directrix_tangent;
        TopExp_Explorer exp(wire, TopAbs_EDGE);
        TopoDS_Edge edge = TopoDS::Edge(exp.Current());
        double u0, u1;
        Handle(Geom_Curve) crv = BRep_Tool::Curve(edge, u0, u1);
        crv->D1(u0, directrix_origin, directrix_tangent);
        directrix = gp_Ax2(directrix_origin, directrix_tangent);
    }

    const double r1 = l->Radius() * getValue(GV_LENGTH_UNIT);
    Handle(Geom_Circle) circle = new Geom_Circle(directrix, r1);
    section1 = BRepBuilderAPI_MakeWire(BRepBuilderAPI_MakeEdge(circle));

    if (hasInnerRadius) {
        const double r2 = l->InnerRadius() * getValue(GV_LENGTH_UNIT);
        if (r2 < getValue(GV_PRECISION)) {
            // Subtraction of pipes with small radii is unstable.
            hasInnerRadius = false;
        } else {
            Handle(Geom_Circle) circle = new Geom_Circle(directrix, r2);
            section2 = BRepBuilderAPI_MakeWire(BRepBuilderAPI_MakeEdge(circle));
        }
    }

    // NB: Note that StartParam and EndParam param are ignored and the assumption is
    // made that the parametric range over which to be swept matches the IfcCurve in
    // its entirety.
    // NB2: Contrary to IfcSurfaceCurveSweptAreaSolid the transition mode has been
    // set to create round corners as this has proven to work better with the types
    // of directrices encountered, which do not necessarily conform to a surface.
    {   BRepOffsetAPI_MakePipeShell builder(wire);
        builder.Add(section1);
        builder.SetTransitionMode(BRepBuilderAPI_RoundCorner);
        builder.Build();
        builder.MakeSolid();
        shape = builder.Shape();
    }

    if (hasInnerRadius) {
        BRepOffsetAPI_MakePipeShell builder(wire);
        builder.Add(section2);
        builder.SetTransitionMode(BRepBuilderAPI_RoundCorner);
        builder.Build();
        builder.MakeSolid();
        TopoDS_Shape inner = builder.Shape();

        BRepAlgoAPI_Cut brep_cut(shape, inner);
        bool is_valid = false;
        if (brep_cut.IsDone()) {
            TopoDS_Shape result = brep_cut;

            ShapeFix_Shape fix(result);
            fix.Perform();
            result = fix.Shape();

            is_valid = BRepCheck_Analyzer(result).IsValid() != 0;
            if (is_valid) {
                shape = result;
            }
        }

        if (!is_valid) {
            Logger::Message(Logger::LOG_WARNING, "Failed to subtract inner radius void for:", l->entity);
        }
    }

    return true;
}
Exemplo n.º 15
0
void Werkstuck::LY(float endPunkt, float Rwz, float Lwz, float Rwz2) // прямое фрезерование по оси Х
// endPunkt - конечная точка
{
    if (Zwz<H0) {
        gp_Pnt punkt1(Xwz-Rwz,Ywz,Zwz);
        gp_Pnt punkt2(Xwz+Rwz,Ywz,Zwz);
        gp_Pnt punkt3(Xwz+Rwz,endPunkt,Zwz);
        gp_Pnt punkt4(Xwz,endPunkt,Zwz);
        if (endPunkt>=Ywz) punkt4.SetY(endPunkt+Rwz);
        else punkt4.SetY(endPunkt-Rwz);

        gp_Pnt punkt5(Xwz-Rwz,endPunkt,Zwz);


        Handle(Geom_TrimmedCurve) aSeg1 = GC_MakeSegment(punkt1 , punkt2);
        Handle(Geom_TrimmedCurve) aSeg2 = GC_MakeSegment(punkt2 , punkt3);
        Handle(Geom_TrimmedCurve) aSeg3 = GC_MakeArcOfCircle(punkt3,punkt4 ,punkt5);
        Handle(Geom_TrimmedCurve) aSeg4 = GC_MakeSegment(punkt5 , punkt1);

        TopoDS_Edge aEdge1 = BRepBuilderAPI_MakeEdge(aSeg1);
        TopoDS_Edge aEdge2 = BRepBuilderAPI_MakeEdge(aSeg2);
        TopoDS_Edge aEdge3 = BRepBuilderAPI_MakeEdge(aSeg3);
        TopoDS_Edge aEdge4 = BRepBuilderAPI_MakeEdge(aSeg4);

        TopoDS_Wire Basis  = BRepBuilderAPI_MakeWire(aEdge1 , aEdge2 , aEdge3, aEdge4);

        TopoDS_Face FlacheBasis = BRepBuilderAPI_MakeFace(Basis);


        if (firstRun) {
            fBasis = FlacheBasis;
            firstRun = false;
        } else {

            fBasis = BRepAlgo_Fuse(fBasis, FlacheBasis);

            gp_Vec PrismVec(0 , 0 , Lwz);

            TopoDS_Shape sLY = BRepPrimAPI_MakePrism(fBasis , PrismVec);

            if (Rwz2>0) {
                BRepFilletAPI_MakeFillet mkFillet(sLY);
                TopExp_Explorer aEdgeExplorer(sLY , TopAbs_EDGE);

                while(aEdgeExplorer.More()) {
                    TopoDS_Edge aEdge = TopoDS::Edge(aEdgeExplorer.Current());
                    mkFillet.Add(Rwz2 , aEdge);
                    aEdgeExplorer.Next();
                }
                sLY = mkFillet.Shape();
            }

            WS = BRepAlgo_Cut(WS,sLY);

            firstRun = true;
        }

        /*gp_Vec PrismVec(0 , 0 , Lwz);

        TopoDS_Shape sLY = BRepPrimAPI_MakePrism(FlacheBasis , PrismVec);

        if (Rwz2>0) {
            BRepFilletAPI_MakeFillet mkFillet(sLY);
            TopExp_Explorer aEdgeExplorer(sLY , TopAbs_EDGE);

            while(aEdgeExplorer.More()){
            TopoDS_Edge aEdge = TopoDS::Edge(aEdgeExplorer.Current());
            mkFillet.Add(Rwz2 , aEdge);
            aEdgeExplorer.Next();
            }
            sLY = mkFillet.Shape();
        }

        WS = BRepAlgo_Cut(WS,sLY);*/

    }
    Ywz=endPunkt;
}
Exemplo n.º 16
0
void rs274emc::slotOutputProtoCode() 
//creates g-Code and saves results to a file
{
    //view Path->projectedPasses
    cout<<"Path->projectedPasses.size(" <<Path->projectedPasses.size()<<")"<<endl; //AK
    for(uint i=0;i < Path->projectedPasses.size(); i++){
	for(uint j=0;j < Path->projectedPasses.at(i).facesUsed.size(); j++)  //AK testing//AK testing
	    cout<<"Path->projectedPasses.at("<<i<<").facesUsed.size("<<j<<")" <<endl; //AK
    }
    
    //check if Toolpath is created
    bool checkVault=false;
    int readVault=3;
    checkVault = (staticVaultComputed(readVault));
    
    if (!checkVault) {
	QMessageBox::warning( 0, "Warning", "rs274emc::slotOutputProtoCode - Compute path first !");
	return;}
    
    
    /*for testing only
    else{
	QMessageBox::warning( 0, "Info", "rs274emc::slotOutputProtoCode - pathComputed==true");
	return;}*/
    
   //open File to write g-Code
    FILE *outG;
    
    //new for enumerating files
    static int M=0;
    char format[] = "G-Code-%i.txt"; 

    char dir[]="G-Code files";
     char parentdir[]="..";
    char filename[sizeof format+100]; 
    sprintf(filename,format,M); 
   // outG = fopen(filename,"w"); 
    chdir(dir);
        outG = fopen(filename,"w"); 
	M++;

    
    
    /* //create pop-up window and give filename and folder manually via gui
    QString fileName = QFileDialog::getSaveFileName(QString::null, "G-code (*.ngc)", 0, 0);
    outG = fopen (fileName, "w");//AK
    //outG = fopen ((const char*)fileName, "w");
    if (outG == NULL) {
	QMessageBox::warning( 0, "Warning", "Can't open that file for writing!");
	return;
// uncomment *1*    
}*/
    
    //set pathComputed false
    checkVault=(staticVaultComputed(2));
    
    //write file content
   
    int setZero=0;
    int stCounter=0; 

     gp_Pnt Cal1,Cal2,Cal1L,Cal2L,ToGo,ToGoL,Start,Buffer,veryFirst,verySecond,A,B,C,D;
   
     //g-code header     
     fprintf(outG,"%%_N_TESTMAZE_CAMOCC)\n");
     fprintf(outG,"; File %s created by cam-occ\n",filename); //ought to insert model's file name and the face ID into comment also...
     //  *1*  fprintf(outG,"; File %s created by cam-occ\n",(const char*)fileName); //ought to insert model's file name and the face ID into comment also...
     fprintf(outG,"; Info Safe height for rapids= %f \n",safeHeight);  //safeHeight set in slotComputeSimplePathOnFace() above  // edited by AK
     fprintf(outG,"; Info Tool Diameter = %i \n",toolDia);
     fprintf(outG,"; Info Feed = %i\n",feed);
     fprintf(outG,"; Info Speed = %i \n",speed);
     fprintf(outG,"\n; cancel tool diameter compensation\n");
     fprintf(outG,"N%4i \t G40\n",stCounter+=10);//set cool compensation zero 
     fprintf(outG,"\n; turn on air cooling\n");
     fprintf(outG,"N%4i \t M71\n",stCounter+=10);//turn on air cooling
     fprintf(outG,"\n; move to home position\n"); 
     fprintf(outG,"N%4i \t G00 X  0.00 \t Y  0.00 \t Z 10.00\n",stCounter+=10); //float limited to 2 decimals, move to home position
     //fprintf(outG,"; tool change\n"); //float limited to 2 decimals
     //fprintf(outG,"N%4i \t G00\t Z100\n",stCounter+=10); //float limited to 2 decimals
     //fprintf(outG,"N%4i \tT4 \t D1 \tM6 \n",stCounter+=10); //float limited to 2 decimals
     fprintf(outG,"\n; speed \t feed \t spindle on clockwise\n");
     fprintf(outG,"N%4i \t S%i \tF%i \tM3 \n",stCounter+=10, speed, feed); //speed, feed spinle clockwise

    
    //missing in g-code
    // move to retract home base
    //switch on spindle
    //move fast to safety distance
    //set working feed
    //move to first point
    
  // Schruppen
      // Senken -2,5 F50
     // schneiden mit F120
    
  //Schlichten
      // Senken -1,5 F 50
      //schneiden mit F200
    
	    
    cout <<"Path->projectedPasses.size()="<< Path->projectedPasses.size() <<endl;	    
    //this loop processes the blue lines drawn on the face
    for (int j=0;j<Path->projectedPasses.size();j++){
	
	int checkLoop = setZero;
	
	cout <<"Test1"<<endl;
	    
	//explorer to decompose the shape and find all edges in shape section AK
	TopExp_Explorer Ex;
	int forCounter=0;
		
	for (Ex.Init(Path->projectedPasses.at(j).P,TopAbs_EDGE); Ex.More(); Ex.Next()) {
	    TopoDS_Wire W = BRepBuilderAPI_MakeWire(TopoDS::Edge(Ex.Current()));
	    TopoDS_Vertex E1,E2;
	    
	    cout <<"Test2"<<endl;
	  
	    //find endpoints of wire, E1 E2 from pathAlgo analyzation
	    TopExp::Vertices(W,E1,E2);
	 
	    // Get the 3D point for the vertex.
	    Cal1 = BRep_Tool::Pnt(E1);
	    Cal2 = BRep_Tool::Pnt(E2);
		
	    if(!forCounter){  // fitst wire decomposed in start- and endpoint
		Cal1L=Cal1;
		Cal2L=Cal2;
		    
		veryFirst=Cal1L;
		verySecond=Cal2L;
	    }
	    
	    if(forCounter){  //second and more wire decomposed
		//to calculate we have Start, ToGo, ToGoL,Cal1, Cal2
		    
		//connect next wire to Cal1L    
		if(comparePoints(Cal1L,Cal1)){
		    ToGoL=Cal1L;
		    ToGo=Cal2;
		    Start=Cal2L;    
		}
	
		if (comparePoints(Cal1L,Cal2)) {
		    ToGoL=Cal1L;
		    ToGo=Cal1;
		    Start=Cal2L;	
		}
		    
		//Connect next Wire to Cal2L
		if(comparePoints(Cal2L,Cal1)){
		    ToGoL=Cal2L;
		    ToGo=Cal2;
		    Start=Cal1L;
		}
		    
		if(comparePoints(Cal2L,Cal2)) {
		    ToGoL=Cal2;
		    ToGo=Cal1;
		    Start=Cal1L;
		}
		
		if(forCounter==1&& (!j)){
		    fprintf(outG,"\n; move to starting point (z) of first level and plunge \n"); //float limited to 2 decimals 
		    fprintf(outG,"N%4i \t G00 X%6.2f \t Y%6.2f \t Z%6.2f \n",stCounter+=10,Start.X(),Start.Y(),safeHeight); //float limited to 2 decimals
		    fprintf(outG,"N%4i \t G01 X%6.2f \t Y%6.2f \t Z%6.2f \t F50 \n",stCounter+=10,Start.X(),Start.Y(),Start.Z()); //float limited to 2 decimals
		    
		    fprintf(outG,"\n; move along tool-path (xy) of first level \n"); //float limited to 2 decimals 
		    fprintf(outG,"N%4i \t G01 X%6.2f \t Y%6.2f \t Z%6.2f \t F%i \n",stCounter+=10,ToGoL.X(),ToGoL.Y(),ToGoL.Z(), feed); //float limited to 2 decimals
		}
		
		if(forCounter==1 && j){
		    //move to first point of new level but in z offset
		    fprintf(outG,"\n; move to starting point (z) of next level and plunge\n"); //float limited to 2 decimals
		    fprintf(outG,"N%4i \t G01 X%6.2f \t Y%6.2f \t Z%6.2f \t F%i \n",stCounter+=10,Start.X(),Start.Y(),Buffer.Z(), feed); //float limited to 2 decimals
		    fprintf(outG,"N%4i \t G01 X%6.2f \t Y%6.2f \t Z%6.2f \t F50 \n",stCounter+=10,Start.X(),Start.Y(),Start.Z()); //float limited to 2 decimals
		    
		    fprintf(outG,"\n; move along tool-path (xy) of next level \n"); //float limited to 2 decimals 
		    fprintf(outG,"N%4i \t G01 X%6.2f \t Y%6.2f \t Z%6.2f \t F%i \n",stCounter+=10,ToGoL.X(),ToGoL.Y(),ToGoL.Z(), feed); //float limited to 2 decimals
		}
		  
		//output standard points to move to
		fprintf(outG,"N%4i \t G01 X%6.2f \t Y%6.2f \t Z%6.2f \t F%i \n",stCounter+=10,ToGo.X(),ToGo.Y(),ToGo.Z(), feed); //float limited to 2 decimals
		  
		Buffer=ToGo;
		Cal1L=Cal1;
		Cal2L=Cal2;
	    }
	    
	    forCounter++;
	}
	   
	//go around the rectangle once to cut "cheese chunks
	if (veryFirst.X() == ToGoL.X() || veryFirst.Y() == ToGoL.Y()){
	    A=veryFirst;
	    B=ToGoL;
	    C=ToGo;
	    D=verySecond; 
	}
	   
	if (verySecond.X() == ToGoL.X() || verySecond.Y() == ToGoL.Y()){
	    A=verySecond;
	    B=ToGoL;
	    C=ToGo;
	    D=veryFirst; 
	}
	       
	fprintf(outG,"\n; move around rectangle (xy) \n"); //float limited to 2 decimals 
	fprintf(outG,"N%4i \t G01 X%6.2f \t Y%6.2f \t Z%6.2f \t F%i \n",stCounter+=10,A.X(),A.Y(),A.Z(), feed); //float limited to 2 decimals
	fprintf(outG,"N%4i \t G01 X%6.2f \t Y%6.2f \t Z%6.2f \t F%i \n",stCounter+=10,B.X(),B.Y(),B.Z(), feed); //float limited to 2 decimals
	fprintf(outG,"N%4i \t G01 X%6.2f \t Y%6.2f \t Z%6.2f \t F%i \n",stCounter+=10,C.X(),C.Y(),C.Z(), feed); //float limited to 2 decimals    
	fprintf(outG,"N%4i \t G01 X%6.2f \t Y%6.2f \t Z%6.2f \t F%i \n",stCounter+=10,D.X(),D.Y(),D.Z(), feed); //float limited to 2 decimals
	   
	checkLoop++;// rise loop counter
    }

    //g-code footer
    
    fprintf(outG,"\n;move to safeHeight\n");    
    fprintf(outG,"N%4i \t G01 X%6.2f \t Y%6.2f \t Z%6.2f\n",stCounter+=10,ToGo.X(),ToGo.Y(),safeHeight); //float limited to 2 decimals   
    fprintf(outG,"\n;stop spindle turning\n");  
    fprintf(outG,"N%4i \t M05 \t  \n",stCounter+=10);    
    fprintf(outG,"\n; move to home position\n");      
    fprintf(outG,"N%4i \t G00 X  0.00 \t Y  0.00 \t Z 10.00\n",stCounter+=10); //float limited to 2 decimals   
    fprintf(outG,"\n; end of main program\n");  
    fprintf(outG,"N%4i \t M30\n",stCounter+=10);
    
    fclose(outG);// close file
    
 chdir(parentdir);
    return ;
}  
Exemplo n.º 17
0
TopoDS_Shape MakeBottle(const Standard_Real myWidth, const Standard_Real myHeight, const Standard_Real myThickness)
{
    // Profile : Define Support Points
    gp_Pnt aPnt1(-myWidth / 2., 0, 0);
    gp_Pnt aPnt2(-myWidth / 2., -myThickness / 4., 0);
    gp_Pnt aPnt3(0, -myThickness / 2., 0);
    gp_Pnt aPnt4(myWidth / 2., -myThickness / 4., 0);
    gp_Pnt aPnt5(myWidth / 2., 0, 0);

    // Profile : Define the Geometry
    Handle(Geom_TrimmedCurve) anArcOfCircle = GC_MakeArcOfCircle(aPnt2,aPnt3,aPnt4);
    Handle(Geom_TrimmedCurve) aSegment1 = GC_MakeSegment(aPnt1, aPnt2);
    Handle(Geom_TrimmedCurve) aSegment2 = GC_MakeSegment(aPnt4, aPnt5);

    // Profile : Define the Topology
    TopoDS_Edge anEdge1 = BRepBuilderAPI_MakeEdge(aSegment1);
    TopoDS_Edge anEdge2 = BRepBuilderAPI_MakeEdge(anArcOfCircle);
    TopoDS_Edge anEdge3 = BRepBuilderAPI_MakeEdge(aSegment2);
    TopoDS_Wire aWire  = BRepBuilderAPI_MakeWire(anEdge1, anEdge2, anEdge3);

    // Complete Profile
    gp_Ax1 xAxis = gp::OX();
    gp_Trsf aTrsf;

    aTrsf.SetMirror(xAxis);
    BRepBuilderAPI_Transform aBRepTrsf(aWire, aTrsf);
    TopoDS_Shape aMirroredShape = aBRepTrsf.Shape();
    TopoDS_Wire aMirroredWire = TopoDS::Wire(aMirroredShape);

    BRepBuilderAPI_MakeWire mkWire;
    mkWire.Add(aWire);
    mkWire.Add(aMirroredWire);
    TopoDS_Wire myWireProfile = mkWire.Wire();

    // Body : Prism the Profile
    TopoDS_Face myFaceProfile = BRepBuilderAPI_MakeFace(myWireProfile);
    gp_Vec aPrismVec(0, 0, myHeight);
    TopoDS_Shape myBody = BRepPrimAPI_MakePrism(myFaceProfile, aPrismVec);

    // Body : Apply Fillets
    BRepFilletAPI_MakeFillet mkFillet(myBody);
    TopExp_Explorer anEdgeExplorer(myBody, TopAbs_EDGE);
    while(anEdgeExplorer.More()) {
        TopoDS_Edge anEdge = TopoDS::Edge(anEdgeExplorer.Current());
        //Add edge to fillet algorithm
        mkFillet.Add(myThickness / 12., anEdge);
        anEdgeExplorer.Next();
    }

    myBody = mkFillet.Shape();

    // Body : Add the Neck
    gp_Pnt neckLocation(0, 0, myHeight);
    gp_Dir neckAxis = gp::DZ();
    gp_Ax2 neckAx2(neckLocation, neckAxis);

    Standard_Real myNeckRadius = myThickness / 4.;
    Standard_Real myNeckHeight = myHeight / 10.;

    BRepPrimAPI_MakeCylinder MKCylinder(neckAx2, myNeckRadius, myNeckHeight);
    TopoDS_Shape myNeck = MKCylinder.Shape();

    myBody = BRepAlgoAPI_Fuse(myBody, myNeck);

    // Body : Create a Hollowed Solid
    TopoDS_Face   faceToRemove;
    Standard_Real zMax = -1;

    for(TopExp_Explorer aFaceExplorer(myBody, TopAbs_FACE); aFaceExplorer.More(); aFaceExplorer.Next()) {
        TopoDS_Face aFace = TopoDS::Face(aFaceExplorer.Current());
        // Check if <aFace> is the top face of the bottle�s neck
        Handle(Geom_Surface) aSurface = BRep_Tool::Surface(aFace);
        if(aSurface->DynamicType() == STANDARD_TYPE(Geom_Plane)) {
            Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast(aSurface);
            gp_Pnt aPnt = aPlane->Location();
            Standard_Real aZ   = aPnt.Z();
            if(aZ > zMax) {
                zMax = aZ;
                faceToRemove = aFace;
            }
        }
    }

    TopTools_ListOfShape facesToRemove;
    facesToRemove.Append(faceToRemove);
    myBody = BRepOffsetAPI_MakeThickSolid(myBody, facesToRemove, -myThickness / 50, 1.e-3);
    // Threading : Create Surfaces
    Handle(Geom_CylindricalSurface) aCyl1 = new Geom_CylindricalSurface(neckAx2, myNeckRadius * 0.99);
    Handle(Geom_CylindricalSurface) aCyl2 = new Geom_CylindricalSurface(neckAx2, myNeckRadius * 1.05);

    // Threading : Define 2D Curves
    gp_Pnt2d aPnt(2. * M_PI, myNeckHeight / 2.);
    gp_Dir2d aDir(2. * M_PI, myNeckHeight / 4.);
    gp_Ax2d anAx2d(aPnt, aDir);

    Standard_Real aMajor = 2. * M_PI;
    Standard_Real aMinor = myNeckHeight / 10;

    Handle(Geom2d_Ellipse) anEllipse1 = new Geom2d_Ellipse(anAx2d, aMajor, aMinor);
    Handle(Geom2d_Ellipse) anEllipse2 = new Geom2d_Ellipse(anAx2d, aMajor, aMinor / 4);
    Handle(Geom2d_TrimmedCurve) anArc1 = new Geom2d_TrimmedCurve(anEllipse1, 0, M_PI);
    Handle(Geom2d_TrimmedCurve) anArc2 = new Geom2d_TrimmedCurve(anEllipse2, 0, M_PI);
    gp_Pnt2d anEllipsePnt1 = anEllipse1->Value(0);
    gp_Pnt2d anEllipsePnt2 = anEllipse1->Value(M_PI);

    Handle(Geom2d_TrimmedCurve) aSegment = GCE2d_MakeSegment(anEllipsePnt1, anEllipsePnt2);
    // Threading : Build Edges and Wires
    TopoDS_Edge anEdge1OnSurf1 = BRepBuilderAPI_MakeEdge(anArc1, aCyl1);
    TopoDS_Edge anEdge2OnSurf1 = BRepBuilderAPI_MakeEdge(aSegment, aCyl1);
    TopoDS_Edge anEdge1OnSurf2 = BRepBuilderAPI_MakeEdge(anArc2, aCyl2);
    TopoDS_Edge anEdge2OnSurf2 = BRepBuilderAPI_MakeEdge(aSegment, aCyl2);
    TopoDS_Wire threadingWire1 = BRepBuilderAPI_MakeWire(anEdge1OnSurf1, anEdge2OnSurf1);
    TopoDS_Wire threadingWire2 = BRepBuilderAPI_MakeWire(anEdge1OnSurf2, anEdge2OnSurf2);
    BRepLib::BuildCurves3d(threadingWire1);
    BRepLib::BuildCurves3d(threadingWire2);

    // Create Threading
    BRepOffsetAPI_ThruSections aTool(Standard_True);
    aTool.AddWire(threadingWire1);
    aTool.AddWire(threadingWire2);
    aTool.CheckCompatibility(Standard_False);

    TopoDS_Shape myThreading = aTool.Shape();

    // Building the Resulting Compound
    TopoDS_Compound aRes;
    BRep_Builder aBuilder;
    aBuilder.MakeCompound (aRes);
    aBuilder.Add (aRes, myBody);
    aBuilder.Add (aRes, myThreading);

    return aRes;
}
//=======================================================================
//function : Execute
//purpose  :
//=======================================================================
Standard_Integer GEOMImpl_PositionDriver::Execute(TFunction_Logbook& log) const
{
  if (Label().IsNull()) return 0;
  Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());

  GEOMImpl_IPosition aCI (aFunction);
  Standard_Integer aType = aFunction->GetType();

  TopoDS_Shape aShape;

  if (aType == POSITION_SHAPE || aType == POSITION_SHAPE_COPY) {
    Handle(GEOM_Function) aRefShape = aCI.GetShape();
    Handle(GEOM_Function) aRefStartLCS = aCI.GetStartLCS();
    Handle(GEOM_Function) aRefEndLCS = aCI.GetEndLCS();

    TopoDS_Shape aShapeBase = aRefShape->GetValue();
    TopoDS_Shape aShapeStartLCS = aRefStartLCS->GetValue();
    TopoDS_Shape aShapeEndLCS = aRefEndLCS->GetValue();

    if (aShapeBase.IsNull() || aShapeStartLCS.IsNull() ||
        aShapeEndLCS.IsNull() || aShapeEndLCS.ShapeType() != TopAbs_FACE)
      return 0;

    gp_Trsf aTrsf;
    gp_Ax3 aStartAx3, aDestAx3;

    // End LCS
    aDestAx3 = GEOMImpl_IMeasureOperations::GetPosition(aShapeEndLCS);

    // Start LCS
    aStartAx3 = GEOMImpl_IMeasureOperations::GetPosition(aShapeStartLCS);

    // Set transformation
    aTrsf.SetDisplacement(aStartAx3, aDestAx3);

    // Perform transformation
    BRepBuilderAPI_Transform aBRepTrsf (aShapeBase, aTrsf, Standard_False);
    aShape = aBRepTrsf.Shape();
  }
  else if (aType == POSITION_SHAPE_FROM_GLOBAL ||
           aType == POSITION_SHAPE_FROM_GLOBAL_COPY) {
    Handle(GEOM_Function) aRefShape = aCI.GetShape();
    Handle(GEOM_Function) aRefEndLCS = aCI.GetEndLCS();

    TopoDS_Shape aShapeBase = aRefShape->GetValue();
    TopoDS_Shape aShapeEndLCS = aRefEndLCS->GetValue();

    if (aShapeBase.IsNull() || aShapeEndLCS.IsNull() ||
        aShapeEndLCS.ShapeType() != TopAbs_FACE)
      return 0;

    gp_Trsf aTrsf;
    gp_Ax3 aStartAx3, aDestAx3;

    // End LCS
    aDestAx3 = GEOMImpl_IMeasureOperations::GetPosition(aShapeEndLCS);

    // Set transformation
    aTrsf.SetDisplacement(aStartAx3, aDestAx3);

    // Perform transformation
    BRepBuilderAPI_Transform aBRepTrsf (aShapeBase, aTrsf, Standard_False);
    aShape = aBRepTrsf.Shape();
  }
  else if (aType == POSITION_ALONG_PATH) {
    Handle(GEOM_Function) aRefShape = aCI.GetShape();
    Handle(GEOM_Function) aPathShape = aCI.GetPath();
    Standard_Real aParameter = aCI.GetDistance();
    bool aReversed = aCI.GetReverse();
    if (aReversed)
      aParameter = 1 - aParameter;

    TopoDS_Shape aShapeBase = aRefShape->GetValue();
    TopoDS_Shape aPath = aPathShape->GetValue();
    TopoDS_Wire aWire;

    if (aShapeBase.IsNull() || aPath.IsNull())
      return 0;

    if ( aPath.ShapeType() == TopAbs_EDGE ) {
      TopoDS_Edge anEdge = TopoDS::Edge(aPath);
      aWire = BRepBuilderAPI_MakeWire(anEdge); 
    }
    else if ( aPath.ShapeType() == TopAbs_WIRE)
      aWire = TopoDS::Wire(aPath);
    else
      return 0;

    Handle(GeomFill_TrihedronLaw) TLaw = new GeomFill_CorrectedFrenet();
    Handle(GeomFill_CurveAndTrihedron) aLocationLaw = new GeomFill_CurveAndTrihedron( TLaw );
    Handle(BRepFill_LocationLaw) aLocation = new BRepFill_Edge3DLaw(aWire, aLocationLaw);

    aLocation->TransformInCompatibleLaw( 0.01 );

    //Calculate a Parameter
    Standard_Real aFirstParam1 = 0, aLastParam1 = 0; // Parameters of the First edge
    Standard_Real aFirstParam2 = 0, aLastParam2 = 0; // Parameters of the Last edge
    aLocation->CurvilinearBounds(aLocation->NbLaw(), aFirstParam2, aLastParam2);

    if ( aLocation->NbLaw() > 1)
      aLocation->CurvilinearBounds(1, aFirstParam1, aLastParam1);
    else if ( aLocation->NbLaw() == 1 )
      aFirstParam1 = aFirstParam2;
    else
      return 0;

    Standard_Real aParam = (aFirstParam1 + (aLastParam2 - aFirstParam1)*aParameter );

    TopoDS_Shape CopyShape = aShapeBase;
    BRepFill_SectionPlacement Place( aLocation, aShapeBase );
    TopLoc_Location Loc2(Place.Transformation()), Loc1;
    Loc1 = CopyShape.Location();
    CopyShape.Location(Loc2.Multiplied(Loc1));

    aLocation->D0( aParam, CopyShape );
    aShape = CopyShape;
  }
  else
    return 0;

  if (aShape.IsNull()) return 0;

  aFunction->SetValue(aShape);

  log.SetTouched(Label());

  return 1;
}