Esempio n. 1
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);
}
Esempio n. 2
0
gp_Pnt HDimension::GetB2()
{
	// return B, possibly flattened
	if(m_mode == TwoPointsXYOnlyDimensionMode)
	{
		gp_Dir zdir = gp_Dir(0, 0, 1).Transformed(m_trsf);
		double dp = gp_Vec(B->m_p.XYZ()) * zdir - gp_Vec(A->m_p.XYZ()) * zdir;
		return gp_Pnt(B->m_p.XYZ() + zdir.XYZ() * (-dp));
	}
	else if(m_mode == TwoPointsXOnlyDimensionMode)
	{
		gp_Dir zdir = gp_Dir(0, 0, 1).Transformed(m_trsf);
		gp_Dir ydir = gp_Dir(0, 1, 0).Transformed(m_trsf);
		double dpz = gp_Vec(B->m_p.XYZ()) * zdir - gp_Vec(A->m_p.XYZ()) * zdir;
		double dpy = gp_Vec(B->m_p.XYZ()) * ydir - gp_Vec(A->m_p.XYZ()) * ydir;
		return gp_Pnt(B->m_p.XYZ() + zdir.XYZ() * (-dpz) + ydir.XYZ() * (-dpy));
	}
	else if(m_mode == TwoPointsYOnlyDimensionMode)
	{
		gp_Dir zdir = gp_Dir(0, 0, 1).Transformed(m_trsf);
		gp_Dir xdir = gp_Dir(1, 0, 0).Transformed(m_trsf);
		double dpz = gp_Vec(B->m_p.XYZ()) * zdir - gp_Vec(A->m_p.XYZ()) * zdir;
		double dpx = gp_Vec(B->m_p.XYZ()) * xdir - gp_Vec(A->m_p.XYZ()) * xdir;
		return gp_Pnt(B->m_p.XYZ() + zdir.XYZ() * (-dpz) + xdir.XYZ() * (-dpx));
	}
	else if(m_mode == TwoPointsZOnlyDimensionMode)
	{
		gp_Dir xdir = gp_Dir(1, 0, 0).Transformed(m_trsf);
		gp_Dir ydir = gp_Dir(0, 1, 0).Transformed(m_trsf);
		double dpx = gp_Vec(B->m_p.XYZ()) * xdir - gp_Vec(A->m_p.XYZ()) * xdir;
		double dpy = gp_Vec(B->m_p.XYZ()) * ydir - gp_Vec(A->m_p.XYZ()) * ydir;
		return gp_Pnt(B->m_p.XYZ() + xdir.XYZ() * (-dpx) + ydir.XYZ() * (-dpy));
	}

	return B->m_p;
}
static Handle(Geom_Surface) mkSurface1()
{
    Standard_Real aCoords[3][3][3] = {
        {{-10,-10,-30},{-10,50,40},{-10,70,-20}},
        {{50,-10,40},{50,50,0},{50,70,30}},
        {{70,-10,20},{70,50,30},{70,70,-20}}
    };
    TColgp_Array2OfPnt aPoles (1, 3, 1, 3);
    for (Standard_Integer iV=0; iV < 3; iV++)
        for (Standard_Integer iU=0; iU < 3; iU++)
            aPoles(iU+1, iV+1) = gp_Pnt (aCoords[iV][iU][0],
                                         aCoords[iV][iU][1],
                                         aCoords[iV][iU][2]);
    return new Geom_BezierSurface (aPoles);
}
Esempio n. 4
0
// Returns a point on the chord line between leading and trailing
// edge as function of parameter xsi, which ranges from 0.0 to 1.0.
// For xsi = 0.0 chord point is equal to leading edge, for xsi = 1.0
// chord point is equal to trailing edge.
gp_Pnt CCPACSWingProfile::GetChordPoint(double xsi)
{
    if (xsi < 0.0 || xsi > 1.0) {
        throw CTiglError("Error: Parameter xsi not in the range 0.0 <= xsi <= 1.0 in CCPACSWingProfile::GetChordPoint", TIGL_ERROR);
    }

    Handle(Geom2d_TrimmedCurve) chordLine = GetChordLine();
    Standard_Real firstParam = chordLine->FirstParameter();
    Standard_Real lastParam  = chordLine->LastParameter();
    Standard_Real param = (lastParam - firstParam) * xsi;

    gp_Pnt2d chordPoint2d;
    chordLine->D0(param, chordPoint2d);
    return gp_Pnt(chordPoint2d.X(), 0.0, chordPoint2d.Y());
}
Esempio n. 5
0
void HDimension::GetBox(CBox &box)
{
	gp_Pnt vt(0, 0, 0);
	vt.Transform(m_trsf);
	double p[3];
	extract(vt, p);
	box.Insert(p);

	wxString text = MakeText();
	float width, height;
	if(!wxGetApp().get_text_size(text, &width, &height))return;

	gp_Pnt point[3];
	point[0] = gp_Pnt(width, 0, 0);
	point[1] = gp_Pnt(0, -height, 0);
	point[2] = gp_Pnt(width, -height, 0);

	for(int i = 0; i<3; i++)
	{
		point[i].Transform(m_trsf);
		extract(point[i], p);
		box.Insert(p);
	}
}
bool PCBMODEL::getModelLocation( bool aBottom, DOUBLET aPosition, double aRotation,
    TRIPLET aOffset, TRIPLET aOrientation, TopLoc_Location& aLocation )
{
    // Order of operations:
    // a. aOrientation is applied -Z*-Y*-X
    // b. aOffset is applied
    //      Top ? add thickness to the Z offset
    // c. Bottom ? Rotate on X axis (in contrast to most ECAD which mirror on Y),
    //             then rotate on +Z
    //    Top ? rotate on -Z
    // d. aPosition is applied
    //
    // Note: Y axis is inverted in KiCad

    gp_Trsf lPos;
    lPos.SetTranslation( gp_Vec( aPosition.x, -aPosition.y, 0.0 ) );

    // offset (inches)
    aOffset.x *= 25.4;
    aOffset.y *= 25.4;
    aOffset.z *= 25.4 + BOARD_OFFSET;
    gp_Trsf lRot;

    if( aBottom )
    {
        lRot.SetRotation( gp_Ax1( gp_Pnt( 0.0, 0.0, 0.0 ), gp_Dir( 0.0, 0.0, 1.0 ) ), aRotation );
        lPos.Multiply( lRot );
        lRot.SetRotation( gp_Ax1( gp_Pnt( 0.0, 0.0, 0.0 ), gp_Dir( 1.0, 0.0, 0.0 ) ), M_PI );
        lPos.Multiply( lRot );
    }
    else
    {
        aOffset.z += m_thickness;
        lRot.SetRotation( gp_Ax1( gp_Pnt( 0.0, 0.0, 0.0 ), gp_Dir( 0.0, 0.0, 1.0 ) ), aRotation );
        lPos.Multiply( lRot );
    }

    gp_Trsf lOff;
    lOff.SetTranslation( gp_Vec( aOffset.x, aOffset.y, aOffset.z ) );
    lPos.Multiply( lOff );

    gp_Trsf lOrient;
    lOrient.SetRotation( gp_Ax1( gp_Pnt( 0.0, 0.0, 0.0 ),
       gp_Dir( 0.0, 0.0, 1.0 ) ), -aOrientation.z );
    lPos.Multiply( lOrient );
    lOrient.SetRotation( gp_Ax1( gp_Pnt( 0.0, 0.0, 0.0 ),
        gp_Dir( 0.0, 1.0, 0.0 ) ), -aOrientation.y );
    lPos.Multiply( lOrient );
    lOrient.SetRotation( gp_Ax1( gp_Pnt( 0.0, 0.0, 0.0 ),
        gp_Dir( 1.0, 0.0, 0.0 ) ), -aOrientation.x );
    lPos.Multiply( lOrient );

    aLocation = TopLoc_Location( lPos );
    return true;
}
Esempio n. 7
0
/**
 * Sample implementation of the method which handles polyline entities.
 */
