bool IfcGeom::Kernel::convert(const IfcSchema::IfcEdgeCurve* l, TopoDS_Wire& result) {
	IfcSchema::IfcPoint* pnt1 = ((IfcSchema::IfcVertexPoint*) l->EdgeStart())->VertexGeometry();
	IfcSchema::IfcPoint* pnt2 = ((IfcSchema::IfcVertexPoint*) l->EdgeEnd())->VertexGeometry();
	if (!pnt1->is(IfcSchema::Type::IfcCartesianPoint) || !pnt2->is(IfcSchema::Type::IfcCartesianPoint)) {
		Logger::Message(Logger::LOG_ERROR, "Only IfcCartesianPoints are supported for VertexGeometry", l->entity);
		return false;
	}
	
	gp_Pnt p1, p2;
	if (!IfcGeom::Kernel::convert(((IfcSchema::IfcCartesianPoint*)pnt1), p1) ||
		!IfcGeom::Kernel::convert(((IfcSchema::IfcCartesianPoint*)pnt2), p2))
	{
		return false;
	}
	
	BRepBuilderAPI_MakeWire mw;
	Handle_Geom_Curve crv;

	// The lack of a clear separation between topological and geometrical entities
	// is starting to get problematic. If the underlying curve is bounded it is
	// assumed that a topological wire can be crafted from it. After which an
	// attempt is made to reconstruct it from the individual curves and the vertices
	// of the IfcEdgeCurve.
	const bool is_bounded = l->EdgeGeometry()->is(IfcSchema::Type::IfcBoundedCurve);

	if (!is_bounded && convert_curve(l->EdgeGeometry(), crv)) {
		mw.Add(BRepBuilderAPI_MakeEdge(crv, p1, p2));
		result = mw;
		return true;
	} else if (is_bounded && convert_wire(l->EdgeGeometry(), result)) {
		if (!l->SameSense()) std::swap(pnt1, pnt2);
		TopExp_Explorer exp(result, TopAbs_EDGE);
		bool first = true;
		while (exp.More()) {
			const TopoDS_Edge& ed = TopoDS::Edge(exp.Current());
			Standard_Real u1, u2;
			Handle(Geom_Curve) ecrv = BRep_Tool::Curve(ed, u1, u2);
			exp.Next();
			const bool last = !exp.More();
			first = false;
			if (first && last) {
				mw.Add(BRepBuilderAPI_MakeEdge(ecrv, p1, p2));
			} else if (first) {
				gp_Pnt pu;
				ecrv->D0(u2, pu);
				mw.Add(BRepBuilderAPI_MakeEdge(ecrv, p1, pu));
			} else if (last) {
				gp_Pnt pu;
				ecrv->D0(u1, pu);
				mw.Add(BRepBuilderAPI_MakeEdge(ecrv, pu, p2));
			} else {
				mw.Add(BRepBuilderAPI_MakeEdge(ecrv, u1, u2));
			}
		}
		result = mw;
		return true;
	} else {
		return false;
	}
}
Example #2
0
bool IfcGeom::Kernel::convert(const IfcSchema::IfcCircleHollowProfileDef* l, TopoDS_Shape& face) {
	const double r = l->Radius() * getValue(GV_LENGTH_UNIT);
	const double t = l->WallThickness() * getValue(GV_LENGTH_UNIT);
	
	if ( r == 0.0f || t == 0.0f ) {
		Logger::Message(Logger::LOG_NOTICE,"Skipping zero sized profile:",l->entity);
		return false;
	}
	
	gp_Trsf2d trsf2d;
	bool has_position = true;
#ifdef USE_IFC4
	has_position = l->hasPosition();
#endif
	if (has_position) {
		IfcGeom::Kernel::convert(l->Position(), trsf2d);
	}

	gp_Ax2 ax = gp_Ax2().Transformed(trsf2d);

	BRepBuilderAPI_MakeWire outer;	
	Handle(Geom_Circle) outerCircle = new Geom_Circle(ax, r);
	outer.Add(BRepBuilderAPI_MakeEdge(outerCircle));
	BRepBuilderAPI_MakeFace mf(outer.Wire(), false);

	BRepBuilderAPI_MakeWire inner;	
	Handle(Geom_Circle) innerCirlce = new Geom_Circle(ax, r-t);
	inner.Add(BRepBuilderAPI_MakeEdge(innerCirlce));
	mf.Add(inner);

	ShapeFix_Shape sfs(mf.Face());
	sfs.Perform();
	face = TopoDS::Face(sfs.Shape());	
	return true;		
}
	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"));
		}
	}
