//Pipe.h
#include <TColStd_Array1OfInteger.hxx>
#define SIZE_ONE 10
#define SIZE_TWO 8
#define SIZE_THREE 6
#define SIZE_FOUR 3
#define LENGTH 500
#define RADIUS 100
#define THICK 10
struct Position
{
gp_Pnt center;
Standard_Integer X;
Standard_Integer Y;
Standard_Integer Z;
};
enum PipeType{LINEAR,PLANE_TWO,PLANE_THREE,PLANE_FOUR,PLANE_T,STERE_THREE,STERE_FOUR,STERE_FIVE,STERE_SIX};
class Pipe //管子基类
{
public:
Pipe* next;
public:
Pipe();
~Pipe();
virtual TopoDS_Shape MakeShape(){ TopoDS_Shape aShape;return aShape;}
};
class _Pipe:public Pipe //派生管子
{
private:
PipeType type;
Position *position;
Standard_Real thick;
Standard_Real *length_array; //长度数组
Standard_Real *radius_array; //半径数组
Standard_Integer point_num;
public:
_Pipe(PipeType p=LINEAR); //里面的case语句进行判断并初始化成员变量
~_Pipe();
public:
void SetPipeType(PipeType p);
PipeType GetPipeType();
void SetRadius(Standard_Integer index,Standard_Real r); //设置半径的规格
Standard_Real* GetRadius_Array();
void SetLength(Standard_Integer index,Standard_Real l); //设置长度的规格
Standard_Real* GetLength_Array();
void SetPosition(gp_Pnt,Standard_Real,Standard_Real,Standard_Real);
void SetPosition_Center(gp_Pnt);
void SetPosition_Axis(Standard_Real,Standard_Real,Standard_Real);
void SetPosition_Axis_X(Standard_Real);
void SetPosition_Axis_Y(Standard_Real);
void SetPosition_Axis_Z(Standard_Real);
Position* GetPosition();
TopoDS_Shape MakeShape();
TopoDS_Shape MakeShape_Linear(Standard_Integer *a,Standard_Integer n);
TopoDS_Shape MakeShape_Plane_Two(Standard_Integer *a,Standard_Integer n);
TopoDS_Shape MakeShape_Plane_T(Standard_Integer *a,Standard_Integer n);
// TopoDS_Shape MakeShape_Plane_Three();
TopoDS_Shape MakeShape_Plane_Four(Standard_Integer *a,Standard_Integer n);
TopoDS_Shape MakeShape_Stere_Three(Standard_Integer *a,Standard_Integer n);
TopoDS_Shape MakeShape_Stere_Four(Standard_Integer *a,Standard_Integer n);
TopoDS_Shape MakeShape_Stere_Five(Standard_Integer *a,Standard_Integer n);
TopoDS_Shape MakeShape_Stere_Six(Standard_Integer *a,Standard_Integer n);
};
class Valve //阀门
{
private:
gp_Pnt location;
gp_Dir norm;
Standard_Integer size;
public:
Valve();
~Valve();
public:
void SetParameters(gp_Pnt,gp_Dir,Standard_Integer);
void SetLocation(gp_Pnt);
void SetNormal(gp_Dir);
gp_Pnt GetLocation();
gp_Dir GetNormal();
void SetSize(Standard_Integer);
Standard_Integer GetSize();
TopoDS_Shape MakeShape();
};
//Pipe.cpp
#include "stdafx.h"
#include "Pipe.h"
#include <BRepOffsetAPI_MakeThickSolid.hxx>
#include <BRepAlgoAPI_Fuse.hxx>
Pipe::Pipe()
{
}
Pipe::~Pipe()
{
Pipe *p=next,*q;
while(p!=NULL)
{
q=p;
p=p->next;
delete q;
}
}
_Pipe::_Pipe(PipeType p)
{
type=p;
radius_array=new Standard_Real[6];
for(Standard_Integer i=0;i<6;i++)
radius_array[i]=0;
length_array=new Standard_Real[6];
for(i=0;i<6;i++)
length_array[i]=0;
position=new Position;
position->center=gp_Pnt(0,0,0);
thick=THICK;
switch(p)
{
case LINEAR:
point_num=2;
SetPosition(position->center,2,0,0);
radius_array[0]=radius_array[1]=RADIUS;
length_array[0]=length_array[1]=LENGTH;
break;
case PLANE_TWO:
point_num=2;
SetPosition(position->center,1,0,1); //XOZ平面
radius_array[0]=RADIUS;
radius_array[4]=RADIUS;
length_array[0]=LENGTH;
length_array[4]=LENGTH;
break;
case PLANE_THREE:break;
case PLANE_FOUR:
point_num=4;
SetPosition(position->center,2,0,2);
radius_array[0]=radius_array[1]=RADIUS;
radius_array[4]=radius_array[5]=RADIUS;
length_array[0]=length_array[1]=LENGTH;
length_array[4]=length_array[5]=LENGTH;
break;
case PLANE_T:
point_num=3;
SetPosition(position->center,2,0,1);
radius_array[0]=radius_array[1]=RADIUS;
radius_array[4]=RADIUS;
length_array[0]=length_array[1]=LENGTH;
length_array[4]=LENGTH;
break;
case STERE_THREE:
point_num=3;
SetPosition(position->center,1,1,1);
radius_array[0]=RADIUS;
radius_array[2]=RADIUS;
radius_array[4]=RADIUS;
length_array[0]=LENGTH;
length_array[2]=LENGTH;
length_array[4]=LENGTH;
break;
case STERE_FOUR:
point_num=4;
SetPosition(position->center,2,1,1);
radius_array[0]=radius_array[1]=RADIUS;
radius_array[2]=RADIUS;
radius_array[4]=RADIUS;
length_array[0]=length_array[1]=LENGTH;
length_array[2]=LENGTH;
length_array[4]=LENGTH;
break;
case STERE_FIVE:
point_num=5;
SetPosition(position->center,2,2,1);
radius_array[0]=radius_array[1]=RADIUS;
radius_array[2]=radius_array[3]=RADIUS;
radius_array[4]=RADIUS;
length_array[0]=length_array[1]=LENGTH;
length_array[2]=length_array[3]=LENGTH;
length_array[4]=LENGTH;
break;
case STERE_SIX:
point_num=6;
SetPosition(position->center,2,2,2);
radius_array[0]=radius_array[1]=RADIUS;
radius_array[2]=radius_array[3]=RADIUS;
radius_array[4]=radius_array[4]=RADIUS;
length_array[0]=length_array[5]=LENGTH;
length_array[2]=length_array[3]=LENGTH;
length_array[4]=length_array[5]=LENGTH;
break;
default:break;
}
}
_Pipe::~_Pipe()
{
if(length_array)
delete length_array;
if(radius_array)
delete radius_array;
if(position)
delete position;
}
void _Pipe::SetRadius(Standard_Integer index,Standard_Real r)
{
if(index>=0 && index<=5)
radius_array[index]=r;
else
AfxMessageBox("SetRadius(Standard_Integer index,Standard_Real r): the index is out of range!");
}
Standard_Real* _Pipe::GetRadius_Array()
{
return radius_array;
}
void _Pipe::SetLength(Standard_Integer index,Standard_Real l)
{
if(index>=0 && index<=5)
length_array[index]=l;
else
AfxMessageBox("SetLength(Standard_Integer index,Standard_Real l): the index is out of range!");
}
Standard_Real* _Pipe::GetLength_Array()
{
return length_array;
}
void _Pipe::SetPosition(gp_Pnt pt,Standard_Real xx,Standard_Real yy,Standard_Real zz)
{
position->center=pt;
position->X=xx;
position->Y=yy;
position->Z=zz;
}
void _Pipe::SetPosition_Center(gp_Pnt pt)
{
position->center=pt;
}
void _Pipe::SetPosition_Axis(Standard_Real xx,Standard_Real yy,Standard_Real zz)
{
position->X=xx;
position->Y=yy;
position->Z=zz;
}
void _Pipe::SetPosition_Axis_X(Standard_Real xx)
{
position->X=xx; //1表示x轴的正向,-1表示x轴的负向,2表示x轴两个方向都有
}
void _Pipe::SetPosition_Axis_Y(Standard_Real yy)
{
position->Y=yy;
}
void _Pipe::SetPosition_Axis_Z(Standard_Real zz)
{
position->Z=zz;
}
Position* _Pipe::GetPosition()
{
return position;
}
void _Pipe::SetPipeType(PipeType p)
{
for(Standard_Integer i=0;i<6;i++)
{
radius_array[i]=length_array[i]=0;
}
type=p;
switch(p)
{
case LINEAR:
point_num=2;
SetPosition(position->center,0,0,0);
break;
case PLANE_TWO:
point_num=2;
SetPosition(position->center,0,0,0);
break;
case PLANE_THREE:break;
case PLANE_FOUR:
point_num=4;
SetPosition(position->center,0,0,0);
break;
case PLANE_T:
point_num=3;
SetPosition(position->center,0,0,0);
break;
case STERE_THREE:
point_num=3;
SetPosition(position->center,0,0,0);
break;
case STERE_FOUR:
point_num=4;
SetPosition(position->center,0,0,0);
break;
case STERE_FIVE:
point_num=5;
SetPosition(position->center,0,0,0);
break;
case STERE_SIX:
point_num=6;
SetPosition(position->center,0,0,0);
break;
default:break;
}
}
PipeType _Pipe::GetPipeType()
{
return type;
}
TopoDS_Shape _Pipe::MakeShape()
{
Standard_Integer a[6];
TopoDS_Shape aShape;
for(Standard_Integer j=0;j<6;j++)
a[j]=0; //用来标记坐标轴方向
Standard_Integer k=0;
for(Standard_Integer i=0;i<6;i++)
{
if(radius_array[i]!=0)
{
a[k++]=i;
}
}
switch(type)
{
case LINEAR:
aShape=MakeShape_Linear(a,2);
break;
case PLANE_TWO:
aShape=MakeShape_Plane_Two(a,2);
break;
case PLANE_THREE:break;
case PLANE_FOUR:
aShape=MakeShape_Plane_Four(a,4);
break;
case PLANE_T:
aShape=MakeShape_Plane_T(a,3);
break;
case STERE_THREE:
aShape=MakeShape_Stere_Three(a,3);
break;
case STERE_FOUR:
aShape=MakeShape_Stere_Four(a,4);
break;
case STERE_FIVE:
aShape=MakeShape_Stere_Five(a,5);
break;
case STERE_SIX:
aShape=MakeShape_Stere_Six(a,6);
break;
default:break;
}
return aShape;
}
TopoDS_Shape _Pipe::MakeShape_Linear(Standard_Integer *a,Standard_Integer n)
{
gp_Ax2 *axis=new gp_Ax2[2];
for(Standard_Integer i=0;i<n;i++)
{
switch(a[i])
{
case 0:
axis[i]=gp_Ax2(position->center,gp::DX());
break;
case 1:
axis[i]=gp_Ax2(position->center,gp_Dir(-1,0,0));
break;
case 2:
axis[i]=gp_Ax2(position->center,gp::DY());
break;
case 3:
axis[i]=gp_Ax2(position->center,gp_Dir(0,-1,0));
break;
case 4:
axis[i]=gp_Ax2(position->center,gp::DZ());
break;
case 5:
axis[i]=gp_Ax2(position->center,gp_Dir(0,0,-1));
break;
default:
break;
}
}
BRepPrimAPI_MakeCylinder Cylinder1(axis[0],radius_array[a[0]],length_array[a[0]]);
TopoDS_Shape aShape1= Cylinder1.Shape();
BRepPrimAPI_MakeCylinder Cylinder2(axis[1],radius_array[a[1]],length_array[a[1]]);
TopoDS_Shape aShape2= Cylinder2.Shape();
aShape1=BRepAlgoAPI_Fuse(aShape1,aShape2);
//Body : Create a Hollowed Solid
TopoDS_Face faceToRemove1;
TopoDS_Face faceToRemove2;
Standard_Real Max =-1000000000;
Standard_Real Min = 1000000000;
for(TopExp_Explorer aFaceExplorer(aShape1, 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();
gp_Vec aVec= gp_Vec(aPnt.X()-(position->center).X(),aPnt.Y()-(position->center).Y(),aPnt.Z()-(position->center).Z());
Standard_Real dot1=aVec.Dot(axis[0].Direction());
// Standard_Real dot2=aVec.Dot(axis[1].Direction());
if(dot1 > Max)
{
Max= dot1;
faceToRemove1 = aFace;
}
if( dot1 < Min)
{
Min = dot1;
faceToRemove2 = aFace;
}
}
}
TopTools_ListOfShape facesToRemove;
facesToRemove.Append(faceToRemove1);
facesToRemove.Append(faceToRemove2);
aShape1 = BRepOffsetAPI_MakeThickSolid(aShape1, facesToRemove , -thick, 1.e-3);
return aShape1;
}
TopoDS_Shape _Pipe::MakeShape_Plane_Two(Standard_Integer *a,Standard_Integer n)
{
gp_Ax2 *axis=new gp_Ax2[2];
for(Standard_Integer i=0;i<n;i++)
{
switch(a[i])
{
case 0:
axis[i]=gp_Ax2(position->center,gp::DX());
break;
case 1:
axis[i]=gp_Ax2(position->center,gp_Dir(-1,0,0));
break;
case 2:
axis[i]=gp_Ax2(position->center,gp::DY());
break;
case 3:
axis[i]=gp_Ax2(position->center,gp_Dir(0,-1,0));
break;
case 4:
axis[i]=gp_Ax2(position->center,gp::DZ());
break;
case 5:
axis[i]=gp_Ax2(position->center,gp_Dir(0,0,-1));
break;
default:
break;
}
}
BRepPrimAPI_MakeCylinder Cylinder1(axis[0],radius_array[a[0]],length_array[a[0]]);
TopoDS_Shape aShape1= Cylinder1.Shape();
BRepPrimAPI_MakeCylinder Cylinder2(axis[1],radius_array[a[1]],length_array[a[1]]);
TopoDS_Shape aShape2= Cylinder2.Shape();
BRepPrimAPI_MakeSphere Sphere(axis[0],radius_array[a[0]]*1.00001);
TopoDS_Shape ball = Sphere.Shape();
aShape1=BRepAlgoAPI_Fuse(aShape1,aShape2);
aShape1=BRepAlgoAPI_Fuse(aShape1,ball);
//Body : Create a Hollowed Solid
TopoDS_Face faceToRemove[2];
Standard_Real Max[2]={-1000000000,-1000000000};
for(TopExp_Explorer aFaceExplorer(aShape1, 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();
gp_Vec aVec= gp_Vec(aPnt.X()-(position->center).X(),aPnt.Y()-(position->center).Y(),aPnt.Z()-(position->center).Z());
Standard_Real dot[2];
dot[0]=aVec.Dot(axis[0].Direction());
dot[1]=aVec.Dot(axis[1].Direction());
if(dot[0] > Max[0])
{
Max[0]= dot[0];
faceToRemove[0] = aFace;
}
if(dot[1] > Max[1])
{
Max[1]= dot[1];
faceToRemove[1] = aFace;
}
}
}
TopTools_ListOfShape facesToRemove;
facesToRemove.Append(faceToRemove[0]);
facesToRemove.Append(faceToRemove[1]);
aShape1 = BRepOffsetAPI_MakeThickSolid(aShape1, facesToRemove , -thick, 1.e-3);
return aShape1;
}
TopoDS_Shape _Pipe::MakeShape_Plane_T(Standard_Integer *a,Standard_Integer n)
{
gp_Ax2 *axis=new gp_Ax2[3];
for(Standard_Integer i=0;i<n;i++)
{
switch(a[i])
{
case 0:
axis[i]=gp_Ax2(position->center,gp::DX());
break;
case 1:
axis[i]=gp_Ax2(position->center,gp_Dir(-1,0,0));
break;
case 2:
axis[i]=gp_Ax2(position->center,gp::DY());
break;
case 3:
axis[i]=gp_Ax2(position->center,gp_Dir(0,-1,0));
break;
case 4:
axis[i]=gp_Ax2(position->center,gp::DZ());
break;
case 5:
axis[i]=gp_Ax2(position->center,gp_Dir(0,0,-1));
break;
default:
break;
}
}
BRepPrimAPI_MakeCylinder Cylinder1(axis[0],radius_array[a[0]],length_array[a[0]]);
TopoDS_Shape aShape1= Cylinder1.Shape();
BRepPrimAPI_MakeCylinder Cylinder2(axis[1],radius_array[a[1]],length_array[a[1]]);
TopoDS_Shape aShape2= Cylinder2.Shape();
BRepPrimAPI_MakeCylinder Cylinder3(axis[2],radius_array[a[2]],length_array[a[2]]);
TopoDS_Shape aShape3= Cylinder3.Shape();
aShape1=BRepAlgoAPI_Fuse(aShape1,aShape2);
aShape1=BRepAlgoAPI_Fuse(aShape1,aShape3);
//Body : Create a Hollowed Solid
TopoDS_Face faceToRemove[3];
Standard_Real Max[3]={-1000000000,-1000000000,-1000000000};
for(TopExp_Explorer aFaceExplorer(aShape1, 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();
gp_Vec aVec= gp_Vec(aPnt.X()-(position->center).X(),aPnt.Y()-(position->center).Y(),aPnt.Z()-(position->center).Z());
Standard_Real dot[3];
dot[0]=aVec.Dot(axis[0].Direction());
dot[1]=aVec.Dot(axis[1].Direction());
dot[2]=aVec.Dot(axis[2].Direction());
for(i=0;i<n;i++)
{
if(dot[i]>Max[i])
{
Max[i]=dot[i];
faceToRemove[i]=aFace;
}
}
}
}
TopTools_ListOfShape facesToRemove;
for(i=0;i<n;i++)
facesToRemove.Append(faceToRemove[i]);
aShape1 = BRepOffsetAPI_MakeThickSolid(aShape1, facesToRemove , thick, 1.e-3);
return aShape1;
}
TopoDS_Shape _Pipe::MakeShape_Plane_Four(Standard_Integer *a,Standard_Integer n)
{
gp_Ax2 *axis=new gp_Ax2[4];
for(Standard_Integer i=0;i<n;i++)
{
switch(a[i])
{
case 0:
axis[i]=gp_Ax2(position->center,gp::DX());
break;
case 1:
axis[i]=gp_Ax2(position->center,gp_Dir(-1,0,0));
break;
case 2:
axis[i]=gp_Ax2(position->center,gp::DY());
break;
case 3:
axis[i]=gp_Ax2(position->center,gp_Dir(0,-1,0));
break;
case 4:
axis[i]=gp_Ax2(position->center,gp::DZ());
break;
case 5:
axis[i]=gp_Ax2(position->center,gp_Dir(0,0,-1));
break;
default:
break;
}
}
BRepPrimAPI_MakeCylinder Cylinder1(axis[0],radius_array[a[0]],length_array[a[0]]);
TopoDS_Shape aShape1= Cylinder1.Shape();
BRepPrimAPI_MakeCylinder Cylinder2(axis[1],radius_array[a[1]],length_array[a[1]]);
TopoDS_Shape aShape2= Cylinder2.Shape();
BRepPrimAPI_MakeCylinder Cylinder3(axis[2],radius_array[a[2]],length_array[a[2]]);
TopoDS_Shape aShape3= Cylinder3.Shape();
BRepPrimAPI_MakeCylinder Cylinder4(axis[3],radius_array[a[3]],length_array[a[3]]);
TopoDS_Shape aShape4= Cylinder4.Shape();
aShape1=BRepAlgoAPI_Fuse(aShape1,aShape2);
aShape1=BRepAlgoAPI_Fuse(aShape1,aShape3);
aShape1=BRepAlgoAPI_Fuse(aShape1,aShape4);
//Body : Create a Hollowed Solid
TopoDS_Face faceToRemove[4];
Standard_Real Max[4]={-1000000000,-1000000000,-1000000000,-1000000000};
for(TopExp_Explorer aFaceExplorer(aShape1, 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();
gp_Vec aVec= gp_Vec(aPnt.X()-(position->center).X(),aPnt.Y()-(position->center).Y(),aPnt.Z()-(position->center).Z());
Standard_Real dot[4];
dot[0]=aVec.Dot(axis[0].Direction());
dot[1]=aVec.Dot(axis[1].Direction());
dot[2]=aVec.Dot(axis[2].Direction());
dot[3]=aVec.Dot(axis[3].Direction());
for(i=0;i<n;i++)
{
if(dot[i]>Max[i])
{
Max[i]=dot[i];
faceToRemove[i]=aFace;
}
}
}
}
TopTools_ListOfShape facesToRemove;
for(i=0;i<n;i++)
facesToRemove.Append(faceToRemove[i]);
aShape1 = BRepOffsetAPI_MakeThickSolid(aShape1, facesToRemove , thick, 1.e-3);
return aShape1;
}
TopoDS_Shape _Pipe::MakeShape_Stere_Three(Standard_Integer *a,Standard_Integer n)
{
gp_Ax2 *axis=new gp_Ax2[3];
for(Standard_Integer i=0;i<n;i++)
{
switch(a[i])
{
case 0:
axis[i]=gp_Ax2(position->center,gp::DX());
break;
case 1:
axis[i]=gp_Ax2(position->center,gp_Dir(-1,0,0));
break;
case 2:
axis[i]=gp_Ax2(position->center,gp::DY());
break;
case 3:
axis[i]=gp_Ax2(position->center,gp_Dir(0,-1,0));
break;
case 4:
axis[i]=gp_Ax2(position->center,gp::DZ());
break;
case 5:
axis[i]=gp_Ax2(position->center,gp_Dir(0,0,-1));
break;
default:
break;
}
}
BRepPrimAPI_MakeCylinder Cylinder1(axis[0],radius_array[a[0]],length_array[a[0]]);
TopoDS_Shape aShape1= Cylinder1.Shape();
BRepPrimAPI_MakeCylinder Cylinder2(axis[1],radius_array[a[1]],length_array[a[1]]);
TopoDS_Shape aShape2= Cylinder2.Shape();
BRepPrimAPI_MakeCylinder Cylinder3(axis[2],radius_array[a[2]],length_array[a[2]]);
TopoDS_Shape aShape3= Cylinder3.Shape();
BRepPrimAPI_MakeSphere Sphere(axis[0],radius_array[a[0]]*1.00001);
TopoDS_Shape ball = Sphere.Shape();
aShape1=BRepAlgoAPI_Fuse(aShape1,aShape2);
aShape1=BRepAlgoAPI_Fuse(aShape1,aShape3);
aShape1=BRepAlgoAPI_Fuse(aShape1,ball);
//Body : Create a Hollowed Solid
TopoDS_Face faceToRemove[3];
Standard_Real Max[4]={-1000000000,-1000000000,-1000000000};
for(TopExp_Explorer aFaceExplorer(aShape1, 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();
gp_Vec aVec= gp_Vec(aPnt.X()-(position->center).X(),aPnt.Y()-(position->center).Y(),aPnt.Z()-(position->center).Z());
Standard_Real dot[3];
dot[0]=aVec.Dot(axis[0].Direction());
dot[1]=aVec.Dot(axis[1].Direction());
dot[2]=aVec.Dot(axis[2].Direction());
for(i=0;i<n;i++)
{
if(dot[i]>Max[i])
{
Max[i]=dot[i];
faceToRemove[i]=aFace;
}
}
}
}
TopTools_ListOfShape facesToRemove;
for(i=0;i<n;i++)
facesToRemove.Append(faceToRemove[i]);
aShape1 = BRepOffsetAPI_MakeThickSolid(aShape1, facesToRemove , thick, 1.e-3);
return aShape1;
}
TopoDS_Shape _Pipe::MakeShape_Stere_Four(Standard_Integer *a,Standard_Integer n)
{
gp_Ax2 *axis=new gp_Ax2[4];
for(Standard_Integer i=0;i<n;i++)
{
switch(a[i])
{
case 0:
axis[i]=gp_Ax2(position->center,gp::DX());
break;
case 1:
axis[i]=gp_Ax2(position->center,gp_Dir(-1,0,0));
break;
case 2:
axis[i]=gp_Ax2(position->center,gp::DY());
break;
case 3:
axis[i]=gp_Ax2(position->center,gp_Dir(0,-1,0));
break;
case 4:
axis[i]=gp_Ax2(position->center,gp::DZ());
break;
case 5:
axis[i]=gp_Ax2(position->center,gp_Dir(0,0,-1));
break;
default:
break;
}
}
BRepPrimAPI_MakeCylinder Cylinder1(axis[0],radius_array[a[0]],length_array[a[0]]);
TopoDS_Shape aShape1= Cylinder1.Shape();
BRepPrimAPI_MakeCylinder Cylinder2(axis[1],radius_array[a[1]],length_array[a[1]]);
TopoDS_Shape aShape2= Cylinder2.Shape();
BRepPrimAPI_MakeCylinder Cylinder3(axis[2],radius_array[a[2]],length_array[a[2]]);
TopoDS_Shape aShape3= Cylinder3.Shape();
BRepPrimAPI_MakeCylinder Cylinder4(axis[3],radius_array[a[3]],length_array[a[3]]);
TopoDS_Shape aShape4= Cylinder4.Shape();
aShape1=BRepAlgoAPI_Fuse(aShape1,aShape2);
aShape1=BRepAlgoAPI_Fuse(aShape1,aShape3);
aShape1=BRepAlgoAPI_Fuse(aShape1,aShape4);
//Body : Create a Hollowed Solid
TopoDS_Face faceToRemove[4];
Standard_Real Max[4]={-1000000000,-1000000000,-1000000000,-1000000000};
for(TopExp_Explorer aFaceExplorer(aShape1, 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();
gp_Vec aVec= gp_Vec(aPnt.X()-(position->center).X(),aPnt.Y()-(position->center).Y(),aPnt.Z()-(position->center).Z());
Standard_Real dot[4];
dot[0]=aVec.Dot(axis[0].Direction());
dot[1]=aVec.Dot(axis[1].Direction());
dot[2]=aVec.Dot(axis[2].Direction());
dot[3]=aVec.Dot(axis[3].Direction());
for(i=0;i<n;i++)
{
if(dot[i]>Max[i])
{
Max[i]=dot[i];
faceToRemove[i]=aFace;
}
}
}
}
TopTools_ListOfShape facesToRemove;
for(i=0;i<n;i++)
facesToRemove.Append(faceToRemove[i]);
aShape1 = BRepOffsetAPI_MakeThickSolid(aShape1, facesToRemove , thick, 1.e-3);
return aShape1;
}
TopoDS_Shape _Pipe::MakeShape_Stere_Five(Standard_Integer *a,Standard_Integer n)
{
gp_Ax2 *axis=new gp_Ax2[5];
for(Standard_Integer i=0;i<n;i++)
{
switch(a[i])
{
case 0:
axis[i]=gp_Ax2(position->center,gp::DX());
break;
case 1:
axis[i]=gp_Ax2(position->center,gp_Dir(-1,0,0));
break;
case 2:
axis[i]=gp_Ax2(position->center,gp::DY());
break;
case 3:
axis[i]=gp_Ax2(position->center,gp_Dir(0,-1,0));
break;
case 4:
axis[i]=gp_Ax2(position->center,gp::DZ());
break;
case 5:
axis[i]=gp_Ax2(position->center,gp_Dir(0,0,-1));
break;
default:
break;
}
}
BRepPrimAPI_MakeCylinder Cylinder1(axis[0],radius_array[a[0]],length_array[a[0]]);
TopoDS_Shape aShape1= Cylinder1.Shape();
BRepPrimAPI_MakeCylinder Cylinder2(axis[1],radius_array[a[1]],length_array[a[1]]);
TopoDS_Shape aShape2= Cylinder2.Shape();
BRepPrimAPI_MakeCylinder Cylinder3(axis[2],radius_array[a[2]],length_array[a[2]]);
TopoDS_Shape aShape3= Cylinder3.Shape();
BRepPrimAPI_MakeCylinder Cylinder4(axis[3],radius_array[a[3]],length_array[a[3]]);
TopoDS_Shape aShape4= Cylinder4.Shape();
BRepPrimAPI_MakeCylinder Cylinder5(axis[4],radius_array[a[4]],length_array[a[4]]);
TopoDS_Shape aShape5= Cylinder5.Shape();
aShape1=BRepAlgoAPI_Fuse(aShape1,aShape2);
aShape1=BRepAlgoAPI_Fuse(aShape1,aShape3);
aShape1=BRepAlgoAPI_Fuse(aShape1,aShape4);
aShape1=BRepAlgoAPI_Fuse(aShape1,aShape5);
//Body : Create a Hollowed Solid
TopoDS_Face faceToRemove[5];
Standard_Real Max[5]={-1000000000,-1000000000,-1000000000,-1000000000,-1000000000};
for(TopExp_Explorer aFaceExplorer(aShape1, 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();
gp_Vec aVec= gp_Vec(aPnt.X()-(position->center).X(),aPnt.Y()-(position->center).Y(),aPnt.Z()-(position->center).Z());
Standard_Real dot[5];
dot[0]=aVec.Dot(axis[0].Direction());
dot[1]=aVec.Dot(axis[1].Direction());
dot[2]=aVec.Dot(axis[2].Direction());
dot[3]=aVec.Dot(axis[3].Direction());
dot[4]=aVec.Dot(axis[4].Direction());
for(i=0;i<n;i++)
{
if(dot[i]>Max[i])
{
Max[i]=dot[i];
faceToRemove[i]=aFace;
}
}
}
}
TopTools_ListOfShape facesToRemove;
for(i=0;i<n;i++)
facesToRemove.Append(faceToRemove[i]);
aShape1 = BRepOffsetAPI_MakeThickSolid(aShape1, facesToRemove , thick, 1.e-3);
return aShape1;
}
TopoDS_Shape _Pipe::MakeShape_Stere_Six(Standard_Integer *a,Standard_Integer n)
{
gp_Ax2 *axis=new gp_Ax2[6];
for(Standard_Integer i=0;i<n;i++)
{
switch(a[i])
{
case 0:
axis[i]=gp_Ax2(position->center,gp::DX());
break;
case 1:
axis[i]=gp_Ax2(position->center,gp_Dir(-1,0,0));
break;
case 2:
axis[i]=gp_Ax2(position->center,gp::DY());
break;
case 3:
axis[i]=gp_Ax2(position->center,gp_Dir(0,-1,0));
break;
case 4:
axis[i]=gp_Ax2(position->center,gp::DZ());
break;
case 5:
axis[i]=gp_Ax2(position->center,gp_Dir(0,0,-1));
break;
default:
break;
}
}
BRepPrimAPI_MakeCylinder Cylinder1(axis[0],radius_array[a[0]],length_array[a[0]]);
TopoDS_Shape aShape1= Cylinder1.Shape();
BRepPrimAPI_MakeCylinder Cylinder2(axis[1],radius_array[a[1]],length_array[a[1]]);
TopoDS_Shape aShape2= Cylinder2.Shape();
BRepPrimAPI_MakeCylinder Cylinder3(axis[2],radius_array[a[2]],length_array[a[2]]);
TopoDS_Shape aShape3= Cylinder3.Shape();
BRepPrimAPI_MakeCylinder Cylinder4(axis[3],radius_array[a[3]],length_array[a[3]]);
TopoDS_Shape aShape4= Cylinder4.Shape();
BRepPrimAPI_MakeCylinder Cylinder5(axis[4],radius_array[a[4]],length_array[a[4]]);
TopoDS_Shape aShape5= Cylinder5.Shape();
BRepPrimAPI_MakeCylinder Cylinder6(axis[5],radius_array[a[5]],length_array[a[5]]);
TopoDS_Shape aShape6= Cylinder6.Shape();
aShape1=BRepAlgoAPI_Fuse(aShape1,aShape2);
aShape1=BRepAlgoAPI_Fuse(aShape1,aShape3);
aShape1=BRepAlgoAPI_Fuse(aShape1,aShape4);
aShape1=BRepAlgoAPI_Fuse(aShape1,aShape5);
aShape1=BRepAlgoAPI_Fuse(aShape1,aShape6);
//Body : Create a Hollowed Solid
TopoDS_Face faceToRemove[6];
Standard_Real Max[6]={-1000000000,-1000000000,-1000000000,-1000000000,-1000000000,-1000000000};
for(TopExp_Explorer aFaceExplorer(aShape1, 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();
gp_Vec aVec= gp_Vec(aPnt.X()-(position->center).X(),aPnt.Y()-(position->center).Y(),aPnt.Z()-(position->center).Z());
Standard_Real dot[6];
dot[0]=aVec.Dot(axis[0].Direction());
dot[1]=aVec.Dot(axis[1].Direction());
dot[2]=aVec.Dot(axis[2].Direction());
dot[3]=aVec.Dot(axis[3].Direction());
dot[4]=aVec.Dot(axis[4].Direction());
dot[5]=aVec.Dot(axis[5].Direction());
for(i=0;i<n;i++)
{
if(dot[i]>Max[i])
{
Max[i]=dot[i];
faceToRemove[i]=aFace;
}
}
}
}
TopTools_ListOfShape facesToRemove;
for(i=0;i<n;i++)
facesToRemove.Append(faceToRemove[i]);
aShape1 = BRepOffsetAPI_MakeThickSolid(aShape1, facesToRemove , thick, 1.e-3);
return aShape1;
}
/*************************Valve*******************************/
Valve::Valve()
{
location=gp_Pnt(0,0,0);
norm=gp_Dir(0,0,1);
size=SIZE_ONE;
}
Valve::~Valve()
{
}
void Valve::SetParameters(gp_Pnt loca,gp_Dir dir,Standard_Integer ss)
{
location=loca;
norm=dir;
size=ss;
}
void Valve::SetLocation(gp_Pnt loca)
{
location=loca;
}
gp_Pnt Valve::GetLocation()
{
return location;
}
void Valve::SetNormal(gp_Dir dir)
{
norm=dir;
}
gp_Dir Valve::GetNormal()
{
return norm;
}
void Valve::SetSize(Standard_Integer ss)
{
size=ss;
}
Standard_Integer Valve::GetSize()
{
return size;
}
TopoDS_Shape Valve::MakeShape()
{
gp_Ax2 axis(location,norm);
BRepPrimAPI_MakeCylinder platform(axis, size*4/5 , size*6/5);
TopoDS_Shape plat= platform.Shape(); // 小平台
BRepPrimAPI_MakeCylinder vertical(axis, size/5 , 1.8*size);
TopoDS_Shape vert= vertical.Shape(); // 竖柱
plat = BRepAlgoAPI_Fuse(plat, vert);
// Trsf aTrsf;
// aTrsf.SetTranslation(norm);
// gp_Pnt torus_location=location.Transformed(aTrsf);
// gp_Pnt torus_location=gp_Pnt(loaction.X()+,location.Y()+,location.Z()+);
gp_Ax2 torus_axis(torus_location,norm);
BRepPrimAPI_MakeTorus Torus(torus_axis,size*4/5,size*0.15); // 泳圈
TopoDS_Shape torus= Torus.Shape();
gp_Pnt neckLocation3( 0, 0, 0);
//gp_Dir neckNormal2 = gp::DX();
gp_Ax2 neckAx23( neckLocation3, neckNormal);
BRepPrimAPI_MakeCylinder MKCylinder3(neckAx23 , radius/10 , radius*0.9); // 泳圈支撑
TopoDS_Shape myCrossDuct4 = MKCylinder3.Shape();
gp_Ax1 zAxis = gp::OZ();
gp_Trsf aTrsf;
gp_Ax1 yAxis = gp::OY();
gp_Trsf aTrsf1;
aTrsf1.SetRotation( yAxis, PI*17/9);
BRepBuilderAPI_Transform aBRepTrsf2( myCrossDuct4, aTrsf1);
myCrossDuct4 = aBRepTrsf2.Shape();
gp_Pnt neckLocation5( 0, 0, 1.8*radius);
gp_Ax2 neckAx25(neckLocation5 , neckNormal1);
BRepPrimAPI_MakeSphere MKSphere( neckAx25, radius/5);
TopoDS_Shape myBall = MKSphere.Shape();
}