void DXFReader::addPolyline(const DL_PolylineData& data) {

    qDebug() << "polyline";
    //
    m_polyline.SetClose(data.flags & 0x1);
    int size = data.m_vertices.size();

    for (int i = 0; i < size; ++i) {
       DL_VertexData v = data.m_vertices[i];
       m_polyline.AddPoint(gp_Pnt(v.x, v.y, v.z));
    }


    //
    //printf("POLYLINE \n");
    //printf("flags: %d\n", (int)data.flags);
    //printAttributes();
}
//================================================================
// Function : Convert_Presentation::sampleToroidalSurface
// Purpose  : 
//================================================================
void Convert_Presentation::sampleToroidalSurface()
{
  getAISContext()->EraseAll();

  Standard_CString aName = "Toroidal surface";
  TCollection_AsciiString aText (
    "  // creating an axis parallel to Y axis" EOL
    "  gp_Ax3 anAx(gp_Pnt(0,0,0), gp_Dir(0,1,0));" EOL
    "  // creating a toroidal surface with major radius = 240 and minor radius = 120" EOL
    "  Handle(Geom_ToroidalSurface) aSurface = new Geom_ToroidalSurface(anAx, 240, 120);" EOL);

  // creating an axis parallel to Y axis 
  gp_Ax3 anAx(gp_Pnt(0,0,0), gp_Dir(0,1,0)); 
  // creating a toroidal surface with major radius = 240 and minor radius = 120
  Handle(Geom_ToroidalSurface) aSurface = new Geom_ToroidalSurface(anAx, 240, 120);

  drawSurfaceAndItsBSpline(aSurface, aName, aText);
}
//================================================================
// Function : Convert_Presentation::sampleSphericalSurface
// Purpose  : 
//================================================================
void Convert_Presentation::sampleSphericalSurface()
{
  getAISContext()->EraseAll();

  Standard_CString aName = "Spherical surface";
  TCollection_AsciiString aText (
    "// creating an axis parallel to Z axis" EOL
    "gp_Ax3 anAx(gp_Pnt(0,0,0), gp_Dir(0,0,1));" EOL
    "// creating a spherical surface with radius = 300" EOL
    "Handle(Geom_SphericalSurface) aSurface = new Geom_SphericalSurface(anAx,300);" EOL);

  // creating an axis parallel to Z axis 
  gp_Ax3 anAx(gp_Pnt(0,0,0), gp_Dir(0,0,1)); 
  // creating a spherical surface with radius = 300
  Handle(Geom_SphericalSurface) aSurface = new Geom_SphericalSurface(anAx,300);

  drawSurfaceAndItsBSpline(aSurface, aName, aText);
}
Esempio n. 10
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;
}
Esempio n. 11
0
	void Run(){
		Drawing *pDrawingMode = dynamic_cast<Drawing *>(wxGetApp().input_mode_object);
		DigitizeMode *pDigitizeMode = dynamic_cast<DigitizeMode *>(wxGetApp().input_mode_object);
		if ((pDrawingMode != NULL) || (pDigitizeMode != NULL))
		{
			gp_Pnt location = HPoint::GetOffset(gp_Pnt(which->m_point[0], which->m_point[1], which->m_point[2]));
		
			if (pDrawingMode != NULL)
			{
				wxGetApp().m_digitizing->digitized_point = DigitizedPoint(location, DigitizeInputType);
				pDrawingMode->AddPoint();
			}

			if (pDigitizeMode != NULL)
			{
				pDigitizeMode->DigitizeToLocatedPosition( location );
			}
		}
	}