Example #4
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;
}
Example #5
0
int OCCEdge::createSpline(OCCVertex *start, OCCVertex *end, std::vector<OCCStruct3d> points,
                           double tolerance)
{
    try {
        Standard_Boolean periodic = false;
        Standard_Real tol = tolerance;
        
        int vertices = 0;
        if (start != NULL && end != NULL) {
            vertices = 2;
        }
        
        int nbControlPoints = points.size();
        Handle(TColgp_HArray1OfPnt) ctrlPoints;
        ctrlPoints = new TColgp_HArray1OfPnt(1, nbControlPoints + vertices);
        
        int index = 1;
        
        if (vertices) {
            ctrlPoints->SetValue(index++, gp_Pnt(start->X(), start->Y(), start->Z()));  
        }
        
        for (int i = 0; i < nbControlPoints; i++) {
            gp_Pnt aP(points[i].x,points[i].y,points[i].z);
            ctrlPoints->SetValue(index++, aP);
        }
        
        if (vertices) {
            ctrlPoints->SetValue(index++, gp_Pnt(end->X(), end->Y(), end->Z()));
        }
        
        GeomAPI_Interpolate INT(ctrlPoints, periodic, tol);
        INT.Perform();
        
        Handle(Geom_BSplineCurve) curve = INT.Curve();
        if (vertices) {
            this->setShape(BRepBuilderAPI_MakeEdge(curve, start->vertex, end->vertex));
        } else {
            this->setShape(BRepBuilderAPI_MakeEdge(curve));
        }
    } 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 spline");
        }
        return 0;
    }
    return 1;
}
void CAngleParamsVerticesPage::OnBnClickedVertex3Btn()
{
  myAISContext->LocalContext()->InitSelected();
  if (!myAISContext->LocalContext()->MoreSelected())
  {
    AfxMessageBox (_T ("Choose the vertex and press the button again"), MB_ICONINFORMATION | MB_OK);
    return;
  }

  myThirdVertex = TopoDS::Vertex (myAISContext->LocalContext()->SelectedShape());
  myAISContext->LocalContext()->ClearSelected();

  //Build dimension here
  TopoDS_Edge anEdge12 = BRepBuilderAPI_MakeEdge (myFirstVertex, mySecondVertex);
  TopoDS_Edge anEdge23 = BRepBuilderAPI_MakeEdge (mySecondVertex, myThirdVertex);

  CDimensionDlg *aDimDlg = (CDimensionDlg*)(GetParentOwner());

  gp_Pnt aP1 = BRep_Tool::Pnt (myFirstVertex),
         aP2 = BRep_Tool::Pnt (mySecondVertex),
         aP3 = BRep_Tool::Pnt (myThirdVertex);
  GC_MakePlane aPlaneBuilder (aP1,aP2,aP3);

  Handle(Geom_Plane) aPlane = aPlaneBuilder.Value();
  Handle(AIS_AngleDimension) anAngleDim = new AIS_AngleDimension (aP1,aP2,aP3);
  Handle(Prs3d_DimensionAspect) anAspect = new Prs3d_DimensionAspect();
  anAspect->MakeArrows3d (Standard_False);
  anAspect->MakeText3d (aDimDlg->GetTextType());
  anAspect->TextAspect()->SetHeight (aDimDlg->GetFontHeight());
  anAspect->MakeTextShaded (aDimDlg->IsText3dShaded());
  anAspect->SetCommonColor (aDimDlg->GetDimensionColor());
  anAspect->MakeUnitsDisplayed (aDimDlg->IsUnitsDisplayed());
  if (aDimDlg->IsUnitsDisplayed())
  {
    anAngleDim->SetDisplayUnits (aDimDlg->GetUnits());
    if ((anAngleDim->GetDisplayUnits().IsEqual (TCollection_AsciiString ("deg"))))
    {
      // No units - for degree is special symbol that is enabled by default
      anAspect->MakeUnitsDisplayed (Standard_False);
    }
    else // radians - no special symbol
    {
      anAngleDim->SetDisplaySpecialSymbol (AIS_DSS_No);
    }
  }
  anAngleDim->SetDimensionAspect (anAspect);
  myAISContext->CloseAllContexts();
  myAISContext->Display (anAngleDim);
  myAISContext->OpenLocalContext();
  myAISContext->ActivateStandardMode (TopAbs_VERTEX);
}
Example #7
0
int OCCEdge::createBezier(OCCVertex *start, OCCVertex *end, std::vector<OCCStruct3d> points)
{
    try {
        int nbControlPoints = points.size();
        int vertices = 0;
        if (start != NULL && end != NULL) {
            vertices = 2;
        }
        
        TColgp_Array1OfPnt ctrlPoints(1, nbControlPoints + vertices);
        
        int index = 1;
        if (vertices) {
            ctrlPoints.SetValue(index++, gp_Pnt(start->X(), start->Y(), start->Z()));
        }
        
        for (int i = 0; i < nbControlPoints; i++) {
            gp_Pnt aP(points[i].x,points[i].y,points[i].z);
            ctrlPoints.SetValue(index++, aP);
        }
        
        if (vertices)
            ctrlPoints.SetValue(index++, gp_Pnt(end->X(), end->Y(), end->Z())); 
        
        Handle(Geom_BezierCurve) bezier = new Geom_BezierCurve(ctrlPoints);
        
        if (vertices) {
            this->setShape(BRepBuilderAPI_MakeEdge(bezier, start->vertex, end->vertex));
        } else {
            this->setShape(BRepBuilderAPI_MakeEdge(bezier));
        }
        
        if (this->length() <= Precision::Confusion()) {
            StdFail_NotDone::Raise("bezier 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 bezier");
        }
        return 0;
    }
    return 1;
}
Example #8
0
bool IfcGeom::Kernel::convert(const IfcSchema::IfcCenterLineProfileDef* l, TopoDS_Shape& face) {
	const double d = l->Thickness() * getValue(GV_LENGTH_UNIT) / 2.;

	TopoDS_Wire wire;
	if (!convert_wire(l->Curve(), wire)) return false;

	// BRepOffsetAPI_MakeOffset insists on creating circular arc
	// segments for joining the curves that constitute the center
	// line. This is probably not in accordance with the IFC spec.
	// Although it does not specify a method to join segments
	// explicitly, it does dictate 'a constant thickness along the
	// curve'. Therefore for simple singular wires a quick
	// alternative is provided that uses a straight join.

	TopExp_Explorer exp(wire, TopAbs_EDGE);
	TopoDS_Edge edge = TopoDS::Edge(exp.Current());
	exp.Next();

	if (!exp.More()) {
		double u1, u2;
		Handle(Geom_Curve) curve = BRep_Tool::Curve(edge, u1, u2);

		Handle(Geom_TrimmedCurve) trim = new Geom_TrimmedCurve(curve, u1, u2);

		Handle(Geom_OffsetCurve) c1 = new Geom_OffsetCurve(trim,  d, gp::DZ());
		Handle(Geom_OffsetCurve) c2 = new Geom_OffsetCurve(trim, -d, gp::DZ());

		gp_Pnt c1a, c1b, c2a, c2b;
		c1->D0(c1->FirstParameter(), c1a);
		c1->D0(c1->LastParameter(), c1b);
		c2->D0(c2->FirstParameter(), c2a);
		c2->D0(c2->LastParameter(), c2b);

		BRepBuilderAPI_MakeWire mw;
		mw.Add(BRepBuilderAPI_MakeEdge(c1));
		mw.Add(BRepBuilderAPI_MakeEdge(c1a, c2a));
		mw.Add(BRepBuilderAPI_MakeEdge(c2));
		mw.Add(BRepBuilderAPI_MakeEdge(c2b, c1b));
		
		face = BRepBuilderAPI_MakeFace(mw.Wire());
	} else {
		BRepOffsetAPI_MakeOffset offset(BRepBuilderAPI_MakeFace(gp_Pln(gp::Origin(), gp::DZ())));
		offset.AddWire(wire);
		offset.Perform(d);
		face = BRepBuilderAPI_MakeFace(TopoDS::Wire(offset));
	}
	return true;
}
Example #9
0
bool IfcGeom::Kernel::convert(const IfcSchema::IfcCircleProfileDef* l, TopoDS_Shape& face) {
	const double r = l->Radius() * getValue(GV_LENGTH_UNIT);
	if ( r == 0.0f ) {
		Logger::Message(Logger::LOG_NOTICE,"Skipping zero sized profile:",l->entity);
		return false;
	}
	
	gp_Trsf2d trsf2d;
	bool has_position = true;
#ifdef USE_IFC4
	has_position = l->hasPosition();
#endif
	if (has_position) {
		IfcGeom::Kernel::convert(l->Position(), trsf2d);
	}
	gp_Ax2 ax = gp_Ax2().Transformed(trsf2d);

	
	Handle(Geom_Circle) circle = new Geom_Circle(ax, r);
	TopoDS_Edge edge = BRepBuilderAPI_MakeEdge(circle);

	BRepBuilderAPI_MakeWire w;
	w.Add(edge);

	TopoDS_Face f;
	bool success = convert_wire_to_face(w, f);
	if (success) face = f;
	return success;
}
Example #10
0
/**
 * Sample implementation of the method which handles arc entities.
 */