Esempio n. 12
0
void occQt::makeFillet()
{
    gp_Ax2 anAxis;
    anAxis.SetLocation(gp_Pnt(0.0, 50.0, 0.0));

    TopoDS_Shape aTopoBox = BRepPrimAPI_MakeBox(anAxis, 3.0, 4.0, 5.0);
    BRepFilletAPI_MakeFillet MF(aTopoBox);

    // Add all the edges to fillet.
    for (TopExp_Explorer ex(aTopoBox, TopAbs_EDGE); ex.More(); ex.Next())
    {
        MF.Add(1.0, TopoDS::Edge(ex.Current()));
    }

    Handle_AIS_Shape anAisShape = new AIS_Shape(MF.Shape());
    anAisShape->SetColor(Quantity_NOC_VIOLET);

    mContext->Display(anAisShape);
}
Esempio n. 13
0
std::vector<RayIntersection> FastLine::RayIntersects(gp_Pnt pnt)
{
	std::vector<RayIntersection> ret;
	//If this line is significantly horizontal, there is nothing good
	//we can do here
	if(B.Y() < A.Y() + TOLERANCE/4 && B.Y() > A.Y() - TOLERANCE/4)
		return ret;

	if((pnt.Y() < B.Y() + TOLERANCE && pnt.Y() > A.Y() - TOLERANCE)||
		(pnt.Y() > B.Y() - TOLERANCE && pnt.Y() < A.Y() + TOLERANCE))
	{
		if(fabs(A.Y() - B.Y()) < TOLERANCE)
			return ret;
		double u = (pnt.Y() - A.Y())/(B.Y()-A.Y());
		double x = GetXatU(u);
		if(x < pnt.X())
			ret.push_back(RayIntersection(u,gp_Pnt(x,pnt.Y(),0),false,false));
	}
	return ret;
}
static Handle(Geom_Curve) mkPBSplineCurve(const Standard_Integer nPoles,
        const Standard_Real theCoords[][3],
        const Standard_Real aScale = 1,
        const gp_XYZ& aShift = gp_XYZ(0,0,0))
{
    TColgp_Array1OfPnt aPoles (1, nPoles);
    TColStd_Array1OfReal aKnots (1, nPoles+1);
    TColStd_Array1OfInteger aMults(1, nPoles+1);

    for (Standard_Integer i=0; i < nPoles; i++)
    {
        gp_XYZ aP (theCoords[i][0], theCoords[i][1], theCoords[i][2]);
        aPoles(i+1) = gp_Pnt (aP * aScale + aShift);
    }
    for (i=1; i <= nPoles+1; i++)
        aKnots(i) = Standard_Real(i-1);
    aMults.Init(1);

    return new Geom_BSplineCurve (aPoles, aKnots, aMults, 3, Standard_True);
}
void LVPS_GM2Displacement1Rotation::Calculate(LVPS_XYZNode* nodes)
{
	double xi = (nodes[DisplacementNodeX.ID].S);
	double yi = (nodes[DisplacementNodeY.ID].S);
	gp_Vec vec;
	vec = gp_Vec(1,0,0)*xi;
	aTrsf.SetTranslation(vec);
	vec = gp_Vec(0,1,0)*yi;
	gp_Trsf trsf, trsf1;
	trsf.SetTranslation(vec);
	aTrsf=trsf*aTrsf;
	
	Standard_Real X=x+nodes[DisplacementNodeX.ID].S;
	Standard_Real Y=y+nodes[DisplacementNodeY.ID].S;

	trsf1.SetRotation(gp_Ax1(gp_Pnt(X,Y,0),/*axisZ*/gp_Dir(0,0,1)),nodes[RotationNode.ID].S);

	aTrsf=trsf1*aTrsf;
	
};
Esempio n. 16
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);
}
Esempio n. 17
0
/// This tests checks, if the bspline
/// has symmetric properties
TEST(BSplines, symmetricBSpline)
{
    // symmetric input points wrt x-y plane
    std::vector<gp_Pnt> points;
    points.push_back(gp_Pnt(0,0,1));
    points.push_back(gp_Pnt(0,-sqrt(0.5),sqrt(0.5)));
    points.push_back(gp_Pnt(0,-1,0));
    points.push_back(gp_Pnt(0,-sqrt(0.5),-sqrt(0.5)));
    points.push_back(gp_Pnt(0,0,-1));

    Handle(Geom_BSplineCurve) curve;
    tigl::CTiglSymetricSplineBuilder builder(points);

    ASSERT_NO_THROW(curve = builder.GetBSpline());

    double umin = curve->FirstParameter();
    double umax = curve->LastParameter();

    // check, that curve start is perpendicular to x-z plane
    gp_Pnt p; gp_Vec v;
    curve->D1(umin, p, v);
    ASSERT_NEAR(0., v * gp_Vec(1,0,0), 1e-10);
    ASSERT_NEAR(0., v * gp_Vec(0,0,1), 1e-10);

    // check interpolation at start
    ASSERT_NEAR(0., p.Distance(gp_Pnt(0,0,1)), 1e-10);

    // check, that curve end is perpendicular to x-z plane
    curve->D1(umax, p, v);
    ASSERT_NEAR(0., v * gp_Vec(1,0,0), 1e-10);
    ASSERT_NEAR(0., v * gp_Vec(0,0,1), 1e-10);

    // check interpolation at end
    ASSERT_NEAR(0., p.Distance(points[points.size()-1]), 1e-10);
    
    // check symmetry wrt x-y plane
    curve->D1((umin+umax)/2., p, v);
    ASSERT_NEAR(0., p.Distance(gp_Pnt(0,-1,0)), 1e-10);
    ASSERT_NEAR(0., v * gp_Vec(0,1,0), 1e-10);
    ASSERT_NEAR(0., v * gp_Vec(1,0,0), 1e-10);
}
Esempio n. 18
0
int OCCEdge::createEllipse(OCCStruct3d pnt, OCCStruct3d nor, double rMajor, double rMinor)
{
    try {
        gp_Ax2 ax2(gp_Pnt(pnt.x,pnt.y,pnt.z), gp_Dir(nor.x,nor.y,nor.z));
        
        if (rMajor <= Precision::Confusion() || rMinor <= Precision::Confusion()) {
            StdFail_NotDone::Raise("radius to small");
        }
        
        gce_MakeElips ellipse(ax2, rMajor, rMinor);
        this->setShape(BRepBuilderAPI_MakeEdge(ellipse));
    } 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 ellipse");
        }
        return 0;
    }
    return 1;
}
Esempio n. 19
0
// static member function
HeeksObj* HGear::ReadFromXMLElement(TiXmlElement* element)
{
	HGear* new_object = new HGear();

	element->Attribute("num_teeth", &new_object->m_num_teeth);
	element->Attribute("module", &new_object->m_module);
	element->Attribute("addendum_offset", &new_object->m_addendum_offset);
	element->Attribute("addendum_multiplier", &new_object->m_addendum_multiplier);
	element->Attribute("dedendum_multiplier", &new_object->m_dedendum_multiplier);
	element->Attribute("pressure_angle", &new_object->m_pressure_angle);
	element->Attribute("tip_relief", &new_object->m_tip_relief);
	element->Attribute("depth", &new_object->m_depth);
	element->Attribute("cone_half_angle", &new_object->m_cone_half_angle);
	element->Attribute("drawn_angle", &new_object->m_angle);

	double l[3] = {0.0, 0.0, 0.0};
	double d[3] = {0.0, 0.0, 1.0};
	double x[3] = {1.0, 0.0, 0.0};

	element->Attribute("lx", &l[0]);
	element->Attribute("ly", &l[1]);
	element->Attribute("lz", &l[2]);

	element->Attribute("dx", &d[0]);
	element->Attribute("dy", &d[1]);
	element->Attribute("dz", &d[2]);

	element->Attribute("xx", &x[0]);
	element->Attribute("xy", &x[1]);
	element->Attribute("xz", &x[2]);

	new_object->m_pos = gp_Ax2(gp_Pnt(l[0], l[1], l[2]), gp_Dir(d[0], d[1], d[2]), gp_Dir(x[0], x[1], x[2]));

	new_object->ReadBaseXML(element);

	return new_object;
}
Esempio n. 20
0
void occQt::makeChamfer()
{
    gp_Ax2 anAxis;
    anAxis.SetLocation(gp_Pnt(8.0, 50.0, 0.0));

    TopoDS_Shape aTopoBox = BRepPrimAPI_MakeBox(anAxis, 3.0, 4.0, 5.0);
    BRepFilletAPI_MakeChamfer MC(aTopoBox);
    TopTools_IndexedDataMapOfShapeListOfShape aEdgeFaceMap;

    TopExp::MapShapesAndAncestors(aTopoBox, TopAbs_EDGE, TopAbs_FACE, aEdgeFaceMap);

    for (Standard_Integer i = 1; i <= aEdgeFaceMap.Extent(); ++i)
    {
        TopoDS_Edge anEdge = TopoDS::Edge(aEdgeFaceMap.FindKey(i));
        TopoDS_Face aFace = TopoDS::Face(aEdgeFaceMap.FindFromIndex(i).First());

        MC.Add(0.6, 0.6, anEdge, aFace);
    }

    Handle_AIS_Shape anAisShape = new AIS_Shape(MC.Shape());
    anAisShape->SetColor(Quantity_NOC_TOMATO);

    mContext->Display(anAisShape);
}
Esempio n. 21
0
HeeksObj* CreateExtrusionOrRevolution(std::list<HeeksObj*> list, double height_or_angle, bool solid_if_possible, bool revolution_not_extrusion, double taper_angle_for_extrusion, bool add_new_objects)
{
	std::list<TopoDS_Shape> faces_or_wires;

	ConvertToFaceOrWire(list, faces_or_wires, (fabs(taper_angle_for_extrusion) <= 0.0000001) && solid_if_possible);

	std::list<TopoDS_Shape> new_shapes;
	gp_Trsf trsf = wxGetApp().GetDrawMatrix(false);
	if(revolution_not_extrusion)
	{
		CreateRevolutions(faces_or_wires, new_shapes, gp_Ax1(gp_Pnt(0, 0, 0).Transformed(trsf), gp_Vec(1, 0, 0).Transformed(trsf)), height_or_angle);
	}
	else
	{
		CreateExtrusions(faces_or_wires, new_shapes, gp_Vec(0, 0, height_or_angle).Transformed(trsf), taper_angle_for_extrusion, solid_if_possible);
	}
	HeeksObj* new_object = 0;
	if(new_shapes.size() > 0)
	{
		for(std::list<TopoDS_Shape>::iterator It = new_shapes.begin(); It != new_shapes.end(); It++){
			TopoDS_Shape& shape = *It;
			new_object = CShape::MakeObject(shape, revolution_not_extrusion ? _("Revolved Solid") : _("Extruded Solid"), SOLID_TYPE_UNKNOWN, wxGetApp().current_color, 1.0f);
			if(add_new_objects)
				wxGetApp().AddUndoably(new_object, NULL, NULL);
			else
				break;
		}
	}

	for(std::list<TopoDS_Shape>::iterator It = faces_or_wires.begin(); It != faces_or_wires.end(); It++)
	{
		TopoDS_Shape shape = *It;
		shape.Free();
	}
	return new_object;
}
Esempio n. 22
0
void HGear::SetSegmentsVariables(void(*callbackfunc)(const double *p))const
{
	callbackfunc_for_point = callbackfunc;
	gear_for_point = this;
	gp_Trsf rotation;
	rotation.SetRotation(gp_Ax1(gp_Pnt(0, 0, 0), gp_Dir(0, 0, 1)), m_angle * M_PI/180);
	mat_for_point = make_matrix(m_pos.Location(), m_pos.XDirection(), m_pos.YDirection());
	mat_for_point = rotation.Multiplied(mat_for_point);
	cone_sin_for_point = sin(m_cone_half_angle);
	cone_cos_for_point = cos(m_cone_half_angle);

	pitch_radius = (double)(m_module * m_num_teeth)/2;
	inside_radius = pitch_radius - m_dedendum_multiplier*m_module;
	outside_radius = pitch_radius + (m_addendum_multiplier*m_module + m_addendum_offset);
	base_radius = pitch_radius * cos(gear_for_point->m_pressure_angle) / cos(gear_for_point->m_cone_half_angle);

	if(inside_radius < base_radius)inside_radius = base_radius;

	inside_phi_and_angle = involute_intersect(inside_radius);
	outside_phi_and_angle = involute_intersect(outside_radius);
	tip_relief_phi_and_angle = involute_intersect(outside_radius - m_tip_relief);
	middle_phi_and_angle = involute_intersect(pitch_radius);
	spline_points_for_gear.clear();
}
Esempio n. 23
0
/// This tests checks, if the bspline
/// is really going through the points
TEST(BSplines, symmetricBSpline_interp)
{
    std::vector<gp_Pnt> points;
    points.push_back(gp_Pnt(0,0,1));
    points.push_back(gp_Pnt(0,-0.2, 0.8));
    points.push_back(gp_Pnt(0,-sqrt(0.5),sqrt(0.5)));
    points.push_back(gp_Pnt(0,-1,0));
    points.push_back(gp_Pnt(0,-sqrt(0.5),-sqrt(0.5)));
    points.push_back(gp_Pnt(0,0,-1));

    Handle(Geom_BSplineCurve) curve;
    tigl::CTiglSymetricSplineBuilder builder(points);

    ASSERT_NO_THROW(curve = builder.GetBSpline());

    GeomAPI_ProjectPointOnCurve proj;
    proj.Init(curve, curve->FirstParameter(), curve->LastParameter());
    for (unsigned int i = 0; i < points.size(); ++i) {
        gp_Pnt p = points[i];
        proj.Perform(p);
        ASSERT_GE(proj.NbPoints(), 1);
        ASSERT_LT(proj.LowerDistance(), 1e-10);
    }
}
//================================================================
// Function : TexturesExt_Presentation::sampleKitchen
// Purpose  : kitchen with texturized items in it.
//================================================================
void TexturesExt_Presentation::sampleKitchen()
{
  TopoDS_Shape aShape;

  if (!loadShape(aShape, "Kitchen\\Room.brep"))
    return;

  gp_Trsf aTrsf;
  gp_Ax3 NewCoordSystem (gp_Pnt(-1,-1, -1),gp_Dir(0,0,1));
  gp_Ax3 CurrentCoordSystem(gp_Pnt(0,0,0),gp_Dir(0,0,1));
  aTrsf.SetDisplacement(CurrentCoordSystem, NewCoordSystem);
  aShape.Location(TopLoc_Location(aTrsf));

  moveScale(aShape);

  // draw kitchen room whithout one wall (to better see the insides)
  TopTools_IndexedMapOfShape aFaces;
  TopExp::MapShapes(aShape, TopAbs_FACE, aFaces);  
  Standard_Integer nbFaces = aFaces.Extent();

  // create a wooden kitchen floor
  // the floor's face will be textured with texture from chataignier.gif
  DISP(Texturize(aFaces(5),"plancher.gif",1,1,2,1));

  // texturize other faces of the room with texture from wallpaper.gif (walls)
  DISP(Texturize(aFaces(1),"wallpaper.gif",1,1,8,6));
  DISP(Texturize(aFaces(3),"wallpaper.gif",1,1,8,6));
  DISP(Texturize(aFaces(4),"wallpaper.gif",1,1,8,6));

//  DISP(drawShape(aFaces(1), Quantity_NOC_LIGHTPINK, Standard_False));
//  DISP(drawShape(aFaces(3), Quantity_NOC_LIGHTPINK, Standard_False));
//  DISP(drawShape(aFaces(4), Quantity_NOC_LIGHTPINK, Standard_False));

  // texturize furniture items with "wooden" texture
  if (loadShape(aShape, "Kitchen\\MODERN_Table_1.brep"))
  {
    moveScale(aShape);
    DISP(Texturize(aShape, "chataignier.gif"));
  }
  if (loadShape(aShape, "Kitchen\\MODERN_Chair_1.brep"))
  {
    moveScale(aShape);
    DISP(Texturize(aShape, "chataignier.gif"));
  }
  if (loadShape(aShape, "Kitchen\\MODERN_Cooker_1.brep"))
  {
    moveScale(aShape);

    aFaces.Clear();
    TopExp::MapShapes(aShape, TopAbs_FACE, aFaces);  
    nbFaces = aFaces.Extent();

    for (Standard_Integer i = 1; i <= nbFaces; i++)
    {
      if (i >= 59)
        DISP(drawShape(aFaces(i), Graphic3d_NOM_STEEL, Standard_False));
      else if (i >= 29)
        DISP(drawShape(aFaces(i), Graphic3d_NOM_ALUMINIUM, Standard_False));
      else if (i == 28)
        DISP(Texturize(aFaces(i), "cookerplate.gif"));
      else  
        DISP(Texturize(aFaces(i), "chataignier.gif"));
    }
  }
  if (loadShape(aShape, "Kitchen\\MODERN_Cooker_1_opened.brep"))
  {
    moveScale(aShape);
    DISP(Texturize(aShape, "chataignier.gif"));
  }
  if (loadShape(aShape, "Kitchen\\MODERN_Exhaust_1.brep"))
  {
    moveScale(aShape);
    DISP(drawShape(aShape, Graphic3d_NOM_STONE, Standard_False));
  }
  if (loadShape(aShape, "Kitchen\\MODERN_MVCooker_1.brep"))
  {
    moveScale(aShape);
    DISP(drawShape(aShape, Graphic3d_NOM_SILVER, Standard_False));
  }
  if (loadShape(aShape, "Kitchen\\MODERN_MVCooker_1_opened.brep"))
  {
    moveScale(aShape);
    DISP(drawShape(aShape, Graphic3d_NOM_SILVER, Standard_False));
  }
  if (loadShape(aShape, "Kitchen\\MODERN_Sink_1.brep"))
  {
    moveScale(aShape);

    aFaces.Clear();
    TopExp::MapShapes(aShape, TopAbs_FACE, aFaces);  
    nbFaces = aFaces.Extent();

    for (Standard_Integer i = 1; i <= nbFaces; i++)
    {
      if (i < 145)
        DISP(drawShape(aFaces(i), Graphic3d_NOM_ALUMINIUM, Standard_False));
      else if (i == 145)
        DISP(Texturize(aFaces(i), "cookerplate.gif"));
      else  
        DISP(Texturize(aFaces(i), "chataignier.gif"));
    }
  }
  if (loadShape(aShape, "Kitchen\\MODERN_Sink_1_opened.brep"))
  {
    moveScale(aShape);
    DISP(Texturize(aShape, "chataignier.gif"));
  }
  if (loadShape(aShape, "Kitchen\\MODERN_Refrigerator_1.brep"))
  {
    moveScale(aShape);
    DISP(drawShape(aShape, Graphic3d_NOM_CHROME, Standard_False));
  }
  if (loadShape(aShape, "Kitchen\\MODERN_Refrigerator_1_opened.brep"))
  {
    moveScale(aShape);
    DISP(drawShape(aShape, Graphic3d_NOM_CHROME, Standard_False));
  }

  getViewer()->Update();
}
Esempio n. 25
0
SALOME_WNT_EXPORT
  TopoDS_Shape ImportIGES (const TCollection_AsciiString& theFileName,
                       const TCollection_AsciiString& theFormatName,
                       TCollection_AsciiString&       theError,
		               const TDF_Label&               theShapeLabel)
  {
    IGESControl_Reader aReader;
    TopoDS_Shape aResShape;
    Interface_Static::SetCVal("xstep.cascade.unit","M");
    try {
      IFSelect_ReturnStatus status = aReader.ReadFile(theFileName.ToCString());

      if (status == IFSelect_RetDone) {

        if( theFormatName == "IGES_UNIT" ) {
	  Handle(IGESData_IGESModel) aModel = 
	    Handle(IGESData_IGESModel)::DownCast(aReader.Model());
	  gp_Pnt P(1.0,0.0,0.0);
	  if(!aModel.IsNull()) {
	    Handle(TCollection_HAsciiString) aUnitName = 
	      aModel->GlobalSection().UnitName();
	    //cout<<"aUnitName = "<<aUnitName->ToCString()<<endl;
	    //cout<<"aUnitFlag = "<<aModel->GlobalSection().UnitFlag()<<endl;
	    if( aUnitName->String()=="MM" ) {
	      P = gp_Pnt(0.001,0.0,0.0);
	    }
	    else if( aUnitName->String()=="CM" ) {
	      P = gp_Pnt(0.01,0.0,0.0);
	    }
	  }
	  BRep_Builder B;
	  TopoDS_Vertex V;
	  B.MakeVertex(V,P,1.e-7);
	  aResShape = V;
	  return aResShape;
	}
	if( theFormatName == "IGES_SCALE" ) {
	  //cout<<"need re-scale a model"<<endl;
	  // set UnitFlag to 'meter'
	  Handle(IGESData_IGESModel) aModel = 
	    Handle(IGESData_IGESModel)::DownCast(aReader.Model());
	  if(!aModel.IsNull()) {
	    IGESData_GlobalSection aGS = aModel->GlobalSection();
	    aGS.SetUnitFlag(6);
	    aModel->SetGlobalSection(aGS);
	  }
	}

        MESSAGE("ImportIGES : all Geometry Transfer");
        //OCC 5.1.2 porting
        //     aReader.Clear();
        //     aReader.TransferRoots(false);
        aReader.ClearShapes();
        aReader.TransferRoots();

        MESSAGE("ImportIGES : count of shapes produced = " << aReader.NbShapes());
        aResShape = aReader.OneShape();

        // BEGIN: Store names of sub-shapes from file
        Handle(Interface_InterfaceModel) Model = aReader.WS()->Model();
        Handle(XSControl_TransferReader) TR = aReader.WS()->TransferReader();
        if (!TR.IsNull()) {
          Handle(Transfer_TransientProcess) TP = /*TransientProcess();*/TR->TransientProcess();
          Standard_Integer nb = Model->NbEntities();
          for (Standard_Integer i = 1; i <= nb; i++) {
            Handle(IGESData_IGESEntity) ent = Handle(IGESData_IGESEntity)::DownCast(Model->Value(i));
            if (ent.IsNull() || ! ent->HasName()) continue;

            // find target shape
            Handle(Transfer_Binder) binder = TP->Find(ent);
            if (binder.IsNull()) continue;
            TopoDS_Shape S = TransferBRep::ShapeResult(binder);
            if (S.IsNull()) continue;

            // create label and set shape
            TDF_Label L;
            TDF_TagSource aTag;
            L = aTag.NewChild(theShapeLabel);
            TNaming_Builder tnBuild (L);
            tnBuild.Generated(S);

            // set a name
            TCollection_AsciiString string = ent->NameValue()->String();
            string.LeftAdjust();
            string.RightAdjust();
            TCollection_ExtendedString str (string);
            TDataStd_Name::Set(L, str);
          }
        }
        // END: Store names
      } else {
//        switch (status) {
//        case IFSelect_RetVoid:
//          theError = "Nothing created or No data to process";
//          break;
//        case IFSelect_RetError:
//          theError = "Error in command or input data";
//          break;
//        case IFSelect_RetFail:
//          theError = "Execution was run, but has failed";
//          break;
//        case IFSelect_RetStop:
//          theError = "Execution has been stopped. Quite possible, an exception was raised";
//          break;
//        default:
//          break;
//        }
        theError = "Wrong format of the imported file. Can't import file.";
	aResShape.Nullify();
      }
    }
    catch(Standard_Failure) {
      Handle(Standard_Failure) aFail = Standard_Failure::Caught();
      theError = aFail->GetMessageString();
      aResShape.Nullify();
    }
    return aResShape;
  }
/**
    take the input point
    move it 'distance' back along X
    determine the overall sketch length
    determine the distance along the sketch for this character based on the distance along the text as well as the justification
    find the point along the sketch for this character
    find the angle of rotation at this point along the sketch
    rotate the point about this character's origin
    translate the point to align it with the point along the sketch.
    return this adjusted point location.
 */
gp_Pnt & COrientationModifier::Transform(gp_Trsf existing_transformation, const double _distance, gp_Pnt & point, const float width )
{
	double tolerance = wxGetApp().m_geom_tol;
	gp_Pnt original_location(point);

    if (m_edges.size() == 0)
	{
		// No children so no modification of position.
		point = original_location;
		return(point);
	}

    // The text is formatted as though the characters start at the origin (0,0,0) and move
    // to the right by the character and/or word spacing as subsequent characters are rendered.
    // This step moves this character so that its origin is at the (0,0,0) location so that
    // we rotate just this character about its origin.  We can use the _distance value as
    // the offset along the X axis at which point this character's origin is located.
	gp_Pnt origin(0.0, 0.0, 0.0);
	gp_Trsf move_to_origin;
	move_to_origin.SetTranslation(origin, gp_Pnt(-1.0 * _distance, 0.0, 0.0));
	point.Transform(move_to_origin);

    // Make sure it's positive.
	double distance(_distance);
	if (distance < 0) distance *= -1.0;

	// Now adjust the distance based on a combination of the justification and how far through
	// the text string we are.
	double distance_remaining = distance;

	switch (m_params.m_justification)
	{
	case COrientationModifierParams::eLeftJustified:
        if (SketchIsClosed())
        {
            // Centre the text on the left edge.  NOTE: This assumes that it's a circle with
            // the starting location in the positive X axis.
            distance_remaining = (m_total_edge_length / 2.0) - (width / 2.0) + distance;
        }
        else
        {
            distance_remaining = distance;	// No special adjustment required.
        }
		break;

	case COrientationModifierParams::eRightJustified:
        if (SketchIsClosed())
        {
            distance_remaining = m_total_edge_length - (width / 2.0) + distance;
        }
        else
        {
            distance_remaining = m_total_edge_length - width + distance;
        }
		break;

	case COrientationModifierParams::eCentreJustified:
		distance_remaining = (m_total_edge_length / 2.0) - (width / 2.0) + distance;
		break;

    case COrientationModifierParams::eTopJustified:
        distance_remaining = (m_total_edge_length / 4.0) - (width / 2.0) + distance;
        break;

    case COrientationModifierParams::eBottomJustified:
        distance_remaining = (m_total_edge_length * 3.0 / 4.0) - (width / 2.0) + distance;
        break;
	} // End switch


    while ((distance_remaining > tolerance) && (m_edges.size() > 0))
    {
        for (Edges_t::iterator itEdge = m_edges.begin(); itEdge != m_edges.end(); itEdge++)
        {

			double edge_length = itEdge->second;
			if (edge_length < distance_remaining)
			{
				distance_remaining -= edge_length;
			}
			else
			{
				// The point we're after is along this edge somewhere.  Find the point and
				// the first derivative at that point.  The vector returned will allow us to
				// find out what angle the sketch is at this point.  We can use this angle
				// to rotate the character.

				BRepAdaptor_Curve curve(itEdge->first);
				gp_Pnt p;
				gp_Vec vec;
				double proportion = distance_remaining / edge_length;
				Standard_Real U = ((curve.LastParameter() - curve.FirstParameter()) * proportion) + curve.FirstParameter();
				curve.D1(U, p, vec);

				double angle = 0.0;
				if (m_params.m_sketch_rotates_text)
				{
				    // Measure the angle with respect to the positive X axis (when looking down from the top)
				    gp_Vec x_axis(gp_Pnt(0.0, 0.0, 0.0), gp_Pnt(1.0, 0.0, 0.0));
				    gp_Vec from_top_down( gp_Pnt(0.0, 0.0, 0.0), gp_Pnt(0.0, 0.0, 1.0));
				    angle = x_axis.AngleWithRef(vec, from_top_down);
				}

                // If the user wants each character given an extra quarter turn (or more)
                // then add this in now.
				if (m_params.m_number_of_rotations > 0)
				{
				    for (int i=0; i<m_params.m_number_of_rotations; i++)
				    {
				        angle += (PI / 2.0);
				    }
				}
				else
				{
				    for (int i=m_params.m_number_of_rotations; i<0; i++)
				    {
				        angle -= (PI / 2.0);
				    }
				}

                // Rotate the point around the origin.
				angle *= -1.0;
				gp_Trsf transformation;
				transformation.SetRotation( gp_Ax1(origin, gp_Vec(0,0,-1)), angle );
				point.Transform( transformation );

                // And then translate the point from the origin to the point along the sketch.
				gp_Trsf around;
				around.SetTranslation(origin, p);
				point.Transform(around);

				return(point);
			}
		} // End for
	} // End while

	return(point);
}
Esempio n. 27
0
TEST(gpTestSuite, testBuildThousandsPoints)
{
    for (int i=1;i<10000;i++) {
        gp_Pnt(1,2,3);
    }
}
Esempio n. 28
0
CCylinder::CCylinder(const TopoDS_Solid &solid, const wxChar* title, const HeeksColor& col, float opacity):CSolid(solid, title, col, opacity), m_pos(gp_Pnt(0, 0, 0), gp_Dir(0, 0, 1), gp_Dir(1, 0, 0)), m_radius(0.0), m_height(0.0)
{
}
Esempio n. 29
0
gp_Pnt Point::getGP_Pnt(){
	return gp_Pnt(x, y, z);
}
Esempio n. 30
0
	DisplacementNodeY = nodeList[1];
	RotationNode = nodeList[2];
	myAISContext = ais;
	boolean=false;

	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;
};