void DXFReader::addArc(const DL_ArcData& data)
{

    gp_Pnt p1(data.cx, data.cy, data.cz);
    gp_Ax2 a2(p1, gp_Dir(0, 0, 1));
    gp_Circ c(a2, data.radius);

    TopoDS_Shape arc = BRepBuilderAPI_MakeEdge(c, DEGTORAD(data.angle1), DEGTORAD(data.angle2)).Shape();
    m_mainClass->draw(arc);


    /*
    gp_Pnt p1(data.cx, data.cy, data.cz);
    gp_Ax2 a2(p1, gp_Dir(0, 0, 1));
    gp_Circ circle(a2, data.radius);
    GC_MakeArcOfCircle geoArc(circle, data.angle1, data.angle2, true);

    TopoDS_Shape arc = BRepBuilderAPI_MakeEdge(geoArc.Value()).Shape();
    m_mainClass->draw(arc);
    qDebug() << data.angle1;
    qDebug() << data.angle2;
    */

    /*printf("ARC      (%6.3f, %6.3f, %6.3f) %6.3f, %6.3f, %6.3f\n",
           data.cx, data.cy, data.cz,
           data.radius, data.angle1, data.angle2);*/
    printAttributes();
}
Example #11
0
bool IfcGeom::Kernel::convert(const IfcSchema::IfcEllipseProfileDef* l, TopoDS_Shape& face) {
	double rx = l->SemiAxis1() * getValue(GV_LENGTH_UNIT);
	double ry = l->SemiAxis2() * getValue(GV_LENGTH_UNIT);

	if ( rx < ALMOST_ZERO || ry < ALMOST_ZERO ) {
		Logger::Message(Logger::LOG_NOTICE,"Skipping zero sized profile:",l->entity);
		return false;
	}

	const bool rotated = ry > rx;
	gp_Trsf2d trsf;	
	convert(l->Position(),trsf);

	gp_Ax2 ax = gp_Ax2();
	if (rotated) {
		ax.Rotate(ax.Axis(), M_PI / 2.);
		std::swap(rx, ry);
	}
	ax.Transform(trsf);

	BRepBuilderAPI_MakeWire w;
	Handle(Geom_Ellipse) ellipse = new Geom_Ellipse(ax, rx, ry);
	TopoDS_Edge edge = BRepBuilderAPI_MakeEdge(ellipse);
	w.Add(edge);

	TopoDS_Face f;
	bool success = convert_wire_to_face(w, f);
	if (success) face = f;
	return success;
}
bool IfcGeom::profile_helper(int numVerts, double* verts, int numFillets, int* filletIndices, double* filletRadii, gp_Trsf2d trsf, TopoDS_Face& face) {
	TopoDS_Vertex* vertices = new TopoDS_Vertex[numVerts];
	
	for ( int i = 0; i < numVerts; i ++ ) {
		gp_XY xy (verts[2*i],verts[2*i+1]);
		trsf.Transforms(xy);
		vertices[i] = BRepBuilderAPI_MakeVertex(gp_Pnt(xy.X(),xy.Y(),0.0f));
	}

	BRepBuilderAPI_MakeWire w;
	for ( int i = 0; i < numVerts; i ++ )
		w.Add(BRepBuilderAPI_MakeEdge(vertices[i],vertices[(i+1)%numVerts]));

	IfcGeom::convert_wire_to_face(w.Wire(),face);

	if ( numFillets && *std::max_element(filletRadii, filletRadii + numFillets) > 1e-7 ) {
		BRepFilletAPI_MakeFillet2d fillet (face);
		for ( int i = 0; i < numFillets; i ++ ) {
			const double radius = filletRadii[i];
			if ( radius <= 1e-7 ) continue;
			fillet.AddFillet(vertices[filletIndices[i]],radius);
		}
		fillet.Build();
		if (fillet.IsDone()) {
			face = TopoDS::Face(fillet.Shape());
		} else {
			Logger::Message(Logger::LOG_WARNING, "Failed to process profile fillets");
		}
	}

	delete[] vertices;
	return true;
}
bool IfcGeom::Kernel::convert(const IfcSchema::IfcEdgeLoop* l, TopoDS_Wire& result) {
	IfcSchema::IfcOrientedEdge::list::ptr li = l->EdgeList();
	BRepBuilderAPI_MakeWire mw;
	for (IfcSchema::IfcOrientedEdge::list::it it = li->begin(); it != li->end(); ++it) {
		IfcSchema::IfcOrientedEdge* e = *it;

		IfcSchema::IfcPoint* pnt1 = ((IfcSchema::IfcVertexPoint*) e->EdgeStart())->VertexGeometry();
		IfcSchema::IfcPoint* pnt2 = ((IfcSchema::IfcVertexPoint*) e->EdgeEnd())->VertexGeometry();
		if (!pnt1->is(IfcSchema::Type::IfcCartesianPoint) || !pnt2->is(IfcSchema::Type::IfcCartesianPoint)) {
			Logger::Message(Logger::LOG_ERROR, "Only IfcCartesianPoints are supported for VertexGeometry", l->entity);
			return false;
		}
	
		gp_Pnt p1, p2;
		if (!IfcGeom::Kernel::convert(((IfcSchema::IfcCartesianPoint*)pnt1), p1) ||
			!IfcGeom::Kernel::convert(((IfcSchema::IfcCartesianPoint*)pnt2), p2))
		{
			return false;
		}

		mw.Add(BRepBuilderAPI_MakeEdge(p1, p2));
		continue;
		
		IfcSchema::IfcEdge* base = e->EdgeElement();
		TopoDS_Wire w;
		if (convert_wire(e->EdgeElement(), w)) {
			if (!e->Orientation()) w.Reverse();
			mw.Add(w);
		}
	}
	result = mw;
	return true;
}
Example #14
0
int OCCEdge::createArc(OCCVertex *start, OCCVertex *end, OCCStruct3d center) {
    try {
        gp_Pnt aP1(start->X(), start->Y(), start->Z());
        gp_Pnt aP2(center.x, center.y, center.z);
        gp_Pnt aP3(end->X(), end->Y(), end->Z());
        
        Standard_Real Radius = aP1.Distance(aP2);
        gce_MakeCirc MC(aP2,gce_MakePln(aP1, aP2, aP3).Value(), Radius);
        const gp_Circ& Circ = MC.Value();
        
        Standard_Real Alpha1 = ElCLib::Parameter(Circ, aP1);
        Standard_Real Alpha2 = ElCLib::Parameter(Circ, aP3);
        Handle(Geom_Circle) C = new Geom_Circle(Circ);
        Handle(Geom_TrimmedCurve) arc = new Geom_TrimmedCurve(C, Alpha1, Alpha2, false);
        
        this->setShape(BRepBuilderAPI_MakeEdge(arc, start->vertex, end->vertex));
    } 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 arc");
        }
        return 0;
    }
    return 1;
}
Example #15
0
/*
Creates the hyperboloid using a formula. 
TODO: Update this so the hyperboloid actually represents a proper parametric model. 
*/
TopoDS_Shape hyperboloid::create(double innerRadius, double height, double heightUnder, double angle)
{
		int detail = 40;
		gp_Pnt Origin(0,0,0);
		gp_Vec Dir(0,0,1);

		int uCount = detail;
		double a = innerRadius;
		double c = angle;
		double totalHeight = height + heightUnder;
		TColgp_Array1OfPnt array (0,uCount - 1);

		for (double u = 0; u < uCount; u++)
		{	
			double uValue = ((totalHeight * u / (uCount - 1)) - heightUnder) / c;
			double vValue = 0;

			double sqrMe = 1 + uValue * uValue;

			double x = a * sqrt(sqrMe) * cos(vValue);
			double y = a * sqrt(sqrMe) * sin(vValue);
			double z = c * uValue;
			gp_Pnt P1(x,y,z);   
			array.SetValue(u,P1); 
		}
	                          
		Handle(Geom_BSplineCurve) hyperbola = GeomAPI_PointsToBSpline(array).Curve();    
		TopoDS_Edge hyperbolaTopoDS = BRepBuilderAPI_MakeEdge(hyperbola); 

		gp_Ax1 axis = gp_Ax1(Origin,Dir); 
		TopoDS_Shape hyperboloid = BRepPrimAPI_MakeRevol(hyperbolaTopoDS, axis); 

		return hyperboloid;
}
Example #16
0
bool IfcGeom::Kernel::convert(const IfcSchema::IfcEdge* l, TopoDS_Wire& result) {
	if (!l->EdgeStart()->is(IfcSchema::Type::IfcVertexPoint) || !l->EdgeEnd()->is(IfcSchema::Type::IfcVertexPoint)) {
		Logger::Message(Logger::LOG_ERROR, "Only IfcVertexPoints are supported for EdgeStart and -End", l->entity);
		return false;
	}

	IfcSchema::IfcPoint* pnt1 = ((IfcSchema::IfcVertexPoint*) l->EdgeStart())->VertexGeometry();
	IfcSchema::IfcPoint* pnt2 = ((IfcSchema::IfcVertexPoint*) l->EdgeEnd())->VertexGeometry();
	if (!pnt1->is(IfcSchema::Type::IfcCartesianPoint) || !pnt2->is(IfcSchema::Type::IfcCartesianPoint)) {
		Logger::Message(Logger::LOG_ERROR, "Only IfcCartesianPoints are supported for VertexGeometry", l->entity);
		return false;
	}
	
	gp_Pnt p1, p2;
	if (!convert(((IfcSchema::IfcCartesianPoint*)pnt1), p1) ||
		!convert(((IfcSchema::IfcCartesianPoint*)pnt2), p2))
	{
		return false;
	}

	BRepBuilderAPI_MakeWire mw;
	mw.Add(BRepBuilderAPI_MakeEdge(p1, p2));

	result = mw.Wire();
	return true;
}
Example #17
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);
}
Example #18
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;
}
Example #19
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;
}
Example #20
0
/**
 * Sample implementation of the method which handles line entities.
 */
void DXFReader::addLine(const DL_LineData& data)
{
    // qDebug() << "addline";
    gp_Pnt p1(data.x1, data.y1, data.z1);
    gp_Pnt p2( data.x2, data.y2, data.z2);
    TopoDS_Shape line = BRepBuilderAPI_MakeEdge(p1, p2).Shape();
    m_mainClass->draw(line);

    /*printf("LINE     (%6.3f, %6.3f, %6.3f) (%6.3f, %6.3f, %6.3f)\n",
           data.x1, data.y1, data.z1, data.x2, data.y2, data.z2);
    printAttributes();
    */
}
Example #21
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);
}
Example #22
0
bool IfcGeom::convert(const Ifc2x3::IfcPolyLoop::ptr l, TopoDS_Wire& result) {
	Ifc2x3::IfcCartesianPoint::list points = l->Polygon();

	BRepBuilderAPI_MakeWire w;
	gp_Pnt P1;gp_Pnt P2;gp_Pnt F;
	int count = 0;
	for( Ifc2x3::IfcCartesianPoint::it it = points->begin(); it != points->end(); ++ it ) {
		IfcGeom::convert(*it,P2);
		if ( it != points->begin() && ( !P1.IsEqual(P2,GetValue(GV_POINT_EQUALITY_TOLERANCE)) ) ) {
			w.Add(BRepBuilderAPI_MakeEdge(P1,P2));
			count ++;
		} else if ( ! count ) F = P2;		
		P1 = P2;
	}
	if ( !P1.IsEqual(F,GetValue(GV_POINT_EQUALITY_TOLERANCE)) ) {
		w.Add(BRepBuilderAPI_MakeEdge(P1,F));
		count ++;
	}
	if ( count < 3 ) return false;

	result = w.Wire();
	return true;
}
Example #23
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);
}
Example #24
0
bool IfcGeom::convert(const Ifc2x3::IfcPolyline::ptr l, TopoDS_Wire& result) {
	Ifc2x3::IfcCartesianPoint::list points = l->Points();

	BRepBuilderAPI_MakeWire w;
	gp_Pnt P1;gp_Pnt P2;
	for( Ifc2x3::IfcCartesianPoint::it it = points->begin(); it != points->end(); ++ it ) {
		IfcGeom::convert(*it,P2);
		if ( it != points->begin() && ( !P1.IsEqual(P2,GetValue(GV_POINT_EQUALITY_TOLERANCE)) ) )
			w.Add(BRepBuilderAPI_MakeEdge(P1,P2));
		P1 = P2;
	}

	result = w.Wire();
	return true;
}
Example #25
0
/**
 * Sample implementation of the method which handles circle entities.
 */
void DXFReader::addCircle(const DL_CircleData& data) {

    qDebug() << "addcircle";
    gp_Pnt p1(data.cx, data.cy, data.cz);
    gp_Ax2 a2(p1, gp_Dir(0, 0, 1));
    gp_Circ c(a2, data.radius);
    TopoDS_Shape circle = BRepBuilderAPI_MakeEdge(c).Shape();
    m_mainClass->draw(circle, Standard_False);

    /*printf("CIRCLE   (%6.3f, %6.3f, %6.3f) %6.3f\n",
           data.cx, data.cy, data.cz,
           data.radius);

    printAttributes();*/
}
Example #26
0
bool IfcGeom::Kernel::convert(const IfcSchema::IfcSubedge* l, TopoDS_Wire& result) {
	TopoDS_Wire temp;
	if (convert_wire(l->ParentEdge(), result) && convert((IfcSchema::IfcEdge*) l, temp)) {
		TopExp_Explorer exp(result, TopAbs_EDGE);
		TopoDS_Edge edge = TopoDS::Edge(exp.Current());
		Standard_Real u1, u2;
		Handle(Geom_Curve) crv = BRep_Tool::Curve(edge, u1, u2);
		TopoDS_Vertex v1, v2;
		TopExp::Vertices(temp, v1, v2);
		BRepBuilderAPI_MakeWire mw;
		mw.Add(BRepBuilderAPI_MakeEdge(crv, v1, v2));
		result = mw.Wire();
		return true;
	} else {
		return false;
	}
}
Example #27
0
int OCCEdge::createLine(OCCVertex *start, OCCVertex *end) {
    try {
        gp_Pnt aP1(start->X(), start->Y(), start->Z());
        gp_Pnt aP2(end->X(), end->Y(), end->Z());
        GC_MakeLine line(aP1, aP2);
        this->setShape(BRepBuilderAPI_MakeEdge(line, start->vertex, end->vertex));
    } 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 line");
        }
        return 0;
    }
    return 1;
}
Example #28
0
int OCCEdge::createHelix(double pitch, double height, double radius, double angle, bool leftHanded)
{
    try {
        gp_Ax2 cylAx2(gp_Pnt(0.0,0.0,0.0) , gp::DZ());
        
        if (radius <= Precision::Confusion()) {
            StdFail_NotDone::Raise("radius to small");
        }
        
        Handle_Geom_Surface surf;
        if (angle <= 0.0) {
            surf = new Geom_CylindricalSurface(cylAx2, radius);
        } else {
            surf = new Geom_ConicalSurface(gp_Ax3(cylAx2), angle, radius);
        }
        
        gp_Pnt2d aPnt(0, 0);
        gp_Dir2d aDir(2. * M_PI, pitch);
        if (leftHanded) {
            aPnt.SetCoord(2. * M_PI, 0.0);
            aDir.SetCoord(-2. * M_PI, pitch);
        }
        gp_Ax2d aAx2d(aPnt, aDir);

        Handle(Geom2d_Line) line = new Geom2d_Line(aAx2d);
        gp_Pnt2d pnt_beg = line->Value(0);
        gp_Pnt2d pnt_end = line->Value(sqrt(4.0*M_PI*M_PI+pitch*pitch)*(height/pitch));
        const Handle(Geom2d_TrimmedCurve)& segm = GCE2d_MakeSegment(pnt_beg , pnt_end);

        this->setShape(BRepBuilderAPI_MakeEdge(segm , surf));
        BRepLib::BuildCurves3d(edge);
        
    } 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 helix");
        }
        return 0;
    }
    return 1;
}
Example #29
0
int OCCEdge::createArc3P(OCCVertex *start, OCCVertex *end, OCCStruct3d aPoint) {
    try {
        gp_Pnt aP1(start->X(), start->Y(), start->Z());
        gp_Pnt aP2(aPoint.x, aPoint.y, aPoint.z);
        gp_Pnt aP3(end->X(), end->Y(), end->Z());
        GC_MakeArcOfCircle arc(aP1, aP2, aP3);
        this->setShape(BRepBuilderAPI_MakeEdge(arc, start->vertex, end->vertex));
    } 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 arc");
        }
        return 0;
    }
    return 1;
}
Example #30
0
TopoDS_Shape
MakeBottle(const Standard_Real myWidth, const Standard_Real myHeight,
           const Standard_Real myThickness)
{

    BRepBuilderAPI_MakeWire wireMaker;

    // Profile : Define Support Points
    {
        Handle(TColgp_HArray1OfPnt) gp_array = new TColgp_HArray1OfPnt(1, 4);
        gp_Pnt p0(-myWidth / 2., 0, 0);
        gp_Pnt p4(myWidth / 2., 0, 0);

//    gp_array->SetValue(0, p0);
        gp_array->SetValue(1, gp_Pnt(-myWidth / 2., -myThickness / 4., 0));
        gp_array->SetValue(2, gp_Pnt(0, -myThickness / 2., 0));
        gp_array->SetValue(3, gp_Pnt(myWidth / 2., -myThickness / 4., 0));
        gp_array->SetValue(4, p4);

        GeomAPI_Interpolate sp(gp_array, true, 1.0e-3);
        sp.Perform();

        wireMaker.Add(BRepBuilderAPI_MakeEdge(sp.Curve()));
    }
    // Body : Prism the Profile
    TopoDS_Face myFaceProfile = BRepBuilderAPI_MakeFace(wireMaker.Wire());
    gp_Vec aPrismVec(0, 0, myHeight);
    TopoDS_Shape myBody = BRepPrimAPI_MakePrism(myFaceProfile, aPrismVec);



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

    return aRes;